Log In  
:: Unfold ::

This is a simple demo of storing movement in speed and angle values instead of speed-x and speed-y. It shows a ball bouncing around inside a box.

Cart #39426 | 2017-04-08 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

up/down: change movement speed
left/right: change movement angle
x: pause movement
z: randomize the movement angle

Introduction to pico-8 angles:
right: 0
up: 0.25
left: 0.5
down: 0.75

The speed of the ball is stored as ball.speed and the angle is stored as ball.angle. When the ball moves, the program uses sin() and cos(), along with the speed and angle, to calculate how far to move the ball in each direction (x/y movement).


The advantage of storing the speed and angle speed-x and speed-y is that they are easier to change directly than manipulating x-speed and y-speed. For example, when the ball bounces off a wall, you can just change the angle and know that the speed will stay the same.

This demo calculates speed-x and speed-y every frame, which isn't really necessary. In a real program, you would probably want to store all four values: speed, angle, speed-x and speed-y, and only recalculate speed-x and speed-y when you change the speed or angle.

In the bounce_ball() function, the angle you provide is the angle of reflection. For example, a vertical line has an angle of 0.25 (it goes straight up) and a horizontal line has an angle of 0.5 (it goes straight left). You can tweak these angles if you want the ball to bounce off at a different angle.

P#39428 2017-04-08 17:07 ( Edited 2017-04-08 21:32)

:: Unfold ::

A while back, joshmillard posted Pico Jr, a fantasy-console-within-a-fantasy-console based on these specs:

"- 48*48 pixel four-tone greyscale graphics (so, colors 0, 5, 6, and 7 in the PICO 8 palette)

  • 2 channel sound
  • dpad and one button (other button could be reserved for meta-game/menu stuff)
  • 1 page of sprite sheet
  • standard sprite size of 6x6 pixels
  • dodgy slow-refresh LCD screen (could simulate this by checking screen buffer every frame and only allowing pixels to move one shade of grey toward whatever the target is)"

I extended Josh's prototype by overwriting most of the Pico-8 functions with wrappers that enforce the Pico Jr limits. For example, if you use pget(12,5), it will give you the value of pixel 12,5 on the Pico Jr screen instead of the Pico-8 screen. It will also give you a color from the Pico Jr palette of {0,1,2,3} instead of the actual Pico-8 values of {0,5,6,7}.

Some functions have been disabled entirely, for example:

  • No map support in Pico Jr
  • No direct memory access (poke, peek, memcpy, etc.). Sorry tweet-jammers.
  • No custom menus
  • No cart data (for the time being)

If you try to use any of the disabled functions, like memcpy() or map(), your code will crash with a syntax error.

Other limitations to be aware of:

  • I have hardly tested this at all. It's probably full of bugs.
  • Put your code into the usual _init(), _update() and _draw() functions. Bare loops won't render correctly. (Sorry again, tweet-jammers.)
  • Keep your code between the "your code below" / "your code above" blocks.
  • Avoid using function or variable names that begin with two underscores (__). That's how all of the backend functions are named, and if you use that pattern yourself, you might end up overwriting something important.
  • I didn't build in Josh's suggestion of 6x6 sprites. All the sprite functions are still based on standard 8x8 sprites.

Here's Josh's original Jump Guy, updated for the new dev kit.

Cart #29416 | 2016-09-26 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

And here's an empty cart, ready for your next portable game:

Cart #30036 | 2016-10-05 | Code ▽ | Embed ▽ | No License

I hope to come back to this and make an Asteroids clone or something. In the meantime, I hope this makes it easier to make more of these goofy mini-games.

P#29418 2016-09-26 02:09 ( Edited 2016-10-08 20:20)

:: Unfold ::

A while back, RhythmLynx posted a couple lowercase fonts that tried to use as little sprite space as possible. I had a lot of fun trying to pack the characters into overlapping regions on the sprite sheet to use even less sprite space.

But, recently I had an idea to skip the sprite sheet entirely and define each character as binary data that can be stored as a number in a table. This is the result. Press z to swap between demo text and a reference guide. The reference guide is stored on the sprite sheet, but is not used for the lowercase print function.

Cart #28452 | 2016-09-13 | Code ▽ | Embed ▽ | No License

Some explanation hidden...

A number in pico-8 is stored in 32 bits (4 bytes), something like this:

0 0000000 00000000 00000000 00000000
^ ^^^^^^^ ^^^^^^^^ ^^^^^^^^ ^^^^^^^^
| | integer part | | decimal part  |
| negative sign

In hexadecimal, the integer and decimal parts are separated by a period, just like in base 10.

a = 30.25
b = 0x1e.4

In Short Text, each character is laid out on a 4x8 grid. Each column is then treated as a byte and joined together into a number. For example, the letter "b" looks like this, where . is a blank pixel and # is a used pixel:


Converted to binary, starting from the bottom right and working up then left, we turn this into...

00000000 00001000 00010100 00011111

which, in hexadecimal, is written as 0x0008.141f, roughly 8.079.

So, we build a table that assigns this number to B.

chars\["b"\] = 0x0008.141f

Then, when we want to draw b, we just check each bit in that number and draw the ones that are set onto the screen.

Even though this method can store 4x8 characters, I only needed a 3x7 space for this font. I originally had a method that allowed me to store two characters per number, but the extra tokens necessary to handle the multi-letter storage outweighed the tokens gained by shortening the array.

The final approach is more flexible and could be used to swap in any custom font, maybe even m7kenji's kana font.

Small Text also allows you to force a default character by inserting a backslash before the character. Be careful: the backslash also has to be escaped, so your string has to look like "\e" to draw a capital E.

P#28345 2016-09-11 19:04 ( Edited 2016-09-18 02:13)

:: Unfold ::

Cart #18680 | 2016-02-07 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

Introducing Writer!, the PICO-8 word processor that nobody asked for. Writer! would have been distributed with the PICO-8 (fantasy) keyboard peripheral, which plugs into both controller ports. Don't have a PICO-8 keyboard of your own? Your standard keyboard's WE, ASDF, XC and arrow keys should emulate the correct inputs.

P#18682 2016-02-07 00:09 ( Edited 2016-02-07 05:09)

Follow Lexaloffle:          
Generated 2023-10-04 10:48:13 | 0.073s | Q:19