about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorBaitinq <you@example.com>2022-02-13 19:00:40 +0000
committerBaitinq <you@example.com>2022-02-13 19:00:40 +0000
commitec98879ceb28df382ce11f6a653192a153d38879 (patch)
tree25cf898190d5db08e9e47044773ded74e0a3625a /src
parentFixed drag calculation and added orbit info sprite (diff)
downloadOSLS-ec98879ceb28df382ce11f6a653192a153d38879.tar.gz
OSLS-ec98879ceb28df382ce11f6a653192a153d38879.tar.bz2
OSLS-ec98879ceb28df382ce11f6a653192a153d38879.zip
Added physics speedup option
Diffstat (limited to 'src')
-rw-r--r--src/main.py56
1 files changed, 32 insertions, 24 deletions
diff --git a/src/main.py b/src/main.py
index b272571..edd690b 100644
--- a/src/main.py
+++ b/src/main.py
@@ -94,12 +94,14 @@ def main(argv):
     simulation_display = pygame.display.set_mode((SCREEN_WIDTH,SCREEN_HEIGHT))
     plot_coords = []
     speedup = 1.0
+    physics_speedup = 1.0
+    fps = 60
     paused = False
     while True:
         if not paused:
             sprite_group.update(simulation_display.get_width(), simulation_display.get_height())
             sprite_group.draw(simulation_display)
-            draw_text_info(simulation_display, simulation, paused, speedup)
+            draw_text_info(simulation_display, simulation, paused, physics_speedup, speedup)
             pygame.display.update()
 
         for event in pygame.event.get(): 
@@ -112,10 +114,16 @@ def main(argv):
                 elif event.key == pygame.K_SPACE:
                     paused = not paused
                 elif event.key == pygame.K_PLUS:
-                    speedup *= 1.1
+                    if pygame.key.get_pressed()[pygame.K_LSHIFT]:
+                        physics_speedup += 0.1
+                    else:
+                        speedup *= 1.1
                 elif event.key == pygame.K_MINUS:
-                    speedup *= 0.9
-                elif event.key == pygame.K_LSHIFT:
+                    if pygame.key.get_pressed()[pygame.K_LSHIFT]:
+                        physics_speedup -= 0.1
+                    else:
+                        speedup *= 0.9
+                elif event.key == pygame.K_RSHIFT:
                     #TODO: make the simulation window not loose focus when plot shown
                     data = np.array(plot_coords)
                     x, y = data.T
@@ -127,7 +135,7 @@ def main(argv):
                 else:
                     handle_key_press(simulation, event.key)
 
-        delta = clock.tick(60) / 1000 #60fps #are we using delta in the simulation tick everywhere needed?
+        delta = clock.tick(fps * physics_speedup) * physics_speedup / 1000
         if not paused:
             print("delta: " + str(delta))
             simulation.tick(delta=delta * speedup)
@@ -135,14 +143,13 @@ def main(argv):
 
         #TODO: Rocket altitude look at todo
         #TODO: DOnt overuse timeskip as physics not done, would have to increase fps for that or smth?
-        #TODO: Do a minimap that shows the body outline and where u are + orbit too
         #TODO: implement apoapsis and periapsis calculation
         #TODO: draw good rocket sprite, persistant clouds and star sprites, etc.
         #TODO: do actual aerodynamic load so heading depends on that and not on speed
         #TODO: do max load on rocket so it blows up
         #TODO: allow multilanguage api for landing algorithms etc
 
-def draw_text_info(simulation_display: type[pygame.Surface], simulation: type[Simulation], paused: bool, speedup: float) -> None:        
+def draw_text_info(simulation_display: type[pygame.Surface], simulation: type[Simulation], paused: bool, physics_speedup: float, speedup: float) -> None:        
         #draw stats text
         font = pygame.font.SysFont("Comic Sans MS", 30)
 
