Log In  


Cart #autofire-1 | 2022-01-07 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
2

TO LOAD THIS CART IN PICO-8, type in immediate mode: load #autofire

VVhat's new ?
(01-07-22)
✅ Added menu to reload after selecting an option instead of closing like earlier.

There have been many Pico-8 game players wanting to have autofire ability, mostly for shooters and auto-selection RPG choices, and in some cases players want to be able to swap the O and X buttons.

Well this program has a foundation that is about as simple as you can get.

In it you use 6-single key variables, ⬅️ ➡️ ⬆️ ⬇️ 🅾️ ❎ which can be easily typed in Pico-8 source-code by holding down the shift key and pressing any of L R U D O X which will appear as a special non-ASCII character.

If any of these variables are TRUE, then that means the player is holding down the button for the corresponding switch.

However, if you pause for the MENU with P or ENTER you will see 3-new options.

AUTOFIRE 🅾️ ON
AUTOFIRE ❎ ON
SWAP 🅾️ AND ❎

In selecting the first or second options, you will now have variable 🅾️ or ❎ stagger its shots. And of course in selecting one or the other it does not automatically turn autofire on both buttons. You get to select which, none, first, second, or both.

The last option is pretty self-explanatory. It will swap reading the 🅾️ AND ❎ buttons thus later if selected and you press the 🅾️ button, the ❎ variable will become true and vice-versa.

Feel free to examine the code and see what is happening here. The code in _UPDATE() is about as simple as it can get it. In _INIT() call function initbuttons().

In your main program when you are ready to read keystrokes, call the function getkeys().

function _update()
  n=1
  cls()
  getkeys()
  if ⬅️ then
    n=2
    x=x-1
  end
  if ➡️ then
    n=3
    x=x+1
  end
  if ⬆️ then
    n=4
    y=y-1
  end
  if ⬇️ then
    n=5
    y=y+1
  end
  if 🅾️ then
    n=6
  end
  if ❎ then
    n=7
  end
  spr(n,x,y)
end

Where you type each of the special arrows above by holding down the SHIFT key and L, R, U, and D respectively.

And that's it ! The rest is handled automatically.

It is my wish that future Pico-8 will have these options automatically available for any cart, and can be optionally turned on or off to appear in menus and to select your autofire rate, currently defined in _init().

Hope This Helps !

2


Hi dw,
IIRC there's a poke that changes the btnp repeat delay, so you don't have to handle it yourself.


Hi @ultrabrite. Yes there is. I didn't know if I wanted to go that route though as I am not covering BTNP(). Someone might decide to either go with the default speed for it or a custom one.

That can be reached via:

POKE(0X5F5C, DELAY) -- SET THE INITIAL DELAY BEFORE REPEATING. 255 MEANS NEVER REPEAT.
POKE(0X5F5D, DELAY) -- SET THE REPEATING DELAY.

Yet it is something to consider adding to the menu, especially if this menu is somehow hardcoded for future Pico-8.



[Please log in to post a comment]