Keybind system redone, display keybinds and mana costs on HUD.
This commit is contained in:
parent
388cf0ba2d
commit
b9e1352288
@ -1,4 +1,5 @@
|
||||
#include "Ability.h"
|
||||
#include "Crawler.h"
|
||||
|
||||
PrecastData::PrecastData()
|
||||
:castTime(0),range(0),size(0){};
|
||||
@ -9,6 +10,9 @@ PrecastData::PrecastData(float castTime,float range,float size)
|
||||
if(castTime>0)precastTargetingRequired=true;
|
||||
};
|
||||
|
||||
Ability::Ability(){};
|
||||
Ability::Ability(std::string name,std::string shortName,float cooldownTime,int manaCost,Pixel barColor1,Pixel barColor2,PrecastData precastInfo,bool canCancelCast)
|
||||
:name(name),shortName(shortName),cooldown(0),COOLDOWN_TIME(cooldownTime),manaCost(manaCost),barColor1(barColor1),barColor2(barColor2),precastInfo(precastInfo),canCancelCast(canCancelCast){}
|
||||
InputGroup Ability::DEFAULT;
|
||||
|
||||
Ability::Ability()
|
||||
:name("???"),shortName("???"),cooldown(0),COOLDOWN_TIME(0),input(&DEFAULT){};
|
||||
Ability::Ability(std::string name,std::string shortName,float cooldownTime,int manaCost,InputGroup*input,Pixel barColor1,Pixel barColor2,PrecastData precastInfo,bool canCancelCast)
|
||||
:name(name),shortName(shortName),cooldown(0),COOLDOWN_TIME(cooldownTime),manaCost(manaCost),input(input),barColor1(barColor1),barColor2(barColor2),precastInfo(precastInfo),canCancelCast(canCancelCast){}
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "olcPixelGameEngine.h"
|
||||
#include "Key.h"
|
||||
|
||||
struct Player;
|
||||
|
||||
@ -25,7 +26,9 @@ struct Ability{
|
||||
Pixel barColor1,barColor2;
|
||||
PrecastData precastInfo;
|
||||
bool canCancelCast=false;
|
||||
InputGroup*input;
|
||||
std::function<bool(Player*,vf2d)>action=[](Player*,vf2d){return false;};
|
||||
static InputGroup DEFAULT;
|
||||
Ability();
|
||||
Ability(std::string name,std::string shortName,float cooldownTime,int manaCost,Pixel barColor1=VERY_DARK_RED,Pixel barColor2=DARK_RED,PrecastData precastInfo={},bool canCancelCast=false);
|
||||
Ability(std::string name,std::string shortName,float cooldownTime,int manaCost,InputGroup*input,Pixel barColor1=VERY_DARK_RED,Pixel barColor2=DARK_RED,PrecastData precastInfo={},bool canCancelCast=false);
|
||||
};
|
@ -16,6 +16,7 @@
|
||||
#include "Emitter.h"
|
||||
#include "config.h"
|
||||
#include "safemap.h"
|
||||
#include "Key.h"
|
||||
|
||||
INCLUDE_EMITTER_LIST
|
||||
|
||||
@ -30,11 +31,11 @@ safemap<std::string,Renderable>GFX;
|
||||
safemap<std::string,MapName>LEVEL_NAMES;
|
||||
utils::datafile DATA;
|
||||
Crawler*game;
|
||||
|
||||
Key Crawler::KEY_ABILITY1=Q;
|
||||
Key Crawler::KEY_ABILITY2=E;
|
||||
Key Crawler::KEY_ABILITY3=R;
|
||||
Key Crawler::KEY_ABILITY4=F;
|
||||
InputGroup Crawler::KEY_LEFT;
|
||||
InputGroup Crawler::KEY_RIGHT;
|
||||
InputGroup Crawler::KEY_UP;
|
||||
InputGroup Crawler::KEY_DOWN;
|
||||
InputGroup Crawler::KEY_ATTACK;
|
||||
|
||||
float Crawler::SIZE_CHANGE_SPEED=1;
|
||||
|
||||
@ -73,6 +74,7 @@ Crawler::Crawler()
|
||||
}
|
||||
|
||||
bool Crawler::OnUserCreate(){
|
||||
InitializeDefaultKeybinds();
|
||||
InitializeLevels();
|
||||
|
||||
circleCooldownPoints.push_back({0,0});
|
||||
@ -139,28 +141,28 @@ bool Crawler::OnUserUpdate(float fElapsedTime){
|
||||
}
|
||||
|
||||
bool Crawler::LeftHeld(){
|
||||
return GetKey(LEFT).bHeld||GetKey(A).bHeld;
|
||||
return KEY_LEFT.Held();
|
||||
}
|
||||
bool Crawler::RightHeld(){
|
||||
return GetKey(RIGHT).bHeld||GetKey(D).bHeld;
|
||||
return KEY_RIGHT.Held();
|
||||
}
|
||||
bool Crawler::UpHeld(){
|
||||
return GetKey(UP).bHeld||GetKey(W).bHeld;
|
||||
return KEY_UP.Held();
|
||||
}
|
||||
bool Crawler::DownHeld(){
|
||||
return GetKey(DOWN).bHeld||GetKey(S).bHeld;
|
||||
return KEY_DOWN.Held();
|
||||
}
|
||||
bool Crawler::LeftReleased(){
|
||||
return GetKey(LEFT).bReleased||GetKey(A).bReleased;
|
||||
return KEY_LEFT.Released();
|
||||
}
|
||||
bool Crawler::RightReleased(){
|
||||
return GetKey(RIGHT).bReleased||GetKey(D).bReleased;
|
||||
return KEY_RIGHT.Released();
|
||||
}
|
||||
bool Crawler::UpReleased(){
|
||||
return GetKey(UP).bReleased||GetKey(W).bReleased;
|
||||
return KEY_UP.Released();
|
||||
}
|
||||
bool Crawler::DownReleased(){
|
||||
return GetKey(DOWN).bReleased||GetKey(S).bReleased;
|
||||
return KEY_DOWN.Released();
|
||||
}
|
||||
|
||||
void Crawler::HandleUserInput(float fElapsedTime){
|
||||
@ -183,15 +185,15 @@ void Crawler::HandleUserInput(float fElapsedTime){
|
||||
}
|
||||
if(GetMouseWheel()<0){
|
||||
switch(player->GetClass()){
|
||||
case WARRIOR:{
|
||||
ChangePlayerClass(WIZARD);
|
||||
}break;
|
||||
case RANGER:{
|
||||
ChangePlayerClass(WARRIOR);
|
||||
}break;
|
||||
case WIZARD:{
|
||||
ChangePlayerClass(RANGER);
|
||||
}break;
|
||||
case WARRIOR:{
|
||||
ChangePlayerClass(WIZARD);
|
||||
}break;
|
||||
case RANGER:{
|
||||
ChangePlayerClass(WARRIOR);
|
||||
}break;
|
||||
case WIZARD:{
|
||||
ChangePlayerClass(RANGER);
|
||||
}break;
|
||||
}
|
||||
}
|
||||
if(player->GetVelocity()==vf2d{0,0}&&player->CanMove()){
|
||||
@ -1048,15 +1050,17 @@ void Crawler::RenderCooldowns(){
|
||||
}
|
||||
DrawDecal(pos,GFX["skill_overlay_icon.png"].Decal());
|
||||
|
||||
Pixel shortNameCol=BLUE,manaCostShadowCol=DARK_BLUE;
|
||||
Pixel shortNameCol=BLUE,manaCostShadowCol=DARK_BLUE,keyDisplayCol=YELLOW;
|
||||
if(player->GetMana()<a.manaCost){
|
||||
DrawDecal(pos,GFX["skill_overlay_icon_overlay.png"].Decal(),{1,1},DARK_RED);
|
||||
shortNameCol=RED;
|
||||
manaCostShadowCol=DARK_RED;
|
||||
keyDisplayCol=RED;
|
||||
}else
|
||||
if(a.cooldown>0){
|
||||
shortNameCol=GREY;
|
||||
manaCostShadowCol=DARK_GREY;
|
||||
keyDisplayCol=GREY;
|
||||
}
|
||||
|
||||
if(a.manaCost>0){
|
||||
@ -1064,6 +1068,9 @@ void Crawler::RenderCooldowns(){
|
||||
DrawShadowStringDecal(pos+vf2d{20,4}-manaCostSize/2,std::to_string(a.manaCost),{192,192,255},manaCostShadowCol,{0.5,0.75});
|
||||
}
|
||||
|
||||
vf2d keyDisplaySize=vf2d{GetTextSize(a.input->GetDisplayName())}*vf2d{0.5,0.5};
|
||||
DrawShadowStringDecal(pos+vf2d{12,-2}-keyDisplaySize/2,a.input->GetDisplayName(),keyDisplayCol,BLACK,{0.5,0.5},1);
|
||||
|
||||
vf2d shortNameSize=vf2d{GetTextSize(a.shortName)}*vf2d{0.5,0.75};
|
||||
DrawShadowStringDecal(pos+vf2d{13,24}-shortNameSize/2,a.shortName,shortNameCol,{255,255,255,64},{0.5,0.75});
|
||||
}
|
||||
@ -1561,3 +1568,20 @@ void Crawler::SpawnMonster(vf2d pos,MonsterData*data,bool upperLevel){
|
||||
void Crawler::DrawPie(vf2d center,float radius,float degreesCut,Pixel col){
|
||||
DrawPolygonDecal(nullptr,circleCooldownPoints,circleCooldownPoints,std::max(1,int(degreesCut/4)),center,radius,col);
|
||||
}
|
||||
|
||||
void Crawler::InitializeDefaultKeybinds(){
|
||||
Player::KEY_ABILITY1.AddKeybind({KEY,Q});
|
||||
Player::KEY_ABILITY2.AddKeybind({KEY,E});
|
||||
Player::KEY_ABILITY3.AddKeybind({KEY,R});
|
||||
Player::KEY_ABILITY4.AddKeybind({KEY,F});
|
||||
Player::KEY_DEFENSIVE.AddKeybind({MOUSE,Mouse::RIGHT});
|
||||
KEY_ATTACK.AddKeybind({MOUSE,Mouse::LEFT});
|
||||
KEY_LEFT.AddKeybind({KEY,LEFT});
|
||||
KEY_LEFT.AddKeybind({KEY,A});
|
||||
KEY_RIGHT.AddKeybind({KEY,RIGHT});
|
||||
KEY_RIGHT.AddKeybind({KEY,D});
|
||||
KEY_UP.AddKeybind({KEY,UP});
|
||||
KEY_UP.AddKeybind({KEY,W});
|
||||
KEY_DOWN.AddKeybind({KEY,DOWN});
|
||||
KEY_DOWN.AddKeybind({KEY,S});
|
||||
}
|
@ -11,6 +11,7 @@
|
||||
#include "Map.h"
|
||||
#include "TMXParser.h"
|
||||
#include "olcUTIL_DataFile.h"
|
||||
#include "Key.h"
|
||||
|
||||
class Crawler : public olc::PixelGameEngine
|
||||
{
|
||||
@ -19,10 +20,11 @@ class Crawler : public olc::PixelGameEngine
|
||||
std::unique_ptr<Player>player;
|
||||
public:
|
||||
Pathfinding pathfinder;
|
||||
static Key KEY_ABILITY1;
|
||||
static Key KEY_ABILITY2;
|
||||
static Key KEY_ABILITY3;
|
||||
static Key KEY_ABILITY4;
|
||||
static InputGroup KEY_ATTACK;
|
||||
static InputGroup KEY_LEFT;
|
||||
static InputGroup KEY_RIGHT;
|
||||
static InputGroup KEY_UP;
|
||||
static InputGroup KEY_DOWN;
|
||||
static float SIZE_CHANGE_SPEED;
|
||||
float levelTime;
|
||||
private:
|
||||
@ -114,6 +116,7 @@ public:
|
||||
void SpawnMonster(vf2d pos,MonsterData*data,bool upperLevel=false); //Queues a monster for spawning on the next frame.
|
||||
void DrawPie(vf2d center,float radius,float degreesCut,Pixel col);
|
||||
void RenderCooldowns();
|
||||
void InitializeDefaultKeybinds();
|
||||
|
||||
struct TileGroupData{
|
||||
vi2d tilePos;
|
||||
|
@ -270,6 +270,7 @@
|
||||
<ClInclude Include="DEFINES.h" />
|
||||
<ClInclude Include="Effect.h" />
|
||||
<ClInclude Include="Emitter.h" />
|
||||
<ClInclude Include="Key.h" />
|
||||
<ClInclude Include="Map.h" />
|
||||
<ClInclude Include="Monster.h" />
|
||||
<ClInclude Include="MonsterAttribute.h" />
|
||||
@ -304,6 +305,7 @@
|
||||
<ClCompile Include="EnergyBolt.cpp" />
|
||||
<ClCompile Include="FallingDebris.h" />
|
||||
<ClCompile Include="FireBolt.cpp" />
|
||||
<ClCompile Include="Key.cpp" />
|
||||
<ClCompile Include="LightningBolt.cpp" />
|
||||
<ClCompile Include="LightningBoltEmitter.cpp" />
|
||||
<ClCompile Include="Map.cpp" />
|
||||
|
@ -138,6 +138,9 @@
|
||||
<ClInclude Include="MonsterAttribute.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Key.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Player.cpp">
|
||||
@ -245,6 +248,9 @@
|
||||
<ClCompile Include="RunAway.cpp">
|
||||
<Filter>Source Files\Monster Strategies</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Key.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="cpp.hint" />
|
||||
|
@ -42,11 +42,11 @@ std::string&class::GetIdleSAnimation(){return idle_s;}; \
|
||||
std::string&class::GetIdleWAnimation(){return idle_w;}; \
|
||||
std::string class::name=""; \
|
||||
Class class::cl=ANY; \
|
||||
Ability class::rightClickAbility=Ability("???","???",0,0); \
|
||||
Ability class::ability1=Ability("???","???",0,0); \
|
||||
Ability class::ability2=Ability("???","???",0,0); \
|
||||
Ability class::ability3=Ability("???","???",0,0); \
|
||||
Ability class::ability4=Ability("???","???",0,0); \
|
||||
Ability class::rightClickAbility=Ability(); \
|
||||
Ability class::ability1=Ability(); \
|
||||
Ability class::ability2=Ability(); \
|
||||
Ability class::ability3=Ability(); \
|
||||
Ability class::ability4=Ability(); \
|
||||
std::string class::idle_n="WARRIOR_IDLE_N"; \
|
||||
std::string class::idle_e="WARRIOR_IDLE_E"; \
|
||||
std::string class::idle_s="WARRIOR_IDLE_S"; \
|
||||
|
200
Crawler/Key.cpp
Normal file
200
Crawler/Key.cpp
Normal file
@ -0,0 +1,200 @@
|
||||
#include "Key.h"
|
||||
#include "DEFINES.h"
|
||||
#include "Crawler.h"
|
||||
|
||||
INCLUDE_game
|
||||
|
||||
Input::Input(InputType type,int key)
|
||||
:type(type),key(key){}
|
||||
|
||||
bool Input::Pressed(){
|
||||
switch(type){
|
||||
case KEY:{
|
||||
return game->GetKey(Key(key)).bPressed;
|
||||
}break;
|
||||
case MOUSE:{
|
||||
return game->GetMouse(key).bPressed;
|
||||
}break;
|
||||
case CONTROLLER:{
|
||||
throw; //TODO: Throw for now, this control scheme is unsupported!
|
||||
}break;
|
||||
}
|
||||
}
|
||||
|
||||
bool Input::Held(){
|
||||
switch(type){
|
||||
case KEY:{
|
||||
return game->GetKey(Key(key)).bHeld;
|
||||
}break;
|
||||
case MOUSE:{
|
||||
return game->GetMouse(key).bHeld;
|
||||
}break;
|
||||
case CONTROLLER:{
|
||||
throw; //TODO: Throw for now, this control scheme is unsupported!
|
||||
}break;
|
||||
}
|
||||
}
|
||||
|
||||
bool Input::Released(){
|
||||
switch(type){
|
||||
case KEY:{
|
||||
return game->GetKey(Key(key)).bReleased;
|
||||
}break;
|
||||
case MOUSE:{
|
||||
return game->GetMouse(key).bReleased;
|
||||
}break;
|
||||
case CONTROLLER:{
|
||||
throw; //TODO: Throw for now, this control scheme is unsupported!
|
||||
}break;
|
||||
}
|
||||
}
|
||||
|
||||
std::string Input::GetDisplayName(){
|
||||
return GenericKey::keyLiteral.at({type,key});
|
||||
}
|
||||
|
||||
InputGroup::InputGroup(){}
|
||||
|
||||
void InputGroup::AddKeybind(Input bind){
|
||||
keys.insert(bind);
|
||||
}
|
||||
|
||||
void InputGroup::RemoveKeybind(Input bind){
|
||||
keys.erase(bind);
|
||||
}
|
||||
|
||||
bool InputGroup::Pressed(){
|
||||
for(Input input:keys){
|
||||
if(input.Pressed())return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InputGroup::Held(){
|
||||
for(Input input:keys){
|
||||
if(input.Held())return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InputGroup::Released(){
|
||||
for(Input input:keys){
|
||||
if(input.Released())return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string InputGroup::GetDisplayName(){
|
||||
std::string combinationDisplay="";
|
||||
for(Input input:keys){
|
||||
if(combinationDisplay.length()>0){
|
||||
combinationDisplay+=",";
|
||||
}
|
||||
combinationDisplay+=input.GetDisplayName();
|
||||
}
|
||||
return combinationDisplay;
|
||||
}
|
||||
|
||||
std::map<std::pair<InputType,int>,std::string> GenericKey::keyLiteral={
|
||||
{{KEY, NONE},""},
|
||||
{{KEY, A},"A"},
|
||||
{{KEY, B},"B"},
|
||||
{{KEY, C},"C"},
|
||||
{{KEY, D},"D"},
|
||||
{{KEY, E},"E"},
|
||||
{{KEY, F},"F"},
|
||||
{{KEY, G},"G"},
|
||||
{{KEY, H},"H"},
|
||||
{{KEY, I},"I"},
|
||||
{{KEY, J},"J"},
|
||||
{{KEY, K},"L"},
|
||||
{{KEY, L},"L"},
|
||||
{{KEY, M},"M"},
|
||||
{{KEY, N},"N"},
|
||||
{{KEY, O},"O"},
|
||||
{{KEY, P},"P"},
|
||||
{{KEY, Q},"Q"},
|
||||
{{KEY, R},"R"},
|
||||
{{KEY, S},"S"},
|
||||
{{KEY, T},"T"},
|
||||
{{KEY, U},"U"},
|
||||
{{KEY, V},"V"},
|
||||
{{KEY, W},"W"},
|
||||
{{KEY, X},"X"},
|
||||
{{KEY, Y},"Y"},
|
||||
{{KEY, Z},"Z"},
|
||||
{{KEY, K0},"0"},
|
||||
{{KEY, K1},"1"},
|
||||
{{KEY, K2},"2"},
|
||||
{{KEY, K3},"3"},
|
||||
{{KEY, K4},"4"},
|
||||
{{KEY, K5},"5"},
|
||||
{{KEY, K6},"6"},
|
||||
{{KEY, K7},"7"},
|
||||
{{KEY, K8},"8"},
|
||||
{{KEY, K9},"9"},
|
||||
{{KEY, F1},"F1"},
|
||||
{{KEY, F2},"F2"},
|
||||
{{KEY, F3},"F3"},
|
||||
{{KEY, F4},"F4"},
|
||||
{{KEY, F5},"F5"},
|
||||
{{KEY, F6},"F6"},
|
||||
{{KEY, F7},"F7"},
|
||||
{{KEY, F8},"F8"},
|
||||
{{KEY, F9},"F9"},
|
||||
{{KEY, F10},"F10"},
|
||||
{{KEY, F11},"F11"},
|
||||
{{KEY, F12},"F12"},
|
||||
{{KEY, UP},"UP"},
|
||||
{{KEY, DOWN},"DOWN"},
|
||||
{{KEY, LEFT},"LEFT"},
|
||||
{{KEY, RIGHT},"RIGHT"},
|
||||
{{KEY, SPACE},"SPACE"},
|
||||
{{KEY, TAB},"TAB"},
|
||||
{{KEY, SHIFT},"SHIFT"},
|
||||
{{KEY, CTRL},"CTRL"},
|
||||
{{KEY, INS},"INS"},
|
||||
{{KEY, DEL},"DEL"},
|
||||
{{KEY, HOME},"HOME"},
|
||||
{{KEY, END},"END"},
|
||||
{{KEY, PGUP},"PGUP"},
|
||||
{{KEY, PGDN},"PGDN"},
|
||||
{{KEY, BACK},"BACK"},
|
||||
{{KEY, ESCAPE},"ESC"},
|
||||
{{KEY, RETURN},"ENTER"},
|
||||
{{KEY, ENTER},"ENTER"},
|
||||
{{KEY, PAUSE},"PAUSE"},
|
||||
{{KEY, SCROLL},"SCR LK"},
|
||||
{{KEY, NP0},"NP0"},
|
||||
{{KEY, NP1},"NP1"},
|
||||
{{KEY, NP2},"NP2"},
|
||||
{{KEY, NP3},"NP3"},
|
||||
{{KEY, NP4},"NP4"},
|
||||
{{KEY, NP5},"NP5"},
|
||||
{{KEY, NP6},"NP6"},
|
||||
{{KEY, NP7},"NP7"},
|
||||
{{KEY, NP8},"NP8"},
|
||||
{{KEY, NP9},"NP9"},
|
||||
{{KEY, NP_MUL},"NP*"},
|
||||
{{KEY, NP_DIV},"NP/"},
|
||||
{{KEY, NP_ADD},"NP+"},
|
||||
{{KEY, NP_SUB},"NP-"},
|
||||
{{KEY, NP_DECIMAL},"NP."},
|
||||
{{KEY, PERIOD},"."},
|
||||
{{KEY, EQUALS},"="},
|
||||
{{KEY, COMMA},","},
|
||||
{{KEY, MINUS},"-"},
|
||||
{{KEY, OEM_1},";"},
|
||||
{{KEY, OEM_2},"/"},
|
||||
{{KEY, OEM_3},"~"},
|
||||
{{KEY, OEM_4},"["},
|
||||
{{KEY, OEM_5},"\\"},
|
||||
{{KEY, OEM_6},"]"},
|
||||
{{KEY, OEM_7},"\""},
|
||||
{{KEY, OEM_8},"\\"},
|
||||
{{KEY, CAPS_LOCK},"CAP LK"},
|
||||
{{KEY, ENUM_END},""},
|
||||
{{MOUSE, Mouse::LEFT},"L.MOUSE"},
|
||||
{{MOUSE, Mouse::RIGHT},"R.MOUSE"},
|
||||
{{MOUSE, Mouse::MIDDLE},"M.MOUSE"},
|
||||
};
|
43
Crawler/Key.h
Normal file
43
Crawler/Key.h
Normal file
@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
#include "olcPixelGameEngine.h"
|
||||
#include <set>
|
||||
|
||||
//Future-proof game controller support.
|
||||
enum InputType{
|
||||
KEY,
|
||||
MOUSE,
|
||||
CONTROLLER
|
||||
};
|
||||
|
||||
//A generic class that represents any type of input.
|
||||
class Input{
|
||||
friend class InputGroup;
|
||||
InputType type;
|
||||
int key; //This will be interpreted differently depending on input type.
|
||||
public:
|
||||
Input(InputType type,int key);
|
||||
bool Pressed();
|
||||
bool Held();
|
||||
bool Released();
|
||||
std::string GetDisplayName();
|
||||
bool operator<(const Input&rhs)const{
|
||||
return type<rhs.type||(type==rhs.type&&key<rhs.key);
|
||||
}
|
||||
};
|
||||
|
||||
class InputGroup{
|
||||
std::set<Input>keys;
|
||||
public:
|
||||
InputGroup();
|
||||
void AddKeybind(Input bind);
|
||||
void RemoveKeybind(Input bind);
|
||||
bool Pressed();
|
||||
bool Held();
|
||||
bool Released();
|
||||
std::string GetDisplayName();
|
||||
};
|
||||
|
||||
class GenericKey{
|
||||
public:
|
||||
static std::map<std::pair<InputType,int>,std::string>keyLiteral; //The displayed text for a given key for a given input type.
|
||||
};
|
@ -7,6 +7,7 @@
|
||||
#include "DEFINES.h"
|
||||
#include "safemap.h"
|
||||
#include "utils.h"
|
||||
#include "Key.h"
|
||||
|
||||
INCLUDE_MONSTER_DATA
|
||||
INCLUDE_MONSTER_LIST
|
||||
@ -18,6 +19,12 @@ INCLUDE_game
|
||||
|
||||
float Player::GROUND_SLAM_SPIN_TIME=0.6f;
|
||||
|
||||
InputGroup Player::KEY_ABILITY1;
|
||||
InputGroup Player::KEY_ABILITY2;
|
||||
InputGroup Player::KEY_ABILITY3;
|
||||
InputGroup Player::KEY_ABILITY4;
|
||||
InputGroup Player::KEY_DEFENSIVE;
|
||||
|
||||
Player::Player()
|
||||
:lastReleasedMovementKey(DOWN),facingDirection(DOWN),state(State::NORMAL){
|
||||
Initialize();
|
||||
@ -337,18 +344,18 @@ void Player::Update(float fElapsedTime){
|
||||
SetX(newX);
|
||||
SetY(newY);
|
||||
}
|
||||
if(CanAct()&&attack_cooldown_timer==0&&game->GetMouse(0).bHeld){
|
||||
if(CanAct()&&attack_cooldown_timer==0&&Crawler::KEY_ATTACK.Held()){
|
||||
AutoAttack();
|
||||
}
|
||||
|
||||
|
||||
auto AllowedToCast=[&](Ability&ability){return !ability.precastInfo.precastTargetingRequired&&GetState()!=State::ANIMATION_LOCK;};
|
||||
//If pressed is set to false, uses held instead.
|
||||
auto CheckAndPerformAbility=[&](Ability&ability,HWButton key){
|
||||
auto CheckAndPerformAbility=[&](Ability&ability,InputGroup key){
|
||||
if(ability.name!="???"){
|
||||
if(CanAct(ability)){
|
||||
if(ability.cooldown==0&&GetMana()>=ability.manaCost){
|
||||
if(key.bHeld||key.bReleased&&&ability==castPrepAbility&&GetState()==State::PREP_CAST){
|
||||
if(key.Held()||key.Released()&&&ability==castPrepAbility&&GetState()==State::PREP_CAST){
|
||||
if(GetState()==State::CASTING){
|
||||
SetState(State::NORMAL);
|
||||
castInfo.castTimer=castInfo.castTotalTime=0;
|
||||
@ -362,31 +369,31 @@ void Player::Update(float fElapsedTime){
|
||||
}
|
||||
}
|
||||
} else
|
||||
if(ability.cooldown==0&&GetMana()<ability.manaCost&&key.bPressed){
|
||||
if(ability.cooldown==0&&GetMana()<ability.manaCost&&key.Pressed()){
|
||||
notEnoughManaDisplay={ability.name,1};
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
CheckAndPerformAbility(GetAbility1(),game->GetKey(Crawler::KEY_ABILITY1));
|
||||
CheckAndPerformAbility(GetAbility2(),game->GetKey(Crawler::KEY_ABILITY2));
|
||||
CheckAndPerformAbility(GetAbility3(),game->GetKey(Crawler::KEY_ABILITY3));
|
||||
CheckAndPerformAbility(GetAbility4(),game->GetKey(Crawler::KEY_ABILITY4));
|
||||
CheckAndPerformAbility(GetRightClickAbility(),game->GetMouse(1));
|
||||
CheckAndPerformAbility(GetAbility1(),Player::KEY_ABILITY1);
|
||||
CheckAndPerformAbility(GetAbility2(),Player::KEY_ABILITY2);
|
||||
CheckAndPerformAbility(GetAbility3(),Player::KEY_ABILITY3);
|
||||
CheckAndPerformAbility(GetAbility4(),Player::KEY_ABILITY4);
|
||||
CheckAndPerformAbility(GetRightClickAbility(),Player::KEY_DEFENSIVE);
|
||||
|
||||
if(GetState()==State::PREP_CAST){
|
||||
#define CheckAbilityKeyReleasedAndCastSpell(ability,input) \
|
||||
if(&ability==castPrepAbility&&input.bReleased){CastSpell(ability);}
|
||||
#define CheckAbilityKeyReleasedAndCastSpell(ability,releaseState) \
|
||||
if(&ability==castPrepAbility&&releaseState){CastSpell(ability);}
|
||||
|
||||
CheckAbilityKeyReleasedAndCastSpell(rightClickAbility,game->GetMouse(1))
|
||||
else
|
||||
CheckAbilityKeyReleasedAndCastSpell(ability,game->GetKey(Crawler::KEY_ABILITY1))
|
||||
else
|
||||
CheckAbilityKeyReleasedAndCastSpell(ability2,game->GetKey(Crawler::KEY_ABILITY2))
|
||||
else
|
||||
CheckAbilityKeyReleasedAndCastSpell(ability3,game->GetKey(Crawler::KEY_ABILITY3))
|
||||
else
|
||||
CheckAbilityKeyReleasedAndCastSpell(ability4,game->GetKey(Crawler::KEY_ABILITY4))
|
||||
CheckAbilityKeyReleasedAndCastSpell(rightClickAbility,Player::KEY_DEFENSIVE.Released())
|
||||
else
|
||||
CheckAbilityKeyReleasedAndCastSpell(ability,Player::KEY_ABILITY1.Released())
|
||||
else
|
||||
CheckAbilityKeyReleasedAndCastSpell(ability2,Player::KEY_ABILITY2.Released())
|
||||
else
|
||||
CheckAbilityKeyReleasedAndCastSpell(ability3,Player::KEY_ABILITY3.Released())
|
||||
else
|
||||
CheckAbilityKeyReleasedAndCastSpell(ability4,Player::KEY_ABILITY4.Released())
|
||||
}
|
||||
|
||||
#pragma region Warrior
|
||||
@ -492,7 +499,7 @@ bool Player::CanMove(){
|
||||
}
|
||||
|
||||
bool Player::CanAct(){
|
||||
Ability dummyAbility{"Dummy Ability","DUMMY",0,0};
|
||||
Ability dummyAbility;
|
||||
return CanAct(dummyAbility);
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "Pathfinding.h"
|
||||
#include "DamageNumber.h"
|
||||
#include "config.h"
|
||||
#include "Key.h"
|
||||
|
||||
struct CastInfo{
|
||||
std::string name;
|
||||
@ -169,6 +170,8 @@ public:
|
||||
|
||||
CastInfo&GetCastInfo();
|
||||
void SetAnimationBasedOnTargetingDirection(float targetDirection);
|
||||
|
||||
static InputGroup KEY_ABILITY1, KEY_ABILITY2, KEY_ABILITY3, KEY_ABILITY4, KEY_DEFENSIVE;
|
||||
};
|
||||
|
||||
struct Warrior:Player{
|
||||
@ -353,6 +356,7 @@ struct Witch:Player{
|
||||
#class".Right Click Ability.Short Name"_S, \
|
||||
#class".Right Click Ability.Cooldown"_F, \
|
||||
#class".Right Click Ability.Mana Cost"_I, \
|
||||
&KEY_DEFENSIVE, \
|
||||
{uint8_t(#class".Right Click Ability.Cooldown Bar Color 1"_f[0]),uint8_t(#class".Right Click Ability.Cooldown Bar Color 1"_f[1]),uint8_t(#class".Right Click Ability.Cooldown Bar Color 1"_f[2]),uint8_t(#class".Right Click Ability.Cooldown Bar Color 1"_f[3]==0?255:#class".Right Click Ability.Cooldown Bar Color 1"_f[3])}, \
|
||||
{uint8_t(#class".Right Click Ability.Cooldown Bar Color 2"_f[0]),uint8_t(#class".Right Click Ability.Cooldown Bar Color 2"_f[1]),uint8_t(#class".Right Click Ability.Cooldown Bar Color 2"_f[2]),uint8_t(#class".Right Click Ability.Cooldown Bar Color 2"_f[3]==0?255:#class".Right Click Ability.Cooldown Bar Color 2"_f[3])}, \
|
||||
{#class".Right Click Ability.Precast Time"_F,#class".Right Click Ability.Casting Range"_I/100.f*24,#class".Right Click Ability.Casting Size"_I/100.f*24}, \
|
||||
@ -363,6 +367,7 @@ struct Witch:Player{
|
||||
#class".Ability 1.Short Name"_S, \
|
||||
#class".Ability 1.Cooldown"_F, \
|
||||
#class".Ability 1.Mana Cost"_I, \
|
||||
&KEY_ABILITY1, \
|
||||
{uint8_t(#class".Ability 1.Cooldown Bar Color 1"_f[0]),uint8_t(#class".Ability 1.Cooldown Bar Color 1"_f[1]),uint8_t(#class".Ability 1.Cooldown Bar Color 1"_f[2]),uint8_t(#class".Ability 1.Cooldown Bar Color 1"_f[3]==0?255:#class".Ability 1.Cooldown Bar Color 1"_f[3])}, \
|
||||
{uint8_t(#class".Ability 1.Cooldown Bar Color 2"_f[0]),uint8_t(#class".Ability 1.Cooldown Bar Color 2"_f[1]),uint8_t(#class".Ability 1.Cooldown Bar Color 2"_f[2]),uint8_t(#class".Ability 1.Cooldown Bar Color 2"_f[3]==0?255:#class".Ability 1.Cooldown Bar Color 2"_f[3])}, \
|
||||
{#class".Ability 1.Precast Time"_F,#class".Ability 1.Casting Range"_I/100.f*24,#class".Ability 1.Casting Size"_I/100.f*24}, \
|
||||
@ -373,6 +378,7 @@ struct Witch:Player{
|
||||
#class".Ability 2.Short Name"_S, \
|
||||
#class".Ability 2.Cooldown"_F, \
|
||||
#class".Ability 2.Mana Cost"_I, \
|
||||
&KEY_ABILITY2, \
|
||||
{uint8_t(#class".Ability 2.Cooldown Bar Color 1"_f[0]),uint8_t(#class".Ability 2.Cooldown Bar Color 1"_f[1]),uint8_t(#class".Ability 2.Cooldown Bar Color 1"_f[2]),uint8_t(#class".Ability 2.Cooldown Bar Color 1"_f[3]==0?255:#class".Ability 2.Cooldown Bar Color 1"_f[3])}, \
|
||||
{uint8_t(#class".Ability 2.Cooldown Bar Color 2"_f[0]),uint8_t(#class".Ability 2.Cooldown Bar Color 2"_f[1]),uint8_t(#class".Ability 2.Cooldown Bar Color 2"_f[2]),uint8_t(#class".Ability 2.Cooldown Bar Color 2"_f[3]==0?255:#class".Ability 2.Cooldown Bar Color 2"_f[3])}, \
|
||||
{#class".Ability 2.Precast Time"_F,#class".Ability 2.Casting Range"_I/100.f*24,#class".Ability 2.Casting Size"_I/100.f*24}, \
|
||||
@ -383,9 +389,10 @@ struct Witch:Player{
|
||||
#class".Ability 3.Short Name"_S, \
|
||||
#class".Ability 3.Cooldown"_F, \
|
||||
#class".Ability 3.Mana Cost"_I, \
|
||||
&KEY_ABILITY3, \
|
||||
{uint8_t(#class".Ability 3.Cooldown Bar Color 1"_f[0]),uint8_t(#class".Ability 3.Cooldown Bar Color 1"_f[1]),uint8_t(#class".Ability 3.Cooldown Bar Color 1"_f[2]),uint8_t(#class".Ability 3.Cooldown Bar Color 1"_f[3]==0?255:#class".Ability 3.Cooldown Bar Color 1"_f[3])}, \
|
||||
{uint8_t(#class".Ability 3.Cooldown Bar Color 2"_f[0]),uint8_t(#class".Ability 3.Cooldown Bar Color 2"_f[1]),uint8_t(#class".Ability 3.Cooldown Bar Color 2"_f[2]),uint8_t(#class".Ability 3.Cooldown Bar Color 2"_f[3]==0?255:#class".Ability 3.Cooldown Bar Color 2"_f[3])}, \
|
||||
{#class".Ability 3.Precast Time"_F,#class".Ability 3.Casting Range"_I/100.f*24,#class".Ability 3.Casting Size"_I/100.f*24}, \
|
||||
bool(#class".Ability 3.CancelCast"_I) \
|
||||
}; \
|
||||
class::ability4={"???","",0,0};
|
||||
class::ability4;
|
@ -2,7 +2,7 @@
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 2
|
||||
#define VERSION_PATCH 0
|
||||
#define VERSION_BUILD 1529
|
||||
#define VERSION_BUILD 1553
|
||||
|
||||
#define stringify(a) stringify_(a)
|
||||
#define stringify_(a) #a
|
||||
|
Loading…
x
Reference in New Issue
Block a user