diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..146ab09
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/assets/hex3.gif b/assets/hex3.gif
new file mode 100644
index 0000000..cef8ba2
Binary files /dev/null and b/assets/hex3.gif differ
diff --git a/assets/units/bob.gif b/assets/units/bob.gif
new file mode 100644
index 0000000..10fdc77
Binary files /dev/null and b/assets/units/bob.gif differ
diff --git a/assets/units/tank.pal b/assets/units/tank.pal
new file mode 100644
index 0000000..78a430e
--- /dev/null
+++ b/assets/units/tank.pal
@@ -0,0 +1 @@
+ŒŠŒüþü¤¢¤”–”DBD¬®¬”’”|~|\Z\œžœ´²´ŒŽŒ¤¦¤
\ No newline at end of file
diff --git a/assets/units/tank.png b/assets/units/tank.png
new file mode 100644
index 0000000..d7220c6
Binary files /dev/null and b/assets/units/tank.png differ
diff --git a/src/main.rs b/src/main.rs
index 190f957..9be6bc8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,16 +1,61 @@
-use skunk2d::{Event, Image, run, WindowState};
+mod unit_kind;
+mod unit;
+
+use std::cell::RefCell;
+use std::rc::Rc;
+use std::time::{Duration, Instant};
+use skunk2d::{Event, HexMap, Image, run, Tileset, Vec2, WindowState};
+use crate::unit::Unit;
+use crate::unit_kind::UnitKind;
struct Game {
+ map: HexMap,
+ unit: Rc>,
+ last_tick: Instant,
+ tick_duration: Duration,
+ current_tick: i32
+}
+fn setup_palette(ws: &mut WindowState) {
+ ws.set_palette(0, 0xc0, 0xf0, 0xd0);
+ ws.set_palette(2, 0x10, 0x30, 0x20);
+ ws.set_palette(1, 0xb0, 0xe0, 0xc0);
+ ws.set_palette(3, 0xa0, 0xd0, 0xb0);
+
+ ws.set_palette(255, 0xff, 0xff, 0xff);
+ ws.set_palette(254, 0x00, 0x00, 0x00);
+ ws.set_palette(253, 0x80, 0x80, 0x80);
+
+}
+
+impl Game {
+ pub fn tick(&mut self, window_state: &mut WindowState) {
+ window_state.log(format!("tick: {}", self.current_tick).as_str());
+
+ self.unit.borrow_mut().pos.y = self.current_tick % self.map.size().y;
+ }
}
impl skunk2d::Game for Game {
fn new(window_state: &mut WindowState) -> Self {
- window_state.scramble_palette();
- Game {}
+ setup_palette(window_state);
+ let tileset = Tileset::load("assets/hex2.gif", Vec2{x: 2, y: 1});
+ let kind = UnitKind::new("bob");
+ Game {
+ map: HexMap::new(Vec2{x: 11, y: 11}, tileset, Vec2{ x: 23, y: 13 }),
+ unit: kind.spawn(Vec2{x: 5, y: 5}),
+ last_tick: Instant::now(),
+ tick_duration: Duration::from_secs(1) / 10,
+ current_tick: 0
+ }
}
fn update(&mut self, window_state: &mut WindowState) {
+ if Instant::now() - self.last_tick >= self.tick_duration {
+ self.tick(window_state);
+ self.last_tick += self.tick_duration;
+ self.current_tick += 1;
+ }
}
fn on_event(&mut self, window_state: &mut WindowState, event: Event) {
@@ -18,6 +63,8 @@ impl skunk2d::Game for Game {
fn draw(&self, target: &mut Image) {
target.clear();
+ target.draw_hexmap(Vec2::zero(), &self.map);
+ self.unit.borrow().draw(target, &self.map);
}
}
diff --git a/src/unit.rs b/src/unit.rs
new file mode 100644
index 0000000..8c4fbb9
--- /dev/null
+++ b/src/unit.rs
@@ -0,0 +1,14 @@
+use std::rc::Rc;
+use skunk2d::{HexMap, Image, Vec2};
+use crate::unit_kind::UnitKind;
+
+pub struct Unit {
+ pub kind: Rc,
+ pub pos: Vec2
+}
+
+impl Unit {
+ pub fn draw(&self, target: &mut Image, map: &HexMap) {
+ target.draw_image( map.coord_to_pixel(self.pos), &self.kind.sprite);
+ }
+}
\ No newline at end of file
diff --git a/src/unit_kind.rs b/src/unit_kind.rs
new file mode 100644
index 0000000..8fc38ec
--- /dev/null
+++ b/src/unit_kind.rs
@@ -0,0 +1,26 @@
+use std::cell::RefCell;
+use std::rc::Rc;
+use skunk2d::{Image, Vec2};
+use crate::unit::Unit;
+
+pub struct UnitKind {
+ pub sprite: Rc,
+ pub name: String
+}
+
+impl UnitKind {
+ pub fn new(name: &str) -> Rc {
+ UnitKind {
+ sprite: Image::load(format!("assets/units/{}.gif", name).as_str()),
+ name: name.into()
+ }.into()
+ }
+
+ pub fn spawn(self: Rc, pos: Vec2) -> Rc> {
+ RefCell::new(Unit {
+ kind: self,
+ pos
+ }).into()
+ }
+}
+