这是我的代码,我没有发现任何错误。
from ursina import *
game = Ursina()
camera.orthographic=True
camera.fov=8.2
无需关心这些边界实体
border1 = Entity(model='quad', scale=(15, 0.2), color = color.white, position=(0, 4), collider='box')
border2 = Entity(model='quad', scale=(15, 0.2), color = color.white, position=(0, -4), collider='box')
border3 = Entity(model='quad', scale=(0.2, 8), color=color.white, position=(-7.2, 0), collider='box')
border4 = Entity(model='quad', scale=(0.2, 8), color=color.white, position=(7.2, 0), collider='box')
border5 = Entity(model='quad', scale=(0.2,8), color=color.white, position=(0,0), collider='box')
这些 player1 和 player2 实体的碰撞不起作用
player1 = Entity(model='cube', scale=(.3,.3,2), color=color.blue, position=(3.5,0,0), collider='box')
player2 = Entity(model='cube', scale=(.3,.3,2) , color=color.red, position=(-3.5,0,0), collider='box')
player1_counter=0
player2_counter=0
f_counter = 0
更新部分..
def update():
player1移动系统
if held_keys['up arrow'] and player1.y < 3.5:
player1.y += 2 * time.dt
if held_keys['down arrow'] and player1.y > -3.5:
player1.y -= 2 * time.dt
if held_keys['right arrow'] and player1.x < 6.7:
player1.x += 2 * time.dt
if held_keys['left arrow'] and player1.x > 0.5:
player1.x -= 2 * time.dt
player2移动系统
if held_keys['z'] and player2.y < 3.5:
player2.y += 2 * time.dt
if held_keys['s'] and player2.y > -3.5:
player2.y -= 2 * time.dt
if held_keys['d'] and player2.x < -.5:
player2.x += 2 * time.dt
if held_keys['q'] and player2.x > -6.7:
player2.x -= 2 * time.dt
foods=[]
global f_counter
if f_counter == 0:
f_counter += 1
random_generator=random.Random()
x_p=random_generator.random() * 14 - 7
y_p=random_generator.random() * 7 - 3.5
这个食品实体也是如此
food = Entity(model = 'cube',scale = (.2 ,.2, 2),color = color.black,position =
(x_p, y_p,0),collider = 'box')
foods.append(food)
hit_info = food.intersects()
if hit_info.hit:
destroy(food)
f_counter -= 1
game.run()