Prep Monster structures

pull/28/head
sigonasr2 1 year ago
parent cbbee7aaa4
commit 86867cd82c
  1. 1
      Crawler/Crawler.vcxproj
  2. 3
      Crawler/Crawler.vcxproj.filters
  3. 41
      Crawler/Monster.cpp
  4. 41
      Crawler/Monster.h
  5. 81
      Crawler/main.cpp

@ -138,6 +138,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
<ClCompile Include="Monster.cpp" />
<ClCompile Include="MonsterData.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

@ -41,5 +41,8 @@
<ClCompile Include="MonsterData.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Monster.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

@ -0,0 +1,41 @@
#include "Monster.h"
MonsterData::MonsterData(){}
MonsterData::MonsterData(int hp,int atk,float moveSpd,float size,MonsterStrategy strategy):
hp(hp),atk(atk),moveSpd(moveSpd),size(size),strategy(strategy){
}
int MonsterData::GetHealth(){
return hp;
}
int MonsterData::GetAttack(){
return atk;
}
float MonsterData::GetMoveSpdMult(){
return moveSpd;
}
float MonsterData::GetSizeMult(){
return size;
}
MonsterStrategy MonsterData::GetAIStrategy(){
return strategy;
}
Monster::Monster(){}
Monster::Monster(vf2d pos,MonsterData data):
pos(pos),hp(data.GetHealth()),maxhp(data.GetHealth()),atk(data.GetAttack()),moveSpd(data.GetMoveSpdMult()),size(data.GetSizeMult()),strategy(data.GetAIStrategy()){
}
vf2d&Monster::GetPos(){
return pos;
}
int Monster::GetHealth(){
return hp;
}
int Monster::GetAttack(){
return atk;
}
float Monster::GetMoveSpdMult(){
return moveSpd;
}
float Monster::GetSizeMult(){
return size;
}

