sanek2005_15

Physic.h

Oct 25th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #pragma once
  2. #include "stdafx.h"
  3.  
  4. class Collision
  5. {
  6. private:
  7.     RectangleShape dynamic_shape;
  8.     RectangleShape static_shape;
  9.     float G = 9.8f;
  10.     RenderWindow* window;
  11.  
  12. public:
  13.  
  14.     Collision(RenderWindow* window)
  15.     {
  16.         this->window = window;
  17.  
  18.         static_shape.setSize(Vector2f(20, 30));
  19.         static_shape.setPosition(Vector2f(230, 250));
  20.         static_shape.setFillColor(Color(232, 34, 38, 255));
  21.  
  22.         dynamic_shape.setSize(static_shape.getSize());
  23.         dynamic_shape.setPosition(static_shape.getPosition() - Vector2f(0, 100));
  24.         dynamic_shape.setFillColor(Color(22, 33, 32, 255));
  25.  
  26.     }
  27.  
  28.     void draw()
  29.     {
  30.         this->window->draw(this->static_shape);
  31.         this->window->draw(this->dynamic_shape);
  32.     }
  33.  
  34.     float distance()
  35.     {
  36.         Vector2f a = static_shape.getPosition() - dynamic_shape.getPosition();
  37.  
  38.         return sqrt((a.x*a.x) - (a.y*a.y));
  39.     }
  40.  
  41.     void update_physic()
  42.     {
  43.        
  44.         if (distance() > Vector2f(dynamic_shape.getSize()).x)
  45.             dynamic_shape.move(0, G);
  46.     }
  47. };
Advertisement
Add Comment
Please, Sign In to add comment