def key_checker(self): getch = Get() start = 0 while True: key_input = input_to(getch) if key_input == 'q': show_cursor() os.system('killall aplay') os.system('clear') sys.exit() if key_input == 'd': if time.time() - start > 0.1: start = time.time() next_input = input_to(getch) if next_input == 'w': os.system('aplay -q sound/small_jump.wav &') os.system('clear') cur = self.player.get_position() if cur['x'] < 37: self.player.jumpscene(1) else: self.player.jumpscene() else: self.player.move(2) elif key_input == 'a': if time.time() - start > 0.1: start = time.time() next_input = input_to(getch) if next_input == 'w': os.system('aplay -q sound/small_jump.wav &') os.system('clear') self.player.jumpscene(-1) else: self.player.move(-2) elif key_input == 'w': os.system('aplay -q sound/small_jump.wav &') os.system('clear') if time.time() - start > 0.1: start = time.time() next_input = input_to(getch) if next_input == 'd': cur = self.player.get_position() if cur['x'] < 37: self.player.jumpscene(1) else: self.player.jumpscene() elif next_input == 'a': self.player.jumpscene(-1) else: self.player.vertical_jump(4) self.render()
def main_screen(self): os.system("clear") os.system('aplay -q ./sounds/main.wav&') self.screen.reset_screen() self.screen.add_to_game_screen(self.my_arjun) self.screen.add_to_game_screen(self.my_brickbreaker) self.screen.add_to_game_screen(self.my_press) self.screen.print_game_screen() while True: self.screen.reset_screen() self.screen.add_to_game_screen(self.my_arjun) self.screen.add_to_game_screen(self.my_brickbreaker) self.screen.add_to_game_screen(self.my_press) self.screen.print_game_screen() c = input_to(self.getch) if (c == "q"): os.system("clear") quit() if (c == 'x'): break if (c == "i"): self.instructions() os.system("clear")
def handle_keyboard_interrupt(self): get = Get() ch = input_to(get.__call__) if ch in KEYS: self._paddle.move(ch) # if(self._level==2): # self._ufo.move(ch) # fixed for ball in self._balls: ball.move_with_paddle(ch) elif (ch == 'q'): sys.exit() elif (ch == 's'): for ball in self._balls: ball.start() elif (ch == 'r'): self._paddle = Paddle([int(self._width / 2) - 4, self._height - 1], [13, 1], [0, 0], [self._width, self._height]) self._balls = [] self._balls.append( Ball([int(self._width / 2), self._height - 2], [1, 1], [0, 0], [self._width, self._height], True)) elif (ch == 'l'): self.level_up()
def run(self): '''Function to run the main game loop ''' getch = Get() while True: input = input_to(getch) if input is not None: if input is 'd': self.right() elif input is 'a': self.left() elif input is 'w': self.up() elif input is 's': self.down() elif input is 'q': self.quit() elif input is ' ': self.space() else: if self.__screen.x_cross > 1245 or self.__magnetpresent: self.degravity() else: self.gravity() # os.system('clear') self.update() self.render() time.sleep(0.02)
def __level_two_run(self): while self.lives > 0: input = input_to(self.getch) self.__game_updates() if not (self.done): self.__final_fight() if self.done: print(self.mario.x) if self.done and self.mario.x >= 227: os.system('aplay -q ../assets/smb_world_clear.wav &') os.system('clear') print("You Won") print("SCORE : " + str(round(self.mario.score))) sys.exit() if not (self.done): if self.Goblin.health <= 0: self.mario.score += 200 self.Goblin.remove_person(self.win) self.done = True del self.Goblin if not (self.done): self.Goblin.attack(self.mario, self.win) self.__ground_move(input, False, False) self.__jump_move(input, False, False) self.y_collisions.check_ground(self.mario, self.pipes, self.boxes) self.__goDown_move(input, False) if not (self.done): self.__frame_updates(self.Goblin) else: self.__frame_updates()
def gameloop(self): while(self.current_board.game_on==1): c=input_to(getch) if c=='q': system("killall vlc") sys.exit(0) if c=='a' or c=='d': self.current_board.moveboardpaddle(c) if c==' ': self.current_board.releaseballs() if c=='s': self.current_board.game_on=0 system("killall vlc") if c=='p': input() if c is not None: time.sleep(0.05) self.current_board.shoot_bullets() self.current_board.detectbulletcollision() self.current_board.moveballs() self.current_board.droppows() self.current_board.detectcollisionballs() self.current_board.reducepows() self.current_board.changehardnessbrick() self.current_board.createbombs() self.current_board.dropbombs() # self.current_board.spawnblocks() self.current_board.increment_frame() self.current_board.printboard()
def gravity(self, boardA, en=None): """Bring Mario down if the ground is empty below him""" try: while (not (self.ground_check(boardA))): self._x += 1 for wi in range(self._dim[1]): boardA.change(self._x - 1, self._y + wi, '.') getch = Get() chbuff = input_to(getch) if (chbuff): self.move(chbuff, boardA) if (en): for e in en: e.graze(boardA) e.render(boardA) self.render(boardA) os.system('clear') print(boardA.printBoard()) print(boardA.count()) self._jump_flag = 0 except: self.deadf() return
def user_input(self): ''' Getting input from the user for paddle movement ''' ch = Get() ch1 = input_to(ch, self.ball.skip_iteration_tp) if ch1 == 'a' or ch1 == 'A': self.paddle.move_left() self.ball.move_with_paddle() elif ch1 == 'd' or ch1 == 'D': self.paddle.move_right() self.ball.move_with_paddle() elif ch1 == 'q' or ch1 == 'Q': quit() elif ch1 == 'p' or ch1 == 'P': self.ball.next_shape() elif ch1 == 'i' or ch1 == 'I': self.ball.speedx == 2 self.ball.speedy == 2 elif ch1 == 'k' or ch1 == 'K': self.ball.speedx == 1 self.ball.speedy == 1 elif ch1 == 'c' or ch1 == 'C': self.ball.expand_paddle_effect() elif ch1 == 'v' or ch1 == 'V': self.ball.shrink_paddle_effect() elif ch1 == 'b' or ch1 == 'B': self.ball.default_paddle_effect() elif ch1 == ' ': self.ball.flip_stick(False)
def user_input(self): c = input_to(self.getch, 0.1) if (c == "a"): self.paddle.move(self.paddle.get_x() - self.paddle.get_xv()) if self.level == 3: self.ufo.move(self.paddle.get_x() - self.paddle.get_xv()) for ball in self.balls: if not ball.should_move(): ball.move(ball.get_x() - self.paddle.get_xv(), ball.get_y()) if (c == "d"): self.paddle.move(self.paddle.get_x() + self.paddle.get_xv()) if self.level == 3: self.ufo.move(self.paddle.get_x() + self.paddle.get_xv()) for ball in self.balls: if not ball.should_move(): ball.move(ball.get_x() + self.paddle.get_xv(), ball.get_y()) if (c == "r"): for ball in self.balls: if not ball.should_move(): ball.flip_move() if (c == "p"): self.pause_screen() if (c == "q"): os.system("clear") quit() if (c == "l"): self.skip_level = True if (c == "s"): if (self.paddle.get_shoot_time() and self.paddle.last_shoot >= 8): self.paddle.last_shoot = 0 self.bullets.append( Bullet(self.paddle.get_x(), self.paddle.get_y() - 1))
def _loopGame(self): paddleobj = [] ballobj = [] brickobj = [] powerupobj = [] bulletobj = [] cannonobj = [] flag = 0 while (self.status()): if self.leveling(brickobj, paddleobj) == 0: self.levels -= 1 num = 3 - self.levels paddleobj, ballobj, brickobj, powerupobj, cannonobj, bulletobj = self.fillthescreen( paddleobj, ballobj, brickobj, powerupobj, cannonobj, bulletobj, num) getch = Get() ch = input_to(getch, 0.1) if ch == 'e': flag = 1 break # if ch=='k': # bulletobj.append(Bullet(FRAMEHEIGHT-4,int(FRAMEWIDTH/2),1,1,-1,0)) if (ch == 'f'): for i in ballobj: i.isCollidedWithPaddle = False print("\033[0;0H") self._update(ballobj, paddleobj, ch, brickobj, powerupobj, bulletobj, cannonobj) self.checkBricks(brickobj, powerupobj) self.checkBall(ballobj, paddleobj) self.checkPowerupIsCollided(powerupobj) self.checkBullets(bulletobj, cannonobj, paddleobj) self._scores(paddleobj) self._printGame() if ch == 's': self.levels -= 1 num = 3 - self.levels paddleobj, ballobj, brickobj, powerupobj, cannonobj, bulletobj = self.fillthescreen( paddleobj, ballobj, brickobj, powerupobj, cannonobj, bulletobj, num) print(f'Skipped level{3-self.levels-1}') if self.levels == -1: flag = 2 break if flag: print("You Exited") print(f"With Score {paddleobj[0].get_score()}") if flag == 2: print("You completed all levels") print(f"With Score {paddleobj[0].get_score()}") else: if (self.lives == 0): os.system('aplay -q ./sounds/lost.wav&') print("You Lost") print(f"With Score {paddleobj[0].get_score()}") else: print("You Won") print(f"With Score {paddleobj[0].get_score()}")
def start(self): while True: #os.system("aplay -q Theme-Ringtone.mp3 &") input = input_to(self.getch) self.board.Print(self.player, self.tort1, self.bossE) print('Press q to quit') if self.player.x > 118: print('Level 2') else: print('Level 1') if input is not None: self.player.move(input, self.tort1, self.bossE) self.player.Jump(self.tort1, self.bossE) self.tort1.sideChange() self.tort1.movetort() if self.player.x >= 118: if self.player.jump == False: self.bossE.sideChange(self.player) self.bossE.moveBossE() else: self.bossE.moveBossE() if self.bossE.x <= 160: self.bossE.x = 160 self.bossE.sideChange(self.player) elif self.bossE.x >= 250: self.bossE.x = 250 self.bossE.sideChange(self.player) if self.player.x + 43 >= self.bossE.x - 2 and self.player.x - 37 <= self.bossE.x + 2 and self.player.y == 0 and self.player.prevjump == False and time.time() - self.player.time >= 2: # for boss killing if self.bossE.remove == 0: self.player.health = self.player.health - 1 self.player.time = time.time() if self.player.prevjump == False and self.player.x + 3 >= self.tort1.x - 1 and self.player.x - 3 <= self.tort1.x + 1 and self.player.y == 0 and time.time() - self.player.time >= 2: # for tort killing if self.tort1.remove == 0: self.player.health = self.player.health - 1 self.player.time = time.time() print("Player Live(s) Left:") print(self.player.health) print("Boss Enemy Live(s) Left:") print(self.bossE.health) print("Player Score:") print(self.player.score) print(self.player.x) print(self.player.y) if self.bossE.remove == 1 and self.tort1.remove == 1: print('Game Over: You won !') sys.exit() if self.player.health == 0: print('Game Over: You lost !') sys.exit() if self.bossE.remove == 1 and self.tort1.remove == 0: print('Go back and kill the Tortoise') if input == 'q': os.system('clear') sys.exit()
def run(self): '''Function to run the main game loop ''' playsound('resources/main_theme.wav') getch = Get() while True: self.FRAMES += 1 input = input_to(getch) if input is not None: if input is 'd': if self.mario.x + self.mario.width < self.screen.x_cross + 108 / 2: clear_sprite(self.mario, self.screen) if not self.mario.check_right_collision_with_map( self.screen): self.mario.x += self.mario.dx elif self.screen.x_cross >= 864: clear_sprite(self.mario, self.screen) if not self.mario.check_right_collision_with_map( self.screen): self.mario.x += self.mario.dx else: if not self.mario.check_right_collision_with_map( self.screen): self.screen.x_cross += self.mario.dx clear_sprite(self.mario, self.screen) self.mario.x += self.mario.dx elif input is 'a': clear_sprite(self.mario, self.screen) if not self.mario.check_left_collision_with_map( self.screen): self.mario.x -= self.mario.dx elif input is 'w': playsound('resources/jump.wav') if self.mario.check_bottom_collision_with_map(self.screen): clear_sprite(self.mario, self.screen) self.mario.y -= 3 self.mario.mario_jump() elif input is 'q': self.quit() if self.mario.check_hit_flagpole(self.flagpole): self.cue_end_animation() if self.mario.lives <= 0: self.cue_lost_card() os.system('clear') self.update() self.render(self.MOVE_BG) time.sleep(0.02)
def instructions(self): os.system("clear") text_string = f"Read README and PDFs for rules and instructions." body = np.array([list(text_string)]) obj = Game_object(50, 20, body[0].size, 1, 0, 0, body, np.full(body.shape, Fore.WHITE + Style.BRIGHT)) self.screen.reset_screen() self.screen.add_to_game_screen(obj) self.screen.add_to_game_screen(self.my_continue) self.screen.print_game_screen() while True: c = input_to(self.getch) if (c == 'c'): break
def lost(self): score_string = f"SCORE: %d" % (self.score) body = np.array([list(score_string)]) obj = Game_object(70, 20, body[0].size, 1, 0, 0, body, np.full(body.shape, Fore.WHITE + Style.BRIGHT)) self.reset() os.system("clear") self.screen.reset_screen() self.screen.add_to_game_screen(self.game_over) self.screen.add_to_game_screen(obj) self.screen.add_to_game_screen(self.my_continue) self.screen.print_game_screen() while True: c = input_to(self.getch) if (c == 'c'): break
def welcome(): ''' Clear the screen and show instruction ''' sys.stdout.flush() sys.stdin.flush() os.system('tput reset') print_art(BRICKBREAKER2, Fore.YELLOW) print_art(MYNAME, Fore.YELLOW) print_art(INSTRUCTION, Fore.GREEN) print_art(GAMEINSTRUCTION, Fore.GREEN) ch = Get() while True: ch1 = input_to(ch, 1000) if ch1 == 'g' or ch1 == 'G': break elif ch1 == 'q' or ch1 == 'Q': quit()
def winpage(self): os.system("clear") os.system('aplay -q ./sounds/win.wav&') self.win = False score_string = f"SCORE: %d" % (self.score) body = np.array([list(score_string)]) obj = Game_object(70, 20, body[0].size, 1, 0, 0, body, np.full(body.shape, Fore.WHITE + Style.BRIGHT)) self.reset() os.system("clear") self.screen.reset_screen() self.screen.add_to_game_screen(self.my_win) self.screen.add_to_game_screen(obj) self.screen.add_to_game_screen(self.my_continue) self.screen.print_game_screen() while True: c = input_to(self.getch) if (c == 'c'): break
def pause_screen(self): os.system("clear") text_string = f"The game is paused." body = np.array([list(text_string)]) obj = Game_object(65, 20, body[0].size, 1, 0, 0, body, np.full(body.shape, Fore.WHITE + Style.BRIGHT)) self.screen.reset_screen() self.screen.add_to_game_screen(obj) self.screen.add_to_game_screen(self.my_continue) self.screen.print_game_screen() start_time = datetime.now() while True: c = input_to(self.getch) if (c == 'c'): end_time = datetime.now() time_delta = end_time - start_time total_seconds = time_delta.total_seconds() self.pause_time += round(total_seconds) // 60 break
def input_handler(): ''' Handles user input and moves the character accordingly ''' getch = Get() chbuff = input_to(getch) if chbuff: if chbuff =='q': defs.livesleft = -2 time.sleep(0.2) print("\033[2J",end="") exit(0) elif chbuff in ['w','a','s','d']: defs.main_rider.move(chbuff) if chbuff=='w': defs.down=1 else: defs.down=1 elif chbuff == 'j': bullet.Bullet(defs.main_rider.xpos_left+defs.board_start+len(defs.main_rider.rider[0]),\ defs.main_rider.ypos_top,2*int(defs.columns)) elif chbuff == ' ': defs.main_rider.sheild() elif not defs.main_rider._isSheilded: defs.main_rider.change_rider(0)
def __level_one_run(self): while self.lives > 0: input = input_to(self.getch) self.__game_updates() self.__level_update() if (self.y_collisions.check_hole(self.mario, self.win)): self.__restart() for self.tortise in self.set_tort: self.tortise.gaurd(self.win) self.__ground_move( input, self.x_collisions.check(-1, self.mario, self.pipes, self.boxes), self.x_collisions.check(1, self.mario, self.pipes, self.boxes)) if self.mario.onSpring: self.y_collisions.restore(self.mario, self.win, self.boxes2[1]) if not (self.mario.onSpring): self.__jump_move(input, self.mario.hit, True) self.__collision_check() self.__goDown_move(input, True) self.y_collisions.check_spring(self.mario, self.win, self.boxes2[1]) self.__frame_updates()
def user_input(self): ''' Getting input from the user for paddle movement ''' ch = Get() ch1 = input_to(ch, self.ball.skip_iteration_tp) if ch1 == 'a' or ch1 == 'A': self.paddle.move_left() self.ball.move_with_paddle() if self.game_status.get_stage() == MAXSTAGE: self.ufo.move_with_paddle() elif ch1 == 'd' or ch1 == 'D': self.paddle.move_right() self.ball.move_with_paddle() if self.game_status.get_stage() == MAXSTAGE: self.ufo.move_with_paddle() elif ch1 == 'q' or ch1 == 'Q': quit() elif ch1 == 'p' or ch1 == 'P': self.ball.next_shape() # elif ch1 == 'i' or ch1 =='I': # self.ball.speedx ==2 # self.ball.speedy ==2 # elif ch1 == 'k' or ch1 =='K': # self.ball.speedx ==1 # self.ball.speedy ==1 # elif ch1 == 'c' or ch1=='C': # self.ball.expand_paddle_effect() # elif ch1 == 'v' or ch1=='V': # self.ball.shrink_paddle_effect() # elif ch1 == 'b' or ch1=='B': # self.ball.default_paddle_effect() elif ch1 == ' ': self.ball.flip_stick(False) elif ch1 == '\\': self.game_status.stage_up()
def make_move(): c = input_to(Get()) if c == 'a': glob.paddle.move_relative(glob.board.matrix, -1) if c == 'd': glob.paddle.move_relative(glob.board.matrix, 1) if c == 'e': glob.paddle.release_ball() if c == 'y': glob.level += 1 if glob.level == 4: os.system('clear') print('Game over') print('Max score is ', glob.max_points) quit() glob.init() if c == 'q': print('game aborted') quit()
def __init__(self): defs.board = self.create_board() defs.board_check = copy.deepcopy(self.create_check()) defs.board_start = 0 stats.Stats.create_board() defs.speed = defs.def_speed self.__main_riderf.ypos_top = int(defs.rows) - 4 thread1 = threading.Thread(target=self.gameplay, daemon=True) thread1.start() while defs.dragonlivesleft >= 0 and defs.livesleft >= 0: getch = Get() chbuff = input_to(getch) if chbuff: if chbuff == 'q': exit(0) elif chbuff in ['w', 's']: self.__main_riderf.move(chbuff) self.__main_dragon.move(chbuff) if chbuff == 'w': defs.down = 0 elif chbuff in ['a', 'd']: self.__main_riderf.move(chbuff) elif chbuff == 'j': bullet.Bullet(self.__main_riderf.xpos_left+len(self.__main_riderf.rider[0]),\ self.__main_riderf.ypos_top,int(defs.columns)) elif chbuff == ' ': self.__main_riderf.sheild() elif not self.__main_riderf._isSheilded: self.__main_riderf.change_rider(0) self.__main_riderf.check_pos() if defs.livesleft >= 0: inp.pr_result(1) else: inp.pr_result(2) print('\033[' + defs.rows + ';' + defs.columns + 'f' + defs.reset_color)
def _loopGame(self): paddleobj= [] paddleobj.append(Paddle(FRAMEHEIGHT-2,int(FRAMEWIDTH/2),1,7,0,0)) ballobj=[] ballobj.append(Ball(FRAMEHEIGHT-3,paddleobj[0]._y+int(paddleobj[0]._ylength/2),1,1,-2,2)) brickobj=[] powerupobj=[] brickobj,powerupobj=self.fillBricks() flag=0 while (self.status(brickobj,paddleobj)): getch=Get() ch=input_to(getch,0.1) if ch=='e': flag=1 break if(ch=='f'): for i in ballobj: i.isCollidedWithPaddle=False print("\033[0;0H") self._update(ballobj,paddleobj,ch,brickobj,powerupobj) self.checkBricks(brickobj,powerupobj) self.checkBall(ballobj,paddleobj) self.checkPowerupIsCollided(powerupobj) self.scores(paddleobj) self._printGame() if flag: print("You Exited") print(f"With Score {paddleobj[0].score}") else: if(self.lives==0): print("You Lost") print(f"With Score {paddleobj[0].score}") else: print("You Won") print(f"With Score {paddleobj[0].score}")
shield_activated_at=old_time flag=0 ### if flag is 0 check mando-lazer collision m_dead=0 e_dead=0 l=0 vel=0 game_start_time=int(time.time()) finish_game=0 while True: if speed_counter < 0: speed_counter=0 print("\033[0;0f",end="") input=input_to(getch) ### this while loop is like sleep function if wait_time!=0: while (time.time() - old_time < wait_time): waste+=1 if (150+game_start_time-time.time()<0): finish_game=1 break #####enable shield if (time.time() - shield_last_disabled > 5 and flag==0 ): shield_available=1 ####disable shield if (time.time() - shield_activated_at > 10 and flag==1):
print("\033[2J") while True: curr_time = time.time() c_ball_time = time.time() if(curr_time - prev_time >= 0.05): print("\033[0;0H") paddle.setTimetaken(int(curr_time-start_time)) screen.printScreen(ball, paddle) prev_time = curr_time if(ball.getfree() == 1 and c_ball_time - p_ball_time >= ball.getSpeed()): ball.movement(screen, paddle, bricks) p_ball_time = c_ball_time inp = input_to(Get()) if(inp == None): inp = "" if (inp == ' ' or inp == ' '): if(ball.getfree() == 0): ball.release(screen,paddle) if (inp == 'a' or inp == 'A' or inp == 'd' or inp == 'D'): if(paddle.getStartpaddle() > 0 and paddle.getStartpaddle() + paddle.getLength() < screen.getGamewidth()): if(ball.getfree() == 0): ball.initializeBall(screen,inp) paddle.movement(screen, inp) if(inp == 'x' or inp == 'X'): exit() x += 1
total_time = 100 refresh_time = 0.05 screen = Screen(1000) mandalorian = Hero(screen, screen.getScreenwidth() / 4, screen.getScreenheight() - 1, refresh_time) firebeams = initialiseFirebeams(screen) coins = initialiseCoins(screen) magnets = initialiseMagnets(screen) boss = Enemy(screen, screen.getGamewidth() - 2, screen.getScreenheight() - 1) bullets = [] get = Get() input_taken = 0 start_time = time.time() previous_time = start_time while True: current_time = time.time() time_remaining = total_time - time.time() + start_time if time_remaining < 0: mandalorian.gameOver(mandalorian) if current_time - previous_time >= refresh_time: print( "\033[0;0H" ) screen.printScreen(mandalorian, time_remaining) previous_time = time.time() input_taken = 0 input = input_to(get, refresh_time) if input == None: input = "" if input_taken == 0: mandalorian.move(screen, boss, firebeams, coins, magnets, bullets, input, refresh_time) input_taken = 1
def move(self, chbuff, boardA, en=None, br=None): checker_l = self.col_check(boardA) if chbuff == 'd' and self._y < 500 - self._dim[1]: """Right""" if len(checker_l): for checker in checker_l: if (checker[1] == self._y + self._dim[1]): return self._y += 1 for i in range(self._dim[0]): boardA.change(self._x + i, self._y - 1, '.') if (self._y >= boardA.start_getter() + 40 and self._y < 460 and self._typ != "Enemy"): boardA.start_setter(boardA.start_getter() + 1) self.render(boardA) elif chbuff == 'a' and self._y: """Left""" if len(checker_l): for checker in checker_l: if (checker[1] == self._y - 1): return if (self._y > 0): self._y -= 1 for i in range(self._dim[0]): boardA.change(self._x + i, self._y + self._dim[1], '.') if (self._y < boardA.start_getter() and self._typ != "Enemy"): boardA.start_setter(boardA.start_getter() - 1) self.render(boardA) else: pass elif chbuff == 'w' and self._jump_flag == 0: """Jump up""" temp = self._x self._jump_flag = 1 for checker in checker_l: if (checker[0] == self._x - 1): self.render(boardA) return while (self._x and self._x >= temp - self._jump_dist): if len(checker_l): for checker in checker_l: if (checker[0] == self._x - 1): return self._x -= 1 for wi in range(self._dim[1]): boardA.change(self._x + self._dim[0], self._y + wi, '.') self.render(boardA) checker_l = self.col_check(boardA) getch = Get() chbuff = input_to(getch) if (chbuff): self.move(chbuff, boardA) if (en): for e in en: e.graze(boardA) e.render(boardA) self.render(boardA) os.system('clear') print(boardA.printBoard()) print(boardA.count()) self.render(boardA)
while True: screen = Render() player = Player(screen) ball = Ball(screen, player) bricks = Bricks(screen) bar = Bar(screen) bar.score = Score bar.lives = Lives bar.level = Level bar.start_time = Time while True: # Restart if player.movement(input_to(), screen): Score = 0 Time = time.time() Lives = 10 break # Endgame if bar.lives == 0: print('You just died. Lol haha xD') sys.exit() # Next Level lvlFlag = True for eachRow in range(bricks.begin['x'], bricks.end['x']): for eachCol in range(bricks.begin['y'], bricks.end['y']): if bricks.frame[eachRow][eachCol] in [1, 2, 3, 4]: lvlFlag = False break
def main(): music = subprocess.Popen(["aplay", "-q", "./main.wav"]) level = gameMap() display = Board(32, 96, level.levelmap) mario = Mario(26, 10, display) enemy = [] enemy.append(EnemyShroom(26, 30, display, level.levelmap, -1)) enemy.append(EnemyShroom(26, 140, display, level.levelmap, -1)) enemy.append(EnemyShroom(26, 300, display, level.levelmap, 1)) enemy.append(EnemyShroom(26, 305, display, level.levelmap, -1)) coins = [] coins.append(Coin(17, 30, display)) coins.append(Coin(17, 34, display)) coins.append(Coin(17, 38, display)) coins.append(Coin(17, 42, display)) coins.append(Coin(17, 140, display)) coins.append(Coin(17, 142, display)) coins.append(Coin(17, 144, display)) coins.append(Coin(17, 146, display)) coins.append(Coin(14, 200, display)) coins.append(Coin(17, 210, display)) coins.append(Coin(17, 300, display)) coins.append(Coin(17, 305, display)) getch = Get() gameloop = True os.system('clear') print(display.getString()) while gameloop == True: mario.death(coins, display, music) cam = mario.playercamera(display, level) if cam == 1: mario.score += 5 if coins: for coin in coins: if (display.y + 95 > coin.y and coin.spawn == 0): coin.y = coin.y - display.y display.drawonBoard(coin, coin.x, coin.y) coin.spawn = 1 elif (coin.spawn == 1): if cam == 1: coin.y -= 1 display.drawonBoard(coin, coin.x, coin.y) if (coin.y == 0): coin.sprite = [[' ']] display.drawonBoard(coin, coin.x, coin.y) coins.remove(coin) if enemy: for monster in enemy: if (display.y + 95 > monster.y + monster.width and monster.spawn == 0): monster.y = monster.y - display.y display.drawonBoard(monster, monster.x, monster.y) monster.spawn = 1 elif (monster.spawn == 1): if cam == 1: monster.y -= 1 monster.movement(display, level.levelmap, mario, coins, music) if (monster.y == 0): monster.life = 0 monster.death(display) enemy.remove(monster) inp = input_to(getch) os.system('clear') if mario.gravityon == -1 or mario.gravityon == 1: fallstate, pos = mario.Descend(display, level.levelmap) if (fallstate == 1): mario.gravityon = 1 elif (fallstate == 2): min = 0 minval = pos + 10 if enemy: for monster in enemy: if (monster.y + 1 < minval): minval = monster.y + 1 min = monster subprocess.Popen(["aplay", "-q", "./kill.wav"]) min.life -= 1 if (min.life <= 0): min.death(display) mario.score += 200 enemy.remove(min) mario.gravityon = 0 mario.jump_height = 7 elif (fallstate == 5): if coins: for coin in coins: if (coin.y == pos): subprocess.Popen(["aplay", "-q", "./coin.wav"]) mario.score += 100 coin.sprite = [[' ']] display.drawonBoard(coin, coin.x, coin.y) coins.remove(coin) elif (fallstate == 4): music.kill() subprocess.Popen(["aplay", "-q", "./win.wav"]) mario.score += 2000 print("Stage Clear!") print("Score: " + str(mario.score)) sys.exit() elif mario.gravityon == 0: if mario.jump_height < 12: mario.jump_height += 1 fallstate, pos = mario.Ascend(display, level.levelmap) if (fallstate == 1): mario.gravityon = -1 elif (fallstate == 5): if coins: for coin in coins: if coin.y == pos: subprocess.Popen(["aplay", "-q", "./coin.wav"]) mario.score += 100 coin.sprite = [[' ']] display.drawonBoard(coin, coin.x, coin.y) coins.remove(coin) if mario.jump_height == 12: mario.jump_height = 0 mario.gravityon = -1 print(Fore.GREEN + Style.BRIGHT + display.getString()) print("Score: " + str(mario.score)) if inp == 'q': os.system('clear') music.kill() sys.exit() if inp is not None: mario.movement(inp, display, level.levelmap, coins, music)
length = 80 height = 25 f = 's' vdist = 0 x = 0 while True: ''' grnd = Ground( length, height ) grnd.renderGround(mappos) grnd.renderMario(posx, posy) print(grnd.returnString()) ''' mat = returnMap(posx, posy, mappos, direction, length * maplength, height) print(renderMap(mat, length, height)) button = input_to(getch) if button == 'q': system('clear') sys.exit() if button == 'd': x = collisionDetect(mat, button, posx, posy, height) direction = '>' travlength = travlength + x if travlength > ((1 / 2 + maplength) * length): posx = posx + x else: if posx + 1 < length / 2: posx = posx + x else: mappos = mappos + x