diff --git a/godot/game.tscn b/godot/game.tscn index f26440b..0c5b949 100644 --- a/godot/game.tscn +++ b/godot/game.tscn @@ -26,9 +26,14 @@ scale = Vector2(1.99747, 0.147406) texture = ExtResource("4_fc0e3") [node name="Car" parent="." instance=ExtResource("1_80nbo")] +controlled_by_player = true script = ExtResource("4_7jktm") [node name="Camera2D" type="Camera2D" parent="Car"] position = Vector2(0, -1) scale = Vector2(0.1, 0.1) zoom = Vector2(0.36, 0.36) + +[node name="Car2" parent="." instance=ExtResource("1_80nbo")] +position = Vector2(512, -1536) +rotation = -1.0472 diff --git a/radio/Cassette FM/Groove Machine.mp3 b/radio/Cassette FM/Groove Machine.mp3 new file mode 100644 index 0000000..98a8140 Binary files /dev/null and b/radio/Cassette FM/Groove Machine.mp3 differ diff --git a/radio/Cassette FM/Road Cassette.mp3 b/radio/Cassette FM/Road Cassette.mp3 new file mode 100644 index 0000000..6c438fd Binary files /dev/null and b/radio/Cassette FM/Road Cassette.mp3 differ diff --git a/radio/Cassette FM/Trumpeteer.mp3 b/radio/Cassette FM/Trumpeteer.mp3 new file mode 100644 index 0000000..118d15f Binary files /dev/null and b/radio/Cassette FM/Trumpeteer.mp3 differ diff --git a/radio/noir/Shadows in the Glow.mp3 b/radio/noir/Shadows in the Glow.mp3 new file mode 100644 index 0000000..6bc4c4b Binary files /dev/null and b/radio/noir/Shadows in the Glow.mp3 differ diff --git a/rust/crates/grand-theft-arena/src/car.rs b/rust/crates/grand-theft-arena/src/car.rs index 4875efc..3a9de9a 100644 --- a/rust/crates/grand-theft-arena/src/car.rs +++ b/rust/crates/grand-theft-arena/src/car.rs @@ -28,6 +28,9 @@ struct Car { /// Unit: radians max_steering_angle: f32, + #[export] + controlled_by_player: bool, + base: Base, } @@ -47,6 +50,14 @@ impl Wheel { } } +struct UserInput { + move_forward: bool, + move_backward: bool, + turn_left: bool, + turn_right: bool, + handbrake: bool, +} + #[godot_api] impl IRigidBody2D for Car { fn init(base: Base) -> Self { @@ -72,6 +83,9 @@ impl IRigidBody2D for Car { y_distance: 200.0, has_grip: true, }, + + // Exported + controlled_by_player: Default::default(), } } @@ -90,14 +104,17 @@ impl IRigidBody2D for Car { self.base_mut().set_angular_velocity(0.0); } - let input = Input::singleton(); - let move_forward = input.is_action_pressed("move_forward"); - let move_backward = input.is_action_pressed("move_backward"); - let turn_left = input.is_action_pressed("turn_left"); - let turn_right = input.is_action_pressed("turn_right"); - - // TODO: Handbrake - let _handbrake = input.is_action_pressed("handbrake"); + let user_input = if self.controlled_by_player { + self.user_input() + } else { + UserInput { + move_forward: false, + move_backward: false, + turn_left: false, + turn_right: false, + handbrake: false, + } + }; let rotation = self.base().get_rotation(); @@ -106,7 +123,7 @@ impl IRigidBody2D for Car { let front_wheel_velocity = self.wheel_velocity(&self.front_wheel); let rear_wheel_velocity = self.wheel_velocity(&self.rear_wheel); - let front_wheel_angle = match (turn_left, turn_right) { + let front_wheel_angle = match (user_input.turn_left, user_input.turn_right) { (true, false) => -self.steering_angle(), (false, true) => self.steering_angle(), (true, true) | (false, false) => 0.0, @@ -119,7 +136,7 @@ impl IRigidBody2D for Car { let rear_wheels_direction = forward; // Engine/thrust force - let thrust_force = match (move_forward, move_backward) { + let thrust_force = match (user_input.move_forward, user_input.move_backward) { (true, false) => self.engine_force * front_wheels_direction, (false, true) => { if forward.dot(self.base().get_linear_velocity()) > 0.0 { @@ -176,6 +193,25 @@ impl IRigidBody2D for Car { } impl Car { + fn user_input(&self) -> UserInput { + let gd_input = Input::singleton(); + let move_forward = gd_input.is_action_pressed("move_forward"); + let move_backward = gd_input.is_action_pressed("move_backward"); + let turn_left = gd_input.is_action_pressed("turn_left"); + let turn_right = gd_input.is_action_pressed("turn_right"); + + // TODO: Handbrake + let _handbrake = gd_input.is_action_pressed("handbrake"); + + UserInput { + move_forward, + move_backward, + turn_left, + turn_right, + handbrake: false, + } + } + fn cornering_force(&mut self, slip_angle: f32) -> Vector2 { debug_assert!(slip_angle.is_finite()); let right = self.right();