#![no_std] #![allow(non_upper_case_globals)] //Include the Arduboy Library #[allow(unused_imports)] use arduboy_rust::prelude::*; mod gameloop; #[allow(dead_code)] pub const arduboy: Arduboy2 = Arduboy2::new(); // dynamic ram variables #[derive(Debug)] pub struct Enemy { pub active: bool, pub bitmap: *const u8, pub bitmap_frame: u8, pub rect: Rect, } impl Enemy { pub fn move_down(&mut self) { self.rect.x -= 1; } } #[derive(Debug)] pub struct Player { pub gamemode: GameMode, pub immortal: bool, pub immortal_frame_count: u8, pub active: bool, pub live: u8, pub level: u8, pub speed: u8, pub speed_change: bool, pub counter: u8, pub bitmap: *const u8, pub bitmap_frame: i8, pub rect: Rect, pub gameover_height: i16, } pub static mut p: Player = Player { gamemode: GameMode::Titlescreen, live: 3, level: 1, immortal: false, immortal_frame_count: 0, active: true, counter: 0, speed: 30, speed_change: false, bitmap: get_sprite_addr!(player), bitmap_frame: 0, rect: Rect { x: 0, y: 8, width: 8, height: 8, }, gameover_height: -30, }; unsafe impl Sync for Player {} #[derive(Debug)] pub enum GameMode { Titlescreen, GameLoop, Winscreen, Losescreen, Scoreboard, Reset, NextLevel, } // 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.set_frame_rate(30); } // 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.clear(); match p.gamemode { GameMode::Titlescreen => { sprites::draw_override(0, 0, get_sprite_addr!(titlescreen), 0); if arduboy.pressed(A) { p.gamemode = GameMode::GameLoop; } } GameMode::GameLoop => { gameloop::gameloop(); } GameMode::Losescreen => { //todo arduboy.set_text_size(2); arduboy.set_cursor(13, p.gameover_height); arduboy.print(get_string_addr!(text_gameover)); if arduboy.every_x_frames(2) && p.gameover_height < 15 { p.gameover_height += 1 } if p.gameover_height == 15 { arduboy.set_text_size(1); arduboy.set_cursor(13, 35); arduboy.print(get_string_addr!(text_gameover_score)); arduboy.print(p.counter as i16); } } GameMode::Winscreen => { arduboy.set_text_size(2); arduboy.set_cursor(13, p.gameover_height); arduboy.print(get_string_addr!(text_levelwin)); if arduboy.every_x_frames(2) && p.gameover_height < 15 { p.gameover_height += 1 } if p.gameover_height == 15 { arduboy.set_text_size(1); arduboy.set_cursor(13, 35); arduboy.print(get_string_addr!(text_gameover_score)); arduboy.print(p.counter as i16); } } GameMode::Scoreboard => { //todo } GameMode::Reset => { //todo } GameMode::NextLevel => { //todo } } arduboy.display(); } pub static mut enemy_count: u8 = 0; pub static mut vec_enemies: Vec = Vec::::new(); progmem!( static text_gameover: [u8; _] = *b"Game Over\0"; static text_levelwin: [u8; _] = *b"Congrats\0"; static text_gameover_score: [u8; _] = *b"Your score is: \0"; pub static player: [u8; _] = [ 8, 8, // width, height, 0xa3, 0x51, 0xa6, 0x51, 0xa1, 0x56, 0xa1, 0x53, // TILE 00 0x7e, 0xdf, 0xb3, 0xdf, 0xbf, 0xd3, 0xbf, 0x7e, // TILE 01 0x7e, 0xc1, 0xad, 0xc1, 0xa1, 0xcd, 0xa1, 0x7e, // TILE 02 ]; pub static titlescreen: [u8; _] = [ // width, height, 128, 64, 0xff, 0xff, 0xff, 0x3f, 0x1f, 0x0f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x0f, 0x1f, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x03, 0x03, 0x03, 0x03, 0x03, 0x07, 0x06, 0x1e, 0xfc, 0xf0, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0x60, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xc3, 0xc3, 0xc3, 0xc3, 0xe7, 0xfe, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x80, 0xe0, 0x60, 0x30, 0x30, 0x30, 0x30, 0x60, 0xe0, 0x80, 0x00, 0x10, 0xf0, 0xe0, 0x80, 0x00, 0x00, 0x00, 0x80, 0xe0, 0x70, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x60, 0x60, 0x60, 0x60, 0x60, 0x70, 0x30, 0x3c, 0x1f, 0x07, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x60, 0x60, 0x60, 0x60, 0x60, 0x71, 0x3f, 0x1e, 0x00, 0x00, 0x00, 0x0f, 0x3f, 0x30, 0x60, 0x60, 0x60, 0x60, 0x30, 0x3f, 0x0f, 0x00, 0x00, 0x00, 0x03, 0x0f, 0xfe, 0xf0, 0x3e, 0x0f, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x10, 0x60, 0x10, 0x10, 0x60, 0x10, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x60, 0x56, 0x60, 0x50, 0x66, 0x50, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x05, 0x0a, 0x05, 0x0a, 0x05, 0x0a, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x6f, 0x59, 0x6f, 0x5f, 0x69, 0x5f, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xe0, 0xc0, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xc0, 0xe0, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd9, 0xb6, 0xb6, 0xb6, 0xcd, 0xff, 0xc7, 0xbb, 0xbb, 0xbb, 0xff, 0xc7, 0xbb, 0xbb, 0xbb, 0xc7, 0xff, 0x83, 0xfb, 0xfb, 0xff, 0xff, 0xc7, 0xab, 0xab, 0xab, 0xa7, 0xff, 0xbb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0xb6, 0xb6, 0xb6, 0xc9, 0xff, 0xff, 0x7f, 0x3e, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x3e, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0xf6, 0xf6, 0xf6, 0xf9, 0xff, 0x80, 0xff, 0x9f, 0xab, 0xab, 0xab, 0x87, 0xff, 0x73, 0x4f, 0x3f, 0xcf, 0xf3, 0xff, 0xbb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xbf, 0xc7, 0xe9, 0xee, 0xe9, 0xc7, 0xbf, 0xff, 0xff, 0xff, 0xff, 0xff, ]; pub static overlay_score: [u8; _] = *b"Score: \0"; pub static enemies: [u8; _] = [ 8, 8, // width, height, 0x7e, 0xd5, 0xab, 0xd5, 0xab, 0xd5, 0xab, 0x7e, // TILE 00 Gray 0x7e, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7e, // TILE 01 White 0x7e, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x7e, // TILE 02 Black ]; pub static overlay_3hearts: [u8; _] = [ // width, height, 64, 8, 0x00, 0x00, 0x7e, 0x40, 0x40, 0x40, 0x00, 0x7a, 0x00, 0x0c, 0x30, 0x40, 0x30, 0x0c, 0x00, 0x38, 0x54, 0x54, 0x58, 0x00, 0x58, 0x54, 0x54, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x1e, 0x3f, 0x7e, 0xfc, 0x7e, 0x3f, 0x1e, 0x0c, 0x00, 0x00, 0x0c, 0x1e, 0x3f, 0x7e, 0xfc, 0x7e, 0x3f, 0x1e, 0x0c, 0x00, 0x00, 0x0c, 0x1e, 0x3f, 0x7e, 0xfc, 0x7e, 0x3f, 0x1e, 0x0c, 0x00, 0x00, 0x00, 0x00, ]; pub static overlay_2hearts: [u8; _] = [ // width, height, 64, 8, 0x00, 0x00, 0x7e, 0x40, 0x40, 0x40, 0x00, 0x7a, 0x00, 0x0c, 0x30, 0x40, 0x30, 0x0c, 0x00, 0x38, 0x54, 0x54, 0x58, 0x00, 0x58, 0x54, 0x54, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x1e, 0x3f, 0x7e, 0xfc, 0x7e, 0x3f, 0x1e, 0x0c, 0x00, 0x00, 0x0c, 0x1e, 0x3f, 0x7e, 0xfc, 0x7e, 0x3f, 0x1e, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]; pub static overlay_1heart: [u8; _] = [ // width, height, 64, 8, 0x00, 0x00, 0x7e, 0x40, 0x40, 0x40, 0x00, 0x7a, 0x00, 0x0c, 0x30, 0x40, 0x30, 0x0c, 0x00, 0x38, 0x54, 0x54, 0x58, 0x00, 0x58, 0x54, 0x54, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x1e, 0x3f, 0x7e, 0xfc, 0x7e, 0x3f, 0x1e, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]; );