Advertisement
DirkEdge

Sprayball

Apr 19th, 2014
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.18 KB | None | 0 0
  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.  
  80.         def __init__(self, x, y):
  81.  
  82.             super(missile, self).__init__(image = missile.image,
  83.                                           x = x, y = y, dy = -7)
  84.  
  85.             def update(self):
  86.                 if self.top <= 50:
  87.                     self.destroy()
  88.                     self.check_collide()
  89.                    
  90.             def check_collide(self):
  91.                 for balloon in self.overlapping_sprites:
  92.                     self.destroy()
  93.                     balloon.handle_collide()
  94.  
  95.             def handle_collide(self):
  96.                 self.top = (self.top - self.height-10)
  97.  
  98. def load_balloons():
  99.     BALLOON_COUNT = 0
  100.     for y in range (50, 250, 20):
  101.         for x in range (15, 635, 16):
  102.             BALLOON_COUNT += 1
  103.             color = random.choice([Balloons.RED, Balloons.BLUE, Balloons.GREEN, Balloons.YELLOW])
  104.             new_balloon = Balloons(x = x, y = y, color = color)
  105.             games.screen.add(new_balloon)
  106.         return BALLOON_COUNT
  107.  
  108. def load_image(x):
  109.     """Load the background image"""
  110.     wall_image = games.load_image(FILES[x], transparent = False)
  111.     games.screen.background = wall_image
  112.  
  113. def main():
  114.    
  115.     global MISSILE_WAIT
  116.     global BALLOON_COUNT
  117.     global FILES
  118.     global LEVEL
  119.    
  120.     FILES=["file1.jpg","file2.jpg","file3.jpg","file4.jpg","file5.jpg","file6.jpg"]
  121.     LEVEL = 0
  122.     load_image(LEVEL)
  123.     the_launcher = Launcher()
  124.     games.screen.add(the_launcher)
  125.  
  126.     BALLOON_COUNT = load_balloons()
  127.    
  128.     games.mouse.is_visible = False
  129.     #We will deal with this command later
  130.     #games.screen.event_grab = True
  131.     games.screen.mainloop()
  132.  
  133.  
  134.  
  135.  
  136. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement