def test_hole_fail(): setting.BOARD = [] setting.LIVES = 1 sample_mario = Mario(15, 39, "/m\\", "|m|") setting.X = sample_mario.x_variable setting.MARIO_POSITION = sample_mario.y_variable board = BOARD(50, 50) board.getnewboard() setting.BOARD[17][40] = " " hole() assert setting.LIVES == 1
def test_jumping_collision(): setting.BOARD=[] setting.COINS=[[16,40]] sample_mario = Mario(16,39,"/m\\","|m|") setting.X=sample_mario.x_variable setting.MARIO_POSITION=sample_mario.y_variable board=BOARD(50,50) board.getnewboard() setting.BOARD[16][40]="===" col_jump=check_collision_juming("===") assert col_jump is True
def test_fail_bring_flag_down(): setting.BOARD = [] setting.F = 14 sample_mario = Mario(15, 200, "/m\\", "|m|") setting.X = sample_mario.x_variable setting.MARIO_POSITION = sample_mario.y_variable board = BOARD(50, 400) board.getnewboard() bring_flag_down() assert setting.F == 14
def movedown(self, key): '''movedown''' # come down until there is no surface # if(BOARD.mat[self.xpos+1][self.ypos] != '*' and # BOARD.mat[self.xpos+1][self.ypos] != '-'): if BOARD.checkstar(self.xpos + 1, self.ypos) != 1 and BOARD.checkstar( self.xpos + 1, self.ypos - 1) != 1: self.xpos += 1 if key == 'd' and BOARD.checkstar(self.xpos, self.ypos + 1) != 1: self.ypos += 1 if key == 'a' and BOARD.checkstar(self.xpos, self.ypos - 2) != 1: self.ypos -= 1
def test_obstacles_below_while_jumping(): setting.BOARD = [] setting.JUMP = True sample_mario = Mario(15, 40, "/m\\", "|m|") setting.X = sample_mario.x_variable setting.MARIO_POSITION = sample_mario.y_variable board = BOARD(50, 50) board.getnewboard() setting.BOARD[14][40] = "{ }" check_collisions_above("===", "[ ]", "? ?") assert setting.JUMP is True
def test_powerup(): setting.BOARD=[] setting.LIVES=0 setting.SCORE=0 setting.SPECIAL_POWER=[[16,40]] sample_mario = Mario(16,39,"/m\\","|m|") setting.X=sample_mario.x_variable setting.MARIO_POSITION=sample_mario.y_variable board=BOARD(50,50) board.getnewboard() setting.BOARD[16][40]="$$$" check_collsion_powerup("$$$",1) assert setting.LIVES==1 and setting.SCORE==100 and setting.MARIOSTR1=="/M\\" and setting.MARIOSTR2=="|M|"
def test_get_coins_from_brick(): setting.BOARD = [] setting.JUMP = True setting.SPECIAL_BRICK = [[14, 40]] sample_mario = Mario(15, 40, "/m\\", "|m|") setting.X = sample_mario.x_variable setting.MARIO_POSITION = sample_mario.y_variable board = BOARD(50, 50) board.getnewboard() setting.BOARD[14][40] = "? ?" get_coin_from__brick("? ?", "???") assert setting.BOARD[13][40] == " * "
def test_coins_collision(): setting.BOARD = [] setting.LIVES = 0 setting.SCORE = 0 setting.COINS = [[16, 40]] sample_mario = Mario(16, 39, "/m\\", "|m|") setting.X = sample_mario.x_variable setting.MARIO_POSITION = sample_mario.y_variable board = BOARD(50, 50) board.getnewboard() setting.BOARD[16][40] = " * " check_collisions_coins(" * ", 1) assert setting.SCORE == 10
def test_obstacles_below_while_jumping(): setting.BOARD=[] setting.JUMP=False setting.JUMP_OFFSET=10 setting.COINS=[[16,40]] sample_mario = Mario(15,40,"/m\\","|m|") setting.X=sample_mario.x_variable setting.MARIO_POSITION=sample_mario.y_variable board=BOARD(50,50) board.getnewboard() setting.BOARD[16][40]="===" check_collisions_below("===","[ ]") assert setting.JUMP_OFFSET ==0
def move(self, i=None): '''for enemy movement''' if BOARD.checkstar(self.xps + 1, self.yps) != 1 and i is None: self.xps += 1 # BOARD.plr(pre_x,pre_y,self.x,self.y,self.sym) self.collision(self.xps, self.yps) self.yps += self.vel
def make_pps(cls): '''make pipe, pit, spring''' BOARD.make_pipe(65, 4) BOARD.make_pipe(90, 5) BOARD.make_pipe(120, 6) BOARD.make_pipe(140, 4) BOARD.make_pit(160, 5) BOARD.make_spring(359, 25) BOARD.make_pit(200, 45) BOARD.make_pit(403, 10) BOARD.make_spring(400, 25) BOARD.make_pipe(430, 6) BOARD.make_spring(495, 18)
''' main module to run mario ''' import time import os from colorama import Back, Style import setting from board import BOARD import persons as p import draw as d from persons import Mario import key_func as kf import scene as sc import check_collisions as c_c import input as key from boss_enemy import BossEnemy KEY_PRESSED = key.KBHit() B = BOARD(30, 22) K = [0] PRIN = [0] GAMEBOARD = B.getnewboard() B.drawboard() sc.make_clouds() d.generate_enemy() CLOCK = time.time() os.system('aplay ./sounds/main_theme.wav&') def level1(): ''' function for running level1 of the game''' while 1: clock1 = time.time()
def moveleft(self, i): '''moveleft''' if BOARD.checkstar(self.xpos, self.ypos - 2) != 1 and self.ypos > i + 1: self.ypos -= 1
def moveright(self): '''moveright''' if BOARD.checkstar(self.xpos, self.ypos + 1) != 1: self.ypos += 1
def print_on_board(self, xps, yps): '''To print bricks''' BOARD.make_brick(xps, yps, self.coin, self.size)
def enemy(cls, lgt): '''make enemy bullets''' # for bullets for k in BULLET_LIST: BOARD.mat[k.xps][k.yps] = k.sym if time.time() - k.tym > 0.1: k.tym = time.time() if BOARD.checkstar(k.xps, k.yps + 1) is 1 or k.yps > lgt + 80: BULLET_LIST.remove(k) else: k.yps += k.vel if k.xps >= 22 and k.xps <= 25 and k.yps == BOSS.y and BOSS.Health >= 0: Manage.bosslife() BULLET_LIST.remove(k) BOSS.Health -= 1 if BOSS.Health >= 0: if time.time() - BOSS.bosstime > 1: BOSS.bosstime = time.time() BOSS.x = random.randint(22, 25) BOSS.y = random.randint(460, 470) BOSS_BULLET.append(Bullet(BOSS.x - 2, BOSS.y, -1, BOSS_B)) prob = random.randint(1, 100) if prob < 20: BOSS_BULLET.append(Bullet(BOSS.x - 3, BOSS.y, -1, BOSS_B)) if prob < 10: BOSS_BULLET.append(Bullet(BOSS.x - 1, BOSS.y, -1, BOSS_B)) if prob == 2: BOSS_BULLET.append(Bullet(BOSS.x, BOSS.y, -1, BOSS_B)) if PERSON.xpos <= 25 and PERSON.xpos >= 22 and PERSON.ypos >= BOSS.y \ and PERSON.ypos <= BOSS.y + 5: Manage.changelives() zps = 0 for i, j in CHECKPOINT: if j >= PERSON.ypos and i is not None: PERSON.xpos = CHECKPOINT[zps - 1][0] PERSON.ypos = CHECKPOINT[zps - 1][1] break zps += 1 for k in BOSS_BULLET: if (k.xps >= PERSON.xpos - 1 and k.xps <= PERSON.xpos or k.xps + 1 == PERSON.xpos) and ( k.yps >= PERSON.ypos - 1 and k.yps <= PERSON.ypos): Manage.changelives() BOSS_BULLET.remove(k) for k in BOSS_BULLET: BOARD.mat[k.xps][k.yps] = k.sym if time.time() - k.tym > 0.1: k.tym = time.time() if BOARD.checkstar(k.xps, k.yps - 1) is 1 or k.yps < lgt: BOSS_BULLET.remove(k) else: k.yps += k.vel # BOSS.print_boss(BOSS.x,BOSS.y) POLY.print_poly(BOSS, BOSS.x, BOSS.y) # print(lgt) for k in ELIST: if k.type == "enemy1": flagvar = False if time.time() - k.tym > 0.5: k.tym = time.time() if k.yps >= lgt and k.yps <= lgt + 80: # k.move(None) POLY.move_poly(k) if (PERSON.xpos == k.xps and PERSON.ypos == k.yps): Manage.changelives() flagvar = True zps = 0 for i, j in CHECKPOINT: if j >= PERSON.ypos: PERSON.xpos = CHECKPOINT[zps - 1][0] PERSON.ypos = CHECKPOINT[zps - 1][1] break zps += 1 if PERSON.xpos + \ 1 == k.xps and (PERSON.ypos - 1 == k.yps or PERSON.ypos == k.yps): try: sound = open('smb_stomp.wav', 'r') os.system('aplay -q ./smb_stomp.wav&') except: pass Manage.enemykill() Manage.changescore(k.type) PERSON.xpos -= 2 ELIST.remove(k) if lgt > 100: if PERSON.xpos == k.xps: if k.vel > 0 and PERSON.ypos < k.yps - 4: k.vel = -k.vel if k.vel < 0 and PERSON.ypos > k.yps + 4: k.vel = -k.vel if k.xps == 26: BOARD.mat[k.xps][k.yps] = ' ' ELIST.remove(k) # k.print_enemy(k.xps,k.yps) POLY.print_poly(k, k.xps, k.yps) if flagvar: return PERSON.ypos - 10 if k.type == "enemy2": # TURTLE ENEMY flagvar = False if time.time() - k.tym > 5 and k.sym == ' ': k.tym = time.time() k.sym = '^' k.vel = random.randrange(-1, 2, 2) if k.yps >= lgt and k.yps <= lgt + 80: # k.move() POLY.move_poly(k) if PERSON.xpos == k.xps and PERSON.ypos + \ 1 == k.yps and k.sym == ' ' and k.vel == 0: try: sound = open('smb_kick.wav', 'r') os.system('aplay -q ./smb_kick.wav&') except: pass k.vel = 1 if PERSON.xpos == k.xps and PERSON.ypos - \ 2 == k.yps and k.sym == ' ' and k.vel == 0: try: sound = open('smb_kick.wav', 'r') os.system('aplay -q ./smb_kick.wav&') except: pass k.vel = -1 # enemy-enemy collision if k.sym == ' ' and k.vel != 0 and time.time() - k.tym > 0.1: k.tym = time.time() if k.yps >= lgt and k.yps <= lgt + 80: POLY.move_poly(k) for enmy in ELIST: if (enmy.xps == k.xps and enmy.yps == k.yps and k != enmy): try: sound = open('smb_stomp.wav', 'r') os.system('aplay -q ./smb_stomp.wav&') except: pass Manage.enemykill() Manage.changescore(enmy.type) ELIST.remove(enmy) if time.time() - k.tym > 0.5 and k.sym == '^': k.tym = time.time() if k.yps >= lgt and k.yps <= lgt + 80: POLY.move_poly(k) if (PERSON.xpos == k.xps and (PERSON.ypos == k.yps or PERSON.ypos - 1 == k.yps) and k.vel != 0): Manage.changelives() flagvar = True zps = 0 for i, j in CHECKPOINT: if j >= PERSON.ypos: PERSON.xpos = CHECKPOINT[zps - 1][0] PERSON.ypos = CHECKPOINT[zps - 1][1] break zps += 1 if (PERSON.xpos + 2 == k.xps and (PERSON.ypos == k.yps or PERSON.ypos - 1 == k.yps) and k.sym == '^'): k.sym = ' ' k.tym = time.time() PERSON.xpos -= 2 k.vel = 0 if (PERSON.xpos + 1 == k.xps and (PERSON.ypos == k.yps or PERSON.ypos - 1 == k.yps) and k.sym == ' '): try: sound = open('smb_stomp.wav', 'r') os.system('aplay -q ./smb_stomp.wav&') except: pass Manage.enemykill() Manage.changescore(k.type) PERSON.xpos -= 2 ELIST.remove(k) if lgt > 100: if PERSON.xpos == k.xps and k.sym == '^': if k.vel > 0 and PERSON.ypos < k.yps - 4: k.vel = -k.vel if k.vel < 0 and PERSON.ypos > k.yps + 4: k.vel = -k.vel if k.xps == 26: BOARD.mat[k.xps][k.yps] = ' ' ELIST.remove(k) # k.print_enemy(k.xps,k.yps,k.sym) POLY.print_poly(k, k.xps, k.yps) if flagvar: return PERSON.ypos - 10 return lgt
def print_board(self): # os.system('clear') board = BOARD.format(**self.BOARD_STATE) print(board) print(PROMPT) return board
def print_on_board(cls, xps, yps): '''print the coins''' BOARD.make_coin(xps, yps)
break os.system("clear") M.printhead() SCENE.make_cm(i) SCENE.make_pps() SCENE.brick_coin() SCENE.moving_bar() SCENE.make_flag() i = SCENE.enemy(i) # PERSON.print_mario(PERSON.xpos,PERSON.ypos) POLY.print_poly(PERSON, PERSON.xpos, PERSON.ypos) # BOARD.print_board(i,i+80) POLY.print_poly(BOARD, i, i + 80) # PERSON.move(i) POLY.move_poly(PERSON, i) if BOARD.checkstar(PERSON.xpos + 1, PERSON.ypos) == 2: Manage.changelives() ZPS = 0 for k, j in CHECKPOINT: if j >= PERSON.ypos: PERSON.xpos = CHECKPOINT[ZPS - 1][0] PERSON.ypos = CHECKPOINT[ZPS - 1][1] i = PERSON.ypos - 10 break ZPS += 1 if TIMER == 5: M.timer() TIMER = 0 TIMER += 1
def collision(self, xps, yps): '''code for collision''' if BOARD.checkstar(xps, yps + self.vel) == 1: self.vel = -self.vel