Bullet and Plane update

This commit is contained in:
CatAClock 2025-06-13 18:22:20 -07:00
parent da838ce296
commit 54d12252a8
14 changed files with 89 additions and 55 deletions

View file

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

View file

@ -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"]

View file

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 562 KiB

After

Width:  |  Height:  |  Size: 530 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 574 KiB

After

Width:  |  Height:  |  Size: 544 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 523 KiB

After

Width:  |  Height:  |  Size: 492 KiB

View file

@ -5,16 +5,68 @@
#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->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;
}
};

View file

@ -2,13 +2,21 @@
#define BULLET_HPP
#include <godot_cpp/classes/rigid_body2d.hpp>
#include <godot_cpp/classes/physics_direct_body_state2d.hpp>
#include <godot_cpp/classes/sprite2d.hpp>
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);
};
};

View file

@ -11,7 +11,7 @@ namespace godot {
}
Enemy::~Enemy() {
queue_free();
}
void Enemy::_bind_methods() {

View file

@ -6,16 +6,14 @@
#include <godot_cpp/classes/engine.hpp>
#include <godot_cpp/classes/area2d.hpp>
#include <godot_cpp/classes/collision_shape2d.hpp>
#include <godot_cpp/classes/rectangle_shape2d.hpp>
#include <godot_cpp/classes/kinematic_collision2d.hpp>
#include <godot_cpp/core/print_string.hpp>
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;

View file

@ -4,6 +4,8 @@
#include <godot_cpp/classes/input.hpp>
#include <godot_cpp/classes/character_body2d.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/sprite2d.hpp>
#include <godot_cpp/classes/packed_scene.hpp>
@ -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();

View file

@ -11,7 +11,7 @@ namespace godot {
}
Wave::~Wave() {
queue_free();
}
void Wave::_bind_methods() {

View file

@ -2,7 +2,7 @@
#include <godot_cpp/godot.hpp>
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[] = {