You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CirclesRefsPointers/Circles/Circles.cpp

82 lines
1.7 KiB

#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"
// Override base class with your custom functionality
class CircleExample : public olc::PixelGameEngine
{
struct Circle{
Circle(olc::vf2d pos,float radius)
:pos(pos),radius(radius){
std::cout<<"Circle created!"<<std::endl;
}
Circle(const Circle&circle)
:pos(circle.pos),radius(circle.radius){
std::cout<<"Circle copied!"<<std::endl;
}
olc::vf2d pos;
float radius;
};
struct CircleGroup{
std::vector<Circle*>circles;
};
public:
CircleExample()
{
// Name your application
sAppName = "Circles Example";
}
std::vector<Circle>circleList;
std::vector<CircleGroup>circleGroupList;
public:
bool OnUserCreate() override
{
// Called once at the start, so create things here
for(int y=0;y<5;y++){
for(int x=0;x<5;x++){
Circle myCircle = {olc::vf2d{x*16.f,y*16.f},8};
circleList.push_back(myCircle);
}
}
CircleGroup myGroup;
myGroup.circles.push_back(&circleList[3]);
myGroup.circles.push_back(&circleList[4]);
myGroup.circles.push_back(&circleList[9]);
circleGroupList.push_back(myGroup);
for(CircleGroup&circleGroup : circleGroupList){
for(Circle*c : circleGroup.circles){
c->pos+={20,0};
}
}
return true;
}
bool OnUserUpdate(float fElapsedTime) override
{
// Called once per frame, draws random coloured pixels
Clear(olc::VERY_DARK_GREEN);
olc::vf2d drawOffset = {64,64};
for(Circle&c : circleList){
DrawCircle(c.pos+drawOffset,c.radius);
}
for(CircleGroup&circleGroup : circleGroupList){
for(Circle*c : circleGroup.circles){
DrawCircle(c->pos+drawOffset,c->radius,olc::RED);
}
}
return true;
}
};
int main()
{
CircleExample demo;
if (demo.Construct(256, 240, 4, 4))
demo.Start();
return 0;
}