The open source repository for the action RPG game in development by Sig Productions titled 'Adventures in Lestoria'!
https://forums.lestoria.net
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
268 lines
12 KiB
268 lines
12 KiB
1 year ago
|
#pragma region License
|
||
1 year ago
|
/*
|
||
|
License (OLC-3)
|
||
|
~~~~~~~~~~~~~~~
|
||
|
|
||
11 months ago
|
Copyright 2024 Joshua Sigona <sigonasr2@gmail.com>
|
||
1 year ago
|
|
||
|
Redistribution and use in source and binary forms, with or without modification,
|
||
|
are permitted provided that the following conditions are met:
|
||
|
|
||
|
1. Redistributions or derivations of source code must retain the above copyright
|
||
|
notice, this list of conditions and the following disclaimer.
|
||
|
|
||
|
2. Redistributions or derivative works in binary form must reproduce the above
|
||
|
copyright notice. This list of conditions and the following disclaimer must be
|
||
|
reproduced in the documentation and/or other materials provided with the distribution.
|
||
|
|
||
|
3. Neither the name of the copyright holder nor the names of its contributors may
|
||
|
be used to endorse or promote products derived from this software without specific
|
||
|
prior written permission.
|
||
|
|
||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||
|
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||
|
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||
|
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||
|
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||
|
SUCH DAMAGE.
|
||
1 year ago
|
|
||
|
Portions of this software are copyright © 2023 The FreeType
|
||
|
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
|
||
|
All rights reserved.
|
||
1 year ago
|
*/
|
||
1 year ago
|
#pragma endregion
|
||
1 year ago
|
#include "Animation.h"
|
||
11 months ago
|
#include "AdventuresInLestoria.h"
|
||
1 year ago
|
#include "DEFINES.h"
|
||
1 year ago
|
#include "safemap.h"
|
||
1 year ago
|
|
||
|
INCLUDE_game
|
||
|
INCLUDE_ANIMATION_DATA
|
||
1 year ago
|
INCLUDE_DATA
|
||
1 year ago
|
INCLUDE_GFX
|
||
1 year ago
|
|
||
|
void sig::Animation::InitializeAnimations(){
|
||
1 year ago
|
auto CreateStillAnimation=[&](std::string imgName,vf2d size,AnimationData data={}){
|
||
1 year ago
|
Animate2D::FrameSequence anim(data.frameDuration,data.style);
|
||
1 year ago
|
anim.AddFrame({&GFX[imgName],{{0,0},size}});
|
||
|
ANIMATION_DATA[imgName]=anim;
|
||
1 year ago
|
};
|
||
|
|
||
1 year ago
|
auto CreateHorizontalAnimationSequence=[&](std::string imgName,int frameCount,vf2d size,AnimationData data={}){
|
||
1 year ago
|
Animate2D::FrameSequence anim(data.frameDuration,data.style);
|
||
|
for(int i=0;i<frameCount;i++){
|
||
1 year ago
|
anim.AddFrame({&GFX[imgName],{{int(i*size.x),0},size}});
|
||
1 year ago
|
}
|
||
1 year ago
|
ANIMATION_DATA[imgName]=anim;
|
||
1 year ago
|
};
|
||
|
|
||
1 year ago
|
auto SetupClassWalkIdleAnimations=[&](Renderable&sheet,std::string className){
|
||
1 year ago
|
Animate2D::FrameSequence pl_walk_s{0.2f};
|
||
1 year ago
|
pl_walk_s.AddFrame({&sheet,{vi2d{0,0}*24,{24,24}}});
|
||
|
pl_walk_s.AddFrame({&sheet,{vi2d{1,0}*24,{24,24}}});
|
||
|
pl_walk_s.AddFrame({&sheet,{vi2d{0,0}*24,{24,24}}});
|
||
|
pl_walk_s.AddFrame({&sheet,{vi2d{2,0}*24,{24,24}}});
|
||
1 year ago
|
ANIMATION_DATA[className+"_WALK_S"]=pl_walk_s;
|
||
1 year ago
|
Animate2D::FrameSequence pl_walk_e{0.2f};
|
||
1 year ago
|
pl_walk_e.AddFrame({&sheet,{vi2d{0,3}*24,{24,24}}});
|
||
|
pl_walk_e.AddFrame({&sheet,{vi2d{1,3}*24,{24,24}}});
|
||
|
pl_walk_e.AddFrame({&sheet,{vi2d{0,3}*24,{24,24}}});
|
||
|
pl_walk_e.AddFrame({&sheet,{vi2d{2,3}*24,{24,24}}});
|
||
1 year ago
|
ANIMATION_DATA[className+"_WALK_E"]=pl_walk_e;
|
||
1 year ago
|
Animate2D::FrameSequence pl_walk_w{0.2f};
|
||
1 year ago
|
pl_walk_w.AddFrame({&sheet,{vi2d{0,2}*24,{24,24}}});
|
||
|
pl_walk_w.AddFrame({&sheet,{vi2d{1,2}*24,{24,24}}});
|
||
|
pl_walk_w.AddFrame({&sheet,{vi2d{0,2}*24,{24,24}}});
|
||
|
pl_walk_w.AddFrame({&sheet,{vi2d{2,2}*24,{24,24}}});
|
||
1 year ago
|
ANIMATION_DATA[className+"_WALK_W"]=pl_walk_w;
|
||
1 year ago
|
Animate2D::FrameSequence pl_walk_n{0.2f};
|
||
1 year ago
|
pl_walk_n.AddFrame({&sheet,{vi2d{0,1}*24,{24,24}}});
|
||
|
pl_walk_n.AddFrame({&sheet,{vi2d{1,1}*24,{24,24}}});
|
||
|
pl_walk_n.AddFrame({&sheet,{vi2d{0,1}*24,{24,24}}});
|
||
|
pl_walk_n.AddFrame({&sheet,{vi2d{2,1}*24,{24,24}}});
|
||
1 year ago
|
ANIMATION_DATA[className+"_WALK_N"]=pl_walk_n;
|
||
1 year ago
|
Animate2D::FrameSequence pl_idle_s;
|
||
|
pl_idle_s.AddFrame({&sheet,{vi2d{0,0}*24,{24,24}}});
|
||
1 year ago
|
ANIMATION_DATA[className+"_IDLE_S"]=pl_idle_s;
|
||
1 year ago
|
Animate2D::FrameSequence pl_idle_e;
|
||
|
pl_idle_e.AddFrame({&sheet,{vi2d{0,3}*24,{24,24}}});
|
||
1 year ago
|
ANIMATION_DATA[className+"_IDLE_E"]=pl_idle_e;
|
||
1 year ago
|
Animate2D::FrameSequence pl_idle_w;
|
||
|
pl_idle_w.AddFrame({&sheet,{vi2d{0,2}*24,{24,24}}});
|
||
1 year ago
|
ANIMATION_DATA[className+"_IDLE_W"]=pl_idle_w;
|
||
1 year ago
|
Animate2D::FrameSequence pl_idle_n;
|
||
|
pl_idle_n.AddFrame({&sheet,{vi2d{0,1}*24,{24,24}}});
|
||
1 year ago
|
ANIMATION_DATA[className+"_IDLE_N"]=pl_idle_n;
|
||
1 year ago
|
};
|
||
|
|
||
1 year ago
|
//Warrior animations.
|
||
1 year ago
|
SetupClassWalkIdleAnimations(GFX["nico-warrior.png"],"WARRIOR");
|
||
1 year ago
|
Animate2D::FrameSequence pl_warrior_swing_s(0.05f),pl_warrior_swing_n(0.05f),pl_warrior_swing_e(0.05f),pl_warrior_swing_w(0.05f);
|
||
|
Animate2D::FrameSequence pl_warrior_sonic_swing_s(0.1f,Animate2D::Style::OneShot),pl_warrior_sonic_swing_n(0.1f,Animate2D::Style::OneShot),pl_warrior_sonic_swing_e(0.1f,Animate2D::Style::OneShot),pl_warrior_sonic_swing_w(0.1f,Animate2D::Style::OneShot);
|
||
1 year ago
|
for (int i=0;i<4;i++){
|
||
1 year ago
|
pl_warrior_swing_s.AddFrame({&GFX["nico-warrior.png"],{vi2d{4+i,0}*24,{24,24}}});
|
||
|
pl_warrior_sonic_swing_s.AddFrame({&GFX["nico-warrior.png"],{vi2d{4+i,4}*24,{24,24}}});
|
||
1 year ago
|
}
|
||
|
for (int i=0;i<4;i++){
|
||
1 year ago
|
pl_warrior_swing_n.AddFrame({&GFX["nico-warrior.png"],{vi2d{4+i,1}*24,{24,24}}});
|
||
|
pl_warrior_sonic_swing_n.AddFrame({&GFX["nico-warrior.png"],{vi2d{4+i,5}*24,{24,24}}});
|
||
1 year ago
|
}
|
||
|
for (int i=0;i<4;i++){
|
||
1 year ago
|
pl_warrior_swing_w.AddFrame({&GFX["nico-warrior.png"],{vi2d{4+i,2}*24,{24,24}}});
|
||
|
pl_warrior_sonic_swing_w.AddFrame({&GFX["nico-warrior.png"],{vi2d{4+i,6}*24,{24,24}}});
|
||
1 year ago
|
}
|
||
|
for (int i=0;i<4;i++){
|
||
1 year ago
|
pl_warrior_swing_e.AddFrame({&GFX["nico-warrior.png"],{vi2d{4+i,3}*24,{24,24}}});
|
||
|
pl_warrior_sonic_swing_e.AddFrame({&GFX["nico-warrior.png"],{vi2d{4+i,7}*24,{24,24}}});
|
||
1 year ago
|
}
|
||
1 year ago
|
ANIMATION_DATA["WARRIOR_SWINGSWORD_N"]=pl_warrior_swing_n;
|
||
|
ANIMATION_DATA["WARRIOR_SWINGSWORD_E"]=pl_warrior_swing_e;
|
||
|
ANIMATION_DATA["WARRIOR_SWINGSWORD_S"]=pl_warrior_swing_s;
|
||
|
ANIMATION_DATA["WARRIOR_SWINGSWORD_W"]=pl_warrior_swing_w;
|
||
|
ANIMATION_DATA["WARRIOR_SWINGSONICSWORD_N"]=pl_warrior_sonic_swing_n;
|
||
|
ANIMATION_DATA["WARRIOR_SWINGSONICSWORD_E"]=pl_warrior_sonic_swing_e;
|
||
|
ANIMATION_DATA["WARRIOR_SWINGSONICSWORD_S"]=pl_warrior_sonic_swing_s;
|
||
|
ANIMATION_DATA["WARRIOR_SWINGSONICSWORD_W"]=pl_warrior_sonic_swing_w;
|
||
1 year ago
|
|
||
|
//Ranger animations
|
||
1 year ago
|
SetupClassWalkIdleAnimations(GFX["nico-ranger.png"],"RANGER");
|
||
1 year ago
|
Animate2D::FrameSequence pl_ranger_shoot_s,pl_ranger_shoot_n,pl_ranger_shoot_e,pl_ranger_shoot_w;
|
||
|
for(int i=0;i<3;i++){
|
||
1 year ago
|
pl_ranger_shoot_s.AddFrame({&GFX["nico-ranger.png"],{vi2d{3+i,0}*24,{24,24}}});
|
||
|
pl_ranger_shoot_n.AddFrame({&GFX["nico-ranger.png"],{vi2d{3+i,1}*24,{24,24}}});
|
||
|
pl_ranger_shoot_e.AddFrame({&GFX["nico-ranger.png"],{vi2d{3+i,3}*24,{24,24}}});
|
||
|
pl_ranger_shoot_w.AddFrame({&GFX["nico-ranger.png"],{vi2d{3+i,2}*24,{24,24}}});
|
||
1 year ago
|
}
|
||
1 year ago
|
ANIMATION_DATA["RANGER_SHOOT_S"]=pl_ranger_shoot_s;
|
||
|
ANIMATION_DATA["RANGER_SHOOT_N"]=pl_ranger_shoot_n;
|
||
|
ANIMATION_DATA["RANGER_SHOOT_E"]=pl_ranger_shoot_e;
|
||
|
ANIMATION_DATA["RANGER_SHOOT_W"]=pl_ranger_shoot_w;
|
||
1 year ago
|
|
||
|
//Wizard animations
|
||
1 year ago
|
SetupClassWalkIdleAnimations(GFX["nico-wizard.png"],"WIZARD");
|
||
1 year ago
|
Animate2D::FrameSequence pl_wizard_idle_attack_s;
|
||
1 year ago
|
pl_wizard_idle_attack_s.AddFrame({&GFX["nico-wizard.png"],{vi2d{4,0}*24,{24,24}}});
|
||
1 year ago
|
ANIMATION_DATA["WIZARD_IDLE_ATTACK_S"]=pl_wizard_idle_attack_s;
|
||
1 year ago
|
Animate2D::FrameSequence pl_wizard_idle_attack_e;
|
||
1 year ago
|
pl_wizard_idle_attack_e.AddFrame({&GFX["nico-wizard.png"],{vi2d{4,3}*24,{24,24}}});
|
||
1 year ago
|
ANIMATION_DATA["WIZARD_IDLE_ATTACK_E"]=pl_wizard_idle_attack_e;
|
||
1 year ago
|
Animate2D::FrameSequence pl_wizard_idle_attack_w;
|
||
1 year ago
|
pl_wizard_idle_attack_w.AddFrame({&GFX["nico-wizard.png"],{vi2d{4,2}*24,{24,24}}});
|
||
1 year ago
|
ANIMATION_DATA["WIZARD_IDLE_ATTACK_W"]=pl_wizard_idle_attack_w;
|
||
1 year ago
|
Animate2D::FrameSequence pl_wizard_idle_attack_n;
|
||
1 year ago
|
pl_wizard_idle_attack_n.AddFrame({&GFX["nico-wizard.png"],{vi2d{4,1}*24,{24,24}}});
|
||
1 year ago
|
ANIMATION_DATA["WIZARD_IDLE_ATTACK_N"]=pl_wizard_idle_attack_n;
|
||
1 year ago
|
Animate2D::FrameSequence pl_wizard_attack_s(0.2f);
|
||
1 year ago
|
for(int i=0;i<3;i++){
|
||
1 year ago
|
pl_wizard_attack_s.AddFrame({&GFX["nico-wizard.png"],{vi2d{4+i,0}*24,{24,24}}});
|
||
1 year ago
|
if(i==1){
|
||
1 year ago
|
pl_wizard_attack_s.AddFrame({&GFX["nico-wizard.png"],{vi2d{4,0}*24,{24,24}}});
|
||
1 year ago
|
}
|
||
|
}
|
||
1 year ago
|
ANIMATION_DATA["WIZARD_ATTACK_S"]=pl_wizard_attack_s;
|
||
1 year ago
|
Animate2D::FrameSequence pl_wizard_attack_e(0.2f);
|
||
1 year ago
|
for(int i=0;i<3;i++){
|
||
1 year ago
|
pl_wizard_attack_e.AddFrame({&GFX["nico-wizard.png"],{vi2d{4+i,3}*24,{24,24}}});
|
||
1 year ago
|
if(i==1){
|
||
1 year ago
|
pl_wizard_attack_e.AddFrame({&GFX["nico-wizard.png"],{vi2d{4,3}*24,{24,24}}});
|
||
1 year ago
|
}
|
||
|
}
|
||
1 year ago
|
ANIMATION_DATA["WIZARD_ATTACK_E"]=pl_wizard_attack_e;
|
||
1 year ago
|
Animate2D::FrameSequence pl_wizard_attack_w(0.2f);
|
||
1 year ago
|
for(int i=0;i<3;i++){
|
||
1 year ago
|
pl_wizard_attack_w.AddFrame({&GFX["nico-wizard.png"],{vi2d{4+i,2}*24,{24,24}}});
|
||
1 year ago
|
if(i==1){
|
||
1 year ago
|
pl_wizard_attack_w.AddFrame({&GFX["nico-wizard.png"],{vi2d{4,2}*24,{24,24}}});
|
||
1 year ago
|
}
|
||
|
}
|
||
1 year ago
|
ANIMATION_DATA["WIZARD_ATTACK_W"]=pl_wizard_attack_w;
|
||
1 year ago
|
Animate2D::FrameSequence pl_wizard_attack_n(0.2f);
|
||
1 year ago
|
for(int i=0;i<3;i++){
|
||
1 year ago
|
pl_wizard_attack_n.AddFrame({&GFX["nico-wizard.png"],{vi2d{4+i,1}*24,{24,24}}});
|
||
1 year ago
|
if(i==1){
|
||
1 year ago
|
pl_wizard_attack_n.AddFrame({&GFX["nico-wizard.png"],{vi2d{4,1}*24,{24,24}}});
|
||
1 year ago
|
}
|
||
|
}
|
||
1 year ago
|
ANIMATION_DATA["WIZARD_ATTACK_N"]=pl_wizard_attack_n;
|
||
1 year ago
|
Animate2D::FrameSequence pl_wizard_cast_s(0.1f);
|
||
1 year ago
|
for(int i=0;i<2;i++){
|
||
1 year ago
|
pl_wizard_cast_s.AddFrame({&GFX["nico-wizard.png"],{vi2d{7+i,0}*24,{24,24}}});
|
||
1 year ago
|
}
|
||
1 year ago
|
ANIMATION_DATA["WIZARD_CAST_S"]=pl_wizard_cast_s;
|
||
1 year ago
|
Animate2D::FrameSequence pl_wizard_cast_e(0.1f);
|
||
1 year ago
|
for(int i=0;i<2;i++){
|
||
1 year ago
|
pl_wizard_cast_e.AddFrame({&GFX["nico-wizard.png"],{vi2d{7+i,3}*24,{24,24}}});
|
||
1 year ago
|
}
|
||
1 year ago
|
ANIMATION_DATA["WIZARD_CAST_E"]=pl_wizard_cast_e;
|
||
1 year ago
|
Animate2D::FrameSequence pl_wizard_cast_n(0.1f);
|
||
1 year ago
|
for(int i=0;i<2;i++){
|
||
1 year ago
|
pl_wizard_cast_n.AddFrame({&GFX["nico-wizard.png"],{vi2d{7+i,1}*24,{24,24}}});
|
||
1 year ago
|
}
|
||
1 year ago
|
ANIMATION_DATA["WIZARD_CAST_N"]=pl_wizard_cast_n;
|
||
1 year ago
|
Animate2D::FrameSequence pl_wizard_cast_w(0.1f);
|
||
1 year ago
|
for(int i=0;i<2;i++){
|
||
1 year ago
|
pl_wizard_cast_w.AddFrame({&GFX["nico-wizard.png"],{vi2d{7+i,2}*24,{24,24}}});
|
||
1 year ago
|
}
|
||
1 year ago
|
ANIMATION_DATA["WIZARD_CAST_W"]=pl_wizard_cast_w;
|
||
1 year ago
|
|
||
1 year ago
|
CreateHorizontalAnimationSequence("ground-slam-attack-back.png",5,{64,64},{0.02f,Animate2D::Style::OneShot});
|
||
|
CreateHorizontalAnimationSequence("ground-slam-attack-front.png",5,{64,64},{0.02f,Animate2D::Style::OneShot});
|
||
|
CreateHorizontalAnimationSequence("battlecry_effect.png",5,{84,84},{0.02f,Animate2D::Style::OneShot});
|
||
|
CreateHorizontalAnimationSequence("sonicslash.png",4,{60,60},{0.04f,Animate2D::Style::OneShot});
|
||
1 year ago
|
|
||
1 year ago
|
CreateStillAnimation("energy_bolt.png",{24,24});
|
||
1 year ago
|
|
||
1 year ago
|
CreateHorizontalAnimationSequence("energy_particle.png",3,{3,3});
|
||
1 year ago
|
|
||
1 year ago
|
CreateHorizontalAnimationSequence("splash_effect.png",5,{24,24},{0.05f});
|
||
1 year ago
|
|
||
1 year ago
|
CreateStillAnimation("circle.png",{3,3});
|
||
1 year ago
|
|
||
1 year ago
|
CreateHorizontalAnimationSequence("lightning_bolt.png",5,{24,24},{0.03f,Animate2D::Style::PingPong});
|
||
1 year ago
|
|
||
1 year ago
|
CreateStillAnimation("lightning_bolt_part1.png",{5,5});
|
||
|
CreateStillAnimation("lightning_bolt_part2.png",{5,5});
|
||
|
CreateStillAnimation("lightning_bolt_part3.png",{5,5});
|
||
|
CreateStillAnimation("lightning_bolt_part4.png",{5,5});
|
||
1 year ago
|
|
||
1 year ago
|
CreateStillAnimation("chain_lightning.png",{1,9});
|
||
1 year ago
|
|
||
1 year ago
|
CreateHorizontalAnimationSequence("lightning_splash_effect.png",5,{24,24});
|
||
1 year ago
|
|
||
1 year ago
|
CreateStillAnimation("meteor.png",{192,192});
|
||
1 year ago
|
|
||
|
for(int i=0;i<5;i++){
|
||
|
Animate2D::FrameSequence firering;
|
||
1 year ago
|
firering.AddFrame({&GFX["fire_ring"+std::to_string(i)+".png"],{{0,0},{24,24}}});
|
||
|
ANIMATION_DATA["fire_ring"+std::to_string(i)+".png"]=firering;
|
||
1 year ago
|
}
|
||
1 year ago
|
CreateStillAnimation("arrow.png",{24,24});
|
||
|
CreateStillAnimation("charged_shot_arrow.png",{48,48});
|
||
|
CreateStillAnimation("laser.png",{5,1});
|
||
|
CreateStillAnimation("range_indicator.png",{24,24});
|
||
1 year ago
|
|
||
|
for(auto&dat:GFX){
|
||
|
std::string imgFile=dat.first;
|
||
|
if(!ANIMATION_DATA.count(imgFile)){
|
||
|
std::cout<<"WARNING! Animation data for "<<imgFile<<" not found! Auto-generating..."<<std::endl;
|
||
|
CreateStillAnimation(imgFile,GFX[imgFile].Sprite()->Size());
|
||
|
}
|
||
|
}
|
||
1 year ago
|
}
|
||
|
|
||
|
void sig::Animation::SetupPlayerAnimations(){
|
||
1 year ago
|
int counter=0;
|
||
|
while("Player"_A.HasProperty("PLAYER_ANIMATION["+std::to_string(counter)+"]")){
|
||
|
game->GetPlayer()->AddAnimation(DATA["Player"]["PLAYER_ANIMATION["+std::to_string(counter)+"]"].GetString()+"_N");
|
||
|
game->GetPlayer()->AddAnimation(DATA["Player"]["PLAYER_ANIMATION["+std::to_string(counter)+"]"].GetString()+"_E");
|
||
|
game->GetPlayer()->AddAnimation(DATA["Player"]["PLAYER_ANIMATION["+std::to_string(counter)+"]"].GetString()+"_S");
|
||
|
game->GetPlayer()->AddAnimation(DATA["Player"]["PLAYER_ANIMATION["+std::to_string(counter)+"]"].GetString()+"_W");
|
||
|
counter++;
|
||
|
}
|
||
1 year ago
|
|
||
|
ANIMATION_DATA.SetInitialized();
|
||
1 year ago
|
}
|