Hey all, having an issue with collision. I'm using arrays to store all tile information. This is the code for my program.
My problem is that the collision is not working. It seems to either not detect the collision, or make a solid line just above the character not allowing movement upwards, even if the collision layer returns a value of 0 instead of 1. The collision is only being checked currently for movement upwards. Does anyone have any idea as to why this is not working out properly? Thanks
Sync ON
Set Display Mode 640,480,32 `20x15 tiles
`Set Display Mode 800,600,32 `25x18.75 tiles
`Set Display Mode 1024,768,32 `32x24 tiles
Set Image ColorKey 255, 0, 255
`----------------------------------------------------------------------------------------------------------------------------
REM Miscellaneous Globals
`----------------------------------------------------------------------------------------------------------------------------
Layers = 5
Global SNum# : SNum# = 1
Global time# : Time# = 1
`----------------------------------------------------------------------------------------------------------------------------
REM Tile Sizes
`----------------------------------------------------------------------------------------------------------------------------
Global CharWidth : CharWidth = 64
Global CharLength : CharLength = 80
Global BaseTileLength : BaseTileLength = 32
Global BaseTileWidth : BaseTileWidth = 32
`----------------------------------------------------------------------------------------------------------------------------
REM STANDARD TILE SET
`----------------------------------------------------------------------------------------------------------------------------
Load Bitmap "32x32Dungeon1d.bmp",10 `This may be used for the items and weapons
Load Bitmap "Kadall02.bmp",2
`----------------------------------------------------------------------------------------------------------------------------
REM Level Tiles
`----------------------------------------------------------------------------------------------------------------------------
dim World(1000,1000,3) `Creates a world with 20x15 blocks and 3 layers,(one screen size) blocks will be MUCH bigger on the overworld like in the 10,000's or more
dim Dungeon(19,14,3) `Creates a world with 20x15 blocks and 3 layers,(one screen size) blocks will be MUCH bigger on the overworld like in the 10,000's or more
dim Tavern(29,20,3)
`----------------------------------------------------------------------------------------------------------------------------
REM Character Tiles
`----------------------------------------------------------------------------------------------------------------------------
Set Current Bitmap 2
get image 1,0,80,64,160
get Image 2,64,80,128,160
get Image 3,128,80,192,160
get Image 4,192,80,256,160
get image 5,256,80,320,160
get Image 6,320,80,384,160
get Image 7,384,80,448,160
get Image 8,448,80,512,160
get image 9,0,160,64,240
get Image 10,64,160,128,240
get Image 11,128,160,192,240
get Image 12,192,160,256,240
get image 13,256,160,320,240
get Image 14,320,160,384,240
get Image 15,384,160,448,240
get Image 16,448,160,512,240
Set Current Bitmap 10
get image 500,0,0,32,32
get Image 501,32,0,64,32
get Image 502,64,0,96,32
get image 503,0,32,32,64
get Image 504,32,32,64,64
get Image 505,64,32,96,64
get image 506,0,64,32,96
get Image 507,32,64,64,96
get Image 508,64,64,96,96
get image 509,0,96,32,128
get Image 510,32,96,64,128
get Image 511,64,96,96,128
get image 512,0,128,32,160
get Image 513,32,128,64,160
get Image 514,64,128,96,160
get image 515,0,160,32,192
get Image 516,32,160,64,192
get Image 517,64,160,96,192
get image 518,0,192,32,224
get Image 519,32,192,64,224
get Image 520,64,192,96,224
Delete Bitmap 10
Delete Bitmap 2
sprite 1,0,0,1
sprite 2,0,0,2
sprite 3,0,0,3
sprite 4,0,0,4
sprite 5,0,0,5
sprite 6,0,0,6
sprite 7,0,0,7
sprite 8,0,0,8
sprite 9,0,0,9
sprite 10,0,0,10
sprite 11,0,0,11
sprite 12,0,0,12
sprite 13,0,0,13
sprite 14,0,0,14
sprite 15,0,0,15
sprite 16,0,0,16
`----------------------------------------------------------------------------------------------------------------------------
REM Weapon/Item Tiles
`----------------------------------------------------------------------------------------------------------------------------
`----------------------------------------------------------------------------------------------------------------------------
REM Main Loop
`----------------------------------------------------------------------------------------------------------------------------
MoveTimerSet# = 1000/10
MoveTimer# = Timer()
restore layer0
for indexY=0 to 14
for indexX=0 to 19
read maintile
Dungeon(indexX,indexY,0)=maintile
next indexY
next indexX
restore layer1
for indexY=0 to 14
for indexX=0 to 19
read MainLayer
Dungeon(indexX,indexY,1)=MainLayer
next indexX
Next Layer
restore layer2
for indexY=0 to 14
for indexX=0 to 19
read Overhead
Dungeon(indexX,indexY,2)=Overhead
next indexX
Next Layer
restore layer3
for indexY=0 to 14
for indexX=0 to 19
read Collision
Dungeon(indexX,indexY,3)=Collision
next indexX
Next Layer
X# = 0
Y# = 0
do
cls 0
if upkey()=1
y#=y#-1 : SAdd# = 12`SNum# will be between 1 and 4
for indexY=0 to 14
for indexX=0 to 19
Layer = 3
if Dungeon(indexX,indexY,Layer)=1 and Sprite Y(SNum# + SAdd#) = IndexY*32 + y#
y# = y# + 1
endif
next index
next indexY
endif
for indexY=0 to 14
for indexX=0 to 19
For Layer = 0 to 1
if Dungeon(indexX,indexY,Layer)>0
paste image Dungeon(indexX,indexY,Layer),indexX*32 - x#,indexY*32 - y#,1
endif
next Layer
next indexX
next indexY
Paste Sprite SNum# + SAdd#,128,126 `can also be x#, y# if needed
for indexY=0 to 14
for indexX=0 to 19
Layer = 2
if Dungeon(indexX,indexY,Layer)>0
sprite Clone,indexX*32,indexY*32
paste image Dungeon(indexX,indexY,Layer),indexX*32 - x#,indexY*32 - y#,1
endif
next indexX
next indexY
text 0,0,"FPS: "+str$(screen fps())
if leftkey()=1 then x#=x#-1 : SAdd# = 0`SNum# will be between 5 and 8
if rightkey()=1 then x#=x#+1 : SAdd# = 4`SNum# will be between 9 and 12
if downkey()=1 then y#=y#+1 : SAdd# = 8`SNum# will be between 13 and 16
Inc Time#
If Time# > 20 then Time# = 0
If Time# = 20 and upkey() = 1 or Time# = 20 and downkey() = 1 or Time# = 20 and leftkey() = 1 or Time# = 20 and rightkey() = 1
Inc SNum#, 1
If SNum# > 4 then SNum# = 1
endif
Inc LayerTime
If LayerTime > 1 then LayerTime = 0
sync
loop
Layer0:
`Layer 0
data 519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519
data 519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519
data 519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519
data 519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519
data 519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519
data 519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519
data 519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519
data 519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519
data 519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519
data 519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519
data 519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519
data 519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519
data 519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519
data 519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519
data 519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519
Layer1:
`Layer 1 COLLISION LAYER
Data 507,507,507,507,507,507,507,508,0,0,503,504,504,504,504,504,504,504,504,504
Data 510,510,510,510,510,510,510,511,0,0,503,504,504,504,504,504,504,504,504,504
Data 513,513,513,513,513,513,513,514,0,0,506,507,507,507,507,507,507,504,504,504
Data 516,516,516,516,516,516,516,517,0,0,509,510,510,510,510,510,510,503,504,504
Data 0,0,0,0,0,0,0,0,0,0,512,513,513,513,513,513,513,503,504,504
Data 0,0,0,0,0,0,0,0,0,0,515,516,516,516,516,516,516,503,504,504
Data 0,0,0,500,501,501,501,502,0,0,0,0,0,0,0,0,0,503,504,504
Data 0,0,0,503,504,504,504,505,0,0,0,0,0,0,0,0,0,503,504,504
Data 502,0,0,503,504,504,504,505,0,0,0,0,0,0,0,0,0,503,504,504
Data 505,0,0,506,507,507,507,508,0,0,0,0,0,0,0,0,0,503,504,504
Data 505,0,0,509,510,510,510,511,0,0,0,0,0,0,0,0,0,503,504,504
Data 505,0,0,512,513,513,513,514,0,0,0,0,0,0,0,0,0,503,504,504
Data 505,0,0,515,516,516,516,517,0,0,0,0,0,0,0,0,0,503,504,504
Data 505,0,0,0,0,0,0,0,0,0,0,500,501,501,501,501,501,504,504,504
Data 504,501,501,501,501,501,501,502,0,0,0,503,504,504,504,504,504,504,504,504
Layer2:
`Layer 2 Overhead Layer
Data 0,0,0,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,0,0,0
Data 0,0,0,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,0,0,0
Data 0,0,0,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,0,0,0
Data 0,0,0,500,501,501,501,502,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,503,504,504,504,505,0,0,0,0,0,0,0,0,0,0,0,0
Data 502,0,0,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,0,0,0
Data 0,0,0,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,0,0,0
Data 0,0,0,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,500,501,501,501,501,501,0,0,0
Data 0,501,501,501,501,501,501,502,0,0,0,503,504,504,504,504,504,0,0,0
Layer3:
`Layer 3 Collision Layer
Data 1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1
Data 0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1
Data 0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1
Data 0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1
Data 0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1
Data 1,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1
Data 1,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1
Data 1,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1
Data 1,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1
Data 1,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1
Data 1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1