Created
November 27, 2022 03:24
-
-
Save VyrCossont/5c82eddd1d991c45adb73daa21d38101 to your computer and use it in GitHub Desktop.
Pinput patch for PICO-8's Jelpi demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- jelpi.p8 | |
+++ jelpi.p8 | |
@@ -1,9 +1,51 @@ | |
pico-8 cartridge // http://www.pico-8.com | |
-version 30 | |
+version 38 | |
__lua__ | |
-- jelpi demo | |
-- by zep | |
+-- modified for pinput | |
+-- by @[email protected] | |
+#include pinput.lua | |
+ | |
+function pi_vibe_all(on) | |
+ if not pi_is_inited() then | |
+ return | |
+ end | |
+ local lvl = 0x00 | |
+ if on then | |
+ lvl = 0xff | |
+ end | |
+ for pl = 0, pi_num_players - 1 do | |
+ if pi_flag(pi_haptic_device, pl) then | |
+ for actuator = pi_lo, pi_hi do | |
+ pi_rumble(actuator, lvl, pl) | |
+ end | |
+ end | |
+ end | |
+end | |
+ | |
+function pi_reset_vibe() | |
+ pi_vibe_frames = 0 | |
+ pi_vibe_all(false) | |
+end | |
+ | |
+function pi_update_vibe() | |
+ if pi_vibe_frames > 0 then | |
+ pi_vibe_frames -= 1 | |
+ else | |
+ pi_vibe_all(false) | |
+ end | |
+end | |
+ | |
+function pi_add_vibe(frames) | |
+ pi_vibe_frames += frames | |
+ pi_vibe_all(true) | |
+end | |
+ | |
+ | |
+-->8 | |
+ | |
level=1 | |
num_players = 1 | |
@@ -102,12 +144,16 @@ | |
-- called at start by pico-8 | |
function _init() | |
+ pi_init() | |
+ pi_reset_vibe() | |
+ | |
init_actor_data() | |
init_level(level) | |
menuitem(1, | |
"restart level", | |
function() | |
+ pi_reset_vibe() | |
init_level(level) | |
end) | |
@@ -235,6 +281,7 @@ | |
if ((btn(4,b)) and | |
pl.standing) then | |
pl.dy = -0.7 | |
+ pi_add_vibe(5) | |
sfx(8) | |
end | |
@@ -268,6 +315,7 @@ | |
pl.dy = pl.dy - 0.2 | |
end | |
+ pi_add_vibe(5) | |
sfx(11) | |
end | |
@@ -323,7 +371,7 @@ | |
if (m.life<=0) then | |
bang_puff(m.x,m.y-0.5,104) | |
- | |
+ pi_add_vibe(15) | |
sfx(14) | |
return | |
end | |
@@ -725,6 +773,8 @@ | |
end | |
function _update() | |
+ | |
+ pi_update_vibe() | |
for a in all(actor) do | |
a:move() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment