Descolado Posted October 25, 2016 Share Posted October 25, 2016 In this code bellow (file ST3.BAS posted in other topic) the explosion uses WAIT to keep the animation in screen, but it "freeze" the screen and all mobs some seconds. How I create an animation explosion WITHOUT use "WAIT" (with no freeze the other mobs in screen). REM Explosion Boom:resetsprite(2)resetsprite(1)For t = 1 to 16 WAIT SPRITE 3, EX + VISIBLE + ZOOMX2, EY + ZOOMY4, SPR03 + SPR_RED MODE 0,T,0,0,0Next t resetsprite(3)#Score=#Score+50PRINT AT 227 COLOR CS_WHITE, <6>#Scoregoto Start Quote Link to comment Share on other sites More sharing options...
Kiwi Posted October 25, 2016 Share Posted October 25, 2016 You can try, if T<>0 then SPRITE 3, EX + VISIBLE + ZOOMX2, EY + ZOOMY4, SPR03 + SPR_RED MODE 0,T,0,0,0 T=T+1 if T=16 then T=0 end if Basically, when T is not 0 then then it'll do what in the if/end if bracket. One thing I don't know if MODE 0,T,0,0,0 will execute or be que'd until WAIT function is reached in the game loop. Whenever event requires explosion, just do T=1. Then the routine above will run along the game without freezing. 1 Quote Link to comment Share on other sites More sharing options...
Descolado Posted October 26, 2016 Author Share Posted October 26, 2016 You can try, if T<>0 then SPRITE 3, EX + VISIBLE + ZOOMX2, EY + ZOOMY4, SPR03 + SPR_RED MODE 0,T,0,0,0 T=T+1 if T=16 then T=0 end if Basically, when T is not 0 then then it'll do what in the if/end if bracket. One thing I don't know if MODE 0,T,0,0,0 will execute or be que'd until WAIT function is reached in the game loop. Whenever event requires explosion, just do T=1. Then the routine above will run along the game without freezing. Humm... Yes, it was how I imagined. You need set "flags" to control automatic movement and explosion sprites in Intybasic, because you need put your code in "loop". Is hard create PROCEDURES to move or explode sprites because you must use "global variables" and it is difficult to manage. Ok, thanks, let me continue my game! Quote Link to comment Share on other sites More sharing options...
+DZ-Jay Posted October 26, 2016 Share Posted October 26, 2016 Humm... Yes, it was how I imagined. You need set "flags" to control automatic movement and explosion sprites in Intybasic, because you need put your code in "loop". Is hard create PROCEDURES to move or explode sprites because you must use "global variables" and it is difficult to manage. Ok, thanks, let me continue my game! Well, the language doesn't support the automatic handling of sprite animations or movement. That means that you will have to do it from your code and manage those resources yourself, and a common way to do this is using a state machine. Moreover, being a procedural language and not an object-oriented one, there is no natural way to encapsulate the data structures for such machines, so you must use global variables. What I advocate is for people to think of their core game logic not as a sequential set of routines, but as a "cyclical engine" where conditions are tested, events are triggered, and the system (i.e., the logical game world) is updated. Each cycle may or may not correspond to an actual frame, though it is easier to consider when it does. If you think about it that way, then those "global variables" are not so much stray and scattered data in the global space, but the actual state of your game engine. dZ. 1 Quote Link to comment Share on other sites More sharing options...
+Tarzilla Posted October 26, 2016 Share Posted October 26, 2016 As DZJay says, think about things in terms of a master game loop. Set up a bunch of frame counters and state variables Use On Gosub to drastically reduce the If/Then cycles penalty PlayerAnimationCounter=0 ExplosionFrame=0 ExplosionFrameDelay=0 ExplosionActive=0 Playerx=100 Playery=30 GameLoop: Gosub CheckController Gosub MovePlayer Gosub MoveEnemies Gosub CheckCollisions Gosub UpdateAnimations Wait Goto GameLoop In the UpdateAnimations procedure, check if an explosion is active (set in CheckCollisions,) update ExplosionFrameDelay, update ExplosionFrame when the delay hits a certain value, reset the delay etc. A variable like ExplosionFrameDelay lets you easily change how long the the explosion lingers, ExplosionFrame lets you have cycle thru as many frames as you want. UpdateAnimations:Procedure If ExplosionActive=1 then ExplosionFrameDelay=ExplosionFrameDelay+1:If ExplosionFrameDelay>4 then ExplosionFrameDelay=0:ExplosionFrame=ExplosionFrame+1 On ExplosionFrame gosub ExplodeFrame0,ExplodeFrame1,ExplodeFrame2 End If End ExplodeFrame0:Procedure Define 60,1,ExplodeBitmap0 End ExplodeFrame1:Procedure Define 60,1,ExplodeBitmap1 End Oh, and don't use 1 or 2 character Variable names like Ex and Ey. IntyBASIC doesn't care, but you will when you code gets bigger IntyBASIC likes PlayerExplosionX/PlayerExplosionY just as much as Ex/Ey Even better, if you have to track several explosions, use arrays that correspond to enemy slots Lets say you have 4 possible enemies that can be shot Dim EnemyExplosionX(4) Dim EnemyExplosionY(4) Dim EnemyExplosionFrame(4) Dim EnemyExplosionFrameDelay(4) Dim EnemyExplosionActive(4) Now you can deal with all 4 in one loop, remembering that arrays start at 0 ExplodeFrame0:Procedure Define 60,1,ExplodeBitmap0 End 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.