I have a collision map for my area, but i need a 2d version of INTERSECT OBJECT. I need this because as my i move the character down (gravity) he gets stuck in the floor.
Here is my code if it helps
Dim CollisionData(192,15)
Load Array "Maps\CollisionData.arr",CollisionData()
Dim MapData(192,15)
Load Array "Maps\MapData.arr",MapData()
`Get Image 100,0,0,192*16,15*16
Gravity# = 1
MaxSpeed = 5
p1x = 20
p1y = 20
Accel# = 0.3
Decel# = 0.7
LegStr = 15
Do
Paste Image 10000,0-BackdropOffset/2,0
For x = 1 to 192
For y = 1 to 15
If MapData(x,y) > 0
`Sprite Csprite,x*16,y*16,MapData(x,y)
Paste Image MapData(x,y),(x)*16-BackdropOffset,(y)*16
`Inc Csprite
Endif
Next y
Next x
If p1x => 160 and P1x <= 480
Inc P1x, Xspeed#
Endif
If P1x > 480 and Xspeed# > 0
Inc BackdropOffset, Xspeed#
Endif
If P1x > 480 and Xspeed# < 0
Inc P1x, Xspeed#
Endif
If p1x < 160 and Xspeed# > 0
Inc P1x, Xspeed#
Endif
If p1x < 160 and Xspeed# < 0
Inc BackdropOffset, Xspeed#
Endif
Sprite 999,p1x,p1y,999
If Rightkey() = 1
`inc p1x,Xspeed#
Facing = 2
`Play Sprite 999,5,6,100
Inc Xspeed#, Accel#
Endif
If Leftkey() = 1
`dec p1x,Xspeed#
Dec Xspeed#, Accel#
Facing = 1
`Play Sprite 999,1,2,100
Endif
If Rightkey() = 0 and Leftkey() = 0 and Xspeed# > Decel# and Xspeed# > 0
Dec Xspeed#, Decel#
Endif
If Rightkey() = 0 and Leftkey() = 0 and Xspeed# < -Decel# and Xspeed# < 0
Inc Xspeed#, Decel#
Endif
If Rightkey() = 0 and Leftkey() = 0 and Xspeed# < Decel# and Xspeed# > 0 then xSpeed# = 0
If Rightkey() = 0 and Leftkey() = 0 and Xspeed# > -Decel# and Xspeed# < 0 then xSpeed# = 0
If Xspeed# > Maxspeed then Xspeed# = MaxSpeed
If Xspeed# < -Maxspeed then Xspeed# = -MaxSpeed
If Spacekey() = 1` and CollisionData(int((p1x+1)/16+0.5), int((p1y+1)/16+1.5)) = 1
PushOff = LegStr
Else
PushOff = 0
Endif
If CollisionData(int((p1x+1)/16+0.5), int((p1y+1)/16+1.5)) = 0
Inc T
Endif
If CollisionData(int((p1x+1)/16+0.5), int((p1y+1)/16+1.5)) = 1
T = 0
Endif
If CollisionData(int((p1x-backdropoffset+1)/16+0.5), int((p1y+1)/16+1.5)) = 0
Inc p1y,Gravity#*T - Pushoff
Endif
Set Cursor 0,0
ink rgb(0,0,0),0
Print "Frame Rate:";SCREEN FPS()
Print "Plx:";p1x
Print "Ply:";p1y
Print "Backdrop Offset:";Backdropoffset
Print "Xspeed:";Xspeed#
Print "Maxspeed:";MaxSpeed
Print "Acceleration";Accel#
Print "Deacceleration:";Decel#
Print "Leg Strength:";Legstr
Print "Timer:";T
Print "Collision Data:";CollisionData(int((p1x+1)/16+0.5), int((p1y+1)/16+1.5))
`Sync
Loop
The collision data is a 2d array with 1 for solid and 0 for non-solid and the map data is a 2d array with the image number for each tile