用户:研X查看:0 回复:1 评论:0 创建时间:2023-01-17T13:09:33
【作品展示】

【作品介绍】
这是一款冒险游戏,但代码并不是很完整,以后我会继续更新的1:w上, a左, s下, d右
2:上, 左, 下, 右
每15秒会出一些小怪
【作品源代码】
import pgzrun
import pygame
import random
import time
b = Actor('背景')
bg = Actor("背景1")
bg.left = 0
w, h = b.size
WIDTH = w
HEIGHT = h
print(type(b))
dm = Actor('背景地面1')
dm.left = 0
dm.y = HEIGHT-75
aa = [Actor('阿短1'), Actor('阿短2'), Actor('阿短3'),
Actor('阿短4'), Actor('阿短5')]
aaa = [Actor('阿短1'), Actor('阿短2'), Actor('阿短3'),
Actor('阿短4'), Actor('阿短5')]
ab = [Actor('阿短1_2'), Actor('阿短2_2'), Actor('阿短3_2'),
Actor('阿短4_2'), Actor('阿短5_2')]
xa = [Actor('小可1'), Actor('小可2'), Actor('小可3'),
Actor('小可4'), Actor('小可5')]
xaa = [Actor('小可1'), Actor('小可2'), Actor('小可3'),
Actor('小可4'), Actor('小可5')]
xb = [Actor('小可1_2'), Actor('小可2_2'), Actor('小可3_2'),
Actor('小可4_2'), Actor('小可5_2')]
na = len(aa)
nx = len(xa)
asp = 0
ai = 0
xsp = 0
xi = 0
ax = 25
ay = 500
xx = 80
xy = 500
sj = 0
Cbmx = []
M = []
B = []
for j in range(3):
m = Actor('地面方块1')
m.x = (j+1)*500
m.y = 400
M.append(m)
for l in range(3):
bm = Actor('地面方块1')
bm.x = m.x + l*bm.width
bm.y = 400
B.append(bm)
Cbmx.append(bm.x)
cb = len(B)
cm = len(M)
C喵x = []
vine = []
for j in range(cm):
喵 = Actor("藤蔓1_1")
喵.x = M[j].x
喵.y = 400 + 110
vine.append(喵)
C喵x.append(喵.x)
cv = len(vine)
for j in range(na):
aa[j].x = ax
aa[j].y = ay
ab[j].x = ax
ab[j].y = ay
aaa[j].x = ax
aaa[j].y = ay
for j in range(nx):
xa[j].x = xx
xa[j].y = xy
xb[j].x = xx
xb[j].y = xy
xaa[j].x = xx
xaa[j].y = xy
def update():
global ax, ay, xx, xy, asp, ai, xsp, xi, na, nx, sj, cb, cv
f = False
l = False
csa = 0
csx = 0
if csa > 2:
f = False
csa = 0
if csx > 2:
l = False
csx = 0
if bg.left >= 0:
bg.left = 0
if bg.right <= WIDTH:
bg.right = WIDTH
if dm.left >= 0:
dm.left = 0
if dm.right <= WIDTH:
dm.right = WIDTH
for j in range(cb):
if B[j].x > Cbmx[j]:
B[j].x = Cbmx[j]
for j in range(cv):
if vine[j].x > C喵x[j]:
vine[j].x = C喵x[j]
if ax >= WIDTH-25:
ax = WIDTH-25
if ax <= 25:
ax = 25
if ay <= 40:
ay = 40
if xx >= WIDTH-25 :
xx = WIDTH-25
if xx <= 25:
xx = 25
if xy <= 40:
xy = 40
if keyboard.d and keyboard.right:
bg.x-= 0.5
for bm in B:
bm.x -= 0.5
dm.x -= 0.5
for 喵 in vine:
喵.x -= 0.5
ax -= 0.5
for j in range(na):
aa[j].x = ax
ab[j].x = ax
aaa[j].x = ax
xx -= 0.5
for j in range(na):
xa[j].x = xx
xb[j].x = xx
xaa[j].x = xx
if keyboard.a and keyboard.left:
bg.x += 0.5
for bm in B:
bm.x += 0.5
dm.x += 0.5
for 喵 in vine:
喵.x += 0.5
ax += 0.5
for j in range(na):
aa[j].x = ax
ab[j].x = ax
aaa[j].x = ax
xx += 0.5
for j in range(na):
xa[j].x = xx
xb[j].x = xx
xaa[j].x = xx
for bm in B:
for j in range(na):
if abs((aa[j] and ab[j] and aaa[j]).bottom-bm.top) <= 2 \
and bm.left-(aa[j] and ab[j] and aaa[j]).left < (aa[j] and ab[j] and aaa[j]).width*2/3 \
and (aa[j] and ab[j] and aaa[j]).right-bm.right < (aa[j] and ab[j] and aaa[j]).width*2/3:
f = True
if keyboard.s:
for 喵 in vine:
if abs((aa[j] and ab[j] and aaa[j]).bottom-喵.top) <= 10 \
and 喵.left-(aa[j] and ab[j] and aaa[j]).left < (aa[j] and ab[j] and aaa[j]).width*2/3 \
and (aa[j] and ab[j] and aaa[j]).right-喵.right < (aa[j] and ab[j] and aaa[j]).width*2/3:
ay += 5
if abs((aa[j] and ab[j] and aaa[j]).top-bm.bottom) <= 5 \
and (aa[j] and ab[j] and aaa[j]).left-bm.left < (aa[j] and ab[j] and aaa[j]).width*2/3 \
and bm.right-(aa[j] and ab[j] and aaa[j]).right < (aa[j] and ab[j] and aaa[j]).width*2/3:
(aa[j] and ab[j] and aaa[j]).top = bm.bottom
f = False
for j in range(nx):
if abs((xa[j] and xb[j] and xaa[j]).bottom-bm.top) <= 2 \
and bm.left-(xa[j] and xb[j] and xaa[j]).left < (xa[j] and xb[j] and xaa[j]).width*2/3 \
and (xa[j] and xb[j] and xaa[j]).right-bm.right < (xa[j] and xb[j] and xaa[j]).width*2/3:
l = True
if keyboard.down:
for 喵 in vine:
if abs((xa[j] and xb[j] and xaa[j]).bottom-喵.top) <= 10 \
and 喵.left-(xa[j] and xb[j] and xaa[j]).left < (xa[j] and xb[j] and xaa[j]).width*2/3 \
and (xa[j] and xb[j] and xaa[j]).right-喵.right < (xa[j] and xb[j] and xaa[j]).width*2/3:
xy += 5
if abs((xa[j] and xb[j] and xaa[j]).top-bm.bottom) <= 5 \
and (xa[j] and xb[j] and xaa[j]).left-bm.left < (xa[j] and xb[j] and xaa[j]).width*2/3 \
and bm.right-(xa[j] and xb[j] and xaa[j]).right < (xa[j] and xb[j] and xaa[j]).width*2/3:
(xa[j] and xb[j] and xaa[j]).top = bm.bottom
l = False
for j in range(na):
if abs(aa[j].bottom-dm.top) < 5 \
and dm.left-(aa[j] and ab[j] and aaa[j]).left < (aa[j] and ab[j] and aaa[j]).width*2/3 \
and (aa[j] and ab[j] and aaa[j]).right-dm.right < (aa[j] and ab[j] and aaa[j]).width*2/3:
f = True
for j in range(nx):
if abs(xa[j].bottom-dm.top) < 5 \
and dm.left-(xa[j] and xb[j] and xaa[j]).left < (xa[j] and xb[j] and xaa[j]).width*2/3 \
and (xa[j] and xb[j] and xaa[j]).right-dm.right < (xa[j] and xb[j] and xaa[j]).width*2/3:
l = True
if keyboard.d:
ax += 1
for j in range(na):
aa[j] = aaa[j]
aa[j].x = ax
ab[j].x = ax
aaa[j].x = ax
asp += 1
if asp % 10 == 0:
ai += 1
if ai >= na:
ai = 0
if keyboard.a:
ax -= 1
for j in range(na):
aa[j] = ab[j]
aa[j].x = ax
ab[j].x = ax
aaa[j].x = ax
asp += 1
if asp % 10 == 0:
ai += 1
if ai >= na:
ai = 0
if keyboard.w:
csa += 1
if csa <= 2:
f = True
ay -= 2.5
for j in range(na):
aa[j].y = ay
ab[j].y = ay
aaa[j].y = ay
for 喵 in vine:
for j in range(na):
if ay < 喵.bottom and ay > 喵.top and keyboard.w\
and (aa[j] and ab[j] and aaa[j]).left-喵.left < (aa[j] and ab[j] and aaa[j]).width*2/3 \
and 喵.right-(aa[j] and ab[j] and aaa[j]).right < (aa[j] and ab[j] and aaa[j]).width*2/3:
ay -= 2
f = True
aa[j].y = ay
ab[j].y = ay
aaa[j].y = ay
if keyboard.right:
xx += 1
for j in range(nx):
xa[j] = xaa[j]
xa[j].x = xx
xb[j].x = xx
xaa[j].x = xx
xsp += 1
if xsp % 10 == 0:
xi += 1
if xi >= nx:
xi = 0
if keyboard.left:
xx -= 1
for j in range(nx):
xa[j] = xb[j]
xa[j].x = xx
xb[j].x = xx
xaa[j].x = xx
xsp += 1
if xsp % 10 == 0:
xi += 1
if xi >= nx:
xi = 0
if keyboard.up:
csx += 1
if csx <= 2:
l = True
xy -= 2.5
for j in range(nx):
xa[j].y = xy
xb[j].y = xy
xaa[j].y = xy
break
for 喵 in vine:
for j in range(nx):
if xy < 喵.bottom and xy > 喵.top and keyboard.up \
and (xa[j] and xb[j] and xaa[j]).left-喵.left < (xa[j] and xb[j] and xaa[j]).width*2/3 \
and 喵.right-(xa[j] and xb[j] and xaa[j]).right < (xa[j] and xb[j] and xaa[j]).width*2/3:
xy -= 2
l = True
xa[j].y = xy
xb[j].y = xy
xaa[j].y = xy
if f == False:
ay += 5
for j in range(na):
aa[j].y = ay
ab[j].y = ay
aaa[j].y = ay
if l == False:
xy += 5
for j in range(nx):
xa[j].y = xy
xb[j].y = xy
xaa[j].y = xy
class XA:
x = None
y = None
sx = None
sy = None
ex = None
ey = None
喵 = None
vy = None
p = ''
def __init__(self, x, y, sx, sy, ex, ey, 喵, vy, p):
self.x = x
self.y = y
self.sx = sx
self.sy = sy
self.ex = ex
self.ey = ey
self.喵 = 喵
self.vy = vy
self.p = p
def draw(self):
screen.draw.circle((self.x, self.y), 10, 'yellow')
def update(self):
self.x += self.喵
self.y += self.vy
if keyboard.d or keyboard.right:
self.x += 0.2
if keyboard.a or keyboard.left:
self.x -= 0.2
def Sdkz(self):
if self.sx > self.x:
self.喵 = random.randint(20, 40)
elif self.sx < self.x:
self.喵 = random.randint(-40, -20)
if self.ex > self.x:
self.喵 = random.randint(20, 40)
elif self.ex < self.x:
self.喵 = random.randint(-40, -20)
if self.sy > self.y:
self.vy = random.randint(20, 40)
elif self.sy < self.y:
self.vy = random.randint(-40, -20)
if self.ey > self.y:
self.vy = random.randint(20, 40)
elif self.ey < self.y:
self.vy = random.randint(-40, -20)
XG = []
def c():
global sj, ax, ay ,xx, xy
sj += 1
if sj % 15 == 0:
喵 = 100
vy = 100
for i in range(random.randint(0, 10)):
p = Actor("alien")
x = random.randint(0,100)
y = 550
xg = XA(x, y, ax, ay, xx, xy, 喵, vy, p)
XG.append(xg)
for i in range(random.randint(0, 10)):
p = Actor("alien1")
x = random.randint(WIDTH-100, WIDTH)
y = 550
xg = XA(x, y, ax, ay, xx, xy, 喵, vy, p)
XG.append(xg)
for xg in XG:
if isinstance(xg, XA):
xg.sx = ax
xg.sy = ay
xg.ex = xx
xg.ey = xy
xg.Sdkz()
xg.update()
clock.schedule_unique(c, 1)
cxg = len(XG)
def draw():
global ai, xi, sj
screen.fill('gray')
bg.draw()
dm.draw()
for bm in B:
bm.draw()
for xg in XG:
xg.draw()
for 喵 in vine:
喵.draw()
aa[ai].draw()
xa[xi].draw()
screen.draw.text(str(sj)+"秒", (w/2, 0), fontsize=50,
fontname='s', color='black')
c()
update()
pgzrun.go()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn