]> git.seodisparate.com - LudumDare45_StartWithNothing/commitdiff
More fixes, add agnostic_interface.rs
authorStephen Seo <seo.disparate@gmail.com>
Mon, 13 Feb 2023 09:53:04 +0000 (18:53 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Mon, 13 Feb 2023 09:53:04 +0000 (18:53 +0900)
src/agnostic_interface.rs [new file with mode: 0644]
src/faux_quicksilver.rs
src/main.rs

diff --git a/src/agnostic_interface.rs b/src/agnostic_interface.rs
new file mode 100644 (file)
index 0000000..99f2e61
--- /dev/null
@@ -0,0 +1,22 @@
+use crate::faux_quicksilver::Color;
+
+pub trait ImageInterface {
+    fn draw(&self, x: f32, y: f32) -> Result<(), String>;
+}
+
+pub trait FontInterface {
+    fn draw(&self, s: &str) -> Result<(), String>;
+}
+
+pub trait SoundInterface {
+    fn play(&self, vol: f32) -> Result<(), String>;
+}
+
+pub trait WindowInterface {
+    fn get_dimensions(&self) -> Result<(f32, f32), String>;
+    fn get_key_pressed(&self, key: char) -> Result<bool, String>;
+    fn get_mouse_pressed(&self) -> Result<Option<(f32, f32)>, String>;
+    fn clear_window(&self, color: Color) -> Result<(), String>;
+    fn begin_drawing(&self) -> Result<(), String>;
+    fn end_drawing(&self) -> Result<(), String>;
+}
index b11d4a5a03f1b0834157eb3ace78c3ca75dbb587..ef172772499f69967c5caa960d6ac62e7757066e 100644 (file)
@@ -2,6 +2,8 @@ use std::ops::{Mul, Add, AddAssign, Sub};
 
 use serde::{Deserialize, Serialize};
 
+use crate::agnostic_interface::WindowInterface;
+
 #[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
 pub struct Color {
     pub r: u8,
@@ -230,6 +232,15 @@ pub struct View {
 }
 
 pub struct Window {
+    interface: Box<dyn WindowInterface>,
+}
+
+impl Window {
+    pub fn new() -> Self {
+        Self {
+            interface: todo!(),
+        }
+    }
 }
 
 pub struct Key {
index b7aec2489ceda5a226c2db169a0e4627b5612295..40687fe55ce4ae88e3b1c1e373b7c4044e40606f 100644 (file)
@@ -13,6 +13,7 @@
 use rand::prelude::*;
 use serde::{Deserialize, Serialize};
 
+mod agnostic_interface;
 mod faux_quicksilver;
 use faux_quicksilver::{Color, Image, Rectangle, Circle, Vector, Transform, Window, Sound, Font, FontStyle, Event, Key, View};
 
@@ -1914,9 +1915,9 @@ impl GameState {
                 0xFF,
                 0xFF,
                 0xFF,
-                self.player_particles.opacity,
+                (self.player_particles.opacity * 255.0) as u8,
             )),
-            Transform::translate(-self.player.size.x / 2.0, -self.player.size.y / 2.0)
+            Transform::translate(-self.player.x / 2.0, -self.player.y / 2.0)
                 * Transform::rotate(self.player_r as f32),
             1,
         );
@@ -1948,9 +1949,10 @@ impl GameState {
                 | SaveLoadNotification::Load { text, timer } => {
                     if let Some(i) = text {
                         let mut c = Color::WHITE;
-                        c.a = (*timer / SL_NOTIF_TIME) as f32;
-                        let mut image_rect = i.area();
-                        image_rect.pos = self.camera.pos + Vector::new(20.0, 20.0);
+                        c.a = ((*timer / SL_NOTIF_TIME) as f32 * 255.0) as u8;
+                        let mut image_rect = i.area_rect();
+                        image_rect.x = self.camera.x + 20.0;
+                        image_rect.y = self.camera.y + 20.0;
                         window.draw(&image_rect, Blended(i, c));
                     }
                 }