@ -13,24 +13,13 @@ struct MonsterData{
float size;
MonsterStrategy strategy;
public:
MonsterData(){};
MonsterData(int hp,int atk,float moveSpd=1.0f,float size=1.0f,MonsterStrategy strategy=RUN_TOWARDS):
hp(hp),atk(atk),moveSpd(moveSpd),size(size),strategy(strategy){}
int GetHealth(){
return hp;
}
int GetAttack(){
return atk;
}
float GetMoveSpdMult(){
return moveSpd;
}
float GetSizeMult(){
return size;
}
MonsterStrategy GetAIStrategy(){
return strategy;
}
MonsterData();
MonsterData(int hp,int atk,float moveSpd=1.0f,float size=1.0f,MonsterStrategy strategy=RUN_TOWARDS);
int GetHealth();
int GetAttack();
float GetMoveSpdMult();
float GetSizeMult();
MonsterStrategy GetAIStrategy();
};
enum MonsterName{
@ -41,5 +30,19 @@ enum MonsterName{
};
struct Monster{
private:
vf2d pos;
int hp,maxhp;
int atk;
float moveSpd;
float size;
MonsterStrategy strategy;
public:
Monster();
Monster(vf2d pos,MonsterData data);
vf2d&GetPos();
int GetHealth();
int GetAttack();
float GetMoveSpdMult();
float GetSizeMult();
};

@ -16,18 +16,59 @@ enum AnimationState{
};
struct Player{
private:
int hp=100,maxhp=hp;
int atk=10;
vf2d pos;
float moveSpd;
float moveSpd=1.0f;
float size=1.0f;
float attack_range=1.5f;
AnimationState animState=AnimationState::IDLE_S;
private:
Animate2D::Animation<AnimationState>animation;
Animate2D::AnimationState internal_animState;
Key lastReleasedMovementKey;
public:
Player(){};
Player(vf2d pos,float moveSpd):
pos(pos),moveSpd(moveSpd){
Player(vf2d pos):
pos(pos){
};
void SetX(float x){
pos.x=x;
};
void SetY(float y){
pos.y=y;
}
void SetPos(vf2d pos){
this->pos=pos;
}
vf2d&GetPos(){
return pos;
}
float GetX(){
return pos.x;
}
float GetY(){
return pos.y;
}
int GetHealth(){
return hp;
}
int GetMaxHealth(){
return maxhp;
}
int GetAttack(){
return atk;
}
float GetMoveSpdMult(){
return moveSpd;
}
float GetSizeMult(){
return size;
}
float GetAttackRangeMult(){
return attack_range;
}
void Update(float fElapsedTime){
animation.UpdateState(internal_animState,fElapsedTime);
}
@ -55,7 +96,7 @@ class Crawler : public olc::PixelGameEngine
const vi2d WORLD_SIZE={64,8};
Camera2D camera;
TileTransformedView view;
Player player=Player{{},100};
Player player=Player{{}};
Renderable GFX_Pl_sheet;
public:
@ -70,7 +111,7 @@ public:
//Initialize Camera.
camera=Camera2D{WINDOW_SIZE};
camera.SetMode(olc::utils::Camera2D::Mode::LazyFollow);
camera.SetTarget(player.pos);
camera.SetTarget(player.GetPos());
camera.SetWorldBoundary({0,0},WORLD_SIZE*24);
camera.EnableWorldBoundary(true);
@ -118,7 +159,7 @@ public:
player.AddAnimation(IDLE_W,pl_idle_w);
view=TileTransformedView{GetScreenSize(),{1,1}};
player.pos={4*24,4*24};
player.SetPos({4*24,4*24});
player.UpdateAnimation(IDLE_S);
std::cout<<MONSTER_DATA[SLIME_BLUE].GetHealth()<<std::endl;
@ -138,19 +179,19 @@ public:
void HandleUserInput(float fElapsedTime){
bool setIdleAnimation=true;
if(GetKey(RIGHT).bHeld){
if(player.pos.x+12+fElapsedTime*player.moveSpd<WORLD_SIZE.x*24){
player.pos.x+=fElapsedTime*player.moveSpd;
if(player.GetPos().x+12+fElapsedTime*100*player.GetMoveSpdMult()<WORLD_SIZE.x*24){
player.SetX(player.GetX()+fElapsedTime*100*player.GetMoveSpdMult());
} else {
player.pos.x=WORLD_SIZE.x*24-12;
player.SetX(WORLD_SIZE.x*24-12);
}
player.UpdateAnimation(WALK_E);
setIdleAnimation=false;
}
if(GetKey(LEFT).bHeld){
if(player.pos.x-12+fElapsedTime*player.moveSpd>0){
player.pos.x-=fElapsedTime*player.moveSpd;
if(player.GetPos().x-12+fElapsedTime*100*player.GetMoveSpdMult()>0){
player.SetX(player.GetX()-fElapsedTime*100*player.GetMoveSpdMult());
} else {
player.pos.x=12;
player.SetX(12);
}
if(setIdleAnimation){
player.UpdateAnimation(WALK_W);
@ -158,10 +199,10 @@ public:
setIdleAnimation=false;
}
if(GetKey(UP).bHeld){
if(player.pos.y-12+fElapsedTime*player.moveSpd>0){
player.pos.y-=fElapsedTime*player.moveSpd;
if(player.GetPos().y-12+fElapsedTime*100*player.GetMoveSpdMult()>0){
player.SetY(player.GetY()-fElapsedTime*100*player.GetMoveSpdMult());
} else {
player.pos.y=12;
player.SetY(12);
}
if(setIdleAnimation){
player.UpdateAnimation(WALK_N);
@ -169,10 +210,10 @@ public:
setIdleAnimation=false;
}
if(GetKey(DOWN).bHeld){
if(player.pos.y+12+fElapsedTime*player.moveSpd<WORLD_SIZE.y*24){
player.pos.y+=fElapsedTime*player.moveSpd;
if(player.GetPos().y+12+fElapsedTime*100*player.GetMoveSpdMult()<WORLD_SIZE.y*24){
player.SetY(player.GetY()+fElapsedTime*100*player.GetMoveSpdMult());
} else {
player.pos.y=WORLD_SIZE.y*24-12;
player.SetY(WORLD_SIZE.y*24-12);
}
if(setIdleAnimation){
player.UpdateAnimation(WALK_S);
@ -262,7 +303,7 @@ public:
view.DrawRect(vi2d{x,y}*24,{24,24},VERY_DARK_GREY);
}
}
view.DrawPartialDecal(player.pos-vi2d{12,12},player.GetFrame().GetSourceImage()->Decal(),player.GetFrame().GetSourceRect().pos,player.GetFrame().GetSourceRect().size);
view.DrawPartialDecal(player.GetPos()-vi2d{12,12},player.GetFrame().GetSourceImage()->Decal(),player.GetFrame().GetSourceRect().pos,player.GetFrame().GetSourceRect().size);
}
};

Loading…
Cancel
Save