Gornova/MarteEngine

PhysicsEntity.motionX / .motionY needlessly bloated (slopes?)

Opened this issue · 3 comments

Hey, I'm refactoring the motion code into mover components, and I came across the code in motionX and motionY that checks against slopes. It's a for loop, and while it's nice to have, as far as I know, all hitboxes are rectangular at the moment, right?

So do we need slope checks? Either way I'm going to extract the slope checks out into a separate method. Let me know if we need it at all at this point, and if so, how do I do slopes!?

Cheers.

Removing the slope checks yields this very lightweight algorithm:

// check each pixel in the length of our move along x
        for (int xCheck = 0; xCheck < Math.abs(entity.speed.x); xCheck++)
        {

            // if we hit something solid in the direction we're moving, stop
            if (entity.collide(Entity.SOLID,
                    entity.x + Math.signum(entity.speed.x), entity.y) != null)
            {
                entity.speed.x = 0;

                // we don't need to check any further
                break;
            }

            entity.x += Math.signum(entity.speed.x);
        }

        // check each pixel in the length of our move along y
        for (int yCheck = 0; yCheck < Math.abs(entity.speed.y); yCheck++)
        {
            // if we collide with a solid
            if (entity.collide(Entity.SOLID, entity.x,
                    entity.y + Math.signum(entity.speed.y)) != null)
            {

                entity.speed.y = 0;

                // we don't need to check any further
                break;
            }

            entity.y += Math.signum(entity.speed.y);

        }

If we incorporate slopes, we just make a slopedMotion() method.

Right now slopes are not in, that's true.
But the current SVN Slick version plus some enhancement mentioned in the Slick forums allows mask based collisions. This is exactly what we would need to add to use the included slope code.
So basically "it's all there" (TM) - we would just need to use the stuff out there.
You have to keep the slope code (either in a method or the way it is right now) in the loops I think to keep it working but I haven't looked at it in detail...

Cool! Well, like I said in my earlier post, I'm going to make a second method for slopedMotion. That way the user has a choice based on whether they will be using slopes.

Also, I have absolutely no idea how to do mask-based collisions. I'm going to have to learn something new.