Untitled
Anonymous
plain_text
02/28/2026 7:30 PM
6.7 KB
13
Indexable
from ursina import *
from ursina.prefabs.first_person_controller import First_Person_Controller
app = Ursina()
# --- Environment Setup ---
Sky(texture='sky_sunset') # Thoda Vice City wala sunset vibe
ground = Entity(model='plane', scale=200, texture='grass', texture_scale=(100,100), collider='box')
# Road banane ke liye
road = Entity(model='cube', scale=(10, 0.1, 200), color=color.dark_gray, z=0, collider='box')
# Buildings (Random colors and sizes)
for i in range(15):
Entity(
model='cube',
color=color.random_color(),
scale=(8, random.uniform(10, 30), 8),
position=(random.choice([-20, 20]), 0, i*15 - 50),
collider='box'
)
# --- Player & Car Setup ---
player = First_Person_Controller()
player.cursor.visible = True
# Car (Abhi ke liye ek simple block jo move karega)
car = Entity(model='cube', color=color.red, scale=(2, 1, 4), position=(5, 0.5, 10), collider='box')
driving = False
# Gun model (Player ke haath mein)
gun = Entity(model='cube', parent=camera, position=(0.5, -0.5, 1), scale=(0.1, 0.2, 0.5), color=color.black)
def update():
global driving
# 1. Fall Protection
if player.y < -5:
player.position = (0, 5, 0)
# 2. Car Driving Logic
if driving:
player.position = car.position + Vec3(0, 1, 0) # Player car ke andar rahega
if held_keys['w']: car.z += time.dt * 15
if held_keys['s']: car.z -= time.dt * 15
if held_keys['a']: car.rotation_y -= time.dt * 50
if held_keys['d']: car.rotation_y += time.dt * 50
# 3. Car Enter/Exit Logic (Distance check)
dist = distance(player.position, car.position)
if dist < 3 and held_keys['v']:
driving = True
player.visible = False # Player ko hide kar do driving ke waqt
if held_keys['escape']: # Exit car
driving = False
player.visible = True
player.position += Vec3(2, 0, 0)
def input(key):
if key == 'left mouse down':
# Shooting effect
Bullet = Entity(model='sphere', scale=0.2, color=color.yellow, position=gun.world_position)
Bullet.animate_position(Bullet.position + camera.forward * 50, duration=0.5)
destroy(Bullet, delay=1)
app.run()
)Editor is loading...
Leave a Comment