def run_game(): pygame.init() pygame.display.set_caption("Mario") ai_settings = Settings() screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) scores = Scoreboard(ai_settings, screen) g_blocks = Group() bg_blocks = Group() enemies = Group() chunks = Group() items = Group() monitor = Monitor(ai_settings, screen, g_blocks, bg_blocks, chunks, enemies, items) mario = Mario(ai_settings, screen, g_blocks, bg_blocks, enemies, monitor, chunks, items) #gf.create_enemy(ai_settings, screen, g_blocks, bg_blocks, mario, enemies, "reg", 500, 100, 500) gf.create_enemy(ai_settings, screen, g_blocks, bg_blocks, mario, enemies, "koopa", 620, 400, 500, items) gf.create_item(ai_settings, screen, g_blocks, bg_blocks, mario, items, "star", 500, 400, 500, True, False) while True: gf.check_events(ai_settings, screen, mario, g_blocks, bg_blocks, monitor, items) mario.update() gf.check_time(ai_settings, scores) gf.update_screen(ai_settings, screen, mario, g_blocks, bg_blocks, enemies, monitor, chunks, items, scores) mainClock.tick(120)
def gen(self, left, chunk_type, scores): x = left y = 0 if chunk_type == "g": for row in self.map: for col in row: if col == "1": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/brick_1.bmp", self.g_blocks, x, y, 400, "reg") if col == "2": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/pipe_1.bmp", self.g_blocks, x, y, 400, "reg") if col == "3": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/pipe_2.bmp", self.g_blocks, x, y, 400, "reg") if col == "4": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/pipe_3.bmp", self.g_blocks, x, y, 400, "reg") if col == "5": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/pipe_4.bmp", self.g_blocks, x, y, 400, "reg") if col == "6": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/stair_1.bmp", self.g_blocks, x, y, 400, "reg") if col == "7": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/brick_3.bmp", self.g_blocks, x, y, 400, "reg") if col == "8": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/brick_4.bmp", self.g_blocks, x, y, 400, "bricks") if col == "9": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/pipe_15.bmp", self.g_blocks, x, y, 400, "reg") if col == "a": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/pipe_16.bmp", self.g_blocks, x, y, 400, "reg") if col == "b": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/pipe_17.bmp", self.g_blocks, x, y, 400, "reg") if col == "c": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/pipe_18.bmp", self.g_blocks, x, y, 400, "reg") if col == "d": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/pipe_19.bmp", self.g_blocks, x, y, 400, "reg") if col == "e": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/pipe_20.bmp", self.g_blocks, x, y, 400, "reg") if col == "f": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/pipe_13.bmp", self.g_blocks, x, y, 400, "reg") if col == "g": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/pipe_14.bmp", self.g_blocks, x, y, 400, "reg") if col == "h": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/pipe_5.bmp", self.g_blocks, x, y, 400, "reg") if col == "i": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/pipe_6.bmp", self.g_blocks, x, y, 400, "reg") if col == "j": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/pipe_7.bmp", self.g_blocks, x, y, 400, "reg") if col == "k": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/pipe_8.bmp", self.g_blocks, x, y, 400, "reg") if col == "l": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/pipe_9.bmp", self.g_blocks, x, y, 400, "reg") if col == "m": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/pipe_10.bmp", self.g_blocks, x, y, 400, "reg") if col == "n": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/stair_2.bmp", self.g_blocks, x, y, 400, "reg") if col == "o": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/pipe_11.bmp", self.g_blocks, x, y, 400, "reg") if col == "p": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/pipe_12.bmp", self.g_blocks, x, y, 400, "reg") if col == "q": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/tree_1.bmp", self.g_blocks, x, y, 400, "reg") if col == "r": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/tree_2.bmp", self.g_blocks, x, y, 400, "reg") if col == "s": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/tree_3.bmp", self.g_blocks, x, y, 400, "reg") if col == "t": create_g_blocks(self.ai_settings, self.screen, "assets/interactible/brick_2.bmp", self.g_blocks, x, y, 400, "bricks") # change type? if col == "u": create_g_blocks(self.ai_settings, self.screen, "assets/interactible/qblock_1.bmp", self.g_blocks, x, y, 400, "qcoin") # change type? if col == "v": create_g_blocks( self.ai_settings, self.screen, "assets/interactible/qblock_used_1.bmp", self.g_blocks, x, y, 400, "reg") # change type? if col == "y": create_g_blocks(self.ai_settings, self.screen, "assets/interactible/qblock_1.bmp", self.g_blocks, x, y, 400, "pup") # change type? QBLOCK WITH P-UP if col == "z": create_g_blocks(self.ai_settings, self.screen, "assets/interactible/brick_2.bmp", self.g_blocks, x, y, 400, "bcoin") # change type? BRICK WITH COIN if col == ".": create_g_blocks(self.ai_settings, self.screen, "assets/interactible/brick_2.bmp", self.g_blocks, x, y, 400, "star") # change type? BRICK WITH STAR if col == "|": create_g_blocks(self.ai_settings, self.screen, "assets/bg_tiles/pole.bmp", self.g_blocks, x, y, 400, "invs") if col == "?": create_g_blocks( self.ai_settings, self.screen, "assets/interactible/qblock_used_1.bmp", self.g_blocks, x, y, 400, "hidden") if col == "!": create_g_blocks( self.ai_settings, self.screen, "assets/interactible/qblock_used_2.bmp", self.g_blocks, x, y, 400, "hidden") if col == "@": create_enemy(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, mario, self.enemies, "goomba", x, y, 400, self.items, scores) if col == "#": create_enemy(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, mario, self.enemies, "koopa", x, y, 400, self.items, scores) if col == "[": create_enemy(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, mario, self.enemies, "plant", x, y + 30, 400, self.items, scores) if col == "}": create_enemy(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, mario, self.enemies, "plant2", x, y + 30, 400, self.items, scores) if col == "]": create_enemy(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, mario, self.enemies, "bgoomba", x, y, 400, self.items, scores) if col == "{": create_enemy(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, mario, self.enemies, "bkoopa", x, y, 400, self.items, scores) if col == ">": create_enemy(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, mario, self.enemies, "rkoopa", x, y, 400, self.items, scores) if col == "<": create_enemy(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, mario, self.enemies, "pkoopa", x, y, 400, self.items, scores) if col == "*": create_enemy(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, mario, self.enemies, "bowser", x, y, 400, self.items, scores) if col == "=": create_g_blocks(self.ai_settings, self.screen, "assets/bg_tiles/pole.bmp", self.g_blocks, x, y, 400, "winner") if col == "~": create_g_blocks(self.ai_settings, self.screen, "assets/interactible/qblock_4.bmp", self.g_blocks, x, y, 400, "qcoin2") if col == "`": create_g_blocks(self.ai_settings, self.screen, "assets/interactible/qblock_4.bmp", self.g_blocks, x, y, 400, "pup2") if col == "+": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/brick_4.bmp", self.g_blocks, x, y, 400, "bcoin2") if col == "-": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/brick_4.bmp", self.g_blocks, x, y, 400, "star2") if col == "_": create_g_blocks(self.ai_settings, self.screen, "assets/interactible/3bar.bmp", self.g_blocks, x, y, 400, "3bar") if col == ")": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/brick_4.bmp", self.g_blocks, x, y, 400, "pup3") if col == "(": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/brick_4.bmp", self.g_blocks, x, y, 400, "1up2") if col == ":": create_item(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, self, self.items, "coin1", x + 21, y + 48, x, False, False) if col == ";": create_item(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, self, self.items, "coin2", x + 21, y + 48, x, False, False) if col == "'": create_g_blocks(self.ai_settings, self.screen, "assets/special/blank.bmp", self.g_blocks, x, y, 400, "blank") if col == "/": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/brick_5.bmp", self.g_blocks, x, y, 400, "cbrick") if col == ",": create_g_blocks( self.ai_settings, self.screen, "assets/interactible/qblock_used_3.bmp", self.g_blocks, x, y, 400, "v") if col == "%": create_g_blocks(self.ai_settings, self.screen, "assets/ground_tiles/bridge.bmp", self.g_blocks, x, y, 400, "bridge") if col == "^": create_g_blocks(self.ai_settings, self.screen, "assets/interactible/2bar.bmp", self.g_blocks, x, y, 400, "2bar") if col == "&": create_item(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, self, self.items, "ax", x + 21, y + 48, x, False, False) if col == "$": create_g_blocks(self.ai_settings, self.screen, "assets/special/toad.bmp", self.g_blocks, x, y + 25, 400, "v") x += 48 y += 48 x = left elif chunk_type == "bg": for row in self.map: for col in row: if col == "b": create_bg_blocks(self.ai_settings, self.screen, "assets/bg_tiles/sky.bmp", self.bg_blocks, x, y, 400, "reg") elif col == "g": create_bg_blocks( self.ai_settings, self.screen, "assets/bg_tiles/hill_slope_left.bmp", self.bg_blocks, x, y, 400, "reg") elif col == "h": create_bg_blocks(self.ai_settings, self.screen, "assets/bg_tiles/hill_top.bmp", self.bg_blocks, x, y, 400, "reg") elif col == "i": create_bg_blocks( self.ai_settings, self.screen, "assets/bg_tiles/hill_slope_right.bmp", self.bg_blocks, x, y, 400, "reg") elif col == "j": create_bg_blocks(self.ai_settings, self.screen, "assets/bg_tiles/hill.bmp", self.bg_blocks, x, y, 400, "reg") elif col == "k": create_bg_blocks( self.ai_settings, self.screen, "assets/bg_tiles/hill_spot_right.bmp", self.bg_blocks, x, y, 400, "reg") elif col == "l": create_bg_blocks(self.ai_settings, self.screen, "assets/bg_tiles/hill_spot_left.bmp", self.bg_blocks, x, y, 400, "reg") elif col == "m": create_bg_blocks(self.ai_settings, self.screen, "assets/bg_tiles/Lbush.bmp", self.bg_blocks, x, y, 400, "reg") elif col == "n": create_bg_blocks(self.ai_settings, self.screen, "assets/bg_tiles/Mbush.bmp", self.bg_blocks, x, y, 400, "reg") elif col == "o": create_bg_blocks(self.ai_settings, self.screen, "assets/bg_tiles/Rbush.bmp", self.bg_blocks, x, y, 400, "reg") elif col == "p": create_bg_blocks(self.ai_settings, self.screen, "assets/bg_tiles/cloud_2_1.bmp", self.bg_blocks, x, y, 400, "reg") elif col == "q": create_bg_blocks(self.ai_settings, self.screen, "assets/bg_tiles/cloud_2_2.bmp", self.bg_blocks, x, y, 400, "reg") elif col == "r": create_bg_blocks(self.ai_settings, self.screen, "assets/bg_tiles/cloud_2_3.bmp", self.bg_blocks, x, y, 400, "reg") elif col == "s": create_bg_blocks(self.ai_settings, self.screen, "assets/bg_tiles/cloud_2_4.bmp", self.bg_blocks, x, y, 400, "reg") elif col == "t": create_bg_blocks(self.ai_settings, self.screen, "assets/bg_tiles/cloud_2_5.bmp", self.bg_blocks, x, y, 400, "reg") elif col == "u": create_bg_blocks(self.ai_settings, self.screen, "assets/bg_tiles/cloud_2_6.bmp", self.bg_blocks, x, y, 400, "reg") elif col == "v": create_bg_blocks(self.ai_settings, self.screen, "assets/bg_tiles/castle_1.bmp", self.bg_blocks, x, y, 400, "reg") elif col == "w": create_bg_blocks(self.ai_settings, self.screen, "assets/bg_tiles/castle_2.bmp", self.bg_blocks, x, y, 400, "reg") elif col == "x": create_bg_blocks(self.ai_settings, self.screen, "assets/bg_tiles/castle_3.bmp", self.bg_blocks, x, y, 400, "reg") elif col == "y": create_bg_blocks(self.ai_settings, self.screen, "assets/bg_tiles/castle_4.bmp", self.bg_blocks, x, y, 400, "reg") elif col == "z": create_bg_blocks(self.ai_settings, self.screen, "assets/bg_tiles/castle_5.bmp", self.bg_blocks, x, y, 400, "reg") elif col == "1": create_bg_blocks(self.ai_settings, self.screen, "assets/bg_tiles/castle_6.bmp", self.bg_blocks, x, y, 400, "reg") elif col == "2": create_bg_blocks(self.ai_settings, self.screen, "assets/bg_tiles/pole.bmp", self.bg_blocks, x, y, 400, "reg") elif col == "3": create_bg_blocks(self.ai_settings, self.screen, "assets/bg_tiles/pole_top.bmp", self.bg_blocks, x, y, 400, "reg") elif col == "4": create_bg_blocks(self.ai_settings, self.screen, "assets/bg_tiles/tree_thick.bmp", self.bg_blocks, x, y, 400, "reg") # change type? elif col == "5": create_bg_blocks(self.ai_settings, self.screen, "assets/special/flag_1_1.bmp", self.bg_blocks, x, y, 400, "reg") # change type? elif col == "6": create_bg_blocks(self.ai_settings, self.screen, "assets/special/flag_1_2.bmp", self.bg_blocks, x, y, 400, "reg") # change type? elif col == "7": create_bg_blocks(self.ai_settings, self.screen, "assets/bg_tiles/lava_wave.bmp", self.bg_blocks, x, y, 400, "reg") elif col == "8": create_bg_blocks(self.ai_settings, self.screen, "assets/bg_tiles/lava.bmp", self.bg_blocks, x, y, 400, "reg") elif col == "9": create_bg_blocks(self.ai_settings, self.screen, "assets/bg_tiles/chain.bmp", self.bg_blocks, x, y, 400, "reg") elif col == "%": create_bg_blocks(self.ai_settings, self.screen, "assets/bg_tiles/msg.bmp", self.bg_blocks, x, y, 400, "reg") elif col == "^": create_bg_blocks(self.ai_settings, self.screen, "assets/special/toad.bmp", self.bg_blocks, x, y, 400, "reg") x += 48 y += 48 x = left
def cur_item(self, block, music, mario): if (block.type_ == "pup" or block.type_ == "pup2" or block.type_ == "pup3") \ and self.state == "reg": if self.dir_face == "right": left = False right = True else: left = True right = False create_item(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, self, self.items, "mushroom", float(block.rect.x) + 25, block.rect.bottom - 60, float(block.rect.x), left, right) if (block.type_ == "pup" or block.type_ == "pup2" or block.type_ == "pup3") \ and (self.state == "super" or self.state == "fire"): create_item(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, self, self.items, "fireflower", float(block.rect.x) + 25, block.rect.bottom - 30, float(block.rect.x), False, False) if block.type_ == "qcoin" or block.type_ == "qcoin2": create_item(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, self, self.items, "coin", float(block.rect.x) + 25, block.rect.bottom - 30, float(block.rect.x), False, False) if block.type_ == "hidden" or block.type_ == "1up2": if block.image_ == 'assets/interactible/qblock_used_2.bmp': create_item(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, self, self.items, "coin", float(block.rect.x) + 25, block.rect.bottom - 30, float(block.rect.x), False, True) else: create_item(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, self, self.items, "1upshroom", float(block.rect.x) + 25, block.rect.bottom - 30, float(block.rect.x), False, True) if block.type_ == "bcoin" or block.type_ == "bcoin2": create_item(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, self, self.items, "coin", float(block.rect.x) + 25, block.rect.bottom - 30, float(block.rect.x), False, False) if block.type_ == "star" or block.type_ == "star2": create_item(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, self, self.items, "star", float(block.rect.x) + 25, block.rect.bottom - 60, float(block.rect.x), False, True) block.blipup(music, mario)
def update(self, music, mario): self.image = pygame.image.load(self.timer.imagerect()) if self.state == "goright": self.go_right_winner() if self.temp_go == 0: self.temp_go = 1 if self.temp_go == 1: if self.walk_an == "r": self.grow_up('assets/mario/Rmario_walk_1.bmp') self.frames_ = [ 'assets/mario/Rmario_walk_1.bmp', 'assets/mario/Rmario_walk_2.bmp', 'assets/mario/Rmario_walk_3.bmp' ] if self.walk_an == "f": self.grow_up('assets/mario/Rfmario_walk_1.bmp') self.frames_ = [ 'assets/mario/Rfmario_walk_1.bmp', 'assets/mario/Rfmario_walk_2.bmp', 'assets/mario/Rfmario_walk_3.bmp' ] if self.walk_an == "s": self.grow_up('assets/mario/Rsmario_walk_1.bmp') self.frames_ = [ 'assets/mario/Rsmario_walk_1.bmp', 'assets/mario/Rsmario_walk_2.bmp', 'assets/mario/Rsmario_walk_3.bmp' ] self.timer.frames = self.frames_ self.timer.reset() self.temp_go = 2 if self.jumping and self.change_y == 0: self.change_y = -20 self.jumping = False if self.state == "super" or self.state == "fire": pygame.mixer.Channel(1).play(music.big_j) else: pygame.mixer.Channel(1).play(music.small_j) if self.jumping_press and self.jump_scaler == 0: if self.jump_scaler < 20: self.jump_scaler += 2 else: self.jumping_press = False self.change_y -= self.jump_scaler else: self.jump_scaler = 0 ff = 1 ma = 12 if self.mov_right and self.fric < ma and not self.died and not self.flag: self.fric += ff elif self.fric > 0: self.fric -= ff if self.mov_left and self.fric > -ma and not self.died and not self.flag: self.fric -= ff elif self.fric < 0: self.fric += ff if self.change_x == 0 and self.change_y == 0 and not self.flag and not self.died and self.state != "dead": if self.dir_face == "right": self.frames_ = ['assets/mario/Rmario_stand.bmp'] if self.star_power is True: self.frames_ = [ 'assets/mario/Rmario_standi.bmp', 'assets/mario/Rmario_stand.bmp' ] if self.dir_face == "left": self.frames_ = ['assets/mario/Lmario_stand.bmp'] if self.star_power is True: self.frames_ = [ 'assets/mario/Lmario_standi.bmp', 'assets/mario/Lmario_stand.bmp' ] if self.state == "super": if self.dir_face == "right": self.frames_ = ['assets/mario/Rsmario_stand.bmp'] if self.star_power is True: self.frames_ = [ 'assets/mario/Rsmario_standi.bmp', 'assets/mario/Rsmario_stand.bmp' ] if self.dir_face == "left": self.frames_ = ['assets/mario/Lsmario_stand.bmp'] if self.star_power is True: self.frames_ = [ 'assets/mario/Lsmario_standi.bmp', 'assets/mario/Lsmario_stand.bmp' ] if self.state == "fire": if self.dir_face == "right": self.frames_ = ['assets/mario/Rfmario_stand.bmp'] if self.star_power is True: self.frames_ = [ 'assets/mario/Rsmario_standi.bmp', 'assets/mario/Rfmario_stand.bmp' ] if self.dir_face == "left": self.frames_ = ['assets/mario/Lfmario_stand.bmp'] if self.star_power is True: self.frames_ = [ 'assets/mario/Lsmario_standi.bmp', 'assets/mario/Lfmario_stand.bmp' ] self.timer.frames = self.frames_ self.timer.reset() if self.mov_left and not self.mov_right and not self.flag and self.state != "dead": self.rect.x += self.change_x self.dir_face = "left" self.frames_ = [ 'assets/mario/Lmario_walk_1.bmp', 'assets/mario/Lmario_walk_2.bmp', 'assets/mario/Lmario_walk_3.bmp', 'assets/mario/Lmario_walk_1.bmp', 'assets/mario/Lmario_walk_2.bmp', 'assets/mario/Lmario_walk_3.bmp' ] if self.star_power is True: self.frames_ = [ 'assets/mario/Lmario_walk_1.bmp', 'assets/mario/Lmario_walk_2i.bmp', 'assets/mario/Lmario_walk_3.bmp', 'assets/mario/Lmario_walk_1i.bmp', 'assets/mario/Lmario_walk_2.bmp', 'assets/mario/Lmario_walk_3i.bmp' ] if self.state == "super": self.frames_ = [ 'assets/mario/Lsmario_walk_1.bmp', 'assets/mario/Lsmario_walk_2.bmp', 'assets/mario/Lsmario_walk_3.bmp', 'assets/mario/Lsmario_walk_1.bmp', 'assets/mario/Lsmario_walk_2.bmp', 'assets/mario/Lsmario_walk_3.bmp' ] if self.star_power is True: self.frames_ = [ 'assets/mario/Lsmario_walk_1.bmp', 'assets/mario/Lsmario_walk_2i.bmp', 'assets/mario/Lsmario_walk_3.bmp', 'assets/mario/Lsmario_walk_1i.bmp', 'assets/mario/Lsmario_walk_2.bmp', 'assets/mario/Lsmario_walk_3i.bmp' ] if self.state == "fire": self.frames_ = [ 'assets/mario/Lfmario_walk_1.bmp', 'assets/mario/Lfmario_walk_2.bmp', 'assets/mario/Lfmario_walk_3.bmp', 'assets/mario/Lfmario_walk_1.bmp', 'assets/mario/Lfmario_walk_2.bmp', 'assets/mario/Lfmario_walk_3.bmp' ] if self.star_power is True: self.frames_ = [ 'assets/mario/Lfmario_walk_1.bmp', 'assets/mario/Lsmario_walk_2i.bmp', 'assets/mario/Lfmario_walk_3.bmp', 'assets/mario/Lsmario_walk_1i.bmp', 'assets/mario/Lfmario_walk_2.bmp', 'assets/mario/Lsmario_walk_3i.bmp' ] self.timer.frames = self.frames_ # self.timer.reset() if self.mov_right and not self.mov_left and self.state != "dead" and not self.flag: self.rect.x += self.change_x self.dir_face = "right" self.frames_ = [ 'assets/mario/Rmario_walk_1.bmp', 'assets/mario/Rmario_walk_2.bmp', 'assets/mario/Rmario_walk_3.bmp', 'assets/mario/Rmario_walk_1.bmp', 'assets/mario/Rmario_walk_2.bmp', 'assets/mario/Rmario_walk_3.bmp' ] if self.star_power is True: self.frames_ = [ 'assets/mario/Rmario_walk_1.bmp', 'assets/mario/Rmario_walk_2i.bmp', 'assets/mario/Rmario_walk_3.bmp', 'assets/mario/Rmario_walk_1i.bmp', 'assets/mario/Rmario_walk_2.bmp', 'assets/mario/Rmario_walk_3i.bmp' ] if self.state == "super": self.frames_ = [ 'assets/mario/Rsmario_walk_1.bmp', 'assets/mario/Rsmario_walk_2.bmp', 'assets/mario/Rsmario_walk_3.bmp', 'assets/mario/Rsmario_walk_1.bmp', 'assets/mario/Rsmario_walk_2.bmp', 'assets/mario/Rsmario_walk_3.bmp' ] if self.star_power is True: self.frames_ = [ 'assets/mario/Rsmario_walk_1.bmp', 'assets/mario/Rsmario_walk_2i.bmp', 'assets/mario/Rsmario_walk_3.bmp', 'assets/mario/Rsmario_walk_1i.bmp', 'assets/mario/Rsmario_walk_2.bmp', 'assets/mario/Rsmario_walk_3i.bmp' ] if self.state == "fire": self.frames_ = [ 'assets/mario/Rfmario_walk_1.bmp', 'assets/mario/Rfmario_walk_2.bmp', 'assets/mario/Rfmario_walk_3.bmp', 'assets/mario/Rfmario_walk_1.bmp', 'assets/mario/Rfmario_walk_2.bmp', 'assets/mario/Rfmario_walk_3.bmp' ] if self.star_power is True: self.frames_ = [ 'assets/mario/Rfmario_walk_1.bmp', 'assets/mario/Rsmario_walk_2i.bmp', 'assets/mario/Rfmario_walk_3.bmp', 'assets/mario/Rsmario_walk_1i.bmp', 'assets/mario/Rfmario_walk_2.bmp', 'assets/mario/Rsmario_walk_3i.bmp' ] self.timer.frames = self.frames_ # self.timer.reset() if self.mov_right and self.fric < 0 and self.state != "dead" and not self.flag: self.frames_ = [ 'assets/mario/mario_turn2R.bmp', 'assets/mario/mario_turn2R.bmp' ] if self.star_power is True: self.frames_ = [ 'assets/mario/mario_turn2R.bmp', 'assets/mario/mario_turn2Ri.bmp' ] if self.state == "super": self.frames_ = [ 'assets/mario/smario_turn2R.bmp', 'assets/mario/smario_turn2R.bmp' ] if self.star_power is True: self.frames_ = [ 'assets/mario/smario_turn2R.bmp', 'assets/mario/smario_turn2Ri.bmp' ] if self.state == "fire": self.frames_ = [ 'assets/mario/fmario_turn2R.bmp', 'assets/mario/fmario_turn2R.bmp' ] if self.star_power is True: self.frames_ = [ 'assets/mario/fmario_turn2R.bmp', 'assets/mario/fmario_turn2Ri.bmp' ] self.timer.frames = self.frames_ self.timer.reset() if self.mov_left and self.fric > 0 and self.state != "dead" and not self.flag: self.frames_ = [ 'assets/mario/mario_turn2L.bmp', 'assets/mario/mario_turn2L.bmp' ] if self.star_power is True: self.frames_ = [ 'assets/mario/mario_turn2L.bmp', 'assets/mario/mario_turn2Li.bmp' ] if self.state == "super": self.frames_ = [ 'assets/mario/smario_turn2L.bmp', 'assets/mario/smario_turn2L.bmp' ] if self.star_power is True: self.frames_ = [ 'assets/mario/smario_turn2L.bmp', 'assets/mario/smario_turn2Li.bmp' ] if self.state == "fire": self.frames_ = [ 'assets/mario/fmario_turn2L.bmp', 'assets/mario/fmario_turn2L.bmp' ] if self.star_power is True: self.frames_ = [ 'assets/mario/fmario_turn2L.bmp', 'assets/mario/fmario_turn2Li.bmp' ] self.timer.frames = self.frames_ self.timer.reset() if self.inair and not self.died and not self.flag: if not self.landed and self.dir_face == "right": self.frames_ = [ 'assets/mario/Rmario_jump.bmp', 'assets/mario/Rmario_jump.bmp' ] if self.state == "super": self.frames_ = [ 'assets/mario/Rsmario_jump.bmp', 'assets/mario/Rsmario_jump.bmp' ] if self.state == "fire": self.frames_ = [ 'assets/mario/Rfmario_jump.bmp', 'assets/mario/Rfmario_jump.bmp' ] self.timer.frames = self.frames_ self.timer.reset() if not self.landed and self.dir_face == "left": self.frames_ = [ 'assets/mario/Lmario_jump.bmp', 'assets/mario/Lmario_jump.bmp' ] if self.state == "super": self.frames_ = [ 'assets/mario/Lsmario_jump.bmp', 'assets/mario/Lsmario_jump.bmp' ] if self.state == "fire": self.frames_ = [ 'assets/mario/Lfmario_jump.bmp', 'assets/mario/Lfmario_jump.bmp' ] self.timer.frames = self.frames_ self.timer.reset() if self.crouch and not self.flag and not self.died: if self.state == "fire" and self.dir_face == "right": self.grow_up('assets/mario/Rfmario_crouch.bmp') self.frames_ = [ 'assets/mario/Rfmario_crouch.bmp', 'assets/mario/Rfmario_crouch.bmp' ] if self.state == "fire" and self.dir_face == "left": self.grow_up('assets/mario/Rfmario_crouch.bmp') self.frames_ = [ 'assets/mario/Lfmario_crouch.bmp', 'assets/mario/Lfmario_crouch.bmp' ] if self.state == "super" and self.dir_face == "right": self.grow_up('assets/mario/Rfmario_crouch.bmp') self.frames_ = [ 'assets/mario/Rsmario_crouch.bmp', 'assets/mario/Rsmario_crouch.bmp' ] if self.state == "super" and self.dir_face == "left": self.grow_up('assets/mario/Rfmario_crouch.bmp') self.frames_ = [ 'assets/mario/Lsmario_crouch.bmp', 'assets/mario/Lsmario_crouch.bmp' ] self.timer.frames = self.frames_ # self.timer.reset() # self.change_x = self.fric if self.rect.centerx < round(self.ai_settings.screen_width / 2) \ and self.mov_right and not self.mov_left and not self.died and not self.flag: self.go_right() elif self.rect.centerx > round(self.ai_settings.screen_width / 2) and self.mov_right \ and not self.mov_left and not self.died and not self.flag: for blocks in self.g_blocks: blocks.rect.x -= self.change_x for blocks in self.bg_blocks: blocks.rect.x -= self.change_x for item in self.items: item.rect.x -= self.change_x for enemy in self.enemies: enemy.rect.x -= self.change_x for chunk in self.chunks: chunk.check_edge -= self.change_x self.rect.x -= self.change_x for block in self.g_blocks: if self.rect.colliderect(block.rect): if block.type_ == "winner": self.state = "next!" if self.rect.colliderect(block.rect) and not self.flag and not self.death and block.type_ != "hidden"\ and block.type_ != "blank": if self.change_x > 0 and block.type_ != "hidden": # and self.rect.bottom != block.rect.top: self.rect.right = block.rect.left elif self.change_x < 0 and block.type_ != "hidden": # and self.rect.bottom != block.rect.top: self.rect.left = block.rect.right if block.type_ == "winner": self.state = "next!" if block.type_ == "invs": self.next_level = self.state if self.state == "fire": self.state = "flagf" if self.state == "super": self.state = "flags" if self.state == "reg": self.state = "flagr" if self.state == "flagf" or self.state == "flags" or self.state == "flagr" and not self.flag: self.flag = True if self.state == "flagf": self.grow_up('assets/mario/Rfmario_pole_1.bmp') self.frames_ = ['assets/mario/Rfmario_pole_1.bmp'] self.walk_an = "f" if self.state == "flags": self.grow_up('assets/mario/Rsmario_pole_1.bmp') self.frames_ = ['assets/mario/Rsmario_pole_1.bmp'] self.walk_an = "s" if self.state == "flagr": self.grow_up('assets/mario/Rmario_pole_1.bmp') self.frames_ = ['assets/mario/Rmario_pole_1.bmp'] self.walk_an = "r" self.timer.frames = self.frames_ self.rect.x += 20 self.timer.reset() self.state = "nextlevel" if not self.died and self.state != "dead" and self.rect.left > 0: self.change_x = self.fric if self.rect.left < 0: self.rect.left = 0 self.calc_grav() self.rect.y += self.change_y for block in self.g_blocks: if self.rect.colliderect( block.rect ) and not self.death and not self.flag and block.type_ != "blank": if self.change_y > 0 and block.type_ != "hidden": self.rect.bottom = block.rect.top self.landed = True elif self.change_y < 0: self.rect.top = block.rect.bottom self.jumping_press = False self.cur_item(block, music, mario) if block.type_ == "bricks" and (self.state == "super" or self.state == "fire"): block.dead = 1 self.change_y = 0 if (block.type_ == "3bar" or block.type_ == "2bar") and self.rect.bottom == block.rect.top and\ block.rect.x <= self.rect.x <= block.rect.x + 144: block.rect.y += 1 if self.invinc > 0: self.invinc -= 1 if self.invinc == 0 and self.star_power is True: self.star_power = False for enemy in self.enemies: if self.rect.right + 900 > enemy.rect.left: enemy.state = "active" if self.rect.colliderect(enemy.rect) and self.star_power is True: enemy.kill() if self.rect.colliderect( enemy.rect) and self.death is False and self.invinc == 0: if self.change_y > 0 and enemy.type != "plant" and enemy.type != "plant2"\ and enemy.type != "bowser": self.rect.bottom = enemy.rect.top self.change_y = -5 self.jumping = True self.change_y = 0 if enemy.state != "dead": enemy.dead_enemy(music) elif enemy.type == "shell": if self.dir_face == "right": create_item(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, self, self.items, "shell_mov", enemy.rect.right, enemy.rect.bottom, enemy.rect.center, False, True) pygame.mixer.Channel(3).play(music.stomp) enemy.kill() elif self.dir_face == "left": create_item(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, self, self.items, "shell_mov", enemy.rect.left, enemy.rect.bottom, enemy.rect.center, True, False) pygame.mixer.Channel(3).play(music.stomp) enemy.kill() elif enemy.type == "bshell": if self.dir_face == "right": create_item(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, self, self.items, "bshell_mov", enemy.rect.right, enemy.rect.bottom, enemy.rect.center, False, True) pygame.mixer.Channel(3).play(music.stomp) enemy.kill() elif self.dir_face == "left": create_item(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, self, self.items, "bshell_mov", enemy.rect.left, enemy.rect.bottom, enemy.rect.center, True, False) pygame.mixer.Channel(3).play(music.stomp) enemy.kill() elif enemy.type == "rshell": if self.dir_face == "right": create_item(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, self, self.items, "rshell_mov", enemy.rect.right, enemy.rect.bottom, enemy.rect.center, False, True) pygame.mixer.Channel(3).play(music.stomp) enemy.kill() elif self.dir_face == "left": create_item(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, self, self.items, "rshell_mov", enemy.rect.left, enemy.rect.bottom, enemy.rect.center, True, False) pygame.mixer.Channel(3).play(music.stomp) enemy.kill() elif enemy.type != "shell" and enemy.type != "bshell" and enemy.type != "rshell": if self.state == "reg": self.death_blow = True elif self.state == "fire": self.invinc = 60 self.grow_up('assets/mario/Rsmario_stand.bmp') self.state = "super" pygame.mixer.Channel(5).play(music.pdown) else: self.invinc = 60 self.grow_up('assets/mario/Rmario_stand.bmp') self.state = "reg" pygame.mixer.Channel(5).play(music.pdown) self.change_y = 0 for item in self.items: if self.rect.colliderect( item.rect ) and self.death is False and item.type != "fireball": if item.type == "mushroom": self.grow_up('assets/mario/Rsmario_stand.bmp') self.state = "super" pygame.mixer.Channel(2).play(music.pup) if item.type == "coin" or item.type == "coin1" or item.type == "coin2": self.ai_settings.coins += 1 self.ai_settings.high_score -= 800 self.scores.prep_coins() pygame.mixer.Channel(2).play(music.coin) if item.type == "star": self.invinc = 300 self.star_power = True pygame.mixer.Channel(2).play(music.pup) if item.type == "1upshroom": self.ai_settings.mario_lives += 1 self.scores.prep_lives() pygame.mixer.Channel(2).play(music.one_up) if self.state == "super" and item.type == "fireflower": self.state = "fire" pygame.mixer.Channel(2).play(music.pup) if self.state != "super" and item.type == "fireflower": self.grow_up('assets/mario/Rsmario_stand.bmp') pygame.mixer.Channel(2).play(music.pup) self.state = "fire" if item.type != "shell_mov" and item.type != "bshell_mov" and item.type != "rshell_mov": self.items.remove(item) if item.type == "ax": self.win = True for block in self.g_blocks: if block.type_ == "bridge": block.kill() self.ai_settings.high_score += 1000 self.scores.prep_score() if self.rect.y >= 720 - self.rect.height and self.change_y >= 0 and not self.died or self.death_blow: self.change_y = -26 self.jumping = False self.death = True self.died = True self.win = False self.state = "dead" self.death_blow = False self.frames_ = ['assets/mario/mario_dead.bmp'] self.timer.frames = self.frames_ self.fric = 0 self.change_x = 0 self.timer.reset()
def cur_item(self, block, music, mario): if block.type_ == "pup" and self.state == "reg": if self.dir_face == "right": left = False right = True else: left = True right = False create_item(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, self, self.items, "mushroom", float(block.rect.x) + 25, block.rect.bottom - 60, float(block.rect.x), left, right) if block.type_ == "pup" and (self.state == "super" or self.state == "fire"): create_item(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, self, self.items, "fireflower", float(block.rect.x) + 25, block.rect.bottom - 30, float(block.rect.x), False, False) if block.type_ == "qcoin": create_item(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, self, self.items, "coin", float(block.rect.x) + 25, block.rect.bottom - 30, float(block.rect.x), False, False) if block.type_ == "hidden": create_item(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, self, self.items, "1upshroom", float(block.rect.x) + 25, block.rect.bottom - 30, float(block.rect.x), False, True) if block.type_ == "bcoin": create_item(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, self, self.items, "coin", float(block.rect.x) + 25, block.rect.bottom - 30, float(block.rect.x), False, False) if block.type_ == "star": create_item(self.ai_settings, self.screen, self.g_blocks, self.bg_blocks, self, self.items, "star", float(block.rect.x) + 25, block.rect.bottom - 60, float(block.rect.x), False, True) block.blipup(music, mario)