diff --git a/Examples/ArduboyFX/fxdrawballs/src/lib.rs b/Examples/ArduboyFX/fxdrawballs/src/lib.rs index 5948963..6e9cbb3 100644 --- a/Examples/ArduboyFX/fxdrawballs/src/lib.rs +++ b/Examples/ArduboyFX/fxdrawballs/src/lib.rs @@ -3,9 +3,9 @@ //Include the Arduboy Library //Initialize the arduboy object + use arduboy_rust::prelude::*; use fx_consts::{dbmMasked, dbmNormal}; - const arduboy: Arduboy2 = Arduboy2::new(); // FX Data diff --git a/Project/test_game/Cargo.toml b/Project/test_game/Cargo.toml new file mode 100644 index 0000000..174126d --- /dev/null +++ b/Project/test_game/Cargo.toml @@ -0,0 +1,13 @@ + +[package] +name = "test_game" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["staticlib"] + +[dependencies] + +[dependencies.arduboy-rust] +path = "../../arduboy-rust" \ No newline at end of file diff --git a/Project/test_game/assets/player_8x8.png b/Project/test_game/assets/player_8x8.png new file mode 100644 index 0000000..94426fa Binary files /dev/null and b/Project/test_game/assets/player_8x8.png differ diff --git a/Project/test_game/config.toml b/Project/test_game/config.toml new file mode 100644 index 0000000..138aabc --- /dev/null +++ b/Project/test_game/config.toml @@ -0,0 +1,9 @@ +Libraries = [ + "Arduboy2", + #"ArduboyTones", + "ArduboyFX", + #"ArdVoice", + #"Serial", + "EEPROM", + "Arduino", +] \ No newline at end of file diff --git a/Project/test_game/fxdata/fxdata-data.bin b/Project/test_game/fxdata/fxdata-data.bin new file mode 100644 index 0000000..ebdee8c Binary files /dev/null and b/Project/test_game/fxdata/fxdata-data.bin differ diff --git a/Project/test_game/fxdata/fxdata.bin b/Project/test_game/fxdata/fxdata.bin new file mode 100644 index 0000000..5bfb776 Binary files /dev/null and b/Project/test_game/fxdata/fxdata.bin differ diff --git a/Project/test_game/fxdata/fxdata.h b/Project/test_game/fxdata/fxdata.h new file mode 100644 index 0000000..fc9f312 --- /dev/null +++ b/Project/test_game/fxdata/fxdata.h @@ -0,0 +1,16 @@ +#pragma once + +/**** FX data header generated by fxdata-build.py tool version 1.15 ****/ + +using uint24_t = __uint24; + +// Initialize FX hardware using FX::begin(FX_DATA_PAGE); in the setup() function. + +constexpr uint16_t FX_DATA_PAGE = 0xffff; +constexpr uint24_t FX_DATA_BYTES = 124; + +constexpr uint24_t FX_DATA_TILES = 0x000000; +constexpr uint16_t FX_DATA_TILES_WIDTH = 8; +constexpr uint16_t FX_DATA_TILESHEIGHT = 8; +constexpr uint8_t FX_DATA_TILES_FRAMES = 15; + diff --git a/Project/test_game/fxdata/fxdata.txt b/Project/test_game/fxdata/fxdata.txt new file mode 100644 index 0000000..c3c7562 --- /dev/null +++ b/Project/test_game/fxdata/fxdata.txt @@ -0,0 +1 @@ +image_t FX_DATA_TILES = "../assets/player_8x8.png" \ No newline at end of file diff --git a/Project/test_game/src/lib.rs b/Project/test_game/src/lib.rs new file mode 100644 index 0000000..fee5eb2 --- /dev/null +++ b/Project/test_game/src/lib.rs @@ -0,0 +1,86 @@ +#![no_std] +#![allow(non_upper_case_globals)] + +//Include the Arduboy Library + +use arduboy_rust::prelude::*; + +extern crate arduboy_rust; +use fx_consts::*; + +const FX_DATA_PAGE: u16 = 0xffff; +const FX_DATA_BYTES: u32 = 244; +const FX_DATA_TILES: u32 = 0x000000; +const FX_DATA_TILES_WIDTH: u16 = 8; +const FX_DATA_TILESHEIGHT: u16 = 8; +const FX_DATA_TILES_FRAMES: u8 = 15; + +#[allow(dead_code)] +const arduboy: Arduboy2 = Arduboy2::new(); + +// Progmem data + +// dynamic ram variables +static mut lol: u8 = 0; +enum State { + Run, + Idle1, + Idle2, + Hurt, + Death, +} +impl State { + fn get_frames(&self) -> (u8, u8) { + match self { + State::Run => (0, 3), + State::Idle1 => (4, 5), + State::Idle2 => (6, 7), + State::Hurt => (8, 10), + State::Death => (11, 14), + } + } + fn next_state(&mut self) { + match self { + State::Run => *self = State::Idle1, + State::Idle1 => *self = State::Idle2, + State::Idle2 => *self = State::Hurt, + State::Hurt => *self = State::Death, + State::Death => *self = State::Run, + } + } +} +static mut state: State = State::Run; +// The setup() function runs once when you turn your Arduboy on +#[no_mangle] +pub unsafe extern "C" fn setup() { + // put your setup code here, to run once: + arduboy.begin(); + fx::begin_data(FX_DATA_PAGE); + arduboy.clear() +} + +// The loop() function repeats forever after setup() is done +#[no_mangle] +#[export_name = "loop"] +pub unsafe extern "C" fn loop_() { + // put your main code here, to run repeatedly: + if !arduboy.next_frame() { + return; + } + arduboy.poll_buttons(); + if A.just_pressed() { + state.next_state(); + } + let (min, max) = state.get_frames(); + if arduboy.every_x_frames(10) { + lol += 1; + if lol < min { + lol = min; + } + if lol > max { + lol = min; + } + } + fx::draw_bitmap(0, 0, FX_DATA_TILES, lol, dbmNormal); + fx::display_clear() +}