10 enemies in demo
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
|
||||
/*
|
||||
# _____ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licensed under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
enum AnimationSequenceCallback {
|
||||
/** On frame change */
|
||||
AnimationSequenceCallback_NextFrame,
|
||||
/** When animation in loop = false will end */
|
||||
AnimationSequenceCallback_End,
|
||||
/** When animation in loop = true will start from beginning */
|
||||
AnimationSequenceCallback_Loop
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -11,8 +11,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "../mesh_frame.hpp"
|
||||
#include "../mesh_material_frame.hpp"
|
||||
#include "./dynamic_mesh_anim_state.hpp"
|
||||
#include "./dynamic_mesh_animation.hpp"
|
||||
#include "../mesh.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
@@ -25,36 +24,15 @@ class DynamicMesh : public Mesh {
|
||||
|
||||
std::vector<MeshFrame*> frames;
|
||||
|
||||
DynamicMeshAnimState animState;
|
||||
DynamicMeshAnimation animation;
|
||||
|
||||
/** @returns bounding box object of current frame. */
|
||||
const BBox& getCurrentBoundingBox() const {
|
||||
return *frames[animState.currentFrame]->bbox;
|
||||
return *frames[animation.getState().currentFrame]->bbox;
|
||||
}
|
||||
|
||||
/** Loop in one frame */
|
||||
void playAnimation(const u32& t_frame);
|
||||
|
||||
/** Play animation in loop from startFrame to endFrame */
|
||||
void playAnimation(const u32& t_startFrame, const u32& t_endFrame);
|
||||
|
||||
/** Play animation from startFrame to endFrame and after loop in stayFrame
|
||||
*/
|
||||
void playAnimation(const u32& t_startFrame, const u32& t_endFrame,
|
||||
const u32& t_stayFrame);
|
||||
|
||||
void setAnimSpeed(const float& t_value) { animState.speed = t_value; }
|
||||
|
||||
void animate();
|
||||
|
||||
/**
|
||||
* Check if this class loaded mesh data first.
|
||||
* Meshes which use loadFrom() method have false there.
|
||||
*/
|
||||
const u8& isStayAnimationSet() const { return animState.isStayFrameSet; }
|
||||
|
||||
private:
|
||||
void initAnimation();
|
||||
/** Update animation */
|
||||
inline void update() { animation.update(); }
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
|
||||
@@ -15,16 +15,10 @@
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
typedef struct {
|
||||
u32 startFrame;
|
||||
u32 endFrame;
|
||||
u32 stayFrame;
|
||||
u8 isStayFrameSet;
|
||||
float speed;
|
||||
struct DynamicMeshAnimState {
|
||||
float interpolation;
|
||||
u32 animType;
|
||||
u32 currentFrame;
|
||||
u32 nextFrame;
|
||||
} DynamicMeshAnimState;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
# _____ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licensed under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tamtypes.h>
|
||||
#include "./dynamic_mesh_anim_state.hpp"
|
||||
#include "./animation_sequence_callback.hpp"
|
||||
#include "../mesh_frame.hpp"
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class DynamicMeshAnimation {
|
||||
public:
|
||||
DynamicMeshAnimation();
|
||||
~DynamicMeshAnimation();
|
||||
|
||||
bool loop;
|
||||
float speed;
|
||||
|
||||
/**
|
||||
* Update animation.
|
||||
* Should be called every frame if you want animation running.
|
||||
*/
|
||||
void update();
|
||||
|
||||
/** Set animation sequence (indices of frames) */
|
||||
void setSequence(const std::vector<u32>& sequence);
|
||||
|
||||
/** Start animation from beginning */
|
||||
void restart();
|
||||
|
||||
/**
|
||||
* @brief Set animation callback.
|
||||
* It will push animation info on every update() call.
|
||||
*/
|
||||
void setCallback(
|
||||
const std::function<void(const AnimationSequenceCallback&)>& callback);
|
||||
|
||||
const DynamicMeshAnimState& getState() const;
|
||||
|
||||
void resetAll(const std::vector<MeshFrame*>& frames);
|
||||
|
||||
private:
|
||||
u32 framesCount;
|
||||
u32 currentFrameSequenceIndex;
|
||||
DynamicMeshAnimState state;
|
||||
|
||||
std::function<void(const AnimationSequenceCallback&)> callback;
|
||||
std::vector<u32> sequence;
|
||||
|
||||
void updateLoopState(AnimationSequenceCallback* callbackInfo);
|
||||
|
||||
/**
|
||||
* @return true Frame changed
|
||||
* @return false No changes
|
||||
*/
|
||||
bool updateNoLoopState(AnimationSequenceCallback* callbackInfo);
|
||||
|
||||
u32 getNextSequenceIndexFrom(const u32& index) const;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -29,6 +29,9 @@ class Mesh {
|
||||
|
||||
M4x4 translation, rotation, scale;
|
||||
|
||||
/** nullptr if not found */
|
||||
MeshMaterial* getMaterialByName(const std::string& name);
|
||||
|
||||
std::vector<MeshMaterial*> materials;
|
||||
|
||||
M4x4 getModelMatrix() const;
|
||||
|
||||
Reference in New Issue
Block a user