Improvements

This commit is contained in:
CatAClock 2025-06-12 14:51:06 -07:00
parent 015aac839e
commit 29ac85d292
3 changed files with 90 additions and 1 deletions

View file

@ -1,6 +1,7 @@
#include "Player.hpp"
#include <godot_cpp/core/class_db.hpp>
#include <godot_cpp/core/property_info.hpp>
#include <godot_cpp/core/memory.hpp>
namespace godot {
@ -13,6 +14,63 @@ namespace godot {
}
void Player::_bind_methods() {
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");
ClassDB::bind_method(D_METHOD("GetSpeed"), &Player::GetSpeed);
ClassDB::bind_method(D_METHOD("SetSpeed", "Speed"), &Player::SetSpeed);
ClassDB::add_property("Player", PropertyInfo(Variant::INT, "Speed"), "SetSpeed", "GetSpeed");
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");
}
void Player::_physics_process(double delta) {
}
// Getters and Setters
int Player::GetHealth() const {
return Health;
}
int Player::GetSpeed() const {
return Speed;
}
float Player::GetInvulnerabilityTime() const {
return InvulnerabilityTime;
}
float Player::GetFireRate() const {
return FireRate;
}
Ref<CompressedTexture2D> Player::GetPlayerUp() const {
return PlayerUp;
}
Ref<CompressedTexture2D> Player::GetPlayerNeutral() const {
return PlayerNeutral;
}
Ref<CompressedTexture2D> Player::GetPlayerDown() const {
return PlayerDown;
}
void Player::SetHealth(const int health) {
Health = health;
}
void Player::SetSpeed(const int speed) {
Speed = speed;
}
void Player::SetInvulnerabilityTime(const float invulnerabilityTime) {
InvulnerabilityTime = invulnerabilityTime;
}
void Player::SetFireRate(const float fireRate) {
FireRate = fireRate;
}
void Player::SetPlayerUp(const Ref<CompressedTexture2D>& playerUp) {
PlayerUp = playerUp;
}
void Player::SetPlayerNeutral(const Ref<CompressedTexture2D>& playerNeutral) {
PlayerNeutral = playerNeutral;
}
void Player::SetPlayerDown(const Ref<CompressedTexture2D>& playerDown) {
PlayerDown = playerDown;
}
};

View file

@ -2,13 +2,26 @@
#define PLAYER_HPP
#include <godot_cpp/classes/character_body2d.hpp>
#include <godot_cpp/classes/compressed_texture2d.hpp>
namespace godot {
class Player : public CharacterBody2D {
GDCLASS(Player, CharacterBody2D)
private:
// Regular
int Health = 3;
int Speed = 50;
bool Invulnerable = false;
float InvulnerabilityTime = 3.0;
// Killing
float FireRate = 0.04;
//Textures
Ref<CompressedTexture2D> PlayerUp;
Ref<CompressedTexture2D> PlayerNeutral;
Ref<CompressedTexture2D> PlayerDown;
protected:
static void _bind_methods();
@ -16,7 +29,25 @@ namespace godot {
public:
Player();
~Player();
void _physics_process(double delta) override;
// Getters and Setters
int GetHealth() const;
int GetSpeed() const;
float GetInvulnerabilityTime() const;
float GetFireRate() const;
Ref<CompressedTexture2D> GetPlayerUp() const;
Ref<CompressedTexture2D> GetPlayerNeutral() const;
Ref<CompressedTexture2D> GetPlayerDown() const;
void SetHealth(const int health);
void SetSpeed(const int speed);
void SetInvulnerabilityTime(const float invulnerabilityTime);
void SetFireRate(const float fireRate);
void SetPlayerUp(const Ref<CompressedTexture2D>& playerUp);
void SetPlayerNeutral(const Ref<CompressedTexture2D>& playerNeutral);
void SetPlayerDown(const Ref<CompressedTexture2D>& playerDown);
};
};