Untitled

 avatar
unknown
plain_text
15 days ago
3.4 kB
7
Indexable
from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
import random

# Uruchomienie aplikacji
app = Ursina()

# Gracz - kamera FPS
player = FirstPersonController()

# Podłoga
ground = Entity(model='plane', texture='grass', scale=(50, 1, 50), collider='box')

# Cele (przeciwnicy)
targets = []

def spawn_target():
    # Tworzenie celu w losowym miejscu
        target = Entity(
                    model='cube',
                            color=color.red,
                                    position=(random.randint(-20, 20), random.randint(1, 5), random.randint(-20, 20)),
                                            scale=(1, 1, 1),
                                                    collider='box'
        )
            targets.append(target)

            # Stwórz kilka celów na start
            for _ in range(5):
                spawn_target()

                # Licznik punktów
                score = 0
                score_text = Text(text=f"Score: {score}", position=(-0.7, 0.45), scale=2)

                # Strzelanie
                def input(key):
                    global score
                        if key == "left mouse down":
                                hit_info = raycast(player.position, camera.forward, distance=100)
                                        if hit_info.hit:
                                                    if hit_info.entity in targets:
                                                                    # Usuwamy trafiony cel
                                                                                    destroy(hit_info.entity)
                                                                                                    targets.remove(hit_info.entity)
                                                                                                                    score += 1
                                                                                                                                    score_text.text = f"Score: {score}"
                                                                                                                                                    spawn_target()

                                                                                                                                                    # Update — można dodać np. ruch celów
                                                                                                                                                    def update():
                                                                                                                                                        for target in targets:
                                                                                                                                                                target.y += sin(time.time() * 2) * 0.02  # Cel lekko się porusza góra-dół dla utrudnienia

                                                                                                                                                                # Start gry
                                                                                                                                                                app.run()
        )
Editor is loading...
Leave a Comment