This commit is contained in:
dani 2023-07-10 14:36:49 +00:00
parent ecc5209772
commit 588797c4b7
5 changed files with 5 additions and 33 deletions

View File

@ -1,14 +1,11 @@
use glam::IVec2; use glam::IVec2;
use rand::Rng; use rand::Rng;
use skunk2d::*; use skunk2d::*;
use std::rc::Rc;
const WIDTH: i32 = 1920 / 3; const WIDTH: i32 = 1920 / 3;
const HEIGHT: i32 = 1080 / 3; const HEIGHT: i32 = 1080 / 3;
struct World { struct World {
img: Rc<Image>,
font: Rc<Tileset>,
pos: IVec2, pos: IVec2,
map: HexMap, map: HexMap,
} }
@ -23,11 +20,6 @@ impl Game for World {
window_state.set_palette(0, 0xc0, 0xf0, 0xd0); window_state.set_palette(0, 0xc0, 0xf0, 0xd0);
window_state.scramble_palette(); window_state.scramble_palette();
Self { Self {
img: Image::load_data(include_bytes!("assets/test.gif")),
font: Tileset::load_data(
include_bytes!("assets/ega-8x14.gif"),
IVec2 { x: 16, y: 16 },
),
pos: IVec2::ZERO, pos: IVec2::ZERO,
map: HexMap::new( map: HexMap::new(
IVec2 { x: 27, y: 13 }, IVec2 { x: 27, y: 13 },
@ -59,18 +51,5 @@ impl Game for World {
fn draw(&self, target: &mut Image) { fn draw(&self, target: &mut Image) {
target.clear(); target.clear();
target.draw_hexmap(IVec2 { x: 0, y: 0 }, &self.map); target.draw_hexmap(IVec2 { x: 0, y: 0 }, &self.map);
/*target.draw_image(Vec2 { x: 200, y: 100 }, &self.img);
target.draw_image(self.pos, self.font.get(68));
target.draw_line(
Vec2 {
x: WIDTH / 2,
y: HEIGHT / 2,
},
self.pos,
10,
);
*/
} }
} }

View File

@ -40,9 +40,9 @@ impl HexMap {
(match dir { (match dir {
Direction::North => IVec2 { x: 0, y: -1 }, Direction::North => IVec2 { x: 0, y: -1 },
Direction::NorthEast => IVec2 { x: 1, y: -1 + yoff }, Direction::NorthEast => IVec2 { x: 1, y: -1 + yoff },
Direction::SouthEast => IVec2 { x: 1, y: 0 + yoff }, Direction::SouthEast => IVec2 { x: 1, y: yoff },
Direction::South => IVec2 { x: 0, y: 1 }, Direction::South => IVec2 { x: 0, y: 1 },
Direction::SouthWest => IVec2 { x: -1, y: 0 + yoff }, Direction::SouthWest => IVec2 { x: -1, y: yoff },
Direction::NorthWest => IVec2 { Direction::NorthWest => IVec2 {
x: -1, x: -1,
y: -1 + yoff, y: -1 + yoff,

View File

@ -1,6 +1,5 @@
use crate::vec_util::{IVec2Helper, IVec2Iter}; use crate::vec_util::{IVec2Helper, IVec2Iter};
use glam::IVec2; use glam::IVec2;
use num::{Num, ToPrimitive};
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct IRect { pub struct IRect {

View File

@ -41,9 +41,9 @@ impl Iterator for IVec2Iter {
type Item = IVec2; type Item = IVec2;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
self.current.x = self.current.x + 1; self.current.x += 1;
if self.current.x >= self.end.x { if self.current.x >= self.end.x {
self.current.y = self.current.y + 1; self.current.y += 1;
self.current.x = self.start.x; self.current.x = self.start.x;
if self.current.y >= self.end.y { if self.current.y >= self.end.y {
return None; return None;

View File

@ -3,7 +3,6 @@ use crate::image::Image;
use crate::Tileset; use crate::Tileset;
use glam::IVec2; use glam::IVec2;
use rand::Rng; use rand::Rng;
use rayon::prelude::*;
use std::cmp::{max, min}; use std::cmp::{max, min};
use std::num::NonZeroU32; use std::num::NonZeroU32;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
@ -172,9 +171,7 @@ pub fn run<T: Game + 'static>(width: i32, height: i32, target_fps: u32) {
WinitMouseButton::Right => MouseButton::Right, WinitMouseButton::Right => MouseButton::Right,
WinitMouseButton::Middle => MouseButton::Middle, WinitMouseButton::Middle => MouseButton::Middle,
//todo: handle other mousebuttons //todo: handle other mousebuttons
WinitMouseButton::Other(b) => match b { WinitMouseButton::Other(_) => MouseButton::Back,
_ => MouseButton::Back,
},
}; };
match state { match state {
ElementState::Pressed => { ElementState::Pressed => {
@ -228,14 +225,11 @@ pub fn run<T: Game + 'static>(width: i32, height: i32, target_fps: u32) {
{ {
let width = width as usize; let width = width as usize;
let height = height as usize;
let window_width = size.width as usize; let window_width = size.width as usize;
let window_height = size.height as usize;
let scale = *scale; let scale = *scale;
let chunk_size = scale * window_width; let chunk_size = scale * window_width;
let screen_data = screen.data(); let screen_data = screen.data();
buf.chunks_exact_mut(chunk_size) buf.chunks_exact_mut(chunk_size)
.into_iter()
.enumerate() .enumerate()
.for_each(|(y, chunk)| { .for_each(|(y, chunk)| {
for x in 0..width { for x in 0..width {