-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwall.cpp
More file actions
73 lines (60 loc) · 2.05 KB
/
wall.cpp
File metadata and controls
73 lines (60 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "wall.hpp"
using namespace std;
void Wall::setProp(Window* win, int xCor, int yCor, int _w, int _h){
mainWindow = win;
width = _w;
height = _h;
corner = Point(xCor, yCor);
}
void normalWall::draw(){
whereIsTheWall = Rectangle(corner, width, height);
mainWindow->fill_rect(whereIsTheWall, RGB(150, 75, 0));
}
void sharpWall::draw(){
whereIsTheWall = Rectangle(corner, width, height);
mainWindow->fill_rect(whereIsTheWall, RED);
}
bool Wall::isColidedFromRight(Ball* b){
if((b->x > whereIsTheWall.x + whereIsTheWall.w) && (b->x < whereIsTheWall.x + whereIsTheWall.w + 15) && (b->y > (whereIsTheWall.y - 15)) &&
(b->y < (whereIsTheWall.y + whereIsTheWall.h + 15))){
return true;
}
return false;
}
bool Wall::isColidedFromLeft(Ball* b){
if((b->x < whereIsTheWall.x) && (b->x > whereIsTheWall.x - 15) && (b->y > (whereIsTheWall.y - 15)) &&
(b->y < (whereIsTheWall.y + whereIsTheWall.h + 15))){
return true;
}
return false;
}
bool Wall::isColidedFromTop(Ball* b){
if((b->y > whereIsTheWall.y - 15) && (b->y < whereIsTheWall.y) &&
(b->x > whereIsTheWall.x - 15) && (b->x < whereIsTheWall.x + whereIsTheWall.w + 15)){
return true;
}
return false;
}
bool Wall::isColidedFromBottom(Ball* b){
if((b->y > whereIsTheWall.y + whereIsTheWall.h) && (b->y < whereIsTheWall.y + whereIsTheWall.h + 15)
&& (b->x > whereIsTheWall.x - 15) && (b->x < whereIsTheWall.x + whereIsTheWall.w + 15)){
return true;
}
return false;
}
void normalWall::checkForCollision(Ball* b){
reflect(b);
}
void sharpWall::checkForCollision(Ball* b){
if(isColidedFromBottom(b) || isColidedFromTop(b) || isColidedFromRight(b) || isColidedFromLeft(b)){
gameOver(mainWindow);
}
}
void normalWall::reflect(Ball* b){
if((isColidedFromRight(b) && b->xVel < 0)|| (isColidedFromLeft(b) && b->xVel > 0)){
b->xVel = -b->xVel;
}
if((isColidedFromTop(b) && b->yVel > 0) || (isColidedFromBottom(b) && b->yVel < 0)){
b->yVel = -b->yVel;
}
}