This commit is contained in:
dani 2023-07-03 14:52:13 +00:00
parent 1e80472c96
commit 3aac7e87ab
6 changed files with 12 additions and 15 deletions

View File

@ -1,5 +1,4 @@
use crate::{Image, Tileset, Vec2}; use crate::{Image, Tileset, Vec2};
use num::complex::ComplexFloat;
use std::rc::Rc; use std::rc::Rc;
//odd-q vertical layout https://www.redblobgames.com/grids/hexagons //odd-q vertical layout https://www.redblobgames.com/grids/hexagons
@ -49,7 +48,6 @@ impl HexMap {
} }
y -= x % 2; y -= x % 2;
} }
let slice = xrepeat / (tilesize.x / 4);
Vec2 { x, y } Vec2 { x, y }
} }

View File

@ -1,7 +1,6 @@
use crate::vec2::Vec2; use crate::vec2::Vec2;
use crate::{HexMap, Rect, Tileset}; use crate::{HexMap, Rect, Tileset};
use std::fs; use std::fs;
use std::fs::File;
use std::rc::Rc; use std::rc::Rc;
//todo: make dynamically different bitdepths //todo: make dynamically different bitdepths
@ -57,9 +56,7 @@ impl Image {
pub fn draw_hexmap(&mut self, pos: Vec2<i32>, hexmap: &HexMap) { pub fn draw_hexmap(&mut self, pos: Vec2<i32>, hexmap: &HexMap) {
for i in hexmap.size().to_rect().iter() { for i in hexmap.size().to_rect().iter() {
if i.x % 1 == 0 { hexmap.draw_tile_to_image(self, i, pos);
hexmap.draw_tile_to_image(self, i, pos);
}
} }
} }
@ -117,13 +114,14 @@ impl Image {
pub fn draw_string(&mut self, pos: Vec2<i32>, str: &str, font: &Tileset) { pub fn draw_string(&mut self, pos: Vec2<i32>, str: &str, font: &Tileset) {
assert!(str.is_ascii()); assert!(str.is_ascii());
let array = str.as_bytes(); let array = str.as_bytes();
for i in 0..array.len() { //for i in 0..array.len()
for (i, idx) in array.iter().enumerate() {
self.draw_image( self.draw_image(
Vec2 { Vec2 {
x: pos.x + font.tile_size().x * i as i32, x: pos.x + font.tile_size().x * i as i32,
y: pos.y, y: pos.y,
}, },
font.get(array[i] as i32), font.get(*idx as i32),
); );
} }
} }

View File

@ -6,7 +6,6 @@ mod tileset;
mod vec2; mod vec2;
mod window; mod window;
pub use console::*;
pub use hexmap::*; pub use hexmap::*;
pub use image::*; pub use image::*;
pub use rect::*; pub use rect::*;

View File

@ -47,6 +47,10 @@ impl Tileset {
&self.images[idx as usize] &self.images[idx as usize]
} }
pub fn count(&self) -> i32 {
self.count
}
pub fn tile_size(&self) -> Vec2<i32> { pub fn tile_size(&self) -> Vec2<i32> {
self.size self.size
} }

View File

@ -1,9 +1,7 @@
use crate::Rect; use crate::Rect;
use num::{Num, ToPrimitive}; use num::{Num, ToPrimitive};
use std::cmp::Ordering; use std::cmp::Ordering;
use std::cmp::Ordering::{Greater, Less}; use std::ops::{Add, AddAssign, Sub, SubAssign};
use std::ops::{Add, AddAssign, Range, Sub, SubAssign};
use Ordering::Equal;
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct Vec2<T: Num + Copy + ToPrimitive + PartialOrd> { pub struct Vec2<T: Num + Copy + ToPrimitive + PartialOrd> {

View File

@ -117,9 +117,9 @@ pub fn run<T: Game + 'static>(width: i32, height: i32) {
let mut off_y = 0usize; let mut off_y = 0usize;
event_loop.run_return(move |event, _, control_flow| { event_loop.run_return(move |event, _, control_flow| {
let mut scale = &mut scale; let scale = &mut scale;
let mut off_x = &mut off_x; let off_x = &mut off_x;
let mut off_y = &mut off_y; let off_y = &mut off_y;
if Instant::now() - last_second > Duration::from_secs(1) { if Instant::now() - last_second > Duration::from_secs(1) {
println!("fps: {}", frames_since_last_second); println!("fps: {}", frames_since_last_second);
frames_since_last_second = 0; frames_since_last_second = 0;