Skip to content

Commit

Permalink
Merge branch 'main' into AI_Update
Browse files Browse the repository at this point in the history
  • Loading branch information
jonylu7 authored May 24, 2024
2 parents 8951fa7 + f595301 commit e838103
Show file tree
Hide file tree
Showing 14 changed files with 246 additions and 220 deletions.
5 changes: 4 additions & 1 deletion include/AI/EnemyScripts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@

#define SPACE 4


enum class SpawnMode { BUILDINGS,AVATAR};
class EnemyScripts{

private:
std::shared_ptr<UnitManager> m_GameObjectManager;
std::shared_ptr<UnitManager> m_EnemyObjectManager;
std::shared_ptr<MapClass> m_Map;

glm::vec2 m_baseCell = {20,20};
glm::vec2 m_baseCell = {20, 20};
int constructCountX = 0;
int constructCountY = 0;


float m_buildingCDTime=0;
float m_AvatarCDTime=0;
float m_buildingCost = 0.F;
Expand Down
36 changes: 34 additions & 2 deletions include/Mechanics/BuiltStructure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class BuiltStructure {
return true;
}

std::vector<std::shared_ptr<Structure>> *getBuiltStructureArray() {
return &m_BuiltStructure;
std::vector<std::shared_ptr<Structure>> getBuiltStructureArray() {
return m_BuiltStructure;
}

void StartBuiltStructure() {
Expand Down Expand Up @@ -91,6 +91,38 @@ class BuiltStructure {
glm::vec2 getPlayerBarrackCell() { return {m_PlayerBarrackCell.x-1,m_PlayerBarrackCell.y-1}; }
glm::vec2 getPlayerWayPointCell() { return m_PlayerWayPointCell; }

public:
glm::vec2 getEnemyBarrackCell() { return m_EnemyBarrackCell; }
glm::vec2 getEnemyWayPointCell() { return m_EnemyWayPointCell; }
glm::vec2 getPlayerBarrackSpawnCell() { return m_PlayerBarrackCell; }
glm::vec2 getPlayerBarrackWayPointCell() { return m_PlayerWayPointCell; }

bool ifBarracksBuilt() {
for (auto i : m_BuiltStructure) {
if (i->getID().getUnitType() == UnitType::BARRACKS) {
return true;
}
}
return false;
}
bool ifPowerPlantsBuilt() {
for (auto i : m_BuiltStructure) {
if (i->getID().getUnitType() == UnitType::POWER_PLANT) {
return true;
}
}
return false;
}
bool ifWarFactoryBuilt() {
for (auto i : m_BuiltStructure) {
if (i->getID().getUnitType() == UnitType::WAR_FACT) {
return true;
}
}
return false;
}


private:
std::shared_ptr<MapClass> m_Map = std::make_shared<MapClass>();
std::vector<std::shared_ptr<Structure>> m_BuiltStructure;
Expand Down
13 changes: 8 additions & 5 deletions include/Mechanics/StructureManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ class StructureManager {
virtual ~StructureManager() {}

void Start(std::shared_ptr<MapClass> map) {
m_StructureArray.Start(map);
m_BuiltStructure->Start(map);
m_Map = map;
}
void Update() {

m_StructSelectingConstructionSite->Update();

m_StructureArray.UpdateBuiltStructure();
m_BuiltStructure->UpdateBuiltStructure();
}

void AddStructSelectingBuiltSite(std::shared_ptr<Structure> newstruct) {
Expand All @@ -36,16 +36,19 @@ class StructureManager {
if (m_StructSelectingConstructionSite->getStructureOrder()
->getStructureOrderType() ==
StructureOrderType::SELECTING_SITE) {
m_StructureArray.buildNewStructure(
m_BuiltStructure->buildNewStructure(
m_StructSelectingConstructionSite);
}
}

BuiltStructure *getStructureArray() { return &m_StructureArray; }
std::shared_ptr<BuiltStructure> getStructureArray() {
return m_BuiltStructure;
}

protected:
std::shared_ptr<MapClass> m_Map = std::make_shared<MapClass>();
BuiltStructure m_StructureArray;
std::shared_ptr<BuiltStructure> m_BuiltStructure =
std::make_shared<BuiltStructure>();
std::shared_ptr<Structure> m_StructSelectingConstructionSite =
std::make_shared<Structure>();
};
Expand Down
21 changes: 10 additions & 11 deletions include/Mechanics/UnitManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class UnitManager : public Player {
public:
int getTotalPower() {
return Player::getTotalPower(
*m_StructureManager->getStructureArray()->getBuiltStructureArray());
m_StructureManager->getStructureArray()->getBuiltStructureArray());
}
std::shared_ptr<AvatarManager> getAvatarManager() {
return m_AvatarManager;
Expand All @@ -64,22 +64,16 @@ class UnitManager : public Player {
}

int UpdateCurrency() {
for (auto i : *m_StructureManager->getStructureArray()
->getBuiltStructureArray()) {
for (auto i : m_StructureManager->getStructureArray()
->getBuiltStructureArray()) {
if (std::dynamic_pointer_cast<OreRefinery>(i)) {
addTotalCurrency(150);
}
}
}

void spawn(std::shared_ptr<MapClass> m_Map, UnitType unit,
HouseType house) {

if (house == HouseType::ENEMY) {
// m_Enemy->addUnitConstructCount(unit, 1);
} else {
// m_Player->setUnitConstructCount(unit, 1);
}
void spawnToWayPoint(std::shared_ptr<MapClass> m_Map, UnitType unit,
HouseType house) {

switch (unit) {
case UnitType::INFANTRY: {
Expand All @@ -93,7 +87,12 @@ class UnitManager : public Player {

avatar->Start(m_StructureManager->getStructureArray()
->getPlayerBarrackCell());

m_AvatarManager->assignMoveOrderToAvatar(avatar,{m_StructureManager->getStructureArray()->getPlayerWayPointCell()});
// assign order
m_AvatarManager->assignMoveOrderToAvatar(
avatar, m_StructureManager->getStructureArray()
->getPlayerWayPointCell());
m_AvatarManager->AppendAvatar(avatar);
m_troopSize+=1;
}
Expand Down
2 changes: 1 addition & 1 deletion include/Scene/Scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Scene {
std::shared_ptr<UnitManager> m_EnemyObjectManager =
std::make_shared<UnitManager>();
Util::Renderer m_Renderer;
UIClass m_UI;
std::shared_ptr<UIClass> m_UI = std::make_shared<UIClass>();
std::shared_ptr<Player> m_Player = std::make_shared<Player>();
};

Expand Down
16 changes: 12 additions & 4 deletions include/Scene/TutorialScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,29 @@
#include "Cursor.hpp"
#include "Scene.hpp"
// #include "Mechanics/GameObjectID.hpp"
#include "Task.hpp"
#include "Util/Prop.hpp"
#include <glm/glm.hpp>
#include "pch.hpp"

#define DEBUG_KEY P


enum class TutorialStages { STAGE1, STAGE2, STAGE3, STAGE4 };

class TutorialScene : public Scene {
enum class Stages { STAGE1, STAGE2, STAGE3, STAGE4 };
public:
TutorialScene(){};
~TutorialScene(){};
void Start() override;
void Update() override;

private:
void stageStart();
void stageUpdate();
void stage1Update();
void stage2Update();
void stage3Update();
void stage4Update();

private:
SpriteSheet m_SpriteSheet;
Expand All @@ -33,8 +40,9 @@ class TutorialScene : public Scene {
std::make_shared<EnemyPlayer>(SceneMode::TUTORIAL);
std::shared_ptr<EnemyScripts> m_EnemyScripts =
std::make_shared<EnemyScripts>();
std::shared_ptr<Task> m_Text = std::make_shared<Task>();
std::shared_ptr<Util::GameObject> m_PlayerObjectivesText =
std::make_shared<Util::GameObject>();
std::shared_ptr<Prop> m_cellProp = std::make_shared<Prop>();
Stages m_stage;
TutorialStages m_stage;
};
#endif // PRACTICALTOOLSFORSIMPLEDESIGN_TUTORIALSCENE_HPP
35 changes: 0 additions & 35 deletions include/Task.hpp

This file was deleted.

15 changes: 15 additions & 0 deletions include/UI/Button.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Created by 盧威任 on 5/21/24.
//

#ifndef PRACTICALTOOLSFORSIMPLEDESIGN_BUTTON_HPP
#define PRACTICALTOOLSFORSIMPLEDESIGN_BUTTON_HPP
#include "Util/GameObject.hpp"
class Button : public Util::GameObject {

// setImage
// given cursor coord or cursor object
public:
private:
};
#endif // PRACTICALTOOLSFORSIMPLEDESIGN_BUTTON_HPP
11 changes: 8 additions & 3 deletions include/Util/GameObject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Util {
*/
class GameObject {
public:
Util::Transform m_Transform; // IDC if this should be here.
Util::Transform m_Transform;

public:
/**
Expand All @@ -37,14 +37,17 @@ class GameObject {
* @param children The children of the game object.
* @param movingRelativeToCamera Whether the object can move relative to
* camera position
* @param transfrom predefined transform
*/
GameObject(const std::shared_ptr<Core::Drawable> &drawable,
const float zIndex, const bool visible = true,
const bool movingRelativeToCamera = true)
const bool movingRelativeToCamera = true,
const Util::Transform transfrom = Util::Transform())
: m_Drawable(std::move(drawable)),
m_ZIndex(zIndex),
m_Visible(visible),
b_MovingRelativeToCamera(movingRelativeToCamera) {}
b_MovingRelativeToCamera(movingRelativeToCamera),
m_Transform(transfrom) {}

/**
* @brief Copy constructor.
Expand Down Expand Up @@ -75,6 +78,8 @@ class GameObject {
*/
float GetZIndex() const { return m_ZIndex; }

void SetTransform(Util::Transform transform) { m_Transform = transform; }

/**
* @brief Get the transform of the game object.
*
Expand Down
47 changes: 25 additions & 22 deletions include/Util/Prop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,53 @@
#ifndef PRACTICALTOOLSFORSIMPLEDESIGN_PROP_HPP
#define PRACTICALTOOLSFORSIMPLEDESIGN_PROP_HPP
#include "Structure/Structure.hpp"
class Prop:public Structure{
class Prop : public Structure {
public:
Prop(bool selectable = false):Structure(selectable){}
~Prop()override{}
void Start(glm::vec2 width)override{
m_width=width;
Prop(bool selectable = false)
: Structure(selectable) {}
~Prop() override {}
void Start(glm::vec2 width) override {
m_width = width;
this->SetAttachVisible(true);
SetZIndex(8);
m_HighLight.SetZIndex(10);
}
void attachmentUpdate()override{
m_HighLight.SetObjectLocation({this->GetDrawLocation().x+m_highlightOffset.x,this->GetDrawLocation().y+m_highlightOffset.y});
void attachmentUpdate() override {
m_HighLight.SetObjectLocation(
{this->GetDrawLocation().x + m_highlightOffset.x,
this->GetDrawLocation().y + m_highlightOffset.y});
m_HighLight.Draw();
}
void setScale(glm::vec2 scale){
m_Transform.scale=scale;
}
void setHighLightImage(std::string path){
void setScale(glm::vec2 scale) { m_Transform.scale = scale; }
void setHighLightImage(std::string path) {
m_HighLight.SetDrawable(std::make_unique<Util::Image>(path));
}
void setHighLightOffset(glm::vec2 globalDistance){
m_highlightOffset=globalDistance;
void setHighLightOffset(glm::vec2 globalDistance) {
m_highlightOffset = globalDistance;
}
void setObjectLocation(glm::vec2 location,float offsetCell){
void setObjectLocation(glm::vec2 location, float offsetCell) {
location = MapUtil::PositionStickToGrid(location);
m_ObjectLocation = location;
m_DrawLocation = {location.x + offsetCell * CELL_SIZE.x,
location.y + offsetCell * CELL_SIZE.y};
m_Transform.translation = m_DrawLocation;
}
bool isOverlaps(glm::vec2 cell){
if(cell.x>m_ObjectLocation.x&&cell.x<m_ObjectLocation.x+m_width.x){
if(cell.y>m_ObjectLocation.y&&cell.y<m_ObjectLocation.y+m_width.y){
return true;
}
bool ifOverlaps(glm::vec2 cell) {
if ((cell.x > getLocationCell().x - m_width.x &&
cell.x < getLocationCell().x) &&
(cell.y > getLocationCell().y - m_width.y &&
cell.y < getLocationCell().y)) {
return true;
}
return false;
}
void Update()override{
void Update() override {
Draw();
attachmentUpdate();
}

private:
glm::vec2 m_width={1,1};
glm::vec2 m_highlightOffset={0,0};
glm::vec2 m_width = {1, 1};
glm::vec2 m_highlightOffset = {0, 0};
};
#endif // PRACTICALTOOLSFORSIMPLEDESIGN_PROP_HPP
Loading

0 comments on commit e838103

Please sign in to comment.