Hi. , Hello, everyone ! This is the little panda
In your childhood memory , Is there a jump 、 The little man with the mushroom has been forgotten ?
Mario grew up eating mushrooms , World famous Superstar . Characterized by a big nose 、 Wear a hat 、 Wearing harness overalls 、 With a beard .
Hat and suspender overalls 、 Features such as a big nose and beard , Far from the image of a hero .
Plus a little fat body , If you don't pay attention, you may think of our hero Mario as a middle-aged uncle working in a convenience store .
But the personality and intimacy brought by the image , But deeply rooted in the hearts of players
If your childhood was demonized Light brainwashing, then go back to nostalgia ~
Today, I will take you to make a super Mary game , Super high reduction ~
What are you waiting for? You can have your own ” Super Marie “ What about the game , Learn quickly ~
__author__ = 'marble_xu'
DEBUG = False
DEBUG_START_X = 110
DEBUG_START_y = 538
SCREEN_HEIGHT = 600
SCREEN_WIDTH = 800
SCREEN_SIZE = (SCREEN_WIDTH,SCREEN_HEIGHT)
ORIGINAL_CAPTION = " Super Marie Problem solving source code Q Group :660193417"
## COLORS ##
# R G B
GRAY = (100, 100, 100)
NAVYBLUE = ( 60, 60, 100)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = ( 0, 255, 0)
FOREST_GREEN = ( 31, 162, 35)
BLUE = ( 0, 0, 255)
SKY_BLUE = ( 39, 145, 251)
YELLOW = (255, 255, 0)
ORANGE = (255, 128, 0)
PURPLE = (255, 0, 255)
CYAN = ( 0, 255, 255)
BLACK = ( 0, 0, 0)
NEAR_BLACK = ( 19, 15, 48)
COMBLUE = (233, 232, 255)
GOLD = (255, 215, 0)
BGCOLOR = WHITE
SIZE_MULTIPLIER = 2.5
BRICK_SIZE_MULTIPLIER = 2.69
BACKGROUND_MULTIPLER = 2.679
GROUND_HEIGHT = SCREEN_HEIGHT - 62
GAME_TIME_OUT = 301
#STATES FOR ENTIRE GAME
MAIN_MENU = 'main menu'
LOAD_SCREEN = 'load screen'
TIME_OUT = 'time out'
GAME_OVER = 'game over'
LEVEL = 'level'
#MAIN MENU CURSOR STATES
PLAYER1 = '1 PLAYER GAME'
PLAYER2 = '2 PLAYER GAME'
#GAME INFO DICTIONARY KEYS
COIN_TOTAL = 'coin total'
SCORE = 'score'
TOP_SCORE = 'top score'
LIVES = 'lives'
CURRENT_TIME = 'current time'
LEVEL_NUM = 'level num'
PLAYER_NAME = 'player name'
PLAYER_MARIO = 'mario'
PLAYER_LUIGI = 'luigi'
#MAP COMPONENTS
MAP_IMAGE = 'image_name'
MAP_MAPS = 'maps'
SUB_MAP = 'sub_map'
MAP_GROUND = 'ground'
MAP_PIPE = 'pipe'
PIPE_TYPE_NONE = 0
PIPE_TYPE_IN = 1 # can go down in the pipe
PIPE_TYPE_HORIZONTAL = 2 # can go right in the pipe
MAP_STEP = 'step'
MAP_BRICK = 'brick'
BRICK_NUM = 'brick_num'
TYPE_NONE = 0
TYPE_COIN = 1
TYPE_STAR = 2
MAP_BOX = 'box'
TYPE_MUSHROOM = 3
TYPE_FIREFLOWER = 4
TYPE_FIREBALL = 5
TYPE_LIFEMUSHROOM = 6
MAP_ENEMY = 'enemy'
ENEMY_TYPE_GOOMBA = 0
ENEMY_TYPE_KOOPA = 1
ENEMY_TYPE_FLY_KOOPA = 2
ENEMY_TYPE_PIRANHA = 3
ENEMY_TYPE_FIRESTICK = 4
ENEMY_TYPE_FIRE_KOOPA = 5
ENEMY_RANGE = 'range'
MAP_CHECKPOINT = 'checkpoint'
ENEMY_GROUPID = 'enemy_groupid'
MAP_INDEX = 'map_index'
CHECKPOINT_TYPE_ENEMY = 0
CHECKPOINT_TYPE_FLAG = 1
CHECKPOINT_TYPE_CASTLE = 2
CHECKPOINT_TYPE_MUSHROOM = 3
CHECKPOINT_TYPE_PIPE = 4 # trigger player to go right in a pipe
CHECKPOINT_TYPE_PIPE_UP = 5 # trigger player to another map and go up out of a pipe
CHECKPOINT_TYPE_MAP = 6 # trigger player to go to another map
CHECKPOINT_TYPE_BOSS = 7 # defeat the boss
MAP_FLAGPOLE = 'flagpole'
FLAGPOLE_TYPE_FLAG = 0
FLAGPOLE_TYPE_POLE = 1
FLAGPOLE_TYPE_TOP = 2
MAP_SLIDER = 'slider'
HORIZONTAL = 0
VERTICAL = 1
VELOCITY = 'velocity'
MAP_COIN = 'coin'
#COMPONENT COLOR
COLOR = 'color'
COLOR_TYPE_ORANGE = 0
COLOR_TYPE_GREEN = 1
COLOR_TYPE_RED = 2
#BRICK STATES
RESTING = 'resting'
BUMPED = 'bumped'
OPENED = 'opened'
#MUSHROOM STATES
REVEAL = 'reveal'
SLIDE = 'slide'
#Player FRAMES
PLAYER_FRAMES = 'image_frames'
RIGHT_SMALL_NORMAL = 'right_small_normal'
RIGHT_BIG_NORMAL = 'right_big_normal'
RIGHT_BIG_FIRE = 'right_big_fire'
#PLAYER States
STAND = 'standing'
WALK = 'walk'
JUMP = 'jump'
FALL = 'fall'
FLY = 'fly'
SMALL_TO_BIG = 'small to big'
BIG_TO_FIRE = 'big to fire'
BIG_TO_SMALL = 'big to small'
FLAGPOLE = 'flag pole'
WALK_AUTO = 'walk auto' # not handle key input in this state
END_OF_LEVEL_FALL = 'end of level fall'
IN_CASTLE = 'in castle'
DOWN_TO_PIPE = 'down to pipe'
UP_OUT_PIPE = 'up out of pipe'
#PLAYER FORCES
PLAYER_SPEED = 'speed'
WALK_ACCEL = 'walk_accel'
RUN_ACCEL = 'run_accel'
JUMP_VEL = 'jump_velocity'
MAX_Y_VEL = 'max_y_velocity'
MAX_RUN_SPEED = 'max_run_speed'
MAX_WALK_SPEED = 'max_walk_speed'
SMALL_TURNAROUND = .35
JUMP_GRAVITY = .31
GRAVITY = 1.01
#LIST of ENEMIES
GOOMBA = 'goomba'
KOOPA = 'koopa'
FLY_KOOPA = 'fly koopa'
FIRE_KOOPA = 'fire koopa'
FIRE = 'fire'
PIRANHA = 'piranha'
FIRESTICK = 'firestick'
#GOOMBA Stuff
LEFT = 'left'
RIGHT = 'right'
JUMPED_ON = 'jumped on'
DEATH_JUMP = 'death jump'
#KOOPA STUFF
SHELL_SLIDE = 'shell slide'
#FLAG STATE
TOP_OF_POLE = 'top of pole'
SLIDE_DOWN = 'slide down'
BOTTOM_OF_POLE = 'bottom of pole'
#FIREBALL STATE
FLYING = 'flying'
BOUNCING = 'bouncing'
EXPLODING = 'exploding'
#IMAGE SHEET
ENEMY_SHEET = 'smb_enemies_sheet'
ITEM_SHEET = 'item_objects'
__author__ = 'marble_xu'
import pygame as pg
from .. import setup, tools
from .. import constants as c
from . import coin, powerup
class Box(pg.sprite.Sprite):
def __init__(self, x, y, type, group=None, name=c.MAP_BOX):
pg.sprite.Sprite.__init__(self)
self.frames = []
self.frame_index = 0
self.load_frames()
self.image = self.frames[self.frame_index]
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y
self.rest_height = y
self.animation_timer = 0
self.first_half = True # First half of animation cycle
self.state = c.RESTING
self.y_vel = 0
self.gravity = 1.2
self.type = type
self.group = group
self.name = name
def load_frames(self):
sheet = setup.GFX['tile_set']
frame_rect_list = [(384, 0, 16, 16), (400, 0, 16, 16),
(416, 0, 16, 16), (400, 0, 16, 16), (432, 0, 16, 16)]
for frame_rect in frame_rect_list:
self.frames.append(tools.get_image(sheet, *frame_rect,
c.BLACK, c.BRICK_SIZE_MULTIPLIER))
def update(self, game_info):
self.current_time = game_info[c.CURRENT_TIME]
if self.state == c.RESTING:
self.resting()
elif self.state == c.BUMPED:
self.bumped()
def resting(self):
time_list = [375, 125, 125, 125]
if (self.current_time - self.animation_timer) > time_list[self.frame_index]:
self.frame_index += 1
if self.frame_index == 4:
self.frame_index = 0
self.animation_timer = self.current_time
self.image = self.frames[self.frame_index]
def bumped(self):
self.rect.y += self.y_vel
self.y_vel += self.gravity
if self.rect.y > self.rest_height + 5:
self.rect.y = self.rest_height
self.state = c.OPENED
if self.type == c.TYPE_MUSHROOM:
self.group.add(powerup.Mushroom(self.rect.centerx, self.rect.y))
elif self.type == c.TYPE_FIREFLOWER:
self.group.add(powerup.FireFlower(self.rect.centerx, self.rect.y))
elif self.type == c.TYPE_LIFEMUSHROOM:
self.group.add(powerup.LifeMushroom(self.rect.centerx, self.rect.y))
self.frame_index = 4
self.image = self.frames[self.frame_index]
def start_bump(self, score_group):
self.y_vel = -6
self.state = c.BUMPED
if self.type == c.TYPE_COIN:
self.group.add(coin.Coin(self.rect.centerx, self.rect.y, score_group))
import pygame as pg
from source.main import main
if __name__=='__main__':
main()
pg.quit()
Because there is too much code, as shown in the figure below ( Part of the ): So let's get the complete code by ourselves !
Thank you Mario! But our princess is 1n another castle! ”
Thank you, Mario , But our princess is in another castle !
If you are interested in the game, please make one by yourself ~
Your support is my biggest motivation !! Thank you for your company ~
Remember Sanlian ~ Welcome to read previous articles