Skip to content

Commit

Permalink
Merge pull request #7 from ntut-Tu/main
Browse files Browse the repository at this point in the history
建築&wayPoint
  • Loading branch information
jonylu7 authored Mar 5, 2024
2 parents 0ef716e + d8b1bd0 commit 50b4e7a
Show file tree
Hide file tree
Showing 32 changed files with 386 additions and 17 deletions.
20 changes: 20 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ set(SRC_FILES
${SRC_DIR}/Infantry.cpp
${SRC_DIR}/Grid.cpp

${SRC_DIR}/WayPoint.cpp
${SRC_DIR}/WayPointTool.cpp
${SRC_DIR}/Structure/IWayPointStructure.cpp

# ${SRC_DIR}/Structure/Buildings.cpp
${SRC_DIR}/Structure/Barracks.cpp
${SRC_DIR}/Structure/OreRefinery.cpp
${SRC_DIR}/Structure/PowerPlants.cpp
${SRC_DIR}/Structure/WarFactory.cpp

${SRC_DIR}/Scene/DefaultScene.cpp
${SRC_DIR}/Camera.cpp
${SRC_DIR}/SpriteSheet.cpp
Expand Down Expand Up @@ -129,6 +139,16 @@ set(INCLUDE_FILES
${INCLUDE_DIR}/Settings.hpp
${INCLUDE_DIR}/Camera.hpp

${INCLUDE_DIR}/WayPoint.hpp
${INCLUDE_DIR}/WayPointTool.h
${INCLUDE_DIR}/Structure/IWayPointStructure.hpp

#${INCLUDE_DIR}/Structure/Buildings.hpp
${INCLUDE_DIR}/Structure/Barracks.hpp
${INCLUDE_DIR}/Structure/OreRefinery.hpp
${INCLUDE_DIR}/Structure/PowerPlants.hpp
${INCLUDE_DIR}/Structure/WarFactory.hpp

${INCLUDE_DIR}/imgui/imconfig.h
${INCLUDE_DIR}/imgui/imgui.h
${INCLUDE_DIR}/imgui/imgui_impl_sdl2.h
Expand Down
Binary file added assets/sprites/OreRefinery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sprites/PowerPlants.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sprites/WarFactory.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sprites/flagB.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sprites/flagO.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sprites/flagW.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion include/Barracks.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Created by 盧威任 on 1/28/24.
//

/*
#ifndef PRACTICALTOOLSFORSIMPLEDESIGN_BARRACKS_HPP
#define PRACTICALTOOLSFORSIMPLEDESIGN_BARRACKS_HPP
Expand All @@ -15,3 +15,4 @@ class Barracks : public Util::GameObject {
};
#endif // PRACTICALTOOLSFORSIMPLEDESIGN_CAPYBARA_HPP
*/
2 changes: 1 addition & 1 deletion include/Core/Drawable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Drawable {
virtual ~Drawable() = default;
virtual void Draw(const Util::Transform &transform, const float zIndex) = 0;

virtual glm::vec2 GetSize() const{};
virtual glm::vec2 GetSize() const { return {0, 0}; };

virtual void DrawUsingCamera(const Util::Transform &transform, const float zIndex){};
};
Expand Down
3 changes: 3 additions & 0 deletions include/Line.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class Line {
glm::vec2 getlineTo() { return lineTo; };
glm::vec3 getColor() { return color; };

void setlineTo(glm::vec2 to){this->lineTo=to;};
void setlineFrom(glm::vec2 from){this->lineFrom=from;};

private:
glm::vec2 lineFrom;
glm::vec2 lineTo;
Expand Down
30 changes: 28 additions & 2 deletions include/Scene/DefaultScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
#include "Util/Logger.hpp"
#include "Util/Root.hpp"

#include "Structure/Barracks.hpp"
#include "Structure/IWayPointStructure.hpp"
#include "Structure/OreRefinery.hpp"
#include "Structure/PowerPlants.hpp"
#include "Structure/WarFactory.hpp"
#include "WayPoint.hpp"
#include "WayPointTool.h"

class DefaultScene {
public:
DefaultScene(){};
Expand All @@ -33,14 +41,16 @@ class DefaultScene {
void End(){};

private:
/*
std::vector<std::shared_ptr<Util::GameObject>> m_GameObjectList = {
std::make_shared<Capybara>(), std::make_shared<Capybara>(),
std::make_shared<Barracks>()};

*/
Rectangle rect;
/*
std::shared_ptr<Structure> m_Structure = std::make_shared<Structure>();
std::shared_ptr<Infantry> m_Inf = std::make_shared<Infantry>();

*/
SpriteSheet m_SpriteSheet;

CameraClass m_SceneCamera;
Expand All @@ -53,6 +63,22 @@ class DefaultScene {
std::vector<int> m_OgMap;
std::shared_ptr<SpriteSheet> m_TileSetSpriteSheet =
std::make_shared<SpriteSheet>();

//Way Point Test Start---------------
WayPointTool m_waypointTool;
Line m_Line;
bool clickCheck= false;
std::shared_ptr<Barracks> m_Barracks = std::make_shared<Barracks>();
std::shared_ptr<OreRefinery> m_OreRefinery = std::make_shared<OreRefinery>();
std::shared_ptr<PowerPlants> m_PowerPlants = std::make_shared<PowerPlants>();
std::shared_ptr<WarFactory> m_WarFactory = std::make_shared<WarFactory>();

std::vector<std::shared_ptr<IWayPointStructure>> m_IWayPointStructureList = {
m_Barracks,m_OreRefinery,m_WarFactory
};

std::shared_ptr<WayPoint> m_WayPoint = std::make_shared<WayPoint>();
//Way Point Test End---------------
};

#endif // PRACTICALTOOLSFORSIMPLEDESIGN_DEFAULTSCENE_HPP
36 changes: 33 additions & 3 deletions include/Structure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,53 @@
#include "Util/TransformUtils.hpp"
#include "glm/glm.hpp"


class Structure : public Util::GameObject {

public:
enum class updateMode { Invisidable, Moveable, Fixed };
Structure(){};
Structure():
electricPower(100.F),buildingTime(100.F),
buildingCost(100.F),buildingHp(100.F){};
Structure(float electricPower,float buildingTime,
float buildingCost,float buildingHp):
electricPower(electricPower),buildingTime(buildingTime),
buildingCost(buildingCost),buildingHp(buildingHp){m_Transform.scale={0.2,0.2};};
~Structure(){};

void Update(const Util::Transform &transform = Util::Transform()) override;

void Start() override{};
updateMode GetCurrentUpdateMode() const { return m_CurrentState; };
void SetCurrentUpdateMode(updateMode mode) { m_CurrentState = mode; };
void SetObjectLocation(glm::vec2 location) { ObjectLocation = location; }
void SetObjectLocation(glm::vec2 location);
glm::vec2 GetObjectLocation(){return this->ObjectLocation; }
//virtual glm::vec2 GetWayPointLocation(){return {0,0};};
//void SetTransformation(glm::vec2 newTrans);
/*
void SetElectricPower(float electricPower);
void SetBuildingTime(float buildingTime);
void SetBuildingCost(float buildingCost);
void SetBuildingHp(float buildingHp);
void DecreaseElectricPower(float Power);
void IncreaseBuildingTime(float Time);
void DecreaseBuildingCost(float Cost);
*/

void DecreaseHp(float Hp);

float GetElectricPower();
float GetBuildingTime();
float GetBuildingCost();
float GetBuildingHp();

private:
updateMode m_CurrentState = updateMode::Invisidable;
glm::vec2 ObjectLocation;
glm::vec2 ObjectLocation={0,0};
float electricPower;
float buildingTime;
float buildingCost;
float buildingHp;
};

#endif // PRACTICALTOOLSFORSIMPLEDESIGN_STRUCTURE_HPP
19 changes: 19 additions & 0 deletions include/Structure/Barracks.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef PRACTICALTOOLSFORSIMPLEDESIGN_STRUCTURE_BARRACKS_HPP
#define PRACTICALTOOLSFORSIMPLEDESIGN_STRUCTURE_BARRACKS_HPP

#include "Structure\IWayPointStructure.hpp"
#include "Structure.hpp"
#define DEFAULT_POWER -20.F
#define DEFAULT_TIME 15.F
#define DEFAULT_COST 300.F
#define DEFAULT_HP 800.F

class Barracks : public Structure,public IWayPointStructure{
public:
Barracks(float electricPower=DEFAULT_POWER,float buildingTime=DEFAULT_POWER,
float buildingCost=DEFAULT_POWER,float buildingHp=DEFAULT_POWER): Structure(electricPower, buildingTime, buildingCost, buildingHp){};
virtual glm::vec2 GetStructureLocation()override{return this->GetObjectLocation();};
void Start() override{this->SetWayPointLocation({this->GetObjectLocation().x+20,this->GetObjectLocation().y+20});};
};

#endif // PRACTICALTOOLSFORSIMPLEDESIGN_CAPYBARA_HPP
12 changes: 12 additions & 0 deletions include/Structure/Buildings.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "Structure.hpp"

#define DEFAULT_POWER 100.F
#define DEFAULT_TIME 100.F
#define DEFAULT_COST 100.F
#define DEFAULT_HP 1000.F

class Building:public Structure{
public:
Building(float electricPower=DEFAULT_POWER,float buildingTime=DEFAULT_TIME,
float buildingCost=DEFAULT_COST,float buildingHp=DEFAULT_HP): Structure(electricPower, buildingTime, buildingCost, buildingHp){};
};
22 changes: 22 additions & 0 deletions include/Structure/IWayPointStructure.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Created by nudle on 2024/3/3.
//

#ifndef PRACTICALTOOLSFORSIMPLEDESIGN_IWAYPOINTSTRUCTURE_HPP
#define PRACTICALTOOLSFORSIMPLEDESIGN_IWAYPOINTSTRUCTURE_HPP
#include "Structure.hpp"
#include "Line.hpp"

class IWayPointStructure{
private:
glm::vec2 waypointLocation;
public:
virtual glm::vec2 GetWayPointLocation(){return this->waypointLocation;};
void SetWayPointLocation(glm::vec2 newLocation){
this->waypointLocation=newLocation;
};
virtual glm::vec2 GetStructureLocation()=0;
};


#endif // PRACTICALTOOLSFORSIMPLEDESIGN_IWAYPOINTSTRUCTURE_HPP
18 changes: 18 additions & 0 deletions include/Structure/OreRefinery.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef PRACTICALTOOLSFORSIMPLEDESIGN_STRUCTURE_OreRefinery_HPP
#define PRACTICALTOOLSFORSIMPLEDESIGN_STRUCTURE_OreRefinery_HPP

#include "IWayPointStructure.hpp"
#include "Structure.hpp"
#define DEFAULT_POWER -30.F
#define DEFAULT_TIME 100.F
#define DEFAULT_COST 2000.F
#define DEFAULT_HP 900.F

class OreRefinery:public Structure,public IWayPointStructure{
public:
OreRefinery(float electricPower=DEFAULT_POWER,float buildingTime=DEFAULT_TIME,
float buildingCost=DEFAULT_COST,float buildingHp=DEFAULT_HP): Structure(electricPower, buildingTime, buildingCost, buildingHp){};
virtual glm::vec2 GetStructureLocation()override{return this->GetObjectLocation();};
void Start() override{this->SetWayPointLocation({this->GetObjectLocation().x+20,this->GetObjectLocation().y+20});};
};
#endif
17 changes: 17 additions & 0 deletions include/Structure/PowerPlants.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef PRACTICALTOOLSFORSIMPLEDESIGN_STRUCTURE_PowerPlants_HPP
#define PRACTICALTOOLSFORSIMPLEDESIGN_STRUCTURE_PowerPlants_HPP


#include "Structure.hpp"
#define DEFAULT_POWER 100.F
#define DEFAULT_TIME 15.F
#define DEFAULT_COST 300.F
#define DEFAULT_HP 400.F

class PowerPlants:public Structure{
public:
PowerPlants(float electricPower=DEFAULT_POWER,float buildingTime=DEFAULT_TIME,
float buildingCost=DEFAULT_COST,float buildingHp=DEFAULT_HP): Structure(electricPower, buildingTime, buildingCost, buildingHp){};
};

#endif
19 changes: 19 additions & 0 deletions include/Structure/WarFactory.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef PRACTICALTOOLSFORSIMPLEDESIGN_STRUCTURE_WarFactory_HPP
#define PRACTICALTOOLSFORSIMPLEDESIGN_STRUCTURE_WarFactory_HPP

#include "IWayPointStructure.hpp"
#include "Structure.hpp"
#define DEFAULT_POWER -30.F
#define DEFAULT_TIME 100.F
#define DEFAULT_COST 2000.F
#define DEFAULT_HP 1000.F

class WarFactory : public Structure,public IWayPointStructure{
public:
WarFactory(float electricPower=DEFAULT_POWER,float buildingTime=DEFAULT_POWER,
float buildingCost=DEFAULT_POWER,float buildingHp=DEFAULT_POWER): Structure(electricPower, buildingTime, buildingCost, buildingHp){};
virtual glm::vec2 GetStructureLocation()override{return this->GetObjectLocation();};
void Start() override{this->SetWayPointLocation({this->GetObjectLocation().x+20,this->GetObjectLocation().y+20});};
};

#endif // PRACTICALTOOLSFORSIMPLEDESIGN_CAPYBARA_HPP
22 changes: 22 additions & 0 deletions include/WayPoint.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Created by nudle on 2024/3/3.
//

#ifndef PRACTICALTOOLSFORSIMPLEDESIGN_WAYPOINT_HPP
#define PRACTICALTOOLSFORSIMPLEDESIGN_WAYPOINT_HPP
#include "Util/GameObject.hpp"
#include "Util/TransformUtils.hpp"
#include "Util/Image.hpp"

class WayPoint : public Util::GameObject{
private:
glm::vec2 ObjectLocation;
public:
WayPoint():Util::GameObject(){m_Transform.scale={0.2,0.2};};
void Update(const Util::Transform &transform = Util::Transform()) override;

void Start() override{/*SetDrawable(std::make_unique<Util::Image>("../assets/sprites/flag.png"));*/};
void SetObjectLocation(glm::vec2 location) ;
glm::vec2 GetObjectLocation(){return this->ObjectLocation; }
};
#endif // PRACTICALTOOLSFORSIMPLEDESIGN_WAYPOINT_HPP
21 changes: 21 additions & 0 deletions include/WayPointTool.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Created by nudle on 2024/3/5.
//

#ifndef PRACTICALTOOLSFORSIMPLEDESIGN_WAYPOINTTOOL_H
#define PRACTICALTOOLSFORSIMPLEDESIGN_WAYPOINTTOOL_H

#include <vector>
#include "glm/glm.hpp"
#include "Util/Input.hpp"
#include "Structure/IWayPointStructure.hpp"
class WayPointTool{
private:
public:
WayPointTool(){};
~WayPointTool(){};

bool checkMous(glm::vec2 objPos,glm::vec2 mousPos);
};

#endif // PRACTICALTOOLSFORSIMPLEDESIGN_WAYPOINTTOOL_H
2 changes: 1 addition & 1 deletion include/pch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <GL/glew.h>

//suppose to be "GL/glut", yet GLUT/glut on mac
#include <GLUT/glut.h>
//#include <GLUT/glut.h>

#include <glm/glm.hpp>
#include <glm/gtx/matrix_transform_2d.hpp>
Expand Down
3 changes: 2 additions & 1 deletion src/Barracks.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//
// Created by 盧威任 on 1/28/24.
//
/*
#include "Barracks.hpp"
#include "Util/GameObject.hpp"
#include "Util/Image.hpp"
Expand Down Expand Up @@ -36,4 +37,4 @@ void Barracks::Update([[maybe_unused]] const Util::Transform &transform) {
m_Drawable->Draw(m_Transform, m_ZIndex);
// LOG_DEBUG("GIRA: x: {}, y: {}", pos.x, pos.y);
}
}*/
Loading

0 comments on commit 50b4e7a

Please sign in to comment.