aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-12-22 20:04:33 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-12-22 20:04:33 +0100
commita600cc55468a6513743ce916aa3da129270c23f0 (patch)
tree324eb574298b321dcfba69a5a29c59b0cc18f007 /src/crepe/api
parent73dea702bdedf48a2d2d26e7922b5ee935063cfd (diff)
more WIP zapper
Diffstat (limited to 'src/crepe/api')
-rw-r--r--src/crepe/api/Animator.cpp18
-rw-r--r--src/crepe/api/Animator.h21
-rw-r--r--src/crepe/api/BehaviorScript.h2
-rw-r--r--src/crepe/api/BehaviorScript.hpp1
-rw-r--r--src/crepe/api/Sprite.h13
5 files changed, 21 insertions, 34 deletions
diff --git a/src/crepe/api/Animator.cpp b/src/crepe/api/Animator.cpp
index c558d86..5ac0617 100644
--- a/src/crepe/api/Animator.cpp
+++ b/src/crepe/api/Animator.cpp
@@ -36,24 +36,12 @@ void Animator::pause() { this->active = false; }
void Animator::stop() {
this->active = false;
- this->data.col = 0;
- this->data.row = 0;
+ this->data.frame = this->data.cycle_start;
}
void Animator::set_fps(int fps) { this->data.fps = fps; }
void Animator::set_cycle_range(int start, int end) {
- this->data.cycle_start = start, this->data.cycle_end = end;
+ this->data.cycle_start = start;
+ this->data.cycle_end = end;
}
-void Animator::set_anim(int col) {
- Animator::Data & ctx = this->data;
- this->spritesheet.mask.x = ctx.row = 0;
- ctx.col = col;
- this->spritesheet.mask.y = ctx.col * this->spritesheet.mask.h;
-}
-
-void Animator::next_anim() {
- Animator::Data & ctx = this->data;
- ctx.row = ++ctx.row % this->grid_size.x;
- this->spritesheet.mask.x = ctx.row * this->spritesheet.mask.w;
-}
diff --git a/src/crepe/api/Animator.h b/src/crepe/api/Animator.h
index 102894d..8be693e 100644
--- a/src/crepe/api/Animator.h
+++ b/src/crepe/api/Animator.h
@@ -1,6 +1,7 @@
#pragma once
#include "../types.h"
+#include "../manager/LoopTimerManager.h"
#include "Component.h"
#include "Sprite.h"
@@ -22,16 +23,15 @@ public:
struct Data {
//! frames per second for animation
unsigned int fps = 1;
- //! The current col being animated.
- unsigned int col = 0;
- //! The current row being animated.
- unsigned int row = 0;
+ //! The current frame being shown
+ unsigned int frame = 0;
+
//! should the animation loop
bool looping = false;
//! starting frame for cycling
unsigned int cycle_start = 0;
//! end frame for cycling (-1 = use last frame)
- int cycle_end = -1;
+ unsigned int cycle_end = -1;
};
public:
@@ -60,14 +60,6 @@ public:
* \param end of row animation
*/
void set_cycle_range(int start, int end);
- /**
- * \brief select which column to animate from
- *
- * \param col animation column
- */
- void set_anim(int col);
- //! will go to the next animaiton of current row
- void next_anim();
public:
/**
@@ -101,6 +93,9 @@ private:
//! Uses the spritesheet
friend AnimatorSystem;
+
+ //! Elasped time since last frame change
+ duration_t elapsed;
};
} // namespace crepe
diff --git a/src/crepe/api/BehaviorScript.h b/src/crepe/api/BehaviorScript.h
index 3909b96..52cf259 100644
--- a/src/crepe/api/BehaviorScript.h
+++ b/src/crepe/api/BehaviorScript.h
@@ -48,6 +48,8 @@ public:
BehaviorScript & set_script(Args &&... args);
protected:
+ //! Script type name
+ std::string name = "unknown script";
//! Script instance
std::unique_ptr<Script> script = nullptr;
//! ScriptSystem needs direct access to the script instance
diff --git a/src/crepe/api/BehaviorScript.hpp b/src/crepe/api/BehaviorScript.hpp
index 353d5e2..218f27c 100644
--- a/src/crepe/api/BehaviorScript.hpp
+++ b/src/crepe/api/BehaviorScript.hpp
@@ -11,6 +11,7 @@ template <class T, typename... Args>
BehaviorScript & BehaviorScript::set_script(Args &&... args) {
static_assert(std::is_base_of<Script, T>::value);
this->script = std::unique_ptr<Script>(new T(std::forward<Args>(args)...));
+ this->name = typeid(T).name();
this->script->game_object_id = this->game_object_id;
this->script->active = this->active;
diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h
index a3fc319..ef65f64 100644
--- a/src/crepe/api/Sprite.h
+++ b/src/crepe/api/Sprite.h
@@ -110,15 +110,16 @@ private:
*/
float aspect_ratio = 0;
- struct Rect {
- int w = 0;
- int h = 0;
- int x = 0;
- int y = 0;
+public:
+ struct Mask {
+ unsigned w = 0;
+ unsigned h = 0;
+ unsigned x = 0;
+ unsigned y = 0;
};
//! Render area of the sprite this will also be adjusted by the AnimatorSystem if an Animator
// object is present in GameObject. this is in sprite pixels
- Rect mask;
+ Mask mask;
};
} // namespace crepe