├── 01 (2).txt ├── PythonSuperMario-master ├── .idea │ ├── PythonSuperMario-master.iml │ ├── inspectionProfiles │ │ └── profiles_settings.xml │ ├── misc.xml │ ├── modules.xml │ └── workspace.xml ├── README.md ├── main.py ├── resources │ ├── demo │ │ ├── level_1_1.png │ │ ├── level_1_2.png │ │ ├── level_1_3.png │ │ └── level_1_4.png │ └── graphics │ │ ├── enemies.png │ │ ├── item_objects.png │ │ ├── level_1.png │ │ ├── level_2.png │ │ ├── level_3.png │ │ ├── level_4.png │ │ ├── mario_bros.png │ │ ├── smb_enemies_sheet.png │ │ ├── text_images.png │ │ ├── tile_set.png │ │ └── title_screen.png └── source │ ├── __init__.py │ ├── __pycache__ │ ├── __init__.cpython-38.pyc │ ├── constants.cpython-38.pyc │ ├── main.cpython-38.pyc │ ├── setup.cpython-38.pyc │ └── tools.cpython-38.pyc │ ├── components │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-38.pyc │ │ ├── box.cpython-38.pyc │ │ ├── brick.cpython-38.pyc │ │ ├── coin.cpython-38.pyc │ │ ├── enemy.cpython-38.pyc │ │ ├── info.cpython-38.pyc │ │ ├── player.cpython-38.pyc │ │ ├── powerup.cpython-38.pyc │ │ └── stuff.cpython-38.pyc │ ├── box.py │ ├── brick.py │ ├── coin.py │ ├── enemy.py │ ├── info.py │ ├── player.py │ ├── powerup.py │ └── stuff.py │ ├── constants.py │ ├── data │ ├── maps │ │ ├── level_1.json │ │ ├── level_2.json │ │ ├── level_3.json │ │ └── level_4.json │ └── player │ │ ├── luigi.json │ │ └── mario.json │ ├── main.py │ ├── setup.py │ ├── states │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-38.pyc │ │ ├── level.cpython-38.pyc │ │ ├── load_screen.cpython-38.pyc │ │ └── main_menu.cpython-38.pyc │ ├── level.py │ ├── load_screen.py │ └── main_menu.py │ └── tools.py ├── README.md └── README1.md /01 (2).txt: -------------------------------------------------------------------------------- 1 | hello world! -------------------------------------------------------------------------------- /PythonSuperMario-master/.idea/PythonSuperMario-master.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 12 | -------------------------------------------------------------------------------- /PythonSuperMario-master/.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /PythonSuperMario-master/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | -------------------------------------------------------------------------------- /PythonSuperMario-master/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /PythonSuperMario-master/.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | 12 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 1596182347807 58 | 63 | 64 | 65 | 66 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /PythonSuperMario-master/README.md: -------------------------------------------------------------------------------- 1 | # SuperMario 2 | A improved supermario game based on https://github.com/justinmeister/Mario-Level-1. 3 | * support four levels:level 1-1 to level 1-4 4 | * support go into the pipe 5 | * use json file to store level data (e.g. position of enemy, brick, box and pipe) 6 | * add new enemies in level 1-3 and 1-4 7 | * add slider in level 1-2 8 | 9 | # Requirement 10 | * Python 3.7 11 | * Python-Pygame 1.9 12 | 13 | # How To Start Game 14 | $ python main.py 15 | 16 | # How to Play 17 | * use LEFT/RIGHT/DOWN key to control player 18 | * use key 'a' to jump 19 | * use key 's' to shoot firewall or run 20 | 21 | # Demo 22 | ![level_1_1](https://raw.githubusercontent.com/marblexu/PythonSuperMario/master/resources/demo/level_1_1.png) 23 | ![level_1_2](https://raw.githubusercontent.com/marblexu/PythonSuperMario/master/resources/demo/level_1_2.png) 24 | ![level_1_3](https://raw.githubusercontent.com/marblexu/PythonSuperMario/master/resources/demo/level_1_3.png) 25 | ![level_1_4](https://raw.githubusercontent.com/marblexu/PythonSuperMario/master/resources/demo/level_1_4.png) 26 | -------------------------------------------------------------------------------- /PythonSuperMario-master/main.py: -------------------------------------------------------------------------------- 1 | import pygame as pg 2 | from source.main import main 3 | 4 | if __name__=='__main__': 5 | main() 6 | pg.quit() -------------------------------------------------------------------------------- /PythonSuperMario-master/resources/demo/level_1_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/resources/demo/level_1_1.png -------------------------------------------------------------------------------- /PythonSuperMario-master/resources/demo/level_1_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/resources/demo/level_1_2.png -------------------------------------------------------------------------------- /PythonSuperMario-master/resources/demo/level_1_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/resources/demo/level_1_3.png -------------------------------------------------------------------------------- /PythonSuperMario-master/resources/demo/level_1_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/resources/demo/level_1_4.png -------------------------------------------------------------------------------- /PythonSuperMario-master/resources/graphics/enemies.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/resources/graphics/enemies.png -------------------------------------------------------------------------------- /PythonSuperMario-master/resources/graphics/item_objects.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/resources/graphics/item_objects.png -------------------------------------------------------------------------------- /PythonSuperMario-master/resources/graphics/level_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/resources/graphics/level_1.png -------------------------------------------------------------------------------- /PythonSuperMario-master/resources/graphics/level_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/resources/graphics/level_2.png -------------------------------------------------------------------------------- /PythonSuperMario-master/resources/graphics/level_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/resources/graphics/level_3.png -------------------------------------------------------------------------------- /PythonSuperMario-master/resources/graphics/level_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/resources/graphics/level_4.png -------------------------------------------------------------------------------- /PythonSuperMario-master/resources/graphics/mario_bros.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/resources/graphics/mario_bros.png -------------------------------------------------------------------------------- /PythonSuperMario-master/resources/graphics/smb_enemies_sheet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/resources/graphics/smb_enemies_sheet.png -------------------------------------------------------------------------------- /PythonSuperMario-master/resources/graphics/text_images.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/resources/graphics/text_images.png -------------------------------------------------------------------------------- /PythonSuperMario-master/resources/graphics/tile_set.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/resources/graphics/tile_set.png -------------------------------------------------------------------------------- /PythonSuperMario-master/resources/graphics/title_screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/resources/graphics/title_screen.png -------------------------------------------------------------------------------- /PythonSuperMario-master/source/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/source/__init__.py -------------------------------------------------------------------------------- /PythonSuperMario-master/source/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/source/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /PythonSuperMario-master/source/__pycache__/constants.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/source/__pycache__/constants.cpython-38.pyc -------------------------------------------------------------------------------- /PythonSuperMario-master/source/__pycache__/main.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/source/__pycache__/main.cpython-38.pyc -------------------------------------------------------------------------------- /PythonSuperMario-master/source/__pycache__/setup.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/source/__pycache__/setup.cpython-38.pyc -------------------------------------------------------------------------------- /PythonSuperMario-master/source/__pycache__/tools.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/source/__pycache__/tools.cpython-38.pyc -------------------------------------------------------------------------------- /PythonSuperMario-master/source/components/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/source/components/__init__.py -------------------------------------------------------------------------------- /PythonSuperMario-master/source/components/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/source/components/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /PythonSuperMario-master/source/components/__pycache__/box.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/source/components/__pycache__/box.cpython-38.pyc -------------------------------------------------------------------------------- /PythonSuperMario-master/source/components/__pycache__/brick.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/source/components/__pycache__/brick.cpython-38.pyc -------------------------------------------------------------------------------- /PythonSuperMario-master/source/components/__pycache__/coin.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/source/components/__pycache__/coin.cpython-38.pyc -------------------------------------------------------------------------------- /PythonSuperMario-master/source/components/__pycache__/enemy.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/source/components/__pycache__/enemy.cpython-38.pyc -------------------------------------------------------------------------------- /PythonSuperMario-master/source/components/__pycache__/info.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/source/components/__pycache__/info.cpython-38.pyc -------------------------------------------------------------------------------- /PythonSuperMario-master/source/components/__pycache__/player.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/source/components/__pycache__/player.cpython-38.pyc -------------------------------------------------------------------------------- /PythonSuperMario-master/source/components/__pycache__/powerup.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/source/components/__pycache__/powerup.cpython-38.pyc -------------------------------------------------------------------------------- /PythonSuperMario-master/source/components/__pycache__/stuff.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/source/components/__pycache__/stuff.cpython-38.pyc -------------------------------------------------------------------------------- /PythonSuperMario-master/source/components/box.py: -------------------------------------------------------------------------------- 1 | __author__ = 'marble_xu' 2 | 3 | import pygame as pg 4 | from .. import setup, tools 5 | from .. import constants as c 6 | from . import coin, powerup 7 | 8 | class Box(pg.sprite.Sprite): 9 | def __init__(self, x, y, type, group=None, name=c.MAP_BOX): 10 | pg.sprite.Sprite.__init__(self) 11 | 12 | self.frames = [] 13 | self.frame_index = 0 14 | self.load_frames() 15 | self.image = self.frames[self.frame_index] 16 | self.rect = self.image.get_rect() 17 | self.rect.x = x 18 | self.rect.y = y 19 | 20 | self.rest_height = y 21 | self.animation_timer = 0 22 | self.first_half = True # First half of animation cycle 23 | self.state = c.RESTING 24 | self.y_vel = 0 25 | self.gravity = 1.2 26 | self.type = type 27 | self.group = group 28 | self.name = name 29 | 30 | def load_frames(self): 31 | sheet = setup.GFX['tile_set'] 32 | frame_rect_list = [(384, 0, 16, 16), (400, 0, 16, 16), 33 | (416, 0, 16, 16), (400, 0, 16, 16), (432, 0, 16, 16)] 34 | for frame_rect in frame_rect_list: 35 | self.frames.append(tools.get_image(sheet, *frame_rect, 36 | c.BLACK, c.BRICK_SIZE_MULTIPLIER)) 37 | 38 | def update(self, game_info): 39 | self.current_time = game_info[c.CURRENT_TIME] 40 | if self.state == c.RESTING: 41 | self.resting() 42 | elif self.state == c.BUMPED: 43 | self.bumped() 44 | 45 | def resting(self): 46 | time_list = [375, 125, 125, 125] 47 | if (self.current_time - self.animation_timer) > time_list[self.frame_index]: 48 | self.frame_index += 1 49 | if self.frame_index == 4: 50 | self.frame_index = 0 51 | self.animation_timer = self.current_time 52 | 53 | self.image = self.frames[self.frame_index] 54 | 55 | def bumped(self): 56 | self.rect.y += self.y_vel 57 | self.y_vel += self.gravity 58 | 59 | if self.rect.y > self.rest_height + 5: 60 | self.rect.y = self.rest_height 61 | self.state = c.OPENED 62 | if self.type == c.TYPE_MUSHROOM: 63 | self.group.add(powerup.Mushroom(self.rect.centerx, self.rect.y)) 64 | elif self.type == c.TYPE_FIREFLOWER: 65 | self.group.add(powerup.FireFlower(self.rect.centerx, self.rect.y)) 66 | elif self.type == c.TYPE_LIFEMUSHROOM: 67 | self.group.add(powerup.LifeMushroom(self.rect.centerx, self.rect.y)) 68 | self.frame_index = 4 69 | self.image = self.frames[self.frame_index] 70 | 71 | def start_bump(self, score_group): 72 | self.y_vel = -6 73 | self.state = c.BUMPED 74 | 75 | if self.type == c.TYPE_COIN: 76 | self.group.add(coin.Coin(self.rect.centerx, self.rect.y, score_group)) 77 | -------------------------------------------------------------------------------- /PythonSuperMario-master/source/components/brick.py: -------------------------------------------------------------------------------- 1 | __author__ = 'marble_xu' 2 | 3 | import pygame as pg 4 | from .. import setup, tools 5 | from .. import constants as c 6 | from . import coin, stuff, powerup 7 | 8 | def create_brick(brick_group, item, level): 9 | if c.COLOR in item: 10 | color = item[c.COLOR] 11 | else: 12 | color = c.COLOR_TYPE_ORANGE 13 | 14 | x, y, type = item['x'], item['y'], item['type'] 15 | if type == c.TYPE_COIN: 16 | brick_group.add(Brick(x, y, type, 17 | color, level.coin_group)) 18 | elif (type == c.TYPE_STAR or 19 | type == c.TYPE_FIREFLOWER or 20 | type == c.TYPE_LIFEMUSHROOM): 21 | brick_group.add(Brick(x, y, type, 22 | color, level.powerup_group)) 23 | else: 24 | if c.BRICK_NUM in item: 25 | create_brick_list(brick_group, item[c.BRICK_NUM], x, y, type, 26 | color, item['direction']) 27 | else: 28 | brick_group.add(Brick(x, y, type, color)) 29 | 30 | 31 | def create_brick_list(brick_group, num, x, y, type, color, direction): 32 | ''' direction:horizontal, create brick from left to right, direction:vertical, create brick from up to bottom ''' 33 | size = 43 # 16 * c.BRICK_SIZE_MULTIPLIER is 43 34 | tmp_x, tmp_y = x, y 35 | for i in range(num): 36 | if direction == c.VERTICAL: 37 | tmp_y = y + i * size 38 | else: 39 | tmp_x = x + i * size 40 | brick_group.add(Brick(tmp_x, tmp_y, type, color)) 41 | 42 | class Brick(stuff.Stuff): 43 | def __init__(self, x, y, type, color=c.ORANGE, group=None, name=c.MAP_BRICK): 44 | orange_rect = [(16, 0, 16, 16), (432, 0, 16, 16)] 45 | green_rect = [(208, 32, 16, 16), (48, 32, 16, 16)] 46 | if color == c.COLOR_TYPE_ORANGE: 47 | frame_rect = orange_rect 48 | else: 49 | frame_rect = green_rect 50 | stuff.Stuff.__init__(self, x, y, setup.GFX['tile_set'], 51 | frame_rect, c.BRICK_SIZE_MULTIPLIER) 52 | 53 | self.rest_height = y 54 | self.state = c.RESTING 55 | self.y_vel = 0 56 | self.gravity = 1.2 57 | self.type = type 58 | if self.type == c.TYPE_COIN: 59 | self.coin_num = 10 60 | else: 61 | self.coin_num = 0 62 | self.group = group 63 | self.name = name 64 | 65 | def update(self): 66 | if self.state == c.BUMPED: 67 | self.bumped() 68 | 69 | def bumped(self): 70 | self.rect.y += self.y_vel 71 | self.y_vel += self.gravity 72 | 73 | if self.rect.y >= self.rest_height: 74 | self.rect.y = self.rest_height 75 | if self.type == c.TYPE_COIN: 76 | if self.coin_num > 0: 77 | self.state = c.RESTING 78 | else: 79 | self.state = c.OPENED 80 | elif self.type == c.TYPE_STAR: 81 | self.state = c.OPENED 82 | self.group.add(powerup.Star(self.rect.centerx, self.rest_height)) 83 | elif self.type == c.TYPE_FIREFLOWER: 84 | self.state = c.OPENED 85 | self.group.add(powerup.FireFlower(self.rect.centerx, self.rest_height)) 86 | elif self.type == c.TYPE_LIFEMUSHROOM: 87 | self.state = c.OPENED 88 | self.group.add(powerup.LifeMushroom(self.rect.centerx, self.rest_height)) 89 | else: 90 | self.state = c.RESTING 91 | 92 | def start_bump(self, score_group): 93 | self.y_vel -= 7 94 | 95 | if self.type == c.TYPE_COIN: 96 | if self.coin_num > 0: 97 | self.group.add(coin.Coin(self.rect.centerx, self.rect.y, score_group)) 98 | self.coin_num -= 1 99 | if self.coin_num == 0: 100 | self.frame_index = 1 101 | self.image = self.frames[self.frame_index] 102 | elif (self.type == c.TYPE_STAR or 103 | self.type == c.TYPE_FIREFLOWER or 104 | self.type == c.TYPE_LIFEMUSHROOM): 105 | self.frame_index = 1 106 | self.image = self.frames[self.frame_index] 107 | 108 | self.state = c.BUMPED 109 | 110 | def change_to_piece(self, group): 111 | arg_list = [(self.rect.x, self.rect.y - (self.rect.height/2), -2, -12), 112 | (self.rect.right, self.rect.y - (self.rect.height/2), 2, -12), 113 | (self.rect.x, self.rect.y, -2, -6), 114 | (self.rect.right, self.rect.y, 2, -6)] 115 | 116 | for arg in arg_list: 117 | group.add(BrickPiece(*arg)) 118 | self.kill() 119 | 120 | class BrickPiece(stuff.Stuff): 121 | def __init__(self, x, y, x_vel, y_vel): 122 | stuff.Stuff.__init__(self, x, y, setup.GFX['tile_set'], 123 | [(68, 20, 8, 8)], c.BRICK_SIZE_MULTIPLIER) 124 | self.x_vel = x_vel 125 | self.y_vel = y_vel 126 | self.gravity = .8 127 | 128 | def update(self, *args): 129 | self.rect.x += self.x_vel 130 | self.rect.y += self.y_vel 131 | self.y_vel += self.gravity 132 | if self.rect.y > c.SCREEN_HEIGHT: 133 | self.kill() 134 | 135 | -------------------------------------------------------------------------------- /PythonSuperMario-master/source/components/coin.py: -------------------------------------------------------------------------------- 1 | __author__ = 'marble_xu' 2 | 3 | import pygame as pg 4 | from .. import setup, tools 5 | from .. import constants as c 6 | 7 | class Coin(pg.sprite.Sprite): 8 | def __init__(self, x, y, score_group): 9 | pg.sprite.Sprite.__init__(self) 10 | 11 | self.frames = [] 12 | self.frame_index = 0 13 | self.load_frames() 14 | self.image = self.frames[self.frame_index] 15 | self.rect = self.image.get_rect() 16 | self.rect.centerx = x 17 | self.rect.bottom = y - 5 18 | self.gravity = 1 19 | self.y_vel = -15 20 | self.animation_timer = 0 21 | self.initial_height = self.rect.bottom - 5 22 | self.score_group = score_group 23 | 24 | def load_frames(self): 25 | sheet = setup.GFX[c.ITEM_SHEET] 26 | frame_rect_list = [(52, 113, 8, 14), (4, 113, 8, 14), 27 | (20, 113, 8, 14), (36, 113, 8, 14)] 28 | for frame_rect in frame_rect_list: 29 | self.frames.append(tools.get_image(sheet, *frame_rect, 30 | c.BLACK, c.BRICK_SIZE_MULTIPLIER)) 31 | 32 | def update(self, game_info): 33 | self.current_time = game_info[c.CURRENT_TIME] 34 | self.spinning() 35 | 36 | def spinning(self): 37 | self.image = self.frames[self.frame_index] 38 | self.rect.y += self.y_vel 39 | self.y_vel += self.gravity 40 | 41 | if (self.current_time - self.animation_timer) > 80: 42 | if self.frame_index < 3: 43 | self.frame_index += 1 44 | else: 45 | self.frame_index = 0 46 | self.animation_timer = self.current_time 47 | 48 | if self.rect.bottom > self.initial_height: 49 | self.kill() 50 | 51 | class FlashCoin(pg.sprite.Sprite): 52 | def __init__(self, x, y): 53 | pg.sprite.Sprite.__init__(self) 54 | self.frame_index = 0 55 | self.frames = [] 56 | self.load_frames() 57 | self.image = self.frames[self.frame_index] 58 | self.rect = self.image.get_rect() 59 | self.rect.x = x 60 | self.rect.y = y 61 | self.animation_timer = 0 62 | 63 | def load_frames(self): 64 | sheet = setup.GFX[c.ITEM_SHEET] 65 | frame_rect_list = [(1, 160, 5, 8), (9, 160, 5, 8), 66 | (17, 160, 5, 8), (9, 160, 5, 8)] 67 | for frame_rect in frame_rect_list: 68 | self.frames.append(tools.get_image(sheet, *frame_rect, 69 | c.BLACK, c.BRICK_SIZE_MULTIPLIER)) 70 | 71 | def update(self, current_time): 72 | time_list = [375, 125, 125, 125] 73 | if self.animation_timer == 0: 74 | self.animation_timer = current_time 75 | elif (current_time - self.animation_timer) > time_list[self.frame_index]: 76 | self.frame_index += 1 77 | if self.frame_index == 4: 78 | self.frame_index = 0 79 | self.animation_timer = current_time 80 | 81 | self.image = self.frames[self.frame_index] 82 | 83 | class StaticCoin(pg.sprite.Sprite): 84 | def __init__(self, x, y): 85 | pg.sprite.Sprite.__init__(self) 86 | self.frame_index = 0 87 | self.frames = [] 88 | self.load_frames() 89 | self.image = self.frames[self.frame_index] 90 | self.rect = self.image.get_rect() 91 | self.rect.x = x 92 | self.rect.y = y 93 | self.animation_timer = 0 94 | 95 | def load_frames(self): 96 | sheet = setup.GFX[c.ITEM_SHEET] 97 | frame_rect_list = [(3, 98, 9, 13), (19, 98, 9, 13), 98 | (35, 98, 9, 13), (51, 98, 9, 13)] 99 | for frame_rect in frame_rect_list: 100 | self.frames.append(tools.get_image(sheet, *frame_rect, 101 | c.BLACK, c.BRICK_SIZE_MULTIPLIER)) 102 | 103 | def update(self, game_info): 104 | self.current_time = game_info[c.CURRENT_TIME] 105 | 106 | time_list = [375, 125, 125, 125] 107 | if self.animation_timer == 0: 108 | self.animation_timer = self.current_time 109 | elif (self.current_time - self.animation_timer) > time_list[self.frame_index]: 110 | self.frame_index += 1 111 | if self.frame_index == 4: 112 | self.frame_index = 0 113 | self.animation_timer = self.current_time 114 | 115 | self.image = self.frames[self.frame_index] -------------------------------------------------------------------------------- /PythonSuperMario-master/source/components/enemy.py: -------------------------------------------------------------------------------- 1 | __author__ = 'marble_xu' 2 | 3 | import math 4 | import pygame as pg 5 | from .. import setup, tools 6 | from .. import constants as c 7 | 8 | ENEMY_SPEED = 1 9 | 10 | def create_enemy(item, level): 11 | dir = c.LEFT if item['direction'] == 0 else c.RIGHT 12 | color = item[c.COLOR] 13 | if c.ENEMY_RANGE in item: 14 | in_range = item[c.ENEMY_RANGE] 15 | range_start = item['range_start'] 16 | range_end = item['range_end'] 17 | else: 18 | in_range = False 19 | range_start = range_end = 0 20 | 21 | if item['type'] == c.ENEMY_TYPE_GOOMBA: 22 | sprite = Goomba(item['x'], item['y'], dir, color, 23 | in_range, range_start, range_end) 24 | elif item['type'] == c.ENEMY_TYPE_KOOPA: 25 | sprite = Koopa(item['x'], item['y'], dir, color, 26 | in_range, range_start, range_end) 27 | elif item['type'] == c.ENEMY_TYPE_FLY_KOOPA: 28 | isVertical = False if item['is_vertical'] == 0 else True 29 | sprite = FlyKoopa(item['x'], item['y'], dir, color, 30 | in_range, range_start, range_end, isVertical) 31 | elif item['type'] == c.ENEMY_TYPE_PIRANHA: 32 | sprite = Piranha(item['x'], item['y'], dir, color, 33 | in_range, range_start, range_end) 34 | elif item['type'] == c.ENEMY_TYPE_FIRE_KOOPA: 35 | sprite = FireKoopa(item['x'], item['y'], dir, color, 36 | in_range, range_start, range_end, level) 37 | elif item['type'] == c.ENEMY_TYPE_FIRESTICK: 38 | '''use a number of fireballs to stimulate a firestick''' 39 | sprite = [] 40 | num = item['num'] 41 | center_x, center_y = item['x'], item['y'] 42 | for i in range(num): 43 | radius = i * 21 # 8 * 2.69 = 21 44 | sprite.append(FireStick(center_x, center_y, dir, color, 45 | radius)) 46 | return sprite 47 | 48 | class Enemy(pg.sprite.Sprite): 49 | def __init__(self): 50 | pg.sprite.Sprite.__init__(self) 51 | 52 | def setup_enemy(self, x, y, direction, name, sheet, frame_rect_list, 53 | in_range, range_start, range_end, isVertical=False): 54 | self.frames = [] 55 | self.frame_index = 0 56 | self.animate_timer = 0 57 | self.gravity = 1.5 58 | self.state = c.WALK 59 | 60 | self.name = name 61 | self.direction = direction 62 | self.load_frames(sheet, frame_rect_list) 63 | self.image = self.frames[self.frame_index] 64 | self.rect = self.image.get_rect() 65 | self.rect.x = x 66 | self.rect.bottom = y 67 | self.in_range = in_range 68 | self.range_start = range_start 69 | self.range_end = range_end 70 | self.isVertical = isVertical 71 | self.set_velocity() 72 | self.death_timer = 0 73 | 74 | def load_frames(self, sheet, frame_rect_list): 75 | for frame_rect in frame_rect_list: 76 | self.frames.append(tools.get_image(sheet, *frame_rect, 77 | c.BLACK, c.SIZE_MULTIPLIER)) 78 | 79 | def set_velocity(self): 80 | if self.isVertical: 81 | self.x_vel = 0 82 | self.y_vel = ENEMY_SPEED 83 | else: 84 | self.x_vel = ENEMY_SPEED *-1 if self.direction == c.LEFT else ENEMY_SPEED 85 | self.y_vel = 0 86 | 87 | def update(self, game_info, level): 88 | self.current_time = game_info[c.CURRENT_TIME] 89 | self.handle_state() 90 | self.animation() 91 | self.update_position(level) 92 | 93 | def handle_state(self): 94 | if (self.state == c.WALK or 95 | self.state == c.FLY): 96 | self.walking() 97 | elif self.state == c.FALL: 98 | self.falling() 99 | elif self.state == c.JUMPED_ON: 100 | self.jumped_on() 101 | elif self.state == c.DEATH_JUMP: 102 | self.death_jumping() 103 | elif self.state == c.SHELL_SLIDE: 104 | self.shell_sliding() 105 | elif self.state == c.REVEAL: 106 | self.revealing() 107 | 108 | def walking(self): 109 | if (self.current_time - self.animate_timer) > 125: 110 | if self.direction == c.RIGHT: 111 | if self.frame_index == 4: 112 | self.frame_index += 1 113 | elif self.frame_index == 5: 114 | self.frame_index = 4 115 | else: 116 | if self.frame_index == 0: 117 | self.frame_index += 1 118 | elif self.frame_index == 1: 119 | self.frame_index = 0 120 | self.animate_timer = self.current_time 121 | 122 | def falling(self): 123 | if self.y_vel < 10: 124 | self.y_vel += self.gravity 125 | 126 | def jumped_on(self): 127 | pass 128 | 129 | def death_jumping(self): 130 | self.rect.y += self.y_vel 131 | self.rect.x += self.x_vel 132 | self.y_vel += self.gravity 133 | if self.rect.y > c.SCREEN_HEIGHT: 134 | self.kill() 135 | 136 | def shell_sliding(self): 137 | if self.direction == c.RIGHT: 138 | self.x_vel = 10 139 | else: 140 | self.x_vel = -10 141 | 142 | def revealing(self): 143 | pass 144 | 145 | def start_death_jump(self, direction): 146 | self.y_vel = -8 147 | self.x_vel = 2 if direction == c.RIGHT else -2 148 | self.gravity = .5 149 | self.frame_index = 3 150 | self.state = c.DEATH_JUMP 151 | 152 | def animation(self): 153 | self.image = self.frames[self.frame_index] 154 | 155 | def update_position(self, level): 156 | self.rect.x += self.x_vel 157 | self.check_x_collisions(level) 158 | 159 | if self.in_range and self.isVertical: 160 | if self.rect.y < self.range_start: 161 | self.rect.y = self.range_start 162 | self.y_vel = ENEMY_SPEED 163 | elif self.rect.bottom > self.range_end: 164 | self.rect.bottom = self.range_end 165 | self.y_vel = -1 * ENEMY_SPEED 166 | 167 | self.rect.y += self.y_vel 168 | if (self.state != c.DEATH_JUMP and 169 | self.state != c.FLY): 170 | self.check_y_collisions(level) 171 | 172 | if self.rect.x <= 0: 173 | self.kill() 174 | elif self.rect.y > (level.viewport.bottom): 175 | self.kill() 176 | 177 | def check_x_collisions(self, level): 178 | if self.in_range and not self.isVertical: 179 | if self.rect.x < self.range_start: 180 | self.rect.x = self.range_start 181 | self.change_direction(c.RIGHT) 182 | elif self.rect.right > self.range_end: 183 | self.rect.right = self.range_end 184 | self.change_direction(c.LEFT) 185 | else: 186 | collider = pg.sprite.spritecollideany(self, level.ground_step_pipe_group) 187 | if collider: 188 | if self.direction == c.RIGHT: 189 | self.rect.right = collider.rect.left 190 | self.change_direction(c.LEFT) 191 | elif self.direction == c.LEFT: 192 | self.rect.left = collider.rect.right 193 | self.change_direction(c.RIGHT) 194 | 195 | if self.state == c.SHELL_SLIDE: 196 | enemy = pg.sprite.spritecollideany(self, level.enemy_group) 197 | if enemy: 198 | level.update_score(100, enemy, 0) 199 | level.move_to_dying_group(level.enemy_group, enemy) 200 | enemy.start_death_jump(self.direction) 201 | 202 | def change_direction(self, direction): 203 | self.direction = direction 204 | if self.direction == c.RIGHT: 205 | self.x_vel = ENEMY_SPEED 206 | if self.state == c.WALK or self.state == c.FLY: 207 | self.frame_index = 4 208 | else: 209 | self.x_vel = ENEMY_SPEED * -1 210 | if self.state == c.WALK or self.state == c.FLY: 211 | self.frame_index = 0 212 | 213 | def check_y_collisions(self, level): 214 | # decrease runtime delay: when enemey is on the ground, don't check brick and box 215 | if self.rect.bottom >= c.GROUND_HEIGHT: 216 | sprite_group = level.ground_step_pipe_group 217 | else: 218 | sprite_group = pg.sprite.Group(level.ground_step_pipe_group, 219 | level.brick_group, level.box_group) 220 | sprite = pg.sprite.spritecollideany(self, sprite_group) 221 | if sprite and sprite.name != c.MAP_SLIDER: 222 | if self.rect.top <= sprite.rect.top: 223 | self.rect.bottom = sprite.rect.y 224 | self.y_vel = 0 225 | self.state = c.WALK 226 | level.check_is_falling(self) 227 | 228 | class Goomba(Enemy): 229 | def __init__(self, x, y, direction, color, in_range, 230 | range_start, range_end, name=c.GOOMBA): 231 | Enemy.__init__(self) 232 | frame_rect_list = self.get_frame_rect(color) 233 | self.setup_enemy(x, y, direction, name, setup.GFX[c.ENEMY_SHEET], 234 | frame_rect_list, in_range, range_start, range_end) 235 | # dead jump image 236 | self.frames.append(pg.transform.flip(self.frames[2], False, True)) 237 | # right walk images 238 | self.frames.append(pg.transform.flip(self.frames[0], True, False)) 239 | self.frames.append(pg.transform.flip(self.frames[1], True, False)) 240 | 241 | def get_frame_rect(self, color): 242 | if color == c.COLOR_TYPE_GREEN: 243 | frame_rect_list = [(0, 34, 16, 16), (30, 34, 16, 16), 244 | (61, 30, 16, 16)] 245 | else: 246 | frame_rect_list = [(0, 4, 16, 16), (30, 4, 16, 16), 247 | (61, 0, 16, 16)] 248 | return frame_rect_list 249 | 250 | def jumped_on(self): 251 | self.x_vel = 0 252 | self.frame_index = 2 253 | if self.death_timer == 0: 254 | self.death_timer = self.current_time 255 | elif (self.current_time - self.death_timer) > 500: 256 | self.kill() 257 | 258 | class Koopa(Enemy): 259 | def __init__(self, x, y, direction, color, in_range, 260 | range_start, range_end, name=c.KOOPA): 261 | Enemy.__init__(self) 262 | frame_rect_list = self.get_frame_rect(color) 263 | self.setup_enemy(x, y, direction, name, setup.GFX[c.ENEMY_SHEET], 264 | frame_rect_list, in_range, range_start, range_end) 265 | # dead jump image 266 | self.frames.append(pg.transform.flip(self.frames[2], False, True)) 267 | # right walk images 268 | self.frames.append(pg.transform.flip(self.frames[0], True, False)) 269 | self.frames.append(pg.transform.flip(self.frames[1], True, False)) 270 | 271 | def get_frame_rect(self, color): 272 | if color == c.COLOR_TYPE_GREEN: 273 | frame_rect_list = [(150, 0, 16, 24), (180, 0, 16, 24), 274 | (360, 5, 16, 15)] 275 | elif color == c.COLOR_TYPE_RED: 276 | frame_rect_list = [(150, 30, 16, 24), (180, 30, 16, 24), 277 | (360, 35, 16, 15)] 278 | else: 279 | frame_rect_list = [(150, 60, 16, 24), (180, 60, 16, 24), 280 | (360, 65, 16, 15)] 281 | return frame_rect_list 282 | 283 | def jumped_on(self): 284 | self.x_vel = 0 285 | self.frame_index = 2 286 | x = self.rect.x 287 | bottom = self.rect.bottom 288 | self.rect = self.frames[self.frame_index].get_rect() 289 | self.rect.x = x 290 | self.rect.bottom = bottom 291 | self.in_range = False 292 | 293 | class FlyKoopa(Enemy): 294 | def __init__(self, x, y, direction, color, in_range, 295 | range_start, range_end, isVertical, name=c.FLY_KOOPA): 296 | Enemy.__init__(self) 297 | frame_rect_list = self.get_frame_rect(color) 298 | self.setup_enemy(x, y, direction, name, setup.GFX[c.ENEMY_SHEET], 299 | frame_rect_list, in_range, range_start, range_end, isVertical) 300 | # dead jump image 301 | self.frames.append(pg.transform.flip(self.frames[2], False, True)) 302 | # right walk images 303 | self.frames.append(pg.transform.flip(self.frames[0], True, False)) 304 | self.frames.append(pg.transform.flip(self.frames[1], True, False)) 305 | self.state = c.FLY 306 | 307 | def get_frame_rect(self, color): 308 | if color == c.COLOR_TYPE_GREEN: 309 | frame_rect_list = [(90, 0, 16, 24), (120, 0, 16, 24), 310 | (330, 5, 16, 15)] 311 | else: 312 | frame_rect_list = [(90, 30, 16, 24), (120, 30, 16, 24), 313 | (330, 35, 16, 15)] 314 | return frame_rect_list 315 | 316 | def jumped_on(self): 317 | self.x_vel = 0 318 | self.frame_index = 2 319 | x = self.rect.x 320 | bottom = self.rect.bottom 321 | self.rect = self.frames[self.frame_index].get_rect() 322 | self.rect.x = x 323 | self.rect.bottom = bottom 324 | self.in_range = False 325 | self.isVertical = False 326 | 327 | class FireKoopa(Enemy): 328 | def __init__(self, x, y, direction, color, in_range, 329 | range_start, range_end, level, name=c.FIRE_KOOPA): 330 | Enemy.__init__(self) 331 | frame_rect_list = [(2, 210, 32, 32), (42, 210, 32, 32), 332 | (82, 210, 32, 32), (122, 210, 32, 32)] 333 | self.setup_enemy(x, y, direction, name, setup.GFX[c.ENEMY_SHEET], 334 | frame_rect_list, in_range, range_start, range_end) 335 | # right walk images 336 | self.frames.append(pg.transform.flip(self.frames[0], True, False)) 337 | self.frames.append(pg.transform.flip(self.frames[1], True, False)) 338 | self.frames.append(pg.transform.flip(self.frames[2], True, False)) 339 | self.frames.append(pg.transform.flip(self.frames[3], True, False)) 340 | self.x_vel = 0 341 | self.gravity = 0.3 342 | self.level = level 343 | self.fire_timer = 0 344 | self.jump_timer = 0 345 | 346 | def load_frames(self, sheet, frame_rect_list): 347 | for frame_rect in frame_rect_list: 348 | self.frames.append(tools.get_image(sheet, *frame_rect, 349 | c.BLACK, c.BRICK_SIZE_MULTIPLIER)) 350 | 351 | def walking(self): 352 | if (self.current_time - self.animate_timer) > 250: 353 | if self.direction == c.RIGHT: 354 | self.frame_index += 1 355 | if self.frame_index > 7: 356 | self.frame_index = 4 357 | else: 358 | self.frame_index += 1 359 | if self.frame_index > 3: 360 | self.frame_index = 0 361 | self.animate_timer = self.current_time 362 | 363 | self.shoot_fire() 364 | if self.should_jump(): 365 | self.y_vel = -7 366 | 367 | def falling(self): 368 | if self.y_vel < 7: 369 | self.y_vel += self.gravity 370 | self.shoot_fire() 371 | 372 | def should_jump(self): 373 | if (self.rect.x - self.level.player.rect.x) < 400: 374 | if (self.current_time - self.jump_timer) > 2500: 375 | self.jump_timer = self.current_time 376 | return True 377 | return False 378 | 379 | def shoot_fire(self): 380 | if (self.current_time - self.fire_timer) > 3000: 381 | self.fire_timer = self.current_time 382 | self.level.enemy_group.add(Fire(self.rect.x, self.rect.bottom-20, self.direction)) 383 | 384 | class Fire(Enemy): 385 | def __init__(self, x, y, direction, name=c.FIRE): 386 | Enemy.__init__(self) 387 | frame_rect_list = [(101, 253, 23, 8), (131, 253, 23, 8)] 388 | in_range, range_start, range_end = False, 0, 0 389 | self.setup_enemy(x, y, direction, name, setup.GFX[c.ENEMY_SHEET], 390 | frame_rect_list, in_range, range_start, range_end) 391 | # right images 392 | self.frames.append(pg.transform.flip(self.frames[0], True, False)) 393 | self.frames.append(pg.transform.flip(self.frames[1], True, False)) 394 | self.state = c.FLY 395 | self.x_vel = 5 if self.direction == c.RIGHT else -5 396 | 397 | def check_x_collisions(self, level): 398 | sprite_group = pg.sprite.Group(level.ground_step_pipe_group, 399 | level.brick_group, level.box_group) 400 | sprite = pg.sprite.spritecollideany(self, sprite_group) 401 | if sprite: 402 | self.kill() 403 | 404 | def start_death_jump(self, direction): 405 | self.kill() 406 | 407 | class Piranha(Enemy): 408 | def __init__(self, x, y, direction, color, in_range, 409 | range_start, range_end, name=c.PIRANHA): 410 | Enemy.__init__(self) 411 | frame_rect_list = self.get_frame_rect(color) 412 | self.setup_enemy(x, y, direction, name, setup.GFX[c.ENEMY_SHEET], 413 | frame_rect_list, in_range, range_start, range_end) 414 | self.state = c.REVEAL 415 | self.y_vel = 1 416 | self.wait_timer = 0 417 | self.group = pg.sprite.Group() 418 | self.group.add(self) 419 | 420 | def get_frame_rect(self, color): 421 | if color == c.COLOR_TYPE_GREEN: 422 | frame_rect_list = [(390, 30, 16, 24), (420, 30, 16, 24)] 423 | else: 424 | frame_rect_list = [(390, 60, 16, 24), (420, 60, 16, 24)] 425 | return frame_rect_list 426 | 427 | def revealing(self): 428 | if (self.current_time - self.animate_timer) > 250: 429 | if self.frame_index == 0: 430 | self.frame_index += 1 431 | elif self.frame_index == 1: 432 | self.frame_index = 0 433 | self.animate_timer = self.current_time 434 | 435 | def update_position(self, level): 436 | if self.check_player_is_on(level): 437 | pass 438 | else: 439 | if self.rect.y < self.range_start: 440 | self.rect.y = self.range_start 441 | self.y_vel = 1 442 | elif self.rect.bottom > self.range_end: 443 | if self.wait_timer == 0: 444 | self.wait_timer = self.current_time 445 | elif (self.current_time - self.wait_timer) < 3000: 446 | return 447 | else: 448 | self.wait_timer = 0 449 | self.rect.bottom = self.range_end 450 | self.y_vel = -1 451 | self.rect.y += self.y_vel 452 | 453 | def check_player_is_on(self, level): 454 | result = False 455 | self.rect.y -= 5 456 | sprite = pg.sprite.spritecollideany(level.player, self.group) 457 | if sprite: 458 | result = True 459 | self.rect.y += 5 460 | return result 461 | 462 | def start_death_jump(self, direction): 463 | self.kill() 464 | 465 | class FireStick(pg.sprite.Sprite): 466 | def __init__(self, center_x, center_y, direction, color, radius, name=c.FIRESTICK): 467 | '''the firestick will rotate around the center of a circle''' 468 | pg.sprite.Sprite.__init__(self) 469 | 470 | self.frames = [] 471 | self.frame_index = 0 472 | self.animate_timer = 0 473 | self.name = name 474 | rect_list = [(96, 144, 8, 8), (104, 144, 8, 8), 475 | (96, 152, 8, 8), (104, 152, 8, 8)] 476 | self.load_frames(setup.GFX[c.ITEM_SHEET], rect_list) 477 | self.animate_timer = 0 478 | self.image = self.frames[self.frame_index] 479 | self.rect = self.image.get_rect() 480 | self.rect.x = center_x - radius 481 | self.rect.y = center_y 482 | self.center_x = center_x 483 | self.center_y = center_y 484 | self.radius = radius 485 | self.angle = 0 486 | 487 | def load_frames(self, sheet, frame_rect_list): 488 | for frame_rect in frame_rect_list: 489 | self.frames.append(tools.get_image(sheet, *frame_rect, 490 | c.BLACK, c.BRICK_SIZE_MULTIPLIER)) 491 | 492 | def update(self, game_info, level): 493 | self.current_time = game_info[c.CURRENT_TIME] 494 | if (self.current_time - self.animate_timer) > 100: 495 | if self.frame_index < 3: 496 | self.frame_index += 1 497 | else: 498 | self.frame_index = 0 499 | self.animate_timer = self.current_time 500 | self.image = self.frames[self.frame_index] 501 | 502 | self.angle += 1 503 | if self.angle == 360: 504 | self.angle = 0 505 | radian = math.radians(self.angle) 506 | self.rect.x = self.center_x + math.sin(radian) * self.radius 507 | self.rect.y = self.center_y + math.cos(radian) * self.radius 508 | -------------------------------------------------------------------------------- /PythonSuperMario-master/source/components/info.py: -------------------------------------------------------------------------------- 1 | __author__ = 'marble_xu' 2 | 3 | import pygame as pg 4 | from .. import setup, tools 5 | from .. import constants as c 6 | from . import coin 7 | 8 | class Character(pg.sprite.Sprite): 9 | def __init__(self, image): 10 | pg.sprite.Sprite.__init__(self) 11 | self.image = image 12 | self.rect = self.image.get_rect() 13 | 14 | class Info(): 15 | def __init__(self, game_info, state): 16 | self.coin_total = game_info[c.COIN_TOTAL] 17 | self.total_lives = game_info[c.LIVES] 18 | self.state = state 19 | self.game_info = game_info 20 | 21 | self.create_font_image_dict() 22 | self.create_info_labels() 23 | self.create_state_labels() 24 | self.flashing_coin = coin.FlashCoin(280, 53) 25 | 26 | def create_font_image_dict(self): 27 | self.image_dict = {} 28 | image_list = [] 29 | 30 | image_rect_list = [# 0 - 9 31 | (3, 230, 7, 7), (12, 230, 7, 7), (19, 230, 7, 7), 32 | (27, 230, 7, 7), (35, 230, 7, 7), (43, 230, 7, 7), 33 | (51, 230, 7, 7), (59, 230, 7, 7), (67, 230, 7, 7), 34 | (75, 230, 7, 7), 35 | # A - Z 36 | (83, 230, 7, 7), (91, 230, 7, 7), (99, 230, 7, 7), 37 | (107, 230, 7, 7), (115, 230, 7, 7), (123, 230, 7, 7), 38 | (3, 238, 7, 7), (11, 238, 7, 7), (20, 238, 7, 7), 39 | (27, 238, 7, 7), (35, 238, 7, 7), (44, 238, 7, 7), 40 | (51, 238, 7, 7), (59, 238, 7, 7), (67, 238, 7, 7), 41 | (75, 238, 7, 7), (83, 238, 7, 7), (91, 238, 7, 7), 42 | (99, 238, 7, 7), (108, 238, 7, 7), (115, 238, 7, 7), 43 | (123, 238, 7, 7), (3, 246, 7, 7), (11, 246, 7, 7), 44 | (20, 246, 7, 7), (27, 246, 7, 7), (48, 246, 7, 7), 45 | # -* 46 | (68, 249, 6, 2), (75, 247, 6, 6)] 47 | 48 | character_string = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ -*' 49 | 50 | for character, image_rect in zip(character_string, image_rect_list): 51 | self.image_dict[character] = tools.get_image(setup.GFX['text_images'], 52 | *image_rect, (92, 148, 252), 2.9) 53 | 54 | def create_info_labels(self): 55 | self.score_text = [] 56 | self.coin_count_text = [] 57 | self.mario_label = [] 58 | self.world_label = [] 59 | self.time_label = [] 60 | self.stage_label = [] 61 | 62 | self.create_label(self.score_text, '000000', 75, 55) 63 | self.create_label(self.coin_count_text, '*00', 300, 55) 64 | self.create_label(self.mario_label, 'MARIO', 75, 30) 65 | self.create_label(self.world_label, 'WORLD', 450, 30) 66 | self.create_label(self.time_label, 'TIME', 625, 30) 67 | self.create_label(self.stage_label, '1-1', 472, 55) 68 | 69 | self.info_labels = [self.score_text, self.coin_count_text, self.mario_label, 70 | self.world_label, self.time_label, self.stage_label] 71 | 72 | def create_state_labels(self): 73 | if self.state == c.MAIN_MENU: 74 | self.create_main_menu_labels() 75 | elif self.state == c.LOAD_SCREEN: 76 | self.create_player_image() 77 | self.create_load_screen_labels() 78 | elif self.state == c.LEVEL: 79 | self.create_level_labels() 80 | elif self.state == c.GAME_OVER: 81 | self.create_game_over_labels() 82 | elif self.state == c.TIME_OUT: 83 | self.create_time_out_labels() 84 | 85 | def create_player_image(self): 86 | self.life_times_image = tools.get_image(setup.GFX['text_images'], 87 | 75, 247, 6, 6, (92, 148, 252), 2.9) 88 | self.life_times_rect = self.life_times_image.get_rect(center=(378, 295)) 89 | self.life_total_label = [] 90 | self.create_label(self.life_total_label, str(self.total_lives), 450, 285) 91 | 92 | if self.game_info[c.PLAYER_NAME] == c.PLAYER_MARIO: 93 | rect = (178, 32, 12, 16) 94 | else: 95 | rect = (178, 128, 12, 16) 96 | self.player_image = tools.get_image(setup.GFX['mario_bros'], 97 | *rect, (92, 148, 252), 2.9) 98 | self.player_rect = self.player_image.get_rect(center=(320, 290)) 99 | 100 | def create_main_menu_labels(self): 101 | mario_game = [] 102 | luigi_game = [] 103 | top = [] 104 | top_score = [] 105 | 106 | self.create_label(mario_game, c.PLAYER1, 272, 360) 107 | self.create_label(luigi_game, c.PLAYER2, 272, 405) 108 | self.create_label(top, 'TOP - ', 290, 465) 109 | self.create_label(top_score, '000000', 400, 465) 110 | self.state_labels = [mario_game, luigi_game, top, top_score, 111 | *self.info_labels] 112 | 113 | def create_load_screen_labels(self): 114 | world_label = [] 115 | self.stage_label2 = [] 116 | 117 | self.create_label(world_label, 'WORLD', 280, 200) 118 | self.create_label(self.stage_label2, '1-1', 430, 200) 119 | self.state_labels = [world_label, self.stage_label2, 120 | *self.info_labels, self.life_total_label] 121 | 122 | def create_level_labels(self): 123 | self.time = c.GAME_TIME_OUT 124 | self.current_time = 0 125 | 126 | self.clock_time_label = [] 127 | self.create_label(self.clock_time_label, str(self.time), 645, 55) 128 | self.state_labels = [*self.info_labels, self.clock_time_label] 129 | 130 | def create_game_over_labels(self): 131 | game_label = [] 132 | over_label = [] 133 | 134 | self.create_label(game_label, 'GAME', 280, 300) 135 | self.create_label(over_label, 'OVER', 400, 300) 136 | 137 | self.state_labels = [game_label, over_label, *self.info_labels] 138 | 139 | def create_time_out_labels(self): 140 | timeout_label = [] 141 | self.create_label(timeout_label, 'TIME OUT', 290, 310) 142 | self.state_labels = [timeout_label, *self.info_labels] 143 | 144 | def create_label(self, label_list, string, x, y): 145 | for letter in string: 146 | label_list.append(Character(self.image_dict[letter])) 147 | self.set_label_rects(label_list, x, y) 148 | 149 | def set_label_rects(self, label_list, x, y): 150 | for i, letter in enumerate(label_list): 151 | letter.rect.x = x + ((letter.rect.width + 3) * i) 152 | letter.rect.y = y 153 | if letter.image == self.image_dict['-']: 154 | letter.rect.y += 7 155 | letter.rect.x += 2 156 | 157 | def update(self, level_info, level=None): 158 | self.level = level 159 | self.handle_level_state(level_info) 160 | 161 | def handle_level_state(self, level_info): 162 | self.score = level_info[c.SCORE] 163 | self.update_text(self.score_text, self.score) 164 | self.update_text(self.coin_count_text, level_info[c.COIN_TOTAL]) 165 | self.update_text(self.stage_label, level_info[c.LEVEL_NUM]) 166 | self.flashing_coin.update(level_info[c.CURRENT_TIME]) 167 | if self.state == c.LOAD_SCREEN: 168 | self.update_text(self.stage_label2, level_info[c.LEVEL_NUM]) 169 | if self.state == c.LEVEL: 170 | if (level_info[c.CURRENT_TIME] - self.current_time) > 1000: 171 | self.current_time = level_info[c.CURRENT_TIME] 172 | self.time -= 1 173 | self.update_text(self.clock_time_label, self.time, True) 174 | 175 | def update_text(self, text, score, reset=False): 176 | if reset and len(text) > len(str(score)): 177 | text.remove(text[0]) 178 | index = len(text) - 1 179 | for digit in reversed(str(score)): 180 | rect = text[index].rect 181 | text[index] = Character(self.image_dict[digit]) 182 | text[index].rect = rect 183 | index -= 1 184 | 185 | def draw(self, surface): 186 | self.draw_info(surface, self.state_labels) 187 | if self.state == c.LOAD_SCREEN: 188 | surface.blit(self.player_image, self.player_rect) 189 | surface.blit(self.life_times_image, self.life_times_rect) 190 | surface.blit(self.flashing_coin.image, self.flashing_coin.rect) 191 | 192 | def draw_info(self, surface, label_list): 193 | for label in label_list: 194 | for letter in label: 195 | surface.blit(letter.image, letter.rect) 196 | 197 | 198 | 199 | -------------------------------------------------------------------------------- /PythonSuperMario-master/source/components/player.py: -------------------------------------------------------------------------------- 1 | __author__ = 'marble_xu' 2 | 3 | import os 4 | import json 5 | import pygame as pg 6 | from .. import setup, tools 7 | from .. import constants as c 8 | from ..components import powerup 9 | 10 | class Player(pg.sprite.Sprite): 11 | def __init__(self, player_name): 12 | pg.sprite.Sprite.__init__(self) 13 | self.player_name = player_name 14 | self.load_data() 15 | self.setup_timer() 16 | self.setup_state() 17 | self.setup_speed() 18 | self.load_images() 19 | 20 | if c.DEBUG: 21 | self.right_frames = self.big_fire_frames[0] 22 | self.left_frames = self.big_fire_frames[1] 23 | self.big = True 24 | self.fire = True 25 | 26 | self.frame_index = 0 27 | self.state = c.WALK 28 | self.image = self.right_frames[self.frame_index] 29 | self.rect = self.image.get_rect() 30 | 31 | def restart(self): 32 | '''restart after player is dead or go to next level''' 33 | if self.dead: 34 | self.dead = False 35 | self.big = False 36 | self.fire = False 37 | self.set_player_image(self.small_normal_frames, 0) 38 | self.right_frames = self.small_normal_frames[0] 39 | self.left_frames = self.small_normal_frames[1] 40 | self.state = c.STAND 41 | 42 | def load_data(self): 43 | player_file = str(self.player_name) + '.json' 44 | file_path = os.path.join('source', 'data', 'player', player_file) 45 | f = open(file_path) 46 | self.player_data = json.load(f) 47 | 48 | def setup_timer(self): 49 | self.walking_timer = 0 50 | self.death_timer = 0 51 | self.flagpole_timer = 0 52 | self.transition_timer = 0 53 | self.hurt_invincible_timer = 0 54 | self.invincible_timer = 0 55 | self.last_fireball_time = 0 56 | 57 | def setup_state(self): 58 | self.facing_right = True 59 | self.allow_jump = True 60 | self.allow_fireball = True 61 | self.dead = False 62 | self.big = False 63 | self.fire = False 64 | self.hurt_invincible = False 65 | self.invincible = False 66 | self.crouching = False 67 | 68 | def setup_speed(self): 69 | speed = self.player_data[c.PLAYER_SPEED] 70 | self.x_vel = 0 71 | self.y_vel = 0 72 | 73 | self.max_walk_vel = speed[c.MAX_WALK_SPEED] 74 | self.max_run_vel = speed[c.MAX_RUN_SPEED] 75 | self.max_y_vel = speed[c.MAX_Y_VEL] 76 | self.walk_accel = speed[c.WALK_ACCEL] 77 | self.run_accel = speed[c.RUN_ACCEL] 78 | self.jump_vel = speed[c.JUMP_VEL] 79 | 80 | self.gravity = c.GRAVITY 81 | self.max_x_vel = self.max_walk_vel 82 | self.x_accel = self.walk_accel 83 | 84 | def load_images(self): 85 | sheet = setup.GFX['mario_bros'] 86 | frames_list = self.player_data[c.PLAYER_FRAMES] 87 | 88 | self.right_frames = [] 89 | self.left_frames = [] 90 | 91 | self.right_small_normal_frames = [] 92 | self.left_small_normal_frames = [] 93 | self.right_big_normal_frames = [] 94 | self.left_big_normal_frames = [] 95 | self.right_big_fire_frames = [] 96 | self.left_big_fire_frames = [] 97 | 98 | for name, frames in frames_list.items(): 99 | for frame in frames: 100 | image = tools.get_image(sheet, frame['x'], frame['y'], 101 | frame['width'], frame['height'], 102 | c.BLACK, c.SIZE_MULTIPLIER) 103 | left_image = pg.transform.flip(image, True, False) 104 | 105 | if name == c.RIGHT_SMALL_NORMAL: 106 | self.right_small_normal_frames.append(image) 107 | self.left_small_normal_frames.append(left_image) 108 | elif name == c.RIGHT_BIG_NORMAL: 109 | self.right_big_normal_frames.append(image) 110 | self.left_big_normal_frames.append(left_image) 111 | elif name == c.RIGHT_BIG_FIRE: 112 | self.right_big_fire_frames.append(image) 113 | self.left_big_fire_frames.append(left_image) 114 | 115 | self.small_normal_frames = [self.right_small_normal_frames, 116 | self.left_small_normal_frames] 117 | self.big_normal_frames = [self.right_big_normal_frames, 118 | self.left_big_normal_frames] 119 | self.big_fire_frames = [self.right_big_fire_frames, 120 | self.left_big_fire_frames] 121 | 122 | self.all_images = [self.right_small_normal_frames, 123 | self.left_small_normal_frames, 124 | self.right_big_normal_frames, 125 | self.left_big_normal_frames, 126 | self.right_big_fire_frames, 127 | self.left_big_fire_frames] 128 | 129 | self.right_frames = self.small_normal_frames[0] 130 | self.left_frames = self.small_normal_frames[1] 131 | 132 | def update(self, keys, game_info, fire_group): 133 | self.current_time = game_info[c.CURRENT_TIME] 134 | self.handle_state(keys, fire_group) 135 | self.check_if_hurt_invincible() 136 | self.check_if_invincible() 137 | self.animation() 138 | 139 | def handle_state(self, keys, fire_group): 140 | if self.state == c.STAND: 141 | self.standing(keys, fire_group) 142 | elif self.state == c.WALK: 143 | self.walking(keys, fire_group) 144 | elif self.state == c.JUMP: 145 | self.jumping(keys, fire_group) 146 | elif self.state == c.FALL: 147 | self.falling(keys, fire_group) 148 | elif self.state == c.DEATH_JUMP: 149 | self.jumping_to_death() 150 | elif self.state == c.FLAGPOLE: 151 | self.flag_pole_sliding() 152 | elif self.state == c.WALK_AUTO: 153 | self.walking_auto() 154 | elif self.state == c.END_OF_LEVEL_FALL: 155 | self.y_vel += self.gravity 156 | elif self.state == c.IN_CASTLE: 157 | self.frame_index = 0 158 | elif self.state == c.SMALL_TO_BIG: 159 | self.changing_to_big() 160 | elif self.state == c.BIG_TO_SMALL: 161 | self.changing_to_small() 162 | elif self.state == c.BIG_TO_FIRE: 163 | self.changing_to_fire() 164 | elif self.state == c.DOWN_TO_PIPE: 165 | self.y_vel = 1 166 | self.rect.y += self.y_vel 167 | elif self.state == c.UP_OUT_PIPE: 168 | self.y_vel = -1 169 | self.rect.y += self.y_vel 170 | if self.rect.bottom < self.up_pipe_y: 171 | self.state = c.STAND 172 | 173 | def check_to_allow_jump(self, keys): 174 | if not keys[tools.keybinding['jump']]: 175 | self.allow_jump = True 176 | 177 | def check_to_allow_fireball(self, keys): 178 | if not keys[tools.keybinding['action']]: 179 | self.allow_fireball = True 180 | 181 | def standing(self, keys, fire_group): 182 | self.check_to_allow_jump(keys) 183 | self.check_to_allow_fireball(keys) 184 | 185 | self.frame_index = 0 186 | self.x_vel = 0 187 | self.y_vel = 0 188 | 189 | if keys[tools.keybinding['action']]: 190 | if self.fire and self.allow_fireball: 191 | self.shoot_fireball(fire_group) 192 | 193 | if keys[tools.keybinding['down']]: 194 | self.update_crouch_or_not(True) 195 | 196 | if keys[tools.keybinding['left']]: 197 | self.facing_right = False 198 | self.update_crouch_or_not() 199 | self.state = c.WALK 200 | elif keys[tools.keybinding['right']]: 201 | self.facing_right = True 202 | self.update_crouch_or_not() 203 | self.state = c.WALK 204 | elif keys[tools.keybinding['jump']]: 205 | if self.allow_jump: 206 | self.state = c.JUMP 207 | self.y_vel = self.jump_vel 208 | 209 | if not keys[tools.keybinding['down']]: 210 | self.update_crouch_or_not() 211 | 212 | def update_crouch_or_not(self, isDown=False): 213 | if not self.big: 214 | self.crouching = True if isDown else False 215 | return 216 | if not isDown and not self.crouching: 217 | return 218 | 219 | self.crouching = True if isDown else False 220 | frame_index = 7 if isDown else 0 221 | bottom = self.rect.bottom 222 | left = self.rect.x 223 | if self.facing_right: 224 | self.image = self.right_frames[frame_index] 225 | else: 226 | self.image = self.left_frames[frame_index] 227 | self.rect = self.image.get_rect() 228 | self.rect.bottom = bottom 229 | self.rect.x = left 230 | self.frame_index = frame_index 231 | 232 | def walking(self, keys, fire_group): 233 | self.check_to_allow_jump(keys) 234 | self.check_to_allow_fireball(keys) 235 | 236 | if self.frame_index == 0: 237 | self.frame_index += 1 238 | self.walking_timer = self.current_time 239 | elif (self.current_time - self.walking_timer > 240 | self.calculate_animation_speed()): 241 | if self.frame_index < 3: 242 | self.frame_index += 1 243 | else: 244 | self.frame_index = 1 245 | self.walking_timer = self.current_time 246 | 247 | if keys[tools.keybinding['action']]: 248 | self.max_x_vel = self.max_run_vel 249 | self.x_accel = self.run_accel 250 | if self.fire and self.allow_fireball: 251 | self.shoot_fireball(fire_group) 252 | else: 253 | self.max_x_vel = self.max_walk_vel 254 | self.x_accel = self.walk_accel 255 | 256 | if keys[tools.keybinding['jump']]: 257 | if self.allow_jump: 258 | self.state = c.JUMP 259 | if abs(self.x_vel) > 4: 260 | self.y_vel = self.jump_vel - .5 261 | else: 262 | self.y_vel = self.jump_vel 263 | 264 | 265 | if keys[tools.keybinding['left']]: 266 | self.facing_right = False 267 | if self.x_vel > 0: 268 | self.frame_index = 5 269 | self.x_accel = c.SMALL_TURNAROUND 270 | 271 | self.x_vel = self.cal_vel(self.x_vel, self.max_x_vel, self.x_accel, True) 272 | elif keys[tools.keybinding['right']]: 273 | self.facing_right = True 274 | if self.x_vel < 0: 275 | self.frame_index = 5 276 | self.x_accel = c.SMALL_TURNAROUND 277 | 278 | self.x_vel = self.cal_vel(self.x_vel, self.max_x_vel, self.x_accel) 279 | else: 280 | if self.facing_right: 281 | if self.x_vel > 0: 282 | self.x_vel -= self.x_accel 283 | else: 284 | self.x_vel = 0 285 | self.state = c.STAND 286 | else: 287 | if self.x_vel < 0: 288 | self.x_vel += self.x_accel 289 | else: 290 | self.x_vel = 0 291 | self.state = c.STAND 292 | 293 | def jumping(self, keys, fire_group): 294 | """ y_vel value: positive is down, negative is up """ 295 | self.check_to_allow_fireball(keys) 296 | 297 | self.allow_jump = False 298 | self.frame_index = 4 299 | self.gravity = c.JUMP_GRAVITY 300 | self.y_vel += self.gravity 301 | 302 | if self.y_vel >= 0 and self.y_vel < self.max_y_vel: 303 | self.gravity = c.GRAVITY 304 | self.state = c.FALL 305 | 306 | if keys[tools.keybinding['right']]: 307 | self.x_vel = self.cal_vel(self.x_vel, self.max_x_vel, self.x_accel) 308 | elif keys[tools.keybinding['left']]: 309 | self.x_vel = self.cal_vel(self.x_vel, self.max_x_vel, self.x_accel, True) 310 | 311 | if not keys[tools.keybinding['jump']]: 312 | self.gravity = c.GRAVITY 313 | self.state = c.FALL 314 | 315 | if keys[tools.keybinding['action']]: 316 | if self.fire and self.allow_fireball: 317 | self.shoot_fireball(fire_group) 318 | 319 | def falling(self, keys, fire_group): 320 | self.check_to_allow_fireball(keys) 321 | self.y_vel = self.cal_vel(self.y_vel, self.max_y_vel, self.gravity) 322 | 323 | if keys[tools.keybinding['right']]: 324 | self.x_vel = self.cal_vel(self.x_vel, self.max_x_vel, self.x_accel) 325 | elif keys[tools.keybinding['left']]: 326 | self.x_vel = self.cal_vel(self.x_vel, self.max_x_vel, self.x_accel, True) 327 | 328 | if keys[tools.keybinding['action']]: 329 | if self.fire and self.allow_fireball: 330 | self.shoot_fireball(fire_group) 331 | 332 | def jumping_to_death(self): 333 | if self.death_timer == 0: 334 | self.death_timer = self.current_time 335 | elif (self.current_time - self.death_timer) > 500: 336 | self.rect.y += self.y_vel 337 | self.y_vel += self.gravity 338 | 339 | def cal_vel(self, vel, max_vel, accel, isNegative=False): 340 | """ max_vel and accel must > 0 """ 341 | if isNegative: 342 | new_vel = vel * -1 343 | else: 344 | new_vel = vel 345 | if (new_vel + accel) < max_vel: 346 | new_vel += accel 347 | else: 348 | new_vel = max_vel 349 | if isNegative: 350 | return new_vel * -1 351 | else: 352 | return new_vel 353 | 354 | def calculate_animation_speed(self): 355 | if self.x_vel == 0: 356 | animation_speed = 130 357 | elif self.x_vel > 0: 358 | animation_speed = 130 - (self.x_vel * 13) 359 | else: 360 | animation_speed = 130 - (self.x_vel * 13 * -1) 361 | return animation_speed 362 | 363 | def shoot_fireball(self, powerup_group): 364 | if (self.current_time - self.last_fireball_time) > 500: 365 | self.allow_fireball = False 366 | powerup_group.add(powerup.FireBall(self.rect.right, 367 | self.rect.y, self.facing_right)) 368 | self.last_fireball_time = self.current_time 369 | self.frame_index = 6 370 | 371 | def flag_pole_sliding(self): 372 | self.state = c.FLAGPOLE 373 | self.x_vel = 0 374 | self.y_vel = 5 375 | 376 | if self.flagpole_timer == 0: 377 | self.flagpole_timer = self.current_time 378 | elif self.rect.bottom < 493: 379 | if (self.current_time - self.flagpole_timer) < 65: 380 | self.frame_index = 9 381 | elif (self.current_time - self.flagpole_timer) < 130: 382 | self.frame_index = 10 383 | else: 384 | self.flagpole_timer = self.current_time 385 | elif self.rect.bottom >= 493: 386 | self.frame_index = 10 387 | 388 | def walking_auto(self): 389 | self.max_x_vel = 5 390 | self.x_accel = self.walk_accel 391 | 392 | self.x_vel = self.cal_vel(self.x_vel, self.max_x_vel, self.x_accel) 393 | 394 | if (self.walking_timer == 0 or (self.current_time - self.walking_timer) > 200): 395 | self.walking_timer = self.current_time 396 | elif (self.current_time - self.walking_timer > 397 | self.calculate_animation_speed()): 398 | if self.frame_index < 3: 399 | self.frame_index += 1 400 | else: 401 | self.frame_index = 1 402 | self.walking_timer = self.current_time 403 | 404 | def changing_to_big(self): 405 | timer_list = [135, 200, 365, 430, 495, 560, 625, 690, 755, 820, 885] 406 | # size value 0:small, 1:middle, 2:big 407 | size_list = [1, 0, 1, 0, 1, 2, 0, 1, 2, 0, 2] 408 | frames = [(self.small_normal_frames, 0), (self.small_normal_frames, 7), 409 | (self.big_normal_frames, 0)] 410 | if self.transition_timer == 0: 411 | self.big = True 412 | self.change_index = 0 413 | self.transition_timer = self.current_time 414 | elif (self.current_time - self.transition_timer) > timer_list[self.change_index]: 415 | if (self.change_index + 1) >= len(timer_list): 416 | # player becomes big 417 | self.transition_timer = 0 418 | self.set_player_image(self.big_normal_frames, 0) 419 | self.state = c.WALK 420 | self.right_frames = self.right_big_normal_frames 421 | self.left_frames = self.left_big_normal_frames 422 | else: 423 | frame, frame_index = frames[size_list[self.change_index]] 424 | self.set_player_image(frame, frame_index) 425 | self.change_index += 1 426 | 427 | def changing_to_small(self): 428 | timer_list = [265, 330, 395, 460, 525, 590, 655, 720, 785, 850, 915] 429 | # size value 0:big, 1:middle, 2:small 430 | size_list = [0, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2] 431 | frames = [(self.big_normal_frames, 4), (self.big_normal_frames, 8), 432 | (self.small_normal_frames, 8)] 433 | 434 | if self.transition_timer == 0: 435 | self.change_index = 0 436 | self.transition_timer = self.current_time 437 | elif (self.current_time - self.transition_timer) > timer_list[self.change_index]: 438 | if (self.change_index + 1) >= len(timer_list): 439 | # player becomes small 440 | self.transition_timer = 0 441 | self.set_player_image(self.small_normal_frames, 0) 442 | self.state = c.WALK 443 | self.big = False 444 | self.fire = False 445 | self.hurt_invincible = True 446 | self.right_frames = self.right_small_normal_frames 447 | self.left_frames = self.left_small_normal_frames 448 | else: 449 | frame, frame_index = frames[size_list[self.change_index]] 450 | self.set_player_image(frame, frame_index) 451 | self.change_index += 1 452 | 453 | def changing_to_fire(self): 454 | timer_list = [65, 195, 260, 325, 390, 455, 520, 585, 650, 715, 780, 845, 910, 975] 455 | # size value 0:fire, 1:big green, 2:big red, 3:big black 456 | size_list = [0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1] 457 | frames = [(self.big_fire_frames, 3), (self.big_normal_frames, 3), 458 | (self.big_fire_frames, 3), (self.big_normal_frames, 3)] 459 | 460 | if self.transition_timer == 0: 461 | self.change_index = 0 462 | self.transition_timer = self.current_time 463 | elif (self.current_time - self.transition_timer) > timer_list[self.change_index]: 464 | if (self.change_index + 1) >= len(timer_list): 465 | # player becomes fire 466 | self.transition_timer = 0 467 | self.set_player_image(self.big_fire_frames, 3) 468 | self.fire = True 469 | self.state = c.WALK 470 | self.right_frames = self.right_big_fire_frames 471 | self.left_frames = self.left_big_fire_frames 472 | else: 473 | frame, frame_index = frames[size_list[self.change_index]] 474 | self.set_player_image(frame, frame_index) 475 | self.change_index += 1 476 | 477 | def set_player_image(self, frames, frame_index): 478 | self.frame_index = frame_index 479 | if self.facing_right: 480 | self.right_frames = frames[0] 481 | self.image = frames[0][frame_index] 482 | else: 483 | self.left_frames = frames[1] 484 | self.image = frames[1][frame_index] 485 | bottom = self.rect.bottom 486 | centerx = self.rect.centerx 487 | self.rect = self.image.get_rect() 488 | self.rect.bottom = bottom 489 | self.rect.centerx = centerx 490 | 491 | def check_if_hurt_invincible(self): 492 | if self.hurt_invincible: 493 | if self.hurt_invincible_timer == 0: 494 | self.hurt_invincible_timer = self.current_time 495 | self.hurt_invincible_timer2 = self.current_time 496 | elif (self.current_time - self.hurt_invincible_timer) < 2000: 497 | if (self.current_time - self.hurt_invincible_timer2) < 35: 498 | self.image.set_alpha(0) 499 | elif (self.current_time - self.hurt_invincible_timer2) < 70: 500 | self.image.set_alpha(255) 501 | self.hurt_invincible_timer2 = self.current_time 502 | else: 503 | self.hurt_invincible = False 504 | self.hurt_invincible_timer = 0 505 | for frames in self.all_images: 506 | for image in frames: 507 | image.set_alpha(255) 508 | 509 | def check_if_invincible(self): 510 | if self.invincible: 511 | if self.invincible_timer == 0: 512 | self.invincible_timer = self.current_time 513 | self.invincible_timer2 = self.current_time 514 | elif (self.current_time - self.invincible_timer) < 10000: 515 | if (self.current_time - self.invincible_timer2) < 35: 516 | self.image.set_alpha(0) 517 | elif (self.current_time - self.invincible_timer2) < 70: 518 | self.image.set_alpha(255) 519 | self.invincible_timer2 = self.current_time 520 | elif (self.current_time - self.invincible_timer) < 12000: 521 | if (self.current_time - self.invincible_timer2) < 100: 522 | self.image.set_alpha(0) 523 | elif (self.current_time - self.invincible_timer2) < 200: 524 | self.image.set_alpha(255) 525 | self.invincible_timer2 = self.current_time 526 | else: 527 | self.invincible = False 528 | self.invincible_timer = 0 529 | for frames in self.all_images: 530 | for image in frames: 531 | image.set_alpha(255) 532 | 533 | def animation(self): 534 | if self.facing_right: 535 | self.image = self.right_frames[self.frame_index] 536 | else: 537 | self.image = self.left_frames[self.frame_index] 538 | 539 | def start_death_jump(self, game_info): 540 | self.dead = True 541 | self.y_vel = -11 542 | self.gravity = .5 543 | self.frame_index = 6 544 | self.state = c.DEATH_JUMP 545 | -------------------------------------------------------------------------------- /PythonSuperMario-master/source/components/powerup.py: -------------------------------------------------------------------------------- 1 | __author__ = 'marble_xu' 2 | 3 | import pygame as pg 4 | from .. import setup, tools 5 | from .. import constants as c 6 | from . import stuff 7 | 8 | class Powerup(stuff.Stuff): 9 | def __init__(self, x, y, sheet, image_rect_list, scale): 10 | stuff.Stuff.__init__(self, x, y, sheet, image_rect_list, scale) 11 | self.rect.centerx = x 12 | self.state = c.REVEAL 13 | self.y_vel = -1 14 | self.x_vel = 0 15 | self.direction = c.RIGHT 16 | self.box_height = y 17 | self.gravity = 1 18 | self.max_y_vel = 8 19 | self.animate_timer = 0 20 | 21 | def update_position(self, level): 22 | self.rect.x += self.x_vel 23 | self.check_x_collisions(level) 24 | 25 | self.rect.y += self.y_vel 26 | self.check_y_collisions(level) 27 | 28 | if self.rect.x <= 0: 29 | self.kill() 30 | elif self.rect.y > (level.viewport.bottom): 31 | self.kill() 32 | 33 | def check_x_collisions(self, level): 34 | sprite_group = pg.sprite.Group(level.ground_step_pipe_group, 35 | level.brick_group, level.box_group) 36 | sprite = pg.sprite.spritecollideany(self, sprite_group) 37 | if sprite: 38 | if self.direction == c.RIGHT: 39 | self.rect.right = sprite.rect.left-1 40 | self.direction = c.LEFT 41 | elif self.direction == c.LEFT: 42 | self.rect.left = sprite.rect.right 43 | self.direction = c.RIGHT 44 | self.x_vel = self.speed if self.direction == c.RIGHT else -1 * self.speed 45 | if sprite.name == c.MAP_BRICK: 46 | self.x_vel = 0 47 | 48 | def check_y_collisions(self, level): 49 | sprite_group = pg.sprite.Group(level.ground_step_pipe_group, 50 | level.brick_group, level.box_group) 51 | 52 | sprite = pg.sprite.spritecollideany(self, sprite_group) 53 | if sprite: 54 | self.y_vel = 0 55 | self.rect.bottom = sprite.rect.top 56 | self.state = c.SLIDE 57 | level.check_is_falling(self) 58 | 59 | def animation(self): 60 | self.image = self.frames[self.frame_index] 61 | 62 | class Mushroom(Powerup): 63 | def __init__(self, x, y): 64 | Powerup.__init__(self, x, y, setup.GFX[c.ITEM_SHEET], 65 | [(0, 0, 16, 16)], c.SIZE_MULTIPLIER) 66 | self.type = c.TYPE_MUSHROOM 67 | self.speed = 2 68 | 69 | def update(self, game_info, level): 70 | if self.state == c.REVEAL: 71 | self.rect.y += self.y_vel 72 | if self.rect.bottom <= self.box_height: 73 | self.rect.bottom = self.box_height 74 | self.y_vel = 0 75 | self.state = c.SLIDE 76 | elif self.state == c.SLIDE: 77 | self.x_vel = self.speed if self.direction == c.RIGHT else -1 * self.speed 78 | elif self.state == c.FALL: 79 | if self.y_vel < self.max_y_vel: 80 | self.y_vel += self.gravity 81 | 82 | if self.state == c.SLIDE or self.state == c.FALL: 83 | self.update_position(level) 84 | self.animation() 85 | 86 | class LifeMushroom(Mushroom): 87 | def __init__(self, x, y): 88 | Powerup.__init__(self, x, y, setup.GFX[c.ITEM_SHEET], 89 | [(16, 0, 16, 16)], c.SIZE_MULTIPLIER) 90 | self.type = c.TYPE_LIFEMUSHROOM 91 | self.speed = 2 92 | 93 | class FireFlower(Powerup): 94 | def __init__(self, x, y): 95 | frame_rect_list = [(0, 32, 16, 16), (16, 32, 16, 16), 96 | (32, 32, 16, 16), (48, 32, 16, 16)] 97 | Powerup.__init__(self, x, y, setup.GFX[c.ITEM_SHEET], 98 | frame_rect_list, c.SIZE_MULTIPLIER) 99 | self.type = c.TYPE_FIREFLOWER 100 | 101 | def update(self, game_info, *args): 102 | self.current_time = game_info[c.CURRENT_TIME] 103 | if self.state == c.REVEAL: 104 | self.rect.y += self.y_vel 105 | if self.rect.bottom <= self.box_height: 106 | self.rect.bottom = self.box_height 107 | self.y_vel = 0 108 | self.state = c.RESTING 109 | 110 | if (self.current_time - self.animate_timer) > 30: 111 | if self.frame_index < 3: 112 | self.frame_index += 1 113 | else: 114 | self.frame_index = 0 115 | self.animate_timer = self.current_time 116 | 117 | self.animation() 118 | 119 | class Star(Powerup): 120 | def __init__(self, x, y): 121 | frame_rect_list = [(1, 48, 15, 16), (17, 48, 15, 16), 122 | (33, 48, 15, 16), (49, 48, 15, 16)] 123 | Powerup.__init__(self, x, y, setup.GFX[c.ITEM_SHEET], 124 | frame_rect_list, c.SIZE_MULTIPLIER) 125 | self.type = c.TYPE_STAR 126 | self.gravity = .4 127 | self.speed = 5 128 | 129 | def update(self, game_info, level): 130 | self.current_time = game_info[c.CURRENT_TIME] 131 | if self.state == c.REVEAL: 132 | self.rect.y += self.y_vel 133 | if self.rect.bottom <= self.box_height: 134 | self.rect.bottom = self.box_height 135 | self.y_vel = -2 136 | self.state = c.BOUNCING 137 | elif self.state == c.BOUNCING: 138 | self.y_vel += self.gravity 139 | self.x_vel = self.speed if self.direction == c.RIGHT else -1 * self.speed 140 | 141 | if (self.current_time - self.animate_timer) > 30: 142 | if self.frame_index < 3: 143 | self.frame_index += 1 144 | else: 145 | self.frame_index = 0 146 | self.animate_timer = self.current_time 147 | 148 | if self.state == c.BOUNCING: 149 | self.update_position(level) 150 | self.animation() 151 | 152 | def check_y_collisions(self, level): 153 | sprite_group = pg.sprite.Group(level.ground_step_pipe_group, 154 | level.brick_group, level.box_group) 155 | 156 | sprite = pg.sprite.spritecollideany(self, sprite_group) 157 | 158 | if sprite: 159 | if self.rect.top > sprite.rect.top: 160 | self.y_vel = 5 161 | else: 162 | self.rect.bottom = sprite.rect.y 163 | self.y_vel = -5 164 | 165 | class FireBall(Powerup): 166 | def __init__(self, x, y, facing_right): 167 | # first 3 Frames are flying, last 4 frams are exploding 168 | frame_rect_list = [(96, 144, 8, 8), (104, 144, 8, 8), 169 | (96, 152, 8, 8), (104, 152, 8, 8), 170 | (112, 144, 16, 16), (112, 160, 16, 16), 171 | (112, 176, 16, 16)] 172 | Powerup.__init__(self, x, y, setup.GFX[c.ITEM_SHEET], 173 | frame_rect_list, c.SIZE_MULTIPLIER) 174 | self.type = c.TYPE_FIREBALL 175 | self.y_vel = 10 176 | self.gravity = .9 177 | self.state = c.FLYING 178 | self.rect.right = x 179 | if facing_right: 180 | self.direction = c.RIGHT 181 | self.x_vel = 12 182 | else: 183 | self.direction = c.LEFT 184 | self.x_vel = -12 185 | 186 | def update(self, game_info, level): 187 | self.current_time = game_info[c.CURRENT_TIME] 188 | 189 | if self.state == c.FLYING or self.state == c.BOUNCING: 190 | self.y_vel += self.gravity 191 | if (self.current_time - self.animate_timer) > 200: 192 | if self.frame_index < 3: 193 | self.frame_index += 1 194 | else: 195 | self.frame_index = 0 196 | self.animate_timer = self.current_time 197 | self.update_position(level) 198 | elif self.state == c.EXPLODING: 199 | if (self.current_time - self.animate_timer) > 50: 200 | if self.frame_index < 6: 201 | self.frame_index += 1 202 | else: 203 | self.kill() 204 | self.animate_timer = self.current_time 205 | 206 | 207 | self.animation() 208 | 209 | def check_x_collisions(self, level): 210 | sprite_group = pg.sprite.Group(level.ground_step_pipe_group, 211 | level.brick_group, level.box_group) 212 | sprite = pg.sprite.spritecollideany(self, sprite_group) 213 | if sprite: 214 | self.change_to_explode() 215 | 216 | def check_y_collisions(self, level): 217 | sprite_group = pg.sprite.Group(level.ground_step_pipe_group, 218 | level.brick_group, level.box_group) 219 | 220 | sprite = pg.sprite.spritecollideany(self, sprite_group) 221 | enemy = pg.sprite.spritecollideany(self, level.enemy_group) 222 | if sprite: 223 | if self.rect.top > sprite.rect.top: 224 | self.change_to_explode() 225 | else: 226 | self.rect.bottom = sprite.rect.y 227 | self.y_vel = -8 228 | if self.direction == c.RIGHT: 229 | self.x_vel = 15 230 | else: 231 | self.x_vel = -15 232 | self.state = c.BOUNCING 233 | elif enemy: 234 | if (enemy.name != c.FIRESTICK) : 235 | level.update_score(100, enemy, 0) 236 | level.move_to_dying_group(level.enemy_group, enemy) 237 | enemy.start_death_jump(self.direction) 238 | self.change_to_explode() 239 | 240 | def change_to_explode(self): 241 | self.frame_index = 4 242 | self.state = c.EXPLODING 243 | 244 | -------------------------------------------------------------------------------- /PythonSuperMario-master/source/components/stuff.py: -------------------------------------------------------------------------------- 1 | __author__ = 'marble_xu' 2 | 3 | import pygame as pg 4 | from .. import setup, tools 5 | from .. import constants as c 6 | 7 | class Collider(pg.sprite.Sprite): 8 | def __init__(self, x, y, width, height, name): 9 | pg.sprite.Sprite.__init__(self) 10 | self.image = pg.Surface((width, height)).convert() 11 | self.rect = self.image.get_rect() 12 | self.rect.x = x 13 | self.rect.y = y 14 | self.name = name 15 | if c.DEBUG: 16 | self.image.fill(c.RED) 17 | 18 | class Checkpoint(pg.sprite.Sprite): 19 | def __init__(self, x, y, width, height, type, enemy_groupid=0, map_index=0, name=c.MAP_CHECKPOINT): 20 | pg.sprite.Sprite.__init__(self) 21 | self.image = pg.Surface((width, height)) 22 | self.rect = self.image.get_rect() 23 | self.rect.x = x 24 | self.rect.y = y 25 | self.type = type 26 | self.enemy_groupid = enemy_groupid 27 | self.map_index = map_index 28 | self.name = name 29 | 30 | class Stuff(pg.sprite.Sprite): 31 | def __init__(self, x, y, sheet, image_rect_list, scale): 32 | pg.sprite.Sprite.__init__(self) 33 | 34 | self.frames = [] 35 | self.frame_index = 0 36 | for image_rect in image_rect_list: 37 | self.frames.append(tools.get_image(sheet, 38 | *image_rect, c.BLACK, scale)) 39 | self.image = self.frames[self.frame_index] 40 | self.rect = self.image.get_rect() 41 | self.rect.x = x 42 | self.rect.y = y 43 | 44 | def update(self, *args): 45 | pass 46 | 47 | class Pole(Stuff): 48 | def __init__(self, x, y): 49 | Stuff.__init__(self, x, y, setup.GFX['tile_set'], 50 | [(263, 144, 2, 16)], c.BRICK_SIZE_MULTIPLIER) 51 | 52 | class PoleTop(Stuff): 53 | def __init__(self, x, y): 54 | Stuff.__init__(self, x, y, setup.GFX['tile_set'], 55 | [(228, 120, 8, 8)], c.BRICK_SIZE_MULTIPLIER) 56 | 57 | class Flag(Stuff): 58 | def __init__(self, x, y): 59 | Stuff.__init__(self, x, y, setup.GFX[c.ITEM_SHEET], 60 | [(128, 32, 16, 16)], c.SIZE_MULTIPLIER) 61 | self.state = c.TOP_OF_POLE 62 | self.y_vel = 5 63 | 64 | def update(self): 65 | if self.state == c.SLIDE_DOWN: 66 | self.rect.y += self.y_vel 67 | if self.rect.bottom >= 485: 68 | self.state = c.BOTTOM_OF_POLE 69 | 70 | class CastleFlag(Stuff): 71 | def __init__(self, x, y): 72 | Stuff.__init__(self, x, y, setup.GFX[c.ITEM_SHEET], 73 | [(129, 2, 14, 14)], c.SIZE_MULTIPLIER) 74 | self.y_vel = -2 75 | self.target_height = y 76 | 77 | def update(self): 78 | if self.rect.bottom > self.target_height: 79 | self.rect.y += self.y_vel 80 | 81 | class Digit(pg.sprite.Sprite): 82 | def __init__(self, image): 83 | pg.sprite.Sprite.__init__(self) 84 | self.image = image 85 | self.rect = self.image.get_rect() 86 | 87 | class Score(): 88 | def __init__(self, x, y, score): 89 | self.x = x 90 | self.y = y 91 | self.y_vel = -3 92 | self.create_images_dict() 93 | self.score = score 94 | self.create_score_digit() 95 | self.distance = 130 if self.score == 1000 else 75 96 | 97 | def create_images_dict(self): 98 | self.image_dict = {} 99 | digit_rect_list = [(1, 168, 3, 8), (5, 168, 3, 8), 100 | (8, 168, 4, 8), (0, 0, 0, 0), 101 | (12, 168, 4, 8), (16, 168, 5, 8), 102 | (0, 0, 0, 0), (0, 0, 0, 0), 103 | (20, 168, 4, 8), (0, 0, 0, 0)] 104 | digit_string = '0123456789' 105 | for digit, image_rect in zip(digit_string, digit_rect_list): 106 | self.image_dict[digit] = tools.get_image(setup.GFX[c.ITEM_SHEET], 107 | *image_rect, c.BLACK, c.BRICK_SIZE_MULTIPLIER) 108 | 109 | def create_score_digit(self): 110 | self.digit_group = pg.sprite.Group() 111 | self.digit_list = [] 112 | for digit in str(self.score): 113 | self.digit_list.append(Digit(self.image_dict[digit])) 114 | 115 | for i, digit in enumerate(self.digit_list): 116 | digit.rect = digit.image.get_rect() 117 | digit.rect.x = self.x + (i * 10) 118 | digit.rect.y = self.y 119 | 120 | def update(self, score_list): 121 | for digit in self.digit_list: 122 | digit.rect.y += self.y_vel 123 | 124 | if (self.y - self.digit_list[0].rect.y) > self.distance: 125 | score_list.remove(self) 126 | 127 | def draw(self, screen): 128 | for digit in self.digit_list: 129 | screen.blit(digit.image, digit.rect) 130 | 131 | 132 | class Pipe(Stuff): 133 | def __init__(self, x, y, width, height, type, name=c.MAP_PIPE): 134 | if type == c.PIPE_TYPE_HORIZONTAL: 135 | rect = [(32, 128, 37, 30)] 136 | else: 137 | rect = [(0, 160, 32, 30)] 138 | Stuff.__init__(self, x, y, setup.GFX['tile_set'], 139 | rect, c.BRICK_SIZE_MULTIPLIER) 140 | self.name = name 141 | self.type = type 142 | if type != c.PIPE_TYPE_HORIZONTAL: 143 | self.create_image(x, y, height) 144 | 145 | def create_image(self, x, y, pipe_height): 146 | img = self.image 147 | rect = self.image.get_rect() 148 | width = rect.w 149 | height = rect.h 150 | self.image = pg.Surface((width, pipe_height)).convert() 151 | self.rect = self.image.get_rect() 152 | self.rect.x = x 153 | self.rect.y = y 154 | 155 | top_height = height//2 + 3 156 | bottom_height = height//2 - 3 157 | self.image.blit(img, (0,0), (0, 0, width, top_height)) 158 | num = (pipe_height - top_height) // bottom_height + 1 159 | for i in range(num): 160 | y = top_height + i * bottom_height 161 | self.image.blit(img, (0,y), (0, top_height, width, bottom_height)) 162 | self.image.set_colorkey(c.BLACK) 163 | 164 | def check_ignore_collision(self, level): 165 | if self.type == c.PIPE_TYPE_HORIZONTAL: 166 | return True 167 | elif level.player.state == c.DOWN_TO_PIPE: 168 | return True 169 | return False 170 | 171 | class Slider(Stuff): 172 | def __init__(self, x, y, num, direction, range_start, range_end, vel, name=c.MAP_SLIDER): 173 | Stuff.__init__(self, x, y, setup.GFX[c.ITEM_SHEET], 174 | [(64, 128, 15, 8)], 2.8) 175 | self.name = name 176 | self.create_image(x, y, num) 177 | self.range_start = range_start 178 | self.range_end = range_end 179 | self.direction = direction 180 | if self.direction == c.VERTICAL: 181 | self.y_vel = vel 182 | else: 183 | self.x_vel = vel 184 | 185 | 186 | def create_image(self, x, y, num): 187 | '''original slider image is short, we need to multiple it ''' 188 | if num == 1: 189 | return 190 | img = self.image 191 | rect = self.image.get_rect() 192 | width = rect.w 193 | height = rect.h 194 | self.image = pg.Surface((width * num, height)).convert() 195 | self.rect = self.image.get_rect() 196 | self.rect.x = x 197 | self.rect.y = y 198 | for i in range(num): 199 | x = i * width 200 | self.image.blit(img, (x,0)) 201 | self.image.set_colorkey(c.BLACK) 202 | 203 | def update(self): 204 | if self.direction ==c.VERTICAL: 205 | self.rect.y += self.y_vel 206 | if self.rect.y < -self.rect.h: 207 | self.rect.y = c.SCREEN_HEIGHT 208 | self.y_vel = -1 209 | elif self.rect.y > c.SCREEN_HEIGHT: 210 | self.rect.y = -self.rect.h 211 | self.y_vel = 1 212 | elif self.rect.y < self.range_start: 213 | self.rect.y = self.range_start 214 | self.y_vel = 1 215 | elif self.rect.bottom > self.range_end: 216 | self.rect.bottom = self.range_end 217 | self.y_vel = -1 218 | else: 219 | self.rect.x += self.x_vel 220 | if self.rect.x < self.range_start: 221 | self.rect.x = self.range_start 222 | self.x_vel = 1 223 | elif self.rect.left > self.range_end: 224 | self.rect.left = self.range_end 225 | self.x_vel = -1 226 | 227 | -------------------------------------------------------------------------------- /PythonSuperMario-master/source/constants.py: -------------------------------------------------------------------------------- 1 | __author__ = 'marble_xu' 2 | 3 | DEBUG = False 4 | DEBUG_START_X = 110 5 | DEBUG_START_y = 538 6 | 7 | SCREEN_HEIGHT = 600 8 | SCREEN_WIDTH = 800 9 | SCREEN_SIZE = (SCREEN_WIDTH,SCREEN_HEIGHT) 10 | 11 | ORIGINAL_CAPTION = "Super Mario Bros" 12 | 13 | ## COLORS ## 14 | # R G B 15 | GRAY = (100, 100, 100) 16 | NAVYBLUE = ( 60, 60, 100) 17 | WHITE = (255, 255, 255) 18 | RED = (255, 0, 0) 19 | GREEN = ( 0, 255, 0) 20 | FOREST_GREEN = ( 31, 162, 35) 21 | BLUE = ( 0, 0, 255) 22 | SKY_BLUE = ( 39, 145, 251) 23 | YELLOW = (255, 255, 0) 24 | ORANGE = (255, 128, 0) 25 | PURPLE = (255, 0, 255) 26 | CYAN = ( 0, 255, 255) 27 | BLACK = ( 0, 0, 0) 28 | NEAR_BLACK = ( 19, 15, 48) 29 | COMBLUE = (233, 232, 255) 30 | GOLD = (255, 215, 0) 31 | 32 | BGCOLOR = WHITE 33 | 34 | 35 | SIZE_MULTIPLIER = 2.5 36 | BRICK_SIZE_MULTIPLIER = 2.69 37 | BACKGROUND_MULTIPLER = 2.679 38 | GROUND_HEIGHT = SCREEN_HEIGHT - 62 39 | 40 | GAME_TIME_OUT = 301 41 | 42 | #STATES FOR ENTIRE GAME 43 | MAIN_MENU = 'main menu' 44 | LOAD_SCREEN = 'load screen' 45 | TIME_OUT = 'time out' 46 | GAME_OVER = 'game over' 47 | LEVEL = 'level' 48 | 49 | #MAIN MENU CURSOR STATES 50 | PLAYER1 = '1 PLAYER GAME' 51 | PLAYER2 = '2 PLAYER GAME' 52 | 53 | #GAME INFO DICTIONARY KEYS 54 | COIN_TOTAL = 'coin total' 55 | SCORE = 'score' 56 | TOP_SCORE = 'top score' 57 | LIVES = 'lives' 58 | CURRENT_TIME = 'current time' 59 | LEVEL_NUM = 'level num' 60 | PLAYER_NAME = 'player name' 61 | PLAYER_MARIO = 'mario' 62 | PLAYER_LUIGI = 'luigi' 63 | 64 | #MAP COMPONENTS 65 | MAP_IMAGE = 'image_name' 66 | MAP_MAPS = 'maps' 67 | SUB_MAP = 'sub_map' 68 | MAP_GROUND = 'ground' 69 | MAP_PIPE = 'pipe' 70 | PIPE_TYPE_NONE = 0 71 | PIPE_TYPE_IN = 1 # can go down in the pipe 72 | PIPE_TYPE_HORIZONTAL = 2 # can go right in the pipe 73 | MAP_STEP = 'step' 74 | MAP_BRICK = 'brick' 75 | BRICK_NUM = 'brick_num' 76 | TYPE_NONE = 0 77 | TYPE_COIN = 1 78 | TYPE_STAR = 2 79 | MAP_BOX = 'box' 80 | TYPE_MUSHROOM = 3 81 | TYPE_FIREFLOWER = 4 82 | TYPE_FIREBALL = 5 83 | TYPE_LIFEMUSHROOM = 6 84 | MAP_ENEMY = 'enemy' 85 | ENEMY_TYPE_GOOMBA = 0 86 | ENEMY_TYPE_KOOPA = 1 87 | ENEMY_TYPE_FLY_KOOPA = 2 88 | ENEMY_TYPE_PIRANHA = 3 89 | ENEMY_TYPE_FIRESTICK = 4 90 | ENEMY_TYPE_FIRE_KOOPA = 5 91 | ENEMY_RANGE = 'range' 92 | MAP_CHECKPOINT = 'checkpoint' 93 | ENEMY_GROUPID = 'enemy_groupid' 94 | MAP_INDEX = 'map_index' 95 | CHECKPOINT_TYPE_ENEMY = 0 96 | CHECKPOINT_TYPE_FLAG = 1 97 | CHECKPOINT_TYPE_CASTLE = 2 98 | CHECKPOINT_TYPE_MUSHROOM = 3 99 | CHECKPOINT_TYPE_PIPE = 4 # trigger player to go right in a pipe 100 | CHECKPOINT_TYPE_PIPE_UP = 5 # trigger player to another map and go up out of a pipe 101 | CHECKPOINT_TYPE_MAP = 6 # trigger player to go to another map 102 | CHECKPOINT_TYPE_BOSS = 7 # defeat the boss 103 | MAP_FLAGPOLE = 'flagpole' 104 | FLAGPOLE_TYPE_FLAG = 0 105 | FLAGPOLE_TYPE_POLE = 1 106 | FLAGPOLE_TYPE_TOP = 2 107 | MAP_SLIDER = 'slider' 108 | HORIZONTAL = 0 109 | VERTICAL = 1 110 | VELOCITY = 'velocity' 111 | MAP_COIN = 'coin' 112 | 113 | #COMPONENT COLOR 114 | COLOR = 'color' 115 | COLOR_TYPE_ORANGE = 0 116 | COLOR_TYPE_GREEN = 1 117 | COLOR_TYPE_RED = 2 118 | 119 | #BRICK STATES 120 | RESTING = 'resting' 121 | BUMPED = 'bumped' 122 | OPENED = 'opened' 123 | 124 | #MUSHROOM STATES 125 | REVEAL = 'reveal' 126 | SLIDE = 'slide' 127 | 128 | #Player FRAMES 129 | PLAYER_FRAMES = 'image_frames' 130 | RIGHT_SMALL_NORMAL = 'right_small_normal' 131 | RIGHT_BIG_NORMAL = 'right_big_normal' 132 | RIGHT_BIG_FIRE = 'right_big_fire' 133 | 134 | #PLAYER States 135 | STAND = 'standing' 136 | WALK = 'walk' 137 | JUMP = 'jump' 138 | FALL = 'fall' 139 | FLY = 'fly' 140 | SMALL_TO_BIG = 'small to big' 141 | BIG_TO_FIRE = 'big to fire' 142 | BIG_TO_SMALL = 'big to small' 143 | FLAGPOLE = 'flag pole' 144 | WALK_AUTO = 'walk auto' # not handle key input in this state 145 | END_OF_LEVEL_FALL = 'end of level fall' 146 | IN_CASTLE = 'in castle' 147 | DOWN_TO_PIPE = 'down to pipe' 148 | UP_OUT_PIPE = 'up out of pipe' 149 | 150 | #PLAYER FORCES 151 | PLAYER_SPEED = 'speed' 152 | WALK_ACCEL = 'walk_accel' 153 | RUN_ACCEL = 'run_accel' 154 | JUMP_VEL = 'jump_velocity' 155 | MAX_Y_VEL = 'max_y_velocity' 156 | MAX_RUN_SPEED = 'max_run_speed' 157 | MAX_WALK_SPEED = 'max_walk_speed' 158 | SMALL_TURNAROUND = .35 159 | JUMP_GRAVITY = .31 160 | GRAVITY = 1.01 161 | 162 | #LIST of ENEMIES 163 | GOOMBA = 'goomba' 164 | KOOPA = 'koopa' 165 | FLY_KOOPA = 'fly koopa' 166 | FIRE_KOOPA = 'fire koopa' 167 | FIRE = 'fire' 168 | PIRANHA = 'piranha' 169 | FIRESTICK = 'firestick' 170 | 171 | #GOOMBA Stuff 172 | LEFT = 'left' 173 | RIGHT = 'right' 174 | JUMPED_ON = 'jumped on' 175 | DEATH_JUMP = 'death jump' 176 | 177 | #KOOPA STUFF 178 | SHELL_SLIDE = 'shell slide' 179 | 180 | #FLAG STATE 181 | TOP_OF_POLE = 'top of pole' 182 | SLIDE_DOWN = 'slide down' 183 | BOTTOM_OF_POLE = 'bottom of pole' 184 | 185 | #FIREBALL STATE 186 | FLYING = 'flying' 187 | BOUNCING = 'bouncing' 188 | EXPLODING = 'exploding' 189 | 190 | #IMAGE SHEET 191 | ENEMY_SHEET = 'smb_enemies_sheet' 192 | ITEM_SHEET = 'item_objects' -------------------------------------------------------------------------------- /PythonSuperMario-master/source/data/maps/level_1.json: -------------------------------------------------------------------------------- 1 | { 2 | "image_name":"level_1", 3 | "maps":[ 4 | {"start_x": 0, "end_x": 9086, "player_x": 110, "player_y":538}, 5 | {"start_x":9090, "end_x": 9890, "player_x": 80, "player_y": 60}, 6 | {"start_x":6740, "end_x": 9086, "player_x": 270, "player_y":450} 7 | ], 8 | "ground":[ 9 | {"x": 0, "y":538, "width":2953, "height":60}, 10 | {"x":3048, "y":538, "width": 635, "height":60}, 11 | {"x":3819, "y":538, "width":2735, "height":60}, 12 | {"x":6647, "y":538, "width":3250, "height":60} 13 | ], 14 | "pipe":[ 15 | {"x":1201, "y":451, "width": 83, "height": 84, "type":0}, 16 | {"x":1629, "y":409, "width": 83, "height":126, "type":0}, 17 | {"x":1972, "y":366, "width": 83, "height":170, "type":0}, 18 | {"x":2444, "y":366, "width": 83, "height":170, "type":1}, 19 | {"x":6987, "y":451, "width": 83, "height": 84, "type":0}, 20 | {"x":7673, "y":451, "width": 83, "height": 84, "type":0}, 21 | {"x":9724, "y":451, "width": 40, "height": 84, "type":2} 22 | ], 23 | "step":[ 24 | {"x":5745, "y":495, "width": 40, "height": 44}, 25 | {"x":5788, "y":452, "width": 40, "height": 44}, 26 | {"x":5831, "y":409, "width": 40, "height": 44}, 27 | {"x":5874, "y":366, "width": 40, "height":176}, 28 | 29 | {"x":6001, "y":366, "width": 40, "height":176}, 30 | {"x":6044, "y":408, "width": 40, "height": 44}, 31 | {"x":6087, "y":452, "width": 40, "height": 44}, 32 | {"x":6130, "y":495, "width": 40, "height": 44}, 33 | 34 | {"x":6345, "y":495, "width": 40, "height": 44}, 35 | {"x":6388, "y":452, "width": 40, "height": 44}, 36 | {"x":6431, "y":409, "width": 40, "height": 44}, 37 | {"x":6474, "y":366, "width": 40, "height": 44}, 38 | {"x":6517, "y":366, "width": 40, "height":176}, 39 | 40 | {"x":6644, "y":366, "width": 40, "height":176}, 41 | {"x":6687, "y":408, "width": 40, "height": 44}, 42 | {"x":6728, "y":452, "width": 40, "height": 44}, 43 | {"x":6771, "y":495, "width": 40, "height": 44}, 44 | 45 | {"x":7760, "y":495, "width": 40, "height": 44}, 46 | {"x":7803, "y":452, "width": 40, "height": 44}, 47 | {"x":7845, "y":409, "width": 40, "height": 44}, 48 | {"x":7888, "y":366, "width": 40, "height": 44}, 49 | {"x":7931, "y":323, "width": 40, "height": 44}, 50 | {"x":7974, "y":280, "width": 40, "height": 44}, 51 | {"x":8017, "y":237, "width": 40, "height": 44}, 52 | {"x":8060, "y":194, "width": 40, "height": 44}, 53 | {"x":8103, "y":194, "width": 40, "height":360}, 54 | 55 | {"x":8488, "y":495, "width": 40, "height": 44}, 56 | {"x":9821, "y": 64, "width": 70, "height":530} 57 | ], 58 | "coin":[ 59 | {"x":9318, "y":369}, 60 | {"x":9362, "y":369}, 61 | {"x":9406, "y":369}, 62 | {"x":9450, "y":369}, 63 | {"x":9494, "y":369}, 64 | {"x":9538, "y":369}, 65 | {"x":9582, "y":369}, 66 | {"x":9318, "y":284}, 67 | {"x":9362, "y":284}, 68 | {"x":9406, "y":284}, 69 | {"x":9450, "y":284}, 70 | {"x":9494, "y":284}, 71 | {"x":9538, "y":284}, 72 | {"x":9582, "y":284}, 73 | {"x":9362, "y":198}, 74 | {"x":9406, "y":198}, 75 | {"x":9450, "y":198}, 76 | {"x":9494, "y":198}, 77 | {"x":9538, "y":198} 78 | ], 79 | "brick":[ 80 | {"x": 858, "y":365, "type":0}, 81 | {"x": 944, "y":365, "type":0}, 82 | {"x":1030, "y":365, "type":0}, 83 | {"x":3299, "y":365, "type":0}, 84 | {"x":3385, "y":365, "type":0}, 85 | 86 | {"x":3430, "y":193, "type":0}, 87 | {"x":3473, "y":193, "type":0}, 88 | {"x":3473, "y":193, "type":0}, 89 | {"x":3516, "y":193, "type":0}, 90 | {"x":3559, "y":193, "type":0}, 91 | {"x":3602, "y":193, "type":0}, 92 | {"x":3645, "y":193, "type":0}, 93 | {"x":3688, "y":193, "type":0}, 94 | {"x":3731, "y":193, "type":0}, 95 | {"x":3901, "y":193, "type":0}, 96 | {"x":3944, "y":193, "type":0}, 97 | {"x":3987, "y":193, "type":0}, 98 | 99 | {"x":4030, "y":365, "type":1}, 100 | {"x":4287, "y":365, "type":0}, 101 | {"x":4330, "y":365, "type":2}, 102 | {"x":5058, "y":365, "type":0}, 103 | 104 | {"x":5187, "y":193, "type":0}, 105 | {"x":5230, "y":193, "type":0}, 106 | {"x":5273, "y":193, "type":0}, 107 | {"x":5488, "y":193, "type":0}, 108 | {"x":5574, "y":193, "type":0}, 109 | {"x":5617, "y":193, "type":0}, 110 | {"x":5531, "y":365, "type":0}, 111 | {"x":5574, "y":365, "type":0}, 112 | {"x":7202, "y":365, "type":0}, 113 | {"x":7245, "y":365, "type":0}, 114 | {"x":7331, "y":365, "type":0}, 115 | 116 | {"x":9090, "y": 64, "type":0, "color":1,"brick_num":11, "direction":1}, 117 | {"x":9310, "y": 64, "type":0, "color":1,"brick_num":7, "direction":0}, 118 | {"x":9310, "y":406, "type":0, "color":1,"brick_num":7, "direction":0}, 119 | {"x":9310, "y":449, "type":0, "color":1,"brick_num":7, "direction":0}, 120 | {"x":9310, "y":492, "type":0, "color":1,"brick_num":7, "direction":0} 121 | ], 122 | "box":[ 123 | {"x": 685, "y":365, "type":1}, 124 | {"x": 901, "y":365, "type":3}, 125 | {"x": 987, "y":365, "type":1}, 126 | {"x": 943, "y":193, "type":1}, 127 | {"x":3342, "y":365, "type":4}, 128 | {"x":4030, "y":193, "type":1}, 129 | {"x":4544, "y":365, "type":1}, 130 | {"x":4672, "y":365, "type":1}, 131 | {"x":4672, "y":193, "type":4}, 132 | {"x":4800, "y":365, "type":1}, 133 | {"x":5531, "y":193, "type":1}, 134 | {"x":7288, "y":365, "type":1} 135 | ], 136 | "enemy":[ 137 | {"0":[ 138 | {"x":1120, "y":538, "direction":0, "type":0, "color":0} 139 | ]}, 140 | {"1":[ 141 | {"x":1920, "y":538, "direction":0, "type":0, "color":0} 142 | ]}, 143 | {"2":[ 144 | {"x":2320, "y":538, "direction":0, "type":0, "color":0}, 145 | {"x":2380, "y":538, "direction":0, "type":0, "color":0} 146 | ]}, 147 | {"3":[ 148 | {"x":3640, "y":193, "direction":0, "type":0, "color":0}, 149 | {"x":3700, "y":193, "direction":0, "type":0, "color":0} 150 | ]}, 151 | {"4":[ 152 | {"x":4270, "y":538, "direction":0, "type":0, "color":0}, 153 | {"x":4330, "y":538, "direction":0, "type":0, "color":0} 154 | ]}, 155 | {"5":[ 156 | {"x":4700, "y":538, "direction":0, "type":1, "color":1} 157 | ]}, 158 | {"6":[ 159 | {"x":4900, "y":538, "direction":0, "type":0, "color":0}, 160 | {"x":4960, "y":538, "direction":0, "type":0, "color":0} 161 | ]}, 162 | {"7":[ 163 | {"x":5300, "y":538, "direction":0, "type":0, "color":0}, 164 | {"x":5360, "y":538, "direction":0, "type":0, "color":0} 165 | ]}, 166 | {"8":[ 167 | {"x":5600, "y":538, "direction":0, "type":0, "color":0}, 168 | {"x":5660, "y":538, "direction":0, "type":0, "color":0} 169 | ]}, 170 | {"9":[ 171 | {"x":7550, "y":538, "direction":0, "type":0, "color":0}, 172 | {"x":7610, "y":538, "direction":0, "type":0, "color":0} 173 | ]} 174 | ], 175 | "checkpoint":[ 176 | {"x": 510, "y": 0, "width":10, "height":600, "type":0, "enemy_groupid":0}, 177 | {"x":1400, "y": 0, "width":10, "height":600, "type":0, "enemy_groupid":1}, 178 | {"x":1740, "y": 0, "width":10, "height":600, "type":0, "enemy_groupid":2}, 179 | {"x":3050, "y": 0, "width":10, "height":600, "type":0, "enemy_groupid":3}, 180 | {"x":3750, "y": 0, "width":10, "height":600, "type":0, "enemy_groupid":4}, 181 | {"x":4100, "y": 0, "width":10, "height":600, "type":0, "enemy_groupid":5}, 182 | {"x":4300, "y": 0, "width":10, "height":600, "type":0, "enemy_groupid":6}, 183 | {"x":4700, "y": 0, "width":10, "height":600, "type":0, "enemy_groupid":7}, 184 | {"x":5000, "y": 0, "width":10, "height":600, "type":0, "enemy_groupid":8}, 185 | {"x":6940, "y": 0, "width":100, "height":600, "type":0, "enemy_groupid":9}, 186 | {"x":2460, "y":439, "width":50, "height": 10, "type":6, "map_index":1}, 187 | {"x":8504, "y":-10, "width": 6, "height":600, "type":1}, 188 | {"x":8780, "y": 0, "width":10, "height":600, "type":2}, 189 | {"x":2740, "y":360, "width":40, "height": 12, "type":3}, 190 | {"x":9731, "y":458, "width":10, "height": 70, "type":4}, 191 | {"x":9800, "y":458, "width":10, "height": 70, "type":5, "map_index":2} 192 | ], 193 | "flagpole":[ 194 | {"x":8470, "y":116, "type":0}, 195 | {"x":8505, "y": 97, "type":1}, 196 | {"x":8505, "y":137, "type":1}, 197 | {"x":8505, "y":177, "type":1}, 198 | {"x":8505, "y":217, "type":1}, 199 | {"x":8505, "y":257, "type":1}, 200 | {"x":8505, "y":297, "type":1}, 201 | {"x":8505, "y":337, "type":1}, 202 | {"x":8505, "y":377, "type":1}, 203 | {"x":8505, "y":417, "type":1}, 204 | {"x":8505, "y":450, "type":1}, 205 | {"x":8497, "y": 97, "type":2} 206 | ] 207 | } -------------------------------------------------------------------------------- /PythonSuperMario-master/source/data/maps/level_2.json: -------------------------------------------------------------------------------- 1 | { 2 | "image_name":"level_2", 3 | "maps":[ 4 | {"start_x": 0, "end_x": 8232, "player_x":110, "player_y": 0}, 5 | {"start_x":8233, "end_x": 9860, "player_x":150, "player_y":451}, 6 | {"start_x":9862, "end_x":10662, "player_x": 50, "player_y": 0} 7 | ], 8 | "ground":[ 9 | {"x": 0, "y":540, "width":3426, "height": 60}, 10 | {"x":3560, "y":540, "width":1582, "height": 60}, 11 | {"x":5230, "y":410, "width": 86, "height":190}, 12 | {"x":5404, "y":540, "width": 510, "height": 60}, 13 | {"x":6218, "y":540, "width": 340, "height": 60}, 14 | {"x":6860, "y":540, "width": 730, "height":190}, 15 | {"x":7590, "y":540, "width": 642, "height": 60}, 16 | {"x":8233, "y":540, "width":1627, "height": 60}, 17 | {"x":9862, "y":540, "width": 800, "height": 60} 18 | ], 19 | "pipe":[ 20 | {"x":4415, "y":410, "width": 82, "height":130, "type":0}, 21 | {"x":4672, "y":367, "width": 82, "height":170, "type":0}, 22 | {"x":4929, "y":453, "width": 82, "height": 86, "type":0}, 23 | {"x":7114, "y":325, "width":104, "height": 86, "type":2}, 24 | {"x":7632, "y":410, "width": 82, "height":130, "type":1}, 25 | {"x":7802, "y":410, "width":104, "height":130, "type":1}, 26 | {"x":7974, "y":410, "width":104, "height":130, "type":1}, 27 | {"x":8360, "y":453, "width": 82, "height": 86, "type":0}, 28 | {"x":10500, "y":453, "width":104, "height": 86, "type":2} 29 | ], 30 | "step":[ 31 | {"x": 730, "y":495, "width": 40, "height": 44}, 32 | {"x": 816, "y":451, "width": 40, "height": 88}, 33 | {"x": 900, "y":410, "width": 40, "height":132}, 34 | {"x": 986, "y":367, "width": 40, "height":176}, 35 | {"x":1072, "y":367, "width": 40, "height":176}, 36 | {"x":1158, "y":410, "width": 40, "height":132}, 37 | {"x":1330, "y":410, "width": 40, "height":132}, 38 | {"x":1416, "y":451, "width": 40, "height": 88}, 39 | 40 | {"x":5702, "y":496, "width": 40, "height": 44}, 41 | {"x":5745, "y":452, "width": 40, "height": 88}, 42 | {"x":5788, "y":410, "width": 40, "height":132}, 43 | {"x":5831, "y":367, "width": 40, "height":176}, 44 | {"x":5874, "y":367, "width": 40, "height":176}, 45 | 46 | {"x":7208, "y": 66, "width": 74, "height":344}, 47 | 48 | {"x":8448, "y":496, "width": 40, "height": 44}, 49 | {"x":8491, "y":452, "width": 40, "height": 88}, 50 | {"x":8534, "y":410, "width": 40, "height":132}, 51 | {"x":8577, "y":367, "width": 40, "height":176}, 52 | {"x":8620, "y":324, "width": 40, "height":220}, 53 | {"x":8663, "y":281, "width": 40, "height":264}, 54 | {"x":8706, "y":237, "width": 40, "height":308}, 55 | {"x":8749, "y":194, "width": 40, "height":352}, 56 | {"x":8792, "y":194, "width": 40, "height":352}, 57 | {"x":9176, "y":496, "width": 40, "height": 44}, 58 | 59 | {"x":10593, "y":66, "width": 74, "height":474} 60 | ], 61 | "slider":[ 62 | {"x":5994, "y": 0, "num":3, "direction":1, "range_start": -50, "range_end": 650, "velocity":1}, 63 | {"x":5994, "y":260, "num":3, "direction":1, "range_start": -50, "range_end": 650, "velocity":1}, 64 | {"x":6642, "y": 0, "num":3, "direction":1, "range_start": -50, "range_end": 650, "velocity":-1}, 65 | {"x":6642, "y":260, "num":3, "direction":1, "range_start": -50, "range_end": 650, "velocity":-1} 66 | ], 67 | "coin":[ 68 | {"x":1724, "y":328}, 69 | {"x":1764, "y":200}, 70 | {"x":1808, "y":200}, 71 | {"x":1852, "y":200}, 72 | {"x":1896, "y":200}, 73 | {"x":1936, "y":328}, 74 | {"x":2494, "y":328}, 75 | {"x":2538, "y":328}, 76 | {"x":2580, "y":328}, 77 | {"x":2622, "y":328}, 78 | {"x":2924, "y":328}, 79 | {"x":3608, "y":200}, 80 | {"x":3650, "y":200}, 81 | {"x":3692, "y":200}, 82 | {"x":3734, "y":200}, 83 | {"x":3776, "y":200}, 84 | 85 | {"x":10126, "y":328}, 86 | {"x":10168, "y":328}, 87 | {"x":10210, "y":328}, 88 | {"x":10252, "y":328}, 89 | {"x":10294, "y":328}, 90 | {"x":10336, "y":328}, 91 | {"x":10378, "y":328}, 92 | {"x":10420, "y":328}, 93 | {"x":10084, "y":500}, 94 | {"x":10126, "y":500}, 95 | {"x":10168, "y":500}, 96 | {"x":10210, "y":500}, 97 | {"x":10252, "y":500}, 98 | {"x":10294, "y":500}, 99 | {"x":10336, "y":500}, 100 | {"x":10378, "y":500}, 101 | {"x":10420, "y":500} 102 | ], 103 | "brick":[ 104 | {"x": 0, "y": 66, "type":0, "color":1,"brick_num":11, "direction":1}, 105 | {"x": 254, "y": 66, "type":0, "color":1,"brick_num":83, "direction":0}, 106 | {"x":3816, "y": 66, "type":6, "color":1}, 107 | {"x":3859, "y": 66, "type":0, "color":1,"brick_num":47, "direction":0}, 108 | {"x":1244, "y":324, "type":1, "color":1}, 109 | 110 | {"x":1672, "y":281, "type":0, "color":1,"brick_num":3, "direction":1}, 111 | {"x":1715, "y":367, "type":0, "color":1}, 112 | {"x":1758, "y":281, "type":0, "color":1,"brick_num":3, "direction":1}, 113 | {"x":1801, "y":281, "type":0, "color":1}, 114 | {"x":1844, "y":281, "type":0, "color":1}, 115 | {"x":1887, "y":281, "type":0, "color":1,"brick_num":3, "direction":1}, 116 | {"x":1930, "y":367, "type":0, "color":1}, 117 | {"x":1973, "y":367, "type":0, "color":1}, 118 | {"x":1973, "y":324, "type":0, "color":1}, 119 | {"x":1973, "y":281, "type":2, "color":1}, 120 | 121 | {"x":2230, "y":195, "type":0, "color":1,"brick_num":5, "direction":1}, 122 | {"x":2273, "y":195, "type":0, "color":1,"brick_num":5, "direction":1}, 123 | {"x":2316, "y":109, "type":0, "color":1,"brick_num":2, "direction":1}, 124 | {"x":2316, "y":367, "type":0, "color":1,"brick_num":3, "direction":1}, 125 | {"x":2359, "y":109, "type":0, "color":1,"brick_num":2, "direction":1}, 126 | {"x":2359, "y":367, "type":0, "color":1,"brick_num":3, "direction":1}, 127 | 128 | {"x":2487, "y":109, "type":0, "color":1,"brick_num":6, "direction":0}, 129 | {"x":2487, "y":152, "type":0, "color":1,"brick_num":6, "direction":0}, 130 | {"x":2659, "y":195, "type":0, "color":1,"brick_num":2, "direction":0}, 131 | {"x":2659, "y":238, "type":0, "color":1,"brick_num":2, "direction":0}, 132 | {"x":2659, "y":281, "type":0, "color":1,"brick_num":2, "direction":0}, 133 | {"x":2659, "y":324, "type":0, "color":1,"brick_num":2, "direction":0}, 134 | {"x":2487, "y":367, "type":0, "color":1,"brick_num":6, "direction":0}, 135 | 136 | {"x":2830, "y":109, "type":0, "color":1,"brick_num":3, "direction":0}, 137 | {"x":2830, "y":152, "type":0, "color":1,"brick_num":3, "direction":0}, 138 | {"x":2873, "y":195, "type":0, "color":1,"brick_num":5, "direction":1}, 139 | {"x":2916, "y":367, "type":0, "color":1}, 140 | {"x":2959, "y":367, "type":0, "color":1}, 141 | {"x":2958, "y":324, "type":4, "color":1}, 142 | 143 | {"x":3087, "y":195, "type":0, "color":1,"brick_num":5, "direction":1}, 144 | {"x":3130, "y":195, "type":0, "color":1,"brick_num":5, "direction":1}, 145 | 146 | {"x":3259, "y":195, "type":0, "color":1,"brick_num":4, "direction":0}, 147 | {"x":3259, "y":238, "type":0, "color":1,"brick_num":4, "direction":0}, 148 | {"x":3259, "y":367, "type":0, "color":1,"brick_num":4, "direction":0}, 149 | 150 | {"x":3602, "y":281, "type":0, "color":1,"brick_num":6, "direction":0}, 151 | {"x":3602, "y":324, "type":0, "color":1,"brick_num":6, "direction":0}, 152 | 153 | {"x":6218, "y":324, "type":0, "color":1,"brick_num":5, "direction":0}, 154 | {"x":6433, "y":324, "type":4, "color":1}, 155 | 156 | {"x":6860, "y":410, "type":0, "color":1,"brick_num":17, "direction":0}, 157 | {"x":6860, "y":453, "type":0, "color":1,"brick_num":17, "direction":0}, 158 | {"x":6860, "y":496, "type":0, "color":1,"brick_num":17, "direction":0}, 159 | {"x":6903, "y": 66, "type":0, "color":1,"brick_num":7, "direction":0}, 160 | {"x":7290, "y": 66, "type":0, "color":1,"brick_num":17, "direction":0}, 161 | {"x":7290, "y":109, "type":0, "color":1,"brick_num":7, "direction":0}, 162 | {"x":7290, "y":152, "type":0, "color":1,"brick_num":7, "direction":0}, 163 | {"x":7290, "y":195, "type":0, "color":1,"brick_num":7, "direction":0}, 164 | {"x":7290, "y":238, "type":0, "color":1,"brick_num":7, "direction":0}, 165 | {"x":7290, "y":281, "type":0, "color":1,"brick_num":7, "direction":0}, 166 | {"x":7290, "y":324, "type":0, "color":1,"brick_num":7, "direction":0}, 167 | {"x":7290, "y":367, "type":0, "color":1,"brick_num":7, "direction":0}, 168 | {"x":8140, "y": 66, "type":0, "color":1,"brick_num":11, "direction":1}, 169 | {"x":8183, "y": 66, "type":0, "color":1,"brick_num":11, "direction":1}, 170 | 171 | {"x":9863, "y": 66, "type":0, "color":1,"brick_num":11, "direction":1}, 172 | {"x":9992, "y": 66, "type":0, "color":1,"brick_num":12, "direction":0}, 173 | {"x":9992, "y":109, "type":0, "color":1,"brick_num":12, "direction":0}, 174 | {"x":9992, "y":152, "type":0, "color":1,"brick_num":12, "direction":0}, 175 | {"x":9992, "y":195, "type":0, "color":1,"brick_num":12, "direction":0}, 176 | {"x":9992, "y":367, "type":0, "color":1,"brick_num":12, "direction":0}, 177 | {"x":10508, "y": 66, "type":0, "color":1,"brick_num":9, "direction":1}, 178 | {"x":10551, "y": 66, "type":0, "color":1,"brick_num":9, "direction":1} 179 | ], 180 | "box":[ 181 | {"x": 426, "y":367, "type":3}, 182 | {"x": 470, "y":367, "type":1}, 183 | {"x": 514, "y":367, "type":1}, 184 | {"x": 556, "y":367, "type":1}, 185 | {"x": 598, "y":367, "type":1} 186 | ], 187 | "enemy":[ 188 | {"0":[ 189 | {"x": 685, "y":540, "direction":0, "type":0, "color":1}, 190 | {"x": 730, "y":495, "direction":0, "type":0, "color":1} 191 | ]}, 192 | {"1":[ 193 | {"x":1260, "y":540, "direction":0, "type":0, "color":1} 194 | ]}, 195 | {"2":[ 196 | {"x":2040, "y":538, "direction":0, "type":1, "color":0}, 197 | {"x":2100, "y":538, "direction":0, "type":1, "color":0} 198 | ]}, 199 | {"3":[ 200 | {"x":2670, "y":538, "direction":0, "type":1, "color":0}, 201 | {"x":2800, "y":538, "direction":0, "type":0, "color":1}, 202 | {"x":2880, "y":538, "direction":0, "type":0, "color":1} 203 | ]}, 204 | {"4":[ 205 | {"x":3130, "y":195, "direction":0, "type":0, "color":1} 206 | ]}, 207 | {"5":[ 208 | {"x":3330, "y":367, "direction":0, "type":0, "color":1}, 209 | {"x":3400, "y":367, "direction":0, "type":0, "color":1} 210 | ]}, 211 | {"6":[ 212 | {"x":4246, "y":538, "direction":0, "type":0, "color":1}, 213 | {"x":4306, "y":538, "direction":0, "type":0, "color":1}, 214 | {"x":4366, "y":538, "direction":0, "type":0, "color":1} 215 | ]}, 216 | {"7":[ 217 | {"x":4440, "y":490, "direction":0, "type":3, "color":0, "range":1, "range_start":360, "range_end":490}, 218 | {"x":4696, "y":445, "direction":0, "type":3, "color":0, "range":1, "range_start":315, "range_end":445}, 219 | {"x":4954, "y":535, "direction":0, "type":3, "color":0, "range":1, "range_start":400, "range_end":535} 220 | ]}, 221 | {"8":[ 222 | {"x":4890, "y":538, "direction":0, "type":0, "color":1} 223 | ]}, 224 | {"9":[ 225 | {"x":5786, "y":410, "direction":0, "type":0, "color":1}, 226 | {"x":5846, "y":367, "direction":0, "type":0, "color":1} 227 | ]}, 228 | {"10":[ 229 | {"x":6500, "y":538, "direction":0, "type":1, "color":2, "range":1, "range_start":6220, "range_end":6755} 230 | ]}, 231 | {"11":[ 232 | {"x":8383, "y":535, "direction":0, "type":3, "color":0, "range":1, "range_start":400, "range_end":535} 233 | ]} 234 | ], 235 | "checkpoint":[ 236 | {"x": 110, "y":0, "width":10, "height":600, "type":0, "enemy_groupid":0}, 237 | {"x": 728, "y":0, "width":10, "height":600, "type":0, "enemy_groupid":1}, 238 | {"x":1400, "y":0, "width":10, "height":600, "type":0, "enemy_groupid":2}, 239 | {"x":2070, "y":0, "width":10, "height":600, "type":0, "enemy_groupid":3}, 240 | {"x":2530, "y":0, "width":10, "height":600, "type":0, "enemy_groupid":4}, 241 | {"x":2730, "y":0, "width":10, "height":600, "type":0, "enemy_groupid":5}, 242 | {"x":3646, "y":0, "width":10, "height":600, "type":0, "enemy_groupid":6}, 243 | {"x":3800, "y":0, "width":10, "height":600, "type":0, "enemy_groupid":7}, 244 | {"x":4290, "y":0, "width":10, "height":600, "type":0, "enemy_groupid":8}, 245 | {"x":5186, "y":0, "width":10, "height":600, "type":0, "enemy_groupid":9}, 246 | {"x":5900, "y":0, "width":10, "height":600, "type":0, "enemy_groupid":10}, 247 | {"x":8383, "y":0, "width":10, "height":600, "type":0, "enemy_groupid":11}, 248 | {"x":7117, "y":330, "width":10, "height":80, "type":4}, 249 | {"x":7187, "y":330, "width":10, "height":80, "type":5, "map_index":1}, 250 | {"x":7634, "y":540, "width":78, "height":10, "type":6, "map_index":2}, 251 | {"x":7804, "y":540, "width":78, "height":10, "type":6, "map_index":2}, 252 | {"x":7976, "y":540, "width":78, "height":10, "type":6, "map_index":2}, 253 | {"x":9195, "y":-15, "width":5, "height":600, "type":1}, 254 | {"x":9470, "y":0, "width":10, "height":600, "type":2}, 255 | {"x":10502, "y":460, "width":10, "height":80, "type":4}, 256 | {"x":10572, "y":460, "width":10, "height":80, "type":5, "map_index":1} 257 | ], 258 | "flagpole":[ 259 | {"x":9156, "y":116, "type":0} 260 | ] 261 | } -------------------------------------------------------------------------------- /PythonSuperMario-master/source/data/maps/level_3.json: -------------------------------------------------------------------------------- 1 | { 2 | "image_name":"level_3", 3 | "ground":[ 4 | {"x": 0, "y":538, "width": 686, "height": 60}, 5 | {"x": 774, "y":496, "width": 166, "height": 36}, 6 | {"x":1031, "y":368, "width": 340, "height": 36}, 7 | {"x":1074, "y":406, "width": 252, "height":194}, 8 | {"x":1118, "y":196, "width": 208, "height": 36}, 9 | {"x":1374, "y":496, "width": 126, "height": 36}, 10 | {"x":1504, "y":325, "width": 208, "height": 36}, 11 | {"x":1544, "y":360, "width": 126, "height":240}, 12 | {"x":1716, "y":153, "width": 296, "height": 36}, 13 | {"x":1760, "y":190, "width": 208, "height":410}, 14 | {"x":2146, "y":538, "width": 166, "height": 36}, 15 | {"x":2534, "y":538, "width": 208, "height": 36}, 16 | {"x":2574, "y":198, "width": 166, "height": 36}, 17 | {"x":2790, "y":538, "width": 208, "height": 36}, 18 | {"x":3002, "y":366, "width": 126, "height": 36}, 19 | {"x":3044, "y":406, "width": 40, "height":194}, 20 | {"x":3262, "y":238, "width": 252, "height": 36}, 21 | {"x":3304, "y":274, "width": 166, "height":326}, 22 | {"x":4204, "y":452, "width": 166, "height": 36}, 23 | {"x":4246, "y":488, "width": 84, "height":112}, 24 | {"x":4462, "y":282, "width": 338, "height": 36}, 25 | {"x":4502, "y":318, "width": 252, "height":282}, 26 | {"x":4847, "y":538, "width": 126, "height": 60}, 27 | {"x":4976, "y":368, "width": 166, "height": 36}, 28 | {"x":5018, "y":406, "width": 84, "height":194}, 29 | {"x":5232, "y":368, "width": 166, "height": 36}, 30 | {"x":5274, "y":406, "width": 84, "height":194}, 31 | {"x":5532, "y":538, "width":1508, "height": 60} 32 | ], 33 | "step":[ 34 | {"x":5917, "y":366, "width": 80, "height":176}, 35 | {"x":6002, "y":280, "width": 80, "height":264}, 36 | {"x":6090, "y":194, "width": 80, "height":352}, 37 | {"x":6516, "y":495, "width": 40, "height": 44} 38 | ], 39 | "slider":[ 40 | {"x":2400, "y":338, "num":3, "direction":1, "range_start": 238, "range_end": 560}, 41 | {"x":3590, "y":322, "num":3, "direction":0, "range_start":3590, "range_end":3750}, 42 | {"x":3790, "y":366, "num":3, "direction":0, "range_start":3790, "range_end":3950}, 43 | {"x":5440, "y":238, "num":3, "direction":0, "range_start":5440, "range_end":5600} 44 | ], 45 | "coin":[ 46 | {"x":1166, "y":156}, 47 | {"x":1208, "y":156}, 48 | {"x":1250, "y":156}, 49 | {"x":1594, "y": 70}, 50 | {"x":1636, "y": 70}, 51 | {"x":2152, "y":240}, 52 | {"x":2194, "y":240}, 53 | {"x":2580, "y":156}, 54 | {"x":2622, "y":156}, 55 | {"x":2664, "y":156}, 56 | {"x":2706, "y":156}, 57 | {"x":3652, "y":198}, 58 | {"x":3694, "y":198}, 59 | {"x":3996, "y":156}, 60 | {"x":4038, "y":156}, 61 | {"x":4166, "y":156}, 62 | {"x":4208, "y":156}, 63 | {"x":4852, "y":496}, 64 | {"x":4894, "y":496}, 65 | {"x":4936, "y":496}, 66 | {"x":5154, "y":198}, 67 | {"x":5196, "y":198} 68 | ], 69 | "box":[ 70 | {"x":2530, "y":408, "type":3} 71 | ], 72 | "enemy":[ 73 | {"0":[ 74 | {"x":1284, "y":196, "direction":0, "type":1, "color":2, "range":1, "range_start":1114, "range_end":1324} 75 | ]}, 76 | {"1":[ 77 | {"x":1886, "y":152, "direction":0, "type":0, "color":0}, 78 | {"x":1946, "y":152, "direction":0, "type":0, "color":0} 79 | ]}, 80 | {"2":[ 81 | {"x":3160, "y":220, "direction":0, "type":2, "color":2, "range":1, "range_start":200, "range_end":440, "is_vertical":1} 82 | ]}, 83 | {"3":[ 84 | {"x":3458, "y":238, "direction":0, "type":0, "color":0, "range":1, "range_start":3262, "range_end":3508} 85 | ]}, 86 | {"4":[ 87 | {"x":4740, "y":282, "direction":0, "type":1, "color":2, "range":1, "range_start":4460, "range_end":4798} 88 | ]}, 89 | {"5":[ 90 | {"x":4880, "y":260, "direction":0, "type":2, "color":2, "range":1, "range_start":230, "range_end":490, "is_vertical":1} 91 | ]}, 92 | {"6":[ 93 | {"x":5836, "y":538, "direction":0, "type":1, "color":2, "range":1, "range_start":5530, "range_end":5908} 94 | ]} 95 | ], 96 | "checkpoint":[ 97 | {"x": 690, "y":0, "width":10, "height":600, "type":0, "enemy_groupid":0}, 98 | {"x":1292, "y":0, "width":10, "height":600, "type":0, "enemy_groupid":1}, 99 | {"x":2300, "y":0, "width":10, "height":600, "type":0, "enemy_groupid":2}, 100 | {"x":2870, "y":0, "width":10, "height":600, "type":0, "enemy_groupid":3}, 101 | {"x":4154, "y":0, "width":10, "height":600, "type":0, "enemy_groupid":4}, 102 | {"x":4466, "y":0, "width":10, "height":600, "type":0, "enemy_groupid":5}, 103 | {"x":5246, "y":0, "width":10, "height":600, "type":0, "enemy_groupid":6}, 104 | {"x":6536, "y":-15, "width": 6, "height":600, "type":1, "enemy_groupid":0}, 105 | {"x":6853, "y":0, "width":10, "height":600, "type":2, "enemy_groupid":0} 106 | ], 107 | "flagpole":[ 108 | {"x":6497, "y":116, "type":0}, 109 | {"x":8505, "y": 97, "type":1}, 110 | {"x":8505, "y":137, "type":1}, 111 | {"x":8505, "y":177, "type":1}, 112 | {"x":8505, "y":217, "type":1}, 113 | {"x":8505, "y":257, "type":1}, 114 | {"x":8505, "y":297, "type":1}, 115 | {"x":8505, "y":337, "type":1}, 116 | {"x":8505, "y":377, "type":1}, 117 | {"x":8505, "y":417, "type":1}, 118 | {"x":8505, "y":450, "type":1}, 119 | {"x":8497, "y": 97, "type":2} 120 | ] 121 | } -------------------------------------------------------------------------------- /PythonSuperMario-master/source/data/maps/level_4.json: -------------------------------------------------------------------------------- 1 | { 2 | "image_name":"level_4", 3 | "maps":[ 4 | {"start_x": 0, "end_x": 6844, "player_x":110, "player_y": 275} 5 | ], 6 | "ground":[ 7 | {"x": 0, "y":409, "width": 556, "height":191}, 8 | {"x": 0, "y":366, "width": 215, "height": 43}, 9 | {"x": 0, "y":323, "width": 172, "height": 43}, 10 | {"x": 0, "y":280, "width": 129, "height": 43}, 11 | {"x": 623, "y":409, "width": 470, "height":191}, 12 | {"x":1222, "y":409, "width": 129, "height":191}, 13 | {"x":1480, "y":409, "width":2956, "height":191}, 14 | {"x":1480, "y":366, "width":1584, "height": 43}, 15 | {"x":4436, "y":537, "width":1031, "height": 60}, 16 | {"x":4952, "y":409, "width": 170, "height":130}, 17 | {"x":5252, "y":409, "width": 213, "height":130}, 18 | {"x":6024, "y":366, "width": 126, "height":170}, 19 | {"x":6024, "y":537, "width": 820, "height": 60} 20 | ], 21 | "step":[ 22 | {"x": 0, "y": 63, "width":1008, "height":127}, 23 | {"x": 966, "y":190, "width": 41, "height": 87}, 24 | {"x":1008, "y": 63, "width": 556, "height": 41}, 25 | {"x":1566, "y": 63, "width":1502, "height":170}, 26 | {"x":1566, "y":234, "width": 41, "height": 41}, 27 | {"x":2080, "y":234, "width": 41, "height": 43}, 28 | {"x":2552, "y":234, "width": 41, "height": 43}, 29 | {"x":2852, "y":234, "width": 41, "height": 43}, 30 | {"x":3066, "y": 63, "width":3778, "height": 40}, 31 | {"x":3238, "y":366, "width": 41, "height": 43}, 32 | {"x":3409, "y":104, "width": 41, "height": 86}, 33 | {"x":3581, "y":366, "width": 41, "height": 43}, 34 | {"x":3752, "y":104, "width": 41, "height": 86}, 35 | {"x":3924, "y":366, "width": 41, "height": 43}, 36 | {"x":3580, "y":366, "width": 41, "height": 43}, 37 | {"x":4138, "y":104, "width": 297, "height": 86}, 38 | {"x":5252, "y":104, "width": 213, "height": 86}, 39 | {"x":6067, "y":104 , "width": 84, "height":128}, 40 | 41 | {"x":5468, "y":409 , "width": 540, "height":44} 42 | ], 43 | "slider":[ 44 | {"x":5750, "y":238, "num":2, "direction":0, "range_start":5720, "range_end":5930} 45 | ], 46 | "box":[ 47 | {"x":1266, "y":236, "type":3} 48 | ], 49 | "enemy":[ 50 | {"0":[ 51 | {"x":1275, "y":422, "direction":0, "type":4, "color":0, "num":6} 52 | ]}, 53 | {"1":[ 54 | {"x":2091, "y":249, "direction":0, "type":4, "color":0, "num":6} 55 | ]}, 56 | {"2":[ 57 | {"x":2562, "y":249, "direction":0, "type":4, "color":0, "num":6} 58 | ]}, 59 | {"3":[ 60 | {"x":2862, "y":249, "direction":0, "type":4, "color":0, "num":6} 61 | ]}, 62 | {"4":[ 63 | {"x":3250, "y":380, "direction":0, "type":4, "color":0, "num":6} 64 | ]}, 65 | {"5":[ 66 | {"x":3592, "y":380, "direction":0, "type":4, "color":0, "num":6} 67 | ]}, 68 | {"6":[ 69 | {"x":3762, "y":163, "direction":0, "type":4, "color":0, "num":6} 70 | ]}, 71 | {"7":[ 72 | {"x":5880, "y":405, "direction":0, "type":5, "color":0, "range":1, "range_start":5750, "range_end":5975} 73 | ]} 74 | ], 75 | "checkpoint":[ 76 | {"x": 577, "y":0, "width":10, "height":600, "type":0, "enemy_groupid":0}, 77 | {"x":1050, "y":0, "width":10, "height":600, "type":0, "enemy_groupid":1}, 78 | {"x":1700, "y":0, "width":10, "height":600, "type":0, "enemy_groupid":2}, 79 | {"x":2162, "y":0, "width":10, "height":600, "type":0, "enemy_groupid":3}, 80 | {"x":2550, "y":0, "width":10, "height":600, "type":0, "enemy_groupid":4}, 81 | {"x":2892, "y":0, "width":10, "height":600, "type":0, "enemy_groupid":5}, 82 | {"x":3062, "y":0, "width":10, "height":600, "type":0, "enemy_groupid":6}, 83 | {"x":3900, "y":0, "width":10, "height":600, "type":0, "enemy_groupid":7}, 84 | {"x":6026, "y":324, "width":40, "height":40, "type":7, "enemy_groupid":0}, 85 | {"x":6510, "y":0, "width":10, "height":600, "type":2, "enemy_groupid":0} 86 | ] 87 | } -------------------------------------------------------------------------------- /PythonSuperMario-master/source/data/player/luigi.json: -------------------------------------------------------------------------------- 1 | { 2 | "image_name":"mario_bros", 3 | "image_frames":{ 4 | "right_small_normal":[ 5 | {"x":178, "y":128, "width":12, "height":16}, 6 | {"x": 80, "y":128, "width":15, "height":16}, 7 | {"x": 96, "y":128, "width":16, "height":16}, 8 | {"x":112, "y":128, "width":16, "height":16}, 9 | {"x":144, "y":128, "width":16, "height":16}, 10 | {"x":130, "y":128, "width":14, "height":16}, 11 | {"x":160, "y":128, "width":15, "height":16}, 12 | {"x":320, "y":105, "width":16, "height":24}, 13 | {"x":241, "y":129, "width":16, "height":16}, 14 | {"x":194, "y":128, "width":12, "height":16}, 15 | {"x":210, "y":129, "width":12, "height":16} 16 | ], 17 | "right_big_normal":[ 18 | {"x":176, "y": 96, "width":16, "height":32}, 19 | {"x": 81, "y": 96, "width":16, "height":32}, 20 | {"x": 97, "y": 96, "width":15, "height":32}, 21 | {"x":113, "y": 96, "width":15, "height":32}, 22 | {"x":144, "y": 96, "width":16, "height":32}, 23 | {"x":128, "y": 96, "width":16, "height":32}, 24 | {"x":336, "y": 96, "width":16, "height":32}, 25 | {"x":160, "y":106, "width":16, "height":22}, 26 | {"x":272, "y": 98, "width":16, "height":29}, 27 | {"x":193, "y": 98, "width":16, "height":29}, 28 | {"x":209, "y": 98, "width":16, "height":29} 29 | ], 30 | "right_big_fire":[ 31 | {"x":176, "y":192, "width":16, "height":32}, 32 | {"x": 81, "y":192, "width":16, "height":32}, 33 | {"x": 97, "y":192, "width":15, "height":32}, 34 | {"x":113, "y":192, "width":15, "height":32}, 35 | {"x":144, "y":192, "width":16, "height":32}, 36 | {"x":128, "y":192, "width":16, "height":32}, 37 | {"x":336, "y":192, "width":16, "height":32}, 38 | {"x":160, "y":202, "width":16, "height":22}, 39 | {"x":272, "y":194, "width":16, "height":29}, 40 | {"x":193, "y":194, "width":16, "height":29}, 41 | {"x":209, "y":194, "width":16, "height":29} 42 | ] 43 | }, 44 | "speed":{ 45 | "max_walk_speed":6, 46 | "max_run_speed":12, 47 | "max_y_velocity":11, 48 | "walk_accel":0.15, 49 | "run_accel":0.3, 50 | "jump_velocity":-10.5 51 | } 52 | 53 | } -------------------------------------------------------------------------------- /PythonSuperMario-master/source/data/player/mario.json: -------------------------------------------------------------------------------- 1 | { 2 | "image_name":"mario_bros", 3 | "image_frames":{ 4 | "right_small_normal":[ 5 | {"x":178, "y": 32, "width":12, "height":16}, 6 | {"x": 80, "y": 32, "width":15, "height":16}, 7 | {"x": 96, "y": 32, "width":16, "height":16}, 8 | {"x":112, "y": 32, "width":16, "height":16}, 9 | {"x":144, "y": 32, "width":16, "height":16}, 10 | {"x":130, "y": 32, "width":14, "height":16}, 11 | {"x":160, "y": 32, "width":15, "height":16}, 12 | {"x":320, "y": 8, "width":16, "height":24}, 13 | {"x":241, "y": 33, "width":16, "height":16}, 14 | {"x":194, "y": 32, "width":12, "height":16}, 15 | {"x":210, "y": 33, "width":12, "height":16} 16 | ], 17 | "right_big_normal":[ 18 | {"x":176, "y": 0, "width":16, "height":32}, 19 | {"x": 81, "y": 0, "width":16, "height":32}, 20 | {"x": 97, "y": 0, "width":15, "height":32}, 21 | {"x":113, "y": 0, "width":15, "height":32}, 22 | {"x":144, "y": 0, "width":16, "height":32}, 23 | {"x":128, "y": 0, "width":16, "height":32}, 24 | {"x":336, "y": 0, "width":16, "height":32}, 25 | {"x":160, "y": 10, "width":16, "height":22}, 26 | {"x":272, "y": 2, "width":16, "height":29}, 27 | {"x":193, "y": 2, "width":16, "height":29}, 28 | {"x":209, "y": 2, "width":16, "height":29} 29 | ], 30 | "right_big_fire":[ 31 | {"x":176, "y": 48, "width":16, "height":32}, 32 | {"x": 81, "y": 48, "width":16, "height":32}, 33 | {"x": 97, "y": 48, "width":15, "height":32}, 34 | {"x":113, "y": 48, "width":15, "height":32}, 35 | {"x":144, "y": 48, "width":16, "height":32}, 36 | {"x":128, "y": 48, "width":16, "height":32}, 37 | {"x":336, "y": 48, "width":16, "height":32}, 38 | {"x":160, "y": 58, "width":16, "height":22}, 39 | {"x":272, "y": 50, "width":16, "height":29}, 40 | {"x":193, "y": 50, "width":16, "height":29}, 41 | {"x":209, "y": 50, "width":16, "height":29} 42 | ] 43 | }, 44 | "speed":{ 45 | "max_walk_speed":6, 46 | "max_run_speed":12, 47 | "max_y_velocity":11, 48 | "walk_accel":0.15, 49 | "run_accel":0.3, 50 | "jump_velocity":-10.5 51 | } 52 | 53 | } -------------------------------------------------------------------------------- /PythonSuperMario-master/source/main.py: -------------------------------------------------------------------------------- 1 | __author__ = 'marble_xu' 2 | 3 | import pygame as pg 4 | from . import setup, tools 5 | from . import constants as c 6 | from .states import main_menu, load_screen, level 7 | 8 | def main(): 9 | game = tools.Control() 10 | state_dict = {c.MAIN_MENU: main_menu.Menu(), 11 | c.LOAD_SCREEN: load_screen.LoadScreen(), 12 | c.LEVEL: level.Level(), 13 | c.GAME_OVER: load_screen.GameOver(), 14 | c.TIME_OUT: load_screen.TimeOut()} 15 | game.setup_states(state_dict, c.MAIN_MENU) 16 | game.main() 17 | -------------------------------------------------------------------------------- /PythonSuperMario-master/source/setup.py: -------------------------------------------------------------------------------- 1 | __author__ = 'marble_xu' 2 | 3 | import os 4 | import pygame as pg 5 | from . import constants as c 6 | from . import tools 7 | 8 | pg.init() 9 | pg.event.set_allowed([pg.KEYDOWN, pg.KEYUP, pg.QUIT]) 10 | pg.display.set_caption(c.ORIGINAL_CAPTION) 11 | SCREEN = pg.display.set_mode(c.SCREEN_SIZE) 12 | SCREEN_RECT = SCREEN.get_rect() 13 | 14 | GFX = tools.load_all_gfx(os.path.join("resources","graphics")) -------------------------------------------------------------------------------- /PythonSuperMario-master/source/states/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/source/states/__init__.py -------------------------------------------------------------------------------- /PythonSuperMario-master/source/states/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/source/states/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /PythonSuperMario-master/source/states/__pycache__/level.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/source/states/__pycache__/level.cpython-38.pyc -------------------------------------------------------------------------------- /PythonSuperMario-master/source/states/__pycache__/load_screen.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/source/states/__pycache__/load_screen.cpython-38.pyc -------------------------------------------------------------------------------- /PythonSuperMario-master/source/states/__pycache__/main_menu.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-han11/PythonSuperMario-master/ffe9bdf8d2df96f3bb15ca720bde030f021efab2/PythonSuperMario-master/source/states/__pycache__/main_menu.cpython-38.pyc -------------------------------------------------------------------------------- /PythonSuperMario-master/source/states/level.py: -------------------------------------------------------------------------------- 1 | __author__ = 'marble_xu' 2 | 3 | import os 4 | import json 5 | import pygame as pg 6 | from .. import setup, tools 7 | from .. import constants as c 8 | from ..components import info, stuff, player, brick, box, enemy, powerup, coin 9 | 10 | 11 | class Level(tools.State): 12 | def __init__(self): 13 | tools.State.__init__(self) 14 | self.player = None 15 | 16 | def startup(self, current_time, persist): 17 | self.game_info = persist 18 | self.persist = self.game_info 19 | self.game_info[c.CURRENT_TIME] = current_time 20 | self.death_timer = 0 21 | self.castle_timer = 0 22 | 23 | self.moving_score_list = [] 24 | self.overhead_info = info.Info(self.game_info, c.LEVEL) 25 | self.load_map() 26 | self.setup_background() 27 | self.setup_maps() 28 | self.ground_group = self.setup_collide(c.MAP_GROUND) 29 | self.step_group = self.setup_collide(c.MAP_STEP) 30 | self.setup_pipe() 31 | self.setup_slider() 32 | self.setup_static_coin() 33 | self.setup_brick_and_box() 34 | self.setup_player() 35 | self.setup_enemies() 36 | self.setup_checkpoints() 37 | self.setup_flagpole() 38 | self.setup_sprite_groups() 39 | 40 | def load_map(self): 41 | map_file = 'level_' + str(self.game_info[c.LEVEL_NUM]) + '.json' 42 | file_path = os.path.join('source', 'data', 'maps', map_file) 43 | f = open(file_path) 44 | self.map_data = json.load(f) 45 | f.close() 46 | 47 | def setup_background(self): 48 | img_name = self.map_data[c.MAP_IMAGE] 49 | self.background = setup.GFX[img_name] 50 | self.bg_rect = self.background.get_rect() 51 | self.background = pg.transform.scale(self.background, 52 | (int(self.bg_rect.width*c.BACKGROUND_MULTIPLER), 53 | int(self.bg_rect.height*c.BACKGROUND_MULTIPLER))) 54 | self.bg_rect = self.background.get_rect() 55 | 56 | self.level = pg.Surface((self.bg_rect.w, self.bg_rect.h)).convert() 57 | self.viewport = setup.SCREEN.get_rect(bottom=self.bg_rect.bottom) 58 | 59 | def setup_maps(self): 60 | self.map_list = [] 61 | if c.MAP_MAPS in self.map_data: 62 | for data in self.map_data[c.MAP_MAPS]: 63 | self.map_list.append((data['start_x'], data['end_x'], data['player_x'], data['player_y'])) 64 | self.start_x, self.end_x, self.player_x, self.player_y = self.map_list[0] 65 | else: 66 | self.start_x = 0 67 | self.end_x = self.bg_rect.w 68 | self.player_x = 110 69 | self.player_y = c.GROUND_HEIGHT 70 | 71 | def change_map(self, index, type): 72 | self.start_x, self.end_x, self.player_x, self.player_y = self.map_list[index] 73 | self.viewport.x = self.start_x 74 | if type == c.CHECKPOINT_TYPE_MAP: 75 | self.player.rect.x = self.viewport.x + self.player_x 76 | self.player.rect.bottom = self.player_y 77 | self.player.state = c.STAND 78 | elif type == c.CHECKPOINT_TYPE_PIPE_UP: 79 | self.player.rect.x = self.viewport.x + self.player_x 80 | self.player.rect.bottom = c.GROUND_HEIGHT 81 | self.player.state = c.UP_OUT_PIPE 82 | self.player.up_pipe_y = self.player_y 83 | 84 | def setup_collide(self, name): 85 | group = pg.sprite.Group() 86 | if name in self.map_data: 87 | for data in self.map_data[name]: 88 | group.add(stuff.Collider(data['x'], data['y'], 89 | data['width'], data['height'], name)) 90 | return group 91 | 92 | def setup_pipe(self): 93 | self.pipe_group = pg.sprite.Group() 94 | if c.MAP_PIPE in self.map_data: 95 | for data in self.map_data[c.MAP_PIPE]: 96 | self.pipe_group.add(stuff.Pipe(data['x'], data['y'], 97 | data['width'], data['height'], data['type'])) 98 | 99 | def setup_slider(self): 100 | self.slider_group = pg.sprite.Group() 101 | if c.MAP_SLIDER in self.map_data: 102 | for data in self.map_data[c.MAP_SLIDER]: 103 | if c.VELOCITY in data: 104 | vel = data[c.VELOCITY] 105 | else: 106 | vel = 1 107 | self.slider_group.add(stuff.Slider(data['x'], data['y'], data['num'], 108 | data['direction'], data['range_start'], data['range_end'], vel)) 109 | 110 | def setup_static_coin(self): 111 | self.static_coin_group = pg.sprite.Group() 112 | if c.MAP_COIN in self.map_data: 113 | for data in self.map_data[c.MAP_COIN]: 114 | self.static_coin_group.add(coin.StaticCoin(data['x'], data['y'])) 115 | 116 | def setup_brick_and_box(self): 117 | self.coin_group = pg.sprite.Group() 118 | self.powerup_group = pg.sprite.Group() 119 | self.brick_group = pg.sprite.Group() 120 | self.brickpiece_group = pg.sprite.Group() 121 | 122 | if c.MAP_BRICK in self.map_data: 123 | for data in self.map_data[c.MAP_BRICK]: 124 | brick.create_brick(self.brick_group, data, self) 125 | 126 | self.box_group = pg.sprite.Group() 127 | if c.MAP_BOX in self.map_data: 128 | for data in self.map_data[c.MAP_BOX]: 129 | if data['type'] == c.TYPE_COIN: 130 | self.box_group.add(box.Box(data['x'], data['y'], data['type'], self.coin_group)) 131 | else: 132 | self.box_group.add(box.Box(data['x'], data['y'], data['type'], self.powerup_group)) 133 | 134 | def setup_player(self): 135 | if self.player is None: 136 | self.player = player.Player(self.game_info[c.PLAYER_NAME]) 137 | else: 138 | self.player.restart() 139 | self.player.rect.x = self.viewport.x + self.player_x 140 | self.player.rect.bottom = self.player_y 141 | if c.DEBUG: 142 | self.player.rect.x = self.viewport.x + c.DEBUG_START_X 143 | self.player.rect.bottom = c.DEBUG_START_y 144 | self.viewport.x = self.player.rect.x - 110 145 | 146 | def setup_enemies(self): 147 | self.enemy_group_list = [] 148 | index = 0 149 | for data in self.map_data[c.MAP_ENEMY]: 150 | group = pg.sprite.Group() 151 | for item in data[str(index)]: 152 | group.add(enemy.create_enemy(item, self)) 153 | self.enemy_group_list.append(group) 154 | index += 1 155 | 156 | def setup_checkpoints(self): 157 | self.checkpoint_group = pg.sprite.Group() 158 | for data in self.map_data[c.MAP_CHECKPOINT]: 159 | if c.ENEMY_GROUPID in data: 160 | enemy_groupid = data[c.ENEMY_GROUPID] 161 | else: 162 | enemy_groupid = 0 163 | if c.MAP_INDEX in data: 164 | map_index = data[c.MAP_INDEX] 165 | else: 166 | map_index = 0 167 | self.checkpoint_group.add(stuff.Checkpoint(data['x'], data['y'], data['width'], 168 | data['height'], data['type'], enemy_groupid, map_index)) 169 | 170 | def setup_flagpole(self): 171 | self.flagpole_group = pg.sprite.Group() 172 | if c.MAP_FLAGPOLE in self.map_data: 173 | for data in self.map_data[c.MAP_FLAGPOLE]: 174 | if data['type'] == c.FLAGPOLE_TYPE_FLAG: 175 | sprite = stuff.Flag(data['x'], data['y']) 176 | self.flag = sprite 177 | elif data['type'] == c.FLAGPOLE_TYPE_POLE: 178 | sprite = stuff.Pole(data['x'], data['y']) 179 | else: 180 | sprite = stuff.PoleTop(data['x'], data['y']) 181 | self.flagpole_group.add(sprite) 182 | 183 | 184 | def setup_sprite_groups(self): 185 | self.dying_group = pg.sprite.Group() 186 | self.enemy_group = pg.sprite.Group() 187 | self.shell_group = pg.sprite.Group() 188 | 189 | self.ground_step_pipe_group = pg.sprite.Group(self.ground_group, 190 | self.pipe_group, self.step_group, self.slider_group) 191 | self.player_group = pg.sprite.Group(self.player) 192 | 193 | def update(self, surface, keys, current_time): 194 | self.game_info[c.CURRENT_TIME] = self.current_time = current_time 195 | self.handle_states(keys) 196 | self.draw(surface) 197 | 198 | def handle_states(self, keys): 199 | self.update_all_sprites(keys) 200 | 201 | def update_all_sprites(self, keys): 202 | if self.player.dead: 203 | self.player.update(keys, self.game_info, self.powerup_group) 204 | if self.current_time - self.death_timer > 3000: 205 | self.update_game_info() 206 | self.done = True 207 | elif self.player.state == c.IN_CASTLE: 208 | self.player.update(keys, self.game_info, None) 209 | self.flagpole_group.update() 210 | if self.current_time - self.castle_timer > 2000: 211 | self.update_game_info() 212 | self.done = True 213 | elif self.in_frozen_state(): 214 | self.player.update(keys, self.game_info, None) 215 | self.check_checkpoints() 216 | self.update_viewport() 217 | self.overhead_info.update(self.game_info, self.player) 218 | for score in self.moving_score_list: 219 | score.update(self.moving_score_list) 220 | else: 221 | self.player.update(keys, self.game_info, self.powerup_group) 222 | self.flagpole_group.update() 223 | self.check_checkpoints() 224 | self.slider_group.update() 225 | self.static_coin_group.update(self.game_info) 226 | self.enemy_group.update(self.game_info, self) 227 | self.shell_group.update(self.game_info, self) 228 | self.brick_group.update() 229 | self.box_group.update(self.game_info) 230 | self.powerup_group.update(self.game_info, self) 231 | self.coin_group.update(self.game_info) 232 | self.brickpiece_group.update() 233 | self.dying_group.update(self.game_info, self) 234 | self.update_player_position() 235 | self.check_for_player_death() 236 | self.update_viewport() 237 | self.overhead_info.update(self.game_info, self.player) 238 | for score in self.moving_score_list: 239 | score.update(self.moving_score_list) 240 | 241 | def check_checkpoints(self): 242 | checkpoint = pg.sprite.spritecollideany(self.player, self.checkpoint_group) 243 | 244 | if checkpoint: 245 | if checkpoint.type == c.CHECKPOINT_TYPE_ENEMY: 246 | group = self.enemy_group_list[checkpoint.enemy_groupid] 247 | self.enemy_group.add(group) 248 | elif checkpoint.type == c.CHECKPOINT_TYPE_FLAG: 249 | self.player.state = c.FLAGPOLE 250 | if self.player.rect.bottom < self.flag.rect.y: 251 | self.player.rect.bottom = self.flag.rect.y 252 | self.flag.state = c.SLIDE_DOWN 253 | self.update_flag_score() 254 | elif checkpoint.type == c.CHECKPOINT_TYPE_CASTLE: 255 | self.player.state = c.IN_CASTLE 256 | self.player.x_vel = 0 257 | self.castle_timer = self.current_time 258 | self.flagpole_group.add(stuff.CastleFlag(8745, 322)) 259 | elif (checkpoint.type == c.CHECKPOINT_TYPE_MUSHROOM and 260 | self.player.y_vel < 0): 261 | mushroom_box = box.Box(checkpoint.rect.x, checkpoint.rect.bottom - 40, 262 | c.TYPE_LIFEMUSHROOM, self.powerup_group) 263 | mushroom_box.start_bump(self.moving_score_list) 264 | self.box_group.add(mushroom_box) 265 | self.player.y_vel = 7 266 | self.player.rect.y = mushroom_box.rect.bottom 267 | self.player.state = c.FALL 268 | elif checkpoint.type == c.CHECKPOINT_TYPE_PIPE: 269 | self.player.state = c.WALK_AUTO 270 | elif checkpoint.type == c.CHECKPOINT_TYPE_PIPE_UP: 271 | self.change_map(checkpoint.map_index, checkpoint.type) 272 | elif checkpoint.type == c.CHECKPOINT_TYPE_MAP: 273 | self.change_map(checkpoint.map_index, checkpoint.type) 274 | elif checkpoint.type == c.CHECKPOINT_TYPE_BOSS: 275 | self.player.state = c.WALK_AUTO 276 | checkpoint.kill() 277 | 278 | def update_flag_score(self): 279 | base_y = c.GROUND_HEIGHT - 80 280 | 281 | y_score_list = [(base_y, 100), (base_y-120, 400), 282 | (base_y-200, 800), (base_y-320, 2000), 283 | (0, 5000)] 284 | for y, score in y_score_list: 285 | if self.player.rect.y > y: 286 | self.update_score(score, self.flag) 287 | break 288 | 289 | def update_player_position(self): 290 | if self.player.state == c.UP_OUT_PIPE: 291 | return 292 | 293 | self.player.rect.x += round(self.player.x_vel) 294 | if self.player.rect.x < self.start_x: 295 | self.player.rect.x = self.start_x 296 | elif self.player.rect.right > self.end_x: 297 | self.player.rect.right = self.end_x 298 | self.check_player_x_collisions() 299 | 300 | if not self.player.dead: 301 | self.player.rect.y += round(self.player.y_vel) 302 | self.check_player_y_collisions() 303 | 304 | def check_player_x_collisions(self): 305 | ground_step_pipe = pg.sprite.spritecollideany(self.player, self.ground_step_pipe_group) 306 | brick = pg.sprite.spritecollideany(self.player, self.brick_group) 307 | box = pg.sprite.spritecollideany(self.player, self.box_group) 308 | enemy = pg.sprite.spritecollideany(self.player, self.enemy_group) 309 | shell = pg.sprite.spritecollideany(self.player, self.shell_group) 310 | powerup = pg.sprite.spritecollideany(self.player, self.powerup_group) 311 | coin = pg.sprite.spritecollideany(self.player, self.static_coin_group) 312 | 313 | if box: 314 | self.adjust_player_for_x_collisions(box) 315 | elif brick: 316 | self.adjust_player_for_x_collisions(brick) 317 | elif ground_step_pipe: 318 | if (ground_step_pipe.name == c.MAP_PIPE and 319 | ground_step_pipe.type == c.PIPE_TYPE_HORIZONTAL): 320 | return 321 | self.adjust_player_for_x_collisions(ground_step_pipe) 322 | elif powerup: 323 | if powerup.type == c.TYPE_MUSHROOM: 324 | self.update_score(1000, powerup, 0) 325 | if not self.player.big: 326 | self.player.y_vel = -1 327 | self.player.state = c.SMALL_TO_BIG 328 | elif powerup.type == c.TYPE_FIREFLOWER: 329 | self.update_score(1000, powerup, 0) 330 | if not self.player.big: 331 | self.player.state = c.SMALL_TO_BIG 332 | elif self.player.big and not self.player.fire: 333 | self.player.state = c.BIG_TO_FIRE 334 | elif powerup.type == c.TYPE_STAR: 335 | self.update_score(1000, powerup, 0) 336 | self.player.invincible = True 337 | elif powerup.type == c.TYPE_LIFEMUSHROOM: 338 | self.update_score(500, powerup, 0) 339 | self.game_info[c.LIVES] += 1 340 | if powerup.type != c.TYPE_FIREBALL: 341 | powerup.kill() 342 | elif enemy: 343 | if self.player.invincible: 344 | self.update_score(100, enemy, 0) 345 | self.move_to_dying_group(self.enemy_group, enemy) 346 | direction = c.RIGHT if self.player.facing_right else c.LEFT 347 | enemy.start_death_jump(direction) 348 | elif self.player.hurt_invincible: 349 | pass 350 | elif self.player.big: 351 | self.player.y_vel = -1 352 | self.player.state = c.BIG_TO_SMALL 353 | else: 354 | self.player.start_death_jump(self.game_info) 355 | self.death_timer = self.current_time 356 | elif shell: 357 | if shell.state == c.SHELL_SLIDE: 358 | if self.player.invincible: 359 | self.update_score(200, shell, 0) 360 | self.move_to_dying_group(self.shell_group, shell) 361 | direction = c.RIGHT if self.player.facing_right else c.LEFT 362 | shell.start_death_jump(direction) 363 | elif self.player.hurt_invincible: 364 | pass 365 | elif self.player.big: 366 | self.player.y_vel = -1 367 | self.player.state = c.BIG_TO_SMALL 368 | else: 369 | self.player.start_death_jump(self.game_info) 370 | self.death_timer = self.current_time 371 | else: 372 | self.update_score(400, shell, 0) 373 | if self.player.rect.x < shell.rect.x: 374 | self.player.rect.left = shell.rect.x 375 | shell.direction = c.RIGHT 376 | shell.x_vel = 10 377 | else: 378 | self.player.rect.x = shell.rect.left 379 | shell.direction = c.LEFT 380 | shell.x_vel = -10 381 | shell.rect.x += shell.x_vel * 4 382 | shell.state = c.SHELL_SLIDE 383 | elif coin: 384 | self.update_score(100, coin, 1) 385 | coin.kill() 386 | 387 | def adjust_player_for_x_collisions(self, collider): 388 | if collider.name == c.MAP_SLIDER: 389 | return 390 | 391 | if self.player.rect.x < collider.rect.x: 392 | self.player.rect.right = collider.rect.left 393 | else: 394 | self.player.rect.left = collider.rect.right 395 | self.player.x_vel = 0 396 | 397 | def check_player_y_collisions(self): 398 | ground_step_pipe = pg.sprite.spritecollideany(self.player, self.ground_step_pipe_group) 399 | enemy = pg.sprite.spritecollideany(self.player, self.enemy_group) 400 | shell = pg.sprite.spritecollideany(self.player, self.shell_group) 401 | 402 | # decrease runtime delay: when player is on the ground, don't check brick and box 403 | if self.player.rect.bottom < c.GROUND_HEIGHT: 404 | brick = pg.sprite.spritecollideany(self.player, self.brick_group) 405 | box = pg.sprite.spritecollideany(self.player, self.box_group) 406 | brick, box = self.prevent_collision_conflict(brick, box) 407 | else: 408 | brick, box = False, False 409 | 410 | if box: 411 | self.adjust_player_for_y_collisions(box) 412 | elif brick: 413 | self.adjust_player_for_y_collisions(brick) 414 | elif ground_step_pipe: 415 | self.adjust_player_for_y_collisions(ground_step_pipe) 416 | elif enemy: 417 | if self.player.invincible: 418 | self.update_score(100, enemy, 0) 419 | self.move_to_dying_group(self.enemy_group, enemy) 420 | direction = c.RIGHT if self.player.facing_right else c.LEFT 421 | enemy.start_death_jump(direction) 422 | elif (enemy.name == c.PIRANHA or 423 | enemy.name == c.FIRESTICK or 424 | enemy.name == c.FIRE_KOOPA or 425 | enemy.name == c.FIRE): 426 | pass 427 | elif self.player.y_vel > 0: 428 | self.update_score(100, enemy, 0) 429 | enemy.state = c.JUMPED_ON 430 | if enemy.name == c.GOOMBA: 431 | self.move_to_dying_group(self.enemy_group, enemy) 432 | elif enemy.name == c.KOOPA or enemy.name == c.FLY_KOOPA: 433 | self.enemy_group.remove(enemy) 434 | self.shell_group.add(enemy) 435 | 436 | self.player.rect.bottom = enemy.rect.top 437 | self.player.state = c.JUMP 438 | self.player.y_vel = -7 439 | elif shell: 440 | if self.player.y_vel > 0: 441 | if shell.state != c.SHELL_SLIDE: 442 | shell.state = c.SHELL_SLIDE 443 | if self.player.rect.centerx < shell.rect.centerx: 444 | shell.direction = c.RIGHT 445 | shell.rect.left = self.player.rect.right + 5 446 | else: 447 | shell.direction = c.LEFT 448 | shell.rect.right = self.player.rect.left - 5 449 | self.check_is_falling(self.player) 450 | self.check_if_player_on_IN_pipe() 451 | 452 | def prevent_collision_conflict(self, sprite1, sprite2): 453 | if sprite1 and sprite2: 454 | distance1 = abs(self.player.rect.centerx - sprite1.rect.centerx) 455 | distance2 = abs(self.player.rect.centerx - sprite2.rect.centerx) 456 | if distance1 < distance2: 457 | sprite2 = False 458 | else: 459 | sprite1 = False 460 | return sprite1, sprite2 461 | 462 | def adjust_player_for_y_collisions(self, sprite): 463 | if self.player.rect.top > sprite.rect.top: 464 | if sprite.name == c.MAP_BRICK: 465 | self.check_if_enemy_on_brick_box(sprite) 466 | if sprite.state == c.RESTING: 467 | if self.player.big and sprite.type == c.TYPE_NONE: 468 | sprite.change_to_piece(self.dying_group) 469 | else: 470 | if sprite.type == c.TYPE_COIN: 471 | self.update_score(200, sprite, 1) 472 | sprite.start_bump(self.moving_score_list) 473 | elif sprite.name == c.MAP_BOX: 474 | self.check_if_enemy_on_brick_box(sprite) 475 | if sprite.state == c.RESTING: 476 | if sprite.type == c.TYPE_COIN: 477 | self.update_score(200, sprite, 1) 478 | sprite.start_bump(self.moving_score_list) 479 | elif (sprite.name == c.MAP_PIPE and 480 | sprite.type == c.PIPE_TYPE_HORIZONTAL): 481 | return 482 | 483 | self.player.y_vel = 7 484 | self.player.rect.top = sprite.rect.bottom 485 | self.player.state = c.FALL 486 | else: 487 | self.player.y_vel = 0 488 | self.player.rect.bottom = sprite.rect.top 489 | if self.player.state == c.FLAGPOLE: 490 | self.player.state = c.WALK_AUTO 491 | elif self.player.state == c.END_OF_LEVEL_FALL: 492 | self.player.state = c.WALK_AUTO 493 | else: 494 | self.player.state = c.WALK 495 | 496 | def check_if_enemy_on_brick_box(self, brick): 497 | brick.rect.y -= 5 498 | enemy = pg.sprite.spritecollideany(brick, self.enemy_group) 499 | if enemy: 500 | self.update_score(100, enemy, 0) 501 | self.move_to_dying_group(self.enemy_group, enemy) 502 | if self.player.rect.centerx > brick.rect.centerx: 503 | direction = c.RIGHT 504 | else: 505 | direction = c.LEFT 506 | enemy.start_death_jump(direction) 507 | brick.rect.y += 5 508 | 509 | def in_frozen_state(self): 510 | if (self.player.state == c.SMALL_TO_BIG or 511 | self.player.state == c.BIG_TO_SMALL or 512 | self.player.state == c.BIG_TO_FIRE or 513 | self.player.state == c.DEATH_JUMP or 514 | self.player.state == c.DOWN_TO_PIPE or 515 | self.player.state == c.UP_OUT_PIPE): 516 | return True 517 | else: 518 | return False 519 | 520 | def check_is_falling(self, sprite): 521 | sprite.rect.y += 1 522 | check_group = pg.sprite.Group(self.ground_step_pipe_group, 523 | self.brick_group, self.box_group) 524 | 525 | if pg.sprite.spritecollideany(sprite, check_group) is None: 526 | if (sprite.state == c.WALK_AUTO or 527 | sprite.state == c.END_OF_LEVEL_FALL): 528 | sprite.state = c.END_OF_LEVEL_FALL 529 | elif (sprite.state != c.JUMP and 530 | sprite.state != c.FLAGPOLE and 531 | not self.in_frozen_state()): 532 | sprite.state = c.FALL 533 | sprite.rect.y -= 1 534 | 535 | def check_for_player_death(self): 536 | if (self.player.rect.y > c.SCREEN_HEIGHT or 537 | self.overhead_info.time <= 0): 538 | self.player.start_death_jump(self.game_info) 539 | self.death_timer = self.current_time 540 | 541 | def check_if_player_on_IN_pipe(self): 542 | '''check if player is on the pipe which can go down in to it ''' 543 | self.player.rect.y += 1 544 | pipe = pg.sprite.spritecollideany(self.player, self.pipe_group) 545 | if pipe and pipe.type == c.PIPE_TYPE_IN: 546 | if (self.player.crouching and 547 | self.player.rect.x < pipe.rect.centerx and 548 | self.player.rect.right > pipe.rect.centerx): 549 | self.player.state = c.DOWN_TO_PIPE 550 | self.player.rect.y -= 1 551 | 552 | def update_game_info(self): 553 | if self.player.dead: 554 | self.persist[c.LIVES] -= 1 555 | 556 | if self.persist[c.LIVES] == 0: 557 | self.next = c.GAME_OVER 558 | elif self.overhead_info.time == 0: 559 | self.next = c.TIME_OUT 560 | elif self.player.dead: 561 | self.next = c.LOAD_SCREEN 562 | else: 563 | self.game_info[c.LEVEL_NUM] += 1 564 | self.next = c.LOAD_SCREEN 565 | 566 | def update_viewport(self): 567 | third = self.viewport.x + self.viewport.w//3 568 | player_center = self.player.rect.centerx 569 | 570 | if (self.player.x_vel > 0 and 571 | player_center >= third and 572 | self.viewport.right < self.end_x): 573 | self.viewport.x += round(self.player.x_vel) 574 | elif self.player.x_vel < 0 and self.viewport.x > self.start_x: 575 | self.viewport.x += round(self.player.x_vel) 576 | 577 | def move_to_dying_group(self, group, sprite): 578 | group.remove(sprite) 579 | self.dying_group.add(sprite) 580 | 581 | def update_score(self, score, sprite, coin_num=0): 582 | self.game_info[c.SCORE] += score 583 | self.game_info[c.COIN_TOTAL] += coin_num 584 | x = sprite.rect.x 585 | y = sprite.rect.y - 10 586 | self.moving_score_list.append(stuff.Score(x, y, score)) 587 | 588 | def draw(self, surface): 589 | self.level.blit(self.background, self.viewport, self.viewport) 590 | self.powerup_group.draw(self.level) 591 | self.brick_group.draw(self.level) 592 | self.box_group.draw(self.level) 593 | self.coin_group.draw(self.level) 594 | self.dying_group.draw(self.level) 595 | self.brickpiece_group.draw(self.level) 596 | self.flagpole_group.draw(self.level) 597 | self.shell_group.draw(self.level) 598 | self.enemy_group.draw(self.level) 599 | self.player_group.draw(self.level) 600 | self.static_coin_group.draw(self.level) 601 | self.slider_group.draw(self.level) 602 | self.pipe_group.draw(self.level) 603 | for score in self.moving_score_list: 604 | score.draw(self.level) 605 | if c.DEBUG: 606 | self.ground_step_pipe_group.draw(self.level) 607 | self.checkpoint_group.draw(self.level) 608 | 609 | surface.blit(self.level, (0,0), self.viewport) 610 | self.overhead_info.draw(surface) 611 | -------------------------------------------------------------------------------- /PythonSuperMario-master/source/states/load_screen.py: -------------------------------------------------------------------------------- 1 | __author__ = 'marble_xu' 2 | 3 | from .. import setup, tools 4 | from .. import constants as c 5 | from ..components import info 6 | 7 | class LoadScreen(tools.State): 8 | def __init__(self): 9 | tools.State.__init__(self) 10 | self.time_list = [2400, 2600, 2635] 11 | 12 | def startup(self, current_time, persist): 13 | self.start_time = current_time 14 | self.persist = persist 15 | self.game_info = self.persist 16 | self.next = self.set_next_state() 17 | 18 | info_state = self.set_info_state() 19 | self.overhead_info = info.Info(self.game_info, info_state) 20 | 21 | def set_next_state(self): 22 | return c.LEVEL 23 | 24 | def set_info_state(self): 25 | return c.LOAD_SCREEN 26 | 27 | def update(self, surface, keys, current_time): 28 | if (current_time - self.start_time) < self.time_list[0]: 29 | surface.fill(c.BLACK) 30 | self.overhead_info.update(self.game_info) 31 | self.overhead_info.draw(surface) 32 | elif (current_time - self.start_time) < self.time_list[1]: 33 | surface.fill(c.BLACK) 34 | elif (current_time - self.start_time) < self.time_list[2]: 35 | surface.fill((106, 150, 252)) 36 | else: 37 | self.done = True 38 | 39 | class GameOver(LoadScreen): 40 | def __init__(self): 41 | LoadScreen.__init__(self) 42 | self.time_list = [3000, 3200, 3235] 43 | 44 | def set_next_state(self): 45 | return c.MAIN_MENU 46 | 47 | def set_info_state(self): 48 | return c.GAME_OVER 49 | 50 | class TimeOut(LoadScreen): 51 | def __init__(self): 52 | LoadScreen.__init__(self) 53 | self.time_list = [2400, 2600, 2635] 54 | 55 | def set_next_state(self): 56 | if self.persist[c.LIVES] == 0: 57 | return c.GAME_OVER 58 | else: 59 | return c.LOAD_SCREEN 60 | 61 | def set_info_state(self): 62 | return c.TIME_OUT 63 | -------------------------------------------------------------------------------- /PythonSuperMario-master/source/states/main_menu.py: -------------------------------------------------------------------------------- 1 | __author__ = 'marble_xu' 2 | 3 | import pygame as pg 4 | from .. import tools 5 | from .. import setup 6 | from .. import constants as c 7 | from .. components import info 8 | 9 | class Menu(tools.State): 10 | def __init__(self): 11 | tools.State.__init__(self) 12 | persist = {c.COIN_TOTAL: 0, 13 | c.SCORE: 0, 14 | c.LIVES: 3, 15 | c.TOP_SCORE: 0, 16 | c.CURRENT_TIME: 0.0, 17 | c.LEVEL_NUM: 1, 18 | c.PLAYER_NAME: c.PLAYER_MARIO} 19 | self.startup(0.0, persist) 20 | 21 | def startup(self, current_time, persist): 22 | self.next = c.LOAD_SCREEN 23 | self.persist = persist 24 | self.game_info = persist 25 | self.overhead_info = info.Info(self.game_info, c.MAIN_MENU) 26 | 27 | self.setup_background() 28 | self.setup_player() 29 | self.setup_cursor() 30 | 31 | def setup_background(self): 32 | self.background = setup.GFX['level_1'] 33 | self.background_rect = self.background.get_rect() 34 | self.background = pg.transform.scale(self.background, 35 | (int(self.background_rect.width*c.BACKGROUND_MULTIPLER), 36 | int(self.background_rect.height*c.BACKGROUND_MULTIPLER))) 37 | 38 | self.viewport = setup.SCREEN.get_rect(bottom=setup.SCREEN_RECT.bottom) 39 | self.image_dict = {} 40 | image = tools.get_image(setup.GFX['title_screen'], 1, 60, 176, 88, 41 | (255, 0, 220), c.SIZE_MULTIPLIER) 42 | rect = image.get_rect() 43 | rect.x, rect.y = (170, 100) 44 | self.image_dict['GAME_NAME_BOX'] = (image, rect) 45 | 46 | def setup_player(self): 47 | self.player_list = [] 48 | player_rect_info = [(178, 32, 12, 16), (178, 128, 12, 16)] 49 | for rect in player_rect_info: 50 | image = tools.get_image(setup.GFX['mario_bros'], 51 | *rect, c.BLACK, 2.9) 52 | rect = image.get_rect() 53 | rect.x, rect.bottom = 110, c.GROUND_HEIGHT 54 | self.player_list.append((image, rect)) 55 | self.player_index = 0 56 | 57 | def setup_cursor(self): 58 | self.cursor = pg.sprite.Sprite() 59 | self.cursor.image = tools.get_image(setup.GFX[c.ITEM_SHEET], 24, 160, 8, 8, c.BLACK, 3) 60 | rect = self.cursor.image.get_rect() 61 | rect.x, rect.y = (220, 358) 62 | self.cursor.rect = rect 63 | self.cursor.state = c.PLAYER1 64 | 65 | def update(self, surface, keys, current_time): 66 | self.current_time = current_time 67 | self.game_info[c.CURRENT_TIME] = self.current_time 68 | self.player_image = self.player_list[self.player_index][0] 69 | self.player_rect = self.player_list[self.player_index][1] 70 | self.update_cursor(keys) 71 | self.overhead_info.update(self.game_info) 72 | 73 | surface.blit(self.background, self.viewport, self.viewport) 74 | surface.blit(self.image_dict['GAME_NAME_BOX'][0], 75 | self.image_dict['GAME_NAME_BOX'][1]) 76 | surface.blit(self.player_image, self.player_rect) 77 | surface.blit(self.cursor.image, self.cursor.rect) 78 | self.overhead_info.draw(surface) 79 | 80 | def update_cursor(self, keys): 81 | if self.cursor.state == c.PLAYER1: 82 | self.cursor.rect.y = 358 83 | if keys[pg.K_DOWN]: 84 | self.cursor.state = c.PLAYER2 85 | self.player_index = 1 86 | self.game_info[c.PLAYER_NAME] = c.PLAYER_LUIGI 87 | elif self.cursor.state == c.PLAYER2: 88 | self.cursor.rect.y = 403 89 | if keys[pg.K_UP]: 90 | self.cursor.state = c.PLAYER1 91 | self.player_index = 0 92 | self.game_info[c.PLAYER_NAME] = c.PLAYER_MARIO 93 | if keys[pg.K_RETURN]: 94 | self.reset_game_info() 95 | self.done = True 96 | 97 | def reset_game_info(self): 98 | self.game_info[c.COIN_TOTAL] = 0 99 | self.game_info[c.SCORE] = 0 100 | self.game_info[c.LIVES] = 3 101 | self.game_info[c.CURRENT_TIME] = 0.0 102 | self.game_info[c.LEVEL_NUM] = 1 103 | 104 | self.persist = self.game_info 105 | -------------------------------------------------------------------------------- /PythonSuperMario-master/source/tools.py: -------------------------------------------------------------------------------- 1 | __author__ = 'marble_xu' 2 | 3 | import os 4 | import pygame as pg 5 | from abc import ABC, abstractmethod 6 | 7 | keybinding = { 8 | 'action':pg.K_s, 9 | 'jump':pg.K_a, 10 | 'left':pg.K_LEFT, 11 | 'right':pg.K_RIGHT, 12 | 'down':pg.K_DOWN 13 | } 14 | 15 | class State(): 16 | def __init__(self): 17 | self.start_time = 0.0 18 | self.current_time = 0.0 19 | self.done = False 20 | self.next = None 21 | self.persist = {} 22 | 23 | @abstractmethod 24 | def startup(self, current_time, persist): 25 | '''abstract method''' 26 | 27 | def cleanup(self): 28 | self.done = False 29 | return self.persist 30 | 31 | @abstractmethod 32 | def update(sefl, surface, keys, current_time): 33 | '''abstract method''' 34 | 35 | class Control(): 36 | def __init__(self): 37 | self.screen = pg.display.get_surface() 38 | self.done = False 39 | self.clock = pg.time.Clock() 40 | self.fps = 60 41 | self.current_time = 0.0 42 | self.keys = pg.key.get_pressed() 43 | self.state_dict = {} 44 | self.state_name = None 45 | self.state = None 46 | 47 | def setup_states(self, state_dict, start_state): 48 | self.state_dict = state_dict 49 | self.state_name = start_state 50 | self.state = self.state_dict[self.state_name] 51 | 52 | def update(self): 53 | self.current_time = pg.time.get_ticks() 54 | if self.state.done: 55 | self.flip_state() 56 | self.state.update(self.screen, self.keys, self.current_time) 57 | 58 | def flip_state(self): 59 | previous, self.state_name = self.state_name, self.state.next 60 | persist = self.state.cleanup() 61 | self.state = self.state_dict[self.state_name] 62 | self.state.startup(self.current_time, persist) 63 | 64 | def event_loop(self): 65 | for event in pg.event.get(): 66 | if event.type == pg.QUIT: 67 | self.done = True 68 | elif event.type == pg.KEYDOWN: 69 | self.keys = pg.key.get_pressed() 70 | elif event.type == pg.KEYUP: 71 | self.keys = pg.key.get_pressed() 72 | 73 | def main(self): 74 | while not self.done: 75 | self.event_loop() 76 | self.update() 77 | pg.display.update() 78 | self.clock.tick(self.fps) 79 | 80 | def get_image(sheet, x, y, width, height, colorkey, scale): 81 | image = pg.Surface([width, height]) 82 | rect = image.get_rect() 83 | 84 | image.blit(sheet, (0, 0), (x, y, width, height)) 85 | image.set_colorkey(colorkey) 86 | image = pg.transform.scale(image, 87 | (int(rect.width*scale), 88 | int(rect.height*scale))) 89 | return image 90 | 91 | def load_all_gfx(directory, colorkey=(255,0,255), accept=('.png', '.jpg', '.bmp', '.gif')): 92 | graphics = {} 93 | for pic in os.listdir(directory): 94 | name, ext = os.path.splitext(pic) 95 | if ext.lower() in accept: 96 | img = pg.image.load(os.path.join(directory, pic)) 97 | if img.get_alpha(): 98 | img = img.convert_alpha() 99 | else: 100 | img = img.convert() 101 | img.set_colorkey(colorkey) 102 | graphics[name] = img 103 | return graphics 104 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PythonSuperMario-master 2 | 超级马里奥游戏 3 | -------------------------------------------------------------------------------- /README1.md: -------------------------------------------------------------------------------- 1 | # PythonSuperMario-master 2 | 超级马里奥游戏 3 | --------------------------------------------------------------------------------