Commit 1f073fee authored by Astro's avatar Astro
Browse files

rkanoid: coors, check finish

parent cff81424
...@@ -25,10 +25,14 @@ impl Blocks { ...@@ -25,10 +25,14 @@ impl Blocks {
let mut count = 0; let mut count = 0;
for line in result.blocks.iter_mut() { for line in result.blocks.iter_mut() {
for block in line.iter_mut() { for block in line.iter_mut() {
let mut buf = [0]; let mut buf = [0, 0, 0, 0];
trng::read(&mut buf); trng::read(&mut buf);
if buf[0] > 0xBF { if buf[0] > 0xBF {
*block = Some(Color::yellow()); *block = Some(Color::rgb8(
0x80 | buf[1],
0x80 | buf[2],
0x80 | buf[3],
));
count += 1; count += 1;
} }
} }
...@@ -51,6 +55,10 @@ impl Blocks { ...@@ -51,6 +55,10 @@ impl Blocks {
None => false, None => false,
} }
} }
fn is_finished(&self) -> bool {
self.blocks.iter().all(|line| line.iter().all(|block| block.is_none()))
}
} }
const PADDLE_HEIGHT: u16 = 4; const PADDLE_HEIGHT: u16 = 4;
...@@ -139,6 +147,7 @@ fn game() -> u32 { ...@@ -139,6 +147,7 @@ fn game() -> u32 {
if input.left_top() { if input.left_top() {
exit(0); exit(0);
} }
let mut check_finish = false;
let speed_steps = 1 + (time() - start_time) / 10; let speed_steps = 1 + (time() - start_time) / 10;
for _ in 0..speed_steps { for _ in 0..speed_steps {
ball_direction.motion(&mut ball_x, &mut ball_y); ball_direction.motion(&mut ball_x, &mut ball_y);
...@@ -166,6 +175,7 @@ fn game() -> u32 { ...@@ -166,6 +175,7 @@ fn game() -> u32 {
ball_direction.bounce(Bounce::Vertical); ball_direction.bounce(Bounce::Vertical);
score += 100; score += 100;
// paddle_size += 2; // paddle_size += 2;
check_finish = true;
vibra::vibrate(60); vibra::vibrate(60);
} }
if blocks.collides(ball_x, ball_y - BALL_RADIUS) || if blocks.collides(ball_x, ball_y - BALL_RADIUS) ||
...@@ -173,21 +183,25 @@ fn game() -> u32 { ...@@ -173,21 +183,25 @@ fn game() -> u32 {
ball_direction.bounce(Bounce::Horizontal); ball_direction.bounce(Bounce::Horizontal);
score += 60; score += 60;
// paddle_size += 1; // paddle_size += 1;
check_finish = true;
vibra::vibrate(40); vibra::vibrate(40);
} }
} }
if check_finish && blocks.is_finished() {
return score + 1000;
}
display.clear(Color::black()); display.clear(Color::black());
// Paddle // Paddle
display.rect( display.rect(
paddle - paddle_size, Display::H - PADDLE_HEIGHT, paddle - paddle_size, Display::H - PADDLE_HEIGHT,
paddle + paddle_size, Display::H - 1, paddle + paddle_size, Display::H - 1,
Color::green(), FillStyle::Filled, 1 Color::rgb8(0x7f, 0xff, 0x7f), FillStyle::Filled, 1
); );
// Ball // Ball
display.circ( display.circ(
ball_x, ball_y, BALL_RADIUS, ball_x, ball_y, BALL_RADIUS,
Color::blue(), FillStyle::Filled, 1 Color::rgb8(0x7f, 0x7f, 0xff), FillStyle::Filled, 1
); );
// Blocks // Blocks
for (lineno, line) in blocks.blocks.iter_mut().enumerate() { for (lineno, line) in blocks.blocks.iter_mut().enumerate() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment