import pgzrun
import environment as ev
from model import *
import random
import ybc_box as box
mobile_key_type
fire_cd_time = 0.3
knife_cd = 0.1
knife_hurt = 0.4
live = 5
score = 0
#设置宽高a
WIDTH = 1000
HEIGHT = 500
#设置速度
#能否行动
ifup = True
ifdown = True
ifleft = True
ifright = True
#角色
chara = ""
if_show_name = False
speed = 7.6
speed = 13
kspeed = 1.3
#状态
state = "ready"
#state = "start"
place = "none"
#获取图片及其坐标
nowlist = []
blist = ev.begin() #开始界面
rlist = ev.rule() #规则界面
flone = ev.flone() #第一层
flone_room1 = ev.flone_room1() #101
flone_room2 = ev.flone_room2()#102
fltwo = ev.fltwo()#第二层
fltwo_room1 = ev.fltwo_room1()#阅览室
fltwo_st = ev.fltwo_st()#二楼走廊
fltwo_room2 = ev.fltwo_room2()
fltwo_room3 = ev.fltwo_room3()
flthree_hall = ev.flthree_hall()
flthree_st = ev.flthree_st()
flthree_room1 = ev.flthree_room1()
flthree_room2 = ev.flthree_room2()
flthree_room3 = ev.flthree_room3()
flthree = ev.flthree()
flfour = ev.flfour()
flfour_room1 = ev.flfour_room1()
flfour_room2 = ev.flfour_room2()
flfour_st = ev.flfour_st()
flfour_room3 = ev.flfour_room3()
flfour_room4 = ev.flfour_room4()
dark_room = ev.dark_room()
END = ev.END()
placedata = {"flone":[flone.flo,flone.place,flone.chara],
"flone_room1":[flone_room1.flo_r1,flone_room1.place,flone_room1.chara],
"flone_room2":[flone_room2.flo_r2,flone_room2.place,flone_room2.chara],
"fltwo":[fltwo.flt,fltwo.place,fltwo.chara],
"fltwo_room1":[fltwo_room1.flt_r1,fltwo_room1.place,fltwo_room1.chara],
"fltwo_st":[fltwo_st.flt_st,fltwo_st.place,fltwo_st.chara],
"fltwo_room2":[fltwo_room2.flt_r2,fltwo_room2.place,fltwo_room2.chara],
"fltwo_room3":[fltwo_room3.flt_r3,fltwo_room3.place,fltwo_room3.chara],
"flthree_hall":[flthree_hall.flt_hall,flthree_hall.place,flthree_hall.chara],
"flthree_st":[flthree_st.flh_st,flthree_st.place,flthree_st.chara],
"flthree_room1":[flthree_room1.flh_r1,flthree_room1.place,flthree_room1.chara],
"flthree_room2":[flthree_room2.flh_r2,flthree_room2.place,flthree_room2.chara],
"flthree_room3":[flthree_room3.flh_r3,flthree_room3.place,flthree_room3.chara],
"flthree":[flthree.flh,flthree.place,flthree.chara],
"flfour":[flfour.flu,flfour.place,flfour.chara],
"flfour_room1":[flfour_room1.flu_r1,flfour_room1.place,flfour_room1.chara],
"flfour_room2":[flfour_room2.flu_r2,flfour_room2.place,flfour_room2.chara],
"flfour_st":[flfour_st.flu_st,flfour_st.place,flfour_st.chara],
"flfour_room4":[flfour_room4.flu_r4,flfour_room4.place,flfour_room4.chara],
"flfour_room3":[flfour_room3.flu_r3,flfour_room3.place,flfour_room3.chara],
"END":[END.en,END.place,END.chara],
"dark_room":[dark_room.dk_room,dark_room.place,dark_room.chara]
}
ifpas = False
#玩家装备
player_p = {}
player_l = []
i_p_pos = {1:[75,190],2:[75,215],3:[75,240],4:[75,265],5:[75,290],6:[75,315],7:[75,350],8:[75,375],9:[75,400]}
p_hold_now = ""
p_hold_num = 1
wave = Actor("../images1/wave.png",[10000,10000])
book = Actor("../images1/book.png",[10000,10000])
mouse_pos = []
ifcd = True
fu = False
didit = False
ifwave = False
i_choice = Actor("../images1/choose.png",[30,200])
i_c_pos = {1:[30,200],2:[30,225],3:[30,250],4:[30,275],5:[30,300],6:[30,325],7:[30,360],8:[30,385],9:[30,410]}
i_star = Actor("../images1/star.png",[30,200])
tj = Actor("../images1/图鉴.png",[1000,1000])
s_tj = Actor("return_button.png",[1000,1000])
ifstj = False
iftj = False
player_n = 1
fire_lst = []
prev_chara_pos=0
intell = True
iffire = False
ifcoll = False
def i_wave():
global ifwave
ifwave = False
def fire(pos1,pos2):
global fire_lst,iffire
special = None
fff = Actor('fire.png',pos1)
fire_lst.append(fff)
if pos1[0] != pos2[0] and pos1[1] != pos2[1]:
k = f(pos1,pos2)[0]
b = f(pos1,pos2)[1]
if pos2[0] > pos1[0]:
f_speed = speed_pay(k)
elif pos2[0] < pos1[0]:
f_speed = -1 * speed_pay(k)
fff.k = k
fff.b = b
special = 1
elif pos1[0] == pos2[0] and pos1[1] != pos2[1]:
if pos1[1] < pos2[1]:
f_speed = 8
elif pos1[1] > pos2[1]:
f_speed = -8
special = 2
elif pos1[1] == pos2[1] and pos1[0] != pos2[0]:
if pos1[0] < pos2[0]:
f_speed = 8
elif pos1[0] > pos2[0]:
f_speed = -8
special = 3
else:
print("你自尽了")
exit()
fff.speed = f_speed
return special
def cool_down():
global ifcd
ifcd = True
#绘制
def draw():
global posy,nowlist
book.draw()
s_tj.draw()
if state == "ready": #绘制开始界面
for b in blist:
b.draw()
elif state == "rule": #绘制规则界面
for r in rlist:
r.draw()
if state == "start":
nowlist = placedata[place][0]
for f in placedata[place][0]:
if f.image == "right.png" or f.image == "left.png":
wave.draw()
f.draw()
if place != "flfour_room4" and place != "flthree_room3" and place != "dark_room":
screen.draw.text(placedata[place][1],[90, 460],fontsize=20)
elif place == "flfour_room4":
screen.draw.text("初三十班",[90, 460],fontsize=20)
screen.draw.text("发现彩蛋屋 初三十班!",[370, 220],fontsize=30,color="blue")
elif place == "flthree_room3" or place == "dark_room":
screen.draw.text("小心!这里是试炼屋!",[470, 140],fontsize=23,color="blue")
#绘制玩家信息
screen.draw.text(player_name,pos = [70, 20],fontsize=20)
if if_show_name:
screen.draw.text(player_name,pos = [chara.pos[0]-20, chara.pos[1]-35],fontsize=10,color="black")
screen.draw.text("得分:"+str(score),pos = [20, 70],fontsize=16)
if live >= 3:
screen.draw.text(str(live)+"/5",pos = [70,95],fontsize=17)
else:
screen.draw.text(str(live)+"/5",pos = [70,95],fontsize=17,color="red")
if len(player_l) != 0:
for i in player_l:
screen.draw.text(i+"x"+str(player_p[i]),pos=i_p_pos[search_l(player_l,i)+1],fontsize=14)
i_choice.draw()
if len(fire_lst) != 0:
for f in fire_lst:
f.draw()
if ifpas:
screen.draw.text("暂停 按“P”解除暂停",pos=[340, 205],fontsize=38,color="blue")
if state == "over":
screen.draw.text("探险失败 按“L”键退出 ",pos=[380, 210],fontsize=35,color="red")
tj.draw()
i_star.draw()
def update():
global state,place,prev_chara_pos,intell,if_show_name,chara,p_hold_now,fu,didit,ifstj,ifegg,ifdo
if place == "flfour_room4":
ifegg = True
if "重要文件" in player_p:
ifdo = True
if place == "END":
state = "WIN"
exit()
if len(nowlist) != 0:
for ae in nowlist:
if ae.image == "wall.png" or ae.image == "wall1.png":
ae.ifdoor = False
if place == "flfour_st" and ae.pos == [563.0, 220.0]:
ae.ifdoor = True
if live <= 0:
chara.image = "../images1/die.png"
state = "over"
if ifstj:
tj.pos = [967.0, 30.0]
if state == "图鉴":
book.pos = [500,250]
s_tj.pos = [949.0, 48.0]
else:
book.pos = [1000,1000]
s_tj.pos = [1000,1000]
if chara != "":
if_show_name = True
else:
if_show_name = False
if state == "exit": #开始界面点击退出
exit()
elif state == "start" and intell: #开始界面点击开始
place = "flone"
intell = False
if state == "start":
ifstj = True
p_hold_now = check_l(player_l,p_hold_num)
if iffire:
if pd == 1:
for fb in fire_lst:
fb.x += fb.speed
fb.y = fb.x * fb.k + fb.b
if pd == 2:
for fb in fire_lst:
fb.y += fb.speed
if pd == 3:
for fb in fire_lst:
fb.x += fb.speed
if ifwave:
wave.pos = chara.pos
clock.schedule(i_wave,knife_cd)
else:
wave.pos = [10000,100000]
if len(nowlist) > 0:
for ee in nowlist:
if chara.image != "../images1/die.png":
if ee.sx == "monster":
if ee.x < chara.x:
ee.x += ee.speed + kspeed
if ee.x > chara.x:
ee.x -= ee.speed + kspeed
if ee.y < chara.y:
ee.y += ee.speed + kspeed
if ee.y > chara.y:
ee.y -= ee.speed + kspeed
if didit:
if ee.ifhurt == False:
clock.schedule(cool_hurt,3)
if fu:
ee.ifhurt = True
didit = False
fu = False
ee.ifhurt = False
chara = placedata[place][2] #获取角色
# 每次更新前保存角色的上一个位置
coll(chara, prev_chara_pos, chara.pos, placedata[place][0]) #一楼大厅碰撞
prev_chara_pos = chara.pos
else:
ifstj = False
tj.pos = [1000,1000]
if state == "start":
if keyboard.K_A and ifleft: #控制角色移动
chara.x -= speed
chara.image = "left.png"
if keyboard.K_D and ifright:
chara.x += speed
chara.image = "right.png"
if keyboard.K_W and ifup:
chara.y -= speed
if chara.image == "../images1/die.png":
chara.image = "right.png"
if keyboard.K_S and ifdown:
chara.y += speed
if chara.image == "../images1/die.png":
chara.image = "right.png"
def on_mouse_move(pos):
global i_star
if state == "start":
i_star.pos = pos
if state == "ready": #开始界面鼠标移动效果
for j in blist:
if j.collidepoint(pos):
if j.image == "begin_button.png":
j.image = "begin_button1.png"
elif j.image == "rule_button.png":
j.image = "rule_button1.png"
elif j.image == "exit_button.png":
j.image = "exit_button1.png"
else:
if j.image == "begin_button1.png":
j.image = "begin_button.png"
elif j.image == "rule_button1.png":
j.image = "rule_button.png"
elif j.image == "exit_button1.png":
j.image = "exit_button.png"
def on_mouse_down(pos,button):
global state,player_p,mouse_pos,iffire,pd,ifcd,ifwave,kn
mouse_pos = pos
if tj.collidepoint(pos):
state = "图鉴"
if state == "ready": #开始界面的跳转页面
if button == mouse.LEFT:
for b in blist:
if b.collidepoint(pos) and b.image != "hall.png":
state = b.sx
elif state == "rule": #规则界面的跳转页面
if button == mouse.LEFT:
for r in rlist:
if r.collidepoint(pos) and r.image != "rule_text.png":
state = "ready"
if state == "start":
i_star.pos = pos
if p_hold_now == "手枪" and button == mouse.LEFT and chara.image !='../images1/die.png':
if "手枪子弹" in player_p:
if player_p["手枪子弹"] > 0 and ifcd:
iffire = True
pd = fire(chara.pos,pos)
player_p["手枪子弹"] -= 1
ifcd = False
clock.schedule(cool_down,fire_cd_time)
elif p_hold_now == "匕首" and button == mouse.LEFT and chara.image != "../images1/die.png":
ifwave = True
if s_tj.collidepoint(pos):
state = "start"
def cool_hurt():
global fu
fu = True
#碰撞检测
def coll(chara, prev_pos, current_pos, lst):
global ifup, ifdown, ifright, ifleft,place,score,player_p,player_l,fire_lst,live,ifcoll,fu,didit,ifdie,kn
for i in lst:
if i.sx == "monster" and wave.colliderect(i):
if i.blood <= 0:
i.image = "../images1/life.png"
i.sx = "life"
i.cet = True
i.show = "生命结晶"
kn += 1
else:
i.blood -= knife_hurt
if len(fire_lst) != 0:
for em in fire_lst:
if em.colliderect(i) and i.sx != "bg" and i.sx != "right" and i.cet == False:
if i.sx == "monster":
i.blood -= 1
if i.blood < 1:
i.image = "../images1/life.png"
i.sx = "life"
i.cet = True
i.show = "生命结晶"
kn += 1
elif i.sx == "药瓶":
lst.remove(i)
fire_lst.remove(em)
if i.sx == "monster":
if i.colliderect(chara):
if wave.x > 900:
if i.ifhurt:
i.ifhurt = False
live -= 1
didit = True
i.ifhurt = False
else:
i.ifhurt = True
fu = False
if chara.colliderect(i):
if i.cet:
if i.show not in player_p:
player_p[i.show] = 1
player_l.append(i.show)
else:
player_p[i.show] += 1
if i.sx == "wall" or i.sx == "wall1":
if i.ifdoor == False:
chara.pos = prev_pos
else:
if i.change == "x":
chara.x += i.s
else:
chara.y += i.s
place = i.toward
fire_lst.clear()
if i.sx == "药瓶":
lst.remove(i)
score += 1
if i.sx == "door" or i.sx == "door1":
if i.change == "x":
chara.x += i.s
else:
chara.y += i.s
place = i.toward
fire_lst.clear()
if i.sx == "stairs_up" or i.sx == "stairs_down":
if i.change == "x":
chara.x += i.s
else:
chara.y += i.s
place = i.toward
fire_lst.clear()
if i.cet:
lst.remove(i)
def on_key_down():
global player_l,player_p,p_hold_num,state,live,ifpas,p,live,state,place
if keyboard.K_P:
if state == "暂停":
state = "start"
ifpas = False
elif state == "start":
state = "暂停"
ifpas = True
if keyboard.K_L:
exit()
if state == "start":
# if keyboard.K_X:
# live = 0
if keyboard.K_1:
i_choice.pos = i_c_pos[1]
p_hold_num = 1
if keyboard.K_2:
i_choice.pos = i_c_pos[2]
p_hold_num = 2
if keyboard.K_3:
i_choice.pos = i_c_pos[3]
p_hold_num = 3
if keyboard.K_4:
i_choice.pos = i_c_pos[4]
p_hold_num = 4
if keyboard.K_5:
i_choice.pos = i_c_pos[5]
p_hold_num = 5
if keyboard.K_6:
i_choice.pos = i_c_pos[6]
p_hold_num = 6
if keyboard.K_7:
i_choice.pos = i_c_pos[7]
p_hold_num = 7
if keyboard.K_8:
i_choice.pos = i_c_pos[8]
p_hold_num = 8
if keyboard.K_9:
i_choice.pos = i_c_pos[9]
p_hold_num = 9
if keyboard.K_0:
print(p_hold_now)
# if keyboard.K_G:
# player_p["手枪子弹"] += 100
if keyboard.K_Z:
chara.image = "../images1/die.png"
if keyboard.K_E:
if p_hold_now == "医疗包" and player_p['医疗包']>0:
if live < 5:
live += 1
player_p['医疗包'] -= 1
#运行程序
pgzrun.go()
box.msgbox("“测验结束——”" + "\n" + "冰冷的提示音响起。你摘下头盔,走出了训练馆。" + "\n" + "“特工9号已经完成测试了。”观察员说道。" + "\n" + "“干的不错。”比你大一岁的师傅,宵后一说道,“不过不要骄傲,好好训练,这个场景可是特工1号在真实任务中用自带的扫描仪扫描下来的场景,完美还原,机会难得”" + "\n" + "“这是个什么学校,怎么这么危险?”你问道。" + "\n" + "“你以为我们想不知道吗?”上司谢飞没好气的说道。这几天他遇到了不少问题,特工1号失联,怪物频繁出现让他焦头烂额。" + "\n" + "“不过我发现有点不对次,更新更多地图。彩蛋屋也会新增。" + "\n" + "反响好的话会出正式版" + "\n" + "下面给正式版画饼:" + "\n" + "1.加入更多道具" + "\n" + "2.加入剧情,音效" + "\n" + "3.加入更多模式(如生存模式、剧情模式、无限模式。当然如果真的做出来会花很久)" + "\n" + "注:代码作者手敲,图片自己绘制,没有工作室没有外包" + "\n" + "PS:王烁我是你粉丝!这个作品是受你鼓励完成的!")
else:
box.msgbox("回信须知:" + "\n" + "1.作者很少打开csdn,回信不及时请谅解。收到信后会回信" + "\n" + "2.有对正式版的建议或者想让作者下个项目做什么,欢迎写信。")
07-01
591
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-02
359
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交