Skip to content

Instantly share code, notes, and snippets.

View Achie72's full-sized avatar
💻
Probably doing some game jam

Achie Game Dev - Bela Toth Achie72

💻
Probably doing some game jam
View GitHub Profile
@Achie72
Achie72 / sort.p8
Created April 27, 2025 09:59
insertion sort by impbox
-- Insertion Sort by @impbox
-- this will sort our closed list by the A* F value.
function sort(array)
for i=1,#array do
local j = i
while j > 1 and array[j-1].f < array[j].f do
array[j],array[j-1] = array[j-1],array[j]
j = j - 1
end
end
@Achie72
Achie72 / text_print_helpers.p8
Last active March 16, 2025 11:12
How to center any text or print with borders
-- a little helper function to print centered text
function print_center(text, x, y, color)
-- get the lenght of the text
-- if you did not know, print returns the position of the last character
-- so fi you print offscreen, starting from 0 you will get the exact lenght of the text
local len = print(text, 0, 400, color)
print(text, x-(len/2), y, color)
end
@Achie72
Achie72 / state_machine.p8
Last active March 16, 2025 11:13
Scene management with state machines
-- state machines might sound complicated, but when it comes down
-- they are just if statements that control how our code behaves.
-- based on certain conditions you can jump between "states"
-- and this can help you also organize stuff better, animate more freely, or
-- for example, let's use state machines to create a menu system for our game
function _init()
-- we will start on the game logo scene
-- and we will have the following:
-- menu: to show a nice menu if you want
-- gameplay: where the actual game code runs
@Achie72
Achie72 / basic_multiplayer.p8
Created March 16, 2025 10:14
Multiplay Demo
function _init()
-- create collection for players
players = {}
-- p1
player1 = {
x = 0,
y = 2,
clr = 12,
health = 10
}
@Achie72
Achie72 / add_something.p8
Created March 16, 2025 09:53
How to spawn stuff in PICO-8 with a function
-- create a table to hold your objects
coins ={}
--now you can add things into here by hand, but you can also make a functionnsonyou can call that point
function add_coin(xpos, ypos)
-- now lets make a temporary local table to hold the coins atrributes, you want position mainly
local coin = {
x = xpos,
y = ypos
@Achie72
Achie72 / pico_playlist.md
Last active March 3, 2025 21:37
Game List
@Achie72
Achie72 / pico8-particles.p8
Last active March 16, 2025 11:12
PICO-8 Particles
-- inside init have a collection called particles
-- this is where we will store each an every particles, so we can iterate
-- over them in the future (aka process them one by one)
particles = {}
-- adder function, you call this anytime you want to add a new particle
-- to the system. This will help us centralise every modification as this
-- function is the only thing that you will have to modifiy.
function add_particle(_x, _y, _sx, _sy, _lifetime, _color, _type)
-- create a local temporary particle where we create the data
@Achie72
Achie72 / map-strings.p8
Created June 22, 2024 17:38
PICO-8 load maps from strings
-- For this I whipped up my good ol’ reliable approach of having the following functions:
-- export the currently drawn map to the clipboard
-- I used this in copied .p8 files to draw levels,
-- run them and copy the given string into this main
-- file's map collection
function export_map()
-- start with empty string
local mapString = ""
-- loop over the map tile by tile
-- and append tile numbers by , after each other
@Achie72
Achie72 / movement.p8
Created June 17, 2024 19:57
PICO-8 Sliding Movement for PPJJGG
-- function to add characters to the game
-- at any point on the map
function add_character(_x, _y)
local p = {
x = _x,
y = _y,
direction = 5,
doReplaceOldTile = false,
replaceTileId = 0
}
@Achie72
Achie72 / pico8_pickups.p8
Last active May 20, 2024 09:53
Pickups in PICO-8
-- Or if you don't want to bother with drawing each pickup with every tile aviable to you, you can make them "objects".
--For this, create an array, that will hold all our pickups:
pickupCollection = {}
-- and a function that you can call to add pickups.
-- we include a _type so later you can differentiate them
-- by checking the this. For ex: _type = 1 is a healing item, _type = 2 is a bomb etc...
function add_pickup(_xPosition, _yPosition, _type)
-- we create a local variable to hold the item