首页 > 作文

超级玛丽怎么玩

更新时间:2023-03-14 21:31:52 阅读: 评论:0

一年级数学下-芹菜炒鸡胗

超级玛丽怎么玩
2023年3月14日发(作者:舟山普陀山)

python:点击就能玩的超级玛丽⼩游戏(附有源码)

程序代码

importpygame,os,wx

fromrandomimportrandint

fromsysimportexit

import*

()

defmain():

#获取屏幕⼤⼩

app=()

WHFRAMES=ySize()

WIDTH=int(WHFRAMES[0]*0.7)

HEIGHT=int(WHFRAMES[1]*0.8)

Timers=0#游戏定时器

TimersSec=0#秒

tim_psd=0

#获取屏幕⼤⼩

screen=_mode((WIDTH,HEIGHT),0,32)

caption=_caption("超级马⾥奥")

([255,255,255])

mariofont=('fonts/',22)

mario_name=("MARIO",True,(84,65,190),None)

#Game_world=("WORLD",True,(84,65,190),None)

Game_moneyX=("X",True,(255,255,128),None)

Game_time=("TIME",True,(84,65,190),None)

money_ic5=('images/PTModelSprite_')

money_ic5=(money_ic5,(25,25))

money_ic6=('images/PTModelSprite_')

money_ic6=(money_ic6,(10,25))

money_ic7=('images/PTModelSprite_')

money_ic7=(money_ic7,(25,25))

money_ic8=('images/PTModelSprite_')

money_ic8=(money_ic8,(25,25))

money_timers=0#图⽚轮播定时器

Game_world=('images/PTModelSprite_')

background=('images/PTModelSprite_').convert_alpha()

background=(background,(WIDTH,HEIGHT))

Roads=('images/PTModelSprite_').convert_alpha()

Roads2=('images/PTModelSprite_').convert_alpha()

hero=('images/PTModelSprite_').convert_alpha()

x,y=15,HEIGHT-200

inp_flag=-2#(stop:-1leftdrection,-2rightdrection),(walk:1rightdrection,2leftdrection)

times,times2=0,0#⼈物动作定时器

move_values,jump_values,jump_values2,jump_values3=12,0,0,0#⼀步移动的距离和跳跃的值1,2

jump_adder,jump_max_point=0,50#跳跃累加器⽤来累加按键的长短然后判断跳跃的⾼度,跳跃的初始值最⾼点

jump_flag=0

bg_w_1,bg_w_2=0,WIDTH-2#两张壁纸⼀前⼀后循环拖动的变量

#播放背景

#播放背景

#游戏信息数据定义

score=0

score=0

money=0

world=11

time=400

Gdata=[score,money,world,time]

#游戏信息数据定义

#初始化函数

