SHOW:
|
|
- or go back to the newest paste.
| 1 | from livewires import games, color | |
| 2 | import random | |
| 3 | games.init(screen_width = 640, screen_height=480,fps = 50) | |
| 4 | ||
| 5 | class Launcher(games.Sprite): | |
| 6 | """A MISSLE LAUNCHER TO POP BALLONS""" | |
| 7 | image = games.load_image("launcher.bmp", transparent = True)
| |
| 8 | ||
| 9 | def __init__(self, y = 450): | |
| 10 | """initialize launcher""" | |
| 11 | super(Launcher, self).__init__(image = Launcher.image, x = games.mouse.x, y = y) | |
| 12 | #Establish Score on the screen (You may need to move this later) | |
| 13 | self.score = games.Text(value = 0, size = 25, color = color.black, x = 575, y = 20) | |
| 14 | games.screen.add(self.score) | |
| 15 | ||
| 16 | def update(self): | |
| 17 | """Move to Mouse Coordinates""" | |
| 18 | global LEVEL | |
| 19 | self.x = games.mouse.x | |
| 20 | if self.left < 0: | |
| 21 | self.left = 0 | |
| 22 | if self.right > games.screen.width: | |
| 23 | self.right = games.screen.width | |
| 24 | ||
| 25 | ## if games.mouse.is_pressed(0): | |
| 26 | ## print "left mouse button pressed" | |
| 27 | ## self.score.value += 2 | |
| 28 | ## if self.score.value%100 == 0: | |
| 29 | ## LEVEL += 1 | |
| 30 | ## if LEVEL == 6: | |
| 31 | ## LEVEL = 0 | |
| 32 | ## load_image(LEVEL) | |
| 33 | ||
| 34 | global MISSILE_WAIT | |
| 35 | MISSILE_WAIT -= 1 | |
| 36 | if games.mouse.is_pressed(0) and MISSILE_WAIT < 0: | |
| 37 | #print "left mouse button pressed" | |
| 38 | new_missile = missile(self.left + 6, self.top) | |
| 39 | games.screen.add(new_missile) | |
| 40 | MISSILE_WAIT = 0 #25 | |
| 41 | ||
| 42 | if games.mouse.is_pressed(2): | |
| 43 | print "Right Mouse Pressed" | |
| 44 | games.screen.quit() | |
| 45 | ||
| 46 | class Balloons(games.Sprite): | |
| 47 | RED = 1 | |
| 48 | BLUE = 2 | |
| 49 | GREEN = 3 | |
| 50 | YELLOW = 4 | |
| 51 | ||
| 52 | images = {RED : games.load_image("rBalloon.bmp"),
| |
| 53 | BLUE : games.load_image("bBalloon.bmp"),
| |
| 54 | GREEN : games.load_image("gBalloon.bmp"),
| |
| 55 | YELLOW : games.load_image("yBalloon.bmp")}
| |
| 56 | ||
| 57 | def __init__(self,x,y,color): | |
| 58 | super(Balloons, self).__init__( | |
| 59 | image = Balloons.images[color], | |
| 60 | x = x, y = y) | |
| 61 | self.color = color | |
| 62 | ||
| 63 | def handle_collide(self): | |
| 64 | self.destroy() | |
| 65 | global BALLOON_COUNT | |
| 66 | global LEVEL | |
| 67 | BALLOON_COUNT -= 1 | |
| 68 | if BALLOON_COUNT == 0: | |
| 69 | LEVEL += 1 | |
| 70 | if LEVEL == 6: | |
| 71 | LEVEL = 0 | |
| 72 | load_image(LEVEL) | |
| 73 | BALLOON_COUNT = load_balloons() | |
| 74 | ||
| 75 | class missile(games.Sprite): | |
| 76 | global MISSILE_WAIT | |
| 77 | MISSILE_WAIT = 0 | |
| 78 | image = games.load_image("missile.bmp")
| |
| 79 | def __init__(self, x, y): | |
| 80 | ||
| 81 | super(missile, self).__init__(image = missile.image, | |
| 82 | x = x, y = y, dy = -7) | |
| 83 | ||
| 84 | def update(self): | |
| 85 | - | def update(self): |
| 85 | + | if self.top <= 50: |
| 86 | - | if self.top <= 50: |
| 86 | + | self.destroy() |
| 87 | - | self.destroy() |
| 87 | + | self.check_collide() |
| 88 | - | self.check_collide() |
| 88 | + | |
| 89 | def check_collide(self): | |
| 90 | - | def check_collide(self): |
| 90 | + | for balloon in self.overlapping_sprites: |
| 91 | - | for balloon in self.overlapping_sprites: |
| 91 | + | self.destroy() |
| 92 | - | self.destroy() |
| 92 | + | balloon.handle_collide() |
| 93 | - | balloon.handle_collide() |
| 93 | + | |
| 94 | def handle_collide(self): | |
| 95 | - | def handle_collide(self): |
| 95 | + | self.top = self.top - self.height-10 |
| 96 | - | self.top = (self.top - self.height-10) |
| 96 | + | |
| 97 | def load_balloons(): | |
| 98 | BALLOON_COUNT = 0 | |
| 99 | for y in range (50, 250, 20): | |
| 100 | for x in range (15, 635, 16): | |
| 101 | BALLOON_COUNT += 1 | |
| 102 | color = random.choice([Balloons.RED, Balloons.BLUE, Balloons.GREEN, Balloons.YELLOW]) | |
| 103 | new_balloon = Balloons(x = x, y = y, color = color) | |
| 104 | games.screen.add(new_balloon) | |
| 105 | return BALLOON_COUNT | |
| 106 | ||
| 107 | def load_image(x): | |
| 108 | """Load the background image""" | |
| 109 | wall_image = games.load_image(FILES[x], transparent = False) | |
| 110 | games.screen.background = wall_image | |
| 111 | ||
| 112 | def main(): | |
| 113 | ||
| 114 | global MISSILE_WAIT | |
| 115 | global BALLOON_COUNT | |
| 116 | global FILES | |
| 117 | global LEVEL | |
| 118 | ||
| 119 | FILES=["file1.jpg","file2.jpg","file3.jpg","file4.jpg","file5.jpg","file6.jpg"] | |
| 120 | LEVEL = 0 | |
| 121 | load_image(LEVEL) | |
| 122 | the_launcher = Launcher() | |
| 123 | games.screen.add(the_launcher) | |
| 124 | ||
| 125 | BALLOON_COUNT = load_balloons() | |
| 126 | ||
| 127 | games.mouse.is_visible = False | |
| 128 | #We will deal with this command later | |
| 129 | #games.screen.event_grab = True | |
| 130 | games.screen.mainloop() | |
| 131 | ||
| 132 | ||
| 133 | ||
| 134 | ||
| 135 | main() |