diff --git a/PyGame/practice/gameprac/hybrid.py b/PyGame/practice/gameprac/hybrid.py index 5da6803..3979010 100644 --- a/PyGame/practice/gameprac/hybrid.py +++ b/PyGame/practice/gameprac/hybrid.py @@ -12,9 +12,16 @@ HEIGHT = 800 WINDOW_SIZE = (WIDTH, HEIGHT) FPS = 60 +WHITE = (255, 255, 255) +BLACK = (0, 0, 0) +RED = (255, 0, 0) +GREEN = (0, 255, 0) +BLUE = (0, 0, 255) ROWS = 5 COLS = 5 +alien_cooldown = 1000 +last_alien_shot = pygame.time.get_ticks() # load background image bg = pygame.image.load("img/bg.png") # FUCK THIS IN THE ASS FIXXED IT FUCK YEA @@ -72,7 +79,6 @@ class Aliens(pygame.sprite.Sprite): self.rect.center = [x, y] self.move_counter = 0 self.move_direction = 1 -# WONT MOVE TO THE RIGHT ONLY TO THE LEFT AND STOP def update(self): self.rect.x += self.move_direction self.move_counter += 1 @@ -80,14 +86,28 @@ class Aliens(pygame.sprite.Sprite): self.move_direction *= -1 self.move_counter *= self.move_direction +class Alien_Bullets(pygame.sprite.Sprite): + def __init__(self, x, y): + pygame.sprite.Sprite.__init__(self) + self.image = pygame.image.load("img/alien_bullet.png") + self.rect = self.image.get_rect() + self.rect.center = [x, y] + def update(self): + self.rect.y += 2 + if self.rect.top > HEIGHT: + self.kill() + # create sprite groups spaceship_group = pygame.sprite.Group() bullet_group = pygame.sprite.Group() - +alien_group = pygame.sprite.Group() +alien_bullet_group = pygame.sprite.Group() # create player spaceship = Spaceship(int(WIDTH / 2), HEIGHT - 100, 3) spaceship_group.add(spaceship) -alien_group = pygame.sprite.Group() + + + def create_aliens(): for row in range(ROWS): @@ -98,14 +118,6 @@ def create_aliens(): create_aliens() - - -WHITE = (255, 255, 255) -BLACK = (0, 0, 0) -RED = (255, 0, 0) -GREEN = (0, 255, 0) -BLUE = (0, 0, 255) - pygame.init() pygame.mixer.init() screen = pygame.display.set_mode(WINDOW_SIZE) @@ -120,20 +132,33 @@ while running: draw_bg() + # create randomw alien bullets + #record current time + time_now = pygame.time.get_ticks() + #shoot + if time_now - last_alien_shot > alien_cooldown and len(alien_bullet_group) < 5 and len(alien_group) > 0: + attacking_alien = random.choice(alien_group.sprites()) + alien_bullet = Alien_Bullets(attacking_alien.rect.centerx, attacking_alien.rect.bottom) + alien_bullet_group.add(alien_bullet) + last_alien_shot = time_now + + # event handlers - for event in pygame.event.get(): if event.type == pygame.QUIT: running = False spaceship.update() + bullet_group.update() alien_group.update() + alien_bullet_group.update() # draw sprite groups on screen spaceship_group.draw(screen) bullet_group.draw(screen) alien_group.draw(screen) - pygame.display.update() # Go over it again FLIP vs UPDATE Which to use When + alien_bullet_group.draw(screen) + pygame.display.update() diff --git a/PyGame/practice/gameprac/img/alien_bullet.png b/PyGame/practice/gameprac/img/alien_bullet.png new file mode 100644 index 0000000..8b0b5c2 Binary files /dev/null and b/PyGame/practice/gameprac/img/alien_bullet.png differ diff --git a/PyGame/practice/gameprac/img/exp1.png b/PyGame/practice/gameprac/img/exp1.png new file mode 100644 index 0000000..f474e97 Binary files /dev/null and b/PyGame/practice/gameprac/img/exp1.png differ diff --git a/PyGame/practice/gameprac/img/exp2.png b/PyGame/practice/gameprac/img/exp2.png new file mode 100644 index 0000000..ca12b9d Binary files /dev/null and b/PyGame/practice/gameprac/img/exp2.png differ diff --git a/PyGame/practice/gameprac/img/exp3.png b/PyGame/practice/gameprac/img/exp3.png new file mode 100644 index 0000000..c86101b Binary files /dev/null and b/PyGame/practice/gameprac/img/exp3.png differ diff --git a/PyGame/practice/gameprac/img/exp4.png b/PyGame/practice/gameprac/img/exp4.png new file mode 100644 index 0000000..ec25e91 Binary files /dev/null and b/PyGame/practice/gameprac/img/exp4.png differ diff --git a/PyGame/practice/gameprac/img/exp5.png b/PyGame/practice/gameprac/img/exp5.png new file mode 100644 index 0000000..888cd12 Binary files /dev/null and b/PyGame/practice/gameprac/img/exp5.png differ diff --git a/PyGame/practice/gameprac/img/explosion.wav b/PyGame/practice/gameprac/img/explosion.wav new file mode 100644 index 0000000..c72284a Binary files /dev/null and b/PyGame/practice/gameprac/img/explosion.wav differ diff --git a/PyGame/practice/gameprac/img/explosion2.wav b/PyGame/practice/gameprac/img/explosion2.wav new file mode 100644 index 0000000..81e03a6 Binary files /dev/null and b/PyGame/practice/gameprac/img/explosion2.wav differ diff --git a/PyGame/practice/gameprac/img/laser.wav b/PyGame/practice/gameprac/img/laser.wav new file mode 100644 index 0000000..438376e Binary files /dev/null and b/PyGame/practice/gameprac/img/laser.wav differ