def restart(): Levels.player = Player() # the player Levels.kbd = Keyboard() # keyboard class to check movement for player Levels.room = None # background for level Levels.Walls = [Wall(0), Wall(1), Wall(2), Wall(3)] # all the walls Levels.playerInteraction = PlayerInteraction( Levels.player, Levels.kbd, Levels.Walls) # interaction to keep player within the walls Levels.levels = [ ] # list of levels. levels get appended here when they load Levels.MeleeEnemies = [] # list of melee enemies Levels.ObjInteractions = [ ] # just initialising var to store interactions between melee enemies Levels.RangedEnemies = [] # list of ranged enemies Levels.Rocks = [] # List of rocks Levels.Projectiles = [] # list of projectiles Levels.wall_interactions = [ ] # list of wall interactions to help keep player within the walls for wall in Levels.Walls: Levels.wall_interactions.append(Interaction(Levels.player, wall)) Levels.Gates = [] # list of gates to move player between levels Levels.GateInteractions = [] # list of interactions for above gates Levels.roomText = 0 # text to represent what room the player is in Scores.score = 0 Levels.projectileCollision = ProjectileCollision(Levels.player)
def __init__(self, player): '''call parent constructor''' Level.__init__(self, player) self.level_limit = -10000 '''array with with width, height, x, and y of platform''' level = [ [210, 70, 500, 500], [210, 70, 800, 400], [210, 70, 1120, 280], [210, 70, 2000, 300], [210, 70, 1800, 500], [210, 70, 2900, 400], ] walls = [[70, 600, 0, 0], [70, 600, 3200, 0]] '''go through the array and add platforms''' for platform in level: block = Platform(platform[0], platform[1]) block.rect.x = platform[2] block.rect.y = platform[3] block.player = self.player self.platform_list.add(block) '''do the same for level walls''' for wall in walls: block = Wall(wall[0], wall[1]) block.rect.x = wall[2] block.rect.y = wall[3] block.player = self.player self.walls_list.add(block) '''add enemies to level''' self.enemy_list.add(Enemy()) self.enemy_list.add(Enemy())
def create_walls(SCREEN_WIDTH, SCREEN_HEIGHT, wall_list, all_sprite_list): # Creating boundary walls # Left tY = 0 while tY < 780: wall = Wall(0, tY, 60, 60) wall_list.add(wall) all_sprite_list.add(wall) tY += 60 # Top tX = 60 while tX < 900: wall = Wall(tX, 0, 60, 60) wall_list.add(wall) all_sprite_list.add(wall) tX += 60 # Right tY = 0 while tY < 780: wall = Wall(SCREEN_WIDTH - 60, tY, 60, 60) wall_list.add(wall) all_sprite_list.add(wall) tY += 60 # Bottom tX = 60 while tX < 900: wall = Wall(tX, SCREEN_HEIGHT - 60, 60, 60) wall_list.add(wall) all_sprite_list.add(wall) tX += 60 # Create all walls in the middle of the board start = 120 for i in range(6): gap = 0 for j in range(5): wall = Wall(start, 120 + gap, 60, 60) wall_list.add(wall) all_sprite_list.add(wall) gap += 120 start += 120
def __init__(self): """class makes pacman move and draws the screen""" self.move_down = False self.move_up = False self.move_right = False self.move_left = False self._pacman_start = True self.first_game_screen = True self.game_over_screen = False self.game_win_screen = False self.game_over = False self.game_win = False self.play_again = None self.width = 890 self.height = 660 self.x = 100 self.y = 100 self._new_x = 0 self._new_y = 0 self._collision = False self.screen = pygame.display.set_mode((self.width, self.height)) pygame.display.set_caption("Pac-Man") self.walls = pygame.sprite.Group() self.pacman_group = pygame.sprite.GroupSingle() self.points = pygame.sprite.Group() self.ghosts_list = pygame.sprite.Group() self.pacman = Pacman(self.x, self.y, self.move_left, self.move_down, self.move_up) self.ghosts = Ghosts(1, 500, 210) self.ghost_1 = Ghosts(1, 775, 40) self.ghost_2 = Ghosts(2, 500, 210) self.ghost_3 = Ghosts(3, 100, 460) self._ghost_collision = False self.ghosts_list.add(self.ghost_1, self.ghost_2, self.ghost_3) self.ghosts_list.add(self.ghost_2) self.ghost_1_direction = "left" self.ghost_2_direction = "right" self.ghost_3_direction = "down" self.wall = Wall(self.x, self.y, self.width, self.height) self.wall.draw_walls(self.screen, self.walls) self.point = Point(self.x, self.y) self.points = self.point.draw_points(self.points) self.point_count = 0 pygame.init() # pylint: disable=(no-member)
def load(self): map_size, map_agents, map_walls, map_columns, map_bonuses = None, None, None, None, None exec( 'from ' + self.name + ' import map_size, map_agents, map_walls, map_columns, map_bonuses' ) if map_size and map_agents and map_walls and map_columns and map_bonuses: map_size[0] += STATS_WIDTH self.width, self.height = map_size self.bg = pygame.Surface((self.width - STATS_WIDTH, self.height)) self.bg.fill(self.background_color) self.stats_bg = pygame.Surface((STATS_WIDTH, self.height)) self.stats_bg.fill(self.background_color) for params in map_agents: agent_creation = 'self.agents.append(' + params[0] + '(' for key in agent_keys: agent_creation += "params[1]['" + key + "']," agent_creation = agent_creation[:-1] + '))' exec agent_creation for col in map_columns: self.obstacles.append(Column(col[0], col[1], col[2])) for wall in map_walls: self.obstacles.append( Wall(center_pos=wall[0], width=wall[1], height=wall[2], color=wall[3])) for i in range(len(all_bonuses)): for bonus in map_bonuses[i]: self.bonus_spawner.append({ 'self': all_bonuses[i], 'pos': (bonus[0], bonus[1]), 'cooldown': bonus[2], 'spawn_next_in': bonus[2] }) self.fill_holder() self.ready = True print 'Loading finished' else: print 'Loading failed'
def main(): random.seed(44) base = 'waves-vertical' prod_svg = svgwrite.Drawing(f'{base}.svg', profile='tiny') debug_svg = svgwrite.Drawing(f'{base}-debug.svg', profile='tiny') for i in range(8, 10): wall = Wall(f"{base}-{i}", outer, x_offset=i * (146 + 10)) make_y(wall, prod_svg) wall.to_svg(prod_svg) wall.make_stl() prod_svg.save() debug_svg.save()
def getting_coords(self): """ Creating walls objects / empty zones coords / Characters coords and stocking them in self.coords defaultdict """ with open("maze_overview.txt", "r") as file: for y, lines in enumerate(file): for x, chars in enumerate(lines): if chars == "#": self.coords["Walls"].append( Wall(x * SPRITE_WIDTH, y * SPRITE_HEIGHT)) elif chars == " ": self.coords["Empty"].append( (x * SPRITE_WIDTH, y * SPRITE_HEIGHT)) elif chars == "G": self.coords["G"].append( (x * SPRITE_WIDTH, y * SPRITE_HEIGHT)) elif chars == "M": self.coords["M"].append( (x * SPRITE_WIDTH, y * SPRITE_HEIGHT)) else: pass return self.coords
def mitchell(cfg, seed: int): wall = Wall(f"mitchell-{seed}", cfg) output = subprocess.check_output(["mitchell/mitchell", str(seed)]) circles = json.loads(output) for circle in circles: center = Vec(circle['x'], circle['y']) r = circle['r'] points = circle_points(center, r, 20) poly = Polygon.Polygon([p.point2 for p in points]) & wall.window wall.result = wall.result + poly wall.result = wall.wall - wall.result wall.make_stl()
def make_y(wall: Wall, svg: Drawing): rngy = np.arange(wall.y0 - 2, wall.y1 + 2, 0.25) waves = Polygon.Polygon() w2 = 0.85 for x in np.arange(wall.x0 - 20, wall.x1 + 20, 6.0): points = [] for y in rngy: fxy = f(x, y / 1.66) points.append((x + fxy - w2, y)) for y in reversed(rngy): fxy = f(x, y / 1.66) points.append((x + fxy + w2, y)) p = Polygon.Polygon(points) waves += wall.window & p svg.save() waves &= wall.window wall.result = wall.wall - wall.window + waves
def make_x(wall: Wall, svg: Drawing): rngx = np.arange(2, 146 - 2, 0.25) waves = Polygon.Polygon() w2 = 0.85 for y in np.arange(80, 100 + 120, 5.0): points = [] for x in rngx: fxy = f(x + wall.x0, y / 1.66) points.append((x + wall.x0, y + fxy + w2)) for x in reversed(rngx): fxy = f(x + wall.x0, y / 1.66) points.append((x + wall.x0, y + fxy - w2)) p = Polygon.Polygon(points) waves += wall.window & p svg.save() waves &= wall.window wall.result = wall.wall - wall.window + waves
def fun_circles(cfg, seed: int): random.seed(seed) wall = Wall(f"fun-circles-{seed}", cfg) points = poisson_disc_samples(width=cfg.width * 3, height=cfg.height * 3, r=cfg.r * 0.80) radii = {} for i in range(len(points)): radii[i] = min( distance(points[i], points[j]) for j in range(len(points)) if i != j) / 2 for i, point in enumerate(points): r = radii[i] * 0.95 center = Vec(*point) points = circle_points(center, r, 20) poly = Polygon.Polygon([p.point2 for p in points]) & wall.window wall.result = wall.result + poly wall.result = wall.wall - wall.result wall.make_stl()
def make_wall(cfg, points, name, debug_svg, x_offset, total_x): wall = Wall(name, cfg, x_offset=x_offset, y_offset=25) radii = {} for i in range(len(points)): radii[i] = min( distance(points[i], points[j]) for j in range(len(points)) if i != j) / 2 cut = Polygon.Polygon() def map_angle(x_in: float, y_in: float) -> float: a0 = 30 * math.pi / 180 f0 = 0.009 c = total_x phi = x_in / c * 2 * math.pi r = c / (2 * math.pi) x = r * math.cos(phi) y = r * math.cos(phi) z = y_in return a0 * noise.snoise3( f0 * x, f0 * y, f0 * z, ) + 0.25 * a0 * noise.snoise3( 2 * f0 * x + 1000, 2 * f0 * y + 1000, 2 * f0 * z + 1000, ) + 0.0 * a0 * (random.random() - 0.5) for i, point in enumerate(points): r = radii[i] * 2.5 center = Vec(*point) theta = map_angle(center.x, center.y) points: List[Vec] = star_points(center, r, theta) debug_svg.add( debug_svg.polygon([p.point2 for p in points], fill_opacity=0, stroke="black", stroke_width=0.25)) poly = Polygon.Polygon([p.point2 for p in points]) cut |= poly mask = wall.window & cut wall.result = wall.wall - mask wall.make_stl() debug_svg.add( debug_svg.polygon(wall.window.contour(0), fill_opacity=0, stroke="black", stroke_width=0.25)) debug_svg.add( debug_svg.polygon(wall.wall.contour(0), fill_opacity=0, stroke="black", stroke_width=0.25))
class Coordinates(): # For doors levels = [0, 4, 7] centers = [-6.25, -4.75, -3.25, -1.75, 0, 1.75, 3.25, 4.75, 6.25] stct = Structure() tops = stct.get_tops() front = Front().get_front() doors_objects = {0: {}, 4: {}, 7: {}} doors = [] left_doors = [] for level in levels: for center in centers: door = Door(level, center) doors_objects[level][center] = door doors.append(door.get_door()) left_doors.append(door.get_left_door()) # tops door lvl, ctr = 10, 0 levels.append(lvl) doors_objects[lvl] = {} door = Door(lvl, ctr) doors_objects[lvl][ctr] = door doors.append(door.get_door()) chairs = [] c_coordsT = [ (-5.5, 0, 9.3), (-4, 0, -15.7), (0, 0, -15.7), (4, 0, -15.7), (-2, 0, -12.7), (2, 0, -12.7), # 0 degrees (-4.7, 0, -15), (-0.7, 0, -15), (3.3, 0, -15), (-2.7, 0, -12), (1.3, 0, -12), (-6.2, 0, -1), # 90 degrees (-3.3, 0, -15), (0.7, 0, -15), (4.7, 0, -15), (-1.3, 0, -12), (2.7, 0, -12), # -90 degrees (-4, 0, -14.3), (0, 0, -14.3), (4, 0, -14.3), (-2, 0, -11.3), (2, 0, -11.3) ] # 180 degrees c_coords = [(0, 0, 0)] * 22 for cc in c_coords: chair = Chair(cc).get_chair() chairs.append(chair) chairs2 = [] c2_coordsT = [(5.5, 0, 6), (-5.5, 0, -6), (-5, 0, -6), (-4, 0, -6), (-3.5, 0, -6), (-2.5, 0, -6), (-2, 0, -6), (1.5, 0, -6), (2.5, 0, -6), (3.5, 0, -6), (4.5, 0, -6), (5.5, 0, -6)] c2_coords = [(0, 0, 0)] * 12 for cc2 in c2_coords: chair = Chair2(cc2).get_chair() chairs2.append(chair) tables = [] ct_coordsT = [(-5.5, 0, 10), (-4, 0, -15), (0, 0, -15), (4, 0, -15), (-2, 0, -12), (2, 0, -12), (-5.5, 0, -1)] ct_coords = [(0, 0, 0)] * 7 for ct in ct_coords: table = Table(ct).get_table() tables.append(table) bookcases = [] cbc_coordsT = [(3.5, 0, 3), (3.5, 4, 3), (-6.6, 0, -6.5), (-6.6, 0, -9.5), (-6.6, 0, -12.5), (-6.6, 0, -15.5), (6.6, 0, -6.5), (6.6, 0, 15.5), (6.6, 0, 12.5), (6.6, 0, 9.5), (6.6, 0, 6.5), (6.6, 0, -9.5), (6.6, 0, -12.5), (-6.5, 0, 6.5), (-6.5, 0, 3.7), (-6.5, 0, 1.3), (6.6, 0, -15.5), (-6.6, 0, 14), (-1.5, 0, -19), (1.5, 0, -19)] cbc_coords = [(0, 0, 0)] * 20 for cbc in cbc_coords: bookcase = Bookcase(cbc).get_bookcase() bookcases.append(bookcase) bookcases2 = [] cbc2_coordsT = [(3.5, 0, 1), (3.5, 4, 1), (-5.5, 0, -19), (6.5, 0, -19), (-3.5, 0, -19), (4.5, 0, -19), (-4.2, 0, 1)] cbc2_coords = [(0, 0, 0)] * 7 for cbc2 in cbc2_coords: bookcase2 = Bookcase2(cbc2).get_bookcase() bookcases2.append(bookcase2) walls = [] cw_coords = [(0, 0, 0)] for cw in cw_coords: wall = Wall(cw).get_wall() walls.append(wall) floors = [] cf_coords = [(0, 0, 0)] for cf in cf_coords: floor = Floor(cf).get_floor() floors.append(floor)
class Levels: # static variable: # this really should be moved to globals but it will be annoying to edit everything player = Player() # the player kbd = Keyboard() # keyboard class to check movement for player room = None # background for level Walls = [Wall(0), Wall(1), Wall(2), Wall(3)] # all the walls playerInteraction = PlayerInteraction( player, kbd, Walls) # interaction to keep player within the walls levels = [] # list of levels. levels get appended here when they load MeleeEnemies = [] # list of melee enemies ObjInteractions = [ ] # just initialising var to store interactions between melee enemies RangedEnemies = [] # list of ranged enemies Enemies = [] Rocks = [] # List of rocks FriendlyProjectiles = [] # list of projectiles EnemyProjectiles = [] wall_interactions = [ ] # list of wall interactions to help keep player within the walls for wall in Walls: wall_interactions.append(Interaction(player, wall)) Gates = [] # list of gates to move player between levels GateInteractions = [] # list of interactions for above gates roomText = 0 # text to represent what room the player is in projectileCollision = ProjectileCollision(player) # called from within level# classes # meleeEnemiesList: the list of enemies from the level # rangedEnemiesList: the list of enemies from the level # gateList: list of gates from the level def LoadLevel(self, meleeEnemiesList, rangedEnemiesList, gateList, rockList, room): Levels.MeleeEnemies = [] Levels.RangedEnemies = [] Levels.Rocks = [] Levels.FriendlyProjectiles = [] Levels.EnemyProjectiles = [] Levels.room = None Levels.ObjInteractions = [] Levels.allObj = [] Levels.Enemies = [] Levels.Rocks = rockList for rock in rockList: Levels.allObj.append(rock) Levels.MeleeEnemies = meleeEnemiesList for enemy in meleeEnemiesList: Levels.allObj.append(enemy) Levels.Enemies.append(enemy) Levels.RangedEnemies = rangedEnemiesList for enemy in rangedEnemiesList: Levels.allObj.append(enemy) Levels.Enemies.append(enemy) Levels.Gates = [] for gate in gateList: Levels.Gates.append(gate) Levels.room = room Levels.allObj.append(Levels.player) Levels.ObjInteractions.append(InteractionSet(Levels.allObj)) @staticmethod def update(): Levels.player.update() Levels.playerInteraction.update() if Levels.player.cooldown <= 0 and (Levels.kbd.arrow_up or Levels.kbd.arrow_right or Levels.kbd.arrow_down or Levels.kbd.arrow_left): Levels.FriendlyProjectiles.append(Levels.playerInteraction.shoot()) for interaction in Levels.wall_interactions: interaction.update() for melee in Levels.MeleeEnemies: melee.daze_cycle() if melee.currentlyTargeting: melee.target(Levels.player.pos) melee.update() for interaction in Levels.ObjInteractions: interaction.update() for ranged in Levels.RangedEnemies: ranged.daze_cycle() if ranged.currentlyTargeting: ranged.target(Levels.player.pos) if ranged.cooldown <= 0: Levels.EnemyProjectiles.append(ranged.shoot(Levels.player.pos)) #Levels.Projectiles.append(ranged.shoot(Levels.player.pos)) ranged.update() for projectile in Levels.EnemyProjectiles: projectile.update() if projectile.frame_life <= 0: Levels.EnemyProjectiles.remove(projectile) for projectile in Levels.FriendlyProjectiles: projectile.update() if projectile.frame_life <= 0: Levels.FriendlyProjectiles.remove(projectile) for gate in Levels.Gates: gate.update() Levels.projectileCollision.update(Levels.EnemyProjectiles, Levels.FriendlyProjectiles, Levels.Rocks, Levels.RangedEnemies, Levels.MeleeEnemies) for enemy in Levels.MeleeEnemies: if Levels.player.collides(enemy) and enemy.currentlyAttacking: Levels.player.health.damaged("Player", Levels.player, Levels.RangedEnemies, Levels.MeleeEnemies) enemy.attacked() @staticmethod def draw(canvas): Levels.room.draw(canvas) Levels.player.draw(canvas) for rock in Levels.Rocks: rock.draw(canvas) for melee in Levels.MeleeEnemies: melee.draw(canvas) for ranged in Levels.RangedEnemies: ranged.draw(canvas) for projectiles in Levels.EnemyProjectiles: projectiles.draw(canvas) for projectiles in Levels.FriendlyProjectiles: projectiles.draw(canvas) for wall in Levels.Walls: wall.draw(canvas) for gate in Levels.Gates: gate.draw(canvas) canvas.draw_text("Room: " + str(Levels.roomText), (10, 9), 15, "White") canvas.draw_text("Score: " + str(Scores.score), (930, 9), 15, "White") @staticmethod def restart(): Levels.player = Player() # the player Levels.kbd = Keyboard() # keyboard class to check movement for player Levels.room = None # background for level Levels.Walls = [Wall(0), Wall(1), Wall(2), Wall(3)] # all the walls Levels.playerInteraction = PlayerInteraction( Levels.player, Levels.kbd, Levels.Walls) # interaction to keep player within the walls Levels.levels = [ ] # list of levels. levels get appended here when they load Levels.MeleeEnemies = [] # list of melee enemies Levels.ObjInteractions = [ ] # just initialising var to store interactions between melee enemies Levels.RangedEnemies = [] # list of ranged enemies Levels.Rocks = [] # List of rocks Levels.Projectiles = [] # list of projectiles Levels.wall_interactions = [ ] # list of wall interactions to help keep player within the walls for wall in Levels.Walls: Levels.wall_interactions.append(Interaction(Levels.player, wall)) Levels.Gates = [] # list of gates to move player between levels Levels.GateInteractions = [] # list of interactions for above gates Levels.roomText = 0 # text to represent what room the player is in Scores.score = 0 Levels.projectileCollision = ProjectileCollision(Levels.player)
class Game: def __init__(self): """class makes pacman move and draws the screen""" self.move_down = False self.move_up = False self.move_right = False self.move_left = False self._pacman_start = True self.first_game_screen = True self.game_over_screen = False self.game_win_screen = False self.game_over = False self.game_win = False self.play_again = None self.width = 890 self.height = 660 self.x = 100 self.y = 100 self._new_x = 0 self._new_y = 0 self._collision = False self.screen = pygame.display.set_mode((self.width, self.height)) pygame.display.set_caption("Pac-Man") self.walls = pygame.sprite.Group() self.pacman_group = pygame.sprite.GroupSingle() self.points = pygame.sprite.Group() self.ghosts_list = pygame.sprite.Group() self.pacman = Pacman(self.x, self.y, self.move_left, self.move_down, self.move_up) self.ghosts = Ghosts(1, 500, 210) self.ghost_1 = Ghosts(1, 775, 40) self.ghost_2 = Ghosts(2, 500, 210) self.ghost_3 = Ghosts(3, 100, 460) self._ghost_collision = False self.ghosts_list.add(self.ghost_1, self.ghost_2, self.ghost_3) self.ghosts_list.add(self.ghost_2) self.ghost_1_direction = "left" self.ghost_2_direction = "right" self.ghost_3_direction = "down" self.wall = Wall(self.x, self.y, self.width, self.height) self.wall.draw_walls(self.screen, self.walls) self.point = Point(self.x, self.y) self.points = self.point.draw_points(self.points) self.point_count = 0 pygame.init() # pylint: disable=(no-member) def draw_screen(self): """draws the screen with points, walls and updated score and place for pacman and ghosts""" self.screen.fill((0, 0, 0)) self._get_points() font = pygame.font.SysFont("Arial", 24) text = font.render("Score: " + str(self.point_count), True, (18, 247, 110)) self.screen.blit(text, (775, 20)) self.points.draw(self.screen) self.pacman_group.draw(self.screen) self.walls.draw(self.screen) self.ghosts_list.draw(self.screen) def _get_points(self): """Uses point_collect method from Point class to test if pacman collides with points. Saves the score if pacman collects points and sets the self.game_win True.""" hit = self.point.collect_points(self.pacman, self.points) if hit == 1: self.point_count += 1 if hit == 2: self.point_count += 2 if self.point_count == 87: self.game_win = True def update_place(self): """updates place for pacman and ghosts""" if self._pacman_start: self.pacman_start_screen() if self._pacman_start is False: self.pacman_move() self._ghost_collision = self.ghosts.ghost_collision( self.pacman, self.ghosts_list) if self._ghost_collision is True: self.game_over = True self.ghost_1_direction = self.ghosts.ghost_move( self.ghost_1, self.ghost_1_direction, self.walls) self.ghost_2_direction = self.ghosts.ghost_move( self.ghost_2, self.ghost_2_direction, self.walls) self.ghost_3_direction = self.ghosts.ghost_move( self.ghost_3, self.ghost_3_direction, self.walls) self.pacman_group.add(self.pacman) def pacman_start_screen(self): """creates a new start view. Different views for first game, game over and winning.""" if self.first_game_screen: self.pacman = Pacman(self.x, self.y, self.move_left, self.move_down, self.move_up) self.pacman_group.add(self.pacman) start = pygame.image.load("src/pictures/start.png") self.screen.blit(start, (205, 170)) if self.game_over_screen: game_over = pygame.image.load("src/pictures/Game_over.png") self.screen.blit(game_over, (205, 170)) self.screen.blit(self.game_over_score, (457, 273)) if self.game_win_screen: win = pygame.image.load("src/pictures/you_won.png") self.screen.blit(win, (205, 170)) def save_game_over_score(self, score): """saves the score for new start view""" font = pygame.font.SysFont("Jellee-Roman", 48) self.game_over_score = font.render(str(score), True, (18, 247, 95)) def pacman_move(self): """updates new coordinates for pacman and uses collision method from Wall class to check for collision Args: new_x (adds new coordinates) new_y (adds new coordinates) """ self.x += self._new_x self.y += self._new_y self.pacman = Pacman(self.x, self.y, False, False, True) self._collision = self.wall.collision(self.pacman, self.walls) if self._collision: self.x -= self._new_x self.y -= self._new_y self.pacman = Pacman(self.x, self.y, self.move_left, self.move_down, self.move_up) self.pacman = Pacman(self.x, self.y, self.move_left, self.move_down, self.move_up) self.pacman_group.add(self.pacman) def move(self): """Functions for different keys. Uses different move methods depending on which key is pressed""" for event in pygame.event.get(): if event.type == pygame.KEYDOWN: # pylint: disable=(no-member) if event.key == pygame.K_LEFT: # pylint: disable=(no-member) self._pacman_set_direction_left() if event.key == pygame.K_RIGHT: # pylint: disable=(no-member) self._pacman_set_direction_right() # pylint: disable=(no-member) if event.key == pygame.K_UP: # pylint: disable=(no-member) self._pacman_set_direction_up() if event.key == pygame.K_DOWN: # pylint: disable=(no-member) self._pacman_set_direction_down() if event.key == pygame.K_RETURN: # pylint: disable=(no-member) self._pacman_start = False if event.type == pygame.QUIT: # pylint: disable=(no-member) exit() def _pacman_set_direction_right(self): """Sets the moving direction. The current direction is True, others are False""" self.move_right = True if self.move_right: self.move_left = False self.move_up = False self.move_down = False self._new_x = 1 self._new_y = 0 def _pacman_set_direction_left(self): """Sets the moving direction. The current direction is True, others are False""" self.move_left = True if self.move_left: self.move_right = False self.move_up = False self.move_down = False self._new_x = -1 self._new_y = 0 def _pacman_set_direction_up(self): """Sets the moving direction. The current direction is True, others are False""" self.move_up = True if self.move_up: self.move_left = False self.move_right = False self.move_down = False self._new_x = 0 self._new_y = -1 def _pacman_set_direction_down(self): """Sets the moving direction. The current direction is True, others are False""" self.move_down = True if self.move_down: self.move_left = False self.move_right = False self.move_up = False self._new_x = 0 self._new_y = 1