Now that we have a game loop. we can do some neat things. Every screen refresh, we can automatically have enemies moving across the screen that we need to avoid. Now your player can not just sit there, it has to look out for oncoming objects Adding the enemies and setting up the code We first add the enemies which will be buttons which we can skin with our images. Then we add the message to the game loop.
on updateScreen if sGameRunning is true then moveBox -- moveTerrain moveEnemy -- detectCollisions -- updateScore end if end updateScreen
end moveEnemy
end detectCollisions Add code to move your enemy in the direction that you want 1. Moving Objects Right to Left Here we
have objects coming towards us and we have to avoid them (or collect
them) They can be asteroids, bees, missiles, arrows, or what ever fits
the theme of your game. They can also be butterflies, coins, diamonds or
objects that you want to collect and get points or awards for. At any
rate, we will do objects moving towards us, from the right. We want our enemies to move to the left so we need to subtract a number from its location on the screen. then we have to check if it went off the left side of the card (screen). If it did, then we want to have it come in from the right again
set the left of the button "e1" to the left of the button "e1" - 12 if the left of the button "e1" < 0 then set the left of the button "e1" to the right of the card "level1" end if set the left of the button "e2" to the left of the button "e2" - 12 if the left of the button "e2" < 0 then set the left of the button "e1" to the right of the card "level1" end if end moveEnemy Add the following to the "detectCollisions" on detectCollisions if intersect (button "box" , button "e1" , 255) then answer "Game Over" stopGame end if if intersect (button "box" , button "e2" , 255) then answer "Game Over" stopGame end detectCollisions 2. Moving Objects From Top to Bottom Here we
have objects falling down on us we have to avoid them (or collect
them) They can be asteroids, rocks, raindrops or what ever fits
the theme of your game. They can also be flowers, coins, diamonds or
objects that you want to collect and get points/awards for. At any
rate, we will do objects falling down from the sky (top of screen)We want our objects to move down so we need to add a number from its location on the screen. then we have to check if it went off the bottom of the card (screen). If it did, then we want to have it come in from the top again
set the top of the button "e1" to the top of the button "e1" + 12 if the top of the button "e1" > the bottom of the card "level1" then set the bottom of the button "e1" to the top of the card "level1" end if set the top of the button "e2" to the top of the button "e2" + 12 if the top of the button "e2" > the bottom of the card "level1" then set the bottom of the button "e2" to the top of the card "level1" end if end moveEnemy Add the following to the "detectCollisions" on detectCollisions if intersect (button "box" , button "e1" , 255) then answer "Game Over" stopGame end if if intersect (button "box" , button "e2" , 255) then answer "Game Over" stopGame end detectCollisions 3. Moving Objects Diagonally From Top to Bottom and Right to Left Here we
have objects coming at us from the sky at different angles (more realistic?)This is a combination of the above two examples. At this point, you should be able to figure it out yourself. just combine the above (#1, #2) and merge them with no duplicate lines of code. Have Fun |
Home >