Well, SegaBoy, I wasn’t originally planning on adding physics support at all, but after working on the platformer samples it occurred to me that physics could simplify some of the tasks particularly where different game genres cross. It makes sense to do your own calculations to control Sonic because he doesn’t necessarily act in a physically accurate way, for example he sticks to sloped ground rather than running into the air at high speeds. However if someone just wants to, say, bounce a ball around a room in an RPG in a freeform manner- not locked to the grid- it would be a hassle for them to have to program the whole state engine just for that sideshow.
@Ninja Pig Studios; SegaBoy has it down. I don’t have access to my files right now, but collision detection basically boils down to calculating the future position of your sprite, checking for tiles there, and checking for whatever tile property you use to determine whether a tile is solid or not. For RPG type games where the sprites are fixed to a grid like CastleDemo, this is pretty straightforward. You just add or subtract 1 from the sprite’s locX or locY parameter and check that location for solid tiles. Collision detection in a platformer is more or less the same but with per-pixel accuracy. You figure out where the “feet” of the sprite will be and check to see if they’re within a tile. If they are you adjust the velocity so they land ontop of the tile. The feet in this case are points you define in your code relative to the sprite. Platformer collision detection can be a little tricky, but I’m hoping Physics integretion will make this easier for people.
@dingo; The hardest part of Sonic movement in my opinion is getting him to stick to and land on the ground. Once that is taken care of the rest is relatively easy because it only interacts with the code you already have. The ground collision code would work for enemies without changes if I remember right. All you’d need for the enemies is their own velX, velY, etc 2D movement variables. Flying enemies would be quiet a bit simpler. Jumping on an enemy would be as easy as checking for a distance threshhold between the Sonic sprite and the enemy, checking whether Sonic’s isJumping variable is true, and if so adding to his Y velocity for the characteristic post-baddy-destruction hop. Spinning, spindash, ducking, etc, would all involve finagling with the control inputs and setting up a bunch of boolean flags, but the annoying part- the ground detection- would need little modification.
@Danny; Thanks Danny! Kudos are much appreciated.
@nick_sherman; Thanks nick_sherman! I’d been itching to do something Sonic related for a while now.