From 037d6a5d54988917f12056055aa51389edf1d525 Mon Sep 17 00:00:00 2001 From: Jessie Williams Date: Sun, 6 Mar 2022 21:40:57 -0500 Subject: [PATCH] let you walk around the title screen Signed-off-by: Jessie Williams --- sprites/Mara.png | Bin 391 -> 391 bytes src/lib.rs | 100 +++++++++++++++++++++++++++++++++++++++-------- src/sprites.rs | 6 ++- 3 files changed, 87 insertions(+), 19 deletions(-) diff --git a/sprites/Mara.png b/sprites/Mara.png index 66efa9a3c882fdded50d4192cd7237bd29c4a9f0..5ac24ff557b16fa8d6305749c4e37a3eeb99b466 100644 GIT binary patch delta 297 zcmV+^0oMM91BU~UXMc_aAqYf))c=3;A{P}JA0}D5Gx0cDAeK!8fTCIVSKfUp?V7~` z_)=jEEaI|=UgMOJ8sRXQ^_uvus3II5jcXET=TrNag` z!I8u7Ml$e!1n`^BZSUw6Z8YZCu00000NkvXXu0mjf=E0Fx delta 297 zcmV+^0oMM91BU~UXMe6kAqYf)%>RG$;p$ezhbG51jmzqQI7$S7vU&GcUVS>+Hj4#_ zrNS6kBxI4j#w8T!N|C*?X$TD!MZ4EbJc)3`SH$bibb8 z$=(k=osOA95j=6#Q3q_z#aXTtq?uLf({H>E&PKifi_;7YuYWr|*mlc;iMB(C~JJ*4iX*!o6ZR>Lr vN5J?08EXx6&LRa@!xN?, } 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, diff --git a/src/sprites.rs b/src/sprites.rs index 7ad9506..6765ab9 100644 --- a/src/sprites.rs +++ b/src/sprites.rs @@ -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,