Log In  
Follow
chermosi
Guide for Making Tweetcarts
by
Guide: Boot straight to PICO-8 on Raspberry Pi OS Lite (no desktop)
by
Syncing PICO-8 installs with Dropbox
by
Simple Mouse
by
Guide: Pico 8 Laptop (using Ubuntu 22.04)
by

I'm trying to do a simple state machine but I'm doing something wrong in the assign.
I wanna assign "running" if a button is pushed from a list of values.

player = {
	lives = 3,
	current_state,
	list_states = {"running","jumping","falling"}
}

function _update()
	if btnp(❎) then
		player.current_state = player.list_states["running"]
	end
end

function _draw()
	cls(1)
	print(player.current_state)
end

This doesn't work:
player.current_state = player.list_states["running"]

This works but its not very useful because I don't see in the code which state I'm assigning:
player.current_state = player.list_states[1]

This also works, but I think it's also not very useful because the usefulness of the state machine is assigning a concrete value from a set of predefined values to avoid mistakes.
player.current_state = "running"

How can i do it? Or whats the usual approach to make states machines?

Thank you!

3 comments



So in Super Mario and similar games the character only jumps when you press the button, and if you just keep the same button press the character doesn't jump. You have to release the button and then press it again.

I've tried to implement a jump action and both with btn and btnp if I keep the button pressed the player keeps jumping forever (in btnp just slower).

How can I do this? Thank you! :)

3 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



I'm trying some math things to learn pico8 and programming in general.

After a few days and realizing that the square root in lua (and in every language?) only gives positive numbers, I’ve come to this monster to draw a simple circle haha

function _init()
end

function _update60()
cls(1)
end

function _draw()
--coordinates
line(64,0,64,128,2)
line(0,64,128,64,2)
manual_circle()
circ(64,64,63)
end

function manual_circle()
for x=0,50 do
radius=50
local y=-sqrt((radius^2)-(x^2))
pset(x+64,y+64,11)
end
for x=-50,0 do
radius=50
local y=-sqrt((radius^2)-(x^2))
pset(x+64,y+64,11)
end
for x=0,50 do
radius=50
local y=-sqrt((radius^2)-(x^2))
pset(x+64,-y+64,11)
end
for x=-50,0 do
radius=50
local y=-sqrt((radius^2)-(x^2))
pset(x+64,-y+64,11)
end
end

And it looks like this:

as you can see the function doesn't print the pixels continuosly as the circ function, probably because of the square root giving decimals.

What is the correct way of drawing a circle “manually”???

[ Continue Reading.. ]

1
5 comments



I'm learning to make hitbox collisions (instead of flags collisions).
Vertical collisions seem to work just fine but horizontals don't.
How can this be done?
Maybe hitbox collisions are just to complicated and shouldn't be used?
.
.
.

Cart #hermo-0 | 2019-01-20 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA


.
.
.

function _init()
    pad_x=45
    pad_y=45
    pad_width=30
    pad_height=30
    pad_color=7
    pad_speed=3

    ball_x=80
    ball_y=10
    ball_radius=4
    ball_color=8
    ball_speed_x=2
    ball_speed_y=2
end

function _update60()
    btnprss=false
    cls(1)

   --ball movement
    ball_x+=ball_speed_x
    ball_y+=ball_speed_y 

    --ball-screen collision
    if ball_x<0 or ball_x>128 then
        ball_speed_x=-ball_speed_x
    end

    if ball_y<0 or ball_y>128 then
        ball_speed_y=-ball_speed_y
    end
    --pad movement
    if btn(0) then
        btnprss=true
        pad_speed=-5
    end

    if btn(1) then
        btnprss=true
        pad_speed=5
    end

    pad_x+=pad_speed

    if btnprss==false then
        pad_speed=pad_speed/2
    end

    if pad_x<1 or pad_x>126-pad_width then
        pad_x=mid(1,pad_x,126-pad_width)
    end

    pad_color=7
    if ball_box(pad_x,pad_y,pad_width,pad_height) then
        pad_color=8
        ball_speed_y=-ball_speed_y
    end
end

function _draw()
    rectfill(pad_x,pad_y,pad_x+pad_width,pad_y+pad_height,pad_color)
    circfill(ball_x,ball_y,ball_radius,ball_color)
end

function ball_box(box_x,box_y,box_w,box_h)
    --conditions where there are no collisions
    if ball_y-ball_radius>box_y+box_h then
        return false
    end
    if ball_y+ball_radius<box_y then
        return false
    end
    if ball_x-ball_radius>box_x+box_w then
        return false
    end
    if ball_x+ball_radius<box_x then
        return false
    end
    return true
end
0 comments



Hello!

I'm learning Pico8 and programming in general, so I'm trying some very very simple things.

I've made a triangle using lines, and using the arrow keys I can move one of the vertices of the triangle.
How can I make it so if I push button5 the arrow keys stop moving that vertex and start moving the second one, press again and changes to the third one and finally press again and changes to the first.

Thank you so much!

So far this is the code I have:

function _init()
    x1=100
    y1=20
    x2=40
    y2=40
    x3=60
    y3=60
    c=7
end

function _update60()
    cls(1)

    if btn(0) then
        x1-=1
    end
    if btn(1) then
        x1+=1
    end
    if btn(2) then
        y1-=1
    end
    if btn(3) then
        y1+=1
    end
end

function _draw()
    line(x1,y1,x2,y2,c)
    line(x2,y2,x3,y3,c)
    line(x3,y3,x1,y1,c)
end
3 comments



I've read somewhere that you can show a flipped sprite using TRUE like in spr(1,x,y,TRUE) but it doesn't seem to work for me.

Is it possible? what i'm i doing wrong?

thank you!!! :)

1 comment



Hello!!!

I'm starting with PICO-8 and loving it!

I’m new to programming and the only thing that I don't like that much is the code editor. The font its pretty hard to read and the horizontal scrolling with so few characters makes it difficult to find errors.

I've read that you can just open the .p8 file and edit them with a text editor and looks like it works just fine but at the end of the file there are some weird big block of characters. Is this expected? If I edit a file with a text editor (lets say Notepad++) I just edit my code and ignore the block of weird characters???

Thank you!!! :D

3 comments