player coming along smoothly

This commit is contained in:
CatAClock 2025-06-12 16:09:20 -07:00
parent 29ac85d292
commit dcd23598da
5 changed files with 155 additions and 112 deletions

View file

@ -1,24 +1,22 @@
[gd_scene load_steps=14 format=3 uid="uid://bjbccem28ir8r"]
[gd_scene load_steps=12 format=3 uid="uid://bjbccem28ir8r"]
[ext_resource type="Script" uid="uid://7w35cdpth8d1" path="res://godot/Scripts/player.gd" id="1_2bkpj"]
[ext_resource type="PackedScene" uid="uid://do4a4d3u60iy1" path="res://godot/Scenes/Bullets/bullet.tscn" id="2_ogm6h"]
[ext_resource type="Texture2D" uid="uid://bcbjh2amre7ke" path="res://non-godot/Textures/Plane/PlaneUp.png" id="1_2h3i0"]
[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://bcbjh2amre7ke" path="res://non-godot/Textures/Plane/PlaneUp.png" id="3_t0dqt"]
[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"]
[ext_resource type="Texture2D" uid="uid://bff4pkabs2ecf" path="res://non-godot/Textures/Plane/PlaneDown.png" id="5_ylcev"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_u1ywu"]
size = Vector2(220, 68)
size = Vector2(1920, 720)
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_xtmdc"]
particle_flag_disable_z = true
emission_shape = 3
emission_box_extents = Vector3(0, 12, 1)
emission_box_extents = Vector3(0, 120, 1)
direction = Vector3(-1, 0, 0)
spread = 0.0
initial_velocity_min = 650.0
initial_velocity_max = 650.0
initial_velocity_min = 1950.0
initial_velocity_max = 1950.0
gravity = Vector3(0, 0, 0)
scale_max = 8.0
color = Color(0.513233, 0.513233, 0.513233, 1)
@ -30,7 +28,7 @@ step = 0.1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:visible")
tracks/0/path = NodePath("GPUParticles2D2:visible")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
@ -42,7 +40,7 @@ tracks/0/keys = {
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("GPUParticles2D2:visible")
tracks/1/path = NodePath("GPUParticles2D:visible")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
@ -54,34 +52,22 @@ tracks/1/keys = {
tracks/2/type = "value"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("GPUParticles2D:visible")
tracks/2/path = NodePath("ColorRect:color")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(3),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [false]
}
tracks/3/type = "value"
tracks/3/imported = false
tracks/3/enabled = true
tracks/3/path = NodePath("ColorRect:color")
tracks/3/interp = 1
tracks/3/loop_wrap = true
tracks/3/keys = {
"times": PackedFloat32Array(3, 5),
"transitions": PackedFloat32Array(1, 2),
"update": 0,
"values": [Color(0, 0, 0, 0), Color(0, 0, 0, 1)]
}
tracks/4/type = "method"
tracks/4/imported = false
tracks/4/enabled = true
tracks/4/path = NodePath(".")
tracks/4/interp = 1
tracks/4/loop_wrap = true
tracks/4/keys = {
tracks/3/type = "method"
tracks/3/imported = false
tracks/3/enabled = true
tracks/3/path = NodePath(".")
tracks/3/interp = 1
tracks/3/loop_wrap = true
tracks/3/keys = {
"times": PackedFloat32Array(4.99),
"transitions": PackedFloat32Array(1),
"values": [{
@ -112,7 +98,7 @@ length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:visible")
tracks/0/path = NodePath("GPUParticles2D2:visible")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
@ -124,7 +110,7 @@ tracks/0/keys = {
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("GPUParticles2D2:visible")
tracks/1/path = NodePath("GPUParticles2D:visible")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
@ -136,64 +122,54 @@ tracks/1/keys = {
tracks/2/type = "value"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("GPUParticles2D:visible")
tracks/2/path = NodePath("ColorRect:color")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [true]
"update": 0,
"values": [Color(0, 0, 0, 0)]
}
tracks/3/type = "value"
tracks/3/imported = false
tracks/3/enabled = true
tracks/3/path = NodePath("ColorRect:color")
tracks/3/path = NodePath(".:modulate")
tracks/3/interp = 1
tracks/3/loop_wrap = true
tracks/3/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Color(0, 0, 0, 0)]
}
tracks/4/type = "value"
tracks/4/imported = false
tracks/4/enabled = true
tracks/4/path = NodePath(".:modulate")
tracks/4/interp = 1
tracks/4/loop_wrap = true
tracks/4/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Color(1, 1, 1, 1)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_vkafp"]
_data = {
"Death": SubResource("Animation_bb0i0"),
"Hit": SubResource("Animation_vh54h"),
"RESET": SubResource("Animation_gbl2x")
&"Death": SubResource("Animation_bb0i0"),
&"Hit": SubResource("Animation_vh54h"),
&"RESET": SubResource("Animation_gbl2x")
}
[node name="Player" type="CharacterBody2D" groups=["Player"]]
[node name="Player" type="Player" groups=["Player"]]
Speed = 500
PlayerUp = ExtResource("1_2h3i0")
PlayerNeutral = ExtResource("3_5g2vf")
PlayerDown = ExtResource("3_edjcf")
Left = &"Left"
Up = &"Up"
Right = &"Right"
Down = &"Down"
scale = Vector2(0.25, 0.25)
collision_layer = 4
collision_mask = 4
motion_mode = 1
script = ExtResource("1_2bkpj")
Speed = 400
Bullet = ExtResource("2_ogm6h")
FireRate = 0.04
PlaneUp = ExtResource("3_t0dqt")
PlaneNeutral = ExtResource("3_5g2vf")
PlaneDown = ExtResource("5_ylcev")
[node name="Area2D" type="Area2D" parent="."]
position = Vector2(3, 3)
[node name="EnemyCollider" type="CollisionShape2D" parent="Area2D"]
position = Vector2(0.5, 3.5)
position = Vector2(0, -60)
shape = SubResource("RectangleShape2D_u1ywu")
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="Area2D"]
@ -211,38 +187,34 @@ volume_db = -20.0
max_polyphony = 2
[node name="GPUParticles2D2" type="GPUParticles2D" parent="."]
position = Vector2(-58, -16)
z_index = -1
position = Vector2(-544, -264)
amount = 500
amount_ratio = 0.66
process_material = SubResource("ParticleProcessMaterial_xtmdc")
lifetime = 5.0
[node name="Sprite2D" type="Sprite2D" parent="."]
position = Vector2(7, 16)
scale = Vector2(0.12, 0.12)
texture = ExtResource("3_5g2vf")
[node name="WallCollider" type="CollisionShape2D" parent="."]
position = Vector2(4, 7)
shape = SubResource("RectangleShape2D_u1ywu")
process_material = SubResource("ParticleProcessMaterial_xtmdc")
[node name="GPUParticles2D" type="GPUParticles2D" parent="."]
position = Vector2(-70, -10)
position = Vector2(-640, -204)
amount = 500
amount_ratio = 0.66
process_material = SubResource("ParticleProcessMaterial_xtmdc")
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")
&"": SubResource("AnimationLibrary_vkafp")
}
[node name="ColorRect" type="ColorRect" parent="."]
offset_left = -5000.0
offset_top = -5000.0
offset_right = 5000.0
offset_bottom = 5000.0
offset_left = -4963.0
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,22 +1,12 @@
extends CharacterBody2D
extends Player
@export_category("Basic")
@export var Health: int = 3
@export var Speed: int
@export var InvulnerabilityTime: int = 3
var Invulnerable: bool = false
var InvulnerabilityTimer: float = 0
@export_category("Shooting")
@export var Bullet: PackedScene
@export var FireRate: float
var FireRateTimer: float
@export_category("Images")
@export var PlaneUp: CompressedTexture2D
@export var PlaneNeutral: CompressedTexture2D
@export var PlaneDown: CompressedTexture2D
@export_category("Other")
@export var OnDeathScene: PackedScene
@ -35,27 +25,6 @@ func _physics_process(delta: float) -> void:
InvulnerabilityTimer = 0
if PlayerControl:
# Movement
var SpeedUp = Input.get_action_raw_strength("SpeedUp")
var xdirection = Input.get_axis("Left", "Right")
var ydirection = Input.get_axis("Up", "Down")
if xdirection || ydirection:
self.velocity = Vector2(xdirection, ydirection).normalized() * Speed * (SpeedUp + 1)
# Adjust sprites on movement
if ydirection == 1:
get_node("Sprite2D").texture = PlaneDown
elif ydirection == -1:
get_node("Sprite2D").texture = PlaneUp
else:
get_node("Sprite2D").texture = PlaneNeutral
else:
# Stop the plane on not moving
self.velocity.x = move_toward(velocity.x, 0, Speed)
self.velocity.y = move_toward(velocity.y, 0, Speed)
# yes, this has to be here. I know, really stupid.
get_node("Sprite2D").texture = PlaneNeutral
# Shooting
if Input.get_action_raw_strength("Shoot") && FireRateTimer >= FireRate:
var bullet = Bullet.instantiate()

View file

@ -3,10 +3,22 @@
#include <godot_cpp/core/class_db.hpp>
#include <godot_cpp/core/property_info.hpp>
#include <godot_cpp/core/memory.hpp>
#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>
namespace godot {
Player::Player() {
CollisionShape2D* Collision = memnew(CollisionShape2D);
RectangleShape2D* CollisionShape = memnew(RectangleShape2D);
Sprite = memnew(Sprite2D);
Collision->set_shape(CollisionShape);
add_child(Collision);
add_child(Sprite);
}
Player::~Player() {
@ -14,6 +26,7 @@ namespace godot {
}
void Player::_bind_methods() {
// Regular Variables
ClassDB::bind_method(D_METHOD("GetHealth"), &Player::GetHealth);
ClassDB::bind_method(D_METHOD("SetHealth", "Health"), &Player::SetHealth);
ClassDB::add_property("Player", PropertyInfo(Variant::INT, "Health"), "SetHealth", "GetHealth");
@ -23,10 +36,55 @@ namespace godot {
ClassDB::bind_method(D_METHOD("GetInvulnerabilityTime"), &Player::GetInvulnerabilityTime);
ClassDB::bind_method(D_METHOD("SetInvulnerabilityTime", "InvulnerabilityTime"), &Player::SetInvulnerabilityTime);
ClassDB::add_property("Player", PropertyInfo(Variant::FLOAT, "InvulnerabilityTime"), "SetInvulnerabilityTime", "GetInvulnerabilityTime");
// Killing
ClassDB::bind_method(D_METHOD("GetFireRate"), &Player::GetFireRate);
ClassDB::bind_method(D_METHOD("SetFireRate", "FireRate"), &Player::SetFireRate);
ClassDB::add_property("Player", PropertyInfo(Variant::FLOAT, "FireRate"), "SetFireRate", "GetFireRate");
// Textures
ClassDB::bind_method(D_METHOD("GetPlayerUp"), &Player::GetPlayerUp);
ClassDB::bind_method(D_METHOD("SetPlayerUp", "PlayerUp"), &Player::SetPlayerUp);
ClassDB::add_property("Player", PropertyInfo(Variant::OBJECT, "PlayerUp"), "SetPlayerUp", "GetPlayerUp");
ClassDB::bind_method(D_METHOD("GetPlayerNeutral"), &Player::GetPlayerNeutral);
ClassDB::bind_method(D_METHOD("SetPlayerNeutral", "PlayerNeutral"), &Player::SetPlayerNeutral);
ClassDB::add_property("Player", PropertyInfo(Variant::OBJECT, "PlayerNeutral"), "SetPlayerNeutral", "GetPlayerNeutral");
ClassDB::bind_method(D_METHOD("GetPlayerDown"), &Player::GetPlayerDown);
ClassDB::bind_method(D_METHOD("SetPlayerDown", "PlayerDown"), &Player::SetPlayerDown);
ClassDB::add_property("Player", PropertyInfo(Variant::OBJECT, "PlayerDown"), "SetPlayerDown", "GetPlayerDown");
// Keys
ClassDB::bind_method(D_METHOD("GetLeft"), &Player::GetLeft);
ClassDB::bind_method(D_METHOD("SetLeft", "Left"), &Player::SetLeft);
ClassDB::add_property("Player", PropertyInfo(Variant::STRING_NAME, "Left"), "SetLeft", "GetLeft");
ClassDB::bind_method(D_METHOD("GetUp"), &Player::GetUp);
ClassDB::bind_method(D_METHOD("SetUp", "Up"), &Player::SetUp);
ClassDB::add_property("Player", PropertyInfo(Variant::STRING_NAME, "Up"), "SetUp", "GetUp");
ClassDB::bind_method(D_METHOD("GetRight"), &Player::GetRight);
ClassDB::bind_method(D_METHOD("SetRight", "Right"), &Player::SetRight);
ClassDB::add_property("Player", PropertyInfo(Variant::STRING_NAME, "Right"), "SetRight", "GetRight");
ClassDB::bind_method(D_METHOD("GetDown"), &Player::GetDown);
ClassDB::bind_method(D_METHOD("SetDown", "Down"), &Player::SetDown);
ClassDB::add_property("Player", PropertyInfo(Variant::STRING_NAME, "Down"), "SetDown", "GetDown");
}
void Player::_physics_process(double delta) {
Sprite->set_texture(PlayerNeutral);
if (Engine::get_singleton()->is_editor_hint()) {
return;
}
int XDirection = Input::get_singleton()->get_axis(Left, Right);
int YDirection = Input::get_singleton()->get_axis(Up, Down);
set_velocity(Vector2(XDirection, YDirection).normalized() * Speed);
// change thing when going up and down.
if (YDirection == 1) {
Sprite->set_texture(PlayerDown);
} else if (YDirection == -1) {
Sprite->set_texture(PlayerUp);
}
move_and_slide();
}
// Getters and Setters
@ -51,6 +109,18 @@ namespace godot {
Ref<CompressedTexture2D> Player::GetPlayerDown() const {
return PlayerDown;
}
StringName Player::GetLeft() const {
return Left;
}
StringName Player::GetUp() const {
return Up;
}
StringName Player::GetRight() const {
return Right;
}
StringName Player::GetDown() const {
return Down;
}
void Player::SetHealth(const int health) {
Health = health;
@ -73,4 +143,16 @@ namespace godot {
void Player::SetPlayerDown(const Ref<CompressedTexture2D>& playerDown) {
PlayerDown = playerDown;
}
void Player::SetLeft(const StringName left) {
Left = left;
}
void Player::SetUp(const StringName up) {
Up = up;
}
void Player::SetRight(const StringName right) {
Right = right;
}
void Player::SetDown(const StringName down) {
Down = down;
}
};

View file

@ -1,8 +1,11 @@
#ifndef PLAYER_HPP
#define PLAYER_HPP
#include <godot_cpp/classes/input.hpp>
#include <godot_cpp/classes/character_body2d.hpp>
#include <godot_cpp/classes/compressed_texture2d.hpp>
#include <godot_cpp/classes/sprite2d.hpp>
namespace godot {
class Player : public CharacterBody2D {
@ -22,7 +25,16 @@ namespace godot {
Ref<CompressedTexture2D> PlayerUp;
Ref<CompressedTexture2D> PlayerNeutral;
Ref<CompressedTexture2D> PlayerDown;
// Keys
StringName Left;
StringName Up;
StringName Right;
StringName Down;
// Nodes
Sprite2D* Sprite;
protected:
static void _bind_methods();
@ -40,6 +52,10 @@ namespace godot {
Ref<CompressedTexture2D> GetPlayerUp() const;
Ref<CompressedTexture2D> GetPlayerNeutral() const;
Ref<CompressedTexture2D> GetPlayerDown() const;
StringName GetLeft() const;
StringName GetUp() const;
StringName GetRight() const;
StringName GetDown() const;
void SetHealth(const int health);
void SetSpeed(const int speed);
@ -48,6 +64,10 @@ namespace godot {
void SetPlayerUp(const Ref<CompressedTexture2D>& playerUp);
void SetPlayerNeutral(const Ref<CompressedTexture2D>& playerNeutral);
void SetPlayerDown(const Ref<CompressedTexture2D>& playerDown);
void SetLeft(const StringName left);
void SetUp(const StringName up);
void SetRight(const StringName right);
void SetDown(const StringName down);
};
};