Added game over popup
authorJustin Worthe <justin@worthe-it.co.za>
Sun, 15 Apr 2018 10:58:16 +0000 (12:58 +0200)
committerJustin Worthe <justin@worthe-it.co.za>
Sun, 15 Apr 2018 10:58:16 +0000 (12:58 +0200)
src/entities/bug.rs
src/main.rs
src_assets/sprites/Gameover.png [new file with mode: 0644]
src_assets/sprites/Gameover.svg [new file with mode: 0644]
src_assets/tiles/NumberFont_t30.png [deleted file]
src_assets/tiles/NumberFont_t60.png [new file with mode: 0644]
src_assets/tiles/NumberFont_t60.svg [moved from src_assets/tiles/NumberFont_t30.svg with 93% similarity]

index 482e5c4..913253c 100644 (file)
@@ -8,7 +8,7 @@ pub struct Bug {
     pub alive: bool
 }
 
-const SPEED: f64 = 75.;
+const SPEED: f64 = 175.;
 
 impl Bug {
     pub fn new(x: f64, y: f64, facing: f64) -> Bug {
index 939c414..5547479 100644 (file)
@@ -96,8 +96,8 @@ impl App<AssetId> for BugBasherGame {
         {
             let points_str = format!("{}", self.points);
             let lives_str = format!("{}", self.lives);
-            BugBasherGame::print_string(renderer, &points_str, - app_width / 2. + 50., app_height / 2. - 50.);
-            BugBasherGame::print_string(renderer, &lives_str, app_width / 2. - 50. - lives_str.len() as f64 * 25., app_height / 2. - 50.);
+            BugBasherGame::print_string(renderer, &points_str, Alignment::Left, - app_width / 2. + 50., app_height / 2. - 50.);
+            BugBasherGame::print_string(renderer, &lives_str, Alignment::Right, app_width / 2. - 50., app_height / 2. - 50.);
         }
         {
             let mut renderer = renderer.sprite_mode();
@@ -112,9 +112,29 @@ impl App<AssetId> for BugBasherGame {
                 );
             }
         }
+        
+        if self.game_over {
+            {
+                let mut renderer = renderer.sprite_mode();
+                renderer.draw(
+                    &Affine::translate(0.,0.),
+                    SpriteId::Gameover
+                );
+            }
+            {
+                let points_str = format!("{}", self.points);
+                BugBasherGame::print_string(renderer, &points_str, Alignment::Center, 0., -25.);
+            }
+        }
     }
 }
 
