Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Game : public Engine
- {
- struct Shape
- {
- Shape(std::vector<Vector2> _points,Color _color,int _thickness,float _inc)
- {
- points = _points;
- color = _color;
- thickness = _thickness;
- inc = _inc;
- }
- Shape(){
- points = {};
- color = Color::White;
- thickness = 1;
- inc = 0.1f;
- }
- std::vector<Vector2> points{};
- Color color;
- int thickness;
- float inc;
- void draw(Drawer& drawer)
- {
- if(points.size() < 2 || inc <= 0) return;
- std::vector<Vector2> newP = points;
- float dist = (newP[0]-newP[1]).length() * inc;
- for(size_t i = 0; i < newP.size(); i++)
- {
- drawer.drawLine(
- newP[i],
- i+1 == newP.size() ? newP[0] :newP[i+1],
- color,
- thickness
- );
- }
- while(true)
- {
- if((newP[0]-newP[1]).length() < dist){ break; }
- for(size_t i = 0; i < newP.size(); i++)
- {
- newP[i] += ((i+1 == newP.size() ? newP[0] :newP[i+1]) - newP[i]) * inc;
- drawer.drawLine(
- i == 0 ? newP[newP.size()-1] : newP[i-1],
- newP[i],
- color,
- thickness
- );
- }
- }
- }
- };
- std::vector<Shape> shapes{};
- Shape currentShape {};
- void Initialize()
- {
- apis.graphicsAPI = GraphicsAPI::OpenGL;
- apis.graphicsAPI.OpenGLVer = 4.5;
- apis.windowAPI = WindowAPI::Android;
- apis.audioAPI = AudioAPI::NoAPI;
- apis.graphicsAPI.maxFramesInFlight = 3;
- //properties.allowResizing = false;
- //properties.windowSize = { 500, 500 };
- properties.maxUPS = 144;
- //properties.maxFPS = 0;
- properties.maxFPS = 60;
- properties.windowName = "Shapes!";
- //addShader(shader_wiggly);
- shapes.push_back(Shape( {{100,100}, {200,100}, {200,200}, {100,200}} ,Color::Blue, 1, 0.1f));
- shapes.push_back(Shape( {{200,100}, {200,200}, {300,200}, {300,100}} ,Color::Blue, 1, 0.1f));
- shapes.push_back(Shape( {{150,300}, {200,200}, {100,200} } ,Color::Blue, 1, 0.1f));
- currentShape.color = Color::Red;
- }
- void Load()
- {
- //setIcon("resources/icon.bmp");
- }
- void Update(double deltaT)
- {
- (void)deltaT;
- if(input.isKeyboardKeyDown(KK::Q)){
- Exit();
- }
- if(input.isMouseKeyClicked(MK::LMB))
- {
- currentShape.points.push_back(input.getMousePosition());
- }
- if(input.isMouseKeyClicked(MK::RMB))
- {
- currentShape.color = Color::Blue;
- shapes.push_back(currentShape);
- currentShape = Shape{};
- currentShape.color = Color::Red;
- }
- if(input.getScrollAmount() != 0)
- {
- currentShape.inc += 0.002f * input.getScrollAmount();
- }
- if(input.isKeyboardKeyClicked(KK::D))
- {
- shapes.clear();
- }
- }
- void Draw(double deltaT)
- {
- drawer.clear();
- drawer.drawText(std::to_string((int)(1/deltaT)), Ubuntu_Font32 , { 0, 0 },{ 0.5f, 0.5f },Color::Green);
- for (auto& shape : shapes)
- {
- shape.draw(drawer);
- }
- currentShape.draw(drawer);
- }
- void OnClose()
- {
- printf("Program closed successfully!\n");
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement