Log In  

BBS > Superblog
Posts: All | Following    GIFs: All | Postcarts    Off-site: Accounts

Hi,

I'm using a metatable for particles in my game. For example, when the player dies the sprite explodes in a burst of pixels. I use rnd() to off-set the player position with a random number, and as I generate a lot of different particles (based on the colors the character is composed of) I want to move the for-loop into the constructor.

Unfortunately, for some reason the randomness doesn't work when I build the for-loop inside the particle constructor. Compare these two examples:

For loop in caller function

particles={}
particle = {
	x_offset=0,
	y_offset=0,
}

function particle:new(o)

	self.__index = self

	local pi = setmetatable(o or {}, self)

	pi.x=pi.x-rnd(pi.x_offset)
	pi.y=pi.y-rnd(pi.y_offset)

	add(particles,pi)

end

function game_over()

	for i=1,6 do
		particle:new({x=p.x,y=p.y,x_offset=12,y_offset=8})
	end

end

Result: I end up with 6 particles, each with a different x and y value due to the rnd() function being passed the x_offset and y_offset values.

For loop in constructor

particles={}
particle = {
	x_offset=0,
	y_offset=0,
}

function particle:new(count,o)

	self.__index = self

	for i=1,count do
		local pi = setmetatable(o or {}, self)

		pi.x=pi.x-rnd(pi.x_offset)
		pi.y=pi.y-rnd(pi.y_offset)

		add(particles,pi)
	end
end

function game_over()

	particle:new(6,{x=p.x,y=p.y,x_offset=12,y_offset=8})

end

Result: I end up with 6 particles, but they all have the same x and y values. As if the rnd() is called only once and then applied to the other 5 iterations of the for-loop.

Questions

  1. Why does the code behave this way?
  2. What's the right pattern to apply here?
12 comments


I can't seem to find any tutorials on how to make monsters move or patrol or have movements routines.

Nothing fancy, something like:

Go from A to B, wait a few frames, go to C, wait again, go back to A and repeat.

The monster doesn't even have to notice the player, just walk its path.

I've tried with loops but I can't make it work.

Thank you very much!!! :D

2 comments


Just a small snippet from a token-saving discussion on the Discord last night.

If you need to iterate over neighboring tiles (for example when writing a path finding algorithm for 7DRL), this natural approach is pretty token heavy:

-- four directions, 29 tokens
for direction in all{{-1,0},{0,-1},{1,0},{0,1}} do
 local x,y=direction[1],direction[2]
end

-- eight directions, 45 tokens
for direction in all{{-1,0},{0,-1},{1,0},{0,1},{1,1},{-1,-1},{1,-1},{-1,1}} do
 local x,y=direction[1],direction[2]
end

-- eight directions, 43 tokens
directions={0,-1,-1,0,1,0,0,1,1,-1,-1,1,1,1,-1,-1}
for i=1,16,2 do
 local x,y=directions[i],directions[i+1]
end

-- eight directions, 30 tokens
directions={-1,0,1}
for x in all(directions) do
 for y in all(directions) do
  if x!=0 or y!=0 then
   --
  end
 end
end

Why not use trigonometry?

-- four directions, 16 tokens
for i=0,1,0.25 do

