From 1dcfbc2db9f906fed1a8d7cec51f928ee1174963 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Mon, 13 Feb 2023 18:53:04 +0900 Subject: [PATCH] More fixes, add agnostic_interface.rs --- src/agnostic_interface.rs | 22 ++++++++++++++++++++++ src/faux_quicksilver.rs | 11 +++++++++++ src/main.rs | 12 +++++++----- 3 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 src/agnostic_interface.rs diff --git a/src/agnostic_interface.rs b/src/agnostic_interface.rs new file mode 100644 index 0000000..99f2e61 --- /dev/null +++ b/src/agnostic_interface.rs @@ -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; + fn get_mouse_pressed(&self) -> Result, String>; + fn clear_window(&self, color: Color) -> Result<(), String>; + fn begin_drawing(&self) -> Result<(), String>; + fn end_drawing(&self) -> Result<(), String>; +} diff --git a/src/faux_quicksilver.rs b/src/faux_quicksilver.rs index b11d4a5..ef17277 100644 --- a/src/faux_quicksilver.rs +++ b/src/faux_quicksilver.rs @@ -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, +} + +impl Window { + pub fn new() -> Self { + Self { + interface: todo!(), + } + } } pub struct Key { diff --git a/src/main.rs b/src/main.rs index b7aec24..40687fe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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)); } }