let you walk around the title screen
Signed-off-by: Jessie Williams <quorawings@gmail.com>
This commit is contained in:
parent
9c44fdd4f6
commit
037d6a5d54
BIN
sprites/Mara.png
BIN
sprites/Mara.png
Binary file not shown.
Before Width: | Height: | Size: 391 B After Width: | Height: | Size: 391 B |
100
src/lib.rs
100
src/lib.rs
|
@ -16,6 +16,8 @@ struct Game {
|
|||
mara_position: Point,
|
||||
mara_frame: u32,
|
||||
mara_dir: Direction,
|
||||
mara_speed: i32,
|
||||
bonk_timer: Option<u8>,
|
||||
}
|
||||
|
||||
impl Game {
|
||||
|
@ -25,21 +27,27 @@ impl Game {
|
|||
prev_gamepad: 0,
|
||||
rng: None,
|
||||
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_dir: Right,
|
||||
mara_speed: 0,
|
||||
bonk_timer: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn update(&mut self) {
|
||||
self.frame_count += 1;
|
||||
fn bonk(&mut self) {
|
||||
if self.bonk_timer.is_some() {
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
tone(220 | (40 << 16), 6 | (6 << 8), 50, TONE_TRIANGLE);
|
||||
self.bonk_timer = Some(12);
|
||||
}
|
||||
|
||||
sprites::MAI.draw(self.mai_position, 0);
|
||||
fn mara_walk(&mut self) {
|
||||
if self.mara_speed == 0 {
|
||||
return;
|
||||
}
|
||||
|
||||
if self.frame_count % 15 == 0 {
|
||||
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.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 {
|
||||
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 {
|
||||
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 {
|
||||
self.mara_dir = Right;
|
||||
self.mara_speed = 0;
|
||||
self.mara_position.y = 64;
|
||||
self.bonk();
|
||||
}
|
||||
|
||||
const SPEED: i32 = 2;
|
||||
match self.mara_dir {
|
||||
Left => self.mara_position.x -= SPEED,
|
||||
Right => self.mara_position.x += SPEED,
|
||||
Up => self.mara_position.y -= SPEED,
|
||||
Down => self.mara_position.y += SPEED,
|
||||
Left => self.mara_position.x -= self.mara_speed,
|
||||
Right => self.mara_position.x += self.mara_speed,
|
||||
Up => self.mara_position.y -= self.mara_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(
|
||||
self.mara_dir,
|
||||
|
|
|
@ -5,7 +5,9 @@ pub const GATE: Sprite<12> = Sprite {
|
|||
width: 12,
|
||||
height: 14,
|
||||
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 {
|
||||
|
@ -49,7 +51,7 @@ pub const MARA: SpriteAtlas<384> = SpriteAtlas {
|
|||
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,
|
||||
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,
|
||||
0x3a, 0xaa, 0xab, 0xb0, 0x00, 0x37, 0xdc, 0x00, 0x00, 0x37, 0xdc, 0x00, 0x00, 0x3f,
|
||||
0xfc, 0x00, 0x00, 0x3f, 0xfc, 0x00, 0x3a, 0xaf, 0xd5, 0xf0, 0x3a, 0xaf, 0xd5, 0xf0,
|
||||
|
|
Loading…
Reference in New Issue