defgame_initializaion(score,money,world,time,Gdata,TimersSec,Timers,x,y,inp_flag,times,times2,move_values,jump_values,jump_values2,jump_values3,jump_

#游戏初始化数据

inp_flag=-2#(stop:-1leftdrection,-2rightdrection),(walk:1rightdrection,2leftdrection)

x,y=15,HEIGHT-200#马⾥奥坐标

times,times2=0,0#⼈物动作定时器

move_values,jump_values,jump_values2,jump_values3=12,0,0,0#⼀步移动的距离和跳跃的值1,2

jump_adder,jump_max_point=0,50#跳跃累加器⽤来累加按键的长短然后判断跳跃的⾼度,跳跃的初始值最⾼点

jump_flag=0

tim_psd=0

bg_w_1,bg_w_2=0,WIDTH-2#两张壁纸⼀前⼀后循环拖动的变量

Timers=0#游戏定时器

score=0#开始分数

money=0#开始⾦钱

world=11#世界关卡第⼀关1-1=11

time=400#游戏总时间

TimersSec=0#游戏⾥的秒

Gdata=[score,money,world,time]

#游戏初始化数据

returnscore,money,world,time,Gdata,TimersSec,Timers,x,y,inp_flag,times,times2,move_values,jump_values,jump_values2,jump_values3,jump_adder,jump_ma

#初始化函数

score,money,world,time,Gdata,TimersSec,Timers,x,y,inp_flag,times,times2,move_values,jump_values,jump_values2,jump_values3,jump_adder,jump_max_poin

game_initializaion(score,money,world,time,Gdata,TimersSec,Timers,x,y,inp_flag,times,times2,move_values,jump_values,jump_values2,jump_values3,jump_add

clock=()

_repeat(55)

()

defWalkAction(times,times2,inp_flag,hero):

#walkaction

ify

ifinp_flag==1:#right

hero=('images/PTModelSprite_').convert_alpha()

ifinp_flag==2:#left

hero=('images/PTModelSprite_').convert_alpha()

hero=(hero,True,Fal)

el:

ifinp_flag==1:#right

times+=2

iftimes<20:

hero=('images/PTModelSprite_').convert_alpha()

eliftimes<20:

hero=('images/PTModelSprite_ID34257..png').convert_alpha()

eliftimes<40:

hero=('images/PTModelSprite_').convert_alpha()

eliftimes<60:

hero=('images/PTModelSprite_').convert_alpha()

eliftimes<80:

hero=('images/PTModelSprite_').convert_alpha()

eliftimes<100:

hero=('images/PTModelSprite_').convert_alpha()

eliftimes<120:

hero=('images/PTModelSprite_').convert_alpha()

eliftimes<140:

times=0

ifinp_flag==2:#left

times2+=2

iftimes2<20:

iftimes2<20:

hero=('images/PTModelSprite_').convert_alpha()

hero=(hero,True,Fal)

eliftimes2<20:

hero=('images/PTModelSprite_ID34257..png').convert_alpha()

hero=(hero,True,Fal)

eliftimes2<40:

hero=('images/PTModelSprite_').convert_alpha()

hero=(hero,True,Fal)

eliftimes2<60:

hero=('images/PTModelSprite_').convert_alpha()

hero=(hero,True,Fal)

eliftimes2<80:

hero=('images/PTModelSprite_').convert_alpha()

hero=(hero,True,Fal)

eliftimes2<100:

hero=('images/PTModelSprite_').convert_alpha()

hero=(hero,True,Fal)

eliftimes2<120:

hero=('images/PTModelSprite_').convert_alpha()

hero=(hero,True,Fal)

eliftimes2<140:

times2=0

elifinp_flag==-1:

hero=('images/PTModelSprite_').convert_alpha()

hero=(hero,True,Fal)

times2=0

elifinp_flag==-2:

hero=('images/PTModelSprite_').convert_alpha()

times2=0

returntimes,times2,inp_flag,hero

defHeroHeightIs():#判断⾓⾊是否为地⾯y轴

ify>=HEIGHT-200:

returnFal

el:#这是在控制的状况

returnTrue

defRet_max_point(jump_max_point):#在地⾯重设默认跳跃的最⾼点(还原)

ify>=(HEIGHT-200):

jump_max_point=50#默认最⾼点是50

returnjump_max_point

defjump_leftScreenBgnotMove(x):

ifx<(WIDTH/4):

ifjump_max_point==50:

ifinp_flag==1:

x+=(2.7)

ifinp_flag==2:

x-=(2.7)

elifjump_max_point==100:

ifinp_flag==1:

x+=(0.27)

ifinp_flag==2:

x-=(0.27)

returnx

defScreen_MoneyIc(screen,money_ic5,money_ic6,money_ic7,money_ic8,money_timers):#绘制第⼆项⾦钱图标

money_timers+=1

ifmoney_timers<15:

ifmoney_timers<15:

(money_ic5,(WIDTH*0.24,25))#绘制第⼆项⾦钱图标1

elifmoney_timers<40:

(money_ic6,(WIDTH*0.24+7.5,25))#绘制第⼆项⾦钱图标2

elifmoney_timers<55:

(money_ic7,(WIDTH*0.24,25))#绘制第⼆项⾦钱图标3

elifmoney_timers<80:

(money_ic8,(WIDTH*0.24,25))#绘制第⼆项⾦钱图标4

el:

money_timers=0

returnscreen,money_ic5,money_ic6,money_ic7,money_ic8,money_timers

defGame_Timers(TimersSec,Gdata,time_pasd,tim_psd):#游戏定时器

tim_psd+=time_pasd

iftim_psd>=1000:#为1秒的时候

TimersSec+=1

tim_psd=0

Gdata[3]=400-TimersSec#游戏所剩时间

returnTimersSec,Gdata,time_pasd,tim_psd

whileTrue:

#事件检测

():

==:

exit()

==KEYDOWN:

keys=_presd()

ifkeys[pygame.K_a]:

==K_wandinp_flag==0:

ify<=HEIGHT-200:#看y坐标必须在起点

jump_flag=3#按了上和向前

ify>=HEIGHT-200:#如果⾓⾊在平地才⾛动后退左

#ifbg_w_1==0:

#x-=5

x-=(move_values+3.5)

inp_flag=2

ifkeys[pygame.K_d]:

==K_wandinp_flag==0:

ify<=HEIGHT-200:#看y坐标必须在起点

jump_flag=2#按了上和向前

ify>=HEIGHT-200:#如果⾓⾊在平地才⾛动前景右

ifx<(WIDTH/4):#⾓⾊还在屏幕左边可移动

x+=(move_values+3.5)

inp_flag=1

ifkeys[pygame.K_w]:#jump

jump_flag=1#仅仅是按了跳跃

jump_adder+=1#跳跃累加器

==pygame.K_dand(jump_flag==1):

ify==HEIGHT-200:#看y坐标必须在起点

jump_flag=2#按了上和向前

==pygame.K_aand(jump_flag==1):

ify==HEIGHT-200:#看y坐标必须在起点

jump_flag=3#按了上和向后

ifkeys[pygame.K_p]:#重启

score,money,world,time,Gdata,TimersSec,Timers,x,y,inp_flag,times,times2,move_values,

jump_values,jump_values2,jump_values3,jump_adder,jump_max_point,jump_flag,bg_w_1,bg_w_2,tim_psd=

game_initializaion(score,money,world,time,Gdata,TimersSec,Timers,x,y,inp_flag,times,times2,

game_initializaion(score,money,world,time,Gdata,TimersSec,Timers,x,y,inp_flag,times,times2,

move_values,jump_values,jump_values2,jump_values3,jump_adder,jump_max_point,jump_flag,bg_w_1,

bg_w_2,tim_psd)

==KEYUP:

ifkeys[pygame.K_a]:

inp_flag=-1

ifkeys[pygame.K_d]:

inp_flag=-2

ifkeys[pygame.K_w]:

ifjump_adder<4:#如果松开按键没有达到jump_adder跳跃累加器的值(那么就他们置零)

jump_adder=0

##在地⾯时重设默认跳跃的最⾼点(还原)

jump_max_point=Ret_max_point(jump_max_point)

#jumpaction1

ifjump_flag==1:#只有跳跃

#让其他⽅式跳跃值为0

jump_values2=0

jump_values3=0

#------

#持续按键跳跃的结构

ifjump_adder>=4:

jump_max_point=100#第⼆次跳跃最⼤值

jump_adder=0

#------

jump_values+=1.25

ifjump_values<=jump_max_point:

y-=5

x=jump_leftScreenBgnotMove(x)

ifjump_max_point==100:#跳跃的⾼度不同y坐标的速度也要慢点

y+=1.5

x=jump_leftScreenBgnotMove(x)

elifjump_values<=jump_max_point+8:

pass

elifjump_values<=jump_max_point*2+8:

ifHeroHeightIs():#如果⾓⾊在控制就继续加y轴的值1

y+=5

x=jump_leftScreenBgnotMove(x)

ifjump_max_point==100:#跳跃的⾼度不同y坐标的速度也要慢点

y-=1.5

x=jump_leftScreenBgnotMove(x)

el:

y=HEIGHT-200

jump_flag=0

jump_values=0

#walldetection

ifx<=0:

x=0

ifx+_width()>WIDTH:

x=_width()

#⾓⾊的动作函数

times,times2,inp_flag,hero=WalkAction(times,times2,inp_flag,hero)

#---blit

(background,(bg_w_2,0))

(background,(bg_w_1,0))

#绘制信息

(mario_name,(WIDTH*0.03,3))#绘制第⼀项名字

screen,money_ic5,money_ic6,money_ic7,money_ic8,money_timers=

Screen_MoneyIc(screen,money_ic5,money_ic6,money_ic7,money_ic8,money_timers)#绘制第⼆项⾦钱图标

(Game_moneyX,(WIDTH*0.28,24))#绘制第⼆项x

(Game_world,(WIDTH*0.5-Game__width()/2,3))#绘制第三项世界地图

(Game_time,(WIDTH*0.84,3))#绘制第四项游戏时间

forDATAiinrange(4):

Game_data=("%s"%Gdata[DATAi],True,(255,255,128),None)#综合绘制:分数⾦币关卡游戏时间

ifDATAi!=2:

(Game_data,(WIDTH*(0.03+DATAi*0.27),24))

elifDATAi==2:

Game_data=("%s-%s"%(Gdata[DATAi]/10,Gdata[DATAi]%10),True,(255,255,128),None)#综合绘制:分数⾦币关卡游戏时间

(Game_data,(WIDTH*0.5-Game__width()/2,15))

#绘制信息

#--panel

#ifinp_flag==2:#往左⾛壁纸向右拖动

#bg_w_1+=move_values/4

#bg_w_2+=move_values/4

ifinp_flag==1andx>=(WIDTH/4):#往右⾛壁纸向左拖动

bg_w_1-=(move_values/4-0.5)

bg_w_2-=(move_values/4-0.5)

ifbg_w_1>=0:

bg_w_1,bg_w_2=0,WIDTH-2

ifbg_w_1<-WIDTH:

bg_w_1,bg_w_2=0,WIDTH-2

(hero,(x,y))

(2)#毫秒

time_pasd=()

TimersSec,Gdata,time_pasd,tim_psd=Game_Timers(TimersSec,Gdata,time_pasd,tim_psd)#游戏定时

()

if__name__=='__main__':

main()

本文发布于:2023-03-14 21:31:51,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/1678800712252605.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:超级玛丽怎么玩.doc

本文 PDF 下载地址:超级玛丽怎么玩.pdf

下一篇:返回列表
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图