This commit is contained in:
Daniel Flanagan 2022-05-25 09:50:36 -05:00
parent f1826cdfd3
commit 24644e4900
Signed by: lytedev
GPG Key ID: 5B2020A0F9921EF4
2 changed files with 8 additions and 7 deletions

View File

@ -1,6 +1,7 @@
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
<title>Flappy Dragon by lyte.dev</title>
</head>
<body>
<canvas id="canvas" width="640" height="480"></canvas>

View File

@ -4,7 +4,7 @@
use bracket_lib::prelude::*;
use std::collections::VecDeque;
const VERSION: &str = "0.3.0";
// const VERSION: &str = "0.3.0";
const SCREEN_WIDTH: u16 = 80;
const SCREEN_HEIGHT: u16 = 50;
const FRAME_DURATION: f32 = 35.0;
@ -90,7 +90,7 @@ struct State {
time: f32,
mode: GameMode,
obstacles: VecDeque<Obstacle>,
obstacleSpawnTime: f32,
obstacle_spawn_time: f32,
score: u32,
}
@ -107,7 +107,7 @@ impl State {
time: 0.0,
mode: GameMode::Menu,
obstacles: VecDeque::new(),
obstacleSpawnTime: 0.0,
obstacle_spawn_time: 0.0,
score: 0u32,
}
}
@ -138,12 +138,12 @@ impl State {
fn play(&mut self, ctx: &mut BTerm) {
ctx.cls_bg(BLACK);
self.time += ctx.frame_time_ms;
self.obstacleSpawnTime -= ctx.frame_time_ms;
self.obstacle_spawn_time -= ctx.frame_time_ms;
ctx.print(1, 1, "Press Space to flap!");
ctx.print(1, 2, &format!("Score: {}", self.score));
// ctx.print(1, 3, &format!("Pos: {}, {}", self.player.x, self.player.y));
// ctx.print(1, 4, &format!("Obstables: (Spawn: {}) #{} {:#?}", self.obstacleSpawnTime, self.obstacles.len(), self.obstacles));
// ctx.print(1, 4, &format!("Obstables: (Spawn: {}) #{} {:#?}", self.obstacle_spawn_time, self.obstacles.len(), self.obstacles));
// update
if self.time > FRAME_DURATION {
@ -151,9 +151,9 @@ impl State {
self.time %= FRAME_DURATION;
}
if self.obstacleSpawnTime < 0.0 {
if self.obstacle_spawn_time < 0.0 {
let mut random = RandomNumberGenerator::new();
self.obstacleSpawnTime += random.range(400.0, 1200.0) - self.score as f32;
self.obstacle_spawn_time += random.range(400.0, 1200.0) - self.score as f32;
let o = Obstacle::new(self.player.x + SCREEN_WIDTH as i32, self.score);
self.obstacles.push_back(o);
}