Runner
Where do start?
- Create objects (and sprites) for
oPlayer
,oWall
, andoSpike
- Update
oPlayer
to move horizontally (constantdx
+ horizontal collisions) - Update
oPlayer
to move vertically (jump + gravity + vertical collisions) - Update
oPlayer
to die when they hit spikes - Update camera to follow the player (I have the camera offset so that the player can see more ahead)
- Add some parallax if you want 😊
How do I make the rotation effect?
The easiest way is probably to increase oPlayer
’s angle when they’re above ground, and lock to 0 when they’re on the ground
That gets tricky, because if you get the rotation speed wrong the oPlayer
can hit the ground mid rotation, and there’ll be a jarring snap to 0
I probably over-engineered this but, I ended up determining the angle based on the current player’s speed. Let’s say our jump speed is 10. That means dy
is -10 at the start of the jump, 0 at the top, and then (assuming flat ground), it’ll be 10 again at the bottom
So with that knowledge I can create a variable to represent how far along I am through the jump (again assuming flat ground): var t = (dy + abs(jump_dy)) / (2*abs(jump_dy))
(this is “current + start / (end - start)”, and it’ll give me a number 0 to 1 representing how far between current and start I am). From there I did angle = lerp(90, -90, t)
, note that dy = 0 maps to angle = 0, so that should give me the correct angle even when I’m not jumping
Extra tip: By default game maker will factor image_angle into your collisions, but you probably want to keep your collisions consistent. To handle this I kept image_angle
at 0, instead used a separate variable together with draw_sprite_ext(..)
How do I detect collisions w/ the side of the wall?
I went over this when covering generic bounce in breaker, but now that we know collision functions it’s much easier. You can use place_meeting
(or place_free
, as well as some others) to only preview collisions using dx
or dy
if(place_meeting(x+dx, y, oSolid)){
// horizontal
}
if(place_meeting(x, y+dy, oSolid)){
// vertical
}
I feel like the spikes kill me when they’re not supposed to 😢
Ah, if you go into the sprite and look at the collision mask, you’ll notice that it uses the entire square as a collision box by default. So if the player clips the corner of the collision box they’ll die without actually hitting the spike art and it won’t seem fair
You could make it precise collision checking, but I opted to keep it a square and make it smaller than the spike art (people only complain about the game cheating when it hurts them 😉)
There’s actually a lot of cases where games bias their systems to keep player’s happy. For example, if a game tells you something is 90% accurate, it’s actually probably even more accurate. Otherwise players will feel like it’s unfair (link)