上次文章:
上次我为大家带来了python我的世界,可是更难的是什么呢?
对,就是写了几个月的超级玛丽!
大家可以尝试自己写一写。
提示:
我这个中包含了音乐哦~
我这里只会放几个程序,要全部的话在最后去百度网盘中的超级玛丽.zip下载。
目录
一、constants.py
__author__ = 'Python代码狂人'
SCREEN_HEIGHT = 600
SCREEN_WIDTH = 800
SCREEN_SIZE = (SCREEN_WIDTH,SCREEN_HEIGHT)
ORIGINAL_CAPTION = "Super Mario Bros 1-1"
## 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
#MARIO FORCES
WALK_ACCEL = .15
RUN_ACCEL = 20
SMALL_TURNAROUND = .35
GRAVITY = 1.01
JUMP_GRAVITY = .31
JUMP_VEL = -11
FAST_JUMP_VEL = -12.5
MAX_Y_VEL = 11
MAX_RUN_SPEED = 800
MAX_WALK_SPEED = 6
#Mario States
STAND = 'standing'
WALK = 'walk'
JUMP = 'jump'
FALL = 'fall'
SMALL_TO_BIG = 'small to big'
BIG_TO_FIRE = 'big to fire'
BIG_TO_SMALL = 'big to small'
FLAGPOLE = 'flag pole'
WALKING_TO_CASTLE = 'walking to castle'
END_OF_LEVEL_FALL = 'end of level fall'
#GOOMBA Stuff
LEFT = 'left'
RIGHT = 'right'
JUMPED_ON = 'jumped on'
DEATH_JUMP = 'death jump'
#KOOPA STUFF
SHELL_SLIDE = 'shell slide'
#BRICK STATES
RESTING = 'resting'
BUMPED = 'bumped'
#COIN STATES
OPENED = 'opened'
#MUSHROOM STATES
REVEAL = 'reveal'
SLIDE = 'slide'
#COIN STATES
SPIN = 'spin'
#STAR STATES
BOUNCE = 'bounce'
#FIRE STATES
FLYING = 'flying'
BOUNCING = 'bouncing'
EXPLODING = 'exploding'
#Brick and coin box contents
MUSHROOM = 'mushroom'
STAR = 'star'
FIREFLOWER = 'fireflower'
SIXCOINS = '6coins'
COIN = 'coin'
LIFE_MUSHROOM = '1up_mushroom'
FIREBALL = 'fireball'
#LIST of ENEMIES
GOOMBA = 'goomba'
KOOPA = 'koopa'
#LEVEL STATES
FROZEN = 'frozen'
NOT_FROZEN = 'not frozen'
IN_CASTLE = 'in castle'
FLAG_AND_FIREWORKS = 'flag and fireworks'
#FLAG STATE
TOP_OF_POLE = 'top of pole'
SLIDE_DOWN = 'slide down'
BOTTOM_OF_POLE = 'bottom of pole'
#1UP score
ONEUP = '379'
#MAIN MENU CURSOR STATES
PLAYER1 = '1 player'
PLAYER2 = '2 player'
#OVERHEAD INFO STATES
MAIN_MENU = 'main menu'
LOAD_SCREEN = 'loading screen'
LEVEL = 'level'
GAME_OVER = 'game over'
FAST_COUNT_DOWN = 'fast count down'
END_OF_LEVEL = 'end of level'
#GAME INFO DICTIONARY KEYS
COIN_TOTAL = 'coin total'
SCORE = 'score'
TOP_SCORE = 'top score'
LIVES = 'lives'
CURRENT_TIME = 'current time'
LEVEL_STATE = 'level state'
CAMERA_START_X = 'camera start x'
MARIO_DEAD = 'mario dead'
#STATES FOR ENTIRE GAME
MAIN_MENU = 'main menu'
LOAD_SCREEN = 'load screen'
TIME_OUT = 'time out'
GAME_OVER = 'game over'
LEVEL1 = 'level1'
#SOUND STATEZ
NORMAL = 'normal'
STAGE_CLEAR = 'stage clear'
WORLD_CLEAR = 'world clear'
TIME_WARNING = 'time warning'
SPED_UP_NORMAL = 'sped up normal'
MARIO_INVINCIBLE = 'mario invincible'
二、main.py
__author__ = 'Python代码狂人'
from . import setup,tools
from .states import main_menu,load_screen,level1
from . import constants as c
def main():
"""Add states to control here."""
run_it = tools.Control(setup.ORIGINAL_CAPTION)
state_dict = {c.MAIN_MENU: main_menu.Menu(),
c.LOAD_SCREEN: load_screen.LoadScreen(),
c.TIME_OUT: load_screen.TimeOut(),
c.GAME_OVER: load_screen.GameOver(),
c.LEVEL1: level1.Level1()}
run_it.setup_states(state_dict, c.MAIN_MENU)
run_it.main()
三、mario_level_1.py
#!/usr/bin/env python
__author__ = 'Python代码狂人'
"""
This is an attempt to recreate the first level of
Super Mario Bros for the NES.
"""
import sys
import pygame as pg
from data.main import main
import cProfile
if __name__=='__main__':
main()
pg.quit()
sys.exit()
在这里感谢python代码大全这位博主。谢谢他给我了文件,我在文件中修改了一些程序。
下载地址:
打开游戏方法:打开mario_level_1.py就可以了!
更多程序请敬请期待!
给每个人的信:
各位亲爱的读者、支持者、博主们:
我再次感谢各位支持我,每次都会看我的文章。虽然我粉丝,观看量不多,但我一直希望可以在csdn上面成为一个有名气的人。python代码大全这个博主:我十分感谢你,我一直以来都想要一个超级玛丽程序,现在有了我十分高兴。如果你们有什么建议或者程序的话可以和我分享。谢谢大家的支持与理解!希望大家不要因为我年纪小就小看我。
我会多多写文章,传资源。我每天坚持学习,编程。我还要复习TOEFL词语和知识,学习语数英、美术、音乐。每次我写文章不是为了炫耀自己小小年纪会写出这么多好的游戏。这归功于我的努力学习。我每次遇到困难,都会到csdn上找答案,我十分感谢csdn上的所有博主,感谢你们给了我这么多帮助!
通过我的学习,现在的我已经会很多python语法了,也有了自己的粉丝和崇拜的博主。各位读者、支持者、博主,你们的经历是怎么样的呢?我希望和你们一样,成为一个很厉害的人,在csdn这个网站上成为最有名,最幽默,年纪最小的博主!
涵子码农-python忠实迷
2022年6月10日
最后感谢:
programmer_ada博主,c343340657c博主,梦执.py,python代码大全博主、公众号,涛哥依旧博主,一行玩python博主,Juni Zhu博主......
各位读者、支持者。
大家加油!