【问题标题】:Enemy collision in Ursina在ursina的敌人碰撞
【发布时间】:2022-01-11 00:01:52
【问题描述】:

我正在 ursina 中制作游戏,并想知道如何输出说明其真假的内容(如布尔值)。因为我正在制作的游戏需要与实体的碰撞。我一直在寻找解决方案,但我找不到任何东西。所以使用ursina的人请帮助我这里是代码:

from ursina import *
import random


#variables
speed = 0.05
number_of_pokemon = 10

app = Ursina()

#textures
player_texture = load_texture('pokemon orange assets/player.png')
pokemon_texture1 = load_texture('pokemon orange assets/pokemon.png')
pokemon_texture2 = load_texture('pokemon orange assets/pokemon2.png')
pokemon_texture3 = load_texture('pokemon orange assets/pokemon3.png')
grass_texture = load_texture('pokemon orange assets/grass.png')
textbox_texture = load_texture('pokemon orange assets/textbox.png')
missingno_texture = load_texture('pokemon orange assets/missingno.png')

pokemontextures = [pokemon_texture1, pokemon_texture2, pokemon_texture3]

#entitys: pokemon(s), player, textbox, battles
player = Entity(model = 'cube', texture = player_texture, scale = (1,1,0), position = 
(0,0,-0.1))
#textbox = Entity(model ='cube', texture = textbox_texture, scale = (5,1,0), position = 
(0,-3,0))

#spawns pokemon
number = random.uniform(0,100)
if(number == 100):
    for i in range (100):
         pokemon = Entity(model ='cube', texture = missingno_texture, scale = (1,2,0), 
      position = (random.uniform(-10,10),random.uniform(-10,10),random.uniform(-10,10)))
else:
    for i in range(number_of_pokemon):
        pokemon = Entity(model ='cube', texture = random.choice(pokemontextures), scale = (1.5,1.5,0), position = (random.uniform(-5,5),random.uniform(-4,4),-0.1))


#spawns grass
for y in range(20):   
    for x in range(20):
        grass = Entity(model ='cube', texture = grass_texture, scale = (1,1,0), position = (x - 10,y - 10,0))

#movement
def update():
    player.x += held_keys['d'] * speed 
    player.x -= held_keys['a'] * speed 
    player.y += held_keys['w'] * speed 
    player.y -= held_keys['s'] * speed 
           


app.run()

【问题讨论】:

    标签: python ursina


    【解决方案1】:

    设置Collider 并检查您的实体是否与另一个实体相交:

    player = Entity(model='cube',
                    texture=player_texture,
                    scale=(1, 1, 0),
                    position=(0, 0, -0.1),
                    collider='box') # <-- do the same for all pokemon entities
    
    hit_info = player.intersects()
    if hit_info.hit:
        print(hit_info.entity)
    

    【讨论】:

    • 谢谢你的解释:D
    • @LucasVuijk 如果我解决了您的问题,请考虑投票和/或将答案标记为已接受以完成 QA 周期。
    猜你喜欢
    • 2021-12-05
    • 1970-01-01
    • 2023-03-23
    • 2019-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-07
    相关资源
    最近更新 更多