Commit | Line | Data |
---|---|---|
e68f847b PG |
1 | /* |
2 | * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com. | |
3 | * | |
4 | * This program is free software: you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation, either version 3 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | */ | |
17 | ||
2c18685d | 18 | #include "Screen.h" |
2c18685d | 19 | |
3d1f0813 PG |
20 | #include "Entities/PhysicsEntity.h" |
21 | #include "Entities/Ball.h" | |
2c18685d | 22 | |
617dcc71 PG |
23 | |
24 | /// ***** Constructors/Destructors ***** | |
25 | ||
2c18685d PG |
26 | Screen::Screen() |
27 | { | |
28 | ||
29 | } | |
30 | Screen::~Screen() | |
31 | { | |
32 | ||
33 | } | |
34 | ||
617dcc71 PG |
35 | /// ***** Public Class Methods ***** |
36 | ||
88085362 | 37 | Vector2 Screen::positionDelta(const PhysicsEntity* e, float /*time_step*/) const |
5d5a6f3f PG |
38 | { |
39 | const Vector2& pos = e->positionRaw(); | |
5d5a6f3f PG |
40 | |
41 | Vector2 acc(0,0); | |
42 | ||
43 | float radius = 0; | |
44 | const Ball* b = dynamic_cast<const Ball*>(e); | |
45 | if( b != NULL ) | |
46 | radius = b->getRadius(); | |
47 | ||
48 | ||
9d6dea5f PG |
49 | if(pos.m_fY > 600-radius) |
50 | acc.m_fY += 600-radius - pos.m_fY; | |
5d5a6f3f | 51 | |
9d6dea5f PG |
52 | if(pos.m_fY < 0+radius) |
53 | acc.m_fY += 0+radius - pos.m_fY; | |
5d5a6f3f | 54 | |
9d6dea5f PG |
55 | if(pos.m_fX > 800-radius) |
56 | acc.m_fX += 800-radius - pos.m_fX; | |
5d5a6f3f | 57 | |
9d6dea5f PG |
58 | if(pos.m_fX < 0+radius) |
59 | acc.m_fX += 0+radius - pos.m_fX; | |
5d5a6f3f PG |
60 | |
61 | return acc; | |
62 | } | |
63 | ||
88085362 | 64 | Vector2 Screen::velocityDelta(const PhysicsEntity* e, float /*time_step*/) const |
2c18685d PG |
65 | { |
66 | const Vector2& pos = e->positionRaw(); | |
67 | const Vector2& velo = e->velocityRaw(); | |
68 | ||
69 | Vector2 acc(0,0); | |
70 | ||
fd1a93a7 | 71 | float CoR = e->m_CoR; |
094a13b8 PG |
72 | float radius = 0; |
73 | const Ball* b = dynamic_cast<const Ball*>(e); | |
74 | if( b != NULL ) | |
75 | radius = b->getRadius(); | |
76 | ||
77 | ||
9d6dea5f PG |
78 | if(pos.m_fY > 600-radius && velo.m_fY > 0) |
79 | acc.m_fY += velo.m_fY * -(1 + CoR); | |
2c18685d | 80 | |
9d6dea5f PG |
81 | if(pos.m_fY < 0+radius && velo.m_fY < 0) |
82 | acc.m_fY += velo.m_fY * -(1 + CoR); | |
2c18685d | 83 | |
9d6dea5f PG |
84 | if(pos.m_fX > 800-radius && velo.m_fX > 0) |
85 | acc.m_fX += velo.m_fX * -(1 + CoR); | |
2c18685d | 86 | |
9d6dea5f PG |
87 | if(pos.m_fX < 0+radius && velo.m_fX < 0) |
88 | acc.m_fX += velo.m_fX * -(1 + CoR); | |
2c18685d PG |
89 | |
90 | return acc; | |
91 | } |