Run and Jump Routine

Por Chilly Willy

Expert (108)

imagem de Chilly Willy

04-09-2022, 20:42

Do you have any idea how hard it is to search for a Jump Routine in Z80 is on Google?

There are only so many links to Z80 Heaven I can stand.

Does anyone have or can point me to source, print of a Jump Routine...no JMP but JUMP.

I have a little guy that goes left and right on the screen.
I would like to press a button on a device, I will define that later, and the guy JUMPS on an Arc.

Google had never been my friend which forced me to search code that might have a routine in it.

I get the concept but trying to figure it out for a week now and my eyes are already swollen from staring at the screen.

Please, someone.

TNX

Entrar ou registrar-se para comentar

Por aoineko

Paragon (1137)

imagem de aoineko

04-09-2022, 22:27

Hello,

I don't have a link to a code of jump in assebleur, but it's not very complicated to do.
If you want to avoid complex calculations, you can create a table with pre-calculated values that you can adjust easily and that you just have to apply on the position of your character at each update of the game.
For example :

jump_offset:
   db 4,3,2,1,0,-1,-2,-3,-4,$FF ; jump 10 pixels up

Then, in the big line, you have to :
- Detect when the jump button is pressed,
- Record the fact that the character is "in the air" (to prevent jumping during the jump)
- Initialize a pointer at the beginning of your offset array (jump_offset)
Then, at each tick of the gameplay code :
- Change the character's Y position by subtracting the pointer's value
- Then, increment the pointer. You can put an end-of-array code ($FF in the example) to either stop the jump (if the ground is still at the same place) or loop on the last value (if the character can "fall").

Por Daemos

Prophet (2169)

imagem de Daemos

05-09-2022, 08:50

How precise do you want your jumps and how is the feel of the jumps. The basic principle is simple like aineko allready outlined but in practice depending on your needs the code can reach high to ultra complexity for maximum jump smoothness. I can search up some code if you need examples.

Por theNestruo

Champion (430)

imagem de theNestruo

05-09-2022, 09:24

Chilly Willy wrote:

Does anyone have or can point me to source, print of a Jump Routine...no JMP but JUMP.
(...)
I would like to press a button on a device, I will define that later, and the guy JUMPS on an Arc.

From Stevedore:
- The player is a finite-state machine; the player can be on the floor, in the air, grabbed to a ladder, etc.
- The player update routine uses a jump table to execute the proper player routine based on the state of the player
- The relevant player routines are: SET_PLAYER_JUMPING and UPDATE_PLAYER_AIR, and they are based in one arc, similar to the one Aoineko posted before.

There is a minimal working example in MSXlib, in case you don't want to fiddle with the full Stevedore source code.