Hi, im working on a side scrolling platformer, like mario. So far i have a sprite whom can run left and right, and a level editor that works by using data.
Next i believe i need collision detection between the tiles and my sprite, but i have no idea how to go about that. I know that i need to use sprite hit or something on the various tiles but i dont know how to do this. Please explain slowly, im a noob.
Please help, thanks in advance
PS. my code is here
`GHOST TEST
`tiles 1-23=ghost
`tiles 24-27=ground
cls
`ghost
load bitmap "ghostsheet.bmp",1
`A=Hight of circle
A=40
`B=Width of circle
b=40
`C=Num of circles along Row
c=4
`D=Num of Frames in Anim
d=23
`E=Num of rows-1
e=5
`f=num of circles in row-1 so leave as is
f=c-1
for y=0 to e
for x=0 to f
get image 1+x+(y*c),(x*b),(y*a),(x*b)+b,(y*a)+a
next x
next y
delete bitmap 1
`tiles
load bitmap "tilesheet.bmp",24
`A=Hight of circle
A=40
`B=Width of circle
b=40
`C=Num of circles along Row
c=2
`D=Num of Frames in Anim
d=4
`E=Num of rows-1
e=1
`f=num of circles in row-1 so leave as is
f=c-1
for y=0 to e
for x=0 to f
get image 25+x+(y*c),(x*b),(y*a),(x*b)+b,(y*a)+a
next x
next y
delete bitmap 24
load image "tilesheet.bmp",24
xpos=200
ypos=200
image=7
rightspeed#=0
leftspeed#=0
tilenum=2
acceleration#=0.5
gravity=1
sync on
sync rate 30
`--------------------------
do
`--------------------------
`----------------------------- MAKE LEVEL -------------------------------------
`making the level
for y=0 to 12
for x=0 to 16
`reads the data at the bottom of the program
read a
`if a=1 puts a sprite in the right place on the screen
if a=1
tile=25
sprite tilenum,x*40,y*40,tile
inc tilenum
endif
if a=2
tile=26
sprite tilenum,x*40,y*40,tile
inc tilenum
endif
if a=3
tile=27
sprite tilenum,x*40,y*40,tile
inc tilenum
endif
if a=4
tile=28
sprite tilenum,x*40,y*40,tile
inc tilenum
endif
next x
next y
`data
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0
data 1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0
data 0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0
data 0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,4,0,4,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0
data 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0
`-----------------------------E-N-D MAKE LEVEL-------------------------------
`-----------------------------MOVE GHOST--------------------------------
`sprite
sprite 1,xpos,ypos,image
wait 1
`run
if keystate(29)=1 then topspeed=10
if keystate(29)=0 then topspeed=5
`right
if keystate(205)=1
if keystate(203)=0
image=image+1
if image>11 then image=7
rightspeed# = rightspeed# + 0.25
if rightspeed#>topspeed then rightspeed# = rightspeed#-0.5
leftspeed#=leftspeed#+0.25
endif
endif
`left
if keystate(203)=1
if keystate(205)=0
if image<12 then image=12
image=image+1
if image>21 then image=16
leftspeed# = leftspeed# - 0.25
if leftspeed#<-topspeed then leftspeed# = leftspeed#+0.5
rightspeed#=rightspeed#-0.25
endif
endif
`no keys pressed
if keystate(203)=0
if keystate(205)=0
image = 1
rightspeed#=rightspeed#-0.5
leftspeed#=leftspeed#+0.5
endif
endif
`both keys pressed (skid)
if keystate(203)=1
if keystate(205)=1
`still
if rightspeed# + leftspeed# =0
image = 1
endif
`skidding left
if rightspeed# + leftspeed# >0
image = 22
endif
`skidding right
if rightspeed# + leftspeed# <0
image = 23
endif
`calculate skid
rightspeed#=rightspeed#-0.5
leftspeed#=leftspeed#+0.5
endif
endif
`renaming values
if leftspeed#>0 then leftspeed#=0
if rightspeed#<0 then rightspeed#=0
xpos=xpos+rightspeed#+leftspeed#
`-----------------------------E-N-D -MOVE GHOST--------------------------------
sync
loop