let you walk around the title screen

Signed-off-by: Jessie Williams <quorawings@gmail.com>
This commit is contained in:
Jessie Williams 2022-03-06 21:40:57 -05:00
parent 9c44fdd4f6
commit 037d6a5d54
3 changed files with 87 additions and 19 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 391 B

After

Width:  |  Height:  |  Size: 391 B

View File

@ -16,6 +16,8 @@ struct Game {
mara_position: Point, mara_position: Point,
mara_frame: u32, mara_frame: u32,
mara_dir: Direction, mara_dir: Direction,
mara_speed: i32,
bonk_timer: Option<u8>,
} }
impl Game { impl Game {
@ -25,21 +27,27 @@ impl Game {
prev_gamepad: 0, prev_gamepad: 0,
rng: None, rng: None,
mai_position: Point { x: 76, y: 48 }, mai_position: Point { x: 76, y: 48 },
mara_position: Point { x: 0, y: 64 }, mara_position: Point { x: 32, y: 90 },
mara_frame: 0, mara_frame: 0,
mara_dir: Right, mara_dir: Right,
mara_speed: 0,
bonk_timer: None,
} }
} }
fn update(&mut self) { fn bonk(&mut self) {
self.frame_count += 1; if self.bonk_timer.is_some() {
return;
}
palette::set_draw_color(2); tone(220 | (40 << 16), 6 | (6 << 8), 50, TONE_TRIANGLE);
text("Mara: Sh0rk of\nJustice 2\npowered by:\nsh0rk engine v0", 10, 10); self.bonk_timer = Some(12);
palette::set_draw_color(3); }
text("From Within, 2022", 10, 144);
sprites::MAI.draw(self.mai_position, 0); fn mara_walk(&mut self) {
if self.mara_speed == 0 {
return;
}
if self.frame_count % 15 == 0 { if self.frame_count % 15 == 0 {
self.mara_frame = if self.mara_frame == 1 { 0 } else { 1 }; self.mara_frame = if self.mara_frame == 1 { 0 } else { 1 };
@ -47,26 +55,84 @@ impl Game {
if self.frame_count % 4 == 0 { if self.frame_count % 4 == 0 {
if self.mara_dir == Right && self.mara_position.x >= 144 { if self.mara_dir == Right && self.mara_position.x >= 144 {
self.mara_dir = Down; self.mara_speed = 0;
self.mara_position.x = 144;
self.bonk();
} }
if self.mara_dir == Down && self.mara_position.y >= 120 { if self.mara_dir == Down && self.mara_position.y >= 120 {
self.mara_dir = Left; self.mara_speed = 0;
self.mara_position.y = 120;
self.bonk();
} }
if self.mara_dir == Left && self.mara_position.x <= 0 { if self.mara_dir == Left && self.mara_position.x <= 0 {
self.mara_dir = Up; self.mara_speed = 0;
self.mara_position.x = 0;
self.bonk();
} }
if self.mara_dir == Up && self.mara_position.y <= 64 { if self.mara_dir == Up && self.mara_position.y <= 64 {
self.mara_dir = Right; self.mara_speed = 0;
self.mara_position.y = 64;
self.bonk();
} }
const SPEED: i32 = 2;
match self.mara_dir { match self.mara_dir {
Left => self.mara_position.x -= SPEED, Left => self.mara_position.x -= self.mara_speed,
Right => self.mara_position.x += SPEED, Right => self.mara_position.x += self.mara_speed,
Up => self.mara_position.y -= SPEED, Up => self.mara_position.y -= self.mara_speed,
Down => self.mara_position.y += SPEED, Down => self.mara_position.y += self.mara_speed,
}; };
} }
}
fn update(&mut self) {
self.frame_count += 1;
if let Some(rem) = self.bonk_timer {
if rem == 0 {
self.bonk_timer = None;
} else {
self.bonk_timer = Some(rem-1);
}
}
self.mara_speed = 0;
let gamepad = unsafe { *GAMEPAD1 };
let just_pressed = gamepad & (gamepad ^ self.prev_gamepad);
let speed = if just_pressed & BUTTON_2 != 0 {
4
} else {
2
};
if gamepad & BUTTON_UP != 0 {
self.mara_dir = Up;
self.mara_speed = speed;
}
if gamepad & BUTTON_DOWN != 0 {
self.mara_dir = Down;
self.mara_speed = speed;
}
if gamepad & BUTTON_LEFT != 0 {
self.mara_dir = Left;
self.mara_speed = speed;
}
if gamepad & BUTTON_RIGHT != 0 {
self.mara_dir = Right;
self.mara_speed = speed;
}
self.mara_walk();
palette::set_draw_color(2);
text("Mara: Sh0rk of\nJustice 2\npowered by:\nsh0rk engine v0", 10, 10);
palette::set_draw_color(3);
text("From Within, 2022", 10, 144);
sprites::MAI.draw(self.mai_position, 0);
sprites::MARA.draw( sprites::MARA.draw(
self.mara_dir, self.mara_dir,

View File

@ -5,7 +5,9 @@ pub const GATE: Sprite<12> = Sprite {
width: 12, width: 12,
height: 14, height: 14,
flags: 1, flags: 1,
sprite: [ 0x3d,0x5a,0xa7,0xf5,0xaa,0x57,0xd6,0xa5,0x6b,0x1f,0xff,0xfc ], sprite: [
0x3d, 0x5a, 0xa7, 0xf5, 0xaa, 0x57, 0xd6, 0xa5, 0x6b, 0x1f, 0xff, 0xfc,
],
}; };
pub const MAI: Sprite<64> = Sprite { pub const MAI: Sprite<64> = Sprite {
@ -49,7 +51,7 @@ pub const MARA: SpriteAtlas<384> = SpriteAtlas {
0xff, 0xc0, 0x0d, 0xea, 0xab, 0x70, 0x0d, 0xea, 0xab, 0x70, 0x0d, 0xee, 0xbb, 0x70, 0xff, 0xc0, 0x0d, 0xea, 0xab, 0x70, 0x0d, 0xea, 0xab, 0x70, 0x0d, 0xee, 0xbb, 0x70,
0x0d, 0xee, 0xbb, 0x70, 0xeb, 0x03, 0xb7, 0xb0, 0xeb, 0x03, 0xb7, 0xb0, 0x0d, 0xea, 0x0d, 0xee, 0xbb, 0x70, 0xeb, 0x03, 0xb7, 0xb0, 0xeb, 0x03, 0xb7, 0xb0, 0x0d, 0xea,
0xab, 0x70, 0x0d, 0xea, 0xab, 0x70, 0x0d, 0xee, 0xbb, 0x70, 0x0d, 0xee, 0xbb, 0x70, 0xab, 0x70, 0x0d, 0xea, 0xab, 0x70, 0x0d, 0xee, 0xbb, 0x70, 0x0d, 0xee, 0xbb, 0x70,
0xea, 0xff, 0xde, 0xb0, 0xea, 0xff, 0xad, 0xf0, 0x00, 0x37, 0xdc, 0xc0, 0x03, 0x37, 0xea, 0xff, 0xde, 0xb0, 0xea, 0xff, 0xad, 0xf0, 0x03, 0x37, 0xdc, 0xc0, 0x03, 0x37,
0xdc, 0xc0, 0x03, 0x3e, 0xbc, 0xc0, 0x03, 0x3e, 0xbc, 0xc0, 0x3a, 0xaa, 0xfa, 0xb0, 0xdc, 0xc0, 0x03, 0x3e, 0xbc, 0xc0, 0x03, 0x3e, 0xbc, 0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