def __init__(self, screen, x, y): super().__init__(self.containers) self.screen = screen self.x = x self.y = y self.angle = 0 self.normalImage = pygame.image.load( image_util.getImage("base.png")).convert_alpha() self.normalImage = pygame.transform.scale(self.normalImage, (200, 900)) self.hurtImage = pygame.image.load( image_util.getImage("Base_hurt.png")).convert_alpha() self.hurtImage = pygame.transform.scale(self.hurtImage, (200, 900)) self.image = self.normalImage self.rect = self.image.get_rect() self.rect.center = (self.x, self.y) self.health_max = 10000 self.health = self.health_max self.health_bar_width = self.image.get_width() self.health_bar_hight = 20 self.health_bar_green = pygame.Rect(0, 0, self.health_bar_width, self.health_bar_hight) self.health_bar_red = pygame.Rect(0, 0, self.health_bar_width, self.health_bar_hight) self.alive = True self.hurtTimer = 0
def __init__(self, screen, x, y, target): super().__init__(screen, x, y, target) self.hurtImage = pygame.image.load( image_util.getImage("Motorcycle_hurt.png")) self.image = pygame.image.load(image_util.getImage("Motorcycle.png")) self.speed = 15 self.health = 45
def __init__(self, screen, x, y, target): super().__init__(screen, x, y, target) self.hurtImage = pygame.image.load( image_util.getImage("Runner_hurt.png")) self.image = pygame.image.load(image_util.getImage("Runner.png")) self.speed = 100 self.health = 15
def __init__(self, screen, x, y, target): super().__init__(screen, x, y, target) self.hurtImage = pygame.image.load( image_util.getImage("Spider_hurt.png")).convert_alpha() self.image = pygame.image.load( image_util.getImage("Spider.png")).convert_alpha() self.speed = 10 self.health = 45
def __init__(self, screen, x, y, target): super().__init__(screen, x, y, target) self.normalImage = pygame.image.load( image_util.getImage("Brute.png")).convert_alpha() self.hurtImage = pygame.image.load( image_util.getImage("Brute_hurt.png")).convert_alpha() self.image = self.normalImage self.speed = 2 self.health = 100
def __init__(self, screen, x, y, target): super().__init__(screen, x, y, target) self.hurtImage = pygame.image.load( image_util.getImage("helicopter_hurt.png")).convert_alpha() self.normalImage = pygame.image.load( image_util.getImage("helicopter.png")).convert_alpha() self.normalImage = pygame.transform.scale(self.normalImage, (40, 40)) self.normalImage = self.normalImage self.speed = 3 self.health = 80
def __init__(self, screen, x, y, target): super().__init__(screen, x, y, target) self.hurtImage = pygame.image.load( image_util.getImage("Crawler_hurt.png")).convert_alpha() self.normalImage = self.normalImage self.normalImage = pygame.image.load( image_util.getImage("Crawler.png")).convert_alpha() self.speed = 1.5 self.health = 75 self.angle = 90
def playSound(name): global sound_library sound = sound_library.get(name) if sound == None: canonicalized_path = image_util.getImage(name) sound = pygame.mixer.Sound(canonicalized_path) sound_library[name] = sound sound.play()
def __init__(self, screen, x, y, target): super().__init__(self.containers) self.screen = screen self.target = target self.x = x self.y = y self.normalImage = pygame.image.load( image_util.getImage("Walker.png")).convert_alpha() self.hurtImage = pygame.image.load( image_util.getImage("Walker_hurt.png")).convert_alpha() self.image = self.normalImage self.rect = self.image.get_rect() self.rect.center = (self.x, self.y) self.angle = 180 self.speed = 5 self.health = 50 self.damage = 10 self.hurtTimer = 0
def __init__(self, screen, x, y): pygame.sprite.Sprite.__init__(self, self.containers) self.screen = screen self.x = x self.y = y self.image = pygame.image.load( image_util.getImage("Main_Character.png")).convert_alpha() self.rect = self.image.get_rect() self.rect.center = (self.x, self.y) self.speed = 5 self.angle = 0 self.shoot_cooldown = 0 self.shoot_cooldown_max = 30
def __init__(self, screen, x, y, angle): pygame.sprite.Sprite.__init__(self, self.containers) self.screen = screen self.x = x self.y = y self.angle = angle self.image = pygame.image.load(image_util.getImage("bullet.png")) self.rect = self.image.get_rect() self.x += 5 self.rect.center = (self.x, self.y) self.image, self.rect = toolbox.getRotatedImage( self.image, self.rect, self.angle) self.speed = 20 self.angle_rads = math.radians(self.angle) self.x_move = math.cos(self.angle_rads) * self.speed self.y_move = -math.sin(self.angle_rads) * self.speed self.damage = 15
import image_util from player import Player from projectile import Bullet import enemy from wave_controller import WaveController from score_manager import ScoreManager from base import Base # Start the game pygame.init() game_width = 1000 game_height = 650 screen = pygame.display.set_mode((game_width, game_height), pygame.FULLSCREEN) clock = pygame.time.Clock() running = True background_image = pygame.image.load( image_util.getImage("landscape.png")).convert() waveComing = False playerGroup = pygame.sprite.Group() projectilesGroup = pygame.sprite.Group() enemiesGroup = pygame.sprite.Group() baseGroup = pygame.sprite.Group() Player.containers = playerGroup Bullet.containers = projectilesGroup enemy.Enemy.containers = enemiesGroup Base.containers = baseGroup mr_player = Player(screen, 180, game_height / 2) base = Base(screen, 100, game_height / 2) wave_controller = WaveController(screen, game_width, game_height, enemiesGroup)