-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
86 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,36 @@ | ||
#ifndef PRACTICALTOOLSFORSIMPLEDESIGN_STRUCTURE_WarFactory_HPP | ||
#define PRACTICALTOOLSFORSIMPLEDESIGN_STRUCTURE_WarFactory_HPP | ||
|
||
#include "Grid.hpp" | ||
#include "HighLight.h" | ||
#include "Line.hpp" | ||
#include "Structure/IWayPointStructure.hpp" | ||
#include "Structure/Structure.hpp" | ||
#include "Util/Image.hpp" | ||
#include "Util/Keycode.hpp" | ||
#include "Util/Input.hpp" | ||
#include "Util/Keycode.hpp" | ||
#include "WayPoint.hpp" | ||
#include "HighLight.h" | ||
#include "Line.hpp" | ||
#include "Grid.hpp" | ||
|
||
class WarFactory : public Structure,public IWayPointStructure{ | ||
class WarFactory : public Structure, public IWayPointStructure { | ||
public: | ||
WarFactory(float electricPower = -30.F, float buildingTime = 100.F, | ||
float buildingCost = 2000.F, float buildingHp = 1000.F) | ||
: Structure(electricPower, buildingTime, buildingCost, buildingHp){}; | ||
void Start() override; | ||
|
||
virtual void onSelected(bool selected) override; | ||
virtual void SetAttachVisible(bool visible) override; | ||
|
||
virtual void updateFixed() override; | ||
virtual void updateMoveable() override; | ||
|
||
private: | ||
std::shared_ptr<WayPoint> m_wayPoint = std::make_shared<WayPoint>(); | ||
HighLight m_HighLight; | ||
bool b_select= true; | ||
bool b_select = true; | ||
Grid m_Grid; | ||
Line m_Line; | ||
std::vector<Line> m_lineVector; | ||
public: | ||
WarFactory(float electricPower=-30.F,float buildingTime=100.F, | ||
float buildingCost=2000.F,float buildingHp=1000.F): | ||
Structure(electricPower, buildingTime, buildingCost, buildingHp){}; | ||
void Start() override; | ||
|
||
virtual void onSelected(bool selected)override; | ||
virtual void SetAttachVisible(bool visible)override; | ||
|
||
virtual void updateFixed()override; | ||
virtual void updateMoveable()override; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,80 @@ | ||
#include "Structure/WarFactory.hpp" | ||
void WarFactory::Start(){ | ||
this->SetWayPointLocation({this->GetObjectLocation().x+20,this->GetObjectLocation().y+20});//Debug Only | ||
//Set Texture---------------------------------------- | ||
this->SetDrawable(std::make_unique<Util::Image>("../assets/sprites/barracks.png")); | ||
m_wayPoint->SetDrawable(std::make_unique<Util::Image>("../assets/sprites/flagB.png")); | ||
m_HighLight.SetDrawable(std::make_unique<Util::Image>("../assets/sprites/HighLightB.png")); | ||
void WarFactory::Start() { | ||
this->SetWayPointLocation({this->GetObjectLocation().x + 20, | ||
this->GetObjectLocation().y + 20}); // Debug Only | ||
// Set Texture---------------------------------------- | ||
this->SetDrawable( | ||
std::make_unique<Util::Image>("../assets/sprites/barracks.png")); | ||
m_wayPoint->SetDrawable( | ||
std::make_unique<Util::Image>("../assets/sprites/flagB.png")); | ||
m_HighLight.SetDrawable( | ||
std::make_unique<Util::Image>("../assets/sprites/HighLightB.png")); | ||
this->SetZIndex(DEFAULT_ZINDEX); | ||
m_wayPoint->SetZIndex(DEFAULT_ZINDEX); | ||
m_HighLight.SetZIndex(DEFAULT_ZINDEX); | ||
//Set Attachment Location & Visibility---------------------------------------- | ||
// Set Attachment Location & | ||
// Visibility---------------------------------------- | ||
m_wayPoint->SetObjectLocation(this->GetWayPointLocation()); | ||
m_HighLight.SetHLScale(this->GetTranScale()); | ||
m_HighLight.SetObjectLocation(this->GetObjectLocation()); | ||
this->SetAttachVisible(false); | ||
//Line Setup---------------------------------------- | ||
m_Grid.Start(std::vector<Line>({Line(GetObjectLocation(),GetWayPointLocation())})); | ||
// Line Setup---------------------------------------- | ||
m_Grid.Start(std::vector<Line>({Line( | ||
GetObjectLocation() + glm::vec2{50.F, 50.F}, GetWayPointLocation())})); | ||
m_Grid.SetActivate(false); | ||
//State | ||
// State | ||
SetCurrentUpdateMode(Structure::updateMode::Moveable); | ||
} | ||
void WarFactory::updateFixed() { | ||
m_Grid.setLine(GetObjectLocation(),GetWayPointLocation()); | ||
m_Grid.setLine(GetObjectLocation(), GetWayPointLocation()); | ||
Util::Transform Trans; | ||
m_Grid.DrawUsingCamera(Trans,DEFAULT_ZINDEX); | ||
m_Grid.DrawUsingCamera(Trans, DEFAULT_ZINDEX); | ||
|
||
|
||
//Attachment and self readjust location and draw--------------- | ||
// Attachment and self readjust location and draw--------------- | ||
m_wayPoint->SetObjectLocation(this->GetWayPointLocation()); | ||
m_HighLight.SetObjectLocation(this->GetObjectLocation()); | ||
this->Draw(); | ||
m_wayPoint->Draw(); | ||
m_HighLight.Draw(); | ||
|
||
//Script when select-------------------- | ||
if(Util::Input::IsKeyDown(Util::Keycode::T)){ | ||
b_select=!b_select; | ||
// Script when select-------------------- | ||
if (Util::Input::IsKeyDown(Util::Keycode::T)) { | ||
b_select = !b_select; | ||
} | ||
if(b_select){ | ||
onSelected(true); | ||
}else{ | ||
onSelected(false); | ||
if (b_select) { | ||
onSelected(true); | ||
} else { | ||
onSelected(false); | ||
} | ||
} | ||
void WarFactory::updateMoveable(){ | ||
glm::vec2 location=Util::Input::GetCursorPosition(); | ||
location=MapClass::ScreenToGlobalCoord(location); | ||
void WarFactory::updateMoveable() { | ||
glm::vec2 location = Util::Input::GetCursorPosition(); | ||
location = MapClass::ScreenToGlobalCoord(location); | ||
this->SetObjectLocation(location); | ||
this->SetVisible(true); | ||
this->Draw(); | ||
if(Util::Input::IsKeyPressed(Util::Keycode::MOUSE_LB)){ | ||
this->SetObjectLocation(location); | ||
m_HighLight.SetObjectLocation({GetObjectLocation().x+0.5*CELL,GetObjectLocation().y+0.5*CELL}); | ||
this->SetWayPointLocation({this->GetObjectLocation().x+48-0.5*CELL,this->GetObjectLocation().y+48-0.5*CELL}); | ||
onSelected(false); | ||
this->SetCurrentUpdateMode(updateMode::Fixed); | ||
if (Util::Input::IsKeyPressed(Util::Keycode::MOUSE_LB)) { | ||
this->SetObjectLocation(location); | ||
m_HighLight.SetObjectLocation({GetObjectLocation().x + 0.5 * CELL, | ||
GetObjectLocation().y + 0.5 * CELL}); | ||
this->SetWayPointLocation( | ||
{this->GetObjectLocation().x + 48 - 0.5 * CELL, | ||
this->GetObjectLocation().y + 48 - 0.5 * CELL}); | ||
onSelected(false); | ||
this->SetCurrentUpdateMode(updateMode::Fixed); | ||
} | ||
} | ||
void WarFactory::onSelected(bool selected) { | ||
this->SetAttachVisible(selected); | ||
if(selected){ | ||
if(Util::Input::IsKeyDown(Util::Keycode::V)){ | ||
this->SetWayPointLocation({GetWayPointLocation().x+5,GetWayPointLocation().y+5}); | ||
if (selected) { | ||
if (Util::Input::IsKeyDown(Util::Keycode::V)) { | ||
this->SetWayPointLocation( | ||
{GetWayPointLocation().x + 5, GetWayPointLocation().y + 5}); | ||
} | ||
} | ||
} | ||
void WarFactory::SetAttachVisible(bool visible) { | ||
m_wayPoint->SetVisible(visible); | ||
m_HighLight.SetVisible(visible); | ||
m_Grid.SetActivate(visible); | ||
} | ||
} |