kikipdph Posted August 19 Share Posted August 19 (edited) I initiated this topic for both beginners and advanced programmers who can provide some tricks and tips from their programming approaches. Here's an example of how we can use a single variable instead of using 3 variables to control the movement of three independent sprites. Each sprite is assigned a specific decimal value, designated here as 'v'. The sprites move up and down, reaching a certain screen height, and change direction, effectively bouncing back. ; Moving sprite 1 if player1y = 18 then v = v | 1 ; Set the first decimal to 1 if sprite 1 has reached the upper wall if player1y = 57 then v = v & 254 ; Set the first decimal to 0 if sprite 1 has reached the lower wall if (v & 1) > 0 && player1y < 195 then player1y = player1y + 1 ; If the first decimal is 1, move sprite 1 downwards if (v & 1) = 0 && player1y < 195 then player1y = player1y - 1 ; If the first decimal is 0, move sprite 1 upwards ; Moving sprite 2 if player2y = 67 then v = v | 2 ; Set the second decimal to 1 if sprite 2 has reached the upper wall if player2y = 100 then v = v & 253 ; Set the second decimal to 0 if sprite 2 has reached the lower wall if (v & 2) > 0 && player2y < 195 then player2y = player2y + 1 ; If the second decimal is 1, move sprite 2 downwards if (v & 2) = 0 && player2y < 195 then player2y = player2y - 1 ; If the second decimal is 0, move sprite 2 upwards ; Moving sprite 3 if player3y = 110 then v = v | 4 ; Set the third decimal to 1 if sprite 3 has reached the upper wall if player3y = 150 then v = v & 251 ; Set the third decimal to 0 if sprite 3 has reached the lower wall if (v & 4) > 0 && player5y < 195 then player3y = player3y + 1 ; If the third decimal is 1, move sprite 3 downwards if (v & 4) = 0 && player5y < 195 then player3y = player3y - 1 ; If the third decimal is 0, move sprite 3 upwards I use this < 195 when the sprite is in a section where movement is needed. For example, if we shoot the sprite, I move it to y = 200, and then movement is not necessary. Edited August 19 by kikipdph 1 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.