and now.... my "proposed" solution code...
Please note, this can be severely optimised, by creating single sub-routines which perform shared tasks for animation 1 and 2, but I'm not going to go into that at this point, as I dont want to overly complicate things! As a result there is some "duplication" withing my code.
Basically, my code assumes that each explosion animation has three variables, it's Frame Number (where if Frame = 0 then we say that the animation is "not playing") and also an X and Y coordinate each.
It also will not allow you to trigger an animation if it is already playing.
LOOP START
- POSITION Mouse Cursor
- DRAW Mouse Cursor
- READ Mouse Buttons
// At this point, we will check if we are needing to "create" an explosion animation
// Is LMB pressed AND Animation 1 Frame=0 ?
-- IF BOTH TRUE THEN
- - Animation 1 Frame=1
- - Animation 1 Postion X = Mouse Cursor X
- - Animation 1 Postion Y = Mouse Cursor Y
-- ENDIF
// Is RMB pressed AND Animation 2 Count=0 ?
-- IF BOTH TRUE THEN
- - Animation 2 Frame=1
- - Animation 2 Postion X = Mouse Cursor X
- - Animation 2 Postion Y = Mouse Cursor Y
-- ENDIF
// Update any running Animations
// Check if we need to "switch off" the animation, because it has drawn the last frame
-- IF Animation 1 Frame > 4
- - REMOVE Explosion Animation 1
- - Animation 1 Frame = 0
-- ENDIF
// Otherwise, draw the animation frame, and increase the counter by 1
-- IF Animation 1 Frame > 0
- - AT Animation 1 X, Animation 1 Y
- - DRAW Explosion Animation 1 Frame
- - Animation 1 Frame = Frame + 1
-- ENDIF
// repeat for animation 2
-- IF Animation 2 Frame > 4
- - REMOVE Explosion Animation 1
- - Animation 2 Frame = 0
-- ENDIF
-- IF Animation 2 Frame > 0
- - AT Animation 2 X, Animation 1 Y
- - DRAW Explosion Animation 2 Frame
- - Animation 2 Frame = Frame + 1
-- ENDIF
LOOP END
I really hope you are still with me on what this is doing!!
What I will do now, is a simialr example to previously, to show what this code would do if it was running.
I am going to assume that we click the LMB on cycle 2 and that we click the RMB half-way through the first explosion animation... which will give us two explosions at the same time!!
in the square brackets [ ] after each variable, i've put in the "value" of that variable at that point of the code...
LOOP CYCLE 1
- POSITION Mouse Cursor
- DRAW Mouse Cursor
- READ Mouse Buttons
// Is LMB pressed AND Animation 1 Frame=0 ?
-- IF BOTH TRUE
-- NO
// although Frame = 0, LMB is not Clicked
// Is RMB pressed AND Animation 1 Frame=0 ?
-- IF BOTH TRUE
-- NO
// although Frame = 0, RMB is not Clicked
// Update Animations
-- IF Animation 1 Frame [0] > 4
-- NO
-- IF Animation 1 Frame [0] > 0
-- NO
-- IF Animation 2 Frame [0] > 4
-- NO
-- IF Animation 2 Frame [0] > 0
-- NO
LOOP CYCLE 1 END
LOOP CYCLE 2
- POSITION Mouse Cursor
- DRAW Mouse Cursor
- READ Mouse Buttons
// Is LMB pressed AND Animation 1 Frame=0 ?
-- IF BOTH TRUE
-- YES
// Frame = 0, LMB *is* Clicked
- - Animation 1 Frame=1
- - Animation 1 Postion X = Mouse Cursor X [20]
- - Animation 1 Postion Y = Mouse Cursor Y [35]
// Is RMB pressed AND Animation 1 Frame=0 ?
-- IF BOTH TRUE
-- NO
// although Frame = 0, RMB is not Clicked
// Update Animations
-- IF Animation 1 Frame [1] > 4
-- NO
-- IF Animation 1 Frame [1] > 0
-- YES
// ** EXPLOSION 1 ANIMATION STARTS BEING DRAWN**
- - AT Animation 1 X [20], Animation 1 Y [35]
- - DRAW Explosion Animation 1 Frame [1]
- - Animation 1 Frame = Frame + 1 [2]
-- IF Animation 2 Frame [0] > 4
-- NO
-- IF Animation 2 Frame [0] > 0
-- NO
LOOP CYCLE 2 END
LOOP CYCLE 3
- POSITION Mouse Cursor
- DRAW Mouse Cursor
- READ Mouse Buttons
// Is LMB pressed AND Animation 1 Frame=0 [3] ?
-- IF BOTH TRUE
-- NO
// Frame = 2, LMB status is unimportant as a result
// Is RMB pressed AND Animation 1 Frame=0 [0] ?
-- IF BOTH TRUE
-- YES
// although Frame = 0, RMB is not Clicked
// Update Animations
-- IF Animation 1 Frame [2] > 4
-- NO
-- IF Animation 1 Frame [2] > 0
-- YES
- - AT Animation 1 X [20], Animation 1 Y [35]
- - DRAW Explosion Animation 1 Frame [2]
- - Animation 1 Frame = Frame + 1 [3]
-- IF Animation 2 Frame [0] > 4
-- NO
-- IF Animation 2 Frame [0] > 0
-- NO
LOOP CYCLE 3 END
LOOP CYCLE 4
- POSITION Mouse Cursor
- DRAW Mouse Cursor
- READ Mouse Buttons
// Is LMB pressed AND Animation 1 Frame=0 [3] ?
-- IF BOTH TRUE
-- NO
// Frame = 3, LMB status is unimportant as a result
// Is RMB pressed AND Animation 1 Frame=0 [0] ?
-- IF BOTH TRUE
-- YES
// Frame = 0, RMB *is* Clicked
- - Animation 2 Frame=1
- - Animation 2 Postion X = Mouse Cursor X [156]
- - Animation 2 Postion Y = Mouse Cursor Y [67]
// Update Animations
-- IF Animation 1 Frame [3] > 4
-- NO
-- IF Animation 1 Frame [3] > 0
-- YES
- - AT Animation 1 X [20], Animation 1 Y [35]
- - DRAW Explosion Animation 1 Frame [3]
- - Animation 1 Frame = Frame + 1 [4]
-- IF Animation 2 Frame [1] > 4
-- NO
-- IF Animation 2 Frame [1] > 0
-- YES
// ** EXPLOSION 2 ANIMATION STARTS BEING DRAWN**
- - AT Animation 2 X [156], Animation 2 Y [67]
- - DRAW Explosion Animation 2 Frame [1]
- - Animation 2 Frame = Frame + 1 [2]
LOOP CYCLE 4 END
LOOP CYCLE 5
- POSITION Mouse Cursor
- DRAW Mouse Cursor
- READ Mouse Buttons
// Is LMB pressed AND Animation 1 Frame=0 [4] ?
-- IF BOTH TRUE
-- NO
// Frame = 4, LMB status is unimportant as a result
// Is RMB pressed AND Animation 1 Frame=0 [2] ?
-- IF BOTH TRUE
-- NO
// Frame = 4, RMB status is unimportant as a result
// Update Animations
-- IF Animation 1 Frame [4] > 4
-- NO
-- IF Animation 1 Frame [4] > 0
-- YES
- - AT Animation 1 X [20], Animation 1 Y [35]
- - DRAW Explosion Animation 1 Frame [4]
- - Animation 1 Frame = Frame + 1 [5]
-- IF Animation 2 Frame [2] > 4
-- NO
-- IF Animation 2 Frame [2] > 0
-- YES
- - AT Animation 2 X [156], Animation 2 Y [67]
- - DRAW Explosion Animation 2 Frame [2]
- - Animation 2 Frame = Frame + 1 [3]
LOOP CYCLE 5 END
LOOP CYCLE 6
- POSITION Mouse Cursor
- DRAW Mouse Cursor
- READ Mouse Buttons
// Is LMB pressed AND Animation 1 Frame=0 [5] ?
-- NO
// Frame = 4, LMB status is unimportant as a result
// Is RMB pressed AND Animation 1 Frame=0 [3] ?
-- NO
// Frame = 4, RMB status is unimportant as a result
// Update Animations
-- IF Animation 1 Frame [5] > 4
-- YES
// Switch-off Animation 1, because we have used all 4 frames.
- - REMOVE Explosion Animation 1
- - Animation 1 Frame = 0
-- IF Animation 1 Frame [4] > 0
-- NO
-- IF Animation 2 Frame [3] > 4
-- NO
-- IF Animation 2 Frame [3] > 0
-- YES
- - AT Animation 2 X [156], Animation 2 Y [67]
- - DRAW Explosion Animation 2 Frame [3]
- - Animation 2 Frame = Frame + 1 [4]
LOOP CYCLE 6 END
by following that all through (!!!) we can see that Animation 1 starts in Loop Cycle 1, and continues drawing one further animation frame each Loop Cycle, meaning that it is finally "switched off" only in Loop Cycle 6.
By keeping the animation updates and the mouse/event checking separate, this allows us to trigger another Animation 2 in Cycle 4, whilst Animation 1 is still happening.... I didnt follow the code through any futher than the 6 loops, but in Loop 7 we would have been able to have triggered Animation 1 again whilst Animation 2 was still running, as our frame counter had been reset back to zero.
I really hope this helps explain a systematic way of achieving a game-loop that allows true multiple events to occur for you!!
Please feel free to ask questions, as it is getting quite ate now, so i've probably written something wrong in there somewhere!