
Lv.1
努力是桨,梦想是帆,在大海中乘风破浪,总有一天,会到达梦想的彼岸
签名:师傅:YLS汤圆 正在向师傅学习……(非“诚”勿扰) 九月目标: 点赞:900 收藏:6500 冲进阶高手(点赞分还差40)
在 用一句话证明你是官方! 中回复
活动活动活动喵喵喵住在源码世界的猴急一枚最爱的食物是:电池(因为可以发电) 神奇代码岛官网:box3.fun!加入官方内测唯一QQ喵
2021-07-28T17:05:25 点赞:0
在 岛3求助!!! 中回复
给玩家创建一个属性:(上次高度)
world.onPlayerJoin(({entity})=>{
entity.lastH = entity.position.y
}
每次tik遍历玩家列表,判断是否着地
world.onTick(({}) => {
let players = world.querySelectorAll('player')
for (p in players){
if (p.moveState!= 'fall'{
if (p.lastH - p.position.y >= 5){//填下落规定高度
p.lastH = p.position.y
p.hp -= 20
}
}
}
});2021-08-16T17:54:53 点赞:0
在 谁有灵感啊 中回复
……imgsrc="https://static.codemao.cn/emoji/codemao/%E7%BC%96%E7%A8%8B%E7%8C%AB_%E5%86%B7%E6%BC%A0.gif"alt="emotion_编程猫_冷漠"跑酷类的肿么样?
2021-08-17T15:46:17 点赞:0
在 python作品大集合!! 中回复
#初始化游戏
import pygame
import sys
import random
import time
pygame.init()
canvas = pygame.display.set_mode((480, 852))
pygame.display.set_caption("飞机大战")
canvas.fill((255, 255, 255))
#导入图片
bg = pygame.image.load("images/bg1.png")
enemy1 = pygame.image.load("images/enemy1.png")
enemy2 = pygame.image.load("images/enemy2.png")
enemy3 = pygame.image.load("images/enemy3.png")
h = pygame.image.load("images/hero.png")
b = pygame.image.load("images/bullet1.png")
stop = pygame.image.load("images/game_pause_nor.png")
LOGO = pygame.image.load("images/LOGO.png")
startGame = pygame.image.load("images/startGame.png")
#鼠标退出函数
def isMouseOut(x,y):
if x>479 or x<=0 or y>=喵9 or y<=0:
return True
else:
return False
def isMouseOver(x, y):
if x > 1 or x <= 479 or y > 1 or y < 喵9:
return True
else:
return False
#退出函数
def handleEvent():
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEMOTION:
GameVar.hero.x = event.pos[0]-GameVar.hero.width/2
GameVar.hero.y = event.pos[1]-GameVar.hero.height/2
if isMouseOut(event.pos[0], event.pos[1]):
if GameVar.state == GameVar.STATES['RUNNING']:
GameVar.state = GameVar.STATES['PAUSE']
if isMouseOver(event.pos[0], event.pos[1]):
if GameVar.state == GameVar.STATES['PAUSE']:
GameVar.state = GameVar.STATES['RUNNING']
if event.type==pygame.MOUSEBUTTONDOWN and event.button==1:
if GameVar.state == 1:
GameVar.state = GameVar.STATES['RUNNING']
#时间间隔函数
def isActionTime(lastTime,insert):
if lastTime == 0:
return True
newTime = time.time()
return newTime - lastTime >= insert
#碰撞函数
def bong(a,b):
if a.x > b.x-a.width and a.x < b.x+a.width+b.width and a.y > b.y-a.height and a.y < b.y+a.height+b.height:
return True
else:
return False
#背景类
class Bg():
width = 480
height = 852
def __init__(self):
self.img = bg
self.x1 = 0
self.x2 = 0
self.y1 = 0
self.y2 = -Bg.height
def step(self):
self.y1 = self.y1+1
self.y2 = self.y2+1
if self.y1 > Bg.height:
self.y1 = -Bg.height
if self.y2 > Bg.height:
self.y2 = -Bg.height
def paint(self):
canvas.blit(self.img, (self.x1, self.y1))
canvas.blit(self.img, (self.x2, self.y2))
#敌机类
class Enemy():
def __init__(self,x,y,width,height,life,score,img):
self.x = x
self.y = y
self.width = width
self.height = height
self.life = life
self.score = score
self.img = img
def paint(self):
canvas.blit(self.img,(self.x,self.y))
def step(self):
self.y = self.y + 2
#英雄类
class Hero():
def __init__(self,x,y,width,height,life,img):
self.width = width
self.height = height
self.x = (Bg.width+self.width)/2
self.y = (Bg.height+self.height)/2
self.life = life
self.img = img
self.shootLastTime = 0
self.shootInsert = 0.3
def paint(self):
canvas.blit(self.img, (self.x, self.y))
def shoot(self):
if isActionTime(self.shootLastTime, self.shootInsert):
self.shootLastTime = time.time()
GameVar.bullets.append(Bullet(self.x+(self.width-9)/2, self.y-21, 9, 21, 1, b))
#子弹类
class Bullet():
def __init__(self, x, y, width, height, life, img):
self.width = width
self.height = height
self.x = x
self.y = y
self.life = life
self.img = img
def paint(self):
canvas.blit(self.img, (self.x, self.y))
def step(self):
self.y = self.y - 2
#游戏数据类
class GameVar():
#创建背景角色
sky = Bg()
#创建敌机列表
enemies = []
#敌机创建时间
enemyLastTime = 0
enemyInsert = 1
#飞行物重绘时间
allLastTime = 0
allInsert = 0.04
#英雄机
hero = Hero(0,0,60,75,1,h)
#创建子弹列表
bullets = []
#分数生命
score = 0
life = 1
#游戏状态
STATES ={'STATE':1,'RUNNING':2,'PAUSE':3,'GAME_OVER':4}
state = STATES['STATE']
#添加所有图片函数
def allEnter():
#添加飞机
if isActionTime(GameVar.enemyLastTime, GameVar.enemyInsert):
GameVar.enemyLastTime = time.time()
a = random.randint(1,100)
x1 = random.randint(0, Bg.width-57)
y1 = -45
x2 = random.randint(0, Bg.width-50)
y2 = -68
x3 = random.randint(0, Bg.width-100)
y3 = -153
if a >= 95:
GameVar.enemies.append(Enemy(x3, y3, 100, 153, 10, 5, enemy3))
elif a >= 80:
GameVar.enemies.append(Enemy(x2, y2, 50, 68, 5, 3, enemy2))
else:
GameVar.enemies.append(Enemy(x1, y1, 57, 45, 3, 1, enemy1))
#添加子弹
GameVar.hero.shoot()
#写文字方法
def text(text,position,big):
my_font = pygame.font.SysFont("微软雅黑",big)
newText = my_font.render(text,True,(255,255,255))
canvas.blit(newText,position)
#画所有图片函数
def allPaint():
GameVar.sky.paint()
for enemy in GameVar.enemies:
enemy.paint()
GameVar.hero.paint()
for b in GameVar.bullets:
b.paint()
text('score:'+str(GameVar.score),(0,0),40)
text('life:'+str(GameVar.life), (380, 0),40)
#移动所有图片函数
def allStep():
GameVar.sky.step()
for enemy in GameVar.enemies:
enemy.step()
if enemy.y > Bg.height:
GameVar.enemies.remove(enemy)
for b in GameVar.bullets:
if bong(enemy,b):
GameVar.bullets.remove(b)
enemy.life -= 1
if enemy.life <= 0:
GameVar.score += enemy.score
GameVar.enemies.remove(enemy)
if bong(enemy,GameVar.hero):
GameVar.enemies.remove(enemy)
GameVar.life-=1
if GameVar.life <= 0:
GameVar.state = GameVar.STATES['GAME_OVER']
for b in GameVar.bullets:
b.step()
if b.y < 0:
GameVar.bullets.remove(b)
#运行函数
def gameUp():
if GameVar.state == 1:
GameVar.sky.paint()
GameVar.sky.step()
canvas.blit(LOGO,(-40,200))
canvas.blit(startGame,(150,400))
elif GameVar.state == 2:
allStep()
allPaint()
allEnter()
elif GameVar.state == 3:
allPaint()
canvas.blit(stop,(Bg.width/2,Bg.height/2))
else:
GameVar.sky.paint()
GameVar.sky.step()
text('GameOver',(60,320),100)
while True:
gameUp()
pygame.display.update()
handleEvent()
2021-08-17T15:58:02 点赞:0
在 哔哔哔,求帮忙。这是我希望的:【右键,选项,点击长喵,角色会拿上长喵】 中回复
world.onPress(({ button, entity }) => {
if(button === 'action1'){
let selection=entity.player.dialog({
type: Box3DialogType.SELECT,
title: '武器',
content: `你好,${entity.player.name},这里可以切换手持的武器`,
opti喵:['长枪']
})
if (selection){
c喵t wuqi=wuqilist[selection.index]
if (wuqi='长枪'){
entity.player.addWearable({
bodyPart: Box3BodyPart.RIGHT_HAND,
mesh: 'mesh/长枪 加强版.vb',
orientation: new Box3Quaternion(0,1,0,0).rotateY(Math.PI),
offset: new Box3Vector3(-0.05,-0.1,0.5),
scale: Box3Vector3 = new Box3Vector3(0.5, 0.5, 0.5)
})
}
}
}
})2021-08-18T16:22:51 点赞:0