skunk2d/examples/test.rs

53 lines
1.2 KiB
Rust
Raw Normal View History

2023-07-01 12:44:21 +02:00
use skunk2d::*;
2023-07-01 19:33:50 +02:00
const WIDTH: i32 = 1280 / 2;
const HEIGHT: i32 = 720 / 2;
2023-07-01 12:44:21 +02:00
struct World {
img: Image,
2023-07-01 16:36:51 +02:00
pos: Vec2<i32>,
2023-07-01 12:44:21 +02:00
}
fn main() {
run::<World>(WIDTH, HEIGHT);
}
impl Game for World {
fn new(window_state: &mut WindowState) -> Self {
//window_state.set_palette(0, 0xc0, 0xf0, 0xd0);
window_state.scramble_palette();
Self {
img: Image::load("examples/assets/test.gif"),
2023-07-01 16:36:51 +02:00
pos: Vec2::zero(),
2023-07-01 12:44:21 +02:00
}
}
fn update(&mut self, window_state: &mut WindowState) {
self.pos = window_state.mouse_pos();
}
fn on_event(&mut self, window_state: &mut WindowState, event: Event) {
match event {
Event::MouseClick(MouseButton::Left, _) => {
window_state.scramble_palette();
}
_ => {}
}
}
fn draw(&self, target: &mut Image) {
target.clear();
2023-07-01 16:36:51 +02:00
target.draw_image(Vec2 { x: 200, y: 100 }, &self.img);
2023-07-01 12:44:21 +02:00
target.draw_image(self.pos, &self.img);
2023-07-01 16:36:51 +02:00
target.draw_line(
Vec2 {
x: WIDTH / 2,
y: HEIGHT / 2,
},
self.pos,
10,
);
2023-07-01 12:44:21 +02:00
}
2023-07-01 16:36:51 +02:00
}