1d tile map whats wrong?

Dubbsta

Active Member
Joined
Jul 13, 2017
i found what seems like a great tutorial on tile based games and collisions. and of course right at the start it all hits rock bottom:oops:. i followed it exact and seems simple but not working as expected. can anyone tell me why this is not working. i cant spot it

Code:
Class Map



Field x:float = 0

Field y:float = 0

Field size:Int = 40

Field cols:Int = 16

Field rows:Int = 9

Field tiles:Int[] = [1,0,1,0,1,0,1,0,1,0,1,0,1,
                           0,0,0,0,0,0,0,0,0,0,0,0,0,
                           1,0,0,0,0,0,0,0,0,0,0,0,1,
                           0,0,0,0,0,0,0,0,0,0,0,0,0,
                           1,0,0,0,0,0,0,0,0,0,0,0,1,
                           0,0,0,0,0,0,0,0,0,0,0,0,0,
                           1,0,1,0,1,0,1,0,1,0,1,0,1]



                     Method Draw:Int()

                          For Local i:Int = 0 Until tiles.Length()

                                  DrawRect((i Mod cols) * size,Floor(i/cols)*size,size,size)

                                        Select tiles[i]

                                               Case 0
                                                    SetColor 0,255,0
                                               Case 1
                                                    SetColor 0,0,255
                                         End

                          next
                           Return 0
                       End

End
 

York

New Member
Patreon Bronze
Joined
Jul 5, 2017
Location
Germany
You need to call SetColor before you draw the rect:

Code:
Select tiles[i]
                Case 0
                    SetColor 0, 255, 0
                Case 1
                    SetColor 0,0,255
            End
       
            DrawRect((i Mod cols) * size,Floor(i/cols)*size,size,size)
and if I see right you defined a field with 13 cols and 7 rows.

Code:
Field cols:Int = 13
    Field rows:Int = 7
Which tutorial are you following?
 
Top Bottom