Henrik, thanks for the example, i still varies from my code alot though. here is my coding so far:
AppTitle "Mega Bomberman Clone v0.0 - Test 1","Do you wish to return to your desktop?"
Graphics 640,510,32,2
SetBuffer BackBuffer()
Global Tiles
Dim Map(16,16)
Load_Map()
While Not KeyHit(1)
Cls
Update()
Flip
Wend
End
Function Load_Map()
Restore Map
For y=000 To 16
For x=000 To 16
Read Map(x,y)
Next
Next
tiles =LoadAnimImage("TileMap.png",29,29,0,13)
End Function
Function Update()
For y= 000 To 16
For x= 000 To 16
DrawImage tiles,x*30,y*30,map(x,y)
Next
Next
End Function
.map
Data 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4
Data 4,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,4
Data 4,12,0,12,0,12,0,12,0,12,0,12,0,12,0,12,4
Data 4,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,4
Data 4,12,0,12,0,12,0,12,0,12,0,12,0,12,0,12,4
Data 4,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,4
Data 4,12,0,12,0,12,0,12,0,12,0,12,0,12,0,12,4
Data 4,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,4
Data 4,12,0,12,0,12,0,12,0,12,0,12,0,12,0,12,4
Data 4,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,4
Data 4,12,0,12,0,12,0,12,0,12,0,12,0,12,0,12,4
Data 4,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,4
Data 4,12,0,12,0,12,0,12,0,12,0,12,0,12,0,12,4
Data 4,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,4
Data 4,12,0,12,0,12,0,12,0,12,0,12,0,12,0,12,4
Data 4,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,4
Data 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4
Dunno how collision fits into this sort of thing.
hope somebody can help.
Maybe you can use this
Bye Henrik
AppTitle "Mega Bomberman Clone v0.0 - Test 1","Do you wish to return to your desktop?"
Graphics 640,510,32,2
SetBuffer BackBuffer()
Global Tiles
Dim Map(16,16)
Load_Map()
While Not KeyHit(1)
Cls
Update()
collisiontest()
Flip
Wend
End
Function collisiontest()
testnumber=4;or 12 or 0 or whatever tile you would like to test!!!
If MouseX()<30*17 And MouseY()<30*17 Then;don´t test if your mouse is outside your mapsize (30*17)
Color 200,0,0
Text 220,200,"Move your mouse"
Line MouseX(),MouseY()-10,MouseX(),MouseY()+10
Line MouseX()-10,MouseY(),MouseX()+10,MouseY()
If Map(MouseX()/30,MouseY()/30)=testnumber Text 180,240," Collision with tile nr:"+testnumber
EndIf
End Function
Function Load_Map()
Restore Map
For y=000 To 16
For x=000 To 16
Read Map(x,y)
Next
Next
tiles =LoadAnimImage("TileMap.png",29,29,0,13)
End Function
Function Update()
For y= 000 To 16
For x= 000 To 16
DrawImage tiles,x*30,y*30,map(x,y)
Next
Next
End Function
.map
Data 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4
Data 4,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,4
Data 4,12,0,12,0,12,0,12,0,12,0,12,0,12,0,12,4
Data 4,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,4
Data 4,12,0,12,0,12,0,12,0,12,0,12,0,12,0,12,4
Data 4,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,4
Data 4,12,0,12,0,12,0,12,0,12,0,12,0,12,0,12,4
Data 4,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,4
Data 4,12,0,12,0,12,0,12,0,12,0,12,0,12,0,12,4
Data 4,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,4
Data 4,12,0,12,0,12,0,12,0,12,0,12,0,12,0,12,4
Data 4,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,4
Data 4,12,0,12,0,12,0,12,0,12,0,12,0,12,0,12,4
Data 4,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,4
Data 4,12,0,12,0,12,0,12,0,12,0,12,0,12,0,12,4
Data 4,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,4
Data 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4
Ok, i thought i wouldn't be back for a while, well, i tried to apply collision so the mouse stoped when it hit a tile but doesn't work can someone tell me what i am doing wrong. i suck at 2d programing.
Here is my code:
AppTitle "Mega Bomberman Clone v0.0 - Test 1","Do you wish to return to your desktop?"
Graphics 640,510,32,2
SetBuffer BackBuffer()
Global Tiles
Dim Map(16,16)
Load_Map()
While Not KeyHit(1)
Cls
Update()
collisiontest()
Flip
Wend
End
Function collisiontest()
OldX=MouseX()
Oldy=MouseY()
testnumber=0;or 12 or 0 or whatever tile you would like to test!!!
If MouseX()<30*17 And MouseY()<30*17 Then;don´t test if your mouse is outside your mapsize (30*17)
Color 200,0,0
Text 220,200,"Move your mouse"
Line MouseX(),MouseY()-10,MouseX(),MouseY()+10
Line MouseX()-10,MouseY(),MouseX()+10,MouseY()
If Map(MouseX()/30,MouseY()/30)=testnumber Text 180,240," Collision with tile nr:"+testnumber
If RectsOverlap(MouseX()-10,MouseY()-10,MouseX()+10,MouseY()+10,Map(x,y)=0,Map(x,y)=0,Map(x,y)=29,Map(x,y)=29) Then
MouseX=OldX
MouseY=OldY
EndIf
EndIf
End Function
Function Load_Map()
Restore Map
For y=000 To 16
For x=000 To 16
Read Map(x,y)
Next
Next
tiles =LoadAnimImage("TileMap.png",29,29,0,13)
End Function
Function Update()
For y= 000 To 16
For x= 000 To 16
DrawImage tiles,x*30,y*30,map(x,y)
Next
Next
End Function
.map
Data 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4
Data 4,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,4
Data 4,12,0,12,0,12,0,12,0,12,0,12,0,12,0,12,4
Data 4,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,4
Data 4,12,0,12,0,12,0,12,0,12,0,12,0,12,0,12,4
Data 4,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,4
Data 4,12,0,12,0,12,0,12,0,12,0,12,0,12,0,12,4
Data 4,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,4
Data 4,12,0,12,0,12,0,12,0,12,0,12,0,12,0,12,4
Data 4,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,4
Data 4,12,0,12,0,12,0,12,0,12,0,12,0,12,0,12,4
Data 4,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,4
Data 4,12,0,12,0,12,0,12,0,12,0,12,0,12,0,12,4
Data 4,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,4
Data 4,12,0,12,0,12,0,12,0,12,0,12,0,12,0,12,4
Data 4,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,4
Data 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4
Hi
I found another great example of tile collision/slideing
on my harddisk i think you can use.
It is made by "Norc" (i think he use another nickname now)
Bye
Henrik
;Demonstration of very simple Non-Image-Collision-based "Wall-Detection"
Graphics 640,480,16;,2
nux#=0
oldx#=0
oldy#=0
x#=100
y#=100
a#=0
Dim tiles(15,15) ; Read the Wall information
For j=0 To 15
For i=0 To 15
Read tiles(i,j)
Next
Next
; MAINLOOP
While KeyHit(1)=0
Cls
For j=0 To 15 ; draw all walls for test purposes
For i=0 To 15 ; use your favorite Picture instead
If tiles(i,j)=1 Then
Color 120,120,120
Rect i*40,j*30,40,30,0
EndIf
Next
Next
oldx=x ; remember old player pos
oldy=y
; Keys
If KeyDown(200)=1 ; fwd
x=x+Sin(a)
y=y+Cos(a)
EndIf
If KeyDown(208)=1 ; back
x=x-Sin(a)
y=y-Cos(a)
EndIf
If KeyDown(203)=1 ; Player angle <
a=a+2
If a> 360 Then a=a-360
EndIf
If KeyDown(205)=1 ; Player angle >
a=a-2
If a< 0 Then a=a+360
EndIf
; dont allow walking tru walls, but allow sliding along
If tiles(((x-20)/40),((y-15)/30))=1 Then ; try new x, new y
nux#=x ; remeber nu x
x=oldx ; reset x to old x
EndIf
If tiles(((x-20)/40),((y-15)/30))=1 Then ; try old x, new y
x=nux#
y=oldy
EndIf
If tiles(((x-20)/40),((y-15)/30))=1 Then ; try new x, old y
x=oldx ; no, no chance, reset x and y both to old pos
y=oldy
EndIf
Color 255,0,0 ; Show a graphical Player
Oval x-5,y-5,10,10,1
Color 255,255,255
; show also wich direction Player is facing
Line x+Sin(a)*10,y+Cos(a)*10,x-Sin(a)*10,y-Cos(a)*10
Flip
Wend
End
; Walls = "1", Air = "0"
; you can also use bigger levels - just keep
; the relation (ie. 640/16=40) to check the Collision
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1
Data 1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1
Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
Data 1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1
Data 1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1
Data 1,1,0,1,1,1,1,1,0,1,1,1,1,0,1,1
Data 1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1
Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
Data 1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1
Data 1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1
Data 1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1
Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
Data 1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1
Data 1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1