Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,34 @@ def setup_overlay(self):
position = (0.6, -0.4),
origin = (0, 0),
scale = 1.5)

self.crosswind_button = Button(
parent = camera.ui,
text = 'Crosswind: Off',
position = (0.75, 0.42),
scale = (0.22,0.05),
color = color.gray.tint(.1),
on_click = self.toggle_crosswind)

self.wind_text = Text(
parent = camera.ui,
text = 'Wind: 0 m/s',
position = (0.75, 0.36),
origin = (0, 0),
scale = 1.0)
def toggle_crosswind(self):
"""
Crosswind toggle and UI update
"""
self.crosswind_enabled = not self.crosswind_enabled
if self.crosswind_enabled:
ws = self.weather.randomWind()
self.crosswind_button.text = 'Crosswind: On'
self.wind_text.text = f'Wind: {ws:.2f} m/s'
else:
self.weather.calmWind()
self.crosswind_button.text = 'Crosswind: Off'
self.wind_text.text = 'Wind: 0 m/s'

# Updated instructions text (moved outside loop)
self.instructions = Text(
Expand Down Expand Up @@ -770,6 +798,11 @@ def update_plane(self):
self.plane.position += self.plane.up * vv * self.dt * movment_scale
self.plane.position += self.plane.right * hv * self.dt * movment_scale

if self.crosswind_enabled:
wind_speed = self.weather.wind_x
self.plane.position += self.plane.right * wind_speed * self.dt * movment_scale
self.wind_text.text = f'Wind: {wind_speed:.2f} m/s'

if self.plane.x > (self.ground_size / 4) or self.plane.z > (self.ground_size / 4):
self.plane.x = 0
self.plane.z = 0
Expand Down Expand Up @@ -890,6 +923,26 @@ def end_simulation(self):
# Transition to post-flight analysis
PostFlight(self.flight_data)

# ---------------------------
# WEATHER EFFECTS
# ---------------------------
class Weather:
"""
Crosswinds modifier to physics
"""
def __init__(self):
self.maxcrosswind = 8.0
self.wind_x = 0.0

def randomWind(self):
self.wind_x = random.uniform(-self.maxcrosswind, self.maxcrosswind)
# random windspeed between -maxcrosswind and maxcrosswind
return self.wind_x
def calmWind(self):
self.wind_x = 0.0
# way to restore calm skies
return self.wind_x

# ---------------------------
# POST-FLIGHT ANALYTICS
# ---------------------------
Expand Down