commit save to work

This commit is contained in:
ZennDev1337 2023-10-09 08:25:48 +02:00
parent 4a3100c0bd
commit 4c3a37dee7
8 changed files with 607 additions and 12 deletions

View file

@ -4,17 +4,511 @@
//Initialize the arduboy object
use arduboy_rust::prelude::*;
const arduboy: Arduboy2 = Arduboy2::new();
// FX Data
const FX_DATA_PAGE: u16 = 0xfffe;
const FX_DATA_BYTES: u32 = 392;
const FX_DATA_TILES: u32 = 0x000000;
const FX_DATA_TILES_WIDTH: u16 = 16;
const FX_DATA_TILESHEIGHT: u16 = 16;
const FX_DATA_TILES_FRAMES: u8 = 2;
const FX_DATA_TILEMAP: u32 = 0x000044;
const FX_DATA_BALLS: u32 = 0x000144;
const FX_DATA_BALLS_WIDTH: u16 = 16;
const FX_DATA_BALLSHEIGHT: u16 = 16;
const FRAME_RATE: u8 = 60;
const MAX_BALLS: u8 = 55;
const CIRCLE_POINTS: u8 = 84;
const VISABLE_TILES_PER_COLUMN: u8 = 5;
const VISABLE_TILES_PER_ROW: u8 = 9;
const ballWidth: u8 = 16;
const ballHeight: u8 = 16;
const tilemapWidth: u8 = 16;
const tileWidth: u8 = 16;
const tileHeight: u8 = 16;
static mut circle_points: [Point; CIRCLE_POINTS as usize] = [
Point { x: -15, y: 0 },
Point { x: -15, y: 1 },
Point { x: -15, y: 2 },
Point { x: -15, y: 3 },
Point { x: -15, y: 4 },
Point { x: -14, y: 5 },
Point { x: -14, y: 6 },
Point { x: -13, y: 7 },
Point { x: -13, y: 8 },
Point { x: -12, y: 9 },
Point { x: -11, y: 10 },
Point { x: -10, y: 11 },
Point { x: -9, y: 12 },
Point { x: -8, y: 13 },
Point { x: -7, y: 13 },
Point { x: -6, y: 14 },
Point { x: -5, y: 14 },
Point { x: -4, y: 14 },
Point { x: -3, y: 15 },
Point { x: -2, y: 15 },
Point { x: -1, y: 15 },
Point { x: 0, y: 15 },
Point { x: 1, y: 15 },
Point { x: 2, y: 15 },
Point { x: 3, y: 15 },
Point { x: 4, y: 14 },
Point { x: 5, y: 14 },
Point { x: 6, y: 14 },
Point { x: 7, y: 13 },
Point { x: 8, y: 13 },
Point { x: 9, y: 12 },
Point { x: 10, y: 11 },
Point { x: 11, y: 10 },
Point { x: 12, y: 9 },
Point { x: 12, y: 8 },
Point { x: 13, y: 7 },
Point { x: 13, y: 6 },
Point { x: 14, y: 5 },
Point { x: 14, y: 4 },
Point { x: 14, y: 3 },
Point { x: 14, y: 2 },
Point { x: 14, y: 1 },
Point { x: 15, y: 0 },
Point { x: 15, y: -1 },
Point { x: 15, y: -2 },
Point { x: 15, y: -3 },
Point { x: 15, y: -4 },
Point { x: 14, y: -5 },
Point { x: 14, y: -6 },
Point { x: 13, y: -7 },
Point { x: 13, y: -8 },
Point { x: 12, y: -9 },
Point { x: 11, y: -10 },
Point { x: 10, y: -11 },
Point { x: 9, y: -12 },
Point { x: 8, y: -13 },
Point { x: 7, y: -13 },
Point { x: 6, y: -14 },
Point { x: 5, y: -14 },
Point { x: 4, y: -14 },
Point { x: 3, y: -15 },
Point { x: 2, y: -15 },
Point { x: 1, y: -15 },
Point { x: 0, y: -15 },
Point { x: -1, y: -15 },
Point { x: -2, y: -15 },
Point { x: -3, y: -15 },
Point { x: -4, y: -14 },
Point { x: -5, y: -14 },
Point { x: -6, y: -14 },
Point { x: -7, y: -13 },
Point { x: -8, y: -13 },
Point { x: -9, y: -12 },
Point { x: -10, y: -11 },
Point { x: -11, y: -10 },
Point { x: -12, y: -9 },
Point { x: -12, y: -8 },
Point { x: -13, y: -7 },
Point { x: -13, y: -6 },
Point { x: -14, y: -5 },
Point { x: -14, y: -4 },
Point { x: -14, y: -3 },
Point { x: -14, y: -2 },
Point { x: -14, y: -1 },
];
static mut camera: Point = Point { x: 0, y: 0 };
static mut map_location: Point = Point { x: 16, y: 16 };
struct Ball {
x: i8,
y: i8,
xspeed: i8,
yspeed: i8,
}
static mut ball: [Ball; MAX_BALLS as usize] = [
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
Ball {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
},
];
static mut balls_visible: u8 = MAX_BALLS;
static mut pos: u8 = 0;
static mut tilemap_buffer: [u8; VISABLE_TILES_PER_ROW as usize] = [0, 0, 0, 0, 0, 0, 0, 0, 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(FRAME_RATE);
fx::begin_data(FX_DATA_PAGE);
ball.iter_mut().for_each(|b| {
b.x = random_less_than(113) as i8;
b.y = random_less_than(49) as i8;
b.xspeed = 1;
if random_less_than(100) > 49 {
b.xspeed = -b.xspeed
}
b.yspeed = 1;
if random_less_than(100) > 49 {
b.yspeed = -b.yspeed
}
})
}
#[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.just_pressed(A) && balls_visible < MAX_BALLS {
balls_visible += 1;
}
if arduboy.just_pressed(B) && balls_visible > 0 {
balls_visible -= 1;
}
if arduboy.pressed(UP) && map_location.y > 16 {
map_location.y -= 1;
}
if arduboy.pressed(DOWN) && map_location.y < 176 {
map_location.y += 1;
}
if arduboy.pressed(LEFT) && map_location.x > 16 {
map_location.x -= 1;
}
if arduboy.pressed(RIGHT) && map_location.x > 112 {
map_location.x += 1;
}
camera.x = map_location.x + circle_points[pos as usize].x;
camera.y = map_location.y + circle_points[pos as usize].y;
}

