def _create_enemy(self, enemy_type): """ Create an enemy in the game with a random direction """ rand = random.choice([-1, 1]) new_enemy = 0 if enemy_type == 1: new_enemy = Goomba(self, rand) if enemy_type == 2: new_enemy = Troopa(self, rand) self.enemies.add(new_enemy)
def create_level(self): dx = dy = 32 for nrow in range(len(self.rows)): row = self.rows[nrow] for ncol in range(len(row)): col = row[ncol] if col == 'x': self.blocks.append( Block(self.screen, ncol * dx, nrow * dy, 0, self.blockfile)) if col == 'b': self.blocks.append( Block(self.screen, ncol * dx, nrow * dy, 1, 'Images/block_tile_1.png')) if col == 'r': self.blocks.append( Block(self.screen, ncol * dx, nrow * dy, 0, 'Images/block_tile_1.png')) if col == 'l': self.blocks.append( Block(self.screen, ncol * dx, nrow * dy, 0, 'Images/pipe-left.png')) if col == 'd': self.blocks.append( Block(self.screen, ncol * dx, nrow * dy, 0, 'Images/pipe-right.png')) if col == 'y': self.blocks.append( Block(self.screen, ncol * dx, nrow * dy, 0, 'Images/pipe-left-top.png')) if col == 'z': self.blocks.append( Block(self.screen, ncol * dx, nrow * dy, 0, 'Images/pipe-right-top.png')) if col == 'v': self.blocks.append( Block(self.screen, ncol * dx, nrow * dy, 0, 'Images/pole-with-flag.png')) if col == 'n': self.blocks.append( Block(self.screen, ncol * dx, nrow * dy, 0, 'Images/pole.png')) if col == 'g': self.goombas.append( Goomba(self.ai_settings, self.screen, ncol * dx, nrow * dy, self.enemy_id, 0)) self.enemy_id += 1 if ncol * dx > self.max_x_value: self.max_x_value = ncol * dx
def create_enemies(self): with open('EnemySettings.txt') as f: for line in f: type, width, height, x, y = line.split() if type == "Koopa": koopa = RegularKoopa(self.screen) # koopa.rect = koopa.sur.get_rect() koopa.rect.x = int(x) koopa.rect.y = int(y) self.enemy_environment.append(koopa) if type == "Goomba": goomba = Goomba(self.screen) goomba.rect.x = int(x) goomba.rect.y = int(y) self.enemy_environment.append(goomba)
from enemies import Goomba import os import sys import time from Levels import * import constants pyg.init() screen = pyg.display.set_mode((960, 470), pyg.RESIZABLE) screen.fill(constants.bg_color) mario = LittleMario(screen) level = Level(screen) level.create_rects() level.create_enemies() goomba = Goomba(screen=screen) enemies = [goomba] koopa = RegularKoopa(screen=screen) koopas = [koopa] while True: gf.check_events(screen=screen, mario=mario) gf.update_mario(mario=mario) gf.update_koopas(koopas=koopas) gf.update_enemies(enemies=enemies) gf.updateLevel(level=level, mario=mario) gf.check_collisiontype(mario=mario, level=level) gf.check_collisiontype_goomba(level=level, enemies=enemies) gf.check_collisiontype_koopa(level=level, koopas=koopas) gf.check_mario_enemy_collision(screen=screen, mario=mario,
def create_goomba(screen, enemies): # create instance of Goomba class goomba = Goomba(screen=screen) enemies.append(goomba)
from PiranhaPlant import UnderGroundPiranha import os import sys import time from Levels import * import constants pyg.init() screen = pyg.display.set_mode((960, 470), pyg.RESIZABLE) screen.fill(constants.bg_color) mario = LittleMario(screen) level = Level(screen) level.create_rects() # level.create_enemies() goomba = Goomba(screen=screen) goomba2 = Goomba(screen=screen) goomba3 = Goomba(screen=screen) goomba4 = Goomba(screen=screen) goomba5 = Goomba(screen=screen) goomba6 = Goomba(screen=screen) goomba2.x = 1100 goomba3.x = 1500 goomba4.x = 1550 goomba5.x = 1750 goomba6.x = 1800 enemies = [goomba, goomba2, goomba3, goomba4, goomba5, goomba6] koopa = RegularKoopa(screen=screen) koopa2 = RegularKoopa(screen=screen) koopa.middle_x = 700 koopa2.middle_x = 1000