; 32 x 32 sprites
;set graphics mode
Graphics 640,480,16,2
;load sprite images and mask
imgobj=LoadAnimImage("sprite.png",32,32,0,144)
MaskImage imgobj,0,0,0
;create game timer
timer = CreateTimer(15)
;set starting frame for animation
frame = 0
;set some vars
x# = 100
y# = 100
Gravity#=.1
gy# = y
onground = True
jleft = False ;was playing with these
jright = False ;true false flags to see if i could stop the movement left / right in the air
;set drawing buffer to back buffer
SetBuffer BackBuffer()
;start main while loop
While Not KeyHit(1)
;clear screen
Cls
;draw a couple of lines for char' to walk/jump on
Line 0,100,64,100
Line 0,132,640,132
;just a load of vars i had on the screen to see what they were up to as i messed about trying different things
Text 0,345,"frame = " + frame
Text 0,365,"jleft = "+jleft
Text 0,385,"jright = "+jright
Text 100,0,"y = " + y
Text 200,0,"gy = " + gy
Text 0,0,"x = " + x
;draw images
DrawImage imgobj,x,y,frame
;jump and gravity stuff
y = y + gravity
If y>gy Then ;gy was one of the vars/flags i was messin with to try and stop movement left / right whilst in the air
y=gy ;also want players y value to change if player happens to have new level of ground below his feet,
Gravity=0 ;not figured that bit out yet !
onground = True
Else
Gravity = Gravity + .5
EndIf
If KeyHit(57) And onground = True ;check for double jump --- as dont want it. This works ok !! :)
Gravity=-6.5
onground = False
EndIf
; left and right movement
If KeyDown(205) ;And onground = True ; <----------- if this is uncommented,(and/or next if statement for left key), as soon as you jump the char' stops moving in the direction
frame = frame + 1 ; he started off in , and just goes straight up and down untill he hits ground again
If frame >= 4 ; I want the char to carry on jumping in the direction he was going in when jump is pressed
frame = 0 ; and not move right / left in the air.
x = x + 16 ; Also if you let go of the right or left key whilst in the air the char'
EndIf ; stops moving in the dir' he started off in and just falls down vertically
EndIf
If KeyDown(203) ;And onground = True
frame = frame - 1
If frame < 4
frame = 7
x = x - 16
EndIf
EndIf
;checks if sprite x cord is no at edge of screen.... if so then reset x cord and frame
If x >= 612
x = 612
frame = 0
EndIf
If x <= 4
x = 4
frame = 7
EndIf
;wait for game timer
WaitTimer timer
;flip buffers to show image on screen
Flip
;end main while loop
Wend
;end program
End
|