@@ -150,23 +157,24 @@ def draw_text_info(simulation_display: type[pygame.Surface], simulation: type[Si
         curr_thrust = simulation.rocket.current_stage().current_thrust(g, simulation.heading)
 
         simulation_display.blit(font.render("Simulation time: {:.0f}s".format(simulation.time), False, (255, 255, 255)),(0,0))
-        simulation_display.blit(font.render("Speedup: x{:.1f}".format(speedup), False, (255, 255, 255)),(0,40))
-        simulation_display.blit(font.render("Altitude: {:.0f}m".format(simulation.rocket_altitude()), False, (255, 255, 255)),(0,80))
-        simulation_display.blit(font.render("X: {:.0f}m".format(simulation.x), False, (255, 255, 255)),(0,120))
-        simulation_display.blit(font.render("Y: {:.0f}m".format(simulation.y), False, (255, 255, 255)),(0,160))
-        simulation_display.blit(font.render("Speed x: {:.0f}m/s".format(simulation.speed_x), False, (255, 255, 255)),(0,200))
-        simulation_display.blit(font.render("Speed y: {:.0f}m/s".format(simulation.speed_y), False, (255, 255, 255)),(0,240))
-        simulation_display.blit(font.render("Acceleration x: {:.2f}m/s2".format(simulation.acceleration_x), False, (255, 255, 255)),(0,280))
-        simulation_display.blit(font.render("Acceleration y: {:.2f}m/s2".format(simulation.acceleration_y), False, (255, 255, 255)),(0,320))
-        simulation_display.blit(font.render("Thrust x: {:.0f}N".format(simulation.rocket.current_stage().current_thrust(g, simulation.heading)[0]), False, (255, 255, 255)),(0,360))
-        simulation_display.blit(font.render("Thrust y: {:.0f}N".format(simulation.rocket.current_stage().current_thrust(g, simulation.heading)[1]), False, (255, 255, 255)),(0,400))
-        simulation_display.blit(font.render("Fuel in stage: {:.0f}kg".format(simulation.rocket.current_stage().fuel_mass), False, (255, 255, 255)),(0,440))
-        simulation_display.blit(font.render("Stage mass: {:.0f}kg".format(simulation.rocket.current_stage().total_mass()), False, (255, 255, 255)),(0,480))
-        simulation_display.blit(font.render("Rocket mass: {:.0f}kg".format(simulation.rocket.total_mass()), False, (255, 255, 255)),(0,520))
-        simulation_display.blit(font.render("Stage number: {:.0f}".format(simulation.rocket.stages_spent), False, (255, 255, 255)),(0,560))
-        simulation_display.blit(font.render("Throttle: {:.0f}%".format(simulation.rocket.current_stage().throttle), False, (255, 255, 255)),(0,600))
-        simulation_display.blit(font.render("Gimbal: {:.2f}deg".format(simulation.rocket.current_stage().gimbal), False, (255, 255, 255)),(0,640))
-        simulation_display.blit(font.render("Heading: {:.2f}deg".format(simulation.heading), False, (255, 255, 255)),(0,680))
+        simulation_display.blit(font.render("Physics peedup: x{:.1f}".format(physics_speedup), False, (255, 255, 255)),(0,40))
+        simulation_display.blit(font.render("Speedup: x{:.1f}".format(speedup), False, (255, 255, 255)),(0,80))
+        simulation_display.blit(font.render("Altitude: {:.0f}m".format(simulation.rocket_altitude()), False, (255, 255, 255)),(0,120))
+        simulation_display.blit(font.render("X: {:.0f}m".format(simulation.x), False, (255, 255, 255)),(0,160))
+        simulation_display.blit(font.render("Y: {:.0f}m".format(simulation.y), False, (255, 255, 255)),(0,200))
+        simulation_display.blit(font.render("Speed x: {:.0f}m/s".format(simulation.speed_x), False, (255, 255, 255)),(0,240))
+        simulation_display.blit(font.render("Speed y: {:.0f}m/s".format(simulation.speed_y), False, (255, 255, 255)),(0,280))
+        simulation_display.blit(font.render("Acceleration x: {:.2f}m/s2".format(simulation.acceleration_x), False, (255, 255, 255)),(0,320))
+        simulation_display.blit(font.render("Acceleration y: {:.2f}m/s2".format(simulation.acceleration_y), False, (255, 255, 255)),(0,360))
+        simulation_display.blit(font.render("Thrust x: {:.0f}N".format(simulation.rocket.current_stage().current_thrust(g, simulation.heading)[0]), False, (255, 255, 255)),(0,400))
+        simulation_display.blit(font.render("Thrust y: {:.0f}N".format(simulation.rocket.current_stage().current_thrust(g, simulation.heading)[1]), False, (255, 255, 255)),(0,440))
+        simulation_display.blit(font.render("Fuel in stage: {:.0f}kg".format(simulation.rocket.current_stage().fuel_mass), False, (255, 255, 255)),(0,480))
+        simulation_display.blit(font.render("Stage mass: {:.0f}kg".format(simulation.rocket.current_stage().total_mass()), False, (255, 255, 255)),(0,520))
+        simulation_display.blit(font.render("Rocket mass: {:.0f}kg".format(simulation.rocket.total_mass()), False, (255, 255, 255)),(0,560))
+        simulation_display.blit(font.render("Stage number: {:.0f}".format(simulation.rocket.stages_spent), False, (255, 255, 255)),(0,600))
+        simulation_display.blit(font.render("Throttle: {:.0f}%".format(simulation.rocket.current_stage().throttle), False, (255, 255, 255)),(0,640))
+        simulation_display.blit(font.render("Gimbal: {:.2f}deg".format(simulation.rocket.current_stage().gimbal), False, (255, 255, 255)),(0,680))
+        simulation_display.blit(font.render("Heading: {:.2f}deg".format(simulation.heading), False, (255, 255, 255)),(0,720))
 
 def handle_key_press(simulation, key):
     if key == pygame.K_x: