Skip to content

Commit

Permalink
print
Browse files Browse the repository at this point in the history
  • Loading branch information
jonylu7 committed Apr 30, 2024
1 parent 32e8fa9 commit 11be6e5
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 44 deletions.
5 changes: 5 additions & 0 deletions include/Map/Tile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class TileClass {
if (m_Avatars.size() < 4) {
setWalkable(true);
}
if (m_Avatars.size() == 0) {
setBuildable(true);
}
return;
}
}
Expand Down Expand Up @@ -106,6 +109,8 @@ class TileClass {
return *this;
}

bool checkedEnemy() { if (m_Structure->getHouse() ==) }

private:
bool m_TerrainWalkable;
bool m_TerrainBuildable;
Expand Down
2 changes: 1 addition & 1 deletion include/Mechanics/House.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class House {
HouseType getHouse() { return m_house; }
void setHouse(HouseType house) { m_house = house; }

private:
protected:
HouseType m_house;
};

Expand Down
4 changes: 4 additions & 0 deletions include/Mechanics/Spawning.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class Spawning {
// unit
unit->setMovePath(queue);
unit->setnewDestinationIsSetted(false);

if (m_Map->getTileByCellPosition(unit->getDestinationCell())
->checkedEnemy()) {
}
}

void keepUpdatingUnitsPosition(std::shared_ptr<Avatar> unit) {
Expand Down
9 changes: 3 additions & 6 deletions include/Structure/Structure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ class Structure : public Util::GameObject,
public AttackAndDamageUnit {

public:
enum class updateMode { Invisidable, Moveable, Fixed };
Structure()
: electricPower(0.F),
buildingTime(0.F),
buildingCost(0.F),
m_ID(GameObjectID(unitType::null, HouseType::NONE)) {
m_CurrentState = updateMode::Invisidable;
m_CurrentState = unitStatus::NotBornedYet;
};

Structure(float electricPower, float buildingTime, float buildingCost,
Expand All @@ -58,8 +57,7 @@ class Structure : public Util::GameObject,
m_StructureSpriteSheet->Start(
"../assets/sprites/Barracks_SpriteSheet.png", 48, 48, 13, 0);
}
updateMode GetCurrentUpdateMode() const { return m_CurrentState; };
void SetCurrentUpdateMode(updateMode mode) { m_CurrentState = mode; };

virtual void SetObjectLocation(glm::vec2 location);

glm::vec2 GetObjectLocation() { return this->ObjectLocation; }
Expand All @@ -70,7 +68,7 @@ class Structure : public Util::GameObject,

virtual void attachmentUpdate();
bool getConstructed() {
if (m_CurrentState == updateMode::Fixed) {
if (m_CurrentState == unitStatus::Alive) {
return true;
} else {
return false;
Expand All @@ -94,7 +92,6 @@ class Structure : public Util::GameObject,
}

protected:
updateMode m_CurrentState = updateMode::Invisidable;
float electricPower;
float buildingTime;
float buildingCost;
Expand Down
28 changes: 27 additions & 1 deletion include/Unit/AttackAndDamageUnit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@

class AttackAndDamageUnit {
public:
enum class unitStatus {
Death,
Alive,
NotBornedYet,
};
enum class unitOrder {
ATTACK,
NOORDER,
MOVE,
MOVE_ATTACK,
Struct_MOVEABLE
};
AttackAndDamageUnit() {}
virtual ~AttackAndDamageUnit() {}

Expand All @@ -27,7 +39,21 @@ class AttackAndDamageUnit {
return;
}

private:
void UpdateDeath() {
if (m_HP <= 0) {
m_CurrentState = unitStatus::Death;
}
}

unitStatus GetCurrentUpdateMode() const { return m_CurrentState; };
unitOrder GetCurrentOrder() const { return m_CurrentOrder; }

void SetCurrentUpdateMode(unitStatus mode) { m_CurrentState = mode; };
void SetCurrentOrder(unitOrder order) { m_CurrentOrder = order; };

protected:
unitStatus m_CurrentState = unitStatus::NotBornedYet;
unitOrder m_CurrentOrder = unitOrder::NOORDER;
int m_HP;
Weapon m_Weapon;
float m_ArmorRate;
Expand Down
3 changes: 0 additions & 3 deletions include/Unit/Avatar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class Avatar : public PathfindingUnit,
public Selectable {

public:
enum class UnitMode { DEAD, MOVE, IDLE, MOVE_ATTACK, ALIVE };
Avatar(){};
~Avatar() override{};

Expand All @@ -38,7 +37,6 @@ class Avatar : public PathfindingUnit,

void DEBUG_printCurrentMoveDirection(MoveDirection Dir);

UnitMode getUnitMode() { return m_currentMode; }
virtual void customizeUpdate() {
if (1 == 1) {
}
Expand All @@ -62,6 +60,5 @@ class Avatar : public PathfindingUnit,

private:
bool b_justStarted = true;
UnitMode m_currentMode;
};
#endif // PRACTICALTOOLSFORSIMPLEDESIGN_DUMMY_HPP
32 changes: 15 additions & 17 deletions src/Structure/Structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,32 @@ void Structure::Start() {
SetZIndex(DEFAULT_ZINDEX);
this->SetAttachVisible(false);
SetSpriteSheet();
m_CurrentState = updateMode::Moveable;
m_CurrentState = unitStatus::Strucutre_Moveable;
}
void Structure::Update() {

switch (m_CurrentState) {
case updateMode::Invisidable: {
this->updateInvinsible();
break;
}
case updateMode::Fixed: {
case unitStatus::NotBornedYet {
this->updateInvinsible(); break;
} case unitStatus::Alive: {
whenSelected();
this->updateFixed();
break;
}
case updateMode::Moveable: {
this->updateMoveable();
break;
if( unitStatus::Strucutre_Moveable: {
this->updateMoveable();
break;
}
}
}
void Structure::updateFixed() {
// Attachment and self readjust location and draw---------------
attachmentUpdate();
if (m_SpriteSheetAnimation->getFinished()) {
m_StructureSpriteSheet->DrawSpriteByIndex(
m_StructureSpriteSheet->getSize() - 1, m_Transform, DEFAULT_ZINDEX);
m_StructureSpriteSheet->DrawSpriteByIndex(
m_StructureSpriteSheet->getSize() - 1, m_Transform, DEFAULT_ZINDEX);
} else {
m_SpriteSheetAnimation->Draw(m_Transform, DEFAULT_ZINDEX);
m_SpriteSheetAnimation->Draw(m_Transform, DEFAULT_ZINDEX);
}
// Script when select--------------------
}
Expand All @@ -58,10 +56,10 @@ void Structure::updateMoveable() {
m_StructureSpriteSheet->DrawSpriteByIndex(
m_StructureSpriteSheet->getSize() - 1, m_Transform, DEFAULT_ZINDEX);
if (Util::Input::IsKeyPressed(Util::Keycode::MOUSE_LB)) {
this->SetObjectLocation(location);
m_SpriteSheetAnimation->initSpriteSheetAnimation(m_StructureSpriteSheet,
true, INTERVAL, false);
this->SetCurrentUpdateMode(updateMode::Fixed);
this->SetObjectLocation(location);
m_SpriteSheetAnimation->initSpriteSheetAnimation(m_StructureSpriteSheet,
true, INTERVAL, false);
this->SetCurrentUpdateMode(updateMode::Fixed);
}
}

Expand All @@ -84,7 +82,7 @@ void Structure::attachmentUpdate() {
std::vector<glm::vec2> Structure::GetAbsoluteOccupiedArea() {
std::vector<glm::vec2> Area;
for (auto i : m_relativeOccupiedArea) {
Area.push_back({i.x + GetObjectCell().x, i.y + GetObjectCell().y});
Area.push_back({i.x + GetObjectCell().x, i.y + GetObjectCell().y});
}
return Area;
}
22 changes: 8 additions & 14 deletions src/Unit/Avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,25 @@ void Avatar::whenSelected() {

void Avatar::Update() {
whenSelected();
switch (m_currentMode) {
case (UnitMode::DEAD): {
switch (m_CurrentState) {
case (unitStatus::Death):
SetVisible(false);
break;
}
case (UnitMode::MOVE): {
aliveUpdate();
break;
}
case (UnitMode::MOVE_ATTACK): {

case (unitStatus::Alive):
aliveUpdate();
customizeUpdate();
break;
}

// attack
}
}

void Avatar::aliveUpdate() {
walkTowardNextCell();
if (arrivedAtNextCell() || b_justStarted) {
walkTowardNextCell();
b_justStarted = false;
setCurrentCell(MapUtil::GlobalCoordToCellCoord(getCurrentLocation()));
// setCurrentDir(m_wayPointUnit.getFirstCellDir());

setNextCell(
PathUtility::getNextCellByCurrent(getCurrentDir(), getNextCell()));
// printf("(aliveUpdate) getting new dir\n");
Expand All @@ -91,10 +86,9 @@ void Avatar::aliveUpdate() {
m_currentDir = MoveDirection::IDLE;
}
}
// m_wayPointUnit.Update();

SetVisible(true);
m_Transform.translation = getCurrentLocation();
m_Transform.translation = m_currentLocation;

Draw();
// m_SpriteSheetAnimation->Draw(m_Transform, DEFAULT_ZINDEX);
Expand Down
3 changes: 1 addition & 2 deletions src/Unit/PathFindingUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ bool PathfindingUnit::arrivedAtNextCell() {
return true;
} else {
m_moveDistance += m_MovementSpeed;
return false;
}

return false;
}

0 comments on commit 11be6e5

Please sign in to comment.