Log In  

@dw817

Follow
Follow

Just another mad coder.

We're all mad. I'm mad. You're mad, you must be - or you wouldn't have come here.

Find my books and biographical works HERE:
http://www.writerscafe.org/dw817

Hyperspace or falling into a black hole. Whichever you think it might be. In any case, thought I would create a new post for this example. Earlier I was explaining some of the interesting things you can do with the PALETTE.

Here is a small example using all 15-colors of the 16-total. It uses the exact same principle you see as the snowflake animation found HERE:

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

So in the animation itself, no pixels are actually being drawn or moved. Only the palette is manipulated. Two per animation cycle at 30fps and likely using zero CPU if any at all despite how many sprites "appear" to be moving.

-- falling into a black hole
-- written by dw817 (11-15-19)

-- standard ⌂ pico-8 license

function main()-------------->>

cls()
for i=0,127,2 do
  pline(64,64,i,0)
  pline(64,64,127-i,127)
  pline(64,64,0,i)
  pline(64,64,127,127-i)
end

circfill(64,64,16,0)

for i=1,15 do
  pal(i,0,1)
end

i=0
repeat--forever
  pal(i+1,7,1)
  flip()
  pal(i+1,0,1)
  i=(i+1)%15
until forever 

end--<<------------------------

-- get random # from a to b
function rand(a,b)
  if (b==nil) return flr(rnd(a))
  if (a>b) a,b=b,a
  return a+flr(rnd(b-a+1))
end

-- draw a line from point to
-- point, starting with a
-- random color and stretching
-- it the further it travels.
function pline(a,b,c,d)
local px,py=c-a,d-b
local ax,ay=abs(px),abs(py)
  if ax>ay then py/=ax px=sgn(px) else px/=ay py=sgn(py) end
  e=rand(0,14)
  f=5
  repeat
    pset(a,b,e+1)
    e=(e+f)%15
    f/=1.06
    a+=px b+=py
  until abs(a-c)<1 and abs(b-d)<1
ff=f
end

main()

Now imagine if Pico-8 could work with 256-colors for their palette instead of this simple 15 ? :)

