Added alien fleet
parent
a3db72f76a
commit
c79f8f7fd2
@ -0,0 +1,24 @@
|
|||||||
|
import pygame
|
||||||
|
from pygame.sprite import Sprite
|
||||||
|
|
||||||
|
class Alien(Sprite):
|
||||||
|
"""A class to represent a single alien in the fleet."""
|
||||||
|
def __init__(self, ai_game):
|
||||||
|
super().__init__()
|
||||||
|
self.screen = ai_game.screen
|
||||||
|
self.settings = ai_game.settings
|
||||||
|
self.image = pygame.image.load("images/alien.bmp")
|
||||||
|
self.rect = self.image.get_rect()
|
||||||
|
self.rect.x = self.rect.width
|
||||||
|
self.rect.y = self.rect.height
|
||||||
|
self.x = float(self.rect.x)
|
||||||
|
|
||||||
|
def check_edges(self):
|
||||||
|
"""Return True if alien is at edge of screen."""
|
||||||
|
screen_rect = self.screen.get_rect()
|
||||||
|
return self.rect.right >= screen_rect.right or self.rect.left <= 0
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
"""Move the alien right or left."""
|
||||||
|
self.x += self.settings.alien_speed * self.settings.fleet_direction
|
||||||
|
self.rect.x = self.x
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
class GameStats:
|
||||||
|
"""Track statistics for Alien Invasion."""
|
||||||
|
|
||||||
|
def __init__(self, ai_game):
|
||||||
|
"""Initialize statistics."""
|
||||||
|
self.settings = ai_game.settings
|
||||||
|
self.reset_stats()
|
||||||
|
# Start Alien Invasion in an active state.
|
||||||
|
self.game_active = True
|
||||||
|
|
||||||
|
def reset_stats(self):
|
||||||
|
"""Initialize statistics that can change during the game."""
|
||||||
|
self.ships_left = self.settings.ship_limit
|
||||||
|
self.score = 0
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
Loading…
Reference in New Issue