tile collision

BlitzPlus Forums/BlitzPlus Programming/tile collision

DI(Posted 2013) [#1]
hello!

trying to add collision to the top of my tiles but it isn't working!
http://pastebin.com/HnPq3ctp
it isn't much code and I made some comments in the code so it is easy to read and understand.

thanks for any help!

Last edited 2013


misth(Posted 2013) [#2]
First off; you only draw your map once when readInfo is 1, after you've read the data into your array. That's not good... You should read your data into the array before the main loop even starts (for example right after you have declared your data).

Secondly; your collision checks are inside the map drawing. Since the drawing is only happening once, so is the collision checks too. You should definitely separate updating and rendering - it really keeps the code more open for new code and clear for searching code.

Maybe use this kind of "framework":
; Declare your Data here
; Data 0,0,0,0..... etc.

; Read your map data after it
; Dim mapData(10,10) : Read Data blah blah

While Not KeyDown(1)

    Update()
    Render()
      
wend

function Update()
    ; Do your updates here (player movement, keyhits, collisions etc.)
    
    UpdatePlayer()
    UpdateCollisions()
    
end function

function Render()
    cls
    
    ; Now here you draw your graphics to the screen
    DrawPlayer()
    DrawMap()
    
    flip
end function

function UpdatePlayer()
    ; Update player movement here
end function

function UpdateCollisions()
    ; Update collisions here
end function

function DrawPlayer()
    ; Draw player and player related stuff here
end function

function DrawMap()
    ; Draw your map here
end function


Hope this helps! :)


DI(Posted 2013) [#3]
Thank you so much for the answer and help, misth! I really appreciate it!

Here's the code so far: http://pastebin.com/SPpd67Vj
Anything I should notice or anything I'm doing wrong?


misth(Posted 2013) [#4]
No problem!

And no, I didn't see anything weird or wrong in that code. :)

Although, you could use labels for your datas. That way, you can have more maps!

Dim myMapArray( 10, 10 ) ; Create an array for our map

Restore	myMapData1 ; "Selects" the myMapData1 for reading

; Read the data to array
For y = 1 To 10
	For x = 1 To 10
		Read myMapArray(x, y)
	Next
Next

; Map #1
.myMapData1
Data 1,1,1,1,1,1,1,1,1,1
Data 1,0,0,0,0,0,0,0,0,1
Data 1,0,1,1,1,1,1,1,1,1
Data 1,0,0,0,0,0,0,0,0,1
Data 1,1,1,1,1,1,1,1,0,1
Data 1,0,0,0,0,0,0,0,0,1
Data 1,0,1,1,1,1,1,1,1,1
Data 1,0,0,0,0,0,0,0,0,1
Data 1,1,1,1,1,1,1,1,0,1
Data 1,0,0,0,0,0,0,0,0,1
Data 1,1,1,1,1,1,1,1,1,1

; Map #2
.myMapData2 ; reversed from map 1
Data 1,1,1,1,1,1,1,1,1,1
Data 1,0,0,0,0,0,0,0,0,1
Data 1,1,1,1,1,1,1,1,0,1
Data 1,0,0,0,0,0,0,0,0,1
Data 1,0,1,1,1,1,1,1,1,1
Data 1,0,0,0,0,0,0,0,0,1
Data 1,1,1,1,1,1,1,1,0,1
Data 1,0,0,0,0,0,0,0,0,1
Data 1,0,1,1,1,1,1,1,1,1
Data 1,0,0,0,0,0,0,0,0,1
Data 1,1,1,1,1,1,1,1,1,1



Hope this helps again! :)

Cheers.


XR069(Posted 2013) [#5]
Well, I have a much better method for tiles.
I've added collision.

Default map: REX-0

DL LINK: http://www.mediafire.com/?kzd2swb2rxuj2wi


DI(Posted 2013) [#6]
XR069, your collison is really good but that wasn't what I wanted. I'm trying to make a simple platformer with gravity but my collision isn't working. Thanks anyway!


indietom(Posted 2013) [#7]
Death Run has the one of the best to do lists I've ever read.