Skip to content

Instantly share code, notes, and snippets.

@jdesiloniz
Last active December 9, 2018 23:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdesiloniz/c8c923f0c97bf16ee18a36ac8c7efe6d to your computer and use it in GitHub Desktop.
Save jdesiloniz/c8c923f0c97bf16ee18a36ac8c7efe6d to your computer and use it in GitHub Desktop.
First stuff in PICO-8! Starfield effect :D
pico-8 cartridge // http://www.pico-8.com
version 16
__lua__
stars = {}
center_coord = 64
total_stars = 64
function _init()
cls()
for i=1,total_stars do
add(stars, gen_star())
end
end
function _update()
for i=1, #stars do
local star = stars[i]
star = update_star(star)
if (star.x < 0 or star.x >= 128 or star.y < 0 or star.y >= 128) then
stars[i] = gen_star()
else
stars[i] = star
end
end
end
function _draw()
rectfill(0, 0, 127, 127, 0)
for star in all(stars) do
pset(star.x, star.y, star.c)
end
end
function gen_star()
star = {}
star.x = center_coord
star.y = center_coord
star.c = rnd(16)
star.v = rnd(3) * 2
star.ang = rnd(1)
return star
end
function update_star(star)
star.x += cos(star.ang) * star.v
star.y += sin(star.ang) * star.v
return star
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment