From: Stephen Seo Date: Sat, 3 Oct 2020 07:50:43 +0000 (+0900) Subject: More impl of mainscene X-Git-Url: https://git.seodisparate.com/tbm-edit-custom-editing.jpg?a=commitdiff_plain;h=a46f709d1b032d483c73be3bf5c18d26e26a2ebd;p=LudumDare47_StuckInALoop More impl of mainscene Added darkness.png as a way to use a black gradient overlay. --- diff --git a/resources/darkness.png b/resources/darkness.png new file mode 100644 index 0000000..1b889b0 Binary files /dev/null and b/resources/darkness.png differ diff --git a/src/player.rs b/src/player.rs index e635bdb..5cc4ea7 100644 --- a/src/player.rs +++ b/src/player.rs @@ -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), )?; } diff --git a/src/scenes/gamestart.rs b/src/scenes/gamestart.rs index 0d87596..2e5613f 100644 --- a/src/scenes/gamestart.rs +++ b/src/scenes/gamestart.rs @@ -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}; diff --git a/src/scenes/mainscene.rs b/src/scenes/mainscene.rs index 8ed9a73..1588823 100644 --- a/src/scenes/mainscene.rs +++ b/src/scenes/mainscene.rs @@ -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>, @@ -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(()) }