]> git.seodisparate.com/gitweb - LudumDare47_StuckInALoop/commitdiff
More impl of mainscene
authorStephen Seo <seo.disparate@gmail.com>
Sat, 3 Oct 2020 07:50:43 +0000 (16:50 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Sat, 3 Oct 2020 07:50:43 +0000 (16:50 +0900)
Added darkness.png as a way to use a black gradient overlay.

resources/darkness.png [new file with mode: 0644]
src/player.rs
src/scenes/gamestart.rs
src/scenes/mainscene.rs

diff --git a/resources/darkness.png b/resources/darkness.png
new file mode 100644 (file)
index 0000000..1b889b0
Binary files /dev/null and b/resources/darkness.png differ
index e635bdb049e830895e624208eeb0a7dcc239d55d..5cc4ea767e6d1ab6f464d5e3cf7ec335098b3c91 100644 (file)
@@ -1,5 +1,5 @@
 use ggez::event::EventHandler;
-use ggez::graphics::{self, Color, DrawParam, Image, Rect};
+use ggez::graphics::{self, Color, DrawParam, Drawable, Image, Rect};
 use ggez::timer::delta;
 use ggez::{Context, GameResult};
 
@@ -14,6 +14,7 @@ pub struct Player {
     sprite: Image,
     pub x: f32,
     pub y: f32,
+    pub rot: f32,
     state: PlayerState,
     pub color: Color,
     xflip: bool,
@@ -25,6 +26,7 @@ impl Player {
             sprite: Image::new(ctx, "/player_sprite.png")?,
             x: 300f32,
             y: 300f32,
+            rot: 0f32,
             state: PlayerState::Standing,
             color,
             xflip: false,
@@ -42,10 +44,8 @@ impl Player {
     pub fn set_xflip(&mut self, xflip: bool) {
         self.xflip = xflip;
     }
-}
 
-impl EventHandler for Player {
-    fn update(&mut self, ctx: &mut Context) -> GameResult<()> {
+    pub fn update(&mut self, ctx: &mut Context) -> GameResult<()> {
         let dt = delta(ctx);
         match &mut self.state {
             PlayerState::Standing => (),
@@ -60,7 +60,7 @@ impl EventHandler for Player {
         Ok(())
     }
 
-    fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
+    pub fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
         match &self.state {
             PlayerState::Standing => {
                 if self.xflip {
@@ -70,6 +70,7 @@ impl EventHandler for Player {
                         DrawParam::new()
                             .src(Rect::new(0f32, 0f32, 0.3333333333333f32, 1f32))
                             .dest([self.x, self.y])
+                            .rotation(self.rot)
                             .color(self.color)
                             .scale([-1f32, 1f32])
                             .offset([1f32, 0f32]),
@@ -81,6 +82,7 @@ impl EventHandler for Player {
                         DrawParam::new()
                             .src(Rect::new(0f32, 0f32, 0.3333333333333f32, 1f32))
                             .dest([self.x, self.y])
+                            .rotation(self.rot)
                             .color(self.color),
                     )?;
                 }
@@ -99,6 +101,7 @@ impl EventHandler for Player {
                                     1f32,
                                 ))
                                 .dest([self.x, self.y])
+                                .rotation(self.rot)
                                 .color(self.color)
                                 .scale([-1f32, 1f32])
                                 .offset([1f32, 0f32]),
@@ -115,6 +118,7 @@ impl EventHandler for Player {
                                     1f32,
                                 ))
                                 .dest([self.x, self.y])
+                                .rotation(self.rot)
                                 .color(self.color),
                         )?;
                     }
@@ -131,6 +135,7 @@ impl EventHandler for Player {
                                     1f32,
                                 ))
                                 .dest([self.x, self.y])
+                                .rotation(self.rot)
                                 .color(self.color)
                                 .scale([-1f32, 1f32])
                                 .offset([1f32, 0f32]),
@@ -147,6 +152,7 @@ impl EventHandler for Player {
                                     1f32,
                                 ))
                                 .dest([self.x, self.y])
+                                .rotation(self.rot)
                                 .color(self.color),
                         )?;
                     }
index 0d875964b3643eb8a70bc89db34d566b60b6d851..2e5613f2a7b79e14f3d9d4f2032eaf99fa93934f 100644 (file)
@@ -3,7 +3,7 @@ use std::rc::Rc;
 
 use ggez::event::EventHandler;
 use ggez::graphics::{
-    self, Color, DrawMode, DrawParam, FillOptions, Font, Mesh, Rect, Scale, Text, TextFragment,
+    self, Color, DrawMode, DrawParam, Font, Mesh, Rect, Scale, Text, TextFragment,
 };
 use ggez::input::mouse::MouseButton;
 use ggez::{Context, GameResult};
index 8ed9a7381f418d5204a6dde262eba57b43e3bc60..1588823e323ff985c966796c90848f1c9dcc3512 100644 (file)
@@ -3,13 +3,20 @@ use std::rc::Rc;
 
 use ggez::audio::{SoundSource, Source};
 use ggez::event::EventHandler;
-use ggez::graphics::{self, DrawParam, Font, Image, Text};
+use ggez::graphics::{self, Color, DrawMode, DrawParam, Font, Image, Mesh, Rect, Text};
 use ggez::input::mouse::MouseButton;
+use ggez::timer::delta;
 use ggez::{Context, GameResult};
 
 use super::Scene;
 use crate::player::Player;
 
+const DARKNESS_PAN_RATE: f32 = 50f32;
+
+enum State {
+    InPod_InDarkness,
+}
+
 pub struct MainScene {
     font: Font,
     player: Rc<RefCell<Player>>,
@@ -20,6 +27,10 @@ pub struct MainScene {
     music: Source,
     pod_image: Image,
     pod_empty_image: Image,
+    ground_rect: Rect,
+    state: State,
+    darkness_image: Image,
+    darkness_yoffset: f32,
 }
 
 impl MainScene {
@@ -37,6 +48,10 @@ impl MainScene {
             music,
             pod_image: Image::new(ctx, "/stasis_pod.png").unwrap(),
             pod_empty_image: Image::new(ctx, "/stasis_pod_empty.png").unwrap(),
+            ground_rect: Rect::new(0f32, 550f32, 800f32, 50f32),
+            state: State::InPod_InDarkness,
+            darkness_image: Image::new(ctx, "/darkness.png").unwrap(),
+            darkness_yoffset: 0f32,
         }
     }
 
@@ -47,16 +62,45 @@ impl MainScene {
 
 impl EventHandler for MainScene {
     fn update(&mut self, ctx: &mut Context) -> GameResult<()> {
+        match self.state {
+            State::InPod_InDarkness => {
+                let mut player = self.player.borrow_mut();
+                player.x = 520f32;
+                player.y = 350f32;
+                player.rot = 0.78f32;
+                if self.darkness_yoffset > -400f32 {
+                    self.darkness_yoffset -= delta(ctx).as_secs_f32() * DARKNESS_PAN_RATE;
+                }
+            }
+        }
         self.player.borrow_mut().update(ctx)?;
         Ok(())
     }
 
     fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
-        self.player.borrow_mut().draw(ctx)?;
+        match self.state {
+            State::InPod_InDarkness => {
+                graphics::draw(
+                    ctx,
+                    &self.pod_image,
+                    DrawParam::new().dest([600f32, 170f32]).rotation(0.7f32),
+                )?;
+                self.player.borrow_mut().draw(ctx)?;
+            }
+        }
+
+        let ground_mesh = Mesh::new_rectangle(
+            ctx,
+            DrawMode::fill(),
+            self.ground_rect,
+            Color::from_rgb(0x49, 0x49, 0x49),
+        )?;
+        graphics::draw(ctx, &ground_mesh, DrawParam::new())?;
+
         graphics::draw(
             ctx,
-            &self.pod_image,
-            DrawParam::new().dest([600f32, 170f32]).rotation(0.7f32),
+            &self.darkness_image,
+            DrawParam::new().dest([0f32, self.darkness_yoffset]),
         )?;
         Ok(())
     }