I did a routine for a jumping code which to my eyes should work. It combines two loops - one for going up and gradually slowing down (gravity pull) and one for going back down again (essentially reversing the process.
I'm too inexperienced to be able to see what's wrong. It could be the jump code, it could be the draw routine, or it could be my ropy attempt at a delay. Either way, if someone (we all know who)

The first bit of code is just the button press in the CONTROLS routine to activate the jump. The second is the actual jump code (both are housed in separate .asm files.
Many thanks!
(Excuse the big spaces between code lines. It makes it easier for my 42 year old eyes to read)
Code: Select all
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;CONTROLS_FLYINGKICK ;;
;;;;;;;;;;;;;;;;;;;;;;;;
bit 5,a ; Set Bit that tests for Joystick JUMP (Fire Button 2) (Bit-5)
jr z,JOYNOT_FLYINGKICK
ld a,6 ; Set STATE for JUMP animation
ld(PLAYER_STATE),a
ld (PLAYER_YPOS),hl ; Get current Y-Position BEFORE JUMP and store in 'hl
ld a,5 ; Jump amount
ld (ZSPEED),a ; Load initial Jump value into ZSPEED before loops start
call PLAYER_VARSETUP ; Sets up some player specific values for the DRAW routine
jp JUMPLOOPS_ASM ; Jump (jp) to JUMP loops
JOYNOT_FLYINGKICK:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; JUMP LOOP(S) ;;
;;;;;;;;;;;;;;;;;;
JUMPUP_LOOP:
ld bc,2000 ; Set delay time
ld (DELAY_AMOUNT),bc
call DELAY
ld bc,&0000 ; Clear 'bc'
ld hl,(PLAYER_YPOS) ; Get current Y-POSITION in the jump and transfer to 'hl'
ld bc,(ZSPEED) ; Jump speed loaded into 'bc'(Pre-loop set at 5, but will go down every loop)
add hl,bc ; Jump up by whatever number is in 'bc'(ZSPEED) by adding to...
;...current 'hl' (PLAYER_YPOS)
ld (PLAYER_YPOS),hl ; Load new 'hl' value back into PLAYER_YPOS variable
call SPRITEPOSITION ; Send new information to DRAW code to display on screen
dec bc ; Reduced jump (ZSPEED) amount by 1 (Pull down of Gravity)
ld (ZSPEED),bc ; Load reduced value back into ZSPEED for next loop (should be 4,3,2...)
ld a,(ZSPEED) ; Load new ZSPEED value into 'a'
ld b,a ; Transfer ZSPEED value from 'a' to 'b'
ld a,0 ; set 'a' to 0
cp b ; See if 'b' (ZSPEED) is 0
jr nz, JUMPUP_LOOP ; If not then repeat loop until 'b' = zero
JUMPDOWN_LOOP:
ld bc,2000 ; Set delay time
ld (DELAY_AMOUNT),bc
call DELAY
ld bc,&0000 ; Clear 'bc'
ld a,(ZSPEED) ; Load current jump speed (ZSPEED) to 'a'(should be 0 after other loop)
ld b,a ; Load 'a' to 'b' (so b = ZSPEED)
ld a,(PLAYER_YPOS) ; Get current Y-POSITION in the jump and load to 'a'
sub b ; Jump down by whatever number is in 'b'(ZSPEED) by subtracting from 'a' (Y position)
ld (PLAYER_YPOS),a ; Load new 'a' value back into PLAYER_YPOS
call SPRITEPOSITION ; Send new information to DRAW code and update screen position
inc b ; Increase jump amount by 1 (Fall back to ground)
ld a,b ; Load new value from 'b' to 'a'
ld (ZSPEED),a ; Load increased value from 'a' back into ZSPEED for next loop (should be 1,2,3...)
ld a,(ZSPEED) ; Load new ZSPEED value into 'a'
ld b,a ; Transfer ZSPEED value from 'a' to 'b'
ld a,8 ; set 'a' to 8
cp b ; See if 'b'(ZSPEED) has increased enough to be = to 8
jr nz, JUMPDOWN_LOOP ; If not then repeat loop until b = 8
cp b
jp z, BACKONGROUND ; if it is equal then jump back to the STANCE state and draw routine
BACKONGROUND:
ld a,1
ld (PLAYER_STATE),a
jp SPRITEDRAW
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; DELAY ;;
;;;;;;;;;;; ** WILL NEED TO PUT THIS IN A FUNCTION SHEET LATER **
DELAY:
ld bc,(DELAY_AMOUNT)
ld a,0
D_LOOP:
djnz, D_loop
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;