def main(): print("Use 'w' for Jump") print("Use 'd' to move right") print("Use 'a' to move left") print("Choose Level:\nAvailable Options: 1,2") level = input() sys.stdin.flush() while (level != "1" and level != "2"): print("Choose valid Level:") level = input() os.system("clear") print("\t\t\t\tINITIALIZING:") time.sleep(1) mario = Mario() bd = Board(level) bd.init_board() bullet = bullets(mario, bd) # nature.append(ghost1) frame_no = bd.frame while (frame_no < 395): ch = config.get_input() if (ch == 'a' or ch == 'd'): bd.move_mario(mario, ch, 1, bullet) elif (ch == 'f'): if (mario.st == 3): bullet.spawn(mario, bd) elif (ch == 'w'): timer = 12 bd.jump_mario(mario, ch, timer, bullet) if (ch == 'z'): exit() bd.print_board(mario.pos_x, mario.pos_y, mario)
def jump_mario(self, mario, ch, timer, bullet, cond=1): while (self.array[mario.pos_x + 1][mario.pos_y] == ' ' or cond == 1 or self.array[mario.pos_x + 1][mario.pos_y] == "G" or self.array[mario.pos_x + 1][mario.pos_y] == "!"): cond = 0 check_t = 0 if (timer > 6): if (mario.medium == 0): mario.pos_x -= 1 else: mario.pos_x -= 2 if (self.array[mario.pos_x - mario.st][mario.pos_y] != ' '): next_piece = self.get_at(mario.pos_x - mario.st, mario.pos_y) obstacle = Obstacle() if (obstacle.process(self, mario, next_piece, bullet) == "break"): self.array[mario.pos_x - mario.st][mario.pos_y] = " " else: mario.pos_x += 1 timer = 13 - timer self.print_board(mario.pos_x, mario.pos_y, mario) else: self.print_board(mario.pos_x, mario.pos_y, mario) else: mario.pos_x += 1 next_piece = self.get_at(mario.pos_x, mario.pos_y) if (next_piece != "!"): mario.medium = 0 if (self.array[mario.pos_x][mario.pos_y] != " "): next_piece = self.get_at(mario.pos_x, mario.pos_y) obstacle = Obstacle() if (obstacle.process(self, mario, next_piece, bullet) != "kill"): cond = 0 mario.pos_x -= 1 else: for object in self.nature: if (object.pos_x - 1 == mario.pos_x and object.pos_y == mario.pos_y): object.on_hit(self, mario, bullet) self.print_board(mario.pos_x, mario.pos_y, mario) else: self.print_board(mario.pos_x, mario.pos_y, mario) ch = config.get_input() if (ch != 'w'): if (ch == 'f'): bullet.spawn(mario, bd) else: cond = 0 self.move_mario(mario, ch, cond, bullet) timer -= 1 return
def check_input(character): if global_var.lives <= 0: global_var.quit_flag = 1 return event = config.get_key(config.get_input()) if event == config.LEFT: character.check_left() elif event == config.RIGHT: character.check_right() elif event == config.QUIT: global_var.quit_flag = 1 return reset_scenery()
def main(): """ Game Engine """ os.system('tput reset') screen_height, screen_width = ROWS - 2 * MARGINY, COLUMNS - 2 * MARGINX board = Board(screen_height, screen_width) board.add_game(Enemy(screen_height, screen_width)) board.add_game(Mario(screen_width, screen_height)) i = 8 while i: board.add_game( Brick(screen_height, screen_width, randint(4, screen_width - 5))) i = i - 1 i = 5 while i: board.add_game( Cloud(screen_height, screen_width, randint(4, screen_width - 6))) i = i - 1 sys.stdout.write(Style.BRIGHT + Back.YELLOW + pos(2, 0) + "SUPER MARIO".center(COLUMNS)) board.render() game_on = True char = " " while game_on: board.player[0].scoreboard.show_score() board.player[0].move(char, board) board.update_enemys() board.update_bullets() if char == 'q': sys.stdout.write(Back.RED + pos(ROWS - 2, 0) + "We got a quitter".center(COLUMNS)) game_on = False char = get_input() board.add_more() board.player[0].scoreboard.score_update("time")
def main(): game = Canvas(DIMENS['Canvas'][0], DIMENS['Canvas'][1]) start_t = datetime.datetime.now() time_now = start_t while ((datetime.datetime.now() - start_t) <= datetime.timedelta(seconds=TIMELIMIT)): input_ = get_input() game.update_frame() game.rerender() timeleft = (TIMELIMIT - (datetime.datetime.now() - start_t).seconds) print("""print 'q' to quit the game {} {}""".format(input_, timeleft)) if input_ == 'q': exit(0) exit(0)
def addObjectList(bd, level_name, *names): for name in names: bd.at = 0 completeName = os.path.join(dir_path + level_name, name + ".txt") file = open(completeName, "w") ob = makeObject(name) mk = objects.Marker(ob, ob.width, ob.height, 60, 30) bd.add(mk, mk.x, mk.y) while True: bd.clear(config.show_width) addobjects(bd, brick, enemy, goomba, spikey, stalker, spring, coin, cloud, specialbrick, boss, castle) bd.add(mk, mk.x, mk.y) os.system('clear') bd.show(config.show_width, config.show_height) event = config.get_key(config.get_input()) if event == config.QUIT: break elif event == config.SHOOT: bd.add(mk, mk.x, mk.y) file.write(str(mk.x) + ',' + str(mk.y) + '\n') lists[name].append(makeObject(name, mk.x, mk.y)) else: mk.move(event) bd.move(event, mk.width) bd.add(mk, mk.x, mk.y) bd.remove(mk, mk.x, mk.y) bd.at = 0
def main(): try: height, width = tuple(map(int, rd[1:3])) except BaseException: height, width = (34, 76) a = 'r' while a == 'r': try: level = int(input("Choose level [[1], 2, 3] :")) if level not in [0, 1, 2, 3]: raise Exception except BaseException: level = 1 # make the board and player bd = board.Board(height, width, level) player = people.Bomber( 5, 3, config.lives[level], config.bombs[level]) # always spawns at top left # spawning the player on the board bd.spawn(player) print("Initializing enemies, bricks ...") if not (spawn(config._enemy, config.enemies[level], bd) and spawn(config._bricks, config.bricks[level], bd)): print("Object Spawn Error") return False print("Objects spawned successfully", "Rendering board", sep="\n") sleep(1) bd.render() is_clean = False p_input = -1 # main loop which renders the game st_time = datetime.datetime.now() prev_round = datetime.datetime.now() while (datetime.datetime.now() - st_time) <= \ datetime.timedelta(seconds=config.timelimit[level]): print(config.printcc("'q' : quit | 'b' : drop bomb || Lives ", 'Gray') + config.printcc('%s' % (player.lives * '♥ '), 'Red') + config.printcc('| Bombs ', 'Gray') + config.printcc('%s' % (player.bombs * '💣 '), 'Dark Gray') + config.printcc("| T : %d " % (config.timelimit[level] - (datetime.datetime.now() - st_time).seconds), 'Gray')) try: bd.is_over(player) except Exception as exc: print(config.printcc(exc.args[0], 'Gray')) is_clean = True break p_input = config.get_key(config.get_input()) if p_input == config.QUIT: break cur_round = datetime.datetime.now() bd.process_input(player, p_input) if (cur_round - prev_round) >= datetime.timedelta(seconds=1): bd.update_frame() prev_round = cur_round bd.render() if not is_clean: print(config.printcc("TIME UP!", 'Gray')) bd.clear_storage() for c, player in enumerate(bd.players): print( config.printcc( "Player %d score : %d" % (c, player.score), 'White')) sleep(3) print( config.printcc( "Press ANY KEY to exit | Press 'r' to restart", 'Gray')) a = config._getch() system('reset')
common.restart_all() config.LIVES = 10 # if mario goes below the floor LEVEL if config.M != "" and config.M.y_pos > common.MIDS_R: raise config.DeadMario # create the scene depending on the LEVEL create_scenery.create_scene() if config.M != "": if Char != config.JUMP: create_scenery.check_floor() common.print_all() # get input from user Char = config.get_key(config.get_input()) if Char == config.QUIT: # shut down all [q] config.STAGE = "quit" common.game_over() if Char == config.START: # create a Person [m] sound.play_sound("mb_new.wav") create_scenery.create_mario() elif Char == config.BREAK: # break the loop [s] os.system("tput reset") break
import board import objects import datetime import config from board import * from config import * ''' Main file for running the code ''' bd = board.Board() p_input = -1 while (True): global lives p_input = config.get_key(config.get_input()) if p_input == config.QUIT: # if input is q, quit the game break # Calling collision function bd.CollisionMarioPipe() bd.process_input(p_input) bd.insert() bd.printIt() flag1 = bd.CollisionMarioBrick() flag = bd.CollisionMarioEnemy() flag2 = bd.CollisionMarioSmartEnemy() bd.CollisionMarioCoin() bd.CollisionMarioSpring() if bd.youWin(): break if board.t == 0: bd.gameOver()
def main(): height, width, buff_width = (40, 80, 400) level = 1 bd = board.Board(height, width, buff_width, level) mario = person.Player((height - 6), 7, 1, 3, bd, level) enemies = [] objects = [] objects_y = [] scene = [] coins = [] make_scene(scene, bd, mario) make_objects(objects, bd, mario, objects_y) put_coins(coins, bd) os.system('clear') bd.init_board(mario) for sc in scene: sc.draw(bd) for c in coins: c.draw(bd) for ob in objects: ob.draw(bd) mario.drawPlayer(bd) spawn(enemies, 2, bd, mario, objects_y) config.print_screen(level, bd, mario, enemies, objects, scene, coins) prev_round = datetime.datetime.now() while (True): cur_round = datetime.datetime.now() if (cur_round - prev_round) >= datetime.timedelta(seconds=0.1): for en in enemies: en.moveEnemy(mario, bd) if bd.buff[en.x + 2][en.y] == " " and bd.buff[en.x + 2][en.y] == " ": enemies.remove(en) if (bd.buff[mario.x][mario.y] == "e") and (bd.buff[mario.x + 1][mario.y] == "e"): en.killPlayer(mario, bd, mario.x, mario.y, enemies) elif (bd.buff[mario.x][mario.y + 1] == "e") and (bd.buff[mario.x + 1][mario.y + 1] == "e"): en.killPlayer(mario, bd, mario.x, mario.y + 1, enemies) if len(enemies) < 2: spawn(enemies, 1, bd, mario, objects_y) config.print_screen(level, bd, mario, enemies, objects, scene, coins) prev_round = cur_round inp = config.get_input() if inp == "q": mario.gameOver(bd, enemies, "GAME ENDED") if bd.buff[mario.x + 2][mario.y + 1] == " " and bd.buff[ mario.x + 2][mario.y + 2] == " ": mario.jump(bd, -2, 1, enemies, objects, scene, coins) else: mario.moveRight(bd) elif (inp == "d"): if bd.buff[mario.x + 2][mario.y + 1] == " " and bd.buff[ mario.x + 2][mario.y + 2] == " ": mario.jump(bd, -2, 1, enemies, objects, scene, coins) else: mario.moveRight(bd) elif (inp == "a"): if bd.buff[mario.x + 2][mario.y] == " " and bd.buff[mario.x + 2][mario.y - 1] == " ": mario.jump(bd, -2, -1, enemies, objects, scene, coins) else: mario.moveLeft(bd) elif (inp == "w"): subprocess.Popen(['aplay', './Sounds/mb_jump.wav']) os.system('clear') mario.jump(bd, 2, 0, enemies, objects, scene, coins) for i in range(2): for j in range(2): x = mario.x + i y = mario.y + j if bd.buff[x][y] == "$": mario.earnCoins() subprocess.Popen(['aplay', './Sounds/mb_coin.wav']) os.system('clear') for c in coins: if c.x == x and c.y == y: coins.remove(c) if c.x == x and c.y + 1 == y: coins.remove(c) break if mario.y >= 355: mario.gameOver(bd, enemies, "CONGRATS!! YOU HAVE WON!!") if mario.play_time() == 100: mario.gameOver(bd, enemies, "TIME OVER. YOU LOST. BETTER LUCK NEXT TIME.") config.print_screen(level, bd, mario, enemies, objects, scene, coins)
def main(): height, width = (24, 76) quit = False won = False print("Waking up Mario ...") sleep(2) print("Yay, he woke up!") print("Now, waking up your enemies ...") a = 'r' while a == 'r': bd = board.Board(24, 400) player = person.Mario(3, height - 3, 3) # while (player.lives > 0): bd.spawn(player) ls = spawn(config._enemy, bd) # ck = spawn_coins(config._coin, bd) if ls == False: # or ck == False: print("Object Spawn Error") return False print("Objects spawned, your enemies have been born\n") print("Rendering Board ...") sleep(3) bd.render(0, 76) x = 0 p_input = -1 st_time = datetime.datetime.now() prev_round = datetime.datetime.now() while (datetime.datetime.now() - st_time) <= datetime.timedelta(seconds=100): # while a=='r': sys.stdout.write(Fore.BLUE + "'q' : quit || Lives " + Fore.RED + '%s' % (player.lives * '♥ ')) sys.stdout.write(' || ' + Fore.BLUE + "Time : %d" % (100 - (datetime.datetime.now() - st_time).seconds)) try: bd.gameover(player) except Exception as exc: print(exc.args[0]) break print(Style.RESET_ALL) p_input = config.get_key(config.get_input()) if p_input == config.QUIT: print(Fore.BLUE + "Quitting game because you're a sore loser ...") print("Resetting your clock ...") print(Style.RESET_ALL) quit = True break cur_round = datetime.datetime.now() if (cur_round - prev_round) >= datetime.timedelta(seconds=1): bd.update_frame() prev_round = cur_round if p_input == config.UP: i = 3 while i > 0: bd.process_input(player, config.UP) bd.render(x, x + 76) inter_input = config.get_key(config.get_input()) if inter_input == config.LEFT or inter_input == config.RIGHT or inter_input == config.UP: bd.process_input(player, inter_input) # sleep(0.1) i = i - 1 '''while i > 0: if i == 2: sleep(0.2) bd.process_input(player, config.DOWN) bd.render() # inter_input = config.get_key(config.get_input()) # bd.process_input(player, inter_input) # bd.render() sleep(0.1) i = i - 1''' '''while player.get_ycoords()+2 != 23: # print(player.get_ycoords()) bd.process_input(player, config.DOWN) bd.render() sleep(0.1) ''' # cur_round = datetime.datetime.now() if p_input == config.LEFT or p_input == config.RIGHT: bd.process_input(player, p_input) try: bd.gameover(player) except Exception as exc: sys.stdout.write(exc.args[0]) break for _ in bd._storage[config.types[config._enemy]]: while _.get_ycoords() + 2 != 23: res = bd.process_input(_, config.DOWN) if res == False: break while player.get_ycoords() != 23: # print(player.get_ycoords()) res = bd.process_input(player, config.DOWN) if res == False: break bd.render(x, x + 76) res = bd.process_input(player, config.DOWN) sleep(0.1) if player.get_ycoords() == 23: player.lives -= 1 try: bd.gameover(player) except Exception as exc: sys.stdout.write(exc.args[0]) break if player.get_xcoords() >= 360: won = True sys.stdout.write(Fore.RED + Style.BRIGHT + Back.BLACK + "YOU BEAT THE GAME") print(Style.RESET_ALL) break # sleep(0.1) # bd.render() """ if (cur_round - prev_round) >= datetime.timedelta(seconds=1): # bd.update_frame() # prev_round = cur_round""" bd.render(x, x + 76) if player.get_xcoords() > (x + 38): x = x + 6 bd.render(x, x + 76) if player.lives > 0 and won == False: sys.stdout.write(Fore.BLUE + "TIME'S UP\n") sleep(2) bd.clear_storage() player.score = ( 100 - (datetime.datetime.now() - st_time).total_seconds()) * 384 for player in bd.players: if quit: sys.stdout.write(Fore.RED + "PLAYER SCORE: 0") else: sys.stdout.write(Fore.RED + "PLAYER SCORE: %d" % player.score) print(Style.RESET_ALL) print("Press 'r' to RESTART") a = config._getch() system('reset')
def main(): lives = 3 reply = input('Do want to make your own level?(y/n) ') if reply == "y": level_name = input('What do you want to name your cutom level? ') levelGenerator.makeLevel(level_name) level_name = input('Please enter level name: ') while lives: tme = 360 + int(time.time()) clearLists(specialbrick, brick, enemy, spring, coin, cloud, castle, boss) bd = board.Board(config.board_width, config.board_width) try: loadLevel(level_name, "brick", "spring", "goomba", "stalker", "spikey", "boss", "castle", "cloud", "coin", "specialbrick") except: print("No such level exists") exit() mario = objects.Player(2, 2, 54, 15) bd.at = 0 while True: bd.clear(config.show_width) levelGenerator.addobjects(bd, brick, enemy, spring, coin, cloud, specialbrick, boss, castle) bd.add(mario, mario.x, mario.y) collisionCheck.bossFight(enemy, boss, bd, mario) collisionCheck.enemyCollision(enemy, enemy, mario, bd) collisionCheck.enemyCollision(boss, boss, mario, bd) collisionCheck.updateEnemy(boss, bd, mario.x, brick, spring) collisionCheck.updateEnemy(enemy, bd, mario.x, brick, spring) collisionCheck.brickCollision(brick, mario, bd) collisionCheck.specialbrickCollision(specialbrick, mario, bd) collisionCheck.springCollision(spring, mario, bd) collisionCheck.coinCollision(coin, mario, bd) if mario.hp <= 0 or mario.y > config.show_height or int( tme - time.time()) <= 0: lives -= 1 break if mario.x >= castle[0].x: print("YOU WIN \t TOTAL SCORE:", mario.score + int(tme - time.time())) lives = 0 break os.system('tput reset') bd.show(config.show_width, config.show_height) print("LIVES:", lives, "\t", "HEALTH:", mario.hp, "\t", "SCORE:", mario.score, "\t", "TIME LEFT:", int(tme - time.time())) event = config.get_key(config.get_input()) if event == config.QUIT: lives = 0 break if mario.move(event) == "move": bd.move(event, 1) print("GAME OVER")