我正在使用 Ursina 引擎创建一个 2D 游戏。在让玩家投篮时,投篮很好,但它根本不动。尝试使用playerShot.y += vel* time.dt
没有奏效。尝试使用animate_position()
,没有正常工作。
这是代码:
mainLibs.py(在 ursina_main.py 上导入)
from ursina import *
def update():
CreatePlayerShot()
def CreatePlayerShot(x, y, sx, sy, vel, ang):
playerBullet = Entity(model = 'quad', scale = (sx, sy), position = (x, y))
playerBullet.rotation_z = ang
playerBullet.y += vel * time.dt
yield
如果需要,生病发送视频!
ursina_main.py(主游戏脚本)
from ursina import *
from mainLibs import *
app = Ursina()
can_shoot = True
last_shot = 0
fullScreenBool = True
playerVel = float
player = Entity(model = 'quad', texture = 'reimuIdle.png', scale = (0.6, 1), position = (0, -4))
hitbox = Entity(model = 'circle', color = color.blue, scale = (0.15, 0.15), position = (0, 0))
ui = Entity(model = 'quad', texture = 'gameGUIStg.png', scale = (15, 11))
player.double_sided = True
window.title = "Touhou Test"
window.fullscreen = False
window.borderless = True
def update():
movement()
image()
slow()
shot()
hitbox.x = player.x
hitbox.y = player.y
global can_shoot, last_shot
if not can_shoot:
last_shot += time.dt
if last_shot > 600: # 1 second
can_shoot = True
def movement():
if held_keys['left arrow'] and player.x > -4.25:
player.x += -playerVel * time.dt
if held_keys['right arrow'] and player.x < 3.90:
player.x += playerVel * time.dt
if held_keys['up arrow'] and player.y < 4.25:
player.y += playerVel * time.dt
if held_keys['down arrow']and player.y >-4.40:
player.y += -playerVel * time.dt
def image():
if held_keys['left arrow']:
player.rotation = (0, 0, 0)
player.texture = 'reimuMove.png'
elif held_keys['right arrow']:
player.rotation = (0, 180, 0)
player.texture = 'reimuMove.png'
else:
player.texture = 'reimuIdle'
def slow():
if held_keys['left shift']:
global playerVel
playerVel = 1.7
else:
playerVel = 3.3
def shot():
if held_keys['z'] and can_shoot == True:
CreatePlayerShot(player.x, player.y, 0.1, 0.2, 10, 0)
app.run()