P#69932 2019-11-15 23:35 ( Edited 2019-11-16 01:36)

 
gt
by dw817
Cart [#gt-1#] | Code | 2019-11-15 | License: CC4-BY-NC-SA | Embed

Wait a minute. Strike that.

Reverse it. Thank you.

Actually this should be titled, "A Tribute To Glowing."

Standard graphics on modern computers today do NOT have a palette. So - what exactly is the difference between graphics that use a palette and that which does not ?

Well generally one that does not means you have total freedom. That is if you can have 256-brightness levels for Red, Green, and Blue, why then you have a total of 16,777,216 colors available per pixel to you !

Nice indeed. So how does this differ from a system that uses a palette ?

well it all started years ago. Let's go back to QBasic for the IBM-pc which would let you have a choice. A 640x480 B&W pixeled screen, a single 320x240 256-color screen, or sixteen 320x240 16-color screens.

Let's go through each of these.

The 640x480 B&W is pretty easy to understand. You have high detail but can only use 2-colors, black and white. And while you can change the palette for each of them, it's not very useful.

Then we have the 320x240 256-palette screen. Let's cover this now.

In your graphics you can set a single number from 0-255 per pixel. This is NOT a true Red, Green, Blue representation as if it were you would only have up to 216-colors available as 6-levels of Red, Green, and Blue total 216. No, it's not that.

It's more an ID code stating that at this exact pixel location you want to plot the color that is from the original PALETTE table, zero usually being red zero green zero and blue zero and 255 being red 255 green 255 and blue 255. In this you could specify exactly which of the 16-million color choices you wanted to have appear for that single ID of a number from 0-255.

You choose the pixel to plot on the screen and THEN you can use POKE() to change what the color actually appears as, and then you can select any of the 16 million colors. So - how is this useful in animation ?

You can for instance make a water pattern using one color, increase that color by one and continue to draw in the same tile the water pattern were it to move. When you're done, using 8 or 16-colors or what have you, you CYCLE the palette. That is let's say you are using colors #1-8 to represent animated water.

Then color #1 would be the brightest color, white, then start to get darkest at #4 and start to get bright again at #8 but not as bright as #1. Then you rotate the palette like this:

1 2 3 4 5 6 7 8
2 3 4 5 6 7 8 1
3 4 5 6 7 8 1 2
4 5 6 7 8 1 2 3
etc.

And it would appear as if the water were MOVING, shifting from bright shades of blue to darker shades, all using only one graphic tile and 8-colors of your available 256 to create the animation effect.

The last QBasic mode gives you 16-screens to work with at 16-colors per screen at a resolution of 320x240. While you would use up half of your entire available list of colors if you tried to use 8 for water, you can do what I did here, which was to make color #15 cycle from black to red and back again.

As it is a single color and we are merely changing the color on how it appears, I included a few additional high-colors (>128) to give a nice animated glowing effect.

Here is the table for it, with the lowest # being black and highest being full red.

0, 1, 2, 3, 4, 3, 2, 1, 0

So after 4-machine cycles the red will be the brightest. The cycles after that it starts to get dark again, finally black, and repeating itself.

And this is not an uncommon programming and animation technique. Many Commodore Amiga demos and games used this color-method to animate. For instance let's try a different type of 8-color set. Let's say the first is white and the remaining 7 after it are black. This can be accomplished with the current code for the cart above. In the sourcecode, change MODE to zero instead of one.

1 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 0
etc.

[8x8]

In this you could have rain coming down from a black sky, flittering snow, or show complex movement like gears, electricity, or anything else that would use a black background and has 8-animations included into it by using each animation step per color used.

Heck I remember years ago I wrote a program called "Seaweed." In it, it drew water, bubbles, and the seaweed both above and below the screen.

Then the actual program only cycled the colors. The water moved, the bubbles churned from the bottom to the top and the seaweed shimmered and seemed to move as brightness layers were both added to and removed from it. All entirely by cycling a palette. No pixels were plotted nor were any moved or shifted. Just - changing the palette.

I did this for a hyperspace effect too, using all 255-colors in this case for the star patterns.

Now if Pico-8 ever does go 256-colors where you can change the palette for each, I could easily write code to demonstrate these advanced animation methods.

As it is we are limited to 16 but you can definitely see how changing one color gives it a glow effect. And you can use that single color on any other tile you draw. With the code provided it will always pulse from black to red and black again.

Same with the 8-colors for the "snow" effect. Have one of those colors lit all the time with the others black or dark and you will get the movement effect.

HOPE THIS HELPS !

P#69928 2019-11-15 20:50

 
hg
by dw817
Cart [#hg-6#] | Code | 2019-11-12 | No License | Embed
2

Hold (O) to see the cycle of life.
TO LOAD THIS CART in immediate mode type:

load #hg

While the cart I'm working on now (and have been for several days) is quite a bit bigger than 560-bytes (hundreds of lines), seeing Conway's life program reiterated reminded me of my Father.

For years ago he wrote a program in Turbo Pascal he called the "Cycle Of Life."

In it, he had 3-different colored pixels randomly appearing on the screen in a 640x480 screen.

He told me that one pixel chases the other and the last chases the first. I really didn't understand him so he explained it to me.

Red chases yellow.
Yellow chases green.
Green chases red.

I thought about it for a-while and thought that was a pretty nifty thing. He later went on to make a very complex program he simply called, "LIFE." where there were gray dots all moving on the screen. If one got boxed in though he would turn red and start killing the gray.

If enough people saw red dots (bodies), they would take it upon themselves to become a policeman (turning blue), and running into the killer would apprehend him. (turning him into a white pixel), imprisonment my Dad said. Where he could not move from that spot but could still be seen by other citizens.

Then if they moved for a long time without finding any killers (red dots), they would revert back to gray (citizen) and the life program would continue, although the prisoner would remain.

At the time I thought it was a very complex thing and really beyond what I could code.

But I did understand the earlier program he wrote where 3-colors chased each other.

Thinking to the chess game, the foxes and the geese, I thought it would be interesting to change it from colored dots to actual pictures. Where red was the fox, yellow was not geese but rabbits as I liked drawing rabbit icons back then (S1), and the green was the grass.

So the new cycle of life was:
Foxes eat rabbits.
Rabbits eat grass.
Grass eats foxes.

When I wrote this back in QBasic so many years ago, someone questioned how the grass could eat the foxes. A valid question !

I told them that the foxes were carnivorous and grass means no meat, so they die out if it encroached on their territory. Ah, a good enough answer for the time I thought. :D

And thus is what you have here, tweetable, meaning it is 560-characters or less.

I think it demonstrates an interesting idea that is quite a bit different than "Conway's" game of life.

It also includes the sprites for the grass, foxes, and rabbits, as part of the source-code so it runs right out of the box ! I call it, "The Hunting Grounds."

Here is the source-code, exactly at 560-chars.

-- hunting grounds
-- written by dw817 (11-12-19)
r,m,n,e,d,c,s=rnd,mget,mset,{2,3,1},{-1,0,0,-1,1,0,0,1},0,"3000000049404940666066600b000000044444006e606e6000300000499999406e606e600000000044a9a44066666660000000300449440006e6e60000000b00004940000666660000003000000e000000676000"
for i=0,167 do sset(i%24+8,i/24,"0x"..sub(s,i+1,i+1))end
for i=0,224 do mset(i%15,i/15,r(3)+1)end
repeat
x,y=r(15),r(15)s,w=flr(r(4))*2+1,m(x,y)
h,v=x+d[s],y+d[s+1]
if m(h,v)==e[w]then n(h,v,w)end
c=(c+1)%32if c==31 then cls()map(0,0,4,4,15,15)repeat flip()until btn(4)end until z

Hold down the (O) key and watch the CYCLE OF LIFE ...

VVhat's going on ?

Random foxes, rabbits, and grass are drawn first on the playfield.

[8x8]
A random position is chosen.

[8x8]
A random direction is chosen. One of up, down, left, or right.

If that random spot can "eat" in that single direction chosen, it will convert that food to the same identity as itself thereby "spawning."

Then the cycle is repeated.

[8x8]

  • The foxes will win if the rabbits eat all the grass.
    [Predator] Foxes
    [Food] Rabbits

[8x8]

  • The rabbits will win if the grass manages to push out all the foxes.
    [Predator] Rabbits
    [Food] Grass

[8x8]

  • The grass will win if the foxes eat all the rabbits.
    [Predator] Grass
    [Food] Foxes (They encroach on their area and drive them out).

And WHO WILL WIN ? Will it be the foxes, the rabbits, or the grass ?
It is entirely possible for one to fill the field entirely.

P#69852 2019-11-12 20:31 ( Edited 2019-11-13 02:05)

[128x128]

You may have seen a few carts show impossible logos both in the BBS and in Splore. Impossible in the fact that you scan both code and memory to see where the logo is but it's nowhere to be found.

So - just how did they get that logo on there in the first place ?

Well, with a little bit of trickery, actually. You can do the same thing in truth.

Load up your cart. In immediate mode type:

export spr.png

to export your tiles to a temporary file.

Then type:

import logo.png

The 128x128 logo that you want.

At the bottom of your code or the first lines in _init() add:

memcpy(24576,0,8192)
repeat until forever

Run that. when the logo appears, press F7 to save that as the logo for your cart.
Press [ESC] to exit.

Then return back to your code, remove those two lines of code and back in immediate mode type:

import spr.png

To recover your original sprites, and you are done.

Save your program if you like and of course to export to the BBS use either SAVE "@CLIP" or save your program as a .PNG, and you are done.

When a preview of your game appears, it will show the logo you imported that for both the code and images that are no longer there.

HOPE THIS HELPS !

P#69767 2019-11-09 23:52 ( Edited 2019-11-10 02:15)

 
sa
by dw817
Cart [#sa-0#] | Code | 2019-11-05 | License: CC4-BY-NC-SA | Embed

To load this program in Pico-8, type:

load #sa

Shuffling a deck of cards on a computer has come a long way, hasn't it ?

The classic method is to go through each card one at a time and shuffle them by taking the index card and swapping it with a random card anywhere in the deck.

The problem with this method is that after a shuffle if the first card is say 2 of Spades, then you already know the next card will be Ace of Spades. So, yeah, it's not perfect.

Another way is to create a table picking a random number from 0-51 adding it to an array until the deck is filled. This will work but it can be slow once it gets near the end picking that random number from 0-51 to get that very last card that is not in the deck.

Thus future coding now has two interesting commands, ADD and DEL.

Add will do just that, add a value on to an existing array placing it right at the end. If it's the first item, obviously it goes in the first place. But each new successive item is placed on the end. So if you wrote code like this:

a={}
add(a,1)
add(a,2)
add(a,3)

Then a would be an array starting with index 1 and contain 1, 2, and 3.

Now here is where DEL comes in and it's quite powerful what it does. In older code if we wanted to remove an item from an array you would have to create a reverse FOR/NEXT loop to copy all the older items one step above the item you were removing. I did this back in S2 and it was not speedy.

However, you do not need to do this in Pico-8, for instance, let's take our original code and remove the middle item:

a={}
add(a,1)
add(a,2)
add(a,3)
del(a,a[2])

Now the results are 1, 3. So with this in mind it does indeed ADD and DELETE items from the array. Doing so we can now make a proper SHUFFLE routine, where every single item in the array can be plucked out randomly, added to a separate array with ADD and neatly sealed closed from the original array with the DEL command.

And it does not swap existing items but actually pulls out each and every single item randomly to be placed in a 2nd growing array.

That is exactly what I am doing in this code, note two functions of use. SHUFFLE() which can shuffle a numeric or string array of any size as well as a function just for this code called PLOTCARD() which draws a small playing card on the screen.

Combining these functions you get a very good card shuffling routine that needs only one pass to make a perfect and completely random shuffle of a deck of cards, using our friend commands, ADD and DEL.

P#69671 2019-11-05 21:42 ( Edited 2019-11-05 22:35)

Was just experimenting with arrays, starting to understand NEW and DEL a little better, when I came across this:

set={}
for i=1,6 do
  set[i]=i
end
newset=set
newset[3]=0
?set[3]

What gives ? The correct answers should be "3."

Normal BASIC with "newset=set" would just copy the array to a new array and let you work with it as a new array. You can't do this in Pico-8 as apparently it's just a shortcut to the original array ?

Is there a way to copy one array to another easily ? Like newset=set{} or something ?

P#69666 2019-11-05 20:27 ( Edited 2019-11-05 20:29)

 
dx
by dw817
Cart [#dx-2#] | Code | 2019-11-05 | License: CC4-BY-NC-SA | Embed

To load this cart in Pico-8, type:

load #dx

VVhat's new ?

  • Now does not show maze-drawing process.
  • Fixed up sprites a bit.
  • Am researching recursion as a possible maze-maker.

This is not so much a game (although you can play it) as a proof of concept.

Something I've wanted to do is have code that automatically builds a fairly large dungeon, in this case 125x125 tiles is a fine testing area and build a maze that cuts the edge of the walls intelligently leaving space for the player to move around, so the corridors are not 1x1 tile in size but actually 3x3 floor space and 2x2 walls.

When you start getting down to having a regular sized dungeon you'll find that the mapper space provided really isn't very big, a maximum of 128x64 and that's only if you sacrifice some of your sprite space for it.

What better way to use the mapper then to create an array for what you need in the map, in this case 125x125 and then draw only the bits you need to the mapper and then just use the MAP() command for that particular area only.

Then intelligently draw black edges around the walls to separate them from the floor, something the default Pico-8 mapper cannot yet do but is included in this code.

Then you get to explore using the arrow keys. Hold two arrow keys to travel a bip-bopping diagonal.

Hold (O) to run instead of walk, and tap (X) to bring up a map of where you've traveled so far or again to hide it so you can focus on the full display.

Your mission is a fairly easy one. Locate the nice cottage in the center of the dungeon and touch it to complete the quest. Know well though that from where you start, there is only one guaranteed path to reach it. And that path is randomized every single time you start a new game.

Also includes torches that flicker, view the code to see how it's done.

Also see unique code of:

  • Constants, _1=true, _0=false.
  • Correct sgn() function where 0 returns 0.
  • Range function where a number is checked to be within a range and returns true if it is.
  • Good generate random number within set range. Negative number ranges are also acceptable.
P#69643 2019-11-04 23:22 ( Edited 2019-11-05 19:27)

I was just watching a video about Loot Boxes and how Online games charge players real money in order to gain these items, which apparently are random items that can benefit the player to progress further in them.

Outlawed in several countries apparently.

https://www.pcgamer.com/the-legal-status-of-loot-boxes-around-the-world-and-whats-next/

And this is new stuff for me, the first I've heard of it. I know, now you can think on that a bit if you like. Sometimes I get so wrapped up in coding I'm unaware of the world around me.

However, I was thinking this might be something good and nice to have for Pico-8.

Not real loot boxes, not the ones that cost money anyways. But no, perhaps missions a player could go on in some of these advanced Pico-8 carts. The reward ? A loot box, completely free, earned by the dedication (and perhaps perspiration) of the player to go beyond the call of duty on side-quests and other items that the average player may skip over in their haste to see the ending to the game.

It's something to consider, and would definitely be icing on the cake of very fine and excellent Pico-8 carts already produced and written or in the process of being written.

There was something existing like this with the Gacha game by the very talented, @enargy.

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

And while it's grand fun, unfortunately that's all it was, a bit of a loot box. Where you get a new card every hour or so but no actual gameplay otherwise to earn them.

I think this could be worked into games where you play, you work at it real hard, and congrats, you finally won the game. But that's not the end of it. As you went through the game you did not see all the secret paths and secret doors that opened up the rest of the game. Or perhaps you saw them but could not access them. Playing and winning the game might get you 25% of finding everything in the game.

It's up to you to play multiple times to find every and all secrets.

And of course for locating one or more of these hard-to-find secrets, you are rewarded with ? A Loot Box.

The Loot Box might have items that let the player jump higher to access areas they could not when they went through the first pass on the game. Perhaps swimming gear so they can finally dive in the water and not drown. Special boots to let them cross hot lava. Special weapons and/or armor, new playable characters, new NPCs to meet, new story paths to follow, you name it.

It could open up paths previously locked but now could be opened since the player has the matching key.

It could have collectable sprites that you can bring up to put on a shelf to view them in detail (with accompanying description) later. I think Brave Fencer Musashi has this ability.

https://youtu.be/oow6QlDqZ0M?t=192

Just like we collect prizes from Cracker Jack or a cereal box, they are collectable.

The Loot Box would have something in it, whether it's a platformer, racer, shooter, fighter, battler, RPG, puzzle, whatever it might be. It might have something in it that would help the player and encourage them to play your game "Just one more time" so they can explore that new area they couldn't earlier.

What are your thoughts ? And are there any existing Pico-8 games that do in fact have Loot Box prizes for outstanding ability or perseverance in gameplay ?

P#69573 2019-11-01 22:27 ( Edited 2019-11-02 18:04)

 
dt
by dw817
Cart [#dt-0#] | Code | 2019-10-28 | License: CC4-BY-NC-SA | Embed
2

TO LOAD THIS CART, type the following in immediate mode:

load #dt

You've probably seen some pretty amazing things in graphic demos done for Pico-8, none to me more satisfying than the dither effect I've seen between two colors, where one side of the screen is black, the other white, and a complex and beautiful pattern between both showing a kind of fade ability using only the same-color pixels.

The fill pattern is by @Megus, and you can find his demoscene cart HERE:

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

Now while he and his crew have made an amazing demo, this tutorial and focus will be only on the dither technique used to create a division between two-colors. While it looks great on 3-dimensional models, it is also quite a thing of beauty to appear even on the screen just by itself.

So, exactly how is this being done ? And why is dithering an important element in graphics ?

First off, Pico-8 has an ability to "shade" pixels automatically with the FILLP() command, so that is how it is being done. Why is it important ? They give the illusion of varying degrees of shade between two colors. Let's take this picture for instance:

Now let's first off convert it to Pico-8's palette:

Obviously it loses some of its quality. But what about this ? Where the picture is comprised of only two colors, black and white ?

While you can adjust the brightness to show more detail, you are still limited to the lost pieces that are too dark or too light to show.

So, how can dithering help this ? Let's see a few. Here is a dither using what is called, ORDERED. It's good, fast, certainly better than straight out B&W, but could be improved upon.

In fact improving this default has always been a bit of a science and artistic thing. Perhaps the most common and popular is the Floyd-Steinburg method thus:

A dramatic improvement. You can find more about this favored method of converting multi-color pictures to a smaller palette, or even just B&W as seen HERE:

https://en.wikipedia.org/wiki/Floyd%E2%80%93Steinberg_dithering

For further research there is also the Burkes and Stucki method, both included on this page:

.

https://en.wikipedia.org/wiki/Dither

But now let's get back to the code here.

What this does is create an array that holds 16-numbers. The dither table itself is stored in Sprites comprised of 4 8x8-pixeled sprites altogether. 8 4x4 patterns across at the top, and 8-more 4x4 patterns at the bottom, yielding 16 in all.

Each of them represent a "winking out" of each of the 4x4 pixels, where the BLUE pixel represents the pixel being added to the total "wink outs" so you can easily track them, or even develop your own. The background colors are there for a guide only.

[32x8]

The current selection of pixels and which are added at what position are done SO in such a precise and perfect way that when spread across the screen, creates a beautiful dithering effect. Which of course can be used to render 3-dimensional objects in Pico-8 with varying degrees of shades to emulate the lack of hardware colors inherent to Pico-8, or can be used simply to create a nice transition between two colors.

See the sourcecode for more details, chock full of remarks on how to code and write your own rectangular dithers and to fully understand the command FILLP(). Thus ends the tutorial.

HOPE THIS HELPS !

P#69408 2019-10-28 20:00 ( Edited 2019-10-28 21:11)

Cart [#nine_keys-3#] | Code | 2019-10-27 | License: CC4-BY-NC-SA | Embed

TO LOAD THIS in Pico-8 type:

load #nine_keys

I am not at all certain if Pico-8 runs 100% correctly on Android and cellphones. I would like to think that if it is not, that @zep is certainly doing his level best to ensure that it can.

This program is fairly simple but opens up input, especially for a touchscreen Android and touchscreen cellphone.

I had originally worked this into a complex cellphone driven programming language earlier with 15 buttons in a 5x3 format, but the language is cumbersome, slow, and not at all user-friendly.

So I have put it here. You can test it with the mouse if you like.

6 buttons are already active.

  • Press the middle up for UP.
  • Press the middle left for LEFT.
  • Press the middle right for RIGHT.
  • Press the middle bottom for DOWN.
  • Press the top-left for INCREASE FOLLOWERS.
  • Press the top-right for DECREASE FOLLOWERS.

Press (X) by itself to swap between showing the nine buttons or hiding them.

And of course this program is using standard _init(), _draw(), and _update() chock full of remarks to guide you. So you can reconfigure all 9 of these buttons for your use and their definitions and actions.

HOPE THIS HELPS !

P#69369 2019-10-27 20:49 ( Edited 2019-10-28 04:21)

Cart [#sufehasede-0#] | Code | 2019-10-25 | No License | Embed

I was interested in making a type of high-number integer counter relying on the length and accuracy of 4-digit decimal numbers less than 1 when I came across this little slice of misfortune.

Here is the source to see there is no complication on my part:

-- real numbers are flawed!

function key()
  repeat
    flip()
  until btnp(4)
end

b=1
e=10

for i=1,5 do
  cls()
  ?"counting "..b.." to "..e.."."
  key()
  ?""
  for i=b,e,b do
    ?i
  end
  key()
  b/=10
  e/=10
end
?""
color(10)
?"complete!"
repeat
  key()
until forever

Any solutions on how to get the correct numbers here ? And ... does this error extend to LUA or just Pico-8 ?

P#69284 2019-10-25 23:39 ( Edited 2019-10-26 18:27)

Was curious to know if you could run and program modern Pico-8 (pico-8_0.1.12c) on this particular piece of hardware:

https://store.planetcom.co.uk/collections/devices/products/gemini-pda-1

Also, do you have Pico-8 running on something off the shelf of a desktop Windows computer ? If so feel free to reply with your findings, both positive and negative, on the portable device you run yours from.

... Or can you recommend some device outside of PocketCHIP that effectively runs Pico-8 and allows you to efficiently code on it besides ?

I'm trying to avoid any reviews of PocketCHIP as the keyboard and physical design look REALLY BAD. (can't fold it and looks like a puffed up membrane keyboard). :(

In all case, please include images, links, and/or prices of the other compatible hardware if they are not readily apparent.

Thanks !

P#69172 2019-10-22 18:56 ( Edited 2019-10-22 20:06)

Calculators have always fascinated me. For that matter numbers. Even before I could bring Dad's calculator to school I was busily working on paper with digits 0-9. Fascinated, just ... fascinated by what they meant, what they implied, and what they COULD mean with new definitions.

When I finally understood computers, I was quite interested. No, that's not the right word. I was OBSESSED. Obsessed to the point of mania would it could mean. What I could do. And what I could do with tools that worked with these numbers. Tools within tools. Numbers within numbers ...

So perhaps this is a work of love, real love, for the majesty and magnificence of numbers.

With that out of the way, let me show you what I have done.

I suppose it's a bit of a calculator, but with a difference. You can have ANY number of digits. And I mean any. Right now I have it scaled for 64-digits. That includes positive and negative.

Most importantly, it does NOT do it a single number at a time as you can tell. No, it truly does add and subtract every digit intelligently. So if you have 16-digits set. Then it will take no more than 5-loops or 80 looped statements to get the right value.

  • [1st loop] retrieve digits
  • [2nd loop] find largest numbers
  • [3rd loop] add digits (if adding)
  • [4th loop] subtract digits (if subtracting)
  • [5th loop] locate beginning of return value
  • [6th loop] send return value to variable

NOT 1-million loops to get a value of 1-million.

So far it's just addition and subtraction, but maybe that's because I don't really know how to write simple code to multiply or divide without a calculator or computer.

Anyways, it does addition and subtraction quite well, and as mentioned, with any number of digits. I'm not kidding about that.

 
mab
by dw817
Cart [#mab-0#] | Code | 2019-10-20 | License: CC4-BY-NC-SA | Embed
1

Try out the sample program included and you have a few controls available to you.

Press LEFT and RIGHT to increase and decrease randomly by several thousand.
Hold (O) and LEFT and RIGHT to do it 100 times over.

Tap (X) to double your value. This will rapidly increase the amount. Remember, I just have it keyed to work no more than 64-digits at the moment. You can always change that.

Tap UP to take out the last digit in your number. A good way to shrink the value.

Try this for a test.

Hold (O) and RIGHT to get it up to about 50-million.

Now hold (X) for a bit to see it dramatically increase by doubling the total each time. You can check my work with a calculator too if you want.

Seems to work well for positive numbers. Alright, either hold (O) and LEFT or UP to get the value back down. Test it for negative numbers now.

Here's where my hardest coding came in. To bounce back and forth between positive and negative WITHOUT getting the wrong value. Test it though, please. I want this to work right. I think it does. I hope it doesn't get any errors.

I feel a little like Willy Wonka developing a new candy. As he (Gene Wilder) said, "I don't think so. Few more tests."

Anyways, there you have it. A single function that you can use in your own code to count well past trillions. Definitely good for scoreboards or long-playing RPGs with huge experience point values.

Likely you can find other more interesting uses for it.

P#69113 2019-10-20 16:59 ( Edited 2019-10-23 04:59)

 
Cart [#debug-2#] | Code | 2019-10-19 | License: CC4-BY-NC-SA | Embed
1

to load this cart in Pico-8 immediate mode type:

load #debug-2

updated 10-18-19: Now works correctly no matter what the names of your functions are or even if you rename the debug() function itself.

Ah ! I bet you did not know about this ?

There is a command in Pico-8 that lets you see what function you are in as well as the line number ! Works with nested functions too, as deep as you please.

Debugging your code just got a lot easier.

Try out this sample program and feel free to use this function I put together to assist you. Every time you call DEBUG() it will display at the bottom of the screen what function called it and at what line number.

Big thanks to @Felice for introduction to trace() command which is neither listed in the Pico-8 manual nor the advanced manual. Sometimes things are just found like that. :)

HOPE THIS HELPS !

P#69039 2019-10-19 02:07 ( Edited 2019-10-19 04:34)

Sometimes you just can't get what you want by plotting sprites cause they may not be there or you've put a bunch of binary code on top of 'em. Sometimes you just MUST pixel.

Well, that's all good and well, and there's a few ways to go about it.

[1] Record every pixel in the area ahead of time and later plot it all out again.

[2] As above but only plot select pixels. In this case, do not plot black pixels.

[3] Unique method caching pixels. Explained later below.

[4] NEW ! Shoxidizer's Serializer.

[5] NEW ! Using PEEK and POKE.

Try this program I wrote:

 
by dw817
Cart [#iymp-0#] | Code | 2019-10-18 | No License | Embed

Use LEFT and RIGHT arrow keys to change drawing method.
Lots of moving and colorful sprites. It starts out in MODE 0, which is the 1st above.

. . .

In mode zero you can see above it records every pixel in the sprite and then plots back every single pixel without caring what color they are. For moving 100 sprites, this uses up 63% of your CPU.

. . .

Mode 1 is better and more intelligent. It like above records every pixel in the sprite area but when it comes back to plotting, it only plots pixels that are not color zero (black). This gives you a slight speed increase. Uses 52% of your CPU.

. . .

So what's going on with the cache method which is the fastest using only 32% of your CPU ? Let me see if I can explain.

Instead of using an array that is 8x8 in size to house every pixel, it creates a new single dimensional array that has 3-separate elements in it.

The first is the X-position in the pixel, the next is the Y-position, lastly the color.

So how is this different from the two above ?

Instead of going through 64-different pixels to see which is lit and which is not, it records the X/Y coordinates for each pixel plus the color and saves THAT as a single item in the array.

I'll let you think about that for a minute before giving an answer. Scroll down to see how it's done. No, I don't know how to hide text in Lex.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

So is this what you were expecting ? If so, congratulations, you got it right ! :D

Yes, THIS method of not only recording each pixel you want plotted but their exact X+Y coordinates runs quite a bit faster than the standard 8x8 sweeping method.

So there you have it.

HOPE THIS HELPS !

NOW DO YOU know of a faster way to plot individual pixels from a table or sprite sheet ?

P#69015 2019-10-18 18:16 ( Edited 2019-10-19 02:22)

What games have you had your eye on that you the most ?

This is by no means a complete list or in any any particular order, but these are definitely some games I thoroughly enjoy playing and playing again and will play again even after I have won them.


Wandering Magic - by @Overkill
Carmina - by @makz
A Messenger's Tale - by @JustFire45
Dungeo The Lich Queen - by @nephilim
Of Ineffable Nature - by @Jimmu
Jack Of Spades - by @BoneVolt
Dusk Child - by @SophieHoulden
Mai-Chan's Sweet Buns - by @Krystman
Celeste v0.1.2 - by @noel
Upward - by @matthias
Feed The Ducks - by @kittenm4ster
Just One Boss - by @bridgs
Minima 1.1.1 - by @Feneric
Dank Tomb - by @krajzeg
Alone In Pico - by @NuSan
Swordfish - by @chowyunbrent
Santa's Christmas Run - by @Tassilo
Charge! (LD39) 1.0 - by @DragonXVI
Kelin's Delivery - Rain v1.2.1 - by @NeithR
The Legend Of Bobby 0.7 - by @AbsolutRenal
The Green Legion v1.03 - by @guerragames
Buzzkill 1.4 - by @morningtoast
Eigengrau 0.1 - by @LeDjinn
Puzzle Cave I and II - by @hackefuffel
Tower Noire I - by @Cow

That's a page right there. I'll try to add more later.

How about you ? What are some of your Pico-8 game favorites ?

And what is it in them that makes them so enjoyable to play for you ? This information could and likely will help game developers across the globe - especially if they happen to be YOU. :)

P#69001 2019-10-18 03:02 ( Edited 2019-10-20 02:29)

 
by dw817
Cart [#sots-2#] | Code | 2019-10-17 | License: CC4-BY-NC-SA | Embed
2

update: put helpful remarks in ALL of code now.

This is not a very complex cart, or perhaps it is.

The classic SNAKE game has been around for many years and during that time some innovative programmers have figured out unique, interesting, and compact ways of handling it.

It's not simply drawing a line, it creates a trail that disappears behind the player according to how far in the game they are.

There are many approaches to writing this. As for me, I have always opted to ID the entire screen, in this case, all 15x15 tiles and use a number to represent a part of the snake.

The higher the number the longer it will be in play. Albeit a lower number means it will vanish more quickly.

To update this I have a sweep of the entire playing area and if one of the tiles is a number that is greater to or equals one, then it decreases by one. So you need only plot a number behind where the player just was, to create this trail effect.

My question to you is how would =YOU= do it more efficiently ?

This is open to any and all programmers, not just you aces and veterans but those who are either learning to program in Pico-8 or have for a-while.

How would you code your SNAKE in the most efficient manner possible, and please, include the source.

Chances are one of us (likely me) will learn something from it. :)

P#68977 2019-10-17 19:57 ( Edited 2019-10-17 20:20)

stars in the galaxy.
Whoops, sorry, not that. No, something BETTER. Millions and billions of VALUES you can now use in Pico-8.

 
mib
by dw817
Cart [#mib-0#] | Code | 2019-10-17 | License: CC4-BY-NC-SA | Embed
2

load this in Pico-8 immediate mode with:

load #mib-0

I understand there was a library made sometime ago that could increase a value to trillions, but it could not decrease, let alone go beyond 0 to negative numbers.

Well, I sat down and thought about it. Realized that getting past 0 is a tricky thing indeed. Especially going from 0 to a negative number and found at least for me a fairly simple solution to get around it.

So what do you have here ?

Well, in the demo hit LEFT and RIGHT to choose a positive or negative number to add or subtract to your total. And calculate the result every time you hit (O).

A program that lets you count up as high as you like, well past a billion or trillion using a STRING instead of a numeric variable. There is a catch though, and likely this is a limitation on my coding ability. You can only add or subtract up to 16383 at a time.

I'm not sure how to do it otherwise, but one advantage is if both numbers are ranged to 16383 or less, positive or negative, then the calculation is instant.

If not, it goes through my function and adds or subtracts properly and it defaults to 16-digits, or you can choose how many digits you want in your numbers if that's not enough.

Useful if you want to have a score over a long time or experience points for an RPG that surpass the 32767 barrier.

I have no doubt my code could be optimized further. :)

...

Wait. What the heck ?? It doesn't work correctly here but it does in Pico-8 ??
Well that's just EVIL. I had this problem in GFA-Basic years ago. My code would ran fine in the editor, compiled, didn't run properly. Augh ! Solution anyone ? Gotta be a bug @zep needs to squash.

Try for yourself to see it works perfect in the actual Pico-8 system.

P#68949 2019-10-17 02:29 ( Edited 2019-10-17 03:54)

Here is the latest, 10-18-19

 
brw
by dw817
Cart [#brw-3#] | Code | 2019-10-18 | License: CC4-BY-NC-SA | Embed
5

To load this in Pico-8, in the console immediate mode type:

load #brw-3

. . .

 
brw
by dw817
Cart [#brw-2#] | Code | 2019-10-15 | No License | Embed
5

(older version)

Hope you don't mind me starting a new thread. I literally had to rewrite more than half the code here so I think it's deserving of it.

And yes, it now has a proportionally spaced font.

New configuration in code lets you turn on/off shadow (runs a lot faster without).
Configure page and ink color too. And of course this will work with any text file, provided you have enough memory for it. Anything close to 19,000 chars will fit.

You have a few questions ? I have a few questions. :D

Would you like me to post an additional version that uses soft-sprites instead of individual pixel-plotting as it is now ?

The advantage will be the bookreader will run much faster even with shadowing, the disadvantage of course is you can't inject your own sprites over the set during reading.

Also I could make a version that just reads the text file by itself without poking it to sprite territory.

Further I have the font-writer with the sprite table of fonts I doodled. Do you like the proportionally spaced font or would you like to build one of your own for it ? You will need that tool.

Let me know, and thanks everyone who's helped me get as far in Pico-8 as I have today !

P#68907 2019-10-15 21:38 ( Edited 2019-10-18 20:16)

Now that I'm mixing and matching my metaphors in programming, metaphorically speaking of course, I'm running into some curious behavior by Pico-8.

For instance, take this code:

a="1"
b=2
?a+b

Which gives you 3, and that's fine.

But if you do this:

a="1"
b={1}
?b[a]

The result is NIL. Now I already know why it is because it's a string, but wouldn't it be easier for Pico (and possibly other programmers) to remove the number "type" completely and instead treat all variables as strings, only doing calculations when desired, and even then the results while visually appearing numerically are still just in truth a string ?

We already have ".." to show linking two strings together so there would be no difficulty with getting the "+" chosen correctly for calculations in determining whether or not it needs to be added to or appended to.

What problems would typecasting everything as a string cause ?

I can already see one advantage. Since strings can be any size this could also mean Pico-8 could be upgraded by @zep and allow numbers with any number of digits in them, both to the left and right of the decimal place. It would break the -32767.9999 and 32767.9999 barrier.

P#68887 2019-10-15 00:10 ( Edited 2019-10-15 01:09)

View Older Posts
About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2019-11-17 16:40 | 0.282s | 4194k | Q:235