-
Notifications
You must be signed in to change notification settings - Fork 0
/
level.pde
122 lines (107 loc) · 3.12 KB
/
level.pde
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
class Level{
int m_id;
Player m_player;
Board m_board;
float m_countDown;
float m_time;
int m_goalPoints;
int m_maxMoves;
Tween m_tween;
String m_endText;
String m_endInfoText;
Level(int id, float time, int points, int moves){
m_id = id;
m_countDown = time;
m_time = time;
m_goalPoints = points;
m_maxMoves = moves;
m_tween = new Tween(2,0,height/2);
m_endText = "You lose!";
m_endInfoText = "Press ESC to go back or press Enter play again";
}
void reset(){
m_countDown = m_time;
m_player.m_points = m_player.m_initPoints;
m_board.reuseBoard();
m_player.m_moves = 0;
}
void update(float dt){
if(hasEnded()){
m_countDown = 0;
if(didGoalReach()){
m_endText = "You won!";
m_endInfoText = "Press ESC to go to menu or press Enter to play next level";
}
m_tween.update(dt);
}
else{
m_player.update(dt);
m_board.update(dt);
m_countDown -= dt;
}
}
void draw(){
m_board.draw();
m_player.draw();
pushStyle();
textSize(16 * g_scaleFactorX);
text(int(m_countDown), m_board.m_x + RECT_SIZE * g_scaleFactorX * BOARD_COLUMNS/2, m_board.m_y - 10 * g_scaleFactorY);
text(int(m_player.m_points) + "/" + m_goalPoints, m_board.m_x + textWidth(str(m_player.m_points) + "/" + str(m_goalPoints))/2 , m_board.m_y - 10 * g_scaleFactorY);
for(int i = 0; i < (m_maxMoves-m_player.m_moves); i++){
image(g_backgroundTile
,m_board.m_x + 0.745 * BOARD_COLUMNS * RECT_SIZE * g_scaleFactorX + (i % 7) * HEART_SIZE * g_scaleFactorX
,m_board.m_y - HEART_SIZE * g_scaleFactorY * int(i/ 7 + 1)
,HEART_SIZE*g_scaleFactorX
,HEART_SIZE*g_scaleFactorY
,BACKTILES.get("HEART").x
,BACKTILES.get("HEART").y
,BACKTILES.get("HEART").x + BACKTILES.get("HEART").width
,BACKTILES.get("HEART").y + BACKTILES.get("HEART").height);
}
text(int(m_player.m_points) + "/" + m_goalPoints,
m_board.m_x + textWidth(str(m_player.m_points) + "/" + str(m_goalPoints))/2 ,
m_board.m_y - 10 * g_scaleFactorY);
popStyle();
}
boolean hasEnded(){
return (m_countDown <= 1 || (m_maxMoves == m_player.m_moves));
}
void lateDraw(){
m_board.lateDraw();
if(m_countDown <= 0){
fill(0,0,0,100);
rect(0,0,width,height);
fill(155,155,155);
rect(0,m_tween.getPosition(),width,60*g_scaleFactorY);
fill(0,0,0);
pushStyle();
textAlign(CENTER);
textSize(12 * g_scaleFactorX);
text(m_endText,width/2,m_tween.getPosition() + 25*g_scaleFactorY);
textSize(9 * g_scaleFactorX);
text(m_endInfoText,width/2,m_tween.getPosition() + 40*g_scaleFactorY);
popStyle();
}
}
void setPlayer(Player p){
if(p==null)return;
m_player = p;
}
void setBoard(Board b){
if(b==null)return;
m_board = b;
}
void setBoardBackground(Frame f){
if(f != null){
m_board.m_backgroundTile = f;
}
}
boolean didGoalReach(){
if(m_player.m_points >= m_goalPoints){
return true;
}
else{
return false;
}
}
}