kurenai

A 2d game engine for WebAssembly. This is a project in development. It works now, but it can dramatically change.

sample

```rust use crate::{ canvas::Canvas, gameloop::GameLoop, gamestate::GameState, image::{imageid::ImageId, imagerepository::ImageRepository, Image}, key_event::{KeyEvent, KeyboardEvent}, point::{Dot, Point}, sprite::Sprite, }; use std::{marker::PhantomData, rc::Rc};

// TestGameState struct TestGameState { data1: GameObject, data2: GameObject, }

impl GameState> for TestGameState { fn keyevent(&mut self, keyevent: &KeyboardEvent) { if keyevent.enter() { // Update data } } fn update(&mut self) { // Update data } fn draw(&self, imagerepository: &ImageRepository>, canvas: &Canvas) { self.data1 .draw(imagerepository, canvas, GamePoint::new(0, 0)) .unwrap(); self.data2 .draw(imagerepository, canvas, GamePoint::new(32, 32)) .unwrap(); } }

impl TestGameState { fn new() -> Self { Self { data1: GameObject::new(ImageId(0), GamePoint::new(32, 32)), data2: GameObject::new(ImageId(1), GamePoint::new(32, 32)), } } }

// GameObject struct GameObject { image_id: ImageId, size: GamePoint, }

impl Sprite> for GameObject { fn imageid(&self) -> &ImageId { &self.imageid }

fn size(&self) -> &GamePoint<Dot> {
    &self.size
}

}

impl GameObject { fn new(imageid: ImageId, size: GamePoint) -> Self { Self { imageid, size } } }

// GamePoint

[derive(Clone, Copy, Debug, Eq, PartialEq)]

struct GamePoint { unit: PhantomData, x: i64, y: i64, }

impl Point for GamePoint { fn new(x: i64, y: i64) -> Self { Self { unit: PhantomData::, x, y, } }

fn x(&self) -> &i64 {
    &self.x
}

fn y(&self) -> &i64 {
    &self.y
}

}

[test]

[should_panic]

fn main() { let testgamestate = TestGameState::new(); let canvas = Canvas::new("main-canvas", GamePoint::new(480, 480), "game-container");

// image_repository factory
let image_repository = {
    let new_html_image_element_rc =
        Rc::new(Image::<GamePoint<Dot>>::create_new_html_image_element(&[], "gif").unwrap());
    let image_repository = ImageRepository::new();
    image_repository
        .save(Image::new(
            ImageId(0),
            new_html_image_element_rc.clone(),
            GamePoint::new(64, 32),
            GamePoint::new(32, 32),
        ))
        .unwrap();
    image_repository
        .save(Image::new(
            ImageId(1),
            new_html_image_element_rc.clone(),
            GamePoint::new(64, 64),
            GamePoint::new(32, 32),
        ))
        .unwrap();
    image_repository
};

GameLoop::run(test_game_state, image_repository, canvas.unwrap()).unwrap();

} ```