parent
7999b27b86
commit
746c91ec85
Binary file not shown.
@ -1,51 +1,59 @@ |
|||||||
#define OLC_PGE_APPLICATION |
#define OLC_PGE_APPLICATION |
||||||
#include "pixelGameEngine.h" |
#include "pixelGameEngine.h" |
||||||
#include <memory> |
|
||||||
using namespace olc; |
using namespace olc; |
||||||
|
|
||||||
struct myStruct{ |
class BoxBorder : public olc::PixelGameEngine |
||||||
std::string name=""; |
{ |
||||||
int level=1; |
public: |
||||||
}; |
BoxBorder() |
||||||
std::vector<std::weak_ptr<myStruct>> vals; |
{ |
||||||
|
sAppName = "Box Border"; |
||||||
void AddVal(std::weak_ptr<myStruct>newVal) { |
} |
||||||
auto findVal=std::find_if(vals.begin(),vals.end(), |
|
||||||
[&newVal](std::weak_ptr<myStruct>&val) |
public: |
||||||
{ |
Decal*box; |
||||||
return val.lock()->name==newVal.lock()->name; |
|
||||||
} |
void DrawBorderBox(const vd2d&pos,const vd2d&size) { |
||||||
); |
DrawPartialDecal(pos,box,{0,0},{13,13}); //Upper-Left Corner
|
||||||
if (findVal!=vals.end()) { |
vd2d ULOffset={13,0}; |
||||||
std::cout<<"Value "<<newVal.lock()->name<<" already exists."<<std::endl; |
DrawPartialDecal(pos+ULOffset,{(float)size.x-26,13},box,{13,0},{91,13}); //Top
|
||||||
findVal->lock()->level++; |
vd2d UROffset={size.x-13,0}; |
||||||
std::cout<<findVal->lock()->name+" is now level "<<findVal->lock()->level<<std::endl; |
DrawPartialDecal(pos+UROffset,box,{104,0},{13,13}); //Upper-Right Corner
|
||||||
} else { |
vd2d ULBottomOffset={0,13}; |
||||||
std::cout<<"Value "<<newVal.lock()->name<<" does not exist."<<std::endl; |
DrawPartialDecal(pos+ULBottomOffset,{13,(float)size.y-25},box,{0,13},{13,73});//Left
|
||||||
vals.push_back(newVal); |
vd2d BLOffset={0,size.y-13}; |
||||||
std::cout<<newVal.lock()->name+" is now level "<<vals[vals.size()-1].lock()->level<<std::endl; |
DrawPartialDecal(pos+BLOffset,box,{0,86},{13,13}); //Bottom-Left Corner
|
||||||
|
vd2d BLLeftOffset={13,size.y-13+0.05}; |
||||||
|
DrawPartialDecal(pos+BLLeftOffset,{(float)size.x-26,13},box,{13,86},{91,13}); //Bottom
|
||||||
|
vd2d BROffset={size.x-13,size.y-13}; |
||||||
|
DrawPartialDecal(pos+BROffset,box,{104,86},{13,13}); //Bottom-Right Corner
|
||||||
|
vd2d TROffset={size.x-13,13}; |
||||||
|
DrawPartialDecal(pos+TROffset,{13,(float)size.y-25},box,{104,13},{13,73});//Right
|
||||||
} |
} |
||||||
} |
|
||||||
|
|
||||||
int main() { |
bool OnUserCreate() override |
||||||
std::shared_ptr<myStruct> myPtr1=std::make_shared<myStruct>(); |
{ |
||||||
std::shared_ptr<myStruct> myPtr2=std::make_shared<myStruct>(); |
box = new Decal(new Sprite("border.png"),false,true); |
||||||
std::shared_ptr<myStruct> myPtr3=std::make_shared<myStruct>(); |
return true; |
||||||
std::shared_ptr<myStruct> myPtr4=std::make_shared<myStruct>(); |
} |
||||||
|
|
||||||
std::weak_ptr<myStruct> refPtr1=myPtr1; |
bool OnUserUpdate(float fElapsedTime) override |
||||||
std::weak_ptr<myStruct> refPtr2=myPtr2; |
{ |
||||||
std::weak_ptr<myStruct> refPtr3=myPtr3; |
vd2d boxPos={24,24}; |
||||||
std::weak_ptr<myStruct> refPtr4=myPtr2; |
vd2d boxSize=GetMousePos()-boxPos; |
||||||
|
FillRectDecal(boxPos,boxSize,GREY); |
||||||
|
DrawBorderBox(boxPos,boxSize); |
||||||
|
return true; |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
refPtr1.lock()->name="Test Upgrade 1"; |
|
||||||
refPtr2.lock()->name="Test Upgrade 2"; |
|
||||||
refPtr3.lock()->name="Test Upgrade 3"; |
|
||||||
|
|
||||||
std::cout<<(refPtr2.lock()==refPtr4.lock())<<std::endl; |
int main() |
||||||
|
{ |
||||||
|
BoxBorder demo; |
||||||
|
if (demo.Construct(256, 240, 4, 4)) |
||||||
|
demo.Start(); |
||||||
|
|
||||||
AddVal(refPtr1); |
return 0; |
||||||
AddVal(refPtr2); |
|
||||||
AddVal(refPtr3); |
|
||||||
AddVal(refPtr4); |
|
||||||
} |
} |
Loading…
Reference in new issue