fixed some problems and added the demos for fxhelloworld, fxbasicexample and fxchompies

This commit is contained in:
ZennDev1337 2023-10-06 15:21:04 +02:00
parent 9ad03927de
commit 4a3100c0bd
18 changed files with 258 additions and 85 deletions

View file

@ -1,20 +1,51 @@
#![no_std]
#![allow(non_upper_case_globals)]
//Include the Arduboy Library
//Initialize the arduboy object
#[allow(unused_imports)]
use arduboy_rust::prelude::*;
#[allow(dead_code)]
const arduboy: Arduboy2 = Arduboy2::new();
//The setup() function runs once when you turn your Arduboy on
// Progmem data
// dynamic ram variables
const FX_DATA_PAGE: u16 = 0xffff;
#[allow(dead_code)]
const FX_DATA_BYTES: u32 = 234;
const FXlogo: u32 = 0x000000;
const FXlogoWith: i16 = 115;
const FXlogoHeight: i16 = 16;
static mut x: i16 = (WIDTH - FXlogoWith) / 2;
static mut y: i16 = 25;
static mut xDir: i8 = 1;
static mut yDir: i8 = 1;
// 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();
arduboy.clear();
arduboy.print(f!(b"Holmes is cool!\0"));
arduboy.display();
arduboy.set_frame_rate(30);
fx::begin_data(FX_DATA_PAGE);
}
// 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;
}
fx::draw_bitmap(x, y, FXlogo, 0, 0);
x += xDir as i16;
y += yDir as i16;
if x == 0 || x == WIDTH - FXlogoWith {
xDir = -xDir;
}
if y == 0 || y == HEIGHT - FXlogoHeight {
yDir = -yDir;
}
fx::display_clear()
}

Binary file not shown.

View file

@ -1,6 +1,6 @@
#pragma once
/**** FX data header generated by fxdata-build.py tool version 1.07 ****/
/**** FX data header generated by fxdata-build.py tool version 1.15 ****/
using uint24_t = __uint24;

View file

@ -1,20 +1,105 @@
#![no_std]
#![allow(non_upper_case_globals)]
//Include the Arduboy Library
//Initialize the arduboy object
use arduboy_rust::prelude::*;
use arduboyfx::fx_consts::*;
const arduboy: Arduboy2 = Arduboy2::new();
// FX Data
const FX_DATA_PAGE: u16 = 0xff65;
const FX_DATA_BYTES: u32 = 39470;
const mapGfx: u32 = 0x000000;
const mapGfxWidth: u16 = 816;
const mapGfxHeight: u16 = 368;
const whaleGfx: u32 = 0x0092A4;
const whaleGfxWidth: u16 = 107;
const whaleGfxHeight: u16 = 69;
static mut showposition: bool = true;
static mut select: usize = 0;
static mut color: u8 = 0;
static mut x: [i16; 2] = [0, 0];
static mut y: [i16; 2] = [0, 0];
static mut mode: u8 = 0;
//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();
arduboy.clear();
arduboy.print(f!(b"Holmes is cool!\0"));
arduboy.display();
arduboy.set_frame_rate(120);
fx::begin_data(FX_DATA_PAGE);
}
#[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 arduboy.pressed(A) && arduboy.pressed(B) {
if arduboy.every_x_frames(120) {
mode += 1;
if mode == 5 {
mode = 0
}
}
}
if arduboy.just_pressed(B) {
showposition = !showposition;
}
if arduboy.pressed(B) {
select = 0;
} else {
select = 1
}
if arduboy.just_pressed(A) {
color ^= dbmReverse;
}
if arduboy.pressed(A) {
if arduboy.just_pressed(UP) {
y[select] -= 1;
}
if arduboy.just_pressed(DOWN) {
y[select] += 1;
}
if arduboy.just_pressed(LEFT) {
x[select] -= 1;
}
if arduboy.just_pressed(RIGHT) {
x[select] += 1;
}
} else {
if arduboy.pressed(UP) {
y[select] -= 1;
}
if arduboy.pressed(DOWN) {
y[select] += 1;
}
if arduboy.pressed(LEFT) {
x[select] -= 1;
}
if arduboy.pressed(RIGHT) {
x[select] += 1;
}
}
fx::draw_bitmap(x[0], y[0], mapGfx, 0, dbmNormal);
match mode {
0 => fx::draw_bitmap(x[1], y[1], whaleGfx, 0, dbmMasked | color),
1 => fx::draw_bitmap(x[1], y[1], whaleGfx, 0, dbfMasked | dbmBlack),
2 => fx::draw_bitmap(x[1], y[1], whaleGfx, 0, dbfMasked | dbmWhite),
3 => fx::draw_bitmap(x[1], y[1], whaleGfx, 0, dbfMasked | dbmInvert),
4 => fx::draw_bitmap(x[1], y[1], whaleGfx, 0, dbfMasked | dbmReverse),
_ => (),
}
if showposition {
arduboy.set_cursor(0, 0);
arduboy.print(x[select]);
arduboy.set_cursor(0, 8);
arduboy.print(y[select]);
}
fx::display_clear();
}

