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 rand::Rng;
use skunk2d::*;
use std::rc::Rc;
const WIDTH: i32 = 1920 / 3;
const HEIGHT: i32 = 1080 / 3;
struct World {
img: Rc<Image>,
font: Rc<Tileset>,
pos: IVec2,
map: HexMap,
}
@ -23,11 +20,6 @@ impl Game for World {
window_state.set_palette(0, 0xc0, 0xf0, 0xd0);
window_state.scramble_palette();
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,
map: HexMap::new(
IVec2 { x: 27, y: 13 },
@ -59,18 +51,5 @@ impl Game for World {
fn draw(&self, target: &mut Image) {
target.clear();
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 {
Direction::North => IVec2 { x: 0, y: -1 },
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::SouthWest => IVec2 { x: -1, y: 0 + yoff },
Direction::SouthWest => IVec2 { x: -1, y: yoff },
Direction::NorthWest => IVec2 {
x: -1,
y: -1 + yoff,

View File

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

View File

@ -41,9 +41,9 @@ impl Iterator for IVec2Iter {
type Item = IVec2;
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 {
self.current.y = self.current.y + 1;
self.current.y += 1;
self.current.x = self.start.x;
if self.current.y >= self.end.y {
return None;

View File

@ -3,7 +3,6 @@ use crate::image::Image;
use crate::Tileset;
use glam::IVec2;
use rand::Rng;
use rayon::prelude::*;
use std::cmp::{max, min};
use std::num::NonZeroU32;
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::Middle => MouseButton::Middle,
//todo: handle other mousebuttons
WinitMouseButton::Other(b) => match b {
_ => MouseButton::Back,
},
WinitMouseButton::Other(_) => MouseButton::Back,
};
match state {
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 height = height as usize;
let window_width = size.width as usize;
let window_height = size.height as usize;
let scale = *scale;
let chunk_size = scale * window_width;
let screen_data = screen.data();
buf.chunks_exact_mut(chunk_size)
.into_iter()
.enumerate()
.for_each(|(y, chunk)| {
for x in 0..width {