rotating blocks?
BlitzMax Forums/BlitzMax Beginners Area/rotating blocks?
| ||
Hi. I need some help with my code. I'm trying to rotate block by changing their positions. here is my code. Check out the rotate function. Strict Graphics 1024,768,16,60 SetMaskColor 255,0,255 Global tiles:TImage = LoadAnimImage("fulltiles.png",32,32,0,16,MASKEDIMAGE) Global tilesX:Int = 300 Global tilesY:Int = 100 Global bricklist:TList = CreateList() Type brick Field TopLeftX Field TopLeftY Field TopRightX Field TopRightY Field BottomLeftX Field BottomLeftY Field BottomRightX Field BottomRightY Function tile_create() Local b:brick = New brick b.TopLeftX = 0 b.TopLeftY = 0 b.TopRightX = 32 b.TopRightY = 0 b.BottomLeftX = 0 b.BottomLeftY = 32 b.BottomRightX = 32 b.BottomRightY = 32 ListAddLast bricklist,(b) End Function Function draw_tiles() For Local b:brick = EachIn bricklist DrawImage tiles,tilesX+b.TopLeftX,TilesY+b.TopLeftY,0 DrawImage tiles,tilesX+b.TopRightX,tilesY+b.TopRightY,1 DrawImage tiles,tilesX+b.BottomLeftX,tilesY+b.BottomLeftY,2 DrawImage tiles,tilesX+b.BottomRightX,tilesY+b.BottomRightY,3 Next End Function Function rotate() If KeyHit(KEY_LEFT) For Local b:brick = EachIn bricklist b.TopLeftX = b.BottomLeftX b.TopLeftY = b.BottomLeftY b.TopRightX = b.TopLeftX b.TopRightY = b.TopLeftY b.BottomRightX = b.TopRightX b.BottomRightY = b.TopRightY b.BottomLeftx = b.BottomRightX b.BottomLeftY = b.BottomRightY Next End If End Function End Type brick.tile_create() While Not KeyHit(KEY_ESCAPE) Cls brick.draw_tiles() brick.rotate() Flip FlushMem Wend Use this image. ![]() |
| ||
Not sure whether you're doing it the best way. Can you create a 'frame' field to the type which matches the frame in the tiles.png? That way you can increment the frame to rotate. <edit> Just in case... Strict Graphics 1024,768,16,60 SetMaskColor 255,0,255 Global tiles:TImage = LoadAnimImage("fulltiles.png",32,32,0,4,MASKEDIMAGE) Type brick Global bricklist:TList Field x Field y Field frame Function tile_create(x,y,frame) If bricklist=Null bricklist=CreateList() Local b:brick = New brick b.x=x b.y=y b.frame=frame ListAddLast bricklist,b End Function Method draw_tiles() DrawImage tiles,x,y,frame End Method Method rotate(dir:Int) frame:+dir If frame>3 frame=0 If frame<0 frame=3 End Method End Type brick.tile_create(0,0,0) brick.tile_create(32,0,1) brick.tile_create(32,32,2) brick.tile_create(0,32,3) DebugLog CountList(brick.bricklist) While Not KeyHit(KEY_ESCAPE) Cls For Local b:brick = EachIn brick.bricklist b.draw_tiles() Next If KeyHit(key_right) For Local b:brick = EachIn brick.bricklist b.rotate(-1) Next EndIf If KeyHit(key_left) For Local b:brick = EachIn brick.bricklist b.rotate(+1) Next EndIf Flip FlushMem Wend |