Log In  


So, I decided to try and make a thing where you can select 1 character and move that character, and then switch characters and start moving the other one, I got this idea from PolyMars, but I have one issue: How do I detect when 1 or 2 is pressed on the keyboard?
Code:

x1 = 64
y1 = 64
x2 = 64
y2 = 64
cur = 1
function _update()
  if (btn(0) and cur==1) x1-=1
  if (btn(1) and cur==1) x1+=1
  if (btn(2) and cur==1) y1-=1
  if (btn(3) and cur==1) y1+=1
  if (btn(0) and cur==2) x2-=1
  if (btn(1) and cur==2) x2+=1
  if (btn(2) and cur==2) y2-=1
  if (btn(3) and cur==2) y2+=1
  if (btnp(1)) cur=1
  if (btnp(2)) cur=2
end

function _draw()
  cls(0)
  spr(1,x1,y1,8,8,false,false)
  spr(2,x2,y2,8,8,false,false)
end


Do you want to use specifically the keyboard numbers 1 and 2 or would the buttons X and O work? Because if you use btnp(4) and btnp(5) to change the cursor, that would reference the buttons; referencing keys that aren't on the controller is harder.


1

There is a way to detect keyboard presses: https://www.lexaloffle.com/dl/docs/pico-8_manual.html#Mouse_and_Keyboard_Input

But PICO-8 pretends to emulate a console that used controllers with 6 buttons, the keyboard being part of the «development kit», so for maximal compatibility with all the devices that people play on, it is best to use the standard buttons only (or an item or location in the game that makes you switch characters).


I agree with merwok.
Or if your game is not particularly arcade-action intensive and allows it you could use a specific Combo?
For instance 🅾️+⬆️?

 if (btn(4) and btnp(2)) cur=cur%2+1

Basically any combo that the player wouldn't do in the usual gameplay.

Edit: forgot to mention this is a "toggle player" solution, so you press the same combo and it switches 1 to 2 and vice-versa.


Years ago I wrote a comprehensive button input library specifically for the 🅾️ and ❎ buttons and arrow keys, @GamingGo2011. You can find that here:

https://www.lexaloffle.com/bbs/?tid=31927

Very recently I wrote one for the mouse, or to be more specific, the "finger."

https://www.lexaloffle.com/bbs/?tid=48075



[Please log in to post a comment]