feat: work on running and weapon inventory

This commit is contained in:
Sara 2025-07-15 00:50:54 +02:00
parent 43c5863e89
commit 6cdb2cbd4f
7 changed files with 58 additions and 3 deletions

Binary file not shown.

Binary file not shown.

View file

@ -27,8 +27,8 @@ public:
private:
bool try_running{ false };
float walk_speed{ 7.f };
float run_speed{ 10.f };
float walk_speed{ 6.f };
float run_speed{ 8.f };
float acceleration{ 40.f };
float jump_strength{ 3.5f };
Vector2 movement_input{};

View file

@ -37,3 +37,11 @@ AnimationPlayer *WeaponBase::get_anim() const {
PlayerCamera *WeaponBase::get_camera() const {
return this->camera;
}
void WeaponBase::set_body(PlayerBody *body) {
this->body = body;
}
PlayerBody *WeaponBase::get_body() const {
return this->body;
}

View file

@ -4,6 +4,7 @@
#include "scene/3d/node_3d.h"
class AnimationPlayer;
class PlayerCamera;
class PlayerBody;
class WeaponBase : public Node3D {
GDCLASS(WeaponBase, Node3D);
@ -16,12 +17,15 @@ protected:
public:
void set_anim(AnimationPlayer *player);
AnimationPlayer *get_anim() const;
PlayerCamera *get_camera() const;
void set_body(PlayerBody *body);
PlayerBody *get_body() const;
private:
AnimationPlayer *anim{ nullptr };
PlayerCamera *camera{ nullptr };
PlayerBody *body{ nullptr };
};
#endif // !WEAPON_BASE_H

View file

@ -0,0 +1,10 @@
#include "weapon_inventory.h"
void WeaponInventory::_bind_methods() {}
void WeaponInventory::on_switch_input() {
this->current = (this->current + 1) % 1;
this->select_weapon(this->weapons[this->current]);
}

View file

@ -0,0 +1,33 @@
#ifndef WEAPON_INVENTORY_H
#define WEAPON_INVENTORY_H
#include "scene/main/node.h"
#include "scene/resources/packed_scene.h"
class PlayerBody;
class WeaponBase;
class WeaponInventory : public Node {
GDCLASS(WeaponInventory, Node);
static void _bind_methods();
void on_switch_input();
void ready();
void select_weapon(WeaponBase *next);
protected:
void _notification(int what);
public:
void set_fallback_weapon(Ref<PackedScene> scene);
Ref<PackedScene> get_fallback_weapon() const;
WeaponBase *get_current_weapon() const;
private:
unsigned current{ 0 };
LocalVector<WeaponBase *> weapons{ nullptr, nullptr };
WeaponBase *current_weapon{ nullptr };
WeaponBase *fallback_weapon{ nullptr };
Ref<PackedScene> default_weapon_scene{};
};
#endif // !WEAPON_INVENTORY_H