Log In  
Follow
gcuellar
Follow

Here comes another newbie question:

If I've got a map of 32*48 tiles (taller than wide), how should I handle the map data in order to print it directly with map() function?

I saw that map can be extended to 64 tiles (height) if you use 0x1000 - 0x2000 memory, but I don't know how to tell the map function to use this extra space.

Searching some post I've read that implementing some kind of map data streaming with peek and poke is a good a idea. Is there some resources, carts or tutorial that can helps me?

P#86571 2021-01-19 08:24

I'm struggling with a function that randomly picks up an element from a table with ponderated probability. For now this is my current code:

items = {
 {value="a",probability=.35},
 {value="b",probability=.35},
 {value="c",probability=.145},
 {value="d",probability=.145},
 {value="e",probability=.008},
 {value="f",probability=.002}
} -- total probability = 1

function rnd_item()
 local rnd_number = rnd() -- between [0,0.99999)
 local i = 1
 local sum = items[i].probability
 while sum < rnd_number do
  i += 1
  sum += items[i].probability
 end
 return items[i]
end

What is the problem with the implementation? Right, In some cases it crashes because 'i' goes out of bounds. It seems that the problem occurs when rnd_number is near 1 (i.e. 0.99997) but I can't figure out how I fix it.

Is there a better implementation to solve the problem?

P#84674 2020-11-25 17:51 ( Edited 2020-11-25 17:51)

Hi mates,

I'm having some issues with an unexpected (for me) behaviour of rnd() and tostr() functions.

Why this fragment of code prints value 1 if it's supposed that calling rnd() with no arguments produces values from 0 to 0.99999? Does tostr() perform some kind of ceil()?

local rnd_number = rnd()
printh("rnd_number:"..tostr(rnd_number),"maplog.txt")

Output:

rnd_number:0.3293
rnd_number:0.7758
rnd_number:0.5745
rnd_number:0.3691
rnd_number:1
rnd_number:0.0995
rnd_number:0.1682

I need to avoid that '1' value.

P#84671 2020-11-25 12:07 ( Edited 2020-11-25 12:09)

Cart #animator8x8v03-0 | 2020-11-11 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
14

Hi folks!

Last month I was trying out some Pico-8 features and finally brought them all together in my first cart.

It's a simple 8x8 pixels animation editor. It features:

  • Pixel editor with "Pencil" and "Fill color" tools.
  • Animations allow up to 12 frames.
  • Add/remove frames to the current animation.
  • Editable frame delay.
  • Play/pause animation controls.
  • Keyboard device for text input.
  • Export to PNG (only sprites, not metadata).

For now I have an alpha version because is not finished yet but I wanted to share with you some kind of build that allows me put my mind in another subject.

I've planned to add new features like multiple animations, export metadata capabilities, and much more, but for now this is the v0.1 release.

Cheers!


New 0.2 version including:

  • Fill tool fixed
  • Start/stop animation with toogle button
  • Export frames to clipboard

New 0.3 version including:

  • Rotate sprite clockwise and anti-clockwise tool
  • Undo tool with 12 actions memory per frame
P#83384 2020-10-26 22:46 ( Edited 2020-11-11 08:33)

Follow Lexaloffle:        
Generated 2021-10-25 16:15:02 | 0.066s | Q:11