def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.keysDown = [] self.label = pyglet.text.Label("test", font_name='Times New Roman', font_size=36, x=self.width // 2, y=self.height // 2, anchor_x='center', anchor_y='center') self.space = pymunk.Space() self.options = DrawOptions() self.score = 0 self.playerCar = car.Car(self.space) self.course = walls.Walls(self.space) self.coins = coins.Coins(self.space) self.fps = FPSDisplay(self) self.nearestCoinPos = self.coins.usedCoinPos[0] handler = self.space.add_collision_handler(1, 2) handler.begin = self.hitWall coinHandler = self.space.add_collision_handler(1, 3) coinHandler.begin = self.collectCoin
def create_board(): ''' Creates board and fills in Obstacles and Scenery ''' board = list() for i in range(int(defs.rows)): temp_list = list() for _ in range(defs.board_len): if i==0 or i==0: clouds.add_element(temp_list,fn=34) elif i==int(defs.rows)-1 : clouds.add_element(temp_list,fn=32) else: clouds.add_element(temp_list,cont=1) board.append(temp_list) defs.board_len-=int(defs.columns) # clouds.Clouds(100,board) defs.plain_board=copy.deepcopy(board) arcs.Arcs((2*int(defs.rows)//3+1),board) coins.Coins(100,board) powerup.Powerup(defs.board_len//5) enemy.Enemy(40) magnet.Magnet(200,10) # defs.board_len+=int(defs.columns) return board
def __init__(self, player): Level.__init__(self, player) level2 = [[40, 80, 300, 120], [40, 80, 700, 220], [40, 80, 400, 320], [40, 80, 500, 420], [40, 80, 200, 520], [40, 50, 800, 620], [40, 70, 200, 40], [40, 50, 650, 40], [40, 50, 650, 140], [40, 50, 100, 320], [40, 50, 100, 450]] level = [[1000, 1, 0, 0], [900, 1, 100, 699], [99, 30, 100, 40], [39, 30, 241, 40], [20, 39, 79, 0], [20, 39, 281, 0], [180, 30, 600, 40], [299, 30, 0, 120], [200, 30, 341, 120], [299, 30, 400, 220], [259, 30, 741, 220], [399, 30, 0, 320], [300, 30, 441, 320], [199, 30, 300, 420], [459, 30, 541, 420], [199, 30, 0, 520], [600, 30, 241, 520], [99, 30, 700, 620], [159, 30, 841, 620]] for plat in level: block = platform.Platform(plat[0], plat[1]) block.rect.x = plat[2] block.rect.y = plat[3] block.player = self.player self.platform_list.add(block) for lad in level2: block = ladder.Ladder(lad[0], lad[1]) block.rect.x = lad[2] block.rect.y = lad[3] self.ladder_list.add(block) for i in range(50): coin = coins.Coins(20, 20) coin.rect.x = random.randrange(1000) coin.rect.y = random.randrange(700) self.coins_list.add(coin) for j in self.platform_list: plat_coin_hit_list = pygame.sprite.spritecollide( j, self.coins_list, True) q = queen.Queen(30, 30) q.rect.x = random.randrange(100, 280) q.rect.y = 9 self.queen_list.add(q)
if 'tests' in os.getcwd(): sys.path.insert(0, os.path.join(os.getcwd(), '../')) elif 'Refactored' not in os.getcwd(): sys.path.insert(0, os.path.join(os.getcwd(), './Refactored/')) import coins import cake import scene import config import collectable_objects import bulletclass import clouds import poles HEIGHT, WIDTH = 37, 168 Coin = coins.Coins() Cakes = cake.Cakes() Mario = scene.Mario_map(HEIGHT, WIDTH) Mario.initialize() class Test_Objects: def test_powerup_problem(self): Mario.make_wall(HEIGHT - 8, WIDTH - 24, WIDTH - 12, config.char, 1) Cakes.set_position(HEIGHT - 8, WIDTH - 14) Cakes.draw(Mario.map_mario, HEIGHT - 10, WIDTH - 14) assert Mario.map_mario[HEIGHT - 10][WIDTH - 14] == "@" or Mario.map_mario[HEIGHT - 10][WIDTH - 14] == "$"
def start_game(screen): height, width = os.popen( 'stty size', 'r' ).read().split() #this obtains board size and width as dependent on the terminal size config.height = int( height ) - 8 config.width = int( width ) * 5 config.frame_width = int( width ) Coin = coins.Coins() Obs = obstacles.Obstacles() Bullets = bullets.Bullet() Mag=Magnet() ice=bullets.Bullet() screen.create_board( height, width, Coin, Obs, Mag ) player = hero.Hero( 4, 40 ) # creating hero with co ordinates config.time_left = 500 config.start_time = time() screen.refresh_screen( player,Bullets ) dragon_flag=0 Dragon=Villain(config.width-49,player.get_y()) itr=1 quitter=False while ((not game_state.is_game_over()) and (config.time_left > 0) and (not quitter)): player.gravity() player.magnet_effect(Mag.get_y(),Mag.get_start(),Mag.get_end()) #to put the effect of the magnet on the hero quitter=player.movehero( screen.get_screen(), Bullets) game_state.coin_check( screen.get_screen() ) game_state.place_bullets( screen.get_screen(), Bullets, Obs ,dragon_flag) config.time_left = 500-(time()-config.start_time) screen.refresh_screen( player ,Bullets) if config.start_col < 4 * int( width ): # for moving the board frame config.start_col += 1 + config.boost_speed else: #this takes place when in the last frame dragon_flag=1 Dragon.update(player.get_y(),ice,screen.get_screen()) game_state.place_ice(screen.get_screen(),ice,player) if config.boost_end_time <= time(): #to handle power ups if config.state == 'u': if config.boost_speed!=0: config.boost_speed = 0 elif config.shield!=0: config.shield=0 config.state = 'c' config.boost_end_time=time()+10 elif config.state=='c': config.boost_end_time=time()+10 config.state='r' itr+=1 if player.get_y()<config.height-3: config.hangtime+=1 if config.result == 1: print( "\nYOU WON !!!!!!!!! :)" ) else: print( "YOU LOST :( :( :(" ) print( "SCORE:- %d" % (config.score) )
def init_game(height, width, level): config.mario = scene.Mario_map(height, width) config.mario.initialize() config.enemy = [] config.coin = coins.Coins() config.cake = cake.Cakes() config.pistol = pistol.Pistol() config.flagger = flag_1.Flag(config.mario.map_mario) if level == 1: counter = 3 elif level == 2: counter = 4 #initialize enemies for i in range(0, counter - 2): for i in config.mario.boundary: enemy_original_y = i + randint(int(width / 2), width - 15) enemy_original_x = height - 4 config.enemy.append( small_enemy.enemy_1(enemy_original_x, enemy_original_y)) stable_set = ["#", "&"] #initialize clouds for i in config.mario.boundary: n = randint(counter, counter + 2) for count in range(0, n): cloud = clouds.Clouds(config.mario.map_mario) cloud_x, cloud_y = randint(30, 140) + i, randint(3, 5) cloud.update(n, cloud_y, cloud_x) config.clouds.append(cloud) #initialize pillars for i in config.mario.boundary: for count in range(0, counter): pole = poles.Poles(config.mario.map_mario) pole_x, pole_y = randint(int(width / 2), width - 15) + i, height - 4 pole.draw(pole_x, pole_y) config.poles.append(pole) #initialize stairs for count in range(0, 3): config.ending = ending.End(config.mario.map_mario) stair_x, stair_y = width * 6 + 20 + count * 21, height - 10 config.ending.draw_left(stair_x, stair_y, height, width) stair_x, stair_y = width * 6 + 31 + count * 21, height - 10 config.ending.draw_right(stair_x, stair_y, height, width) config.stair_coordinates.append([stair_x, stair_y]) #initialize coins for j in range(0, 4): for i in range(0, 6): k = randint(height - 14, height - 8) a = randint(int(width / 12), width - 24) b = a + 12 config.coin.set_position(k, a, randint(0, 13), config.mario.boundary[i]) config.coin.set_position(k, a, randint(0, 13), config.mario.boundary[i]) config.mario.make_wall(k, a, b, config.char, i) config.mario.make_wall(k - 1, a, b, config.char, i) if i % 3 == 0: cake_y, cake_x = k, a + randint(1, 11) + config.mario.boundary[i] config.cake.set_position(cake_y, cake_x) if i % 3 == 1: pistol_y, pistol_x = k, a + randint( 1, 11) + config.mario.boundary[i] config.pistol.set_position(pistol_y, pistol_x) #initialize variables config.x_flag = width * 6 + int(width / 2) + 30 config.y_flag = height - 14 config.flagger.draw_2(config.y_flag, config.x_flag) config.distance = 0 config.score = 0 config.index = 0 config.counter = 0 config.counter_back = 0 config.start_x = 0 os.system('clear') print("score- " + str(config.score) + " " + "distance- " + str(config.distance)) config.player = mario_player.Mario(int(height - 4), 0) config.player.draw(config.mario.map_mario) for items in config.enemy: items.draw(config.mario.map_mario) config.enemy_count.append(1) config.mario.print_map(int(width), int(height), config.start_x) config.final_height = height - 4 config.limit = 0 config.flag = 1 config.follow_coefficient = -1 config.game_over = False config.big_mario = False os.system('aplay -qN ./sound/theme.wav &')
def init_game(height, width, level): """gaurav""" config.mario = scene.Mario_map(height, width) config.mario.initialize() config.ENEMY = [] config.coin = coins.Coins() config.cake = cake.Cakes() config.pistol = pistol.Pistol() config.flagger = flag_1.Flag(config.mario.map_mario) if level == 1: counter = 3 elif level == 2: counter = 4 # initialize enemies for j in range(0, counter - 2): for i in config.mario.boundary: enemy_original_y = i + randint(int(width / 2), width - 15) enemy_original_x = height - 4 config.ENEMY.append( small_enemy.enemy_1(enemy_original_x, enemy_original_y)) for i in config.mario.boundary: number = randint(counter, counter + 2) for count in range(0, number): cloud = clouds.Clouds(config.mario.map_mario) cloud_x, cloud_y = randint(30, 140) + i, randint(3, 5) cloud.update(number, cloud_y, cloud_x) config.CLOUDS.append(cloud) # initialize pillars for i in config.mario.boundary: for count in range(0, counter): pole = poles.Poles(config.mario.map_mario) pole_x, pole_y = randint(int(width / 2), width - 15) + i, height - 4 pole.draw(pole_x, pole_y) config.POLES.append(pole) # initialize stairs for count in range(0, 3): config.ending = ending.End(config.mario.map_mario) stair_x, stair_y = width * 6 + 20 + count * 21, height - 10 config.ending.draw_left(stair_x, stair_y, height, width) stair_x, stair_y = width * 6 + 31 + count * 21, height - 10 config.ending.draw_right(stair_x, stair_y, height, width) config.STAIR_COORDINATES.append([stair_x, stair_y]) # initialize coins for j in range(0, 4): for i in range(0, 6): j = j temp = randint(height - 14, height - 8) air = randint(int(width / 12), width - 24) boom = air + 12 config.coin.set_position(temp, air, randint(0, 13), config.mario.boundary[i]) config.coin.set_position(temp, air, randint(0, 13), config.mario.boundary[i]) config.mario.make_wall(temp, air, boom, config.CHAR, i) config.mario.make_wall(temp - 1, air, boom, config.CHAR, i) if i % 3 == 0: cake_y, cake_x = temp, air + \ randint(1, 11)+config.mario.boundary[i] config.cake.set_position(cake_y, cake_x) if i % 3 == 1: pistol_y, pistol_x = temp, air + \ randint(1, 11)+config.mario.boundary[i] config.pistol.set_position(pistol_y, pistol_x) # initialize variables config.X_FLAG = width * 6 + int(width / 2) + 30 config.Y_FLAG = height - 14 config.flagger.draw_2(config.Y_FLAG, config.X_FLAG) config.DISTANCE = 0 config.SCORE = 0 config.INDEX = 0 config.COUNTER = 0 config.COUNTER_BACK = 0 config.START_X = 0 os.system('clear') print("score- " + str(config.SCORE) + " " + "distance- " + str(config.DISTANCE)) config.player = mario_player.Mario(int(height - 4), 0) config.player.draw(config.mario.map_mario) for items in config.ENEMY: items.draw(config.mario.map_mario) config.ENEMY_COUNT.append(1) config.mario.print_map(int(width), int(height), config.START_X) config.FINAL_HEIGHT = height - 4 config.LIMIT = 0 config.FLAG = 1 config.follow_coefficient = -1 config.GAME_OVER = False config.BIG_MARIO = False os.system('aplay -qN ./sound/theme.wav &')