+enum Alignment {
+    Left,
+    Right,
+    Center
+}
+
 impl BugBasherGame {
     fn new() -> BugBasherGame {
         let mut game = BugBasherGame {
@@ -137,11 +157,18 @@ impl BugBasherGame {
         self.game_over = false;
     }
 
-    fn print_string(renderer: &mut Renderer<AssetId>, string: &str, x: f64, y: f64) {
-        let mut renderer = renderer.tiled_mode(-x, -y);
-        let spacing = 25.;
+    fn print_string(renderer: &mut Renderer<AssetId>, string: &str, alignment: Alignment, x: f64, y: f64) {
+        let letter_spacing = 25.;
+        let left = match alignment {
+            Alignment::Left => x,
+            Alignment::Right => x - string.len() as f64 * letter_spacing,
+            Alignment::Center => x - string.len() as f64 * letter_spacing / 2.
+        };
+        
+        let mut renderer = renderer.tiled_mode(-left, -y);
+
         for (i, c) in string.chars().enumerate() {
-            let affine = Affine::translate(i as f64 * spacing, 0.);
+            let affine = Affine::translate(i as f64 * letter_spacing, 0.);
             let tile = match c {
                 '-' => TileId::NumberFontR0C0,
                 '0' => TileId::NumberFontR0C1,
diff --git a/src_assets/sprites/Gameover.png b/src_assets/sprites/Gameover.png
new file mode 100644 (file)
index 0000000..794c4be
Binary files /dev/null and b/src_assets/sprites/Gameover.png differ
diff --git a/src_assets/sprites/Gameover.svg b/src_assets/sprites/Gameover.svg
new file mode 100644 (file)
index 0000000..9845b4e
--- /dev/null
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   width="1000"
+   height="400"
+   viewBox="0 0 264.58333 105.83333"
+   version="1.1"
+   id="svg8"
+   inkscape:version="0.92.2 2405546, 2018-03-11"
+   sodipodi:docname="GameOver.svg"
+   inkscape:export-filename="/home/justin/proj/bug_basher/src_assets/sprites/GameOver.png"
+   inkscape:export-xdpi="96"
+   inkscape:export-ydpi="96">
+  <defs
+     id="defs2" />
+  <sodipodi:namedview
+     id="base"
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1.0"
+     inkscape:pageopacity="0.0"
+     inkscape:pageshadow="2"
+     inkscape:zoom="0.7"
+     inkscape:cx="567.14762"
+     inkscape:cy="305.59287"
+     inkscape:document-units="px"
+     inkscape:current-layer="layer1"
+     showgrid="false"
+     units="px"
+     inkscape:window-width="1916"
+     inkscape:window-height="1055"
+     inkscape:window-x="0"
+     inkscape:window-y="21"
+     inkscape:window-maximized="0" />
+  <metadata
+     id="metadata5">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+        <dc:title></dc:title>
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <g
+     inkscape:label="Layer 1"
+     inkscape:groupmode="layer"
+     id="layer1"
+     transform="translate(0,-191.16666)">
+    <rect
+       style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:1.58749998;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+       id="rect1406"
+       width="261.9375"
+       height="103.1875"
+       x="1.3229166"
+       y="192.48958"
+       ry="4.5357256" />
+    <text
+       xml:space="preserve"
+       style="font-style:normal;font-weight:normal;font-size:10.58333302px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
+       x="132.31441"
+       y="215.1404"
+       id="text1377"><tspan
+         sodipodi:role="line"
+         id="tspan1375"
+         x="132.31441"
+         y="215.1404"
+         style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:15.875px;font-family:Hack;-inkscape-font-specification:Hack;text-align:center;text-anchor:middle;stroke-width:0.26458332">Game over!</tspan><tspan
+         sodipodi:role="line"
+         x="132.31441"
+         y="234.98415"
+         style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:15.875px;font-family:Hack;-inkscape-font-specification:Hack;text-align:center;text-anchor:middle;stroke-width:0.26458332"
+         id="tspan1383">Your final score:</tspan><tspan
+         sodipodi:role="line"
+         x="132.31441"
+         y="250.14601"
+         style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:15.875px;font-family:Hack;-inkscape-font-specification:Hack;text-align:center;text-anchor:middle;stroke-width:0.26458332"
+         id="tspan1385" /><tspan
+         sodipodi:role="line"
+         x="132.31441"
+         y="263.37518"
+         style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:15.875px;font-family:Hack;-inkscape-font-specification:Hack;text-align:center;text-anchor:middle;stroke-width:0.26458332"
+         id="tspan1379" /><tspan
+         sodipodi:role="line"
+         x="132.31441"
+         y="281.28622"
+         style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:15.875px;font-family:Hack;-inkscape-font-specification:Hack;text-align:center;text-anchor:middle;stroke-width:0.26458332"
+         id="tspan1381">Press enter to try again</tspan></text>
+  </g>
+</svg>
diff --git a/src_assets/tiles/NumberFont_t30.png b/src_assets/tiles/NumberFont_t30.png
deleted file mode 100644 (file)
index 429b770..0000000
Binary files a/src_assets/tiles/NumberFont_t30.png and /dev/null differ
diff --git a/src_assets/tiles/NumberFont_t60.png b/src_assets/tiles/NumberFont_t60.png
new file mode 100644 (file)
index 0000000..12e0b26
Binary files /dev/null and b/src_assets/tiles/NumberFont_t60.png differ
similarity index 93%
rename from src_assets/tiles/NumberFont_t30.svg
rename to src_assets/tiles/NumberFont_t60.svg
index 8c89b70..cc27fda 100644 (file)
@@ -16,9 +16,9 @@
    id="svg5356"
    inkscape:version="0.92.2 2405546, 2018-03-11"
    sodipodi:docname="NumberFont_t30.svg"
-   inkscape:export-filename="/home/justin/proj/bug_basher/src_assets/tiles/NumberFont_t30.png"
-   inkscape:export-xdpi="96"
-   inkscape:export-ydpi="96">
+   inkscape:export-filename="/home/justin/proj/bug_basher/src_assets/tiles/NumberFont_t60.png"
+   inkscape:export-xdpi="192"
+   inkscape:export-ydpi="192">
   <defs
      id="defs5350" />
   <sodipodi:namedview
@@ -66,7 +66,7 @@
         <dc:format>image/svg+xml</dc:format>
         <dc:type
            rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
-        <dc:title></dc:title>
+        <dc:title />
       </cc:Work>
     </rdf:RDF>
   </metadata>
@@ -85,7 +85,7 @@
          id="tspan5905"
          x="-0.51676428"
          y="296.85013"
-         style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:Hack;-inkscape-font-specification:Hack;letter-spacing:1.57691667px;stroke-width:0.26458332"
+         style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:Hack;-inkscape-font-specification:Hack;letter-spacing:1.57691669px;stroke-width:0.26458332"
          dx="1.3">-0123456789</tspan></text>
   </g>
 </svg>