-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcannon.cpp
More file actions
74 lines (59 loc) · 1.5 KB
/
Copy pathcannon.cpp
File metadata and controls
74 lines (59 loc) · 1.5 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
74
#include "cannon.h"
#include <SFML/Graphics.hpp>
#include <iostream>
#include "common.h"
Cannon::Cannon()
:height(CELL)
,width(CELL*2)
,x(0)
,y(8*CELL) {
}
Cannon::~Cannon() {
}
void Cannon::Init() {
rectangle.setSize(sf::Vector2f(width, height));
rectangle.setPosition(x,y);
rectangle.setFillColor(sf::Color::Transparent);
rectangle1.setSize(sf::Vector2f(width, height-CELL/3));
rectangle1.setPosition(x,y+CELL/3);
rectangle1.setFillColor(sf::Color::Green);
rectangle2.setSize(sf::Vector2f(width/3, CELL/3));
rectangle2.setPosition(x+2*CELL/3,y);
rectangle2.setFillColor(sf::Color::Green);
}
void Cannon::Update() {
// update the paddle
}
void Cannon::Draw(sf::RenderWindow& window) {
window.draw(rectangle);
window.draw(rectangle1);
window.draw(rectangle2);
}
void Cannon::Reset() {
//reset when game restarts
}
void Cannon::Move(int dir, sf::RenderWindow& window) {
if (dir == RIGHT && (x + CELL) < CELL*(XCELLS - 1)) {
x += CELL/3;
}
if (dir == LEFT && x >= NONE) {
x -= CELL/3;
}
rectangle.setPosition(x,y);
rectangle1.setPosition(x,y+CELL/3);
rectangle2.setPosition(x+2*CELL/3,y);
}
int Cannon::GetX() {
return x;
}
int Cannon::GetY() {
return y;
}
bool Cannon::Hit(int x, int y) const{
int bx = rectangle.getPosition().x;
int by = rectangle.getPosition().y;
if (bx <= x && bx + width >= x && by <= y && by + height >= y) {
return true;
}
return false;
}