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};
sprite: Image,
pub x: f32,
pub y: f32,
+ pub rot: f32,
state: PlayerState,
pub color: Color,
xflip: bool,
sprite: Image::new(ctx, "/player_sprite.png")?,
x: 300f32,
y: 300f32,
+ rot: 0f32,
state: PlayerState::Standing,
color,
xflip: false,
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 => (),
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 {
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]),
DrawParam::new()
.src(Rect::new(0f32, 0f32, 0.3333333333333f32, 1f32))
.dest([self.x, self.y])
+ .rotation(self.rot)
.color(self.color),
)?;
}
1f32,
))
.dest([self.x, self.y])
+ .rotation(self.rot)
.color(self.color)
.scale([-1f32, 1f32])
.offset([1f32, 0f32]),
1f32,
))
.dest([self.x, self.y])
+ .rotation(self.rot)
.color(self.color),
)?;
}
1f32,
))
.dest([self.x, self.y])
+ .rotation(self.rot)
.color(self.color)
.scale([-1f32, 1f32])
.offset([1f32, 0f32]),
1f32,
))
.dest([self.x, self.y])
+ .rotation(self.rot)
.color(self.color),
)?;
}
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};
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>>,
music: Source,
pod_image: Image,
pod_empty_image: Image,
+ ground_rect: Rect,
+ state: State,
+ darkness_image: Image,
+ darkness_yoffset: f32,
}
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,
}
}
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(())
}