about summary refs log tree commit diff
path: root/simulation.py
diff options
context:
space:
mode:
Diffstat (limited to 'simulation.py')
-rw-r--r--simulation.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/simulation.py b/simulation.py
index a382f63..4d6fc73 100644
--- a/simulation.py
+++ b/simulation.py
@@ -23,18 +23,18 @@ class Simulation():
 
     #simulation logic
     def tick(self, delta: int) -> None:
+        current_stage = self.rocket.current_stage()
         #calculate upwards force by fuel       
-        # TODO able to turn engine on and off 
-        fuel_used = self.rocket.total_fuel_used(delta)
-        if self.rocket.fuel_mass < fuel_used:
-            fuel_used = self.rocket.fuel_mass
-        self.rocket.fuel_mass -= fuel_used
-        print("Fuel remaining: " + str(self.rocket.fuel_mass))
+        fuel_used = current_stage.total_fuel_used(delta)
+        if current_stage.fuel_mass < fuel_used:
+            fuel_used = current_stage.fuel_mass
+        current_stage.fuel_mass -= fuel_used
+        print("Fuel remaining: " + str(current_stage.fuel_mass))
         
         #upwards_force = fuel_used * self.rocket.fuel_type.energy_density #we should calculate thrust based on this
         upwards_force = 0
         if fuel_used > 0:
-            upwards_force = self.rocket.total_thrust()
+            upwards_force = current_stage.current_thrust()
         print("Upwards force: " + str(upwards_force))
 
         print("g: " + str(self.body.g(G=self.universe.G, height=self.y)))
@@ -49,8 +49,11 @@ class Simulation():
         print("Atmosphere density: " + str(self.body.atmosphere.density_at_height(self.y, self.body.g(G=self.universe.G, height=self.y))))
 
         #https://www.grc.nasa.gov/www/k-12/airplane/drageq.html
-        drag_force = (1/2) * self.body.atmosphere.density_at_height(self.y, self.body.g(G=self.universe.G, height=self.y)) * (self.speed_y ** 2) * self.rocket.drag_coefficient * self.rocket.cross_sectional_area
-        print("Drag: " + str(drag_force)) #drag can be negative too?
+        drag_force = (1/2) * self.body.atmosphere.density_at_height(self.y, self.body.g(G=self.universe.G, height=self.y)) * (self.speed_y ** 2) * self.rocket.s_drag_coefficient() * self.rocket.s_cross_sectional_area()
+        #drag goes against speed
+        if self.speed_y < 0:
+            drag_force *= -1
+        print("Drag: " + str(drag_force))
 
         downwards_force = gravitational_force + drag_force #shouldnt delta influence, TODO: WAIT DRAG COULD BE POSITIVE OR NEGATIVE
         print("Downwards force: " + str(downwards_force))