re:rotating square simple coding
BlitzMax Forums/BlitzMax Beginners Area/re:rotating square simple coding
| ||
Thanks to jesse for my previous post. Heres something a bit similar but a lot simple. I need some help with this please. Ok ive got a square rotating on the screen. There are a total of 8 squares. I have 8 animimages but they are all the same image as the image of the squares are all the same. Its like the back of a tile!!! what i want to happen is this: I want to rotate the first square which is on the screen The below code is rotating the 8 squares which is good but after I have rotated the first square a certain number of times i need to go onto the next square. This is like it randomly turning the backs of the board tiles. Im not bothered at the moment about arrays or positions of the squares as the back image is the same for all squares. I just want to create an illusion that the squares are turning at different times rather than them all turning exactly the same. What i was thinking is i want a for next loop that randomly picks a number from 1 to 10 (to decide the number of turns for each square) and then once it has turned the random number of turns for the first square to then start rotating the next square a random number of turns. Once all 8 squares are turned i want to exit the program. The trouble is these functions are in a while loop and it doesnt exit the loop until escape is pressed. Is there any way of randonly turning my square a random number of turns and then to start turning the next square a random number of turns and so on and so on until it reaches the 8th square and after it has turned a random number of turns to exit the program. I think I will need some sort of frame delay as well so you can actually see what is happening. Thankyou very much for your help. Kind Regards Joe Heres my code: SetGraphicsDriver GLMax2DDriver() Graphics 1920,1080 Global tilebackanim:TImage=LoadAnimImage("d:\DungeonTwister\ART\Board\tilebackanim.bmp",255,255,0,2) Global tilebackanim2:TImage=LoadAnimImage("d:\DungeonTwister\ART\Board\tilebackanim.bmp",255,255,0,2) Global tilebackanim3:TImage=LoadAnimImage("d:\DungeonTwister\ART\Board\tilebackanim.bmp",255,255,0,2) Global tilebackanim4:TImage=LoadAnimImage("d:\DungeonTwister\ART\Board\tilebackanim.bmp",255,255,0,2) Global tilebackanim5:TImage=LoadAnimImage("d:\DungeonTwister\ART\Board\tilebackanim.bmp",255,255,0,2) Global tilebackanim6:TImage=LoadAnimImage("d:\DungeonTwister\ART\Board\tilebackanim.bmp",255,255,0,2) Global tilebackanim7:TImage=LoadAnimImage("d:\DungeonTwister\ART\Board\tilebackanim.bmp",255,255,0,2) Global tilebackanim8:TImage=LoadAnimImage("d:\DungeonTwister\ART\Board\tilebackanim.bmp",255,255,0,2) Global tilebackanimx=450 Global tilebackanimy=150 Global frame=0 Global maxframes=2 Global frametimer Global framedelay=400 While Not KeyDown(KEY_ESCAPE) SetClsColor 0,0,0 Cls SetColor 255,203,75 'put functions here Setup_RandomizeBoard() Flip Wend End Function Setup_RandomizeBoard() DrawText "Randomizing Board - Please Wait ........................",690,700 DrawImage tilebackanim,tilebackanimx,tilebackanimy,frame DrawImage tilebackanim2,tilebackanimx+255,tilebackanimy,frame DrawImage tilebackanim3,tilebackanimx+510,tilebackanimy,frame DrawImage tilebackanim4,tilebackanimx+765,tilebackanimy,frame DrawImage tilebackanim5,tilebackanimx,tilebackanimy+255,frame DrawImage tilebackanim6,tilebackanimx+255,tilebackanimy+255,frame DrawImage tilebackanim7,tilebackanimx+510,tilebackanimy+255,frame DrawImage tilebackanim8,tilebackanimx+765,tilebackanimy+255,frame If MilliSecs() > frametimer frametimer = MilliSecs()+framedelay frame=frame+1 If frame =>maxframes Then frame=0 EndIf EndIf 'WaitKey 'WaitKey EndFunction Last edited 2011 Last edited 2011 |
| ||
Hiya, As this sounds like some kind of school work, I'll post pseudo code for you and leave you to fill in where you need to. Sticking to your spec above - something along the lines the code below will get the job done. I would never do it this way for a real game ( hence my ref to school work ), so I leave it to you to work out how to put it into a 'game usable format'... Global NumOfTiles = 8 Global TileAnim:TImage[NumOfTiles] 'Load anim images For local iTile = 0 until NumOfTiles TileAnim[ iTile ] = LoadAnimImage(............) Next For Local iTile = 0 until NumTiles Local NumTurns = Rnd(1,10) For Local iTurns = 0 until iNumTurns 'increase timer for an image frame counter here DrawImage( TileAnim[ iTile ], x,y,image frame counter) Flip Next Next End |