diff options
author | Tom Barrett <tom@tombarrett.xyz> | 2022-02-02 19:08:44 +0100 |
---|---|---|
committer | Tom Barrett <tom@tombarrett.xyz> | 2022-02-02 19:08:44 +0100 |
commit | ceb3eff116f9ddf8dcb71a0a77efb63531f75ab2 (patch) | |
tree | c818ad7241797fa72e0cb802f09c9a1b296e1fb0 /src | |
parent | 8cdbe7352c4846eb339358bcca6083f747e27721 (diff) |
Diffstat (limited to 'src')
-rw-r--r-- | src/animations.rs | 5 | ||||
-rw-r--r-- | src/camera.rs | 8 | ||||
-rw-r--r-- | src/cell.rs | 6 | ||||
-rw-r--r-- | src/dialogbox.rs | 13 | ||||
-rw-r--r-- | src/entity.rs | 8 | ||||
-rw-r--r-- | src/game.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 4 | ||||
-rw-r--r-- | src/map.rs | 8 | ||||
-rw-r--r-- | src/npc.rs | 14 | ||||
-rw-r--r-- | src/player.rs | 6 | ||||
-rw-r--r-- | src/tile.rs | 11 | ||||
-rw-r--r-- | src/world.rs | 7 |
12 files changed, 48 insertions, 44 deletions
diff --git a/src/animations.rs b/src/animations.rs index cbaad41..21e05c7 100644 --- a/src/animations.rs +++ b/src/animations.rs @@ -1,5 +1,4 @@ use ggez::graphics::spritebatch::SpriteBatch; -use ggez::nalgebra::Point2; use rand::Rng; use std::collections::HashMap; use std::time::Instant; @@ -48,7 +47,7 @@ impl Animation { } } - pub fn draw(&self, spritebatch: &mut SpriteBatch, position: Point2<f32>) { + pub fn draw(&self, spritebatch: &mut SpriteBatch, position: glam::Vec2) { self.current.draw(spritebatch, position); } } @@ -101,7 +100,7 @@ impl Animations { self.current.update(); } - pub fn draw(&self, spritebatch: &mut SpriteBatch, position: Point2<f32>) { + pub fn draw(&self, spritebatch: &mut SpriteBatch, position: glam::Vec2) { self.current.draw(spritebatch, position) } } diff --git a/src/camera.rs b/src/camera.rs index bcb8f69..3461df1 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -1,10 +1,10 @@ use ggez::conf::Conf; -use ggez::nalgebra::Point2; +use glam::*; use crate::constants; pub struct Camera { - pub draw: Point2<f32>, + pub draw: glam::Vec2, window_dimensions: (f32, f32), map_dimensions: (f32, f32), } @@ -13,13 +13,13 @@ impl Camera { pub fn new(map_dimensions: (f32, f32)) -> Camera { let conf = Conf::new(); Camera { - draw: Point2::new(0.0, 0.0), + draw: glam::Vec2::new(0.0, 0.0), window_dimensions: (conf.window_mode.width, conf.window_mode.height), map_dimensions, } } - pub fn give_center(&mut self, center: Point2<f32>) { + pub fn give_center(&mut self, center: glam::Vec2) { self.draw.x = ((self.window_dimensions.0 / 2.0) - center.x) - (constants::TILE_WIDTH); self.draw.y = ((self.window_dimensions.1 / 2.0) - center.y) - (constants::TILE_HEIGHT); diff --git a/src/cell.rs b/src/cell.rs index bce744b..db99edd 100644 --- a/src/cell.rs +++ b/src/cell.rs @@ -1,5 +1,5 @@ use ggez::graphics::spritebatch::SpriteBatch; -use ggez::nalgebra::Point2; +use glam; use crate::animations::Animation; use crate::constants; @@ -9,7 +9,7 @@ use crate::tileset::Tileset; #[derive(Debug, Clone)] pub struct Cell { pub id: usize, - pub destination: Point2<f32>, + pub destination: glam::Vec2, animation: Animation, } @@ -31,7 +31,7 @@ impl Cell { let y = (i as f32 / dimensions.1 as f32).floor(); let offset = (constants::TILE_WIDTH / 2.0) * constants::TILE_SCALE; - let destination = Point2::new( + let destination = glam::Vec2::new( (constants::TILE_WIDTH * constants::TILE_SCALE * x) + offset, (constants::TILE_HEIGHT * constants::TILE_SCALE * y) + offset, ); diff --git a/src/dialogbox.rs b/src/dialogbox.rs index 7e140ba..0fe2571 100644 --- a/src/dialogbox.rs +++ b/src/dialogbox.rs @@ -1,9 +1,9 @@ use ggez::conf::Conf; use ggez::graphics::{ - self, DrawMode, DrawParam, Font, Mesh, MeshBuilder, Rect, Scale, Text, TextFragment, + self, DrawMode, DrawParam, Font, Mesh, MeshBuilder, PxScale, Rect, Text, TextFragment, }; -use ggez::nalgebra::Point2; use ggez::{filesystem, Context, GameResult}; +use glam; use serde::{Deserialize, Serialize}; use std::collections::HashMap; @@ -59,6 +59,7 @@ impl DialogBox { ), constants::PURPLE, ) + .unwrap() .build(context) .unwrap(), conf, @@ -76,14 +77,14 @@ impl DialogBox { let text = Text::new( TextFragment::new(dialog.text.as_str()) .font(self.font) - .scale(Scale::uniform(40.0)), + .scale(PxScale::from(40.0)), ); graphics::draw(context, &self.mesh, DrawParam::default())?; graphics::draw( context, &text, - DrawParam::default().dest(Point2::new( + DrawParam::default().dest(glam::vec2( self.conf.window_mode.width * 0.11, 2.6 * self.conf.window_mode.height / 4.0, )), @@ -99,14 +100,14 @@ impl DialogBox { let text = Text::new( TextFragment::new(response.1.as_str()) .font(self.font) - .scale(Scale::uniform(40.0)), + .scale(PxScale::from(40.0)), ); graphics::draw( context, &text, DrawParam::default() - .dest(Point2::new( + .dest(glam::vec2( self.conf.window_mode.width * 0.11, (2.6 + (0.25 * (i + 1) as f32)) * self.conf.window_mode.height / 4.0, )) diff --git a/src/entity.rs b/src/entity.rs index f3ca328..ffe32b5 100644 --- a/src/entity.rs +++ b/src/entity.rs @@ -1,5 +1,5 @@ use ggez::graphics::spritebatch::SpriteBatch; -use ggez::nalgebra::Point2; +use glam; use crate::constants; @@ -10,14 +10,14 @@ pub trait Operable { #[derive(Debug, Clone)] pub struct Entity { - pub position: Point2<f32>, - pub spawn: Point2<f32>, + pub position: glam::Vec2, + pub spawn: glam::Vec2, pub action: Action, map_dimensions: (f32, f32), } impl Entity { - pub fn new(spawn: Point2<f32>, map_dimensions: (f32, f32)) -> Entity { + pub fn new(spawn: glam::Vec2, map_dimensions: (f32, f32)) -> Entity { Entity { spawn, action: Action::IdleLeft, diff --git a/src/game.rs b/src/game.rs index ebf5ffa..51cc5db 100644 --- a/src/game.rs +++ b/src/game.rs @@ -45,7 +45,7 @@ impl EventHandler for Game { } fn draw(&mut self, context: &mut Context) -> GameResult { - graphics::clear(context, graphics::BLACK); + graphics::clear(context, graphics::Color::BLACK); self.world.draw(&mut self.spritebatch); diff --git a/src/main.rs b/src/main.rs index e2465d9..6ec13db 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ use ggez::{event, ContextBuilder, GameResult}; use pax_romana::game::Game; fn main() -> GameResult { - let (ref mut context, ref mut event_loop) = ContextBuilder::new("pax-romana", "tom barrett") + let (mut context, event_loop) = ContextBuilder::new("pax-romana", "tom barrett") .window_setup( WindowSetup::default() .title("pax_romana") @@ -13,7 +13,7 @@ fn main() -> GameResult { .add_resource_path("./resources") .build()?; - let game = &mut Game::new(context)?; + let game = Game::new(&mut context)?; event::run(context, event_loop, game) } @@ -1,6 +1,6 @@ use ggez::filesystem::File; use ggez::graphics::spritebatch::SpriteBatch; -use ggez::nalgebra::Point2; +use glam; use std::collections::HashMap; use xml::reader::XmlEvent::Characters; @@ -16,7 +16,7 @@ use crate::xmlelements::XMLElements; pub struct Map { dimensions: (usize, usize), layers: Vec<Layer>, - spawns: Vec<(String, Point2<f32>)>, + spawns: Vec<(String, glam::Vec2)>, } impl Operable for Map { @@ -74,7 +74,7 @@ impl Map { fn find_spawn_points( layers: &[Layer], spawn_tiles: HashMap<usize, Tile>, - ) -> Vec<(String, Point2<f32>)> { + ) -> Vec<(String, glam::Vec2)> { let mut spawn_points = Vec::new(); for layer in layers.iter() { @@ -91,7 +91,7 @@ impl Map { spawn_points } - pub fn get_spawn_points(&self, character: Character) -> Vec<Point2<f32>> { + pub fn get_spawn_points(&self, character: Character) -> Vec<glam::Vec2> { self.spawns .clone() .into_iter() @@ -1,6 +1,6 @@ use ggez::graphics::spritebatch::SpriteBatch; -use ggez::nalgebra::{distance, Point2}; use ggez::Context; +use glam::*; use rand::Rng; use std::f32::consts::PI; use std::time::Instant; @@ -57,7 +57,7 @@ impl NPC { character: Character, context: &mut Context, tileset: &Tileset, - spawn: Point2<f32>, + spawn: glam::Vec2, map_dimensions: (f32, f32), ) -> NPC { NPC { @@ -69,10 +69,10 @@ impl NPC { } } - fn move_torwards(&mut self, destination: Point2<f32>) { + fn move_torwards(&mut self, destination: glam::Vec2) { let position = self.entity.position; - if distance(&position, &destination) < constants::INTERACT_DISTANCE { + if glam::f32::Vec2::distance(position, destination) < constants::INTERACT_DISTANCE { self.entity.action = Action::IdleRight; self.behavior = Behavior::Waiting(Instant::now()); } else if (position.x - destination.x).abs() < constants::INTERACT_DISTANCE { @@ -149,11 +149,11 @@ impl NPC { enum Behavior { Talking, Waiting(Instant), - Wandering(Point2<f32>), + Wandering(glam::Vec2), } -pub fn random_nearby_point(origin: Point2<f32>, within_radius: f32) -> Point2<f32> { +pub fn random_nearby_point(origin: glam::Vec2, within_radius: f32) -> glam::Vec2 { let w = within_radius * rand::thread_rng().gen_range(0.0, 1.0); let t = 2.0 * PI * rand::thread_rng().gen_range(0.0, 1.0); - Point2::new(origin.x + w * t.cos(), origin.y + w * t.sin()) + glam::Vec2::new(origin.x + w * t.cos(), origin.y + w * t.sin()) } diff --git a/src/player.rs b/src/player.rs index 7df0922..722c98e 100644 --- a/src/player.rs +++ b/src/player.rs @@ -1,6 +1,6 @@ use ggez::event::KeyCode; use ggez::graphics::spritebatch::SpriteBatch; -use ggez::nalgebra::Point2; +use glam; use crate::animations::Animations; use crate::entity::{Action, Entity, Operable}; @@ -24,14 +24,14 @@ impl Operable for Player { } impl Player { - pub fn new(tileset: &Tileset, spawn: Point2<f32>, map_dimensions: (f32, f32)) -> Player { + pub fn new(tileset: &Tileset, spawn: glam::Vec2, map_dimensions: (f32, f32)) -> Player { Player { entity: Entity::new(spawn, map_dimensions), animations: Animations::new(tileset), } } - pub fn get_position(&self) -> Point2<f32> { + pub fn get_position(&self) -> glam::Vec2 { self.entity.position } diff --git a/src/tile.rs b/src/tile.rs index d6f5c0e..246308b 100644 --- a/src/tile.rs +++ b/src/tile.rs @@ -1,5 +1,5 @@ use ggez::graphics::{spritebatch::SpriteBatch, DrawParam, Rect}; -use ggez::nalgebra::{Point2, Vector2}; +use glam; use std::f32::consts::PI; use xml::reader::XmlEvent; @@ -17,7 +17,7 @@ impl Tile { Tile { source, properties } } - pub fn draw(&self, spritebatch: &mut SpriteBatch, position: Point2<f32>) { + pub fn draw(&self, spritebatch: &mut SpriteBatch, position: glam::Vec2) { let draw = match self.properties.visible { Some(draw) => draw, None => true, @@ -28,9 +28,12 @@ impl Tile { DrawParam::default() .src(self.source) .rotation(self.properties.rotation) - .offset(Point2::new(0.5, 0.5)) + .offset(glam::Vec2::new(0.5, 0.5)) .dest(position) - .scale(Vector2::new(constants::TILE_SCALE, constants::TILE_SCALE)), + .scale(glam::Vec2::new( + constants::TILE_SCALE, + constants::TILE_SCALE, + )), ); } } diff --git a/src/world.rs b/src/world.rs index 4e9a965..877253b 100644 --- a/src/world.rs +++ b/src/world.rs @@ -1,7 +1,7 @@ use ggez::event::KeyCode; use ggez::graphics::spritebatch::SpriteBatch; -use ggez::nalgebra::distance; use ggez::{filesystem, Context}; +use glam; use crate::constants; use crate::dialogbox::DialogTree; @@ -55,7 +55,7 @@ impl World { pub fn player_in_talking_range(&mut self) -> bool { if let Some(npc) = self.npcs.iter_mut().find(|npc| npc.is_talking()) { if constants::INTERACT_DISTANCE - > distance(&self.player.entity.position, &npc.entity.position) + > glam::f32::Vec2::distance(self.player.entity.position, npc.entity.position) { true } else { @@ -70,7 +70,8 @@ impl World { pub fn get_dialogtree(&mut self) -> Option<DialogTree> { let player_position = self.player.entity.position; if let Some(npc) = self.npcs.iter_mut().find(|npc| { - constants::INTERACT_DISTANCE > distance(&player_position, &npc.entity.position) + constants::INTERACT_DISTANCE + > glam::f32::Vec2::distance(player_position, npc.entity.position) }) { Some(npc.get_dialogtree()) } else { |