diff --git a/demo/bin/libSideScrollingShooter.linux.template_debug.x86_64.so b/demo/bin/libSideScrollingShooter.linux.template_debug.x86_64.so index c51f599..8c32515 100755 Binary files a/demo/bin/libSideScrollingShooter.linux.template_debug.x86_64.so and b/demo/bin/libSideScrollingShooter.linux.template_debug.x86_64.so differ diff --git a/demo/godot/Scenes/Bullets/bullet.tscn b/demo/godot/Scenes/Bullets/bullet.tscn index 00a5e08..e34eb5e 100644 --- a/demo/godot/Scenes/Bullets/bullet.tscn +++ b/demo/godot/Scenes/Bullets/bullet.tscn @@ -1,21 +1,14 @@ -[gd_scene load_steps=5 format=3 uid="uid://do4a4d3u60iy1"] +[gd_scene load_steps=3 format=3 uid="uid://do4a4d3u60iy1"] -[ext_resource type="Script" uid="uid://dyr00ngj1j5le" path="res://godot/Scripts/bullet.gd" id="1_utvym"] [ext_resource type="Texture2D" uid="uid://d07qtvmhqjjts" path="res://non-godot/Textures/Bullet.png" id="2_xbn07"] [ext_resource type="AudioStream" uid="uid://b4r0manp60hb4" path="res://non-godot/Sound/HitHurt.ogg" id="3_qwtek"] -[sub_resource type="CircleShape2D" id="CircleShape2D_ad2gx"] -radius = 14.0 - -[node name="Bullet" type="RigidBody2D" groups=["Bullet"]] +[node name="Bullet" type="Bullet" groups=["Bullet"]] +Direction = Vector2(1, 0) gravity_scale = 0.0 lock_rotation = true contact_monitor = true max_contacts_reported = 1 -script = ExtResource("1_utvym") - -[node name="CollisionShape2D" type="CollisionShape2D" parent="."] -shape = SubResource("CircleShape2D_ad2gx") [node name="Sprite2D" type="Sprite2D" parent="."] position = Vector2(1.42109e-14, 1) diff --git a/demo/godot/Scenes/player.tscn b/demo/godot/Scenes/player.tscn index 9f0ceac..90d6712 100644 --- a/demo/godot/Scenes/player.tscn +++ b/demo/godot/Scenes/player.tscn @@ -1,15 +1,11 @@ -[gd_scene load_steps=13 format=3 uid="uid://bjbccem28ir8r"] +[gd_scene load_steps=11 format=3 uid="uid://bjbccem28ir8r"] [ext_resource type="Texture2D" uid="uid://bcbjh2amre7ke" path="res://non-godot/Textures/Plane/PlaneUp.png" id="1_2h3i0"] [ext_resource type="PackedScene" uid="uid://do4a4d3u60iy1" path="res://godot/Scenes/Bullets/bullet.tscn" id="1_edjcf"] [ext_resource type="Texture2D" uid="uid://c5kt81t5h4vgn" path="res://non-godot/Textures/Plane/Plane.png" id="3_5g2vf"] -[ext_resource type="AudioStream" uid="uid://dg1f8fv4a2jdm" path="res://non-godot/Sound/Explosion.ogg" id="3_apj4i"] [ext_resource type="Texture2D" uid="uid://bff4pkabs2ecf" path="res://non-godot/Textures/Plane/PlaneDown.png" id="3_edjcf"] [ext_resource type="AudioStream" uid="uid://do4a5aj5a0216" path="res://non-godot/Sound/Shoot.ogg" id="4_m3gyy"] -[sub_resource type="RectangleShape2D" id="RectangleShape2D_u1ywu"] -size = Vector2(1920, 720) - [sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_xtmdc"] particle_flag_disable_z = true emission_shape = 3 @@ -166,21 +162,11 @@ SpeedUp = &"SpeedUp" scale = Vector2(0.15, 0.15) motion_mode = 1 -[node name="Area2D" type="Area2D" parent="."] -position = Vector2(3, 3) - -[node name="EnemyCollider" type="CollisionShape2D" parent="Area2D"] -position = Vector2(0, -60) -shape = SubResource("RectangleShape2D_u1ywu") - -[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="Area2D"] -stream = ExtResource("3_apj4i") - [node name="Gun" type="Node2D" parent="."] position = Vector2(1, 1) [node name="Marker2D" type="Marker2D" parent="Gun"] -position = Vector2(85, 33) +position = Vector2(545.6666, 259) [node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="Gun"] stream = ExtResource("4_m3gyy") @@ -202,10 +188,6 @@ amount_ratio = 0.66 lifetime = 5.0 process_material = SubResource("ParticleProcessMaterial_xtmdc") -[node name="WallCollider" type="CollisionShape2D" parent="."] -position = Vector2(0, -60) -shape = SubResource("RectangleShape2D_u1ywu") - [node name="AnimationPlayer" type="AnimationPlayer" parent="."] libraries = { &"": SubResource("AnimationLibrary_vkafp") @@ -217,5 +199,3 @@ offset_top = -5294.0 offset_right = 5037.0 offset_bottom = 4706.0 color = Color(0, 0, 0, 0) - -[connection signal="body_entered" from="Area2D" to="." method="_on_area_2d_body_entered"] diff --git a/demo/godot/Scripts/bullet.gd b/demo/godot/Scripts/bullet.gd index 4ae28cb..595ae3d 100644 --- a/demo/godot/Scripts/bullet.gd +++ b/demo/godot/Scripts/bullet.gd @@ -1,30 +1,18 @@ extends RigidBody2D -var Speed = 1200 - var DespawnTimer: float = 5 var timer: float = 0 @export var EnemyBullet: bool = false # rotato is here to fix a fucking bug. Thanks engine! @export var rotato: float -var Direction: Vector2 = Vector2(0, 0) func _integrate_forces(_state: PhysicsDirectBodyState2D): - self.linear_velocity = Direction * Speed self.rotation_degrees = rotato - # Direction using trig - Direction = Vector2(cos(deg_to_rad(rotato)), sin(deg_to_rad(rotato))) # Flip it correctly when rotated if rotato > 90 and rotato <= 270: get_node("Sprite2D").flip_v = true -func _physics_process(delta: float): - # Despawn to stop game from lagging - timer += delta - if timer >= DespawnTimer: - self.queue_free() - func _on_body_entered(body: Node) -> void: # Bullets collide into each other sometimes. Remove it by putting bullets into a group. if !body.is_in_group("Bullet") and EnemyBullet != true and body.is_in_group("Enemy"): diff --git a/demo/non-godot/Textures/Plane/Plane.png b/demo/non-godot/Textures/Plane/Plane.png index 092ab10..fd7d084 100644 Binary files a/demo/non-godot/Textures/Plane/Plane.png and b/demo/non-godot/Textures/Plane/Plane.png differ diff --git a/demo/non-godot/Textures/Plane/PlaneDown.png b/demo/non-godot/Textures/Plane/PlaneDown.png index e36a53d..7ede50c 100644 Binary files a/demo/non-godot/Textures/Plane/PlaneDown.png and b/demo/non-godot/Textures/Plane/PlaneDown.png differ diff --git a/demo/non-godot/Textures/Plane/PlaneUp.png b/demo/non-godot/Textures/Plane/PlaneUp.png index cd54506..dc9b5e1 100644 Binary files a/demo/non-godot/Textures/Plane/PlaneUp.png and b/demo/non-godot/Textures/Plane/PlaneUp.png differ diff --git a/src/Bullet.cpp b/src/Bullet.cpp index 935fa94..0524b58 100644 --- a/src/Bullet.cpp +++ b/src/Bullet.cpp @@ -5,16 +5,68 @@ #include #include +#include +#include + namespace godot { Bullet::Bullet() { + Sprite = memnew(Sprite2D); + CollisionShape2D* Collision = memnew(CollisionShape2D); + RectangleShape2D* CollisionShape = memnew(RectangleShape2D); + Collision->set_shape(CollisionShape); + + add_child(Sprite); + add_child(Collision); } Bullet::~Bullet() { - + queue_free(); } void Bullet::_bind_methods() { - + ClassDB::bind_method(D_METHOD("GetSpeed"), &Bullet::GetSpeed); + ClassDB::bind_method(D_METHOD("SetSpeed", "Speed"), &Bullet::SetSpeed); + ClassDB::add_property("Bullet", PropertyInfo(Variant::INT, "Speed"), "SetSpeed", "GetSpeed"); + ClassDB::bind_method(D_METHOD("GetDirection"), &Bullet::GetDirection); + ClassDB::bind_method(D_METHOD("SetDirection", "Direction"), &Bullet::SetDirection); + ClassDB::add_property("Bullet", PropertyInfo(Variant::VECTOR2, "Direction"), "SetDirection", "GetDirection"); + } + + void Bullet::_integrate_forces(PhysicsDirectBodyState2D* state) { + if (Engine::get_singleton()->is_editor_hint()) { + return; + } + set_linear_velocity(Direction * Speed); + if (Sprite->get_rotation_degrees() > 90 && Sprite->get_rotation_degrees() <= 270) { + Sprite->set_flip_v(true); + } else { + Sprite->set_flip_v(false); + } + } + + void Bullet::_physics_process(double delta) { + if (Engine::get_singleton()->is_editor_hint()) { + return; + } + DespawnTimer += delta; + if (DespawnTimer >= DespawnTime) { + queue_free(); + } + } + + // Getters and setters + int Bullet::GetSpeed() const { + return Speed; + } + Vector2 Bullet::GetDirection() const { + return Direction; + } + + void Bullet::SetSpeed(const int speed) { + Speed = speed; + } + void Bullet::SetDirection(const Vector2 direction) { + Direction = direction; } }; diff --git a/src/Bullet.hpp b/src/Bullet.hpp index 50b395b..2e8c934 100644 --- a/src/Bullet.hpp +++ b/src/Bullet.hpp @@ -2,13 +2,21 @@ #define BULLET_HPP #include +#include +#include namespace godot { class Bullet : public RigidBody2D { GDCLASS(Bullet, RigidBody2D) private: - int nothing = 0; + int Speed = 1200; + Vector2 Direction; + double DespawnTime = 5; + double DespawnTimer = 0; + + // Nodes + Sprite2D* Sprite; protected: static void _bind_methods(); @@ -16,6 +24,16 @@ namespace godot { public: Bullet(); ~Bullet(); + + void _integrate_forces(PhysicsDirectBodyState2D* state) override; + void _physics_process(double delta) override; + + // Getters and setters + int GetSpeed() const; + Vector2 GetDirection() const; + + void SetSpeed(const int speed); + void SetDirection(const Vector2 direction); }; }; diff --git a/src/Enemy.cpp b/src/Enemy.cpp index 641de94..c889648 100644 --- a/src/Enemy.cpp +++ b/src/Enemy.cpp @@ -11,7 +11,7 @@ namespace godot { } Enemy::~Enemy() { - + queue_free(); } void Enemy::_bind_methods() { diff --git a/src/Player.cpp b/src/Player.cpp index d7fed20..67fdd58 100644 --- a/src/Player.cpp +++ b/src/Player.cpp @@ -6,16 +6,14 @@ #include #include -#include -#include #include #include namespace godot { Player::Player() { - CollisionShape2D* Collision = memnew(CollisionShape2D); - RectangleShape2D* CollisionShape = memnew(RectangleShape2D); + Collision = memnew(CollisionShape2D); + CollisionShape = memnew(RectangleShape2D); Sprite = memnew(Sprite2D); Collision->set_shape(CollisionShape); @@ -84,6 +82,7 @@ namespace godot { int TheSpeed = Speed; FireRateTimer += delta; Sprite->set_texture(PlayerNeutral); + CollisionShape->set_size(Vector2(PlayerNeutral->get_width(), PlayerNeutral->get_height())); if (Engine::get_singleton()->is_editor_hint()) { return; diff --git a/src/Player.hpp b/src/Player.hpp index b68a422..dbd3a5a 100644 --- a/src/Player.hpp +++ b/src/Player.hpp @@ -4,6 +4,8 @@ #include #include +#include +#include #include #include #include @@ -17,7 +19,7 @@ namespace godot { int Health = 3; int Speed = 500; bool Invulnerable = false; - double InvulnerabilityTime = 3.0; + double InvulnerabilityTime = 3; double InvulnerabilityTimer = 0; bool PlayerControl = true; @@ -41,6 +43,8 @@ namespace godot { // Nodes Sprite2D* Sprite; + CollisionShape2D* Collision; + RectangleShape2D* CollisionShape; protected: static void _bind_methods(); diff --git a/src/Wave.cpp b/src/Wave.cpp index f9c1b43..d9e54c8 100644 --- a/src/Wave.cpp +++ b/src/Wave.cpp @@ -11,7 +11,7 @@ namespace godot { } Wave::~Wave() { - + queue_free(); } void Wave::_bind_methods() { diff --git a/src/gen/doc_data.gen.cpp b/src/gen/doc_data.gen.cpp index c688ca7..9bb954b 100644 --- a/src/gen/doc_data.gen.cpp +++ b/src/gen/doc_data.gen.cpp @@ -2,7 +2,7 @@ #include -static const char *_doc_data_hash = "125723246888636448"; +static const char *_doc_data_hash = "5307739025143130596"; static const int _doc_data_uncompressed_size = 0; static const int _doc_data_compressed_size = 8; static const unsigned char _doc_data_compressed[] = {