In my puzzle game a tile is selected according to what image the arrow has collided with. The problem is the arrow collides with 2 tiles and causes an eroor. In blitz3d or BlitzPlus I would use ImagesRect Collide to test for the collision using a 1*1 pixel rect.
Is there anything like this in blitzMax or is anything planned for it to be added. Also, Just in case its my code I'll post it here for you to see.
The function Below changes the current tile. I've commented out the problem code.
The Function below places all the tiles on screen and assigns a number to curtile. ex: t.id = curtiletype
Below is the code for the whole game:
Is there anything like this in blitzMax or is anything planned for it to be added. Also, Just in case its my code I'll post it here for you to see.
The function Below changes the current tile. I've commented out the problem code.
Function change_curtile() ' For Local t:tile = EachIn tilelist ' If ImagesCollide(curser2,mx2,my2,0,tiles,t.xpos,t.xpos,t.id) And MouseHit(KEY_MOUSELEFT) ' curtile = t.id ' EndIf ' Next If KeyHit(KEY_OPENBRACKET) curtile:-1 ElseIf KeyHit(KEY_CLOSEBRACKET) curtile:+1 EndIf If curtile > 20 Then curtile = 0 If curtile < 0 Then curtile = 20 End Function
The Function below places all the tiles on screen and assigns a number to curtile. ex: t.id = curtiletype
Function settileset() If ty < 640 tx = 896 ty = 128 curtiletype = 0 For Local x:Int = 0 To 7 Local t:tile = New tile t.xpos = tx t.ypos = ty t.id = curtiletype ListAddLast tilelist,(t) curtiletype:+1 ty:+64 Next EndIf If ty >= 640 tx = 192 ty = 673 curtiletype = 8 For Local x2:Int = 0 To 11 Local t:tile = New tile t.xpos = tx t.ypos = ty t.id = curtiletype ListAddLast tilelist,(t) curtiletype:+1 tx:+64 Next EndIf End Function
Below is the code for the whole game:
Strict Framework BRL.Blitz Import BRL.glmax2d Import brl.max2d Import brl.pngloader Import brl.oggloader Import brl.math Import brl.ramstream Incbin "gfx/background1.png" Incbin "gfx/tiles.png" Incbin "gfx/curser.png" Incbin "gfx/curser2.png" Graphics 1024,768,16,60 SetMaskColor 255,0,255 Global tiles:TImage = LoadAnimImage("incbin::gfx/tiles.png",64,64,0,22,MASKEDIMAGE) Global backg:TImage = LoadImage("incbin::gfx/background1.png",MASKEDIMAGE) SetMaskColor 0,0,0 Global curser:TImage = LoadImage("incbin::gfx/curser.png",MASKEDIMAGE) Global curser2:TImage = LoadImage("incbin::gfx/curser2.png",MASKEDIMAGE) SetMaskColor 255,0,255 Global gamemode:Int=1'Tests wether in gamemode or intro mode. Global mapx:Int=10 Global mapy:Int=8 Global map:Int[mapx,mapy] Global Xoff:Int = 192 Global Yoff:Int = 128 Global curtile = 0 Global curtiletype:Int = 0 Global tx:Int, ty:Int Global mx:Int,my:Int,mx2:Int,my2:Int' mouse coords for inside and out of map area Global tilelist:TList = CreateList() Type tile Field xpos:Int Field ypos:Int Field id:Int End Type HideMouse() Repeat Cls If gamemode = 0 WaitKey End ElseIf gamemode = 1 factory() EndIf FlushMem Flip Until KeyHit(KEY_ESCAPE) Function factory() init_map() settileset() Repeat Cls mx = MouseX()/64*64 my = MouseY()/64*64 mx2 = MouseX() my2 = MouseY() If KeyHit(KEY_ESCAPE) gamemode = 0 Return EndIf DrawImage backg,0,0,0 update_map() draw_tileset() placetile() change_curtile() draw_curser() FlushMem Flip Forever End Function Function init_map() For Local x:Int = 0 To mapx-1 For Local y:Int = 0 To mapy-1 map[x,y] = 21 Next Next End Function Function update_map() For Local x:Int = 0 To mapx-1 For Local y:Int = 0 To mapy-1 DrawImage tiles,Xoff+x*64,Yoff+y*64,map[x,y] Next Next End Function Function settileset() If ty < 640 tx = 896 ty = 128 curtiletype = 0 For Local x:Int = 0 To 7 Local t:tile = New tile t.xpos = tx t.ypos = ty t.id = curtiletype ListAddLast tilelist,(t) curtiletype:+1 ty:+64 Next EndIf If ty >= 640 tx = 192 ty = 673 curtiletype = 8 For Local x2:Int = 0 To 11 Local t:tile = New tile t.xpos = tx t.ypos = ty t.id = curtiletype ListAddLast tilelist,(t) curtiletype:+1 tx:+64 Next EndIf End Function Function draw_tileset() For Local t:tile = EachIn tilelist DrawImage tiles,t.xpos,t.ypos,t.id Next DrawImage tiles,895,25,20 DrawImage tiles,25,25,curtile End Function Function draw_curser() If MouseX()>= Xoff And MouseX() <= 835 And MouseY() >= Yoff And MouseY() <= 640 DrawImage curser,mx,my,0 EndIf 'If MouseX() <=Xoff And MouseX() >= 835 And MouseY() <= Yoff And MouseY() >= 640 DrawImage curser2,mx2,my2,0 'EndIf End Function Function change_curtile() ' For Local t:tile = EachIn tilelist ' If ImagesCollide(curser2,mx2,my2,0,tiles,t.xpos,t.xpos,t.id) And MouseHit(KEY_MOUSELEFT) ' curtile = t.id ' EndIf ' Next If KeyHit(KEY_OPENBRACKET) curtile:-1 ElseIf KeyHit(KEY_CLOSEBRACKET) curtile:+1 EndIf If curtile > 20 Then curtile = 0 If curtile < 0 Then curtile = 20 End Function Function placetile() If KeyDown(KEY_MOUSELEFT) And MouseX() >= Xoff And MouseX() <= 800 And MouseY() >= Yoff And MouseY() <= 620 map[(MouseX()-Xoff) / 64,(MouseY()-Yoff) /64] = curtile EndIf If KeyDown(KEY_MOUSERIGHT) And MouseX() >= Xoff And MouseX() <= 800 And MouseY() >= Yoff And MouseY() <= 620 map[(MouseX()-Xoff) / 64,(MouseY()-Yoff) /64] = 21 EndIf End Function