]> git.seodisparate.com/gitweb - LudumDare47_StuckInALoop/commitdiff
Fix player flip, some impl, added music
authorStephen Seo <seo.disparate@gmail.com>
Sat, 3 Oct 2020 07:22:56 +0000 (16:22 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Sat, 3 Oct 2020 07:22:56 +0000 (16:22 +0900)
resources/music00.ogg [new file with mode: 0644]
src/player.rs
src/scenes/mainscene.rs

diff --git a/resources/music00.ogg b/resources/music00.ogg
new file mode 100644 (file)
index 0000000..7274278
Binary files /dev/null and b/resources/music00.ogg differ
index 755a9c3aab4290f801c7c6107484df1716571cca..e635bdb049e830895e624208eeb0a7dcc239d55d 100644 (file)
@@ -3,7 +3,7 @@ use ggez::graphics::{self, Color, DrawParam, Image, Rect};
 use ggez::timer::delta;
 use ggez::{Context, GameResult};
 
-const WALK_TIME: f32 = 0.4f32;
+const WALK_TIME: f32 = 0.34f32;
 
 pub enum PlayerState {
     Standing,
@@ -16,16 +16,18 @@ pub struct Player {
     pub y: f32,
     state: PlayerState,
     pub color: Color,
+    xflip: bool,
 }
 
 impl Player {
     pub fn new(ctx: &mut Context, color: Color) -> GameResult<Self> {
         Ok(Self {
             sprite: Image::new(ctx, "/player_sprite.png")?,
-            x: 0f32,
-            y: 0f32,
+            x: 300f32,
+            y: 300f32,
             state: PlayerState::Standing,
             color,
+            xflip: false,
         })
     }
 
@@ -36,6 +38,10 @@ impl Player {
             self.state = PlayerState::Walking(true, 0f32);
         }
     }
+
+    pub fn set_xflip(&mut self, xflip: bool) {
+        self.xflip = xflip;
+    }
 }
 
 impl EventHandler for Player {
@@ -57,46 +63,95 @@ impl EventHandler for Player {
     fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
         match &self.state {
             PlayerState::Standing => {
-                graphics::draw(
-                    ctx,
-                    &self.sprite,
-                    DrawParam::new()
-                        .src(Rect::new(0f32, 0f32, 0.3333333333333f32, 1f32))
-                        .dest([self.x, self.y])
-                        .color(self.color),
-                )?;
-            }
-            PlayerState::Walking(left, _) => {
-                if *left {
+                if self.xflip {
                     graphics::draw(
                         ctx,
                         &self.sprite,
                         DrawParam::new()
-                            .src(Rect::new(
-                                0.3333333333333f32,
-                                0f32,
-                                0.3333333333333f32,
-                                1f32,
-                            ))
+                            .src(Rect::new(0f32, 0f32, 0.3333333333333f32, 1f32))
                             .dest([self.x, self.y])
-                            .color(self.color),
+                            .color(self.color)
+                            .scale([-1f32, 1f32])
+                            .offset([1f32, 0f32]),
                     )?;
                 } else {
                     graphics::draw(
                         ctx,
                         &self.sprite,
                         DrawParam::new()
-                            .src(Rect::new(
-                                0.6666666666666f32,
-                                0f32,
-                                0.3333333333333f32,
-                                1f32,
-                            ))
+                            .src(Rect::new(0f32, 0f32, 0.3333333333333f32, 1f32))
                             .dest([self.x, self.y])
                             .color(self.color),
                     )?;
                 }
             }
+            PlayerState::Walking(left, _) => {
+                if *left {
+                    if self.xflip {
+                        graphics::draw(
+                            ctx,
+                            &self.sprite,
+                            DrawParam::new()
+                                .src(Rect::new(
+                                    0.3333333333333f32,
+                                    0f32,
+                                    0.3333333333333f32,
+                                    1f32,
+                                ))
+                                .dest([self.x, self.y])
+                                .color(self.color)
+                                .scale([-1f32, 1f32])
+                                .offset([1f32, 0f32]),
+                        )?;
+                    } else {
+                        graphics::draw(
+                            ctx,
+                            &self.sprite,
+                            DrawParam::new()
+                                .src(Rect::new(
+                                    0.3333333333333f32,
+                                    0f32,
+                                    0.3333333333333f32,
+                                    1f32,
+                                ))
+                                .dest([self.x, self.y])
+                                .color(self.color),
+                        )?;
+                    }
+                } else {
+                    if self.xflip {
+                        graphics::draw(
+                            ctx,
+                            &self.sprite,
+                            DrawParam::new()
+                                .src(Rect::new(
+                                    0.6666666666666f32,
+                                    0f32,
+                                    0.3333333333333f32,
+                                    1f32,
+                                ))
+                                .dest([self.x, self.y])
+                                .color(self.color)
+                                .scale([-1f32, 1f32])
+                                .offset([1f32, 0f32]),
+                        )?;
+                    } else {
+                        graphics::draw(
+                            ctx,
+                            &self.sprite,
+                            DrawParam::new()
+                                .src(Rect::new(
+                                    0.6666666666666f32,
+                                    0f32,
+                                    0.3333333333333f32,
+                                    1f32,
+                                ))
+                                .dest([self.x, self.y])
+                                .color(self.color),
+                        )?;
+                    }
+                }
+            }
         }
         Ok(())
     }
index 689f1d1dd2f3e70f87fcdf9a07c12a76e91164ea..8ed9a7381f418d5204a6dde262eba57b43e3bc60 100644 (file)
@@ -1,8 +1,9 @@
 use std::cell::RefCell;
 use std::rc::Rc;
 
+use ggez::audio::{SoundSource, Source};
 use ggez::event::EventHandler;
-use ggez::graphics::{self, Font, Text};
+use ggez::graphics::{self, DrawParam, Font, Image, Text};
 use ggez::input::mouse::MouseButton;
 use ggez::{Context, GameResult};
 
@@ -16,10 +17,16 @@ pub struct MainScene {
     current_text: Text,
     final_text: String,
     text_idx: usize,
+    music: Source,
+    pod_image: Image,
+    pod_empty_image: Image,
 }
 
 impl MainScene {
-    pub fn new(_ctx: &mut Context, font: Font, player: Rc<RefCell<Player>>) -> Self {
+    pub fn new(ctx: &mut Context, font: Font, player: Rc<RefCell<Player>>) -> Self {
+        let mut music = Source::new(ctx, "/music00.ogg").unwrap();
+        music.set_repeat(true);
+        //        music.play().unwrap();
         Self {
             font,
             player,
@@ -27,6 +34,9 @@ impl MainScene {
             current_text: Text::new("".to_owned()),
             final_text: String::new(),
             text_idx: 0usize,
+            music,
+            pod_image: Image::new(ctx, "/stasis_pod.png").unwrap(),
+            pod_empty_image: Image::new(ctx, "/stasis_pod_empty.png").unwrap(),
         }
     }
 
@@ -36,12 +46,18 @@ impl MainScene {
 }
 
 impl EventHandler for MainScene {
-    fn update(&mut self, _ctx: &mut Context) -> GameResult<()> {
+    fn update(&mut self, ctx: &mut Context) -> GameResult<()> {
+        self.player.borrow_mut().update(ctx)?;
         Ok(())
     }
 
     fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
         self.player.borrow_mut().draw(ctx)?;
+        graphics::draw(
+            ctx,
+            &self.pod_image,
+            DrawParam::new().dest([600f32, 170f32]).rotation(0.7f32),
+        )?;
         Ok(())
     }