def make_flying_obstacle(self): obstacle = obstacles.Obstacle(random.choice(self.obstacle_options)[0]) obstacle.rect.x = random.randint(constants.SCREEN_WIDTH, constants.SCREEN_WIDTH * 2) obstacle.rect.y = random.randint(0, constants.SCREEN_HEIGHT / 2) obstacle.player = self.player self.obstacle_list.add(obstacle)
def __init__(self, player): """ Create level 5. """ # Call the parent constructor Level.__init__(self, player) self.background = pygame.image.load( "arts/graphics/beijing.png").convert_alpha() self.background = pygame.transform.scale(self.background, constants.screenSize) self.background.set_colorkey((255, 255, 255)) self.level_soundtrack = pygame.mixer.Sound("arts/audio/beijing.wav") # List of "fixed" obstacles, and x, y location of the obstacle. self.collection = [[obstacles.MASK1], [obstacles.MASK2], [obstacles.MASK3], [obstacles.BOOK], [obstacles.LUCKY_BAG], [obstacles.KNOT]] # Add the empire state building self.obstacle_type = obstacles.Obstacle([obstacles.TV_TOWER][0]) # fill it up self.fill_with_flying_obstacles(3) # Add a horizontally moving obstacle self.make_special_obstacle(obstacles.BOOK, -4, 0) # self.maximum = 5 self.maximum = 40
def __init__(self, player): """ Create level 3. """ # Call the parent constructor Level.__init__(self, player) self.background = pygame.image.load( "arts/graphics/Paris.png").convert_alpha() self.background = pygame.transform.scale(self.background, constants.screenSize) self.background.set_colorkey((255, 255, 255)) self.level_soundtrack = pygame.mixer.Sound("arts/audio/paris.wav") # List of "fixed" obstacles, and x, y location of the obstacle. self.collection = [[obstacles.CLOUD], [obstacles.CHEESE2], [obstacles.CROISSANT], [obstacles.BOTTLE], [obstacles.BREAD]] self.obstacle_type = obstacles.Obstacle([obstacles.TOWER][0]) # fill it up self.fill_with_flying_obstacles(2) # to make this level challenging self.make_special_obstacle(obstacles.PLANE, -3, -1) self.maximum = 20
def __init__(self, player): """ Create level 4. """ # Call the parent constructor Level.__init__(self, player) self.background = pygame.image.load( "arts/graphics/newyork.png").convert_alpha() self.background = pygame.transform.scale(self.background, constants.screenSize) self.background.set_colorkey((255, 255, 255)) self.level_soundtrack = pygame.mixer.Sound("arts/audio/new_york.wav") # List of "fixed" obstacles, and x, y location of the obstacle. self.collection = [[obstacles.TAXI], [obstacles.APPLE], [obstacles.HAT], [obstacles.BURGER], [obstacles.FRIES]] self.obstacle_type = obstacles.Obstacle([obstacles.STATUE_OF_LIBERTY ][0]) # fill it up self.fill_with_flying_obstacles(2) # to make this level challenging self.make_special_obstacle(obstacles.PLANE, -3, -1) self.make_ground_obstacle(self.obstacle_type) self.maximum = 30
async def fly_garbage(canvas, column, garbage_frame, speed=0.5): """Animate garbage, flying from top to bottom. Сolumn position will stay same, as specified on start.""" global obstacles, obstacles_in_last_collisions rows_number, columns_number = canvas.getmaxyx() height, width = get_frame_size(garbage_frame) column = max(column, 0) column = min(column, columns_number - 1) row = 0 obstacle = obs.Obstacle(row, column, height, width) obstacles.append(obstacle) while row < rows_number: if obstacle in obstacles_in_last_collisions: obstacles.remove(obstacle) obstacles_in_last_collisions.remove(obstacle) await explode(canvas, row + height / 2, column + width / 2) return draw_frame(canvas, row, column, garbage_frame) await asyncio.sleep(0) draw_frame(canvas, row, column, garbage_frame, negative=True) row += speed obstacle.row = row obstacles.remove(obstacle)
def reset(): global obs global bird try: canvas.delete(bird.image) for ob in obs: canvas.delete(ob.image[0]) canvas.delete(ob.image[1]) except: pass bird = objects.Bird(x0=1, y0=5, mass=2, vx=0, vy=0) bird.insert(canvas) obs = [ obstacles.Obstacle(x0=0.5 * constantes.width), obstacles.Obstacle(x0=0.75 * constantes.width), obstacles.Obstacle(x0=1 * constantes.width), obstacles.Obstacle(x0=1.25 * constantes.width) ] for ob in obs: ob.insert(canvas)
def fill_with_flying_obstacles(self, obstacles_density): # List of "fixed" obstacles, and x, y location of the obstacle. for i in range(obstacles_density): choice = random.choice(self.collection) self.obstacle_options.append(choice) # Go through the list above, add obstacles for i in self.obstacle_options: # should import obstacle class obstacle = obstacles.Obstacle(i[0]) obstacle.rect.x = random.randint(constants.SCREEN_WIDTH, constants.SCREEN_WIDTH * 2) obstacle.rect.y = random.randint(0, constants.SCREEN_HEIGHT / 2) obstacle.player = self.player self.obstacle_list.add(obstacle)
def __init__(self, player): """ Create level 1. """ # Call the parent constructor Level.__init__(self, player) self.background = pygame.image.load( "arts/graphics/level1.png").convert_alpha() self.background = pygame.transform.scale(self.background, constants.screenSize) self.background.set_colorkey((255, 255, 255)) self.level_soundtrack = pygame.mixer.Sound("arts/audio/level_one.wav") # List of "fixed" obstacles, and x, y location of the obstacle. self.collection = [[obstacles.CLOUD]] self.obstacle_type = obstacles.Obstacle([obstacles.MOUNTAIN][0]) # fill level with obstacles and add the ground obstacle self.fill_with_flying_obstacles(1)
def new(self): ''' Scanning the tmx map and assign elems to Classes''' self.obj_poss_loc = [] for tile_object in self.map.tmxdata.objects: if tile_object.name == 'player': self.player = player.Player(self, tile_object.x, tile_object.y) if tile_object.name == 'wall': self.wall = obstacles.Obstacle(self, tile_object.x, tile_object.y, tile_object.width, tile_object.height) if tile_object.name == 'boss': self.boss = boss.Boss(self, tile_object.x, tile_object.y, tile_object.width, tile_object.height) if tile_object.name == 'end': self.end = end.End(self, tile_object.x, tile_object.y, tile_object.width, tile_object.height) if tile_object.name == 'object': self.obj_poss_loc.append((tile_object.x, tile_object.y)) self.place_objects(['tube', 'ether', 'needle'])
def __init__(self, player): """ Create level 2. """ # Call the parent constructor Level.__init__(self, player) self.background = pygame.image.load( "arts/graphics/egypt.png").convert_alpha() self.background = pygame.transform.scale(self.background, constants.screenSize) self.background.set_colorkey((255, 255, 255)) self.level_soundtrack = pygame.mixer.Sound("arts/audio/egypt.wav") # List of "fixed" obstacles, and x, y location of the obstacle. self.collection = [[obstacles.HEAD], [obstacles.PYRAMID]] self.obstacle_type = obstacles.Obstacle([obstacles.MONUMENT][0]) # fill it up self.fill_with_flying_obstacles(1) self.make_ground_obstacle(self.obstacle_type) # to make this level challenging self.make_special_obstacle(obstacles.PLANE, -3, 0) self.maximum = 15
def run_the_map(): from msvcrt import getch from os import system import os import random import title_screen import obstacles import player import sys # TO DO LIST # 1) We need to add limitations to where the player can go. (The player can't go outside of the boundaries.. The game crashes if they do.) # 2) Under the check_the_spot(), add the cage code that will interact with the player when they hit a '#' the_map = [[ "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---" ], [ "| ", " ", " ", " ", " ", " ", " # ", " # ", " # ", " ", " ", " ", " ", " ", " ", " ", " ", " |" ], [ "| ", " # ", " ! ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " |" ], [ "| ", " # ", " ", " ", " ", " ", " ", " ! ", " ", " ", " ", " # ", " # ", " # ", " ", " ", " ", " |" ], [ "| ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ! ", " ", " ! ", " ", " |" ], [ "| ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " # ", " |" ], [ "| ", " ! ", " ", " ! ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " # ", " |" ], [ "| ", " # ", " ", " ", " ", " ! ", " # ", " ", " ! ", " # ", " ", " ", " ! ", " ", " ", " ", " # ", " |" ], [ "| ", " # ", " ", " ", " ", " ", " # ", " ", " ", " # ", " ", " ", " ", " ", " ", " ", " # ", " |" ], [ "| ", " # ", " ", " ", " ", " ", " ", " ", " ", " # ", " ", " ", " ", " ", " ", " ", " ! ", " |" ], [ "| ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " |" ], [ "| ", " ", " ", " ! ", " ", " ", " # ", " # ", " # ", " ", " ! ", " ", " # ", " # ", " # ", " # ", " ", " |" ], [ "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---" ], ["------------------ Legacy ------------------"], ["| '!' - Obstacle |"], ["| '#' - Animal Cage |"], ["| |"], ["| Game Instructions: Get to 50 Points. |"], ["| Use 'W' 'A' 'S' 'D' to move. |"], ["|__________________________________________|"], [" "]] def print_the_map(the_map): for each_row in the_map: print() for each_character in each_row: print(each_character, end="") row = 1 character = 1 the_map[row][character] = " X " print_the_map(the_map) ##added## player_location = "" obstacle_list = [] new_obstacle1 = obstacles.Obstacle("A cat meows at you.", "good") new_obstacle2 = obstacles.Obstacle("You found some coins on the ground!", "good") new_obstacle3 = obstacles.Obstacle( "A snake slithers around you... looking for prey.", "bad") new_obstacle4 = obstacles.Obstacle( "You stepped in dog poo! Your shoes are now dirty.", "bad") new_obstacle5 = obstacles.Obstacle( "A random chocolate bar was left here. It looks delicious!", "good") new_obstacle6 = obstacles.Obstacle( "Player:\t 'What is this random drink??? It's black!.....\nI think it's making me feel sick.'", "bad") new_obstacle7 = obstacles.Obstacle("A butterfly just flew past you.", "good") new_obstacle8 = obstacles.Obstacle( "You looked inside this barrel and found a lot of trash.", "bad") new_obstacle9 = obstacles.Obstacle( "Player:\t 'Is this a baseball card?\nGuess it is mine now.'", "good") new_obstacle10 = obstacles.Obstacle( "Player:\t 'It STINKS over here. Ugh...'", "bad") new_obstacle11 = obstacles.Obstacle( "The trash bin is located here. \nPlayer:\t 'Looks like the trash is full, gross.'", "bad") new_obstacle12 = obstacles.Obstacle( "You found a stray liter of newborn lizards!\nPlayer:\t 'I think I will just grab one of these lizards...for myself.'", "good") obstacle_list.append(new_obstacle1) obstacle_list.append(new_obstacle2) obstacle_list.append(new_obstacle3) obstacle_list.append(new_obstacle4) obstacle_list.append(new_obstacle5) obstacle_list.append(new_obstacle6) obstacle_list.append(new_obstacle7) obstacle_list.append(new_obstacle8) obstacle_list.append(new_obstacle10) obstacle_list.append(new_obstacle11) obstacle_list.append(new_obstacle12) print() def check_the_spot(player_location): print("\nPlayer Good Points: \t", player.new_player.good_points) print("\n") print("Player Bad Points: \t", player.new_player.bad_points, "\n") if player_location == " # ": animalList = [] file = FileReader.open_file("Animals.txt", "r") name, description, good, bad = AnimalList.next_block(file) while name: animal = Animal(name, description, good, bad) animalList.append(animal) name, description, good, bad = AnimalList.next_block(file) file.close() temp = random.choice(animalList) print("**--**--****--**--****--**--****--**--**") print() print(temp) print() print("**--**--****--**--****--**--****--**--**") user_input = "" while user_input not in ("0", "1"): user_input = input(animal_menu) if user_input == "0": player.new_player.add_good_points() else: player.new_player.add_bad_points() os.system('cls') print_the_map(the_map) print("\nPlayer Good Points: \t", player.new_player.good_points) print("\n") print("Player Bad Points: \t", player.new_player.bad_points, "\n") elif player_location == " ! ": obstacle_to_use = random.choice(obstacle_list) print() print(obstacle_to_use) if obstacle_to_use.stat == "good": obstacle_to_use.obstacle_add_good_points() else: obstacle_to_use.obstacle_add_bad_points() elif player_location > the_map[11][character]: print_border_msg() elif player_location == the_map[0][character]: print_border_msg() elif player_location > the_map[row][17]: print_border_msg() elif player_location == the_map[row][0]: print_border_msg() # player score if (player.new_player.good_points >= 50 or player.new_player.bad_points >= 50): # quiz time lady = AngryOldLady("AngryQuiz.txt") quest = lady.getQuestion() for i in range(5): os.system('cls') intro = quest[0] print("**~***~***~***~***~***~***~***") print() print(intro) question = quest[1] print(question) print() print("**~***~***~***~***~***~***~***") print() for i in quest[2]: print(i) correct = quest[3] incorrect = quest[4] quest = lady.getQuestion() user_quiz_input = "" while user_quiz_input not in ("1", "2", "3"): user_quiz_input = str(input(quiz_menu)) print() if user_quiz_input == correct: # Good lady.addGood() elif user_quiz_input == incorrect: # Bad lady.addBad() else: lady.addGood() if lady.getGoodPoints() > lady.getBadPoints(): ###### ADD CODE HERE ######## # print the good ending os.system('cls') print("**~***~***~*~*~*~~* ENDING ***~*~*~**~*~*~*") print() print(lady.gEnding) print() input("\nPress enter to exit.") sys.exit() else: ###### ADD CODE HERE ######## # print the bad ending os.system('cls') print("**~***~***~*~*~*~~* ENDING ***~*~*~**~*~*~*") print() print(lady.bEnding) print() input("\nPress enter to exit.") sys.exit() def print_border_msg(): print("HALT. DO NOT GO BEYOND THIS POINT.") print("EXECUTION IS LIKELY.") def move_up(): player_location = the_map[row - 1][character] the_map[row - 1][character] = " X " the_map[1][1] = " " os.system('cls') print_the_map(the_map) check_the_spot(player_location) return previous_char def move_down(): player_location = the_map[row + 1][character] the_map[row + 1][character] = " X " the_map[1][1] = " " os.system('cls') print_the_map(the_map) check_the_spot(player_location) return previous_char def move_left(): player_location = the_map[row][character - 1] the_map[row][character - 1] = " X " the_map[1][1] = " " os.system('cls') print_the_map(the_map) check_the_spot(player_location) return previous_char def move_right(): player_location = the_map[row][character + 1] the_map[row][character + 1] = " X " the_map[1][1] = " " os.system('cls') print_the_map(the_map) check_the_spot(player_location) return previous_char while (True): key = ord(getch()) if key == 119: previous_char = the_map[row - 1][character] move_up() row -= 1 the_map[row][character] = str(previous_char) elif key == 97: previous_char = the_map[row][character - 1] move_left() character -= 1 the_map[row][character] = str(previous_char) elif key == 115: previous_char = the_map[row + 1][character] move_down() row += 1 the_map[row][character] = str(previous_char) elif key == 100: previous_char = the_map[row][character + 1] move_right() character += 1 the_map[row][character] = str(previous_char) ###inserted code for saving and loading after this ############################################ ############################################ elif key == 107: print( str(row) + str(character) + str(player.new_player.good_points) + str(player.new_player.bad_points)) SaveAndLoader.save(row, character, player.new_player.good_points, player.new_player.bad_points) print("Game Saved!") elif key == 108: varList = [] varList += SaveAndLoader.load() row = int(varList.pop(0)) character = int(varList.pop(0)) print(varList) player.new_player.setGoodPoints = int(varList.pop(0)) print(player.new_player.good_points) print(varList) player.new_player.setBadPoints = int(varList.pop(0)) print(player.new_player.bad_points) print(varList) print("Game loaded")
def run_the_map(): from msvcrt import getch from os import system import os import random import title_screen import obstacles import player # TO DO LIST # 1) We need to add limitations to where the player can go. (The player can't go outside of the boundaries.. The game crashes if they do.) # 2) Under the check_the_spot(), add the cage code that will interact with the player when they hit a '#' the_map = [[ "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", " ", "----------- Legacy -------------" ], [ "| ", " ", " ", " ", " ", " ", " # ", " # ", " # ", " ", " ", " ", " ", " ", " ", " ", " ", " |", " ", "| |" ], [ "| ", " # ", " ! ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " |", " ", "| '!' - Obstacle |" ], [ "| ", " # ", " ", " ", " ", " ", " ", " ! ", " ", " ", " ", " # ", " # ", " # ", " ", " ", " ", " |", " ", "| '#' - Animal Cage |" ], [ "| ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ! ", " ", " ! ", " ", " |", " ", "| |" ], [ "| ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " # ", " |", " ", "| Use 'W' 'A' 'S' 'D' to move. |" ], [ "| ", " ! ", " ", " ! ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " # ", " |", " ", "|______________________________|" ], [ "| ", " # ", " ", " ", " ", " ! ", " # ", " ", " ! ", " # ", " ", " ", " ! ", " ", " ", " ", " # ", " |" ], [ "| ", " # ", " ", " ", " ", " ", " # ", " ", " ", " # ", " ", " ", " ", " ", " ", " ", " # ", " |" ], [ "| ", " # ", " ", " ", " ", " ", " ", " ", " ", " # ", " ", " ", " ", " ", " ", " ", " ! ", " |" ], [ "| ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " |" ], [ "| ", " ", " ", " ! ", " ", " ", " # ", " # ", " # ", " ", " ! ", " ", " # ", " # ", " # ", " # ", " ", " |" ], [ "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---" ]] def print_the_map(the_map): for each_row in the_map: print() for each_character in each_row: print(each_character, end="") row = 1 character = 1 the_map[row][character] = " X " print_the_map(the_map) obstacle_list = [] new_obstacle1 = obstacles.Obstacle("A cat meows at you.", "good") new_obstacle2 = obstacles.Obstacle("You found some coins on the ground!", "good") new_obstacle3 = obstacles.Obstacle( "A snake slithers around you... looking for prey.", "bad") new_obstacle4 = obstacles.Obstacle( "You stepped in dog poo! Your shoes are now dirty.", "bad") new_obstacle5 = obstacles.Obstacle( "A random chocolate bar was left here. It looks delicious!", "good") new_obstacle6 = obstacles.Obstacle( "Player:\t 'What is this random drink??? It's black!.....\nI think it's making me feel sick.'", "bad") new_obstacle7 = obstacles.Obstacle("A butterfly just flew past you.", "good") new_obstacle8 = obstacles.Obstacle( "You looked inside this barrel and found a lot of trash.", "bad") new_obstacle9 = obstacles.Obstacle( "Player:\t 'Is this a baseball card?\nGuess it is mine now.'", "good") new_obstacle10 = obstacles.Obstacle( "Player:\t 'It STINKS over here. Ugh...'", "bad") new_obstacle11 = obstacles.Obstacle( "The trash bin is located here. \nPlayer:\t 'Looks like the trash is full, gross.'", "bad") new_obstacle12 = obstacles.Obstacle( "You found a stray liter of newborn lizards!\nPlayer:\t 'I think I will just grab one of these lizards...for myself.'", "good") obstacle_list.append(new_obstacle1) obstacle_list.append(new_obstacle2) obstacle_list.append(new_obstacle3) obstacle_list.append(new_obstacle4) obstacle_list.append(new_obstacle5) obstacle_list.append(new_obstacle6) obstacle_list.append(new_obstacle7) obstacle_list.append(new_obstacle8) obstacle_list.append(new_obstacle10) obstacle_list.append(new_obstacle11) obstacle_list.append(new_obstacle12) print() def check_the_spot(player_location): print("\nPlayer Good Points: \t", player.new_player.good_points) print("\n") print("Player Bad Points: \t", player.new_player.bad_points, "\n") if player_location == " # ": # insert the animal/cage code here print("HELLO!!!") elif player_location == " ! ": obstacle_to_use = random.choice(obstacle_list) print() print(obstacle_to_use) if obstacle_to_use.stat == "good": obstacle_to_use.obstacle_add_good_points() else: obstacle_to_use.obstacle_add_bad_points() elif player_location > the_map[11][character]: print_border_msg() elif player_location == the_map[0][character]: print_border_msg() elif player_location > the_map[row][17]: print_border_msg() elif player_location == the_map[row][0]: print_border_msg() def print_border_msg(): print("HALT. DO NOT GO BEYOND THIS POINT.") print("EXECUTION IS LIKELY.") def move_up(): player_location = the_map[row - 1][character] the_map[row - 1][character] = " X " the_map[1][1] = " " os.system('cls') print_the_map(the_map) check_the_spot(player_location) return previous_char def move_down(): player_location = the_map[row + 1][character] the_map[row + 1][character] = " X " the_map[1][1] = " " os.system('cls') print_the_map(the_map) check_the_spot(player_location) return previous_char def move_left(): player_location = the_map[row][character - 1] the_map[row][character - 1] = " X " the_map[1][1] = " " os.system('cls') print_the_map(the_map) check_the_spot(player_location) return previous_char def move_right(): player_location = the_map[row][character + 1] the_map[row][character + 1] = " X " the_map[1][1] = " " os.system('cls') print_the_map(the_map) check_the_spot(player_location) return previous_char while (True): key = ord(getch()) if key == 119: previous_char = the_map[row - 1][character] move_up() row -= 1 the_map[row][character] = str(previous_char) elif key == 97: previous_char = the_map[row][character - 1] move_left() character -= 1 the_map[row][character] = str(previous_char) elif key == 115: previous_char = the_map[row + 1][character] move_down() row += 1 the_map[row][character] = str(previous_char) elif key == 100: previous_char = the_map[row][character + 1] move_right() character += 1 the_map[row][character] = str(previous_char)