Hello,
I'm a noob at programming and need some help please.
I'm try to write a for next loop that randomly fills an 2D array (my game grid), but I also want it to check that if that cell already has been used, then knock the counter back -1 and tries again. So in this way, at the end of the loop there should be a set number of cells filled.
My code works great except that when it detaches a duplicate cell, it doesn't roll the counter back.
So say at loop count 50, there's a duplicate cell, it doesn't alter the cell (which is correct), but it doesn't roll the loop counter back, it just continues.
Here's my code. I was hoping that the i-=1 would do the trick, but it doesn't.
function make_grid()
for i=1,level*100+1 do
y=flr(rnd(gridheight-6))
x=flr(rnd(gridwidth-6))
--is the space empty? then add
--a bomb. if not rollback counter
if grid[1][y+3][x+1]==0 then
grid[1][y+3][x+1]=2
else
i-=1
end
end



This is a tiny (47 token!) Entity Component System library.
Entity Component Systems are design patterns where entities are generic collections of components and logic is written for specific component types. It's popular for game design as we often have many 'things' that don't always fall within clear cut types.
There's different approaches to ECS, here we'll consider a table to be an entity, and the key/value pairs to be component names and values.
This library is basically a single function, system, which creates a function that selects every entity with the specified components and calls the user provided function on each one.









Hi, I have a function that takes a string in a specific format and then creates a table used elsewhere in my game from the string.
Currently the function parses the string correctly and creates the table but after I assign a variable to the newly created table it is then lost. Is this a thing where I'm assigning a reference and then the original is cleared by garbage collection? How could I get around this?
for i=1,#levelonepaths do --stringtopath is the parseing function levelonepaths is a table containing the strings local path = stringtopath(levelonepaths[i]) --Printing the local variables 1st entries x co ordinate gives the correct result print(path[1].x) --I then assign where the string was to the new table currently stored in the local var path levelonepaths[i] = {} levelonepaths[i] = path end --this print gives nil print(levelonepaths[1].x) --this print gives nil print(levelonepaths[1].y) |


Ok, it isn't pretty but sometimes you just want to know what the CPU cost of something is. I've started this cart just to see what things cost. This runs at 60fps, so if you're using a 30fps cart, you can divide the CPU cost by 2.
Its structured to be really easy to add more tests to, if you're curious. Let me know if you have any questions! This lives on github at:
https://github.com/ssteinbach/pico8carts/blob/master/performance_test_gallery.p8
PRs welcome!
Back 30 years ago, After Burner and Thunderblade ruled the arcades.
As a kid, I only had an Amiga and near zero coding skills to produce very (very) weak clones.
Now a seasoned programmer with the mighty power of PICO-8, I can beat a Sega X board!
Well, err...:

