Ok while searching this forum I found a nice jumping script that I wanted to adept to my game.
This is the code I found:
`Basic Jumping Demo
`Programmed By: **Name Erased**
`Version: 1.0 - Bulit in Graphics
`Declare variables used
`variables for cords
xpos# = 100.0
ypos# = 350.0
xvel# = 0.0
yvel# = 0.0
grav# = -0.2
jumpimpulse# = 10.0
`Setup the framerate and window
`Intalize the window setup
set window on
set window title "Basic Jumping Demo - DBC - **Insert Your Name Here**"
set window layout 1,1,1
set window position 100,200
set window size 640,480
`Configurate the framerate
sync on
sync rate 60
`Hide the mouse pointer
hide mouse
`Disable the escape key
`Start a new loop
do
`You can show the pointer by clicking
`This is to avoid frustration to our player
if mouseclick() = 1 or mouseclick() = 2 then show mouse
`You can hide it again by pressing the enterkey
if returnkey() = 1 then hide mouse
`Sideways controls
if jumping = 0
xvel# = 0.0
if leftkey() = 1 then xvel# = -7
if rightkey() = 1 then xvel# = 7
endif
if jumping = 1 and xvel# > 0
xvel# = xvel# - 0.05
endif
if jumping = 1 and xvel# < 0
xvel# = xvel# + 0.05
endif
`Jumping
if spacekey()=1 and jumping=0
yvel# = yvel# + jumpimpulse#
jumping = 1
endif
`Acceleration due to gravity
yvel# = yvel#+grav#
`Increase position by velocity
xpos# = xpos#+xVel#
ypos# = ypos#+yVel#
`If ball is below ground, move it above ground and set velocity to 0
if ypos# < 10.0
ypos# = 10.0
yvel# = 0.0
jumping = 0
endif
`Draw the main character a green circle
ink rgb(0,255,0),1
circle xpos#,480-ypos#,10
PRINT yvel#
PRINT xvel#
print ypos#
print xpos#
`Refresh the screen
sync
`Clear screen so no flicker
cls
loop
so now I tried this and liked the jumping behaviour...with a few modifications its easy to adept to any game...but...after merging the code with mine im falling to the top...not downwards...and when I jump I jump downwards...there must have been a lil mistake while converting the code to fit in mine but I cant find it.
REM SETUP OF ENGINE
backdrop off
set display mode 1024,768,32
sync on
sync rate 60
global onground
onground=0
global spritecollision
REM LOADING ALL IMAGES
load image "gfx/mainchar.png",1,1
sprite 1,1024/2,768/2,1
load image "gfx/ground.jpg",2,1
sprite 2,0,768-110,2
sprite 3,269,768-110,2
sprite 4,269+269,768-110,2
REM ADDITION
xpos# = 100.0
ypos# = 768.0
xvel# = 0.0
yvel# = 0.0
grav# = -0.2
jumpimpulse# = 10.0
REM END ADDITION
do
set cursor 0,0
print Sprite X(1),",",Sprite Y(1)
REM ADDITION
sprite 1,xpos#,ypos#,1
set cursor 0,10
print spritecollision
set cursor 0,20
print scancode()
gosub controlplayer
gosub ongroundcheck
gosub gravity
sync
loop
controlplayer:
REMSTART
if onground=1
if leftkey()=1
sprite 1,sprite x(1)-2,sprite y(1),1
endif
if rightkey()=1
sprite 1,sprite x(1)+2,sprite y(1),1
endif
if scancode()=31 and rightkey()=0 and leftkey()=0
sprite 1,sprite x(1),sprite y(1)-100,1
endif
endif
REMEND
REM ADDITION
if jumping = 0
xvel# = 0.0
if leftkey() = 1 then xvel# = -7
if rightkey() = 1 then xvel# = 7
endif
if jumping = 1 and xvel# > 0
xvel# = xvel# - 0.05
endif
if jumping = 1 and xvel# < 0
xvel# = xvel# + 0.05
endif
`Jumping
if spacekey()=1 and jumping=0
yvel# = yvel# + jumpimpulse#
jumping = 1
endif
REM ADDITION END
ongroundcheck:
spritecollision=sprite hit(1,0)
for i=1 to 4
if spritecollision=i
sprite 1,sprite x(1),sprite y(i)-159,1
endif
next i
if spritecollision>0 and spritecollision<5
onground=1
REM ADDITION
yvel# = 0.0
jumping = 0
REM ADDITION END
else
onground=0
endif
return
gravity:
REMSTART
if onground=0
sprite 1,sprite x(1),sprite y(1)+2,1
endif
REMEND
REM ADDITION
yvel# = yvel#+grav#
`Increase position by velocity
xpos# = xpos#+xVel#
ypos# = ypos#+yVel#
REM ADDITION END
return
I know its kinda confusing searching some other ones code but I could really need the help since its been a long time I used DBPro. Also I left in my old testing code and marked it out with rems and also stated where I added the code from the upper code snippet.
Thanks in advance
Ben