View file

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

View file

@ -1,20 +1,57 @@
#![no_std]
#![allow(non_upper_case_globals)]
//Include the Arduboy Library
//Initialize the arduboy object
use arduboy_rust::prelude::*;
const arduboy: Arduboy2 = Arduboy2::new();
//The setup() function runs once when you turn your Arduboy on
const FX_DATA_PAGE: u16 = 0xfff0;
const FX_DATA_BYTES: u32 = 0;
const FX_SAVE_PAGE: u16 = 0xfff0;
const FX_SAVE_BYTES: u32 = 2;
struct GameState {
name: &'static str,
count: u16,
}
static mut gamestate: GameState = GameState {
name: "\0",
count: 0,
};
#[no_mangle]
pub unsafe extern "C" fn setup() {
// put your setup code here, to run once:
arduboy.begin();
fx::begin_data_save(FX_DATA_PAGE, FX_SAVE_PAGE);
if fx::load_game_state(&mut gamestate) > 1 {
gamestate.name = "Hello World !!!\0";
gamestate.count = 1;
} else {
gamestate.name = "Save state Loaded\0";
gamestate.count += 1;
}
fx::save_game_state(&gamestate);
arduboy.clear();
arduboy.print(f!(b"Holmes is cool!\0"));
arduboy.display();
arduboy.set_cursor(0, 32 - 8);
arduboy.print(gamestate.name);
arduboy.set_cursor(0, 32 + 8);
arduboy.print("Number of times this\nscetch is run: \0");
arduboy.print(gamestate.count);
fx::display();
}
#[no_mangle]
#[export_name = "loop"]
pub unsafe extern "C" fn loop_() {
// put your main code here, to run repeatedly:
if !arduboy.next_frame() {
return;
}
if arduboy.buttons_state() > 0 {
arduboy.exit_to_bootloader()
}
}