summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Barrett <tom@tombarrett.xyz>2021-02-03 18:13:57 +0100
committerTom Barrett <tom@tombarrett.xyz>2021-02-03 18:13:57 +0100
commit46ab0e5df51cdf25e3df32b6e395604e86375a26 (patch)
tree3b2d9d146da2fe9aba31d29b80683700b3e146a8 /src
parentbdd01a8d64f8acd2315d4e28534cd1fd429331e8 (diff)
things fall
Diffstat (limited to 'src')
-rw-r--r--src/main.rs24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs
index 0fa52ab..18dd403 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -73,6 +73,14 @@ impl Cell {
false
}
+ pub fn moveable(&self) -> bool {
+ match self.occupant {
+ Occupant::Explosion { .. } => false,
+ Occupant::None => false,
+ _ => true,
+ }
+ }
+
pub fn clicked_on(&mut self) {
self.clicked = true;
}
@@ -248,13 +256,16 @@ impl Game {
}
fn update_dropping(&mut self) {
- /*
- for (i, row) in self.grid.iter_mut().enumerate() {
- for (j, cell) in row.iter_mut().enumerate() {
- println!("a");
+ for i in 1..COLUMNS {
+ for j in 0..ROWS {
+ if self.grid[i][j].occupant == Occupant::None
+ && self.grid[i - 1][j].occupant != Occupant::None
+ {
+ self.grid[i][j].occupant = self.grid[i - 1][j].occupant;
+ self.grid[i - 1][j].occupant = Occupant::None;
+ }
}
}
- */
}
fn update_frames(&mut self) {
@@ -319,7 +330,7 @@ impl EventHandler for Game {
let position = Point2 { x, y };
for (i, row) in self.grid.iter_mut().enumerate() {
for (j, cell) in row.iter_mut().enumerate() {
- if cell.contains(position) {
+ if cell.contains(position) && cell.moveable() {
self.selected = Some((i, j));
cell.clicked_on();
}
@@ -348,6 +359,7 @@ impl EventHandler for Game {
for (i, row) in self.grid.iter_mut().enumerate() {
for (j, cell) in row.iter_mut().enumerate() {
if cell.contains(position)
+ && cell.moveable()
&& (((i + 1 == selected.0) && (j == selected.1))
|| ((i.overflowing_sub(1).0 == selected.0) && (j == selected.1))
|| ((i == selected.0) && (j + 1 == selected.1))