drboy finish 1.0.0

This commit is contained in:
ZennDev1337 2023-09-04 12:56:36 +02:00
parent 60ecb63360
commit 495c04a648
2 changed files with 392 additions and 30 deletions

View file

@ -58,7 +58,7 @@ pub unsafe fn gameloop() {
} }
} }
}); });
if arduboy.every_x_frames((p.speed * 2) as u8) && enemy_count < 30 { if arduboy.every_x_frames((p.speed * 2) as u8) {
if enemy_count > 8 { if enemy_count > 8 {
let _ = vec_enemies.remove(0); let _ = vec_enemies.remove(0);
} }
@ -78,9 +78,12 @@ pub unsafe fn gameloop() {
enemy_count += 1 enemy_count += 1
} }
if p.live == 0 { if p.live == 0 {
let score = scorebord.check_score(p.counter);
if score > 0 {
scorebord.update_score(p.counter)
}
p.gamemode = GameMode::Losescreen; p.gamemode = GameMode::Losescreen;
} }
arduboy.poll_buttons();
if arduboy.pressed(UP) { if arduboy.pressed(UP) {
if p.rect.y > 7 { if p.rect.y > 7 {
p.rect.y -= 1; p.rect.y -= 1;
@ -117,10 +120,10 @@ pub unsafe fn gameloop() {
p.speed_change = true; p.speed_change = true;
p.speed -= 1 p.speed -= 1
} }
if p.counter == 30 { // if p.counter == 30 {
p.level += 1; // p.level += 1;
p.gamemode = GameMode::Winscreen; // p.gamemode = GameMode::Winscreen;
} // }
} }
progmem!(); progmem!();

View file

@ -4,11 +4,54 @@
//Include the Arduboy Library //Include the Arduboy Library
#[allow(unused_imports)] #[allow(unused_imports)]
use arduboy_rust::prelude::*; use arduboy_rust::prelude::*;
use arduboy_tone::arduboy_tone_pitch::*;
mod gameloop; mod gameloop;
#[allow(dead_code)] #[allow(dead_code)]
pub const arduboy: Arduboy2 = Arduboy2::new(); pub const arduboy: Arduboy2 = Arduboy2::new();
pub const sound: ArduboyTones = ArduboyTones::new();
pub static eeprom: EEPROM = EEPROM::new(200);
pub static mut scorebord: Scoreboard = Scoreboard {
player1: 0,
player2: 0,
player3: 0,
};
pub struct Scoreboard {
pub player1: u16,
pub player2: u16,
pub player3: u16,
}
impl Scoreboard {
pub fn check_score(&self, score: u16) -> u8 {
match score {
s if s > self.player1 => 1,
s if s == self.player1 => 2,
s if s > self.player2 => 2,
s if s == self.player1 => 3,
s if s > self.player3 => 3,
_ => 0,
}
}
pub fn update_score(&mut self, score: u16) {
let place = self.check_score(score);
match place {
1 => {
self.player3 = self.player2;
self.player2 = self.player1;
self.player1 = score;
}
2 => {
self.player3 = self.player2;
self.player2 = score;
}
3 => {
self.player3 = score;
}
_ => (),
}
}
}
// dynamic ram variables // dynamic ram variables
#[derive(Debug)] #[derive(Debug)]
pub struct Enemy { pub struct Enemy {
@ -32,11 +75,12 @@ pub struct Player {
pub level: u8, pub level: u8,
pub speed: u8, pub speed: u8,
pub speed_change: bool, pub speed_change: bool,
pub counter: u8, pub counter: u16,
pub bitmap: *const u8, pub bitmap: *const u8,
pub bitmap_frame: i8, pub bitmap_frame: i8,
pub rect: Rect, pub rect: Rect,
pub gameover_height: i16, pub gameover_height: i16,
pub sound: bool,
} }
pub static mut p: Player = Player { pub static mut p: Player = Player {
@ -47,7 +91,7 @@ pub static mut p: Player = Player {
immortal_frame_count: 0, immortal_frame_count: 0,
active: true, active: true,
counter: 0, counter: 0,
speed: 30, speed: 60,
speed_change: false, speed_change: false,
bitmap: get_sprite_addr!(player), bitmap: get_sprite_addr!(player),
bitmap_frame: 0, bitmap_frame: 0,
@ -58,6 +102,7 @@ pub static mut p: Player = Player {
height: 8, height: 8,
}, },
gameover_height: -30, gameover_height: -30,
sound: true,
}; };
unsafe impl Sync for Player {} unsafe impl Sync for Player {}
@ -65,11 +110,9 @@ unsafe impl Sync for Player {}
pub enum GameMode { pub enum GameMode {
Titlescreen, Titlescreen,
GameLoop, GameLoop,
Winscreen,
Losescreen, Losescreen,
Scoreboard, Scoreboard,
Reset, Reset,
NextLevel,
} }
// The setup() function runs once when you turn your Arduboy on // The setup() function runs once when you turn your Arduboy on
@ -77,7 +120,9 @@ pub enum GameMode {
pub unsafe extern "C" fn setup() { pub unsafe extern "C" fn setup() {
// put your setup code here, to run once: // put your setup code here, to run once:
arduboy.begin(); arduboy.begin();
arduboy.set_frame_rate(30); eeprom.init(&mut scorebord);
arduboy.set_frame_rate(60);
sound.tones(get_tones_addr!(music));
} }
// The loop() function repeats forever after setup() is done // The loop() function repeats forever after setup() is done
@ -89,13 +134,20 @@ pub unsafe extern "C" fn loop_() {
return; return;
} }
arduboy.clear(); arduboy.clear();
arduboy.poll_buttons();
match p.gamemode { match p.gamemode {
GameMode::Titlescreen => { GameMode::Titlescreen => {
sprites::draw_override(0, 0, get_sprite_addr!(titlescreen), 0); sprites::draw_override(0, 0, get_sprite_addr!(titlescreen), 0);
if arduboy.pressed(A) { if arduboy.just_pressed(A) {
p.gamemode = GameMode::GameLoop; p.gamemode = GameMode::GameLoop;
} }
if arduboy.just_pressed(B) {
p.gamemode = GameMode::Scoreboard;
}
if arduboy.just_pressed(DOWN) {
arduboy.audio_toggle();
}
} }
GameMode::GameLoop => { GameMode::GameLoop => {
gameloop::gameloop(); gameloop::gameloop();
@ -114,29 +166,51 @@ pub unsafe extern "C" fn loop_() {
arduboy.print(get_string_addr!(text_gameover_score)); arduboy.print(get_string_addr!(text_gameover_score));
arduboy.print(p.counter as i16); arduboy.print(p.counter as i16);
} }
} if arduboy.just_pressed(A) || arduboy.just_pressed(B) {
GameMode::Winscreen => { p.gamemode = GameMode::Reset;
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 => { GameMode::Scoreboard => {
//todo arduboy.set_text_size(2);
arduboy.set_cursor(0, 0);
arduboy.print(f!(b"Scoreboard\0"));
arduboy.set_text_size(1);
arduboy.print(f!(b"\n\n\n\0"));
arduboy.print(f!(b"Player 1: \0"));
arduboy.print(scorebord.player1);
arduboy.print(f!(b"\n\0"));
arduboy.print(f!(b"Player 2: \0"));
arduboy.print(scorebord.player2);
arduboy.print(f!(b"\n\0"));
arduboy.print(f!(b"Player 3: \0"));
arduboy.print(scorebord.player3);
if arduboy.just_pressed(A) || arduboy.just_pressed(B) {
p.gamemode = GameMode::Reset
}
} }
GameMode::Reset => { GameMode::Reset => {
//todo vec_enemies = Vec::<Enemy, 9>::new();
} p = Player {
GameMode::NextLevel => { gamemode: GameMode::Titlescreen,
//todo live: 3,
level: 1,
immortal: false,
immortal_frame_count: 0,
active: true,
counter: 0,
speed: 60,
speed_change: false,
bitmap: get_sprite_addr!(player),
bitmap_frame: 0,
rect: Rect {
x: 0,
y: 8,
width: 8,
height: 8,
},
gameover_height: -30,
sound: p.sound,
};
} }
} }
@ -259,4 +333,289 @@ progmem!(
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,
]; ];
static music: [u16; _] = [
NOTE_D2,
473,
NOTE_REST,
26,
NOTE_D2,
473,
NOTE_REST,
26,
NOTE_D2,
236,
NOTE_REST,
13,
NOTE_A2,
1186,
NOTE_REST,
63,
NOTE_A2,
473,
NOTE_REST,
26,
NOTE_E2,
711,
NOTE_REST,
38,
NOTE_F2,
236,
NOTE_REST,
13,
NOTE_E2,
473,
NOTE_REST,
26,
NOTE_D2,
1423,
NOTE_REST,
576,
NOTE_A2,
473,
NOTE_REST,
26,
NOTE_C3,
473,
NOTE_REST,
26,
NOTE_D3,
948,
NOTE_REST,
51,
NOTE_C3,
473,
NOTE_REST,
26,
NOTE_A2,
473,
NOTE_REST,
26,
NOTE_B2,
473,
NOTE_REST,
26,
NOTE_G2,
473,
NOTE_REST,
26,
NOTE_A2,
1423,
NOTE_REST,
1076,
NOTE_D3,
473,
NOTE_REST,
26,
NOTE_D3,
948,
NOTE_REST,
51,
NOTE_D3,
473,
NOTE_REST,
26,
NOTE_C3,
948,
NOTE_REST,
51,
NOTE_A2,
473,
NOTE_REST,
26,
NOTE_A2,
473,
NOTE_REST,
26,
NOTE_G2,
473,
NOTE_REST,
26,
NOTE_F2,
473,
NOTE_REST,
26,
NOTE_E2,
1423,
NOTE_REST,
1576,
NOTE_D2,
473,
NOTE_REST,
26,
NOTE_F2,
473,
NOTE_REST,
26,
NOTE_A2,
473,
NOTE_REST,
26,
NOTE_G2,
948,
NOTE_REST,
51,
NOTE_F2,
473,
NOTE_REST,
26,
NOTE_E2,
473,
NOTE_REST,
26,
NOTE_D2,
473,
NOTE_REST,
26,
NOTE_C2,
473,
NOTE_REST,
26,
NOTE_D2,
1423,
NOTE_REST,
1576,
NOTE_D2,
473,
NOTE_REST,
26,
NOTE_D2,
473,
NOTE_REST,
26,
NOTE_D2,
473,
NOTE_REST,
26,
NOTE_A2,
473,
NOTE_REST,
26,
NOTE_A2,
473,
NOTE_REST,
26,
NOTE_A2,
473,
NOTE_REST,
26,
NOTE_E2,
711,
NOTE_REST,
38,
NOTE_F2,
236,
NOTE_REST,
13,
NOTE_E2,
473,
NOTE_REST,
26,
NOTE_D2,
1423,
NOTE_REST,
576,
NOTE_A2,
473,
NOTE_REST,
26,
NOTE_C3,
473,
NOTE_REST,
26,
NOTE_D3,
948,
NOTE_REST,
51,
NOTE_C3,
473,
NOTE_REST,
26,
NOTE_A2,
473,
NOTE_REST,
26,
NOTE_B2,
473,
NOTE_REST,
26,
NOTE_G2,
473,
NOTE_REST,
26,
NOTE_A2,
1423,
NOTE_REST,
1076,
NOTE_D3,
473,
NOTE_REST,
26,
NOTE_D3,
948,
NOTE_REST,
51,
NOTE_D3,
473,
NOTE_REST,
26,
NOTE_C3,
948,
NOTE_REST,
51,
NOTE_A2,
473,
NOTE_REST,
26,
NOTE_A2,
498,
NOTE_REST,
1,
NOTE_G2,
473,
NOTE_REST,
26,
NOTE_F2,
473,
NOTE_REST,
26,
NOTE_E2,
1423,
NOTE_REST,
1576,
NOTE_D2,
948,
NOTE_REST,
51,
NOTE_A2,
473,
NOTE_REST,
26,
NOTE_G2,
948,
NOTE_REST,
51,
NOTE_F2,
473,
NOTE_REST,
26,
NOTE_E2,
473,
NOTE_REST,
26,
NOTE_D2,
473,
NOTE_REST,
26,
NOTE_C2,
473,
NOTE_REST,
26,
NOTE_D2,
1423,
NOTE_REST,
1576,
NOTE_F2,
1423,
TONES_REPEAT,
];
); );