Class quick test swapping reimplemented.

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
pull/28/head
Nic0Nic0Nii 1 year ago
parent c75a01a1ad
commit 8d117c42e3
  1. 3
      .vscode/settings.json
  2. BIN
      Crawler/Crawler
  3. 37
      Crawler/Crawler.cpp
  4. 2
      Crawler/DEFINES.h
  5. 3
      Crawler/Monster.cpp
  6. 4
      Crawler/Player.cpp
  7. 10
      Crawler/Player.h
  8. 2
      Crawler/sig

@ -88,6 +88,7 @@
"bitset": "cpp",
"regex": "cpp",
"valarray": "cpp",
"*.inc": "cpp"
"*.inc": "cpp",
"future": "cpp"
}
}

Binary file not shown.

@ -39,9 +39,7 @@ bool Crawler::OnUserCreate(){
InitializeLevel("assets/Campaigns/1_1.tmx",CAMPAIGN_1_1);
std::cout<<"Player loading."<<std::endl;
player=std::make_unique<Warrior>();
std::cout<<"Player loaded."<<std::endl;
//Initialize Camera.
camera=Camera2D{WINDOW_SIZE};
@ -50,7 +48,6 @@ bool Crawler::OnUserCreate(){
camera.SetWorldBoundary({0,0},WORLD_SIZE*24);
camera.EnableWorldBoundary(false);
std::cout<<"Camera loaded."<<std::endl;
//Graphics
GFX_Warrior_Sheet.Load("assets/nico-warrior.png");
GFX_Slime_Sheet.Load("assets/slime.png");
@ -77,7 +74,6 @@ bool Crawler::OnUserCreate(){
GFX_ChainLightning.Load("assets/chain_lightning.png");
GFX_LightningSplash.Load("assets/lightning_splash_effect.png");
GFX_Meteor.Load("assets/meteor.png");
std::cout<<"Images loaded."<<std::endl;
//Animations
sig::Animation::InitializeAnimations();
@ -86,9 +82,7 @@ bool Crawler::OnUserCreate(){
view=TileTransformedView{GetScreenSize(),{1,1}};
LoadLevel(CAMPAIGN_1_1);
std::cout<<"Done Loading."<<std::endl;
//ChangePlayerClass(WARRIOR);
std::cout<<"Set player class."<<std::endl;
ChangePlayerClass(WARRIOR);
return true;
}
@ -753,7 +747,7 @@ void Crawler::SetupWorldShake(float duration){
void Crawler::InitializeLevel(std::string mapFile,MapName map){
TMXParser level(mapFile);
std::cout<<"Done parsing."<<std::endl;
size_t slashMarker = mapFile.find_last_of('/');
std::string baseDir=mapFile.substr(0,slashMarker+1);
MAP_DATA[map]=level.GetData();
@ -762,7 +756,6 @@ void Crawler::InitializeLevel(std::string mapFile,MapName map){
std::string baseSourceDir=tag.data["source"].substr(slashMarkerSourceDir+1);
if(MAP_TILESETS.find("assets/maps/"+baseSourceDir)==MAP_TILESETS.end()){
TSXParser tileset(baseDir+tag.data["source"]);
std::cout<<"Done parsing tex. "<<std::endl;
Renderable*r=new Renderable();
MAP_TILESETS["assets/maps/"+baseSourceDir].tileset=r;
MAP_TILESETS["assets/maps/"+baseSourceDir].foregroundTiles=tileset.GetData().ForegroundTileData;
@ -770,10 +763,8 @@ void Crawler::InitializeLevel(std::string mapFile,MapName map){
MAP_TILESETS["assets/maps/"+baseSourceDir].collision=tileset.GetData().CollisionData;
MAP_TILESETS["assets/maps/"+baseSourceDir].staircaseTiles=tileset.GetData().StaircaseData;
r->Load("assets/maps/"+tileset.GetData().ImageData.data["source"]);
std::cout<<"Done loading. "<<std::endl;
}
}
std::cout<<"Function done. "<<std::endl;
}
void Crawler::LoadLevel(MapName map){
@ -781,7 +772,7 @@ void Crawler::LoadLevel(MapName map){
foregroundTileGroups.clear();
currentLevel=map;
WORLD_SIZE={MAP_DATA[map].MapData.width,MAP_DATA[map].MapData.height};
std::cout<<"Setup world size."<<std::endl;
for(auto key:MAP_DATA[map].SpawnerData){
SpawnerTag&spawnData=MAP_DATA[map].SpawnerData[key.first];
std::vector<std::pair<MonsterName,vf2d>>monster_list;
@ -795,7 +786,7 @@ void Crawler::LoadLevel(MapName map){
}
SPAWNER_LIST.push_back(MonsterSpawner{{spawnData.ObjectData.GetFloat("x"),spawnData.ObjectData.GetFloat("y")},spawnerRadius*2,monster_list,spawnData.upperLevel});
}
std::cout<<"Spawner lists done."<<std::endl;
std::set<vi2d>foregroundTilesAdded,upperForegroundTilesAdded;
for(int x=0;x<WORLD_SIZE.x;x++){
for(int y=0;y<WORLD_SIZE.y;y++){
@ -877,7 +868,7 @@ void Crawler::LoadLevel(MapName map){
}
}
}
std::cout<<"Done preparing tilesheet reads"<<std::endl;
int counter=0;
bridgeLayerIndex=-1;
for(LayerTag&layer:MAP_DATA[map].LayerData){
@ -886,10 +877,10 @@ void Crawler::LoadLevel(MapName map){
}
counter++;
}
std::cout<<"Bridge Layer indexing done."<<std::endl;
player->upperLevel=false; //Assume player starts on lower level.
player->SetPos(MAP_DATA[map].MapData.playerSpawnLocation);
std::cout<<"Player spawn info set."<<std::endl;
pathfinder.Initialize();
}
@ -982,24 +973,26 @@ std::map<std::string,std::vector<geom2d::rect<int>>>&Crawler::GetZoneData(MapNam
void Crawler::ChangePlayerClass(Class cl){
switch(cl){
case WARRIOR:{
player.reset(new Warrior());
player.reset(new Warrior(player.get()));
}break;
case THIEF:{
player.reset(new Thief());
player.reset(new Thief(player.get()));
}break;
case TRAPPER:{
player.reset(new Trapper());
player.reset(new Trapper(player.get()));
}break;
case RANGER:{
player.reset(new Ranger());
player.reset(new Ranger(player.get()));
}break;
case WIZARD:{
player.reset(new Wizard());
player.reset(new Wizard(player.get()));
}break;
case WITCH:{
player.reset(new Witch());
player.reset(new Witch(player.get()));
}break;
}
sig::Animation::SetupPlayerAnimations();
GetPlayer()->InitializeClassAbilities();
GetPlayer()->UpdateIdleAnimation(DOWN);
}

@ -15,6 +15,8 @@
#define SETUP_CLASS(class) \
class::class(){InitializeClassAbilities();} \
class::class(Player*player) \
:Player::Player(player){} \
Class class::GetClass(){return cl;} \
std::string class::GetClassName(){return name;} \
Ability&class::GetRightClickAbility(){return rightClickAbility;}; \

@ -406,12 +406,9 @@ void Monster::PathAroundBehavior(float fElapsedTime){
}else{
if(pathIndex+1>=path.size()){
//We have reached the end of the path!
std::cout<<"Reached the end of the path."<<std::endl;
targetAcquireTimer=0;
}else{
std::cout<<"End of pathing "<<pathIndex<<". Advancing."<<std::endl;
pathIndex++;
std::cout<<" Current Target:"<<path[pathIndex]*24<<std::endl;
}
}
} else {

@ -19,6 +19,10 @@ const float Player::GROUND_SLAM_SPIN_TIME=0.6f;
Player::Player()
:state(State::NORMAL),lastReleasedMovementKey(DOWN),facingDirection(DOWN){}
Player::Player(Player*player)
:pos(player->GetPos()),vel(player->GetVelocity()),iframe_time(player->iframe_time),lastReleasedMovementKey(player->GetLastReleasedMovementKey()),
facingDirection(GetFacingDirection()){}
bool Player::SetX(float x){
vf2d newPos={x,pos.y};
vi2d tilePos=vi2d(newPos/24)*24;

@ -62,6 +62,10 @@ protected:
float swordSwingTimer=0;
public:
Player();
//So this is rather fascinating and only exists because we have the ability to change classes which means we need to initialize a class
//using a new object type... Because of that we'll take the pointer reference to the old object and copy some of its properties to this new
//one. It's hackish but it means we can reduce the amount of extra boilerplate when class changing...I don't know how to feel about this.
Player(Player*player);
const static float GROUND_SLAM_SPIN_TIME;
vf2d&GetPos();
float GetX();
@ -125,6 +129,7 @@ struct Warrior:Player{
static Ability rightClickAbility,ability1,ability2,ability3,ability4;
static AnimationState walk_n,walk_e,walk_s,walk_w,idle_n,idle_e,idle_s,idle_w;
Warrior();
Warrior(Player*player);
Class GetClass()override;
bool AutoAttack()override;
void OnUpdate(float fElapsedTime)override;
@ -151,6 +156,7 @@ struct Thief:Player{
static Ability rightClickAbility,ability1,ability2,ability3,ability4;
static AnimationState walk_n,walk_e,walk_s,walk_w,idle_n,idle_e,idle_s,idle_w;
Thief();
Thief(Player*player);
Class GetClass()override;
bool AutoAttack()override;
void OnUpdate(float fElapsedTime)override;
@ -177,6 +183,7 @@ struct Ranger:Player{
static Ability rightClickAbility,ability1,ability2,ability3,ability4;
static AnimationState walk_n,walk_e,walk_s,walk_w,idle_n,idle_e,idle_s,idle_w;
Ranger();
Ranger(Player*player);
Class GetClass()override;
bool AutoAttack()override;
void OnUpdate(float fElapsedTime)override;
@ -203,6 +210,7 @@ struct Trapper:Player{
static Ability rightClickAbility,ability1,ability2,ability3,ability4;
static AnimationState walk_n,walk_e,walk_s,walk_w,idle_n,idle_e,idle_s,idle_w;
Trapper();
Trapper(Player*player);
Class GetClass()override;
bool AutoAttack()override;
void OnUpdate(float fElapsedTime)override;
@ -229,6 +237,7 @@ struct Wizard:Player{
static Ability rightClickAbility,ability1,ability2,ability3,ability4;
static AnimationState walk_n,walk_e,walk_s,walk_w,idle_n,idle_e,idle_s,idle_w;
Wizard();
Wizard(Player*player);
Class GetClass()override;
bool AutoAttack()override;
void OnUpdate(float fElapsedTime)override;
@ -255,6 +264,7 @@ struct Witch:Player{
static Ability rightClickAbility,ability1,ability2,ability3,ability4;
static AnimationState walk_n,walk_e,walk_s,walk_w,idle_n,idle_e,idle_s,idle_w;
Witch();
Witch(Player*player);
Class GetClass()override;
bool AutoAttack()override;
void OnUpdate(float fElapsedTime)override;

@ -1,4 +1,4 @@
export AUTO_UPDATE=false
export AUTO_UPDATE=true
source utils/define.sh

Loading…
Cancel
Save