Skip to content
Open
Binary file modified project/__pycache__/physics_engine.cpython-312.pyc
Binary file not shown.
Binary file not shown.
Binary file modified project/__pycache__/settings.cpython-312.pyc
Binary file not shown.
Binary file added project/__pycache__/settings.cpython-313.pyc
Binary file not shown.
Binary file modified project/core/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file added project/core/__pycache__/__init__.cpython-313.pyc
Binary file not shown.
Binary file modified project/core/__pycache__/base_object.cpython-312.pyc
Binary file not shown.
Binary file not shown.
Binary file modified project/core/__pycache__/environment.cpython-312.pyc
Binary file not shown.
Binary file not shown.
Binary file modified project/core/__pycache__/projectile.cpython-312.pyc
Binary file not shown.
Binary file added project/core/__pycache__/projectile.cpython-313.pyc
Binary file not shown.
Binary file modified project/core/__pycache__/rocket.cpython-312.pyc
Binary file not shown.
Binary file added project/core/__pycache__/rocket.cpython-313.pyc
Binary file not shown.
Binary file modified project/core/__pycache__/static.cpython-312.pyc
Binary file not shown.
Binary file added project/core/__pycache__/static.cpython-313.pyc
Binary file not shown.
60 changes: 36 additions & 24 deletions project/core/rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ def __init__(self,screen,launchsite,result = None,object_type = "rocket",dt=None

#TESING INITIAL MASS, THRUST & ANGLE
self.mass = 10 #EXAMPLE mass of rocket (kg)
self.thrust = 200 #EXAMPLE initial thrust (N)
self.thrust = 0 #EXAMPLE initial thrust (N)
self.angle = np.radians(90) #EXAMPLE initial angle of rocket (rad)
self.velocity = [0,0]

# Add this line to define is_thrusting
self.is_thrusting = False # Tracks whether thrust is active


def draw(self):

image = self.original_image
Expand All @@ -50,35 +54,43 @@ def compute_altitude(self):
def check_collision(self,other,environment):
pass



def update(self, environment=None):

# Calculate the magnitude of thrust components
self.thrust_x = self.thrust * np.cos(self.angle)
self.thrust_y = self.thrust * np.sin(self.angle)

def update(self,environment=None):
# Calculate force
self.force_x = self.thrust_x
self.force_y = self.thrust_y + (self.mass * environment.gravity) # Inverted for pygame coordinates
self.force = np.array([self.force_x, self.force_y])

#EXAMPLE Calculate the magnitude of thrust components
thrust_x = self.thrust * np.cos(self.angle)
thrust_y = self.thrust * np.sin(self.angle)
# Use physics_engine to calculate acceleration
self.acceleration = physics_engine.calculate_acceleration(self.force, self.mass)

#EXAMPLE Calculate force
force_x = thrust_x
force_y = thrust_y + (self.mass * environment.gravity) #inverted for pygame coordinates (0,0) at the top left
force = np.array([force_x, force_y])
if self.is_thrusting: # Apply thrust only when 'W' is pressed
self.thrust_x = self.thrust * np.cos(self.angle)
self.thrust_y = self.thrust * np.sin(self.angle)

#Use physics_engine to calculate acceleration with force and mass
acceleration = physics_engine.calculate_acceleration(force,self.mass)
self.force_x = self.thrust_x
self.force_y = self.thrust_y + (self.mass * environment.gravity) # Gravity included

#Update velocity
# a = dv/dt
# a * dt = vf - vi
# vf = vi + (a * dt)
self.velocity = np.array(self.velocity) + (np.array(acceleration) * self.dt)
self.force = np.array([self.force_x, self.force_y])
self.acceleration = physics_engine.calculate_acceleration(self.force, self.mass)

self.launch() # Apply physics to move the rocket

def launch(self):

# v = ds/dt
# v * dt = sf - si
# sf = si + (v * dt)
self.x += self.velocity[0] * self.dt
self.y -= self.velocity[1] * self.dt #inverted for pygame coordinates (0,0) at the top left
print(f"Thrust: {thrust_y} Force: {force_y} Velocity: {self.velocity}, Position: ({self.x}, {self.y})")
#this will update forces and stuff
# Update velocity
self.velocity = np.array(self.velocity) + (np.array(self.acceleration) * self.dt)

# Update position
self.x += self.velocity[0] * self.dt
self.y -= self.velocity[1] * self.dt # Inverted for pygame coordinates

print(f"Thrust: {self.thrust_y}, Force: {self.force_y}, Velocity: {self.velocity}, Position: ({self.x}, {self.y})")


1 change: 1 addition & 0 deletions project/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import core
from core import environment
from core.rocket import Rocket
import pygame


def is_complete():
Expand Down