Added number font and points
[bug-basher.git] / src / main.rs
index 960197f..ff8b64f 100644 (file)
@@ -15,7 +15,8 @@ mod entities;
 use entities::bug::Bug;
 
 struct BugBasherGame {
-    bugs: Vec<Bug>
+    bugs: Vec<Bug>,
+    points: i64
 }
 
 impl App<AssetId> for BugBasherGame {
@@ -44,8 +45,33 @@ impl App<AssetId> for BugBasherGame {
     }
 
     fn render(&mut self, renderer: &mut Renderer<AssetId>) {
+        let (app_width, app_height) = (renderer.app_width(), renderer.app_height());
         renderer.clear((255,255,255));
         {
+            let mut renderer = renderer.tiled_mode(app_width / 2. - 50., -app_height / 2. + 50.);
+            let spacing = 25.;
+            let point_str = format!("{}", self.points);
+            for (i, c) in point_str.chars().enumerate() {
+                let affine = Affine::translate(i as f64 * spacing, 0.);
+                let tile = match c {
+                    '-' => TileId::NumberFontR0C0,
+                    '0' => TileId::NumberFontR0C1,
+                    '1' => TileId::NumberFontR0C2,
+                    '2' => TileId::NumberFontR0C3,
+                    '3' => TileId::NumberFontR0C4,
+                    '4' => TileId::NumberFontR0C5,
+                    '5' => TileId::NumberFontR0C6,
+                    '6' => TileId::NumberFontR0C7,
+                    '7' => TileId::NumberFontR0C8,
+                    '8' => TileId::NumberFontR0C9,
+                    '9' => TileId::NumberFontR0C10,
+                    _ => TileId::NumberFontR0C0,
+                };
+                renderer.draw(&affine, tile);
+            };
+            
+        }
+        {
             let mut renderer = renderer.sprite_mode();
             for bug in &self.bugs {
                 renderer.draw(
@@ -72,6 +98,7 @@ fn main() {
             Bug::new(0., 1100., 0.),
             Bug::new(0., -1500., 0.3),
             Bug::new(300., -1200., 1.5),
-        )
+        ),
+        points: 0
     });
 }