Quote: "I think i made the mistake of taking that from the codebase whithout looking at what it was for. I think it was for darkbasic pro."
I tried it in Pro and it just gave me errors. :-(
Quote: "But no i haven't got the jumping to work properly yet."
That's ok. The following code is what I was talking about. It doesn't have any fancy math so once it hits the ceiling it immediately goes down.
` Initialize the program
hide mouse
sync rate 0
sync on
load bitmap "protoman.png", 1
` Grab running Protoman images
get image 1,30,379,56,406,1
get image 2,61,379,87,406,1
get image 3,92,379,118,406,1
get image 4,128,379,154,406,1
` Grab climbing Protoman images
get image 5,39,628,65,661,1
get image 6,73,628,99,661,1
` Grab jumping Protoman image
get image 7,32,425,59,458,1
cls
` Change to main view screen (because of loading bitmap)
set current bitmap 0
` Set the current image number and OldDirection
CImage=1
OldDirection=1
` Set the starting x and y of the character
x=30:y=56
` Set the timers for movement, animation, and jumping
tim=timer()
Imagetim=timer()
timjump=timer()
` DO this LOOP forever (no exit)
do
` Draw the sprite
sprite 1,x,y,CImage
` Go Up (Don't allow a jump while going up at the same time)
if upkey() and timer()>tim+10 and Jump=0
dec y
` Check if its time to change the image for animation
if timer()>Imagetim+150
inc CImage
` Check if the image is within range of frames 5 and 6
if CImage<5 then CImage=5
if CImage>=7 then CImage=5
` Reset animation timer
Imagetim=timer()
endif
` Reset movement timer
tim=timer()
endif
` Go Down (Don't allow a jump while going down at the same time)
if downkey() and timer()>tim+10 and Jump=0
inc y
` Check if its time to change the image for animation
if timer()>Imagetim+150
inc CImage
` Check if the image is within range of frames 5 and 6
if CImage<5 then CImage=5
if CImage>=7 then CImage=5
` Reset animation timer
Imagetim=timer()
endif
` Reset movement timer
tim=timer()
endif
` Go Left
if leftkey() and timer()>tim+10
` Check if the sprite needs to be mirrored
if OldDirection=1 then mirror sprite 1:OldDirection=2
dec x
` Check if its time to change the image for animation (and not during a jump)
if timer()>Imagetim+150 and Jump=0
inc CImage
` Check if the image is within range of frames 5 and 6
if CImage>=5 then CImage=1
` Reset animation timer
Imagetim=timer()
endif
` Reset movement timer
tim=timer()
endif
` Go Right
if rightkey() and timer()>tim+10
` Check if the sprite needs to be mirrored
if OldDirection=2 then mirror sprite 1:OldDirection=1
inc x
` Check if its time to change the image for animation (and not during a jump)
if timer()>Imagetim+150 and Jump=0
inc CImage
` Check if the image is within range of frames 5 and 6
if CImage>=5 then CImage=1
` Reset animation timer
Imagetim=timer()
endif
` Reset movement timer
tim=timer()
endif
` Jump (only allow when not jumping already)
if spacekey() and timer()>timjump+5 and Jump=0
` Save the old sprite image number
OldImage=sprite image(1)
` Set current image to jump image
CImage=7
` Set jump variable (used to check if jump is active or not)
Jump=1
` Save starting y
OldY=sprite y(1)
` Calculate how high the jump will go
JumpCeiling=OldY-40
` Reset jump timer
timjump=timer()
endif
` Check if Protoman is falling from a jump
if Jump=2 and timer()>timjump+5
` Increase current y coordinate
inc y
` Check if the starting y has been reached and stop jump (change to 0)
if y=>OldY then Jump=0:CImage=OldImage :` Change image to oldimage
` Reset jump timer
timjump=timer()
endif
` Check if Protoman is jumping
if Jump=1 and timer()>timjump+5
` Decrease current y coordinate
dec y
` Check if the Jump Ceiling has been reached (change to 2)
if y<=JumpCeiling then Jump=2
` Reset jump timer
timjump=timer()
endif
sync
loop