GithubHelp home page GithubHelp logo

Comments (17)

Suprcode avatar Suprcode commented on July 30, 2024 1

The images only ever go as high as they have atleast 1 pixel in them. As you can see from below the pink cells show the bottom of each image (where its physically placed).

image

So all you need to do is get the height of the image, divide is by the constant cell height - that'll give you the cells tall an image is.

then as you loop down your Y coord - you check if the player coord is greater than the Y coord minus the image height. If it is, you know the player is over it.

player Y = 100

checking Y coord = 105
105's image height = 5

if (100 > 105 - 5) Player is behind image.

image height will always be minimum of 1. So in most cases for a single cell image

if (100 > 101 - 1) player not behind

(you'll need to do this on front and middle layers)

Should be as simple as that. Obviously you're not going to be able to know if just a foot is behind the image, but you're still massively reducing when you have to double draw the player.

from zircon.

FluffyDuckyEU avatar FluffyDuckyEU commented on July 30, 2024

I feel like this should be handled as part of PlayerObject Draw() method.

https://github.com/Suprcode/mir3-zircon/blob/3a890d540ed4fa4a9b90f0089d2c3cadf2ef05e4/Client/Models/PlayerObject.cs#L801

Imo maybe I should just reimplement that whole Draw method while i'm touching it :|

from zircon.

Suprcode avatar Suprcode commented on July 30, 2024

Yes double drawing has always been a requirement to see yourself behind objects.

I don't think you lose the colour when you hover if that's what you meant. Just a side effect of the draw blend / opacity making the image brighter and losing colour I think.

I'm not sure how you'd plan to get around needing to double draw. The simplest fix would be to just double draw the wings too - I can't think of any other way you can resolve it in a single draw.

from zircon.

FluffyDuckyEU avatar FluffyDuckyEU commented on July 30, 2024

It seems like a waste to process twice, i was hoping to be able to determine whether the character is hidden whilst processing in the PlayerObject.Draw but because the map object spans over multiple cells whilst only actually being assigned to one cell that the player isn't likely on makes it not possible like you said :/

from zircon.

Suprcode avatar Suprcode commented on July 30, 2024

To be honest you probably can work it out. You'd have to look at the current X coord, and all Y coordinates directly below the player (plus maybe +/- 1 X due to overflowing image to out cells). Then you'd need to look at all 3 layer images to see if the cell height reaches the player.

It'll certainly be an expensive calculation to constantly do, so you'd need to ensure its cached - which might use abit of memory after a certain period.

from zircon.

Suprcode avatar Suprcode commented on July 30, 2024

Thinking about it, you're really only going to need to calculate 3 cells below you - each time you move. So maybe not that expensive and worth looking in to. Certainly would be better than drawing opacity over the player constantly

from zircon.

FluffyDuckyEU avatar FluffyDuckyEU commented on July 30, 2024

I thought some map objects were quite tall, let me see if I can investigate that as a separate thing.

from zircon.

Suprcode avatar Suprcode commented on July 30, 2024

They are, but there's only 3 cells below you. Any objects lower than that won't get drawn, even if they're more than 3 cells tall. I think.

from zircon.

FluffyDuckyEU avatar FluffyDuckyEU commented on July 30, 2024

Here is the same example. This particular object is 1x13 size.

image

from zircon.

FluffyDuckyEU avatar FluffyDuckyEU commented on July 30, 2024

Do you think it's still possible to be able to calculate a top image that is up to maybe 10 cells away from your character?

Sorry for the horrible pink lines, i don't know where i found this program but it does the job for viewing the map😅

image

from zircon.

FluffyDuckyEU avatar FluffyDuckyEU commented on July 30, 2024

The more I think about it, the more I think it's not possible, how would you also handle a character half under shelter and half not? The double draw handles this, but would you end up with the draw fully oqaue not opaque at all if you had this situation with manually worked out solution?

image

from zircon.

Suprcode avatar Suprcode commented on July 30, 2024

You'd have to just double draw as soon as the feet/player cell is in the area. But it still means 99% of the time you're not double drawing.

Maybe write the function to search for 10 coords below you and see how the performance is. Since you only need to do it once every time you move, it'll probably be fine

from zircon.

FluffyDuckyEU avatar FluffyDuckyEU commented on July 30, 2024

I may be thinking about this too simply, but using the cell positions I don't think is enough to work.

image

Maybe you have something in mind that i don't, when you say:

Then you'd need to look at all 3 layer images to see if the cell height reaches the player.

How would I know if the map object image overflow lands on top of the player fully or not? The only way I can see this being achieved is if you check whether the images intersect, not by cells but by pixel maybe?

from zircon.

Suprcode avatar Suprcode commented on July 30, 2024

I've given this a quick go, and although it does kind of work - it certainly not perfect.

public bool IsBehindObject()
        {
            if (User == null) return false;

            var location = User.CurrentLocation;

            IsBehind = false;

            for (int offset = 0; offset < 20; offset++)
            {
                var y = location.Y + offset;

                var cell = Cells[location.X, y];

                if (cell == null) continue;

                LibraryFile file;
                MirLibrary library;

                if (Libraries.KROrder.TryGetValue(cell.MiddleFile, out file) && file != LibraryFile.Tilesc && CEnvir.LibraryList.TryGetValue(file, out library))
                {
                    int index = cell.MiddleImage - 1;

                    Size s = library.GetSize(index);

                    var cellsTall = s.Height / CellHeight;

                    if (location.Y > (location.Y + offset - cellsTall))
                    {
                        IsBehind = true;
                        break;
                    }
                }

                if (Libraries.KROrder.TryGetValue(cell.FrontFile, out file) && file != LibraryFile.Tilesc && CEnvir.LibraryList.TryGetValue(file, out library))
                {
                    int index = cell.FrontImage - 1;

                    Size s = library.GetSize(index);

                    var cellsTall = s.Height / CellHeight;

                    if (location.Y > (location.Y + offset - cellsTall))
                    {
                        IsBehind = true;
                        break;
                    }
                }
            }

            System.Diagnostics.Debug.WriteLine(IsBehind ? "true" : "false");

            return IsBehind;
        }

Then add an "IsBehind" variable to map control

call this line inside LocationChanged()

GameScene.Game.MapControl.IsBehindObject();

and finally wrap drawPlayer around the check


if (IsBehind)
            {
                MapObject.User.DrawPlayer(false);
            }

It would probably be much better just doing this check when the map gets drawn itself - and it doesn't always look to work, often i find myself double drawing when i'm not behind anything.

Ideally checking if there is a visible pixel on the image would be much better - but i can only think performance on that would be an issue.

from zircon.

FluffyDuckyEU avatar FluffyDuckyEU commented on July 30, 2024

I didn't have much time to look myself but i was thinking more along this train of thought, but it didn't work.. maybe i missed something simple.

image

from zircon.

FluffyDuckyEU avatar FluffyDuckyEU commented on July 30, 2024

Ah it does kind of work if I change this code a bit.

                        if (!playerOverlap)
                        {
                            if (s.Width == 0 || s.Height == 0) continue;

                            Rectangle MidImage = new Rectangle(drawX, drawY, s.Width, s.Height);
                            bool result = !Rectangle.Intersect(MidImage, playerRectangle).IsEmpty;
                            playerOverlap = result;
                        }

It still has issues though.

  • Flickering when transitioning between cells
  • Not drawing if the head is showing, weirdly it works if the head is hidden and bottom half of body is showing.

DDB

Maybe easier to see without the huge armour wings.
DDB1

from zircon.

Suprcode avatar Suprcode commented on July 30, 2024

That sounds like a much better approach

i think you'll need to cache it though so it only rechecks once per player move.

Also, the player dimensions are alot more than just body - if you look in DrawBody theres an l/t/r/b value which gets used to create the shadows - maybe you can store this as a rectangle to reuse it for intersecting?

from zircon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.