Then I realized a few things.
- I only need to worry about Q*bert when he is moving downwards on the screen - when his yVelocity is positive.
- If Q*bert "knows" which cube he is jumping onto, then I only need to manage collisions with that particular cube - in fact, all other cubes are problematic distractions.
- As far as the collision with that cube, all I need to do is figure out when Q*bert's feet have arrived at a certain height on the top face of the cube.
- ... and all this will work on most of the other critters on the screen.
To make Q*bert jump, then, I had to give him an initial x- and y- velocity (depending on which way he was moving); set a variable, IAmMoving, to True; and let him know which Cube he was trying to land on. It took a little bit of tinkering with the starting x- and y-velocities and the downwards acceleration to find values that looked right and got him to land on the right spot.
To make him stop, I checked periodically (while he was moving) to see whether he was moving down, and whether his feet were below the middle of the top face of the cube. If so, I set IAmMoving to False. (I also corrected his position to the center of that face, so there isn't any drift over time.)
So now Q*bert (or his rectangle, at least) is hopping around.
No comments:
Post a Comment