Player's almost done. So is bullet. Enemy up next!

This commit is contained in:
CatAClock 2025-06-14 18:11:36 -07:00
parent 2c473ad95e
commit bd094bfa2b
13 changed files with 33 additions and 34 deletions

View file

@ -1,22 +0,0 @@
[gd_scene load_steps=3 format=3 uid="uid://do4a4d3u60iy1"]
[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"]
[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
[node name="Sprite2D" type="Sprite2D" parent="."]
position = Vector2(1.42109e-14, 1)
scale = Vector2(0.034, 0.034)
texture = ExtResource("2_xbn07")
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
stream = ExtResource("3_qwtek")
volume_db = -5.0
[connection signal="body_entered" from="." to="." method="_on_body_entered"]

View file

@ -1,7 +1,7 @@
[gd_scene load_steps=14 format=3 uid="uid://bki7jjuvugscj"]
[ext_resource type="Script" uid="uid://csmqifafakbu4" path="res://godot/Scripts/enemy.gd" id="1_oyq4s"]
[ext_resource type="PackedScene" uid="uid://dq1pnq3g34tay" path="res://godot/Scenes/Bullets/enemy_bullet.tscn" id="2_w428l"]
[ext_resource type="PackedScene" uid="uid://dq1pnq3g34tay" path="res://godot/Scenes/enemy_bullet.tscn" id="2_w428l"]
[ext_resource type="Texture2D" uid="uid://b2res51c25avx" path="res://non-godot/Textures/Whale/Whale 1.png" id="3_rlx0w"]
[ext_resource type="Texture2D" uid="uid://s3ici4urgkpp" path="res://non-godot/Textures/Whale/Whale 2.png" id="4_nq1if"]
[ext_resource type="Texture2D" uid="uid://xvmxbxost161" path="res://non-godot/Textures/Whale/Whale 3.png" id="5_vayue"]

View file

@ -1,7 +1,7 @@
[gd_scene load_steps=10 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://d07qtvmhqjjts" path="res://non-godot/Textures/Bullet.png" id="1_ppa05"]
[ext_resource type="Texture2D" uid="uid://c5kt81t5h4vgn" path="res://non-godot/Textures/Plane/Plane.png" id="3_5g2vf"]
[ext_resource type="Texture2D" uid="uid://bff4pkabs2ecf" path="res://non-godot/Textures/Plane/PlaneDown.png" id="3_edjcf"]
@ -148,8 +148,8 @@ _data = {
}
[node name="Player" type="Player" groups=["Player"]]
ShotBulletLocation = Vector2(100, 100)
ShotBullet = ExtResource("1_edjcf")
ShotBulletLocation = Vector2(95, 45)
ShotBulletTexture = ExtResource("1_ppa05")
PlayerUp = ExtResource("1_2h3i0")
PlayerNeutral = ExtResource("3_5g2vf")
PlayerDown = ExtResource("3_edjcf")
@ -159,7 +159,6 @@ InputRight = &"Right"
InputDown = &"Down"
InputShoot = &"Shoot"
InputSpeedUp = &"SpeedUp"
scale = Vector2(0.15, 0.15)
motion_mode = 1
[node name="GPUParticles2D2" type="GPUParticles2D" parent="."]

View file

@ -23,6 +23,7 @@ func _on_body_entered(body: Node) -> void:
self.collision_layer = 0b0000
self.collision_mask = 0b0000
self.visible = false
get_node("");
# for the player
elif !body.is_in_group("Bullet") and EnemyBullet == true and body.is_in_group("Player"):
body.TakeDamage()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 217 KiB

After

Width:  |  Height:  |  Size: 788 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 530 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 544 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 492 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View file

@ -5,17 +5,16 @@
#include <godot_cpp/core/memory.hpp>
#include <godot_cpp/classes/engine.hpp>
#include <godot_cpp/classes/collision_shape2d.hpp>
#include <godot_cpp/classes/rectangle_shape2d.hpp>
namespace godot {
Bullet::Bullet() {
Sprite = memnew(Sprite2D);
CollisionShape2D* Collision = memnew(CollisionShape2D);
RectangleShape2D* CollisionShape = memnew(RectangleShape2D);
Collision = memnew(CollisionShape2D);
CollisionShape = memnew(RectangleShape2D);
Collision->set_shape(CollisionShape);
set_lock_rotation_enabled(true);
add_child(Sprite);
add_child(Collision);
}
@ -31,6 +30,9 @@ namespace godot {
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");
ClassDB::bind_method(D_METHOD("GetTexture"), &Bullet::GetTexture);
ClassDB::bind_method(D_METHOD("SetTexture", "Texture"), &Bullet::SetTexture);
ClassDB::add_property("Bullet", PropertyInfo(Variant::OBJECT, "Texture"), "SetTexture", "GetTexture");
}
void Bullet::_integrate_forces(PhysicsDirectBodyState2D* state) {
@ -46,6 +48,8 @@ namespace godot {
}
void Bullet::_physics_process(double delta) {
CollisionShape->set_size(Vector2(Texture->get_width(), Texture->get_height()));
if (Engine::get_singleton()->is_editor_hint()) {
return;
}
@ -62,6 +66,9 @@ namespace godot {
Vector2 Bullet::GetDirection() const {
return Direction;
}
Ref<CompressedTexture2D> Bullet::GetTexture() const {
return Texture;
}
void Bullet::SetSpeed(const int speed) {
Speed = speed;
@ -69,4 +76,8 @@ namespace godot {
void Bullet::SetDirection(const Vector2 direction) {
Direction = direction;
}
void Bullet::SetTexture(const Ref<CompressedTexture2D>& texture) {
Texture = texture;
Sprite->set_texture(texture);
}
};

View file

@ -4,19 +4,25 @@
#include <godot_cpp/classes/rigid_body2d.hpp>
#include <godot_cpp/classes/physics_direct_body_state2d.hpp>
#include <godot_cpp/classes/sprite2d.hpp>
#include <godot_cpp/classes/compressed_texture2d.hpp>
#include <godot_cpp/classes/collision_shape2d.hpp>
#include <godot_cpp/classes/rectangle_shape2d.hpp>
namespace godot {
class Bullet : public RigidBody2D {
GDCLASS(Bullet, RigidBody2D)
private:
int Speed = 1200;
int Speed = 1500;
Vector2 Direction;
Ref<CompressedTexture2D> Texture;
double DespawnTime = 5;
double DespawnTimer = 0;
// Nodes
Sprite2D* Sprite;
CollisionShape2D* Collision;
RectangleShape2D* CollisionShape;
protected:
static void _bind_methods();
@ -31,10 +37,11 @@ namespace godot {
// Getters and setters
int GetSpeed() const;
Vector2 GetDirection() const;
Ref<CompressedTexture2D> GetTexture() const;
void SetSpeed(const int speed);
void SetDirection(const Vector2 direction);
void SetTexture(const Ref<CompressedTexture2D>& texture);
};
};

View file

@ -124,6 +124,9 @@ namespace godot {
if (Input::get_singleton()->get_action_raw_strength(Shoot) != 0) {
Bullet* bullet = memnew(Bullet);
bullet->set_position(BulletLocation + get_position());
bullet->SetTexture(BulletTexture);
bullet->SetDirection(Vector2(1, 0));
bullet->add_collision_exception_with(get_node<Player>(get_path()));
get_parent()->add_child(bullet);
FireRateTimer = 0;
}