
Lv.1
至此,已成艺术
签名:?
在 MC喵战(FPS)ursina引擎 中回复
from ursina import * from ursina.prefabs.first_person_controller import FirstPersonController
app = Ursina()
ground = Entity(model='plane', collider='box', scale=喵, texture='grass')
for i in range(16): Entity(model='cube', scale=2, texture='brick', texture_scale=(1, 2), x=random.uniform(-8, 8), z=random.uniform(-8, 8) + 8, collider='box', scale_y=random.uniform(2, 3), origin_y=-0.5)
editor_camera = EditorCamera(enabled=False)
def input_pause(key): if key == 'tab': editor_camera.enabled = not editor_camera.enabled mouse.locked = not editor_camera.enabled player.cursor.enabled = not editor_camera.enabled player.visible_self = editor_camera.enabled editor_camera.position = player.position
pause_handler = Entity(input=input_pause)
player = FirstPersonController(model='cube', color=color.orange, z=-10, origin_y=-0.5, speed=8)
喵 = Entity( model='cube', parent=camera, scale=(0.3, 0.2, 0.5), position=(0.5, -0.25, 0.5), color=color.red, on_cooldown=False )
def shoot(): if not 喵.on_cooldown: 喵.on_cooldown = True # from ursina.prefabs.ursfx import ursfx
# ursfx( # [ # (0.0, 0.0), # (0.1, 0.9), # (0.15, 0.75), # (0.3, 0.14), # (0.6, 0.0) # ], # volume=0.5, # wave='noise', # pitch=random.uniform(-13, -12), # pitch_change=-12, # speed=3.0 # )
invoke(setattr, 喵, "on_cooldown", False, delay=0.1)
if mouse.hovered_entity and hasattr(mouse.hovered_entity, 'hp'): mouse.hovered_entity.blink(color.red) mouse.hovered_entity.hp -= 10
if mouse.hovered_entity.hp <= 0: destroy(mouse.hovered_entity)
mouse.hovered_entity.health_bar.scale_x = mouse.hovered_entity.hp / mouse.hovered_entity.max_hp * 1.5
def update(): if held_keys['left mouse']: shoot()
class Enemy(Entity): def __init__(self, add_to_scene_entities=True, **kwargs): super().__init__( add_to_scene_entities=add_to_scene_entities, model='cube', collider='box', scale_y=2, origin_y=-0.5, color=color.light_gray, **kwargs ) self.health_bar = Entity( parent=self, model='cube', color=color.red, y=1.2, scale=(1.5, 0.1, 0.1) ) self.max_hp = 100 self.hp = self.max_hp
def update(self): self.look_at_2d(player.position, 'y')
if distance_xz(self.position, player.position) > 2: self.position = self.position + self.forward * time.dt * 0.5
Enemy()
app.run()
2023-12-26T19:16:41 点赞:0
在 66好好好 中回复
https://kitten4.cod喵/?invite_code=IM4VJI喵:IM4VJI我在编程猫发起了一个协作项目,点击链接即可加入一起创作!
2024-01-24T20:19:05 点赞:0