Credits
• Chris Butler (player + tank sprites lifted from the C64 1989 version)
• gamax92 for midi to pico-8 program
• dw817 (david w) for image decompression code (http://writerscafe.org/dw817)
• pico-8 community
What's Missing
• gameplay tweaking...
• levels 2,3,4,5
• gazillions of buildings on screen!
Tech Details
Map:
Drawn using sprite sheet (2), you can tweak the level using colors:
4: tank
6,7,13: building
8: enemy helicopter
9: Battleship boss
10: swtich to chase mode
11: switch to top-down mode
15: end_game (use carrefully!)
Title screen:
Title image is loaded from a stringified image, decompression done 'asynchronously' with yield.
Main screen:
Buildings are mostly drawn with many rectfill using a big checkerboard pattern to simulate windows/floors.
Everything is z-sorted (w actually ;) before being drawn. This 'zbuffer' is in charge of drawing every asset.
Game screen manager:
A light version of what I've extensively used during my XNA period. Allows nice decoupling between game loop and other loops (title, game over).
Coroutines:
Used only for rare events (like player dying) to easily control animation and state changes.
Lessons Learned
• PICO-8 is a fantastic platform. Forces you to keep things simple (say that to my dozen or so failed Unity attempts...)
• token count is everything
• Coroutines are unfortunately too slow to be used in the core game loop
• Throw OOP techniques out. The nice class:method() construct eats up too many tokens - had to rewrite half of the code to stays within the limits :[
• bnot-cheating the platform is way too easy (but resisted against!)
• Did I say token count is everything?






I am attempting to make the screen flash and shake. However, I would like it to be randomly generated. I vaguely researched the use of srand/rnd, but I ultimately do not know how to implement the proper code into what I currently have.
Warning: I have no idea what I'm doing.
player = {} player.x = 60 player.y = 60 player.sprite = 0 player.speed = 1 player.moving = false player.timer = 1 music(0) cam_x = 0 cam_y = 0 fliph = false flipv = false shake = 0 function _rand function _draw() cls() camera (cam_x,cam_y) cam_x = player.x-60 cam_y = player.y-60 map(0,0,0,0,16*8,16*2,0) --map(0,0,0,0,16,8) --map(0,0,0,64,16,8) spr (player.sprite, player.x, player.y,1,1,player.fliph,player.flipv) end function movex() player.moving = true player.sprite += 1 if player.sprite > 3 then player.sprite = 2 end end function movey() player.moving = true player.sprite += 1 if player.sprite > 5 then player.sprite = 4 end end function _update() player.moving = false if btn(0) then player.x -= player.speed movex() player.fliph = true elseif btn(1) then player.x += player.speed movex() player.fliph = false elseif btn(2) then player.y -= player.speed movey() player.flipv = true elseif btn(3) then player.y += player.speed movey() player.flipv = false end -- if not player.moving then --player.sprite = 0 -- end if not player.moving then player.timer = player.timer+1 end if player.timer >=30 then player.sprite = 1 end if player.timer >=60 then player.sprite = 0 player.timer = 0 end if player.moving then player.timer = 0 end end |



Hey, I'm a relative beginner, and I've been trying to create a general-purpose shape collider for a little project I'm making. I've run into a bit of a problem when trying to make a function for detecting collision between circles and rectangles. The problem is, as far as I can tell, that Pico-8 doesn't have enough floating point precision to accurately calculate the distance between a point and a line (using a formula I copped off of Wikipedia). Here's what I've got:
-- I'm aware these function names are garbage, I'm gonna change them up later. local function dOfLine(a, b) -- takes two points and returns the distance between return sqrt((b.y - a.y)^2 + (b.x - a.x)^2) end local function dToLine(p, a, b) -- takes a point and the two endpoints of a line and returns the length -- of the perpendicular between the point and the line. num = abs(((b.y - a.y) * p.x - (b.x - a.x) * p.y + b.x * a.y - b.y * a.y)) return num / dOfLine(a, b) end |


8:00 AM by Sushicats
The objective is to make sure that the cars reach their destination and avoiding traffic jams.
Controls:
You move the cursor with arrows.
While Z is pressed and you move the cursor you place roads.
While X is pressed and you move the cursor you remove roads.
Tapping X on top of an existing road will cycle through some options, you can make straight roads one directional and you can add semaphores on top of intersections.

I started playing around with the shallow water equations and got to something that's maybe a little bit fun. Arrow keys make waves, Z switches boundaries between (approximately) open and reflecting. My implementation mostly follows https://graphics.ethz.ch/Downloads/Publications/Tutorials/2008/Mue08/coursenotes.pdf .
Current limitations/known bugs:
- Dissipates energy rapidly, although you'll probably only notice this if the boundaries are reflective.
- No handling of dry regions. Weird things may happen if depth goes to 0!
- Weird oscillations around both (nearly-)dry regions and shocks/big elevation changes. Not sure yet how much of this is attributable to bugs vs. limitations of the discretization I'm using.
- Liquid volume is not conserved. Not really a meaningful concept with open boundaries, but pretty noticeable with reflective boundaries.
- No wave breaking etc. Shallow water equations are a heightfield model and I don't think I'll get around to full liquids on PICO-8 any time soon. :)
I hope this cart is fun to play with! I'm hoping to fix a few of the items above, clean up the graphics a bit, and maybe find a way to build a little bit of a game around these dynamics.


I love seeing work-in-progress screenshots.
The great thing about keeping these screenshots is that after the game is finished, you can tell in retrospect which screenshots were significant and interesting. Pico-8 encourages screenshotting, with its built-in screenshot and gif capability. And the file size is minimal. ... So I figure a lot of folk probably have cool early screenshots of games that later become great games. So let's see 'em! |

@zep:
Is this really the expected behavior?
> ?shl(1,32) 1 > ?shr(1,32) 1 |
I'd have expected 0 in both cases.
It works correctly for lesser shifts that push the 1 off of either end:
> ?shl(1,31) 0 > ?shr(1,31) 0 |
Seems like you're doing a modulo of the shift with 32:
> ?shl(1,33) 2 > ?shr(1,33) 0.5 |
Doesn't feel like the right behavior to me. Like, in assembly language, maybe, but not in a higher language.
PS: It would be nice to have bith arithmetic and logical shifts right, btw. :)




[previous: 44810]
Controls
Z to start, or X to skip all instructions.
Arrows move/dig through mine.
Z brings up map.
Commentary
This was going to be a maze game where you had a 'zoom in/out' button, and that idea was going great for a while, until I realised mazes are hard and I didn't know if I could do justice to a maze generator in the time I had. So instead it became a digging game, and grew in scope disgustingly until I had more work than the maze would have been in the first place. But inspiration will be inspiration I suppose.
Use your map to see roughly where the gold is, then make your way towards it, being careful to manage your truffles (food) and glow crystals (flashlight power). You can find both in the mine but you have to balance things carefully. At any time you can press Z to check the map, and see an indication of local tile types. Try to reach the gold before you starve!
itch.io page: here



Hi!
I'm new to Pico-8. I've been learning from the great carts very talented ppl publish here at Pico-8 BBS. I've just seen a demo doing pretty colorful spirals and wanted to test myself doing something similar in a per pixel color fashion.
The code is a pretty slow unoptimized version without look up tables or palette reordering, but, hey, it works!
Use left/right/up/down to tweak parameters.
Have fun!

-- 11/13/17 --
Soon. :)
-- 10/27/2017 ---
REMINDER! You've got one weekend left :)
To be specific, you need to finish your games at some point on 10/30 and upload them by/on 10/31. Don't worry about getting it uploaded exactly before the stroke of midnight or anything; this is a chill jam...
Buuuuutttt.... if you get your games in before mid-day on 10/31 and post the cartridge ID (that '[ # 02156489# ]' thing you use to display it in a forum post) in this thread (or send it to me on twitter, I guess -- @enargy)... you'll be happily surprised.
For reasons. :)
Trust me.
[evil, secret laughter]
As for our project, I still have a ways to go before making use of all of this amazing art by @castpixel but here's an update gif:

Good luck and happy jamming! Have a spoooooky weekend! I can't wait to check out all the things I've been seeing previewed!
--- 10/13/2017 ---
Reminder that the #3CJam -- the 3 Color Jam -- is running all month. Feel free to take a week. Or a day. Or even just an hour -- it's all up to you. Just make sure you only use 3 unique colors on-screen (at a time).
Here's some progress on the entry @castpixel and I are working on --










