Facebook
From V3mdroid, 2 Weeks ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 147
  1. yum yum gems
  2. # GAME SET UP
  3. # Spawns the objects for the game: the avatar, the gem, and the enemy.
  4. avatar = game.spawnObject("turtle")
  5. avatar.setControl("arrows")
  6.  
  7. gem = game.spawnObject("gem-green", "random", "random")
  8.  
  9. enemy = game.spawnObject("spider")
  10. enemy.setChaseTarget(gem)
  11. enemy.setSpeed(0.8)
  12.  
  13. # Shows the directions of the game to the player.
  14. game.addTextDirections("Use arrow keys to help the turtle eat the gems before the enemy does!")
  15.  
  16. points = 0
  17.  
  18. # Defines a function that moves the gem to a random location.
  19. def moveGem():
  20.     gem.setX("random")
  21.     gem.setY("random")
  22.  
  23. # GAME LOOP
  24. # The while loop repeats rounds of the game until 60 seconds have passed.
  25. # Each round updates displays and checks if objects have hit the gem.
  26. while game.timePassed() < 60:
  27.     game.advanceGame()
  28.     game.setDisplay("TIME", game.timePassed())
  29.     game.setDisplay("SCORE", points)
  30.     if avatar.hit(gem):
  31.         points += 1
  32.         moveGem()
  33.     if enemy.hit(gem):
  34.         moveGem()
  35.  
  36.  
  37.  
  38. # GAME END
  39. # After the loop ends, the conditional checks the point score.
  40. # Depending on the number of points, the player sees a win or an end screen.
  41. if points >= 10:
  42.     game.win("You got " + points + " points!  You Win!")
  43. else:
  44.     game.end("You got <20 points! Try Again.")
  45.  
  46.  
  47.  
  48.  
  49.  
  50. rock catches leaf
  51. # GAME SET UP
  52. # Creates the rock and displays the number of rocks that players get.
  53. rock = game.spawnObject("rock-clay", 4.5, 2)
  54.  
  55. # Creates a paddle made of 3 boxes that is moved together with arrow keys.
  56. paddle1 = game.spawnObject("box", 4, 0)
  57. paddle2 = game.spawnObject("box", 4.5, 0)
  58. paddle3 = game.spawnObject("box", 5, 0)
  59. paddle1.setControl("arrows")
  60. paddle2.setControl("arrows")
  61. paddle3.setControl("arrows")
  62.  
  63. # Creates leaves that spell out the word "OK" for the rock to hit.
  64. game.spawnObject("leaf-red", 1, 6)
  65. game.spawnObject("leaf-red", 1, 5)
  66. game.spawnObject("leaf-red", 1, 4)
  67. game.spawnObject("leaf-red", 1, 3)
  68. game.spawnObject("leaf-red", 2, 6)
  69. game.spawnObject("leaf-red", 2, 3)
  70. game.spawnObject("leaf-red", 3, 6)
  71. game.spawnObject("leaf-red", 3, 5)
  72. game.spawnObject("leaf-red", 3, 4)
  73. game.spawnObject("leaf-red", 3, 3)
  74. game.spawnObject("leaf-red", 5, 6)
  75. game.spawnObject("leaf-red", 5, 5)
  76. game.spawnObject("leaf-red", 5, 4)
  77. game.spawnObject("leaf-red", 5, 3)
  78. game.spawnObject("leaf-red", 6, 5)
  79. game.spawnObject("leaf-red", 6, 4)
  80. game.spawnObject("leaf-red", 7, 6)
  81. game.spawnObject("leaf-red", 7, 3)
  82. game.spawnObject("leaf-red", 9, 3)
  83.  
  84. # Shows the directions of the game.
  85. game.addTextDirections("Catch all the leaves!")
  86. game.setBorders("infinite")
  87.  
  88. #Creates global variables that will be used during the game.
  89. leavesToCatch = 19 #the number of leaves spawned above
  90. numOfRocks = 3
  91. ROCK_SPEED = 0.1
  92. rockVX = -ROCK_SPEED
  93. rockVY = ROCK_SPEED
  94.  
  95. # Displays the number of rocks to the player.
  96. game.setDisplay("rocks", numOfRocks)
  97.  
  98. # This function resets the rock to its starting location and movement direction.
  99. def initRock():
  100.     global rockVX, rockVY, ROCK_SPEED
  101.     rockVX = -ROCK_SPEED
  102.     rockVY = ROCK_SPEED
  103.     rock.setXY(4.5, 1.5)
  104.  
  105. # These functions set up how the rock moves when it hits an object.    
  106. def bounceLeftRight():
  107.     global rockVX
  108.     rockVX = -rockVX
  109.  
  110. def bounceUpDown():
  111.     global rockVY
  112.     rockVY = -rockVY
  113.  
  114. # This function is called if the rock hits a leaf.
  115. def removeLeaf(leaf):
  116.     global leavesToCatch
  117.     # The rock's direction is changed.
  118.     if leaf.getY() - rock.getY() > .4:
  119.         bounceUpDown()
  120.     elif leaf.getY() - rock.getY() < -.4:
  121.         bounceUpDown()
  122.     else:
  123.         bounceLeftRight()
  124.     # The leaf that is caught is hidden.
  125.     leaf.hide()
  126.     leavesToCatch = leavesToCatch - 1
  127.  
  128.     #If all the leaves are caught, then the player gets the win screen!  
  129.     if leavesToCatch == 0:
  130.         rock.hide()
  131.         game.win("You Did It!")
  132.  
  133. # GAME LOOP
  134. # The for loop plays 9999 rounds of the game.
  135. # Look at comments inside the loop to find out what happens in each round.
  136. for i in range(9999):
  137.     game.advanceGame()
  138.  
  139.     # Moves the rock forward with its current direction and speed.
  140.     rock.setX(rock.getX() + rockVX)
  141.     rock.setY(rock.getY() + rockVY)
  142.  
  143.     paddle1.setY(0) #only move left/right
  144.     paddle2.setY(0) #only move left/right
  145.     paddle3.setY(0) #only move left/right
  146.    
  147.     # Checks to see if the rock hits the paddle.
  148.     # If so, it changes the rock's direction, depending on its location.
  149.     hitPaddle = rock.hit("box")
  150.     if hitPaddle:
  151.         rockVY = ROCK_SPEED
  152.     # Checks to see if the rock hits a side of the game screen.
  153.     # If so, it changes the rock's direction, depending on its location.
  154.     if rock.getX() <= -0.2:
  155.         rockVX = ROCK_SPEED
  156.     if rock.getX() > 9.2:
  157.         rockVX = -ROCK_SPEED
  158.     if rock.getY() > 7.2:
  159.         rockVY = -ROCK_SPEED
  160.    
  161.     # Checks to see if the rock hits any of the leaves.
  162.     #I f so, it calls the removeLeaf function using the leaf that's hit.
  163.     rockHitLeaf = rock.hit("leaf-red")
  164.     if rockHitLeaf:
  165.         removeLeaf(rock.findNearest("leaf-red"))
  166.  
  167.     # Checks to see if the rock has fallen to the bottom of the screen.
  168.     # If so, then the players loses a rock.
  169.     if rock.getY() < -0.5:
  170.         numOfRocks = numOfRocks - 1
  171.         game.setDisplay("rocks", numOfRocks)
  172.         if numOfRocks > 0:
  173.             initRock()
  174.         else:
  175.             rock.hide()
  176.             game.end("WOMP WOMP")
  177.            
  178.            
  179.            
  180.            
  181.  
  182.  
  183. moth battle
  184. #  GAME SET UP
  185.  
  186. # Creates the objects for the game: a moth, a skull, and enemies.
  187. enemy1 = game.spawnObject("storm","center", -1)
  188. enemy2 = game.spawnObject("storm", "center", -1)
  189. enemy3 = game.spawnObject("storm", "center", -1)
  190.  
  191. skull = game.spawnObject("skull","center", "bottom")
  192. skull.setScale(0.5)
  193.  
  194. moth = game.spawnObject("moth","center", "bottom")
  195. moth.setControl("wasd")
  196.  
  197. # Shows the directions to the player and sets up the border.
  198. game.addTextDirections("Defeat the enemies with skulls of fire! Use WASD keys and don't get hit or touch the walls.")
  199. game.setBorders("infinite")
  200.  
  201. # Creates variables that will be used during the game.
  202. width = 6
  203. mothSpeed = 0.1
  204. skullSpeed = 0.2
  205.  
  206. points = 0
  207. lives = 3
  208.  
  209. # Displays the points and lives for the player
  210. game.setDisplay("points", points)
  211. game.setDisplay("life", lives)
  212.  
  213. # These functions reset objects to new starting locations.
  214. def initAvatar():
  215.     moth.setXY("center", "bottom")
  216.  
  217. def initEnemy(enemy):
  218.     mothSpeed = mothSpeed + 0.005
  219.     enemy.setXY(game.random(1, 8), 7)
  220.  
  221. def initSkull():
  222.     skull.setXY(moth.getX(), moth.getY())
  223.  
  224. # This function moves an enemy one step down the screen.
  225. def enemyStep(enemy):
  226.     enemy.setY(enemy.getY() - mothSpeed)
  227.  
  228. # This function checks if an enemy has reached the bottom of the game screen. If it has, then its location resets.
  229. def checkEnemy(enemy):
  230.     if enemy.getY() > 0:
  231.         enemyStep(enemy)
  232.     else:
  233.         initEnemy(enemy)
  234.  
  235. # Builds a wall on the left and right side of the game screen.
  236. for i in range(8):
  237.     game.spawnObject("wall", 0, i)
  238.     game.spawnObject("wall", 9, i)
  239.  
  240. # GAME LOOP
  241. # The for loop plays 9999 rounds of the game.
  242. # Look at comments inside the loop to find out what happens in each round.
  243. for frame in range(9999):
  244.     game.advanceGame()
  245.     game.setDisplay("points", points)
  246.    
  247.     # Checks the location of each enemy and moves them one step down the screen.
  248.     checkEnemy(enemy1)
  249.     checkEnemy(enemy2)
  250.     checkEnemy(enemy3)
  251.    
  252.     # Moves the skull one step up the game screen.
  253.     skull.setY(skull.getY() + skullSpeed)
  254.    
  255.     # Checks if the skull hits any enemy.
  256.     # If so, the player gets a point, the enemy resets, and the moth starts moving faster.
  257.     skullHit = skull.hit("storm")
  258.     if skullHit:
  259.         points = points + 1
  260.         thisStorm = skull.findNearest("storm")
  261.         initEnemy(thisStorm) #  respawn immediately
  262.         initSkull()
  263.         mothSpeed = mothSpeed + 0.01 #  every time you defeat an enemy, the moth gets faster
  264.    
  265.     # Moves the skull back to the moth once it moves off the screen.
  266.     if skull.getY() > 7.5:
  267.         initSkull()
  268.  
  269.     # Checks if the moth has hit one of the enemies.
  270.     # If so, the player loses a life and the moth location is reset.
  271.     crashEnemy = moth.hit("storm")
  272.     if crashEnemy:
  273.         points = points + 1
  274.         lives = lives - 1
  275.         game.setDisplay("life", lives)
  276.         initAvatar()
  277.         # If the player runs out of lives, then the game ends.
  278.         if lives<1:
  279.             game.end("GAME OVER")
  280.    
  281.     # Checks if the moth has hit one of the walls.
  282.     # If so, the game ends.
  283.     crashWall = moth.hit("wall")
  284.     if crashWall:
  285.         game.end("GAME OVER")
  286.        
  287.     # Keeps the moth from moving off the screen
  288.     if moth.getY()>7:
  289.         moth.setY(7)
  290.     elif moth.getY()<0:
  291.         moth.setY(0)
  292.  
  293.