Hi I'm working on a platformer but I don't know how to move a sprite with the circle pad or even make it jump.
Moving sprite and making it jump
Root / Programming Questions / [.]
TheFallingCheezCreated:
OK let's say you have a game loop:
VAR GO=1 WHILE GO _INPUT _UPDATE _DRAW WENDThe _INPUT function will be something like:
DEF _INPUT VAR BT=BUTTON() VAR TX,TY STICK OUT TX,TY IF BT AND #A THEN 'A button pressed VEL_Y=-50 'Set player velocity END IF VEL_X=TX 'Set x velocity to direction of stick ENDThe _UPDATE function will check that the player velocity doesn't exceed a certain value, then move the player by adding its x and y velocity values to its x and y position values. Then it will check that the player's new position isn't outside the game area (eg the screen) and cancel it's velocity and reset its position if it is. The _DRAW function will simply iterate through your game objects and draw them to the screen. Hope this helps?
Thanks but I'm still confused
I don't know what to do for update and draw. The hint made me more confused
For update, you just write some statements that add the velocity to the position.
Like INC X,VX, which will add VX to X.
Drawing would just consist of a SPOFS to X and Y of your player.
Collision is a bit trickier, though. I won't explain it right now as typing on a mobile device is terrible.
"hint spoiler"
The hint was a reminder to add gravity as far as I could tell. It accelerates downwards (for earth) at 9.8 m/s.Indeed! Don't worry about gravity until you've got the basic movement and jumping working. Once you've done that it will probably be obvious to you what you need to do to fix it.
First of all, just think about your game loop and what it needs to do.
Most game engines work the same way: they will loop forever, and they'll do three things.
1. Capture and process player input
2. Update the state of the game world
3. Draw the updated state to the screen.
Keeping these things separate help make a well-structured game.
In the first stage you want to separate the player's intention (eg. jump or move right) from their eventual action (their x and y position being updated) because the player might not be allowed to perform their desired action at that particular point in time (maybe they're already jumping, so can't jump again right now, or maybe they're trying to move into a wall)
In the second stage you'll need to iterate through all of your game's objects and update their state. Does an enemy need to move closer to the player, or does it need to shoot?
Once the state of your game world has been updated, then all you need to do is iterate again and call the drawing functions you require (maybe they're sprite animations, or maybe they're GLINE function calls).
Finally, one sixtieth of a second later, your game loop starts all over again.
Don't worry about getting it right the first time, and don't worry about speed optimisations. Right now you should focus just on getting something that works when you run it.
It doesn't matter if it's not perfect, or if does the wrong thing: post your code here and ask for help.