[ [size=16][color=#ffaabb] [ Continue Reading.. ] [/color][/size] ](/bbs/?pid=62065#p)
7
4 comments


Remember SAM? (https://simulationcorner.net/index.php?page=sam).

Would it be possible in some way to use the white-noise for samples and/or digi-speech?

I'm not talking about a full-blown conversion of SAM (https://github.com/s-macke/SAM), but maybe a smaller version. Also - shouldn't it be possible to use at least 3-bit samples on the PICO-8? (https://gist.github.com/munshkr/30f35e39905e63876ff7)

I'm not the person to dive into this, but maybe someone else might be able to do some sort of conversion of the above. Personally, I would really enjoy being able to have short/small samples and make the Pico speak!

/ Pingo

14
25 comments


Cart #jojiyazya-0 | 2019-02-18 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

0 comments


Cart #walrush_1_1-1 | 2019-02-18 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
3

Previous version

Cart #walrush_1_0-0 | 2019-02-18 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
3

About

Wal-Rush! is a game of walrii, fish, and flight. Based on a game I made for a programming competition at codewalr.us, this game lets you play as the mascot of the website, Walrii, as he flies through the sky. Collect fish, rack up points, and watch out for the spike mines!

[ Continue Reading.. ]

3
1 comment


Hi all,

I'd like to set up PICO-8 so that it will run from a USB pen drive and load, run, and save, export, etc to a folder and\or folders on the drive relative to the application.

Ho do I go about doing that?

Thank you.

1
1 comment


Hello everyone, I'm Dead_Pixel.

I recently discovered Pico-8 and I'm really intrigued by the whole concept of it and look forward to getting to grips with it.

I'm really impressed by the quality of the cartridges and look forward to contributing some of my own work in the future too.

Before signing off I have one question - why was Lua chosen as the programming language?

Thanks.

0 comments



A while ago I made a function for this
https://www.lexaloffle.com/bbs/?tid=30033

This was very clunky so I remade it. It used to have 124 tokens but I lowered it to 43.

You can use this function as much as you want without credit.

How to use:

printl(text,x,y,inner color,outer color,height)

text,
x,
y,
inner color --the color inside the border
outer color --the outline,
height --how far down you want your outline to reach. 0 means the outline has the same width in all directions.

--the x and y are the coordinates of the top right corner of the inside color.

8
0 comments


Cart #gemhoppico-0 | 2019-02-17 | Code ▽ | Embed ▽ | No License
2

2
4 comments


Cart #blastoff-14 | 2023-03-11 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
18

A game about rockets, for little and big kids. This is a one-button game with no possibility of failure.
Press X to skip the SPACE WALK.
See if you can activate the hidden autopilot for landing!

Change log:

0.2

  • Sound, stars, random birds, sky colours, tracking camera

0.3

  • Added a countdown! Player can tap UP or hold it.

0.4

  • Used fill patterns to dither the gradations of atmosphere.

0.5

  • Attract screen plays out an animation of astronaut getting on board.
  • Added states to complete the game loop, you can get to orbit and back.
  • Added SPACE WALK.
  • Added rocket heating up depending on reentry velocity.
  • Adjusted volume for less pew-pew and more engines.

[ Continue Reading.. ]

18
4 comments


Cart #derbyamplify-0 | 2019-02-17 | Code ▽ | Embed ▽ | No License
2

CAN YOU DEFEAT THE SKULL?

Kirby samurai clone by @krazl and @verdog.

2
6 comments


A starfield effect, inspired by the old Windows screensaver, though the style is more in line with Star Trek. Use up and down to increase and decrease speed, and press X to show stats.

I used nucleartide's Pico-8 snippets, specifically vec3 and pline(), to do the 3D projection. I was encouraged by reinvdwoerd's Perspective Lines and used his cartridge to figure out how to use pline().

To really get immersed, shout "increase speed to [warp number]!" as you hold the up key or "all stop!" as you slow down to zero.

Cart #starfield-0 | 2019-02-16 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
5

5
13 comments


Cart #dodge_1-0 | 2019-02-16 | Code ▽ | Embed ▽ | No License


Dodge is a fast paced reflex game. There is no end, you just have to survive the longest possible. Enemies move towards you and it's game over if they touch you, but they explode and give you a point if they touch each other.
There is a powerup (the ball with fire particles) that you can touch to destroy all enemies that are currently on the screen.
This game is still WIP and will be updated regularly. There will be music, better sound effects, updated graphics, and maybe even some more gameplay elements depending how far we want to go with it.

1 comment


Hey all,

A slightly annoying bit of Lua syntax is how verbose the anonymous function syntax is.

For example consider a function filter function that accepts an array and a test function that accepts a single element and returns true or false if the element should be kept. The filter function would then return an array of all elements for which the test function returns true.

function filter(array, test_fn)
 local ret = {}
 for elem in all(array) do
  if (test_fn(elem)) add(ret, elem)
 end
 return ret
end

So yeah a pretty straight forward functional programming paradigm that's easy to use and awesome.

It is especially convenient to use with anonymous functions where your test function need not be defined anywhere and can instead be defined inline with the function call. Here's an example that would filter an array to only even numbered elements:

filter({1, 2, 3, 4, 5, 6, 7, 8, 9}, function(v) return v%2==0 end) -- result: {2,4,6,8}

[ [size=16][color=#ffaabb] [ Continue Reading.. ] [/color][/size] ](/bbs/?pid=61932#p)
2 comments


HACK*MATCH

Cart #deadpixl_hackmatch_1-1 | 2019-02-16 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
22

Screenshots

About

HACK*MATCH is a mini-game in EXAPUNKS, a programming puzzle game by Zachtronics. When I first played the mini-game I loved it, and thought that it would work really well on PICO-8. This is my own version of the mini-game with some slight modifications.

How to play

The goal is to connect 4 or more of the same coloured piece. There are two ways you can do this, by either picking pieces up and putting them down in a different location, or by swapping two pieces, either the two above you, or the one you're holding and the one above you. The game takes some getting used to so it might take a few rounds before you're comfortable with the controls.

[ Continue Reading.. ]

22
12 comments


Cart #arcade_pong-4 | 2019-02-23 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
2


Welcome to my first game ever finished!

  • Controls
    • Player 1 -> E(Up) / D(own)
    • Player 2 -> Arrow Keys
  • Description
    • It is a simple PONG game that you can play alone trying to survive as long as you can or with a friend trying to beat him.
  • Special Thanks
    • Thanks to @Alfedi for finding bugs and giving me feedback <3
2
2 comments


Cart #zeldamos-0 | 2019-02-15 | Code ▽ | Embed ▽ | No License
8

Zeldamos is a Zelda-esque Engine similar in style to the GameBoy titles.
I will be updating this throughout to hopefully make an example dungeon with combat, puzzles, and a boss.

v1.0 --

  • 8-Way Movement
  • Screen Transitions
  • HUD
8
7 comments


Cart #pip13-0 | 2019-02-26 | Code ▽ | Embed ▽ | No License
55

A retro platformer where Pip, the tiny birb, must collect feathers to get strong enough to return to their nest and finish their nap.

Z/C to jump and airjump
X/V to short hop (on ground) and dive (in air)

Current version: 1.3, patch notes farther down in thread

55
19 comments


Cart #descenders_v9-1 | 2019-02-16 | Code ▽ | Embed ▽ | No License
6

updated: added ricochets / music / music toggle / screenshake toggle. use the 'return menu' to access the options.

z=shoot
x=jump
l/r=move left/right

get a high score! ammo is limited so be sure to retrieve your shots. chain together multiple kills with 1 bullet for score multipliers, and ricochet bullets off walls for bonuses.

some tips:

  1. bullets take on the left/right momentum of the player, so use that to line up shots!
  2. jumping can help you launch bullets higher!
  3. when bullets hit an enemy, their direction/travel speed is affected by the enemy movement. i.e a fast enemy moving left will knock the bullet left by a moderate amount and halt its upward momentum significantly.

[ Continue Reading.. ]

6
3 comments




Top    Load More Posts ->