Init
This commit is contained in:
commit
17fbfb3426
BIN
__pycache__/engine.cpython-311.pyc
Normal file
BIN
__pycache__/engine.cpython-311.pyc
Normal file
Binary file not shown.
50
engine.py
Normal file
50
engine.py
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
import math
|
||||||
|
|
||||||
|
class Engine:
|
||||||
|
rpm = 0
|
||||||
|
throttle = 0
|
||||||
|
load = 0
|
||||||
|
instant_torque = 0
|
||||||
|
gear = 0
|
||||||
|
flywheel_inertia = 0
|
||||||
|
idle_rpm = 750
|
||||||
|
max_rpm = 6500
|
||||||
|
|
||||||
|
fuel_rate = 0
|
||||||
|
afr = 0
|
||||||
|
coolant_temp = 0
|
||||||
|
oil_temp = 0
|
||||||
|
|
||||||
|
ignition_timing = 0
|
||||||
|
|
||||||
|
ambient_temp = 0
|
||||||
|
altitude = 0
|
||||||
|
intake_pressure = 0
|
||||||
|
vehicle_mass = 0
|
||||||
|
drivetrain_loss = 0
|
||||||
|
|
||||||
|
oil_pressure = 0
|
||||||
|
turbo_boost = 0
|
||||||
|
kr = 0
|
||||||
|
exhaust_temp = 0
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
rpm = 250
|
||||||
|
|
||||||
|
def update(self, throttle, load, dt):
|
||||||
|
|
||||||
|
if not self.running:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.throttle = throttle
|
||||||
|
self.load = load
|
||||||
|
|
||||||
|
# Apply simplified engine RPM dynamics
|
||||||
|
rpm_change = (throttle - load) * self.torque_curve(self.rpm) / self.flywheel_inertia
|
||||||
|
self.rpm += rpm_change * dt
|
||||||
|
self.rpm = max(self.idle_rpm, min(self.rpm, self.max_rpm))
|
||||||
|
|
||||||
|
self.torque = self.torque_curve(self.rpm) * throttle
|
||||||
|
self.fuel_rate = self.rpm * throttle * self.fuel_efficiency
|
||||||
|
|
||||||
|
self._update_temps(dt)
|
80
main.py
Normal file
80
main.py
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
# Example file showing a circle moving on screen
|
||||||
|
import pygame
|
||||||
|
import math
|
||||||
|
from engine import Engine
|
||||||
|
|
||||||
|
# pygame setup
|
||||||
|
pygame.init()
|
||||||
|
screen = pygame.display.set_mode((1280, 720))
|
||||||
|
clock = pygame.time.Clock()
|
||||||
|
running = True
|
||||||
|
dt = 0
|
||||||
|
|
||||||
|
player_pos = pygame.Vector2(screen.get_width() / 2, screen.get_height() / 2)
|
||||||
|
|
||||||
|
rpm_pos = pygame.Vector2(screen.get_width() * 0.25, screen.get_height() / 2)
|
||||||
|
spd_pos = pygame.Vector2(screen.get_width() * 0.75, screen.get_height() / 2)
|
||||||
|
|
||||||
|
gauge_radius = screen.get_height() / 5
|
||||||
|
|
||||||
|
# Angle for gauge
|
||||||
|
angle_rad = math.radians(145)
|
||||||
|
|
||||||
|
needle_color = "black"
|
||||||
|
needle_width = 4
|
||||||
|
tip_radius = needle_width
|
||||||
|
|
||||||
|
offset_vector = pygame.Vector2(
|
||||||
|
math.cos(angle_rad) * gauge_radius,
|
||||||
|
math.sin(angle_rad) * gauge_radius
|
||||||
|
)
|
||||||
|
|
||||||
|
e = engine()
|
||||||
|
|
||||||
|
while running:
|
||||||
|
# poll for events
|
||||||
|
# pygame.QUIT event means the user clicked X to close your window
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
running = False
|
||||||
|
|
||||||
|
# fill the screen with a color to wipe away anything from last frame
|
||||||
|
screen.fill("white")
|
||||||
|
|
||||||
|
# RPM
|
||||||
|
# Min = 0 at 45 degrees
|
||||||
|
# Max = 8 at 315 degrees
|
||||||
|
pygame.draw.circle(screen, "red", rpm_pos, gauge_radius)
|
||||||
|
rpm_tip = rpm_pos + offset_vector
|
||||||
|
pygame.draw.line(screen, needle_color, rpm_pos, rpm_tip, needle_width)
|
||||||
|
pygame.draw.circle(screen, needle_color, rpm_tip, tip_radius)
|
||||||
|
|
||||||
|
# Trans Speed
|
||||||
|
# Min = 0 at 45 degrees
|
||||||
|
# Max = 160 at 315 degrees
|
||||||
|
pygame.draw.circle(screen, "red", spd_pos, gauge_radius)
|
||||||
|
spd_tip = spd_pos + offset_vector
|
||||||
|
pygame.draw.line(screen, needle_color, spd_pos, spd_tip, needle_width)
|
||||||
|
pygame.draw.circle(screen, needle_color, spd_tip, tip_radius)
|
||||||
|
|
||||||
|
pygame.draw.circle(screen, "red", player_pos, 40)
|
||||||
|
|
||||||
|
keys = pygame.key.get_pressed()
|
||||||
|
if keys[pygame.K_w]:
|
||||||
|
player_pos.y -= 300 * dt
|
||||||
|
if keys[pygame.K_s]:
|
||||||
|
player_pos.y += 300 * dt
|
||||||
|
if keys[pygame.K_a]:
|
||||||
|
player_pos.x -= 300 * dt
|
||||||
|
if keys[pygame.K_d]:
|
||||||
|
player_pos.x += 300 * dt
|
||||||
|
|
||||||
|
# flip() the display to put your work on screen
|
||||||
|
pygame.display.flip()
|
||||||
|
|
||||||
|
# limits FPS to 60
|
||||||
|
# dt is delta time in seconds since last frame, used for framerate-
|
||||||
|
# independent physics.
|
||||||
|
dt = clock.tick(60) / 1000
|
||||||
|
|
||||||
|
pygame.quit()
|
Loading…
x
Reference in New Issue
Block a user