Scale downs, enemies complete, just the wave function

This commit is contained in:
CatAClock 2025-06-17 15:14:13 -07:00
parent 9085972a22
commit b3c1f78d74
17 changed files with 92 additions and 55 deletions

View file

@ -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)

View file

@ -1 +0,0 @@

View file

@ -1 +0,0 @@
uid://csmqifafakbu4

Binary file not shown.

Before

Width:  |  Height:  |  Size: 292 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 294 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 292 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 292 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 281 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 254 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 266 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 281 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 263 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 248 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 287 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View file

@ -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<Enemy>(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<SpriteFrames> Enemy::GetFrames() const {
return Frames;
}
bool Enemy::GetIsShooting() const {
return IsShooting;
}
@ -108,6 +129,12 @@ namespace godot {
Vector2 Enemy::GetBulletDirection() const {
return BulletDirection;
}
Ref<CompressedTexture2D> 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>& 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<CompressedTexture2D>& bulletTexture) {
BulletTexture = bulletTexture;
}
void Enemy::SetBulletLocation(const Vector2 bulletLocation) {
BulletLocation = bulletLocation;
}
};

View file

@ -3,6 +3,11 @@
#include <godot_cpp/classes/rigid_body2d.hpp>
#include <godot_cpp/classes/physics_direct_body_state2d.hpp>
#include <godot_cpp/classes/collision_shape2d.hpp>
#include <godot_cpp/classes/rectangle_shape2d.hpp>
#include <godot_cpp/classes/compressed_texture2d.hpp>
#include <godot_cpp/classes/animated_sprite2d.hpp>
#include <godot_cpp/classes/sprite_frames.hpp>
#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<SpriteFrames> Frames;
double DespawnTimer = 0;
// Shooting
bool IsShooting = false;
double FireRate = 1;
double FireRateTimer = 0;
Vector2 BulletDirection = Vector2(-1, 0);
double DespawnTimer = 0;
Ref<CompressedTexture2D> 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<SpriteFrames> GetFrames() const;
bool GetIsShooting() const;
double GetFireRate() const;
Vector2 GetBulletDirection() const;
Ref<CompressedTexture2D> 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>& spriteFrames);
void SetIsShooting(const bool isShooting);
void SetFireRate(const double fireRate);
void SetBulletDirection(const Vector2 bulletDirection);
void SetBulletTexture(const Ref<CompressedTexture2D>& bulletTexture);
void SetBulletLocation(const Vector2 bulletLocation);
};
};