]> git.seodisparate.com - LudumDare47_StuckInALoop/commitdiff
A little work on mainscene, cargo fmt
authorStephen Seo <seo.disparate@gmail.com>
Sat, 3 Oct 2020 06:15:03 +0000 (15:15 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Sat, 3 Oct 2020 06:15:03 +0000 (15:15 +0900)
src/game.rs
src/scenes/gamestart.rs
src/scenes/mainscene.rs

index 25aa649f800385b1bd382d6bedb7403efef03565..4d6450965f28c7dd52e4373403536f30099c42bc 100644 (file)
@@ -1,5 +1,5 @@
-use std::rc::Rc;
 use std::cell::RefCell;
+use std::rc::Rc;
 
 use ggez::event::EventHandler;
 use ggez::graphics::{self, Font};
@@ -7,9 +7,9 @@ use ggez::input::keyboard::{KeyCode, KeyMods};
 use ggez::input::mouse::MouseButton;
 use ggez::{Context, GameResult};
 
-use crate::scenes::{gamestart::GameStartScene, mainscene::MainScene};
-use crate::scenes::Scene;
 use crate::player::Player;
+use crate::scenes::Scene;
+use crate::scenes::{gamestart::GameStartScene, mainscene::MainScene};
 
 pub struct Game {
     current_scene: Box<dyn Scene>,
@@ -24,7 +24,12 @@ pub enum GameState {
 }
 
 impl GameState {
-    fn get_scene(&self, ctx: &mut Context, font: Font, player: Rc<RefCell<Player>>) -> Box<dyn Scene> {
+    fn get_scene(
+        &self,
+        ctx: &mut Context,
+        font: Font,
+        player: Rc<RefCell<Player>>,
+    ) -> Box<dyn Scene> {
         match self {
             GameState::GameStart => GameStartScene::new_boxed(ctx, font, player),
             GameState::MainState => MainScene::new_boxed(ctx, font, player),
index 31434c0003d6cd8e9acc61e0f8638596d342393e..0d875964b3643eb8a70bc89db34d566b60b6d851 100644 (file)
@@ -1,10 +1,12 @@
-use std::rc::Rc;
 use std::cell::RefCell;
+use std::rc::Rc;
 
 use ggez::event::EventHandler;
-use ggez::{Context, GameResult};
-use ggez::graphics::{self, Color, DrawParam, DrawMode, FillOptions, Font, Scale, Text, TextFragment, Mesh, Rect};
+use ggez::graphics::{
+    self, Color, DrawMode, DrawParam, FillOptions, Font, Mesh, Rect, Scale, Text, TextFragment,
+};
 use ggez::input::mouse::MouseButton;
+use ggez::{Context, GameResult};
 
 use super::Scene;
 use crate::player::Player;
@@ -25,7 +27,9 @@ pub struct GameStartScene {
 
 impl GameStartScene {
     pub fn new(_ctx: &mut Context, font: Font, player: Rc<RefCell<Player>>) -> Self {
-        let mut pick_color_text: Text = Text::new(TextFragment::new("Pick your color").color(Color::from_rgb(0xff, 0xff, 0xff)));
+        let mut pick_color_text: Text = Text::new(
+            TextFragment::new("Pick your color").color(Color::from_rgb(0xff, 0xff, 0xff)),
+        );
         pick_color_text.set_font(font, Scale::uniform(32f32));
         Self {
             font,
@@ -54,33 +58,102 @@ impl EventHandler for GameStartScene {
 
     fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
         let text_width = self.pick_color_text.width(ctx) as f32 / 2f32;
-        graphics::draw(ctx, &self.pick_color_text, DrawParam::new().dest([400f32 - text_width, 150f32]))?;
-
-        let pale_mesh = Mesh::new_rectangle(ctx, DrawMode::fill(), Rect::new(0f32, 0f32, 128f32, 128f32), self.color_pale)?;
-        graphics::draw(ctx, &pale_mesh, DrawParam::new().dest([400f32 - 128f32 - 64f32 - 64f32, 200f32]))?;
-
-        let white_mesh = Mesh::new_rectangle(ctx, DrawMode::fill(), Rect::new(0f32, 0f32, 128f32, 128f32), self.color_white)?;
-        graphics::draw(ctx, &white_mesh, DrawParam::new().dest([400f32 - 64f32 - 64f32, 200f32]))?;
-
-        let brown_mesh = Mesh::new_rectangle(ctx, DrawMode::fill(), Rect::new(0f32, 0f32, 128f32, 128f32), self.color_brown)?;
+        graphics::draw(
+            ctx,
+            &self.pick_color_text,
+            DrawParam::new().dest([400f32 - text_width, 150f32]),
+        )?;
+
+        let pale_mesh = Mesh::new_rectangle(
+            ctx,
+            DrawMode::fill(),
+            Rect::new(0f32, 0f32, 128f32, 128f32),
+            self.color_pale,
+        )?;
+        graphics::draw(
+            ctx,
+            &pale_mesh,
+            DrawParam::new().dest([400f32 - 128f32 - 64f32 - 64f32, 200f32]),
+        )?;
+
+        let white_mesh = Mesh::new_rectangle(
+            ctx,
+            DrawMode::fill(),
+            Rect::new(0f32, 0f32, 128f32, 128f32),
+            self.color_white,
+        )?;
+        graphics::draw(
+            ctx,
+            &white_mesh,
+            DrawParam::new().dest([400f32 - 64f32 - 64f32, 200f32]),
+        )?;
+
+        let brown_mesh = Mesh::new_rectangle(
+            ctx,
+            DrawMode::fill(),
+            Rect::new(0f32, 0f32, 128f32, 128f32),
+            self.color_brown,
+        )?;
         graphics::draw(ctx, &brown_mesh, DrawParam::new().dest([400f32, 200f32]))?;
 
-        let black_mesh = Mesh::new_rectangle(ctx, DrawMode::fill(), Rect::new(0f32, 0f32, 128f32, 128f32), self.color_black)?;
-        graphics::draw(ctx, &black_mesh, DrawParam::new().dest([400f32 + 128f32, 200f32]))?;
-
-        let red_mesh = Mesh::new_rectangle(ctx, DrawMode::fill(), Rect::new(0f32, 0f32, 128f32, 128f32), self.color_red)?;
-        graphics::draw(ctx, &red_mesh, DrawParam::new().dest([400f32 - 128f32 - 64f32, 328f32]))?;
-
-        let green_mesh = Mesh::new_rectangle(ctx, DrawMode::fill(), Rect::new(0f32, 0f32, 128f32, 128f32), self.color_green)?;
-        graphics::draw(ctx, &green_mesh, DrawParam::new().dest([400f32 - 64f32, 328f32]))?;
-
-        let blue_mesh = Mesh::new_rectangle(ctx, DrawMode::fill(), Rect::new(0f32, 0f32, 128f32, 128f32), self.color_blue)?;
-        graphics::draw(ctx, &blue_mesh, DrawParam::new().dest([400f32 + 128f32 - 64f32, 328f32]))?;
+        let black_mesh = Mesh::new_rectangle(
+            ctx,
+            DrawMode::fill(),
+            Rect::new(0f32, 0f32, 128f32, 128f32),
+            self.color_black,
+        )?;
+        graphics::draw(
+            ctx,
+            &black_mesh,
+            DrawParam::new().dest([400f32 + 128f32, 200f32]),
+        )?;
+
+        let red_mesh = Mesh::new_rectangle(
+            ctx,
+            DrawMode::fill(),
+            Rect::new(0f32, 0f32, 128f32, 128f32),
+            self.color_red,
+        )?;
+        graphics::draw(
+            ctx,
+            &red_mesh,
+            DrawParam::new().dest([400f32 - 128f32 - 64f32, 328f32]),
+        )?;
+
+        let green_mesh = Mesh::new_rectangle(
+            ctx,
+            DrawMode::fill(),
+            Rect::new(0f32, 0f32, 128f32, 128f32),
+            self.color_green,
+        )?;
+        graphics::draw(
+            ctx,
+            &green_mesh,
+            DrawParam::new().dest([400f32 - 64f32, 328f32]),
+        )?;
+
+        let blue_mesh = Mesh::new_rectangle(
+            ctx,
+            DrawMode::fill(),
+            Rect::new(0f32, 0f32, 128f32, 128f32),
+            self.color_blue,
+        )?;
+        graphics::draw(
+            ctx,
+            &blue_mesh,
+            DrawParam::new().dest([400f32 + 128f32 - 64f32, 328f32]),
+        )?;
 
         Ok(())
     }
 
-    fn mouse_button_down_event(&mut self, _ctx: &mut Context, _button: MouseButton, x: f32, y: f32) {
+    fn mouse_button_down_event(
+        &mut self,
+        _ctx: &mut Context,
+        _button: MouseButton,
+        x: f32,
+        y: f32,
+    ) {
         if y > 200f32 && y < 200f32 + 128f32 {
             if x > 400f32 - 256f32 && x < 400f32 - 128f32 {
                 self.player.borrow_mut().color = self.color_pale;
index 2d8689197ef4cb080398dc8632656e20c9294faf..689f1d1dd2f3e70f87fcdf9a07c12a76e91164ea 100644 (file)
@@ -1,18 +1,21 @@
-use std::rc::Rc;
 use std::cell::RefCell;
+use std::rc::Rc;
 
-use ggez::{Context, GameResult};
-use ggez::graphics::{self, Font};
 use ggez::event::EventHandler;
+use ggez::graphics::{self, Font, Text};
 use ggez::input::mouse::MouseButton;
+use ggez::{Context, GameResult};
 
-use crate::player::Player;
 use super::Scene;
+use crate::player::Player;
 
 pub struct MainScene {
     font: Font,
     player: Rc<RefCell<Player>>,
     finished: bool,
+    current_text: Text,
+    final_text: String,
+    text_idx: usize,
 }
 
 impl MainScene {
@@ -21,6 +24,9 @@ impl MainScene {
             font,
             player,
             finished: false,
+            current_text: Text::new("".to_owned()),
+            final_text: String::new(),
+            text_idx: 0usize,
         }
     }
 
@@ -39,7 +45,13 @@ impl EventHandler for MainScene {
         Ok(())
     }
 
-    fn mouse_button_down_event(&mut self, _ctx: &mut Context, _button: MouseButton, x: f32, y: f32) {
+    fn mouse_button_down_event(
+        &mut self,
+        _ctx: &mut Context,
+        _button: MouseButton,
+        x: f32,
+        y: f32,
+    ) {
     }
 }