Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "stdafx.h"
- class Collision
- {
- private:
- RectangleShape dynamic_shape;
- RectangleShape static_shape;
- float G = 9.8f;
- RenderWindow* window;
- public:
- Collision(RenderWindow* window)
- {
- this->window = window;
- static_shape.setSize(Vector2f(20, 30));
- static_shape.setPosition(Vector2f(230, 250));
- static_shape.setFillColor(Color(232, 34, 38, 255));
- dynamic_shape.setSize(static_shape.getSize());
- dynamic_shape.setPosition(static_shape.getPosition() - Vector2f(0, 100));
- dynamic_shape.setFillColor(Color(22, 33, 32, 255));
- }
- void draw()
- {
- this->window->draw(this->static_shape);
- this->window->draw(this->dynamic_shape);
- }
- float distance()
- {
- Vector2f a = static_shape.getPosition() - dynamic_shape.getPosition();
- return sqrt((a.x*a.x) - (a.y*a.y));
- }
- void update_physic()
- {
- if (distance() > Vector2f(dynamic_shape.getSize()).x)
- dynamic_shape.move(0, G);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment