def load(self): with open("savefile", "rb") as f: loaddata = pickle.load(f) self.all_sprites = pg.sprite.LayeredUpdates() self.walls = pg.sprite.Group() self.mobs = pg.sprite.Group() self.mobslist = [] self.ghostlist = [] self.bullets = pg.sprite.Group() self.items = pg.sprite.Group() self.itemslist = [] self.map = TiledMap(path.join(map_folder, 'Fase1.tmx')) self.map_img = self.map.make_map() self.map.rect = self.map_img.get_rect() self.player = Player(self, loaddata[0][2][0], loaddata[0][2][1]) self.player.health = loaddata[0][0] self.player.weapon = loaddata[0][1] for zombie in loaddata[1]: M = Mob(self, zombie[0], zombie[1]) self.mobslist.append(M) for ghost in loaddata[3]: G = Ghost(self, ghost[0], ghost[1]) self.ghostlist.append(G) for item in loaddata[2]: I = Item(self, item[0], item[1]) self.itemslist.append(I) for tile_object in self.map.tmxdata.objects: if tile_object.name == 'wall': Obstacle(self, tile_object.x, tile_object.y, tile_object.width, tile_object.height) self.camera = Camera(self.map.width, self.map.height) self.draw_debug = False self.paused = False
def create_new_enemies_wave(self, enemy): if enemy is Ghost: for i in range(rnd.randint(1, self.difficulty.value[0])): pos = (-100 if rnd.randint(0, 100) % 2 == 0 else WIDTH + 100, rnd.randint(0, HEIGHT)) self.entities.append(Ghost(pos)) if enemy is Pumpkin: pos = (self.player.rect.centerx, -50) self.entities.append(Pumpkin(pos))
def create_entities(self): self.entities = [ Ghost((rnd.randint(-200, 0), rnd.randint(0, self.display.HEIGHT // 4))), Pumpkin((rnd.randint(0, WIDTH), -100)) ] self.player = Player( (self.display.WIDTH / 2, self.display.HEIGHT - 200), 'player_stand')
def new(self): # Criando grupos de sprites self.all_sprites = pg.sprite.Group() self.walls = pg.sprite.Group() self.mobs = pg.sprite.Group() self.mobslist = [] self.ghostlist = [] self.bullets = pg.sprite.Group() self.items = pg.sprite.Group() self.itemslist = [] # Usando a biblioteca Pytween para criar um mapa em tiles, usando o editor de mapas self.map = TiledMap( path.join(path.join(path.dirname(__file__), 'maps'), 'fase1.tmx')) self.map_img = self.map.make_map() self.map.rect = self.map_img.get_rect() # loop que lê os objetos posicionados no editor de mapas e cria eles for tile_object in self.map.tmxdata.objects: obj_center = vec(tile_object.x + tile_object.width / 2, tile_object.y + tile_object.height / 2) if tile_object.name == 'player': self.player = Player(self, obj_center.x, obj_center.y) if tile_object.name == 'zombie': M = Mob(self, obj_center.x, obj_center.y) self.mobslist.append(M) if tile_object.name == 'ghost': G = Ghost(self, obj_center.x, obj_center.y) self.ghostlist.append(G) if tile_object.name == 'wall': Obstacle(self, tile_object.x, tile_object.y, tile_object.width, tile_object.height) if tile_object.name in ['health', 'shotgun', 'staff']: I = Item(self, obj_center, tile_object.name) self.itemslist.append(I) self.camera = Camera(self.map.width, self.map.height) self.paused = False
def __init__(self): Ghost.__init__(self, pg.image.load("assets/images/pinky.png"))
def move(self, pacman_location): next_move = r.choice(list(Movement)) Ghost.move(self, next_move)