這篇文章,我們首先介紹了超級(jí)瑪麗游戲中多狀態(tài)跳躍和行走地圖拖動(dòng)的原理,然后實(shí)現(xiàn)。(約翰f肯尼迪)。
并實(shí)現(xiàn)倒計(jì)時(shí)和金幣動(dòng)態(tài)效果(代碼在后面,可以直接復(fù)制)接下來用下面這四張圖,就可以完全懂得游戲中背景是怎么會(huì)移動(dòng)的。
圖一
圖二
圖三
圖四
注:由于代碼是我前幾年學(xué)習(xí)python的時(shí)候做的,代碼寫的很擠都整到一個(gè)源文件中,大家看的時(shí)候仔細(xì)。
源代碼:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import pygame,os,wx
from random import randint
from sys import exit
from import *
()
def main():
#獲取屏幕大小
app=wx.App()
WHFRAMES=wx.DisplaySize()
WIDTH=int(WHFRAMES[0]*0.7)
HEIGHT=int(WHFRAMES[1]*0.8)
Timers = 0 #游戲定時(shí)器
TimersSec = 0 #秒
tim_psd = 0
#獲取屏幕大小
screen=((WIDTH,HEIGHT),0,32)
caption=("超級(jí)馬里奧")
([255,255,255])
mariofont = ('fon;,22)
mario_name = mario("MARIO",True,(84,65,190),None)
#Game_world = mario("WORLD",True,(84,65,190),None)
Game_moneyX = mario("X",True,(255,255,128),None)
Game_time = mario("TIME",True,(84,65,190),None)
money_ic5 = pygame.image.load('image;)
money_ic5 = (money_ic5, (25, 25))
money_ic6 = pygame.image.load('image;)
money_ic6 = (money_ic6, (10, 25))
money_ic7 = pygame.image.load('image;)
money_ic7 = (money_ic7, (25, 25))
money_ic8 = pygame.image.load('image;)
money_ic8 = (money_ic8, (25, 25))
money_timers = 0 #圖片輪播定時(shí)器
Game_world = pygame.image.load('image;)
background = pygame.image.load('image;).convert_alpha()
background = (background, (WIDTH, HEIGHT))
Roads = pygame.image.load('image;).convert_alpha()
Roads2 = pygame.image.load('image;).convert_alpha()
hero = pygame.image.load('image;).convert_alpha()
x,y = 15,HEIGHT-200
inp_flag = -2 #(stop:-1 left drection ,-2 right drection) ,(walk:1 right drection ,2 left drection)
times,times2 = 0,0 #人物動(dòng)作定時(shí)器
move_values,jump_values,jump_values2,jump_values3 = 12,0,0,0 #一步移動(dòng)的距離 和 跳躍的值1,2
jump_adder,jump_max_point = 0,50 #跳躍累加器 用來累加按鍵的長(zhǎng)短 然后判斷跳躍的高度,跳躍的初始值最高點(diǎn)
jump_flag = 0
bg_w_1,bg_w_2 = 0,WIDTH-2 #兩張壁紙 一前一后循環(huán)拖動(dòng)的變量
#播放背景
#播放背景
#游戲信息數(shù)據(jù)定義
score = 0
money = 0
world = 11
time = 400
Gdata = [score,money,world,time]
#游戲信息數(shù)據(jù)定義
#初始化函數(shù)
def 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):#數(shù)據(jù)初始化
#游戲初始化數(shù)據(jù)
inp_flag = -2 #(stop:-1 left drection ,-2 right drection) ,(walk:1 right drection ,2 left drection)
x,y = 15,HEIGHT-200 #馬里奧坐標(biāo)
times,times2 = 0,0 #人物動(dòng)作定時(shí)器
move_values,jump_values,jump_values2,jump_values3 = 12,0,0,0 #一步移動(dòng)的距離 和 跳躍的值1,2
jump_adder,jump_max_point = 0,50 #跳躍累加器 用來累加按鍵的長(zhǎng)短 然后判斷跳躍的高度,跳躍的初始值最高點(diǎn)
jump_flag = 0
tim_psd = 0
bg_w_1,bg_w_2 = 0,WIDTH-2 #兩張壁紙 一前一后循環(huán)拖動(dòng)的變量
Timers = 0 #游戲定時(shí)器
score = 0 #開始分?jǐn)?shù)
money = 0 #開始金錢
world = 11 #世界關(guān)卡第一關(guān)1-1 = 11
time = 400#游戲總時(shí)間
TimersSec = 0 #游戲里的秒
Gdata = [score,money,world,time]
#游戲初始化數(shù)據(jù)
return 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
#初始化函數(shù)
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,move_values,jump_values,jump_values2,jump_values3,jump_adder,jump_max_point,jump_flag,bg_w_1,bg_w_2,tim_psd)#數(shù)據(jù)初始化主調(diào)函數(shù)
clock = ()
(55)
()
def WalkAction(times,times2,inp_flag,hero):
#walk action
if y < HEIGHT -200: #如果在空中 為跳躍圖片
if inp_flag == 1: #right
hero = pygame.image.load('image;).convert_alpha()
if inp_flag == 2: #left
hero = pygame.image.load('image;).convert_alpha()
hero = (hero, True, False)
else:
if inp_flag == 1: #right
times += 2
if times < 20:
hero = pygame.image.load('image;).convert_alpha()
elif times < 20:
hero = pygame.image.load('images/PTModelSprite_ID34257..png').convert_alpha()
elif times < 40:
hero = pygame.image.load('image;).convert_alpha()
elif times < 60:
hero = pygame.image.load('image;).convert_alpha()
elif times < 80:
hero = pygame.image.load('image;).convert_alpha()
elif times < 100:
hero = pygame.image.load('image;).convert_alpha()
elif times < 120:
hero = pygame.image.load('image;).convert_alpha()
elif times < 140:
times = 0
if inp_flag == 2: #left
times2 += 2
if times2 < 20:
hero = pygame.image.load('image;).convert_alpha()
hero = (hero, True, False)
elif times2 < 20:
hero = pygame.image.load('images/PTModelSprite_ID34257..png').convert_alpha()
hero = (hero, True, False)
elif times2 < 40:
hero = pygame.image.load('image;).convert_alpha()
hero = (hero, True, False)
elif times2 < 60:
hero = pygame.image.load('image;).convert_alpha()
hero = (hero, True, False)
elif times2 < 80:
hero = pygame.image.load('image;).convert_alpha()
hero = (hero, True, False)
elif times2 < 100:
hero = pygame.image.load('image;).convert_alpha()
hero = (hero, True, False)
elif times2 < 120:
hero = pygame.image.load('image;).convert_alpha()
hero = (hero, True, False)
elif times2 < 140:
times2 = 0
elif inp_flag == -1:
hero = pygame.image.load('image;).convert_alpha()
hero = (hero, True, False)
times2 = 0
elif inp_flag == -2:
hero = pygame.image.load('image;).convert_alpha()
times2 = 0
return times,times2,inp_flag,hero
def HeroHeightIs(): #判斷角色是否為地面y軸
if y >= HEIGHT-200:
return False
else:#這是在控制的狀況
return True
def Reset_max_point(jump_max_point):#在地面重設(shè)默認(rèn)跳躍的最高點(diǎn)(還原)
if y >= (HEIGHT-200):
jump_max_point = 50 #默認(rèn)最高點(diǎn)是 50
return jump_max_point
def jump_leftScreenBgnotMove(x):
if x<(WIDTH/4):
if jump_max_point == 50 :
if inp_flag == 1:
x+=)
if inp_flag == 2:
x-=)
elif jump_max_point == 100 :
if inp_flag == 1:
x+=)
if inp_flag == 2:
x-=)
return x
def Screen_MoneyIc(screen,money_ic5,money_ic6,money_ic7,money_ic8,money_timers) : #繪制第二項(xiàng) 金錢圖標(biāo)
money_timers += 1
if money_timers < 15 :
(money_ic5,(WIDTH*0.24,25)) #繪制第二項(xiàng) 金錢圖標(biāo)1
elif money_timers < 40 :
(money_ic6,(WIDTH*0.24+7.5,25)) #繪制第二項(xiàng) 金錢圖標(biāo)2
elif money_timers < 55 :
(money_ic7,(WIDTH*0.24,25)) #繪制第二項(xiàng) 金錢圖標(biāo)3
elif money_timers < 80 :
(money_ic8,(WIDTH*0.24,25)) #繪制第二項(xiàng) 金錢圖標(biāo)4
else:
money_timers = 0
return screen,money_ic5,money_ic6,money_ic7,money_ic8,money_timers
def Game_Timers(TimersSec,Gdata,time_passed,tim_psd) : #游戲定時(shí)器
tim_psd += time_passed
if tim_psd >= 1000 : #為1秒的時(shí)候
TimersSec += 1
tim_psd = 0
Gdata[3] = 400 - TimersSec #游戲所剩時(shí)間
return TimersSec,Gdata,time_passed,tim_psd
while True:
#事件檢測(cè)
for event in ():
if event.type == :
exit()
if event.type == KEYDOWN:
keys=()
if keys[]:
if event.key == K_w and inp_flag == 0:
if y <= HEIGHT-200: #看y坐標(biāo) 必須在起點(diǎn)
jump_flag = 3 #按了上 和 向前
if y >= HEIGHT-200:#如果角色在平地才走動(dòng) 后退 左
#if bg_w_1==0:
#x-=5
x-=(move_values+3.5)
inp_flag = 2
if keys[]:
if event.key == K_w and inp_flag == 0:
if y <= HEIGHT-200: #看y坐標(biāo) 必須在起點(diǎn)
jump_flag = 2 #按了上 和 向前
if y >= HEIGHT-200:#如果角色在平地才走動(dòng) 前景 右
if x<(WIDTH/4): #角色還在屏幕左邊 可移動(dòng)
x+=(move_values+3.5)
inp_flag = 1
if keys[]: #jump
jump_flag = 1 #僅僅是按了跳躍
jump_adder += 1 #跳躍累加器
if event.key == and (jump_flag == 1):
if y == HEIGHT-200: #看y坐標(biāo) 必須在起點(diǎn)
jump_flag = 2 #按了上 和 向前
if event.key == and (jump_flag == 1):
if y == HEIGHT-200: #看y坐標(biāo) 必須在起點(diǎn)
jump_flag = 3 #按了上 和 向后
if keys[]: #重啟
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,
move_values,jump_values,jump_values2,jump_values3,jump_adder,jump_max_point,jump_flag,bg_w_1,
bg_w_2,tim_psd)
if event.type == KEYUP:
if keys[]:
inp_flag = -1
if keys[]:
inp_flag = -2
if keys[]:
if jump_adder < 4 : #如果松開按鍵沒有達(dá)到j(luò)ump_adder跳躍累加器的值 (那么就他們置零)
jump_adder = 0
##在地面時(shí) 重設(shè)默認(rèn)跳躍的最高點(diǎn)(還原)
jump_max_point = Reset_max_point(jump_max_point)
#jump action 1
if jump_flag == 1: #只有跳躍
#讓其他方式跳躍值為 0
jump_values2 = 0
jump_values3 = 0
#------
#持續(xù)按鍵跳躍的結(jié)構(gòu)
if jump_adder >=4 :
jump_max_point = 100#第二次跳躍最大值
jump_adder = 0
#------
jump_values+=1.25
if jump_values <= jump_max_point:
y -= 5
x = jump_leftScreenBgnotMove(x)
if jump_max_point == 100:#跳躍的高度不同 y坐標(biāo)的速度也要慢點(diǎn)
y += 1.5
x = jump_leftScreenBgnotMove(x)
elif jump_values <= jump_max_point+8:
pass
elif jump_values <=jump_max_point*2+8:
if HeroHeightIs(): #如果角色在控制 就繼續(xù)加y軸的值 1
y += 5
x = jump_leftScreenBgnotMove(x)
if jump_max_point == 100:#跳躍的高度不同 y坐標(biāo)的速度也要慢點(diǎn)
y -= 1.5
x = jump_leftScreenBgnotMove(x)
else:
y = HEIGHT-200
jump_flag = 0
jump_values = 0
#wall detection
if x<=0:
x=0
if x+()>WIDTH:
x=WIDTH-()
#角色的動(dòng)作 函數(shù)
times,times2,inp_flag,hero = WalkAction(times,times2,inp_flag,hero)
#1 .bg move---blit
(background,(bg_w_2,0))
(background,(bg_w_1,0))
#繪制信息
(mario_name,(WIDTH*0.03,3))#繪制第一項(xiàng) 名字
screen,money_ic5,money_ic6,money_ic7,money_ic8,money_timers =
Screen_MoneyIc(screen,money_ic5,money_ic6,money_ic7,money_ic8,money_timers) #繪制第二項(xiàng) 金錢圖標(biāo)
(Game_moneyX,(WIDTH*0.28,24))#繪制第二項(xiàng) x
(Game_world,(WIDTH*0.5-Game_world.get_width()/2,3))#繪制第三項(xiàng) 世界地圖
(Game_time,(WIDTH*0.84,3))#繪制第四項(xiàng) 游戲時(shí)間
for DATAi in range(4):
Game_data = mario("%s"% Gdata[DATAi],True,(255,255,128),None) #綜合繪制: 分?jǐn)?shù) 金幣 關(guān)卡 游戲時(shí)間
if DATAi != 2:
(Game_data,(WIDTH**0.27),24))
elif DATAi == 2:
Game_data = mario("%s-%s"% (Gdata[DATAi]/10,Gdata[DATAi]%10),True,(255,255,128),None) #綜合繪制: 分?jǐn)?shù) 金幣 關(guān)卡 游戲時(shí)間
(Game_data,(WIDTH*0.5-Game_da()/2,15))
#繪制信息
#2 .bg move--panel
#if inp_flag == 2: #往左走 壁紙向右拖動(dòng)
#bg_w_1+=move_values/4
#bg_w_2+=move_values/4
if inp_flag == 1 and x>=(WIDTH/4):#往右走 壁紙向左拖動(dòng)
bg_w_1-=(move_value)
bg_w_2-=(m#!/usr/bin/env python
# -*- coding:utf-8 -*-
import pygame,os,wx
from random import randint
from sys import exit
from import *
()
def main():
#獲取屏幕大小
app=wx.App()
WHFRAMES=wx.DisplaySize()
WIDTH=int(WHFRAMES[0]*0.7)
HEIGHT=int(WHFRAMES[1]*0.8)
Timers = 0 #游戲定時(shí)器
TimersSec = 0 #秒
tim_psd = 0
#獲取屏幕大小
screen=((WIDTH,HEIGHT),0,32)
caption=("超級(jí)馬里奧")
([255,255,255])
mariofont = ('fon;,22)
mario_name = mario("MARIO",True,(84,65,190),None)
#Game_world = mario("WORLD",True,(84,65,190),None)
Game_moneyX = mario("X",True,(255,255,128),None)
Game_time = mario("TIME",True,(84,65,190),None)
money_ic5 = pygame.image.load('image;)
money_ic5 = (money_ic5, (25, 25))
money_ic6 = pygame.image.load('image;)
money_ic6 = (money_ic6, (10, 25))
money_ic7 = pygame.image.load('image;)
money_ic7 = (money_ic7, (25, 25))
money_ic8 = pygame.image.load('image;)
money_ic8 = (money_ic8, (25, 25))
money_timers = 0 #圖片輪播定時(shí)器
Game_world = pygame.image.load('image;)
background = pygame.image.load('image;).convert_alpha()
background = (background, (WIDTH, HEIGHT))
Roads = pygame.image.load('image;).convert_alpha()
Roads2 = pygame.image.load('image;).convert_alpha()
hero = pygame.image.load('image;).convert_alpha()
x,y = 15,HEIGHT-200
inp_flag = -2 #(stop:-1 left drection ,-2 right drection) ,(walk:1 right drection ,2 left drection)
times,times2 = 0,0 #人物動(dòng)作定時(shí)器
move_values,jump_values,jump_values2,jump_values3 = 12,0,0,0 #一步移動(dòng)的距離 和 跳躍的值1,2
jump_adder,jump_max_point = 0,50 #跳躍累加器 用來累加按鍵的長(zhǎng)短 然后判斷跳躍的高度,跳躍的初始值最高點(diǎn)
jump_flag = 0
bg_w_1,bg_w_2 = 0,WIDTH-2 #兩張壁紙 一前一后循環(huán)拖動(dòng)的變量
#播放背景
#播放背景
#游戲信息數(shù)據(jù)定義
score = 0
money = 0
world = 11
time = 400
Gdata = [score,money,world,time]
#游戲信息數(shù)據(jù)定義
#初始化函數(shù)
def 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):#數(shù)據(jù)初始化
#游戲初始化數(shù)據(jù)
inp_flag = -2 #(stop:-1 left drection ,-2 right drection) ,(walk:1 right drection ,2 left drection)
x,y = 15,HEIGHT-200 #馬里奧坐標(biāo)
times,times2 = 0,0 #人物動(dòng)作定時(shí)器
move_values,jump_values,jump_values2,jump_values3 = 12,0,0,0 #一步移動(dòng)的距離 和 跳躍的值1,2
jump_adder,jump_max_point = 0,50 #跳躍累加器 用來累加按鍵的長(zhǎng)短 然后判斷跳躍的高度,跳躍的初始值最高點(diǎn)
jump_flag = 0
tim_psd = 0
bg_w_1,bg_w_2 = 0,WIDTH-2 #兩張壁紙 一前一后循環(huán)拖動(dòng)的變量
Timers = 0 #游戲定時(shí)器
score = 0 #開始分?jǐn)?shù)
money = 0 #開始金錢
world = 11 #世界關(guān)卡第一關(guān)1-1 = 11
time = 400#游戲總時(shí)間
TimersSec = 0 #游戲里的秒
Gdata = [score,money,world,time]
#游戲初始化數(shù)據(jù)
return 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
#初始化函數(shù)
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,move_values,jump_values,jump_values2,jump_values3,jump_adder,jump_max_point,jump_flag,bg_w_1,bg_w_2,tim_psd)#數(shù)據(jù)初始化主調(diào)函數(shù)
clock = ()
(55)
()
def WalkAction(times,times2,inp_flag,hero):
#walk action
if y < HEIGHT -200: #如果在空中 為跳躍圖片
if inp_flag == 1: #right
hero = pygame.image.load('image;).convert_alpha()
if inp_flag == 2: #left
hero = pygame.image.load('image;).convert_alpha()
hero = (hero, True, False)
else:
if inp_flag == 1: #right
times += 2
if times < 20:
hero = pygame.image.load('image;).convert_alpha()
elif times < 20:
hero = pygame.image.load('images/PTModelSprite_ID34257..png').convert_alpha()
elif times < 40:
hero = pygame.image.load('image;).convert_alpha()
elif times < 60:
hero = pygame.image.load('image;).convert_alpha()
elif times < 80:
hero = pygame.image.load('image;).convert_alpha()
elif times < 100:
hero = pygame.image.load('image;).convert_alpha()
elif times < 120:
hero = pygame.image.load('image;).convert_alpha()
elif times < 140:
times = 0
if inp_flag == 2: #left
times2 += 2
if times2 < 20:
hero = pygame.image.load('image;).convert_alpha()
hero = (hero, True, False)
elif times2 < 20:
hero = pygame.image.load('images/PTModelSprite_ID34257..png').convert_alpha()
hero = (hero, True, False)
elif times2 < 40:
hero = pygame.image.load('image;).convert_alpha()
hero = (hero, True, False)
elif times2 < 60:
hero = pygame.image.load('image;).convert_alpha()
hero = (hero, True, False)
elif times2 < 80:
hero = pygame.image.load('image;).convert_alpha()
hero = (hero, True, False)
elif times2 < 100:
hero = pygame.image.load('image;).convert_alpha()
hero = (hero, True, False)
elif times2 < 120:
hero = pygame.image.load('image;).convert_alpha()
hero = (hero, True, False)
elif times2 < 140:
times2 = 0
elif inp_flag == -1:
hero = pygame.image.load('image;).convert_alpha()
hero = (hero, True, False)
times2 = 0
elif inp_flag == -2:
hero = pygame.image.load('image;).convert_alpha()
times2 = 0
return times,times2,inp_flag,hero
def HeroHeightIs(): #判斷角色是否為地面y軸
if y >= HEIGHT-200:
return False
else:#這是在控制的狀況
return True
def Reset_max_point(jump_max_point):#在地面重設(shè)默認(rèn)跳躍的最高點(diǎn)(還原)
if y >= (HEIGHT-200):
jump_max_point = 50 #默認(rèn)最高點(diǎn)是 50
return jump_max_point
def jump_leftScreenBgnotMove(x):
if x<(WIDTH/4):
if jump_max_point == 50 :
if inp_flag == 1:
x+=)
if inp_flag == 2:
x-=)
elif jump_max_point == 100 :
if inp_flag == 1:
x+=)
if inp_flag == 2:
x-=)
return x
def Screen_MoneyIc(screen,money_ic5,money_ic6,money_ic7,money_ic8,money_timers) : #繪制第二項(xiàng) 金錢圖標(biāo)
money_timers += 1
if money_timers < 15 :
(money_ic5,(WIDTH*0.24,25)) #繪制第二項(xiàng) 金錢圖標(biāo)1
elif money_timers < 40 :
(money_ic6,(WIDTH*0.24+7.5,25)) #繪制第二項(xiàng) 金錢圖標(biāo)2
elif money_timers < 55 :
(money_ic7,(WIDTH*0.24,25)) #繪制第二項(xiàng) 金錢圖標(biāo)3
elif money_timers < 80 :
(money_ic8,(WIDTH*0.24,25)) #繪制第二項(xiàng) 金錢圖標(biāo)4
else:
money_timers = 0
return screen,money_ic5,money_ic6,money_ic7,money_ic8,money_timers
def Game_Timers(TimersSec,Gdata,time_passed,tim_psd) : #游戲定時(shí)器
tim_psd += time_passed
if tim_psd >= 1000 : #為1秒的時(shí)候
TimersSec += 1
tim_psd = 0
Gdata[3] = 400 - TimersSec #游戲所剩時(shí)間
return TimersSec,Gdata,time_passed,tim_psd
while True:
#事件檢測(cè)
for event in ():
if event.type == :
exit()
if event.type == KEYDOWN:
keys=()
if keys[]:
if event.key == K_w and inp_flag == 0:
if y <= HEIGHT-200: #看y坐標(biāo) 必須在起點(diǎn)
jump_flag = 3 #按了上 和 向前
if y >= HEIGHT-200:#如果角色在平地才走動(dòng) 后退 左
#if bg_w_1==0:
#x-=5
x-=(move_values+3.5)
inp_flag = 2
if keys[]:
if event.key == K_w and inp_flag == 0:
if y <= HEIGHT-200: #看y坐標(biāo) 必須在起點(diǎn)
jump_flag = 2 #按了上 和 向前
if y >= HEIGHT-200:#如果角色在平地才走動(dòng) 前景 右
if x<(WIDTH/4): #角色還在屏幕左邊 可移動(dòng)
x+=(move_values+3.5)
inp_flag = 1
if keys[]: #jump
jump_flag = 1 #僅僅是按了跳躍
jump_adder += 1 #跳躍累加器
if event.key == and (jump_flag == 1):
if y == HEIGHT-200: #看y坐標(biāo) 必須在起點(diǎn)
jump_flag = 2 #按了上 和 向前
if event.key == and (jump_flag == 1):
if y == HEIGHT-200: #看y坐標(biāo) 必須在起點(diǎn)
jump_flag = 3 #按了上 和 向后
if keys[]: #重啟
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,
move_values,jump_values,jump_values2,jump_values3,jump_adder,jump_max_point,jump_flag,bg_w_1,
bg_w_2,tim_psd)
if event.type == KEYUP:
if keys[]:
inp_flag = -1
if keys[]:
inp_flag = -2
if keys[]:
if jump_adder < 4 : #如果松開按鍵沒有達(dá)到j(luò)ump_adder跳躍累加器的值 (那么就他們置零)
jump_adder = 0
##在地面時(shí) 重設(shè)默認(rèn)跳躍的最高點(diǎn)(還原)
jump_max_point = Reset_max_point(jump_max_point)
#jump action 1
if jump_flag == 1: #只有跳躍
#讓其他方式跳躍值為 0
jump_values2 = 0
jump_values3 = 0
#------
#持續(xù)按鍵跳躍的結(jié)構(gòu)
if jump_adder >=4 :
jump_max_point = 100#第二次跳躍最大值
jump_adder = 0
#------
jump_values+=1.25
if jump_values <= jump_max_point:
y -= 5
x = jump_leftScreenBgnotMove(x)
if jump_max_point == 100:#跳躍的高度不同 y坐標(biāo)的速度也要慢點(diǎn)
y += 1.5
x = jump_leftScreenBgnotMove(x)
elif jump_values <= jump_max_point+8:
pass
elif jump_values <=jump_max_point*2+8:
if HeroHeightIs(): #如果角色在控制 就繼續(xù)加y軸的值 1
y += 5
x = jump_leftScreenBgnotMove(x)
if jump_max_point == 100:#跳躍的高度不同 y坐標(biāo)的速度也要慢點(diǎn)
y -= 1.5
x = jump_leftScreenBgnotMove(x)
else:
y = HEIGHT-200
jump_flag = 0
jump_values = 0
#wall detection
if x<=0:
x=0
if x+()>WIDTH:
x=WIDTH-()
#角色的動(dòng)作 函數(shù)
times,times2,inp_flag,hero = WalkAction(times,times2,inp_flag,hero)
#1 .bg move---blit
(background,(bg_w_2,0))
(background,(bg_w_1,0))
#繪制信息
(mario_name,(WIDTH*0.03,3))#繪制第一項(xiàng) 名字
screen,money_ic5,money_ic6,money_ic7,money_ic8,money_timers =
Screen_MoneyIc(screen,money_ic5,money_ic6,money_ic7,money_ic8,money_timers) #繪制第二項(xiàng) 金錢圖標(biāo)
(Game_moneyX,(WIDTH*0.28,24))#繪制第二項(xiàng) x
(Game_world,(WIDTH*0.5-Game_world.get_width()/2,3))#繪制第三項(xiàng) 世界地圖
(Game_time,(WIDTH*0.84,3))#繪制第四項(xiàng) 游戲時(shí)間
for DATAi in range(4):
Game_data = mario("%s"% Gdata[DATAi],True,(255,255,128),None) #綜合繪制: 分?jǐn)?shù) 金幣 關(guān)卡 游戲時(shí)間
if DATAi != 2:
(Game_data,(WIDTH**0.27),24))
elif DATAi == 2:
Game_data = mario("%s-%s"% (Gdata[DATAi]/10,Gdata[DATAi]%10),True,(255,255,128),None) #綜合繪制: 分?jǐn)?shù) 金幣 關(guān)卡 游戲時(shí)間
(Game_data,(WIDTH*0.5-Game_da()/2,15))
#繪制信息
#2 .bg move--panel
#if inp_flag == 2: #往左走 壁紙向右拖動(dòng)
#bg_w_1+=move_values/4
#bg_w_2+=move_values/4
if inp_flag == 1 and x>=(WIDTH/4):#往右走 壁紙向左拖動(dòng)
bg_w_1-=(move_value)
bg_w_2-=(move_value)
if bg_w_1>=0:
bg_w_1,bg_w_2 = 0,WIDTH-2
if bg_w_1<-WIDTH:
bg_w_1,bg_w_2 = 0,WIDTH-2
(hero,(x,y))
(2) #毫秒
time_passed = clock.tick()
TimersSec,Gdata,time_passed,tim_psd = Game_Timers(TimersSec,Gdata,time_passed,tim_psd) #游戲定時(shí)
()
if __name__ == '__main__':
main()ove_value)
if bg_w_1>=0:
bg_w_1,bg_w_2 = 0,WIDTH-2
if bg_w_1<-WIDTH:
bg_w_1,bg_w_2 = 0,WIDTH-2
(hero,(x,y))
(2) #毫秒
time_passed = clock.tick()
TimersSec,Gdata,time_passed,tim_psd = Game_Timers(TimersSec,Gdata,time_passed,tim_psd) #游戲定時(shí)
()
if __name__ == '__main__':
main()
1.《關(guān)于超級(jí)瑪麗84怎么過技巧,你需要知道這些Python做超級(jí)瑪麗》援引自互聯(lián)網(wǎng),旨在傳遞更多網(wǎng)絡(luò)信息知識(shí),僅代表作者本人觀點(diǎn),與本網(wǎng)站無關(guān),侵刪請(qǐng)聯(lián)系頁(yè)腳下方聯(lián)系方式。
2.《關(guān)于超級(jí)瑪麗84怎么過技巧,你需要知道這些Python做超級(jí)瑪麗》僅供讀者參考,本網(wǎng)站未對(duì)該內(nèi)容進(jìn)行證實(shí),對(duì)其原創(chuàng)性、真實(shí)性、完整性、及時(shí)性不作任何保證。
3.文章轉(zhuǎn)載時(shí)請(qǐng)保留本站內(nèi)容來源地址,http://f99ss.com/gl/3203596.html