View file

@ -1,20 +1,89 @@
#![no_std]
#![allow(non_upper_case_globals)]
//Include the Arduboy Library
//Initialize the arduboy object
use arduboy_rust::prelude::*;
use arduboyfx::fx_consts::*;
const arduboy: Arduboy2 = Arduboy2::new();
//FX Data
const FX_DATA_PAGE: u16 = 0xffc9;
const FX_DATA_BYTES: u32 = 13937;
const arduboyFont: u32 = 0x000000;
const arduboyFontWidth: u16 = 6;
const arduboyFontHeight: u16 = 8;
const arduboyFontFrames: u16 = 256;
const maskedFont: u32 = 0x000604;
const maskedFontWidth: u16 = 16;
const maskedFontHeight: u16 = 24;
const maskedFontFrames: u8 = 128;
const helloWorld: u32 = 0x003608;
static mut frames: u16 = 0;
static mut speed: u8 = 1;
static mut scroll_x: i16 = 128;
static mut font_mode: u8 = dcmNormal;
static mut leading_digits: i8 = 5;
static str: &str = "FX Demo\0";
//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();
arduboy.clear();
arduboy.print(f!(b"Holmes is cool!\0"));
arduboy.display();
fx::begin_data(FX_DATA_PAGE);
fx::set_font(arduboyFont, dcmNormal);
fx::set_cursor_range(0, 32767);
}
#[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();
fx::set_cursor(0, 0);
fx::set_font_mode(dcmNormal);
fx::draw_string(str);
fx::set_cursor(WIDTH - 5 * arduboyFontWidth as i16, 0);
fx::draw_number(frames, leading_digits);
fx::set_cursor(scroll_x, 24);
fx::set_font(maskedFont, dcmMasked | font_mode);
fx::draw_string(helloWorld);
fx::set_cursor(13, HEIGHT - arduboyFontHeight as i16);
fx::set_font(arduboyFont, font_mode);
fx::draw_string(" Press any button \0");
fx::display_clear();
scroll_x -= speed as i16;
if scroll_x < -1792 {
scroll_x = 128
}
frames += 1;
if arduboy.just_pressed(ANY_BUTTON) {
frames = 0
}
if arduboy.just_pressed(UP) {
speed = 2
}
if arduboy.just_pressed(DOWN) {
speed = 1
}
if arduboy.just_pressed(LEFT) {
leading_digits = if leading_digits == -5 { 0 } else { -5 }
}
if arduboy.just_pressed(RIGHT) {
leading_digits = if leading_digits == 5 { 0 } else { 5 }
}
if arduboy.just_pressed(A) {
font_mode = dcmNormal
}
if arduboy.just_pressed(B) {
font_mode = dcmReverse
}
}

View file

@ -7,7 +7,6 @@ use arduboy_rust::prelude::*;
use arduboy_tones::tones_pitch::*;
mod gameloop;
#[allow(dead_code)]
pub const arduboy: Arduboy2 = Arduboy2::new();
pub const sound: ArduboyTones = ArduboyTones::new();
@ -155,7 +154,6 @@ pub unsafe extern "C" fn loop_() {
gameloop::gameloop();
}
GameMode::Losescreen => {
//todo
arduboy.set_text_size(2);
arduboy.set_cursor(13, p.gameover_height);
arduboy.print(get_string_addr!(text_gameover));