-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stone.h
88 lines (72 loc) · 2.15 KB
/
Stone.h
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef STONE_H
#define STONE_H
#include <vector>
#include "ScreenBuffer.h"
#include "Drawable.h"
#include "WorldConstants.h"
#include "PointF.h"
/*
* A Stone consists of 4 subStones, represented in Points.
* The Stones have an own inner coordinate system:
* -2
* ....|....
* ....|....
* -4----+----+4
* ....|....
* ....|....
* +2
* The "+" is the midpoint relative it is always (0|0),
* but the absolute position depence from the Stone position in the
* Play field.
*/
class Stone : public Drawable
{
private:
// The position of all substones which result in the whole Stone
PointF m_subStones[4];
// The rotation point
PointF m_rotationPoint;
// The absolute position of the midpoint
PointF m_position;
/*
* Store the old absolute position and relativ Position of the Stones
* after the position or orientation changed,
* so we can restore if necessary (e.g. if there is a collision)
*/
PointF m_positionOld;
PointF m_subStonesOld[4];
public:
Stone();
Stone(const float midPointX, const float midPointY,
const float subStone1X, const float subStone1Y,
const float subStone2X, const float subStone2Y,
const float subStone3X, const float subStone3Y,
const float subStone4X, const float subStone4Y);
// Set the Stone to the default point and choose a new Stone sort
void spawn();
// Set the field start position
void toFieldStartPos();
// Get the position of the specific axe of the point which is most in the
// specic direction
int getLeft() const;
int getRight() const;
int getTop() const;
int getBottom() const;
// Retrun the Points with global coordinates
void fillWithGlobalPoints(PointF *points) const;
void moveDown();
void moveLeft();
void moveRight();
void rotateRight();
void rotateLeft();
// Store the Stone in the buffer so we can later draw it with
// all the other Stones
virtual void fillScreenBuffer
(const int StartX, const int StartY, ScreenBuffer *screenBuffer) const;
bool isCollidingWithPoint(const PointF &point) const;
void restoreOldPosition();
private:
void initStone();
void saveOldPosition();
};
#endif // !STONE_H