diff --git a/demo/bin/libSideScrollingShooter.linux.template_debug.x86_64.so b/demo/bin/libSideScrollingShooter.linux.template_debug.x86_64.so index a10083e..cd45c8a 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/Enemies/enemy.tscn b/demo/godot/Scenes/Enemies/enemy.tscn index c68282e..c09c159 100644 --- a/demo/godot/Scenes/Enemies/enemy.tscn +++ b/demo/godot/Scenes/Enemies/enemy.tscn @@ -1,63 +1,60 @@ -[gd_scene load_steps=15 format=3 uid="uid://8l43dsk30uq3"] +[gd_scene load_steps=13 format=3 uid="uid://8l43dsk30uq3"] -[ext_resource type="Script" uid="uid://csmqifafakbu4" path="res://godot/Scripts/enemy.gd" id="1_4aawx"] -[ext_resource type="Texture2D" uid="uid://blrbc8mp71nub" path="res://non-godot/Textures/Route/Route 1.png" id="2_h84n4"] -[ext_resource type="Texture2D" uid="uid://cphw4low4de4b" path="res://non-godot/Textures/Route/Route 2.png" id="3_tnxi1"] -[ext_resource type="Texture2D" uid="uid://dwdn12rkkr1uo" path="res://non-godot/Textures/Route/Route 3.png" id="4_8tegk"] -[ext_resource type="Texture2D" uid="uid://bbupn4br1fog7" path="res://non-godot/Textures/Route/Route 4.png" id="5_nodwr"] -[ext_resource type="Texture2D" uid="uid://tfbp816emics" path="res://non-godot/Textures/Route/Route 5.png" id="6_dky81"] -[ext_resource type="Texture2D" uid="uid://cl0sil1psnxs1" path="res://non-godot/Textures/Route/Route 6.png" id="7_lif88"] -[ext_resource type="Texture2D" uid="uid://cgv78fuua01eg" path="res://non-godot/Textures/Route/Route 7.png" id="8_slcma"] -[ext_resource type="Texture2D" uid="uid://y2e4mmb2u3h5" path="res://non-godot/Textures/Route/Route 8.png" id="9_g78pb"] -[ext_resource type="Texture2D" uid="uid://cfonr11og4um" path="res://non-godot/Textures/Route/Route 9.png" id="10_i4jqp"] -[ext_resource type="Texture2D" uid="uid://dtgyeeu1t0n7h" path="res://non-godot/Textures/Route/Route 10.png" id="11_skrsr"] -[ext_resource type="Texture2D" uid="uid://b1xcgdrf6sdbp" path="res://non-godot/Textures/Route/Route 11.png" id="12_gr3uw"] +[ext_resource type="Texture2D" uid="uid://blrbc8mp71nub" path="res://non-godot/Textures/Route/Route 1.png" id="1_uik3p"] +[ext_resource type="Texture2D" uid="uid://cphw4low4de4b" path="res://non-godot/Textures/Route/Route 2.png" id="2_pc1hf"] +[ext_resource type="Texture2D" uid="uid://dwdn12rkkr1uo" path="res://non-godot/Textures/Route/Route 3.png" id="3_oe5f7"] +[ext_resource type="Texture2D" uid="uid://bbupn4br1fog7" path="res://non-godot/Textures/Route/Route 4.png" id="4_kv6ro"] +[ext_resource type="Texture2D" uid="uid://tfbp816emics" path="res://non-godot/Textures/Route/Route 5.png" id="5_t3tp2"] +[ext_resource type="Texture2D" uid="uid://cl0sil1psnxs1" path="res://non-godot/Textures/Route/Route 6.png" id="6_rev51"] +[ext_resource type="Texture2D" uid="uid://cgv78fuua01eg" path="res://non-godot/Textures/Route/Route 7.png" id="7_1lddk"] +[ext_resource type="Texture2D" uid="uid://y2e4mmb2u3h5" path="res://non-godot/Textures/Route/Route 8.png" id="8_361xq"] +[ext_resource type="Texture2D" uid="uid://cfonr11og4um" path="res://non-godot/Textures/Route/Route 9.png" id="9_cvp1u"] +[ext_resource type="Texture2D" uid="uid://dtgyeeu1t0n7h" path="res://non-godot/Textures/Route/Route 10.png" id="10_u6cmc"] +[ext_resource type="Texture2D" uid="uid://b1xcgdrf6sdbp" path="res://non-godot/Textures/Route/Route 11.png" id="11_v2k31"] -[sub_resource type="SpriteFrames" id="SpriteFrames_48384"] +[sub_resource type="SpriteFrames" id="SpriteFrames_4uncb"] animations = [{ "frames": [{ "duration": 1.0, -"texture": ExtResource("2_h84n4") +"texture": ExtResource("1_uik3p") }, { "duration": 1.0, -"texture": ExtResource("3_tnxi1") +"texture": ExtResource("2_pc1hf") }, { "duration": 1.0, -"texture": ExtResource("4_8tegk") +"texture": ExtResource("3_oe5f7") }, { "duration": 1.0, -"texture": ExtResource("5_nodwr") +"texture": ExtResource("4_kv6ro") }, { "duration": 1.0, -"texture": ExtResource("6_dky81") +"texture": ExtResource("5_t3tp2") }, { "duration": 1.0, -"texture": ExtResource("7_lif88") +"texture": ExtResource("6_rev51") }, { "duration": 1.0, -"texture": ExtResource("8_slcma") +"texture": ExtResource("7_1lddk") }, { "duration": 1.0, -"texture": ExtResource("9_g78pb") +"texture": ExtResource("8_361xq") }, { "duration": 1.0, -"texture": ExtResource("10_i4jqp") +"texture": ExtResource("9_cvp1u") }, { "duration": 1.0, -"texture": ExtResource("11_skrsr") +"texture": ExtResource("10_u6cmc") }, { "duration": 1.0, -"texture": ExtResource("12_gr3uw") +"texture": ExtResource("11_v2k31") }], "loop": true, "name": &"default", "speed": 22.0 }] -[sub_resource type="RectangleShape2D" id="RectangleShape2D_t28hd"] -size = Vector2(77, 77) - -[node name="Enemy" type="RigidBody2D" groups=["Enemy"]] +[node name="Enemy" type="Enemy" groups=["Enemy"]] +Frames = SubResource("SpriteFrames_4uncb") collision_layer = 3 collision_mask = 3 mass = 50.0 @@ -66,20 +63,3 @@ lock_rotation = true custom_integrator = true contact_monitor = true max_contacts_reported = 1 -script = ExtResource("1_4aawx") - -[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] -position = Vector2(-9, 4) -scale = Vector2(0.08, 0.08) -sprite_frames = SubResource("SpriteFrames_48384") -autoplay = "default" -frame_progress = 0.329504 - -[node name="CollisionShape2D" type="CollisionShape2D" parent="."] -position = Vector2(0.5, 0.5) -shape = SubResource("RectangleShape2D_t28hd") - -[node name="Arm" type="Node2D" parent="."] - -[node name="Marker2D" type="Marker2D" parent="Arm"] -position = Vector2(-130, 0) diff --git a/demo/godot/Scripts/enemy.gd b/demo/godot/Scripts/enemy.gd deleted file mode 100644 index 8b13789..0000000 --- a/demo/godot/Scripts/enemy.gd +++ /dev/null @@ -1 +0,0 @@ - diff --git a/demo/godot/Scripts/enemy.gd.uid b/demo/godot/Scripts/enemy.gd.uid deleted file mode 100644 index c3495b0..0000000 --- a/demo/godot/Scripts/enemy.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://csmqifafakbu4 diff --git a/demo/non-godot/Textures/Route/Route 1.png b/demo/non-godot/Textures/Route/Route 1.png index 285f817..3846816 100644 Binary files a/demo/non-godot/Textures/Route/Route 1.png and b/demo/non-godot/Textures/Route/Route 1.png differ diff --git a/demo/non-godot/Textures/Route/Route 10.png b/demo/non-godot/Textures/Route/Route 10.png index d797321..9e59b7c 100644 Binary files a/demo/non-godot/Textures/Route/Route 10.png and b/demo/non-godot/Textures/Route/Route 10.png differ diff --git a/demo/non-godot/Textures/Route/Route 11.png b/demo/non-godot/Textures/Route/Route 11.png index 970c666..3846816 100644 Binary files a/demo/non-godot/Textures/Route/Route 11.png and b/demo/non-godot/Textures/Route/Route 11.png differ diff --git a/demo/non-godot/Textures/Route/Route 2.png b/demo/non-godot/Textures/Route/Route 2.png index 4d8dd74..d05308b 100644 Binary files a/demo/non-godot/Textures/Route/Route 2.png and b/demo/non-godot/Textures/Route/Route 2.png differ diff --git a/demo/non-godot/Textures/Route/Route 3.png b/demo/non-godot/Textures/Route/Route 3.png index 87ef92d..5c4e382 100644 Binary files a/demo/non-godot/Textures/Route/Route 3.png and b/demo/non-godot/Textures/Route/Route 3.png differ diff --git a/demo/non-godot/Textures/Route/Route 4.png b/demo/non-godot/Textures/Route/Route 4.png index c78cb2e..9604a50 100644 Binary files a/demo/non-godot/Textures/Route/Route 4.png and b/demo/non-godot/Textures/Route/Route 4.png differ diff --git a/demo/non-godot/Textures/Route/Route 5.png b/demo/non-godot/Textures/Route/Route 5.png index b5188f9..0830013 100644 Binary files a/demo/non-godot/Textures/Route/Route 5.png and b/demo/non-godot/Textures/Route/Route 5.png differ diff --git a/demo/non-godot/Textures/Route/Route 6.png b/demo/non-godot/Textures/Route/Route 6.png index 76b518f..855ef81 100644 Binary files a/demo/non-godot/Textures/Route/Route 6.png and b/demo/non-godot/Textures/Route/Route 6.png differ diff --git a/demo/non-godot/Textures/Route/Route 7.png b/demo/non-godot/Textures/Route/Route 7.png index 2fca92f..486be1a 100644 Binary files a/demo/non-godot/Textures/Route/Route 7.png and b/demo/non-godot/Textures/Route/Route 7.png differ diff --git a/demo/non-godot/Textures/Route/Route 8.png b/demo/non-godot/Textures/Route/Route 8.png index 2b43fe6..59238ba 100644 Binary files a/demo/non-godot/Textures/Route/Route 8.png and b/demo/non-godot/Textures/Route/Route 8.png differ diff --git a/demo/non-godot/Textures/Route/Route 9.png b/demo/non-godot/Textures/Route/Route 9.png index c9db33c..a3f5846 100644 Binary files a/demo/non-godot/Textures/Route/Route 9.png and b/demo/non-godot/Textures/Route/Route 9.png differ diff --git a/src/Enemy.cpp b/src/Enemy.cpp index 219b069..2d69743 100644 --- a/src/Enemy.cpp +++ b/src/Enemy.cpp @@ -7,7 +7,16 @@ namespace godot { Enemy::Enemy() { + Sprite = memnew(AnimatedSprite2D); + Collision = memnew(CollisionShape2D); + CollisionShape = memnew(RectangleShape2D); + Collision->set_shape(CollisionShape); + SetFrames(memnew(SpriteFrames)); + Sprite->set_autoplay("default"); + + add_child(Collision); + add_child(Sprite); } Enemy::~Enemy() { @@ -21,13 +30,16 @@ namespace godot { ClassDB::add_property("Enemy", PropertyInfo(Variant::INT, "Health"), "SetHealth", "GetHealth"); ClassDB::bind_method(D_METHOD("GetSpeed"), &Enemy::GetSpeed); ClassDB::bind_method(D_METHOD("SetSpeed", "Speed"), &Enemy::SetSpeed); - ClassDB::add_property("Enemy", PropertyInfo(Variant::INT, "Speed"), "SetUp", "GetUp"); + ClassDB::add_property("Enemy", PropertyInfo(Variant::INT, "Speed"), "SetSpeed", "GetSpeed"); ClassDB::bind_method(D_METHOD("GetDirection"), &Enemy::GetDirection); ClassDB::bind_method(D_METHOD("SetDirection", "Direction"), &Enemy::SetDirection); ClassDB::add_property("Enemy", PropertyInfo(Variant::VECTOR2, "Direction"), "SetDirection", "GetDirection"); ClassDB::bind_method(D_METHOD("GetScoreAmount"), &Enemy::GetScoreAmount); ClassDB::bind_method(D_METHOD("SetScoreAmount", "ScoreAmount"), &Enemy::SetScoreAmount); ClassDB::add_property("Enemy", PropertyInfo(Variant::INT, "ScoreAmount"), "SetScoreAmount", "GetScoreAmount"); + ClassDB::bind_method(D_METHOD("GetFrames"), &Enemy::GetFrames); + ClassDB::bind_method(D_METHOD("SetFrames", "Frames"), &Enemy::SetFrames); + ClassDB::add_property("Enemy", PropertyInfo(Variant::OBJECT, "Frames", PROPERTY_HINT_RESOURCE_TYPE, "SpriteFrames"), "SetFrames", "GetFrames"); // Shooting ClassDB::add_property_group("Enemy", "Shooting", "Shot"); @@ -40,6 +52,9 @@ namespace godot { ClassDB::bind_method(D_METHOD("GetBulletDirection"), &Enemy::GetBulletDirection); ClassDB::bind_method(D_METHOD("SetBulletDirection", "BulletDirection"), &Enemy::SetBulletDirection); ClassDB::add_property("Enemy", PropertyInfo(Variant::FLOAT, "ShotBulletDirection"), "SetBulletDirection", "GetBulletDirection"); + ClassDB::bind_method(D_METHOD("GetBulletTexture"), &Enemy::GetBulletTexture); + ClassDB::bind_method(D_METHOD("SetBulletTexture", "BulletTexture"), &Enemy::SetBulletTexture); + ClassDB::add_property("Enemy", PropertyInfo(Variant::OBJECT, "ShotBulletTexture"), "SetBulletTexture", "GetBulletTexture"); // Signals ClassDB::add_signal("Enemy", MethodInfo("AddScore")); @@ -54,24 +69,27 @@ namespace godot { set_linear_velocity(Direction * Speed); } void Enemy::_physics_process(double delta) { + if (Frames->get_frame_count("default") != 0) { + CollisionShape->set_size(Vector2(Frames->get_frame_texture("default", Sprite->get_frame())->get_width(), Frames->get_frame_texture("default", Sprite->get_frame())->get_height())); + } if (Engine::get_singleton()->is_editor_hint()) { return; } + // Memfree despawn. DespawnTimer += delta; - - // Memfree despawn if (DespawnTimer >= 30) { queue_free(); } - // Shooting + // Shooting. if (IsShooting == true) { FireRateTimer += delta; if (FireRateTimer >= FireRate) { Bullet* bullet = memnew(Bullet); - bullet->set_position(get_position()); + bullet->set_position(BulletLocation + get_position()); + bullet->SetTexture(BulletTexture); bullet->SetDirection(BulletDirection); bullet->add_collision_exception_with(get_node(get_path())); get_parent()->add_child(bullet); @@ -79,7 +97,7 @@ namespace godot { } } - // Dying + // Dying. if (Health <= 0) { emit_signal("AddScore"); queue_free(); @@ -99,6 +117,9 @@ namespace godot { int Enemy::GetScoreAmount() const { return ScoreAmount; } + Ref Enemy::GetFrames() const { + return Frames; + } bool Enemy::GetIsShooting() const { return IsShooting; } @@ -108,6 +129,12 @@ namespace godot { Vector2 Enemy::GetBulletDirection() const { return BulletDirection; } + Ref Enemy::GetBulletTexture() const { + return BulletTexture; + } + Vector2 Enemy::GetBulletLocation() const { + return BulletLocation; + } void Enemy::SetHealth(const int health) { Health = health; @@ -121,6 +148,10 @@ namespace godot { void Enemy::SetScoreAmount(const int scoreAmount) { ScoreAmount = scoreAmount; } + void Enemy::SetFrames(const Ref& spriteFrames) { + Frames = spriteFrames; + Sprite->set_sprite_frames(spriteFrames); + } void Enemy::SetIsShooting(const bool isShooting) { IsShooting = isShooting; } @@ -130,4 +161,10 @@ namespace godot { void Enemy::SetBulletDirection(const Vector2 bulletDirection) { BulletDirection = bulletDirection; } + void Enemy::SetBulletTexture(const Ref& bulletTexture) { + BulletTexture = bulletTexture; + } + void Enemy::SetBulletLocation(const Vector2 bulletLocation) { + BulletLocation = bulletLocation; + } }; diff --git a/src/Enemy.hpp b/src/Enemy.hpp index 9534f52..9f4ec58 100644 --- a/src/Enemy.hpp +++ b/src/Enemy.hpp @@ -3,6 +3,11 @@ #include #include +#include +#include +#include +#include +#include #include "Bullet.hpp" @@ -11,16 +16,27 @@ namespace godot { GDCLASS(Enemy, RigidBody2D) private: + // General int Health = 5; int Speed = 250; Vector2 Direction = Vector2(-1, 0); int ScoreAmount = 200; + Ref Frames; + double DespawnTimer = 0; + + // Shooting bool IsShooting = false; double FireRate = 1; double FireRateTimer = 0; Vector2 BulletDirection = Vector2(-1, 0); - double DespawnTimer = 0; + Ref BulletTexture; + Vector2 BulletLocation = Vector2(0, 0); + + // Nodes + AnimatedSprite2D* Sprite; + CollisionShape2D* Collision; + RectangleShape2D* CollisionShape; protected: static void _bind_methods(); @@ -37,17 +53,23 @@ namespace godot { int GetSpeed() const; Vector2 GetDirection() const; int GetScoreAmount() const; + Ref GetFrames() const; bool GetIsShooting() const; double GetFireRate() const; Vector2 GetBulletDirection() const; + Ref GetBulletTexture() const; + Vector2 GetBulletLocation() const; void SetHealth(const int health); void SetSpeed(const int speed); void SetDirection(const Vector2 direction); void SetScoreAmount(const int scoreAmount); + void SetFrames(const Ref& spriteFrames); void SetIsShooting(const bool isShooting); void SetFireRate(const double fireRate); void SetBulletDirection(const Vector2 bulletDirection); + void SetBulletTexture(const Ref& bulletTexture); + void SetBulletLocation(const Vector2 bulletLocation); }; };