I've writen part of a sidescroller using Emperor Baal's tutorial for sprite collision (which, thankfully, included gravity/jumping), but there are a few problems that I can't seem to fix.
`Test Megaman like game
#include "TileSetFunc.dba"
Sync on
Sync rate 30
dim R(3,32,32)
dim G(3,32,32)
dim B(3,32,32)
Size=ReadTileset("newtileset.tst",4)
GetTile(2,1)
undim R(3,32,32)
undim G(3,32,32)
undim B(3,32,32)
`load image "grass.bmp",1
load image "mage_move[1].bmp",2
load image "mage_move[2].bmp",3
load image "mage_jump.bmp",4
dim tile(20,15)
dim platform(50)
for a=0 to 19
tile(a,14)=1
paste image tile(a,14),a*32,14*32
next a
platform(1)=7
platform(2)=8
get image platform(1),0,14*32,(19*32)+32,(14*32+32)
get image platform(2),0,14*32,(3*32)+32,(14*32+32)
sprite 1,0,14*32,platform(1)
sprite 2,5*32,13*32,platform(2)
sprite 3,9*32,12*32-5,platform(2)
maxplatforms=3
dim mage(5)
mage(1)=2
mage(2)=3
mage(3)=4
magesprite=5
sprite magesprite,2,10*32,mage(1)
frame=1
player_x=2
player_y=13*32
cls
load bitmap "back.png",0
do
inc player_y,2
old_x=player_x
if player_x>screen width() then player_x=0
if player_x+sprite width(magesprite)<0 then player_x=screen width()-sprite width(magesprite)
sprite magesprite,player_x,player_y,mage(frame)
if jumping=0
for a = 1 to maxplatforms
if sprite x(magesprite)+sprite width(magesprite) => sprite x(a) and sprite x(magesprite)=< sprite x(a)+sprite width(a)
if sprite y(magesprite)+sprite height(magesprite) > sprite y(a)
sprite magesprite, sprite x(magesprite), sprite y(a) - sprite height(magesprite),mage(frame)
endif
endif
next a
if leftkey()=1
if sprite mirrored(magesprite)=1 then mirror sprite magesprite
if frame=1
frame=2
else
frame=1
endif
dec player_x,5
endif
if rightkey()=1
if sprite mirrored(magesprite)=0 then mirror sprite magesprite
if frame=1
frame=2
else
frame=1
endif
inc player_x,5
endif
endif
If downkey()=1 and jumping = 1
jumping=0
endif
If upkey()=1 and jumping = 0
jumping = 1
jump_angle = 0
jump_height = sprite y(magesprite)
endif
If jumping = 1
inc jump_angle,4
sprite magesprite, sprite x(magesprite), jump_height - sin(jump_angle)*50,mage(3)
for a = 1 to maxplatforms
if sprite x(magesprite)+sprite width(magesprite) => sprite x(a) and sprite x(magesprite)=< sprite x(a)+sprite width(a)
if sprite y(magesprite)+sprite height(magesprite) > sprite y(a)
sprite magesprite, sprite x(magesprite), sprite y(a) - sprite height(magesprite),mage(frame)
jumping=0
endif
endif
next a
if leftkey()=1
if sprite mirrored(magesprite)=1 then mirror sprite magesprite
dec player_x,3
endif
if rightkey()=1
if sprite mirrored(magesprite)=0 then mirror sprite magesprite
inc player_x,3
endif
endif
sync
loop
end
The problems I am experiencing are as follow:
- whenever the character touches the side of a platform, it automaticly jums to the top of the platform
- whenever the character reaches the edge of the platform, it drop straight to the platform below at an alarming rate
- whenever it jumps off the edge of a platform it goes up like its supposed to, but when it goes down it reaches a certain point and starts to acend once again and keeps repeating the process until it touches the platform it jumps off of again.
if anyone can figure out why the code is causing this and maybe sugest a solution for the problem, it would be greatly appreciated
Dragael Software
Current Project: Nothing worth mentioning