feat: implemented shield powerup and enemy cars

This commit is contained in:
Sara 2024-05-24 11:09:03 +02:00
parent a8f7bd20db
commit b8d487f14e
27 changed files with 353 additions and 114 deletions

View file

@ -13,7 +13,7 @@ radius = 0.308023
[node name="Beam" type="Beam"]
collision_layer = 0
collision_mask = 4
collision_mask = 2
monitorable = false
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]

View file

@ -1,11 +1,11 @@
[gd_scene load_steps=4 format=3 uid="uid://d0ir0dpghkikq"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_36cjj"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_nvwav"]
shading_mode = 0
albedo_color = Color(0.227451, 0.827451, 0.678431, 1)
albedo_color = Color(1, 0.415825, 0.249137, 1)
[sub_resource type="CapsuleMesh" id="CapsuleMesh_2fqgx"]
material = SubResource("StandardMaterial3D_36cjj")
[sub_resource type="CapsuleMesh" id="CapsuleMesh_gx8hk"]
material = SubResource("StandardMaterial3D_nvwav")
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_v1t6q"]
radius = 0.0869471
@ -17,7 +17,7 @@ monitorable = false
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0, 0)
mesh = SubResource("CapsuleMesh_2fqgx")
mesh = SubResource("CapsuleMesh_gx8hk")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0, 0)

View file

@ -1,10 +1,11 @@
[gd_scene load_steps=14 format=3 uid="uid://dkvgi7x2epurk"]
[gd_scene load_steps=15 format=3 uid="uid://dkvgi7x2epurk"]
[ext_resource type="PackedScene" uid="uid://1eawpg0buvah" path="res://GameObjects/player_turret.tscn" id="1_ing2c"]
[ext_resource type="PackedScene" uid="uid://bm2mavtmnbaw1" path="res://Models/CarParts/SM_Veh_Hatch_01.fbx" id="1_tymeg"]
[ext_resource type="PackedScene" uid="uid://cr1ytl0o43ftv" path="res://GameObjects/beacon_powerup.tscn" id="1_uhbx0"]
[ext_resource type="PackedScene" uid="uid://bfq7ipx01ag7p" path="res://Models/CarParts/SM_Veh_Hatch_01_Bonnet_01.fbx" id="2_l8ox5"]
[ext_resource type="PackedScene" uid="uid://ci63le6giakt1" path="res://Models/CarParts/SM_Veh_Hatch_01_Front_Bumper_01.fbx" id="3_8ayy1"]
[ext_resource type="PackedScene" uid="uid://dihk5i2dqoorb" path="res://GameObjects/shield_powerup.tscn" id="3_pck3g"]
[ext_resource type="PackedScene" uid="uid://buhilfnxfvnor" path="res://Models/CarParts/SM_Veh_Hatch_01_Light_Covers_01.fbx" id="4_ebbck"]
[ext_resource type="PackedScene" uid="uid://bapool371ad5g" path="res://Models/CarParts/SM_Veh_Hatch_01_Rear_Bumper_01.fbx" id="5_v2arc"]
[ext_resource type="PackedScene" uid="uid://6qwqncti3xr2" path="res://Models/CarParts/SM_Veh_Hatch_01_Fenders_02.fbx" id="6_xu64x"]
@ -22,24 +23,24 @@ friction = 0.0
rough = true
absorbent = true
[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_4xe1s"]
points = PackedVector3Array(-1.155, -0.6, -3.48, 1.155, -0.6, -3.48, -1.155, -0.6, 1.405, 1.155, -0.6, 1.405, 1.155, -0.6, 2.81, -1.155, -0.6, 2.81, -1.155, 1.16, -3.48, 1.155, 1.16, -3.48, -1.155, 1.16, 0.65, 1.155, 1.16, 0.65, 1.155, 0.335, 2.81, -1.155, 0.335, 2.81)
[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_0bup5"]
points = PackedVector3Array(-1.055, -0.6, -2.11, 1.055, -0.6, -2.11, -1.055, -0.6, 1.405, 1.055, -0.6, 1.405, 0.7, -0.6, 2.155, -0.7, -0.6, 2.155, -0.71, 0.475, -2.11, 0.71, 0.475, -2.11, -0.71, 0.475, 0.11, 0.71, 0.475, 0.11, 0.675, -0.235, 2.04, -0.675, -0.235, 2.04)
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_p38n5"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_3cogn"]
radius = 0.48558
height = 2.765
height = 2.26312
[node name="CarPlayer" type="CarPlayer"]
turret_scene = ExtResource("1_ing2c")
beacon_scene = ExtResource("1_uhbx0")
shield_scene = ExtResource("1_uhbx0")
shield_scene = ExtResource("3_pck3g")
oversteer_curve = SubResource("Curve_dpk6q")
oversteer_curve_x_scale = 40.0
understeer_curve = SubResource("Curve_htvme")
understeer_curve_x_scale = 40.0
max_slide_speed = 10.0
oversteer_speed_penalty = 10.0
collision_layer = 7
collision_layer = 5
collision_mask = 3
mass = 1000.0
physics_material_override = SubResource("PhysicsMaterial_vwjm3")
@ -59,15 +60,15 @@ fov = 68.9128
[node name="Body" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.687824, 0.174572)
shape = SubResource("ConvexPolygonShape3D_4xe1s")
shape = SubResource("ConvexPolygonShape3D_0bup5")
[node name="FrontWheels" type="CollisionShape3D" parent="."]
transform = Transform3D(-4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0, 0, 1, 0, 0.156071, 1.51353)
shape = SubResource("CapsuleShape3D_p38n5")
transform = Transform3D(-4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0, 0, 1, 0, 0.156071, 1.46129)
shape = SubResource("CapsuleShape3D_3cogn")
[node name="BackWheels" type="CollisionShape3D" parent="."]
transform = Transform3D(-4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0, 0, 1, 0, 0.156071, -1.52522)
shape = SubResource("CapsuleShape3D_p38n5")
transform = Transform3D(-4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0, 0, 1, 0, 0.156071, -1.32497)
shape = SubResource("CapsuleShape3D_3cogn")
[node name="Mesh" parent="." instance=ExtResource("1_tymeg")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.372761, 0)

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=7 format=3 uid="uid://b3p3ikural0cq"]
[gd_scene load_steps=8 format=3 uid="uid://b3p3ikural0cq"]
[ext_resource type="PackedScene" uid="uid://dsi3prgr34t85" path="res://Models/SM_Veh_Armored_Truck_01.fbx" id="1_2m0nm"]
@ -16,17 +16,21 @@ rough = true
absorbent = true
[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_4xe1s"]
points = PackedVector3Array(-1.155, -0.6, -3.48, 1.155, -0.6, -3.48, -1.155, -0.6, 1.405, 1.155, -0.6, 1.405, 1.155, -0.6, 2.81, -1.155, -0.6, 2.81, -1.155, 1.16, -3.48, 1.155, 1.16, -3.48, -1.155, 1.16, 0.65, 1.155, 1.16, 0.65, 1.155, 0.335, 2.81, -1.155, 0.335, 2.81)
points = PackedVector3Array(-1.155, -0.6, -3.48, 1.155, -0.6, -3.48, -1.155, -0.6, 1.405, 1.155, -0.6, 1.405, 1.155, -0.6, 2.81, -1.155, -0.6, 2.81, -1.155, 1.16, -3.48, 1.155, 1.16, -3.48, -1.155, 1.16, 0.65, 1.155, 1.16, 0.65, 1.155, 0.335, 2.565, -1.155, 0.335, 2.565)
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_p38n5"]
radius = 0.48558
height = 2.765
[sub_resource type="BoxShape3D" id="BoxShape3D_a4n5y"]
size = Vector3(1.58301, 1, 0.363281)
[node name="EnemyCar" type="EnemyCar"]
oversteer_curve = SubResource("Curve_dpk6q")
oversteer_curve_x_scale = 40.0
understeer_curve = SubResource("Curve_htvme")
understeer_curve_x_scale = 40.0
acceleration = 10.0
max_slide_speed = 10.0
oversteer_speed_penalty = 10.0
collision_layer = 7
@ -43,9 +47,9 @@ contact_monitor = true
linear_damp_mode = 1
linear_damp = 0.5
[node name="Camera3D" type="Camera3D" parent="."]
transform = Transform3D(-1, -2.02334e-08, -8.50491e-08, -2.87879e-08, 0.994803, 0.10182, 8.25469e-08, 0.10182, -0.994803, 4.6449e-07, 2.24116, -4.7912)
fov = 68.9128
[node name="NavigationAgent3D" type="NavigationAgent3D" parent="."]
path_desired_distance = 8.0
target_desired_distance = 5.0
[node name="Body" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.27103, 0.174572)
@ -64,4 +68,8 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.31348, -0.510359)
[node name="Root Scene" parent="." instance=ExtResource("1_2m0nm")]
[node name="NavigationAgent3D" type="NavigationAgent3D" parent="."]
[node name="DamageArea" type="DamageArea" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.08846, 3.19529)
[node name="CollisionShape3D" type="CollisionShape3D" parent="DamageArea"]
shape = SubResource("BoxShape3D_a4n5y")

View file

@ -1,6 +1,6 @@
[gd_scene load_steps=7 format=3 uid="uid://1eawpg0buvah"]
[ext_resource type="PackedScene" uid="uid://d0ir0dpghkikq" path="res://GameObjects/beam.tscn" id="1_xm6id"]
[ext_resource type="PackedScene" uid="uid://b74cqcryut76c" path="res://GameObjects/anti_air_beam.tscn" id="1_newd3"]
[ext_resource type="PackedScene" uid="uid://v5p6ih28q6ro" path="res://Models/SM_Wep_Shotgun_Plasma_01.fbx" id="2_vsdye"]
[sub_resource type="CylinderMesh" id="CylinderMesh_1btvq"]
@ -18,7 +18,7 @@ radius = 0.392821
[node name="Turret" type="Turret"]
attack_classes = [&"EnemyTargetBody"]
beam_scene = ExtResource("1_xm6id")
beam_scene = ExtResource("1_newd3")
fire_time = 0.2
charge_time = 0.0
lock_time = 0.5

File diff suppressed because one or more lines are too long

View file

@ -41,7 +41,7 @@ shape = SubResource("BoxShape3D_rxnqc")
[node name="AwarenessArea" type="Area3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -15.7959, 0)
collision_layer = 0
collision_mask = 2
collision_mask = 6
monitorable = false
[node name="CollisionShape3D" type="CollisionShape3D" parent="AwarenessArea"]

File diff suppressed because one or more lines are too long

BIN
godot/Models/SM_Prop_Shield_Bubble_01.fbx (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -0,0 +1,41 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://b4huabphwko5m"
path="res://.godot/imported/SM_Prop_Shield_Bubble_01.fbx-7d4f4fd44777175048ae86eef9fd49b9.scn"
[deps]
source_file="res://Models/SM_Prop_Shield_Bubble_01.fbx"
dest_files=["res://.godot/imported/SM_Prop_Shield_Bubble_01.fbx-7d4f4fd44777175048ae86eef9fd49b9.scn"]
[params]
nodes/root_type=""
nodes/root_name=""
nodes/apply_root_scale=true
nodes/root_scale=1.0
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
meshes/force_disable_compression=false
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
import_script/path=""
_subresources={
"materials": {
"lambert27": {
"use_external/enabled": true,
"use_external/path": "res://Models/World/City/city.tres"
}
}
}
gltf/naming_version=1
gltf/embedded_image_handling=1

BIN
godot/Models/SimpleSky.png (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dgbcs774tvf4d"
path.s3tc="res://.godot/imported/SimpleSky.png-923f3134b6d4d5df241dd4b6ba4ed69e.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://Models/SimpleSky.png"
dest_files=["res://.godot/imported/SimpleSky.png-923f3134b6d4d5df241dd4b6ba4ed69e.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0

6
godot/Models/sky.tres Normal file
View file

@ -0,0 +1,6 @@
[gd_resource type="PanoramaSkyMaterial" load_steps=2 format=3 uid="uid://b3w42bhig0vhh"]
[ext_resource type="Texture2D" uid="uid://dgbcs774tvf4d" path="res://Models/SimpleSky.png" id="1_p6xiq"]
[resource]
panorama = ExtResource("1_p6xiq")

View file

@ -185,6 +185,10 @@ Vector3 CarPhysics::world_to_local_velocity() const {
};
}
float CarPhysics::get_current_speed() const {
return this->local_velocity.z;
}
void CarPhysics::set_target_speed(float target) {
this->target_speed = target;
}

View file

@ -40,6 +40,7 @@ public:
// convert the local_velocity to world coordinates
Vector3 local_to_world_velocity() const;
Vector3 world_to_local_velocity() const;
float get_current_speed() const;
void set_target_speed(float target);
float get_target_speed() const;
void set_current_steering(float steering);

View file

@ -64,6 +64,8 @@ void CarPlayer::destroy_all_powerups() {
for(int i = 0; i < this->roof_slot->get_child_count(); ++i) {
if(this->roof_slot->get_child(0)->is_class("Turret"))
Ref<RallyRushGameMode>(GameRoot3D::get_singleton()->get_game_mode())->notify_end_turret_pickup();
if(this->roof_slot->get_child(0)->is_class("ShieldPowerup"))
this->takes_damage = true;
this->roof_slot->get_child(0)->queue_free();
}
}
@ -81,7 +83,10 @@ void CarPlayer::activate_turret() {
this->activate_powerup(this->turret);
}
void CarPlayer::activate_beacon() { this->activate_powerup(this->beacon); }
void CarPlayer::activate_shield() { this->activate_powerup(this->turret); }
void CarPlayer::activate_shield() {
this->activate_powerup(this->shield);
this->takes_damage = false;
}
void CarPlayer::set_turret_scene(Ref<PackedScene> scene) {
this->turret = scene;

View file

@ -41,6 +41,7 @@ public:
private:
int health{5};
double end_of_powerup{0.0};
bool takes_damage{true};
Node3D *roof_slot{nullptr};

View file

@ -10,7 +10,9 @@ void DamageArea::_bind_methods() {
void DamageArea::_enter_tree() { GDGAMEONLY();
this->connect("body_entered", callable_mp(this, &DamageArea::body_entered));
this->anim = this->get_node<AnimationPlayer>("AnimationPlayer");
if(this->has_node("AnimationPlayer"))
this->anim = this->get_node<AnimationPlayer>("AnimationPlayer");
this->car = Object::cast_to<EnemyCar>(this->get_parent());
}
void DamageArea::_process(double delta_time) {
@ -19,8 +21,9 @@ void DamageArea::_process(double delta_time) {
}
void DamageArea::body_entered(Node3D *node) {
if(this->target_classes.has(node->get_class()))
if(this->target_classes.has(node->get_class()) && (!this->car || this->car->get_current_speed() > 30)) {
node->call("damage");
}
}
void DamageArea::set_target_classes(Array array) {

View file

@ -1,6 +1,7 @@
#ifndef DAMAGE_AREA_HPP
#define DAMAGE_AREA_HPP
#include "enemy_car.hpp"
#include "godot_cpp/classes/animation_player.hpp"
#include <godot_cpp/classes/area3d.hpp>
#include <godot_cpp/templates/vector.hpp>
@ -18,6 +19,7 @@ protected:
Array get_target_classes() const;
private:
Vector<StringName> target_classes{};
EnemyCar *car{nullptr};
AnimationPlayer *anim{nullptr};
};
}

View file

@ -1,6 +1,7 @@
#include "drone.hpp"
#include "godot_cpp/classes/animation_player.hpp"
#include "godot_cpp/classes/global_constants.hpp"
#include "godot_cpp/variant/utility_functions.hpp"
#include "rally_rush_game_mode.hpp"
#include "utils/game_root.hpp"
#include "utils/godot_macros.h"
@ -85,11 +86,13 @@ void Drone::key_found(int total) {
}
void Drone::start_flee() {
UtilityFunctions::print(this->get_path(), " flee");
if(this->state == DroneState::CHASE)
this->state = DroneState::FLEE;
}
void Drone::end_flee() {
UtilityFunctions::print(this->get_path(), " chase");
if(this->state == DroneState::FLEE)
this->state = DroneState::CHASE;
}

View file

@ -20,6 +20,10 @@ void EnemyCar::_process(double delta_time) { GDGAMEONLY();
this->process_navigate();
}
void EnemyCar::damage() {
this->queue_free();
}
void EnemyCar::process_navigate() {
--this->next_recalc;
if(this->next_recalc <= 0)
@ -27,9 +31,9 @@ void EnemyCar::process_navigate() {
Vector3 const target_direction{this->agent->get_next_path_position() - this->get_global_position()};
Vector3 const direction{this->get_global_basis().get_column(2)};
float const ang_dif = target_direction.signed_angle_to(direction.normalized(), this->get_global_basis().get_column(1));
this->set_target_speed(this->max_speed);
bool const slow = target_direction.length() < this->brake_distance && this->get_current_speed() > 3.f;
this->set_target_speed(slow ? this->turn_target_speed : this->max_speed);
this->set_current_steering(Math::abs(ang_dif) * this->steering_speed);
this->set_brake(target_direction.length() < this->brake_distance);
}
void EnemyCar::recalculate_navigation() {

View file

@ -18,11 +18,11 @@ protected:
void recalculate_navigation();
private:
int next_recalc{0};
int recalc_frame_interval{10};
int recalc_frame_interval{60};
float turn_target_speed{3.f};
float max_speed{45.f};
float brake_distance{7.f};
float steering_speed{1.f};
float steering_speed{1.5f};
NavigationAgent3D *agent{nullptr};
CarPlayer *player{nullptr};
};

View file

@ -10,6 +10,8 @@ void RallyRushGameMode::_bind_methods() {
GDSIGNAL("all_keys_found");
GDSIGNAL("turret_pickup");
GDSIGNAL("end_turret_pickup");
GDSIGNAL("shield_pickup");
GDSIGNAL("end_shield_pickup");
}
int RallyRushGameMode::get_num_found_keys() {
@ -31,6 +33,14 @@ void RallyRushGameMode::notify_end_turret_pickup() {
this->emit_signal("end_turret_pickup");
}
void RallyRushGameMode::notify_shield_pickup() {
this->emit_signal("shield_pickup");
}
void RallyRushGameMode::notify_end_shield_pickup() {
this->emit_signal("end_shield_pickup");
}
#define GAME_END_SCENE "res://Levels/game_end_screen.tscn"
void RallyRushGameMode::notify_player_death() {
GameRoot3D::get_singleton()->replace_levels(ResourceLoader::get_singleton()->load(GAME_END_SCENE));

View file

@ -14,6 +14,8 @@ public:
void notify_player_escaped();
void notify_turret_pickup();
void notify_end_turret_pickup();
void notify_shield_pickup();
void notify_end_shield_pickup();
private:
int num_keys_found{0};
};

View file

@ -15,6 +15,7 @@
#include "key_pickup.hpp"
#include "menu_ui.hpp"
#include "rally_rush_game_mode.hpp"
#include "shield_powerup.hpp"
#include "spawner.hpp"
#include "turret.hpp"
#include "utils/game_mode.hpp"
@ -62,6 +63,7 @@ void initialize_gdextension_types(ModuleInitializationLevel p_level)
ClassDB::register_class<WeaponPickup>();
ClassDB::register_class<BeaconPowerup>();
ClassDB::register_class<EnemyCar>();
ClassDB::register_class<ShieldPowerup>();
}
extern "C"

18
src/shield_powerup.cpp Normal file
View file

@ -0,0 +1,18 @@
#include "shield_powerup.hpp"
#include "enemy_car.hpp"
#include "utils/godot_macros.h"
namespace godot {
void ShieldPowerup::_bind_methods() {
#define CLASSNAME ShieldPowerup
}
void ShieldPowerup::_enter_tree() { GDGAMEONLY();
this->connect("body_entered", callable_mp(this, &ShieldPowerup::body_entered));
}
void ShieldPowerup::body_entered(Node3D *body) {
EnemyCar *car = Object::cast_to<EnemyCar>(body);
if(car) car->damage();
}
}

17
src/shield_powerup.hpp Normal file
View file

@ -0,0 +1,17 @@
#ifndef SHIELD_POWERUP_HPP
#define SHIELD_POWERUP_HPP
#include <godot_cpp/classes/area3d.hpp>
namespace godot {
class ShieldPowerup : public Area3D {
GDCLASS(ShieldPowerup, Area3D);
static void _bind_methods();
public:
virtual void _enter_tree() override;
protected:
void body_entered(Node3D *body);
};
}
#endif // !SHIELD_POWERUP_HPP