C++ Project 2016-2017: Arkanoid
entity.cpp
Go to the documentation of this file.
1 
3 #include "entity.h"
4 #include "../math/vector2D.h"
5 
6 #include <iostream>
7 
8 using namespace std;
9 
10 
11 namespace arkanoid {
12 
13  Entity::Entity() {}
14 
15  Entity::Entity(double x, double y, pair<double, double> newSize) : position(x, y), size(newSize) {}
16 
18  return position;
19  }
20 
21  void Entity::setPosition(double x, double y) {
22  position.x = x;
23  position.y = y;
24  }
25 
26  void Entity::setPosition(const Vector2D &vector) {
27  position = vector;
28  }
29 
30  void Entity::setSize(pair<double, double> newSize) {
31  size = newSize;
32  }
33 
34  pair<double, double> Entity::getSize() const {
35  return size;
36  }
37 
38  bool Entity::collidesWith(const Entity &other) const {
39 
40  if(
41  // Check if left/right is in other's surface
42  position.x < other.getPosition().x + other.getSize().first
43  && position.x + size.first > other.getPosition().x
44 
45  // Check if top/bottom is in other's surface
46  && position.y < other.getPosition().y + other.getSize().second
47  && position.y + size.second > other.getPosition().y
48  ) {
49  return true;
50  }
51 
52  return false;
53  }
54 }
void setSize(pair< double, double > newSize)
Definition: entity.cpp:30
Vector2D position
The current position of the Entity (in the 9x7 grid).
Definition: entity.h:17
bool collidesWith(const Entity &other) const
Definition: entity.cpp:38
Representation of a vector.
Definition: vector2D.h:14
Vector2D getPosition() const
Definition: entity.cpp:17
double y
The &#39;y&#39; component of the Vector2D.
Definition: vector2D.h:18
double x
The &#39;x&#39; component of the Vector2D.
Definition: vector2D.h:17
All the game logic of the Arkanoid game.
Definition: ball.cpp:15
pair< double, double > getSize() const
Definition: entity.cpp:34
An Entity represents an "object" (like Player, Ball, Block, ...) in the game World.
Definition: entity.h:15
void setPosition(double x, double y)
Definition: entity.cpp:21
pair< double, double > size
The size (width and height respectively) of the Entity.
Definition: entity.h:18