Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #4 Add ability to edit animation #6

Merged
merged 1 commit into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "deps/Boxer"]
path = deps/Boxer
url = https://github.com/aaronmjacobs/Boxer.git
[submodule "deps/yaml-cpp"]
path = deps/yaml-cpp
url = https://github.com/jbeder/yaml-cpp.git
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ target_link_libraries(${PROJECT_NAME} ${OPENGL_LIBRARIES} glfw )
add_subdirectory(${DEPS_DIR}/Boxer)
target_link_libraries(${PROJECT_NAME} Boxer)

# yaml-cpp
add_subdirectory(${DEPS_DIR}/yaml-cpp)
target_link_libraries(${PROJECT_NAME} yaml-cpp)

########### Define ############
target_compile_definitions(${PROJECT_NAME} PRIVATE PROJECT_VERSION="${PROJECT_VERSION}")

Expand Down
1 change: 1 addition & 0 deletions deps/yaml-cpp
Submodule yaml-cpp added at 1b5010
31 changes: 30 additions & 1 deletion include/Vector2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <cfloat>
#include <cmath>
#include "yaml-cpp/node/convert.h"

template <typename T>
union Vector2 {
Expand Down Expand Up @@ -198,7 +199,8 @@ union Vector2 {
return {abs(x), abbs(y)};
}

static constexpr Vector2 remap(const Vector2 value, const Vector2& from1, const Vector2& to1, const Vector2& from2, const Vector2& to2)
static constexpr Vector2 remap(const Vector2 value, const Vector2& from1, const Vector2& to1, const Vector2& from2,
const Vector2& to2)
{
return (value - from1) / (to1 - from1) * (to2 - from2) + from2;
}
Expand Down Expand Up @@ -362,6 +364,33 @@ union Vector2 {
}
};

namespace YAML
{
template <typename T>
struct convert<Vector2<T>>
{
static Node encode(const Vector2<T>& rhs)
{
Node node;
node.push_back(rhs.x);
node.push_back(rhs.y);
return node;
}

static bool decode(const Node& node, Vector2<T>& rhs)
{
if (!node.IsSequence() || node.size() != 2)
{
return false;
}

rhs.x = node[0].as<double>();
rhs.y = node[1].as<double>();
return true;
}
};
} // namespace YAML

using Vec2 = Vector2<float>;
using vec2 = Vector2<float>;
using Vec2i = Vector2<int>;
Expand Down
80 changes: 80 additions & 0 deletions resources/setting/animation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
FirstNode: idle
Nodes:
AnimationNode:
name: idle
sprite: idle.png
framerate: 10
loop: true
GrabNode:
name: grab
sprite: grab.png
framerate: 10
loop: true
PetWalkNode:
name: walk
sprite: walk.png
framerate: 10
direction: [1, 0]
thrust: 0.2
loop: true
PetJumpNode:
name: jump
sprite: jump.png
framerate: 10
direction: [1, 0]
verticalThrust: 0.15
horizontalThrust: 0.3
AnimationNode:
name: air
sprite: air.png
framerate: 10
loop: true
AnimationNode:
name: landing
sprite: landing.png
framerate: 10
loop: false
Transitions:
StartLeftClicTransition:
from: idle
to: grab
RandomDelayTransitionMultipleExit:
from: idle
duration: 3000
interval: 1000
chanceToEnterEntries:
entry:
to: walk
chance: 1
entry:
to: jump
chance: 1
IsNotGroundedTransition:
from: idle
to: air
StartLeftClicTransition:
from: walk
to: grab
RandomDelayTransition:
from: walk
to: idle
duration: 3000
interval: 500
StartLeftClicTransition:
from: walk
to: air
StartLeftClicTransition:
from: jump
to: grab
AnimationEndTransition:
from: jump
to: air
EndLeftClicTransition:
from: grab
to: air
IsGroundedTransition:
from: air
to: landing
AnimationEndTransition:
from: landing
to: idle
10 changes: 0 additions & 10 deletions resources/setting/setting.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,12 @@ Friction = 0.85 # [0, 1] : 0 no friction, 1 max friction
GravityX = 0
GravityY = 9.81
Bounciness = 0.7 # [0, 1] : 0 no bounciness, 1 full energie restitution
JumpVerticalThrust = 0.15 # min 0
JumpHorizontalThrust = 0.3 # min 0
ContinusCollisionMaxVelocity = 40 # min 0
FootBasasementWidth = 4 # min 2
FootBasasementHeight = 2 # min 2
CollisionPixelRatioStopMovement = 0.3 # min 0, max 1. Ratio of pixel with collision to detect a real collision
IsGroundedDetection = 1.0 # min 0

[Animation]
AnimationFrameRate = 10
WalkSpeed = 0.2 #min 0
WalkDuration = 1000 #min 0. in ms
WalkDurationInterval = 500 # in ms
IdleDuration = 3000 #min 0. in ms
IdleDurationInterval = 1000 # in ms

[Window]
ShowFrameBufferBackground = false
UseFowardWindow = true
Expand Down
3 changes: 3 additions & 0 deletions resources/sprites/air.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions resources/sprites/grab.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions resources/sprites/jump.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions resources/sprites/landing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading