-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblock_state.cpp
More file actions
28 lines (25 loc) · 785 Bytes
/
block_state.cpp
File metadata and controls
28 lines (25 loc) · 785 Bytes
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
#include "include/globals.h"
#include "include/state_management.h"
#include "include/state_init.h"
#include "include/draw.h"
void block_update(Block& b, GameState& g) {
if (!b.active) {
block_destroy(b, g);
return;
}
if (b.pos.y < b.target_pos.y) {
b.y_vel += 0.1;
b.pos.y += b.y_vel;
if (b.pos.y >= b.target_pos.y) {
b.pos.y = b.target_pos.y;
b.y_vel = 0;
}
}
}
void block_destroy(const Block& b, GameState& g) {
++g.score;
for (int i = 0; i < 2; ++i) {
vector_2d particle_vel = {rng.randomFloat(-2.0f, 2.0f), rng.randomFloat(2.0f, 0.0f)}; // can't have upward trajectory
g.particles.push_back(new_particle(b.pos, particle_vel, b.clr, rng.randomInt(1,2), 90));
}
}