Корабът Радецки - Eight ball pool v 1.0
The documnetation for our physics-themed project.
table.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "sprite.hpp"
4#include "config.h"
5#include <list>
6#include <physac.h>
7#include <raylib.h>
8#include <iostream>
9#include <string>
10
11class Ball : public Sprite
12{
13private:
14 int ball_number;
15 PhysicsBody body;
16
17public:
18 Ball(int number, Vector2 initial_position)
19 : Sprite(
20 Sprite("resources/images/white_ball.png", initial_position)
21 // number == 0 ?
22 // Sprite("resources/images/white_ball.png", initial_position) :
23 // number == 8 ?
24 // Sprite("resources/images/black_ball.png", initial_position) :
25 // number <= 7 ?
26 // Sprite("resources/images/yellow_ball.png", initial_position) :
27 // Sprite("resources/images/red_ball.png", initial_position)
28 )
29 {
30 std::cout << "Called Ball()" << std::endl;
31 ball_number = number;
32 sprite_scale_factor = 50.0f / sprite_texture.width;
33
34 body = CreatePhysicsBodyCircle({ sprite_position.x + GetWidth() / 2, sprite_position.y + GetHeight() / 2 }, GetWidth() / 2, .5f);
35 body->restitution = 1.0f;
36 body->dynamicFriction = 0.5f;
37 body->staticFriction = 0.5f;
38 body->enabled = true;
39 }
40
41 virtual ~Ball() = default;
42
43 Vector2 GetPosition();
44 Vector2 GetVelocity();
45 void SetPosition(Vector2 pos);
46 void AddForce(Vector2 force);
47
48 void Update() override;
49 void Draw() override;
50};
51
52class Stick : public Sprite
53{
54private:
55 const Vector2 starting_stick_position = { WINDOW_WIDTH / 2 - 340, WINDOW_HEIGHT / 2 };
56 float force_amount;
57 bool shown;
58
59public:
60 Stick(Vector2 position) : Sprite("resources/images/stick.png", position)
61 {
63 force_amount = 30.f;
64 shown = true;
65 }
66
67 virtual ~Stick() = default;
68
69 void SetShown(bool value);
70 void SetForce(float value);
71 bool GetShown();
72 Vector2 GetCurrentForce();
73
74 void Create() override;
75 void Update() override;
76 void Draw() override;
77};
78
79class Table : public Sprite
80{
81private:
82 PhysicsBody top_wall[2];
83 PhysicsBody bottom_wall[2];
84 PhysicsBody left_wall[2];
85 PhysicsBody right_wall[2];
86
87 PhysicsBody hole[6];
88
89public:
90 Table() : Sprite("resources/images/table.png", {})
91 {
93 }
94
95 void Create() override;
96};
97
Definition: table.hpp:12
void SetPosition(Vector2 pos)
Definition: table.cpp:13
void Update() override
Definition: table.cpp:18
void Draw() override
Draws the sprites.
Definition: table.cpp:23
void AddForce(Vector2 force)
Definition: table.cpp:81
Ball(int number, Vector2 initial_position)
Definition: table.hpp:18
Vector2 GetVelocity()
Definition: table.cpp:8
Vector2 GetPosition()
Definition: table.cpp:3
virtual ~Ball()=default
Definition: sprite.hpp:8
Vector2 sprite_position
Definition: sprite.hpp:10
float GetWidth()
Gets the width of the sprites.
Definition: sprite.cpp:24
float sprite_scale_factor
Definition: sprite.hpp:12
float GetHeight()
Gets the height of the sprites.
Definition: sprite.cpp:29
Texture2D sprite_texture
Definition: sprite.hpp:11
Definition: table.hpp:53
Stick(Vector2 position)
Definition: table.hpp:60
void SetForce(float value)
Definition: table.cpp:201
void Create() override
Definition: table.cpp:141
Vector2 GetCurrentForce()
Definition: table.cpp:211
bool GetShown()
Definition: table.cpp:206
void Update() override
Definition: table.cpp:148
virtual ~Stick()=default
void SetShown(bool value)
Definition: table.cpp:196
void Draw() override
Draws the sprites.
Definition: table.cpp:178
Definition: table.hpp:80
Table()
Definition: table.hpp:90
void Create() override
Definition: table.cpp:86
#define WINDOW_WIDTH
Definition: config.h:1
#define WINDOW_HEIGHT
Definition: config.h:2