make a little game where you play as a frog and can eat flies that are flying around with your controllable tongue in pico8
Assistant
Creating a simple game in Pico-8 where you play as a frog trying to eat flies is a fun project. Here's a basic outline and code for a game where you control a frog and try to catch flies with your tongue:
Game Concept
Objective: Control a frog to catch as many flies as possible with its tongue.
Controls: Use arrow keys to move the frog and the 'Z' key to extend its tongue.
Game elements:
Frog: Player-controlled character.
Flies: Randomly moving targets.
Tongue: Extends when you press 'Z', and retracts automatically.
Game Over: Time limit or a specific number of flies caught.
Pico-8 Code
Here's a simple implementation of this concept:
lua
-- Frog game in Pico-8
-- Player controls a frog to eat flies
-- Constants
FLY_COUNT = 5
FLY_SPEED = 0.5
TONGUE_LEN = 10
GAME_DURATION = 60
-- Game variables
frogs = {x=64, y=64, tongue_x=nil, tongue_y=nil, tongue_active=false}
flies = {}
score = 0
time_left = GAME_DURATION
function _init()
-- Initialize flies
for i=1, FLY_COUNT do
add(flies, {x=flr(rnd(128)), y=flr(rnd(128))})
end
end
function _update()
-- Update frog position
if (btn(0)) frogs.x = max(0, frogs.x - 1) -- Left
if (btn(1)) frogs.x = min(127, frogs.x + 1) -- Right
if (btn(2)) frogs.y = max(0, frogs.y - 1) -- Up
if (btn(3)) frogs.y = min(127, frogs.y + 1) -- Down
-- Handle tongue extension
if (btnp(4) and not frogs.tongue_active) then
frogs.tongue_x = frogs.x
frogs.tongue_y = frogs.y
frogs.tongue_active = true
end
if frogs.tongue_active then
frogs.tongue_x = frogs.tongue_x + (frogs.tongue_x < frogs.x + TONGUE_LEN and 2 or -2)
frogs.tongue_y = frogs.tongue_y + (frogs.tongue_y < frogs.y + TONGUE_LEN and 2 or -2)
-- Check if tongue reached max length
if abs(frogs.tongue_x - frogs.x) >= TONGUE_LEN then
frogs.tongue_active = false
end
end
-- Update flies
for fly in all(flies) do
fly.x = fly.x + (rnd(2) - 1) * FLY_SPEED
fly.y = fly.y + (rnd(2) - 1) * FLY_SPEED
fly.x = mid(0, fly.x, 127)
fly.y = mid(0, fly.y, 127)
-- Check collision with tongue
if frogs.tongue_active then
if abs(fly.x - frogs.tongue_x) < 4 and abs(fly.y - frogs.tongue_y) < 4 then
del(flies, fly)
score += 1
end
end
end
-- Game timer
time_left -= 1 / 30
if time_left <= 0 or (#flies == 0) then
time_left = 0
end
end
function _draw()
cls()
-- Draw frog
spr(1, frogs.x, frogs.y)
-- Draw tongue
if frogs.tongue_active then
line(frogs.x + 4, frogs.y + 4, frogs.tongue_x, frogs.tongue_y, 8) -- Tongue
end
-- Draw flies
for fly in all(flies) do
circ(fly.x, fly.y, 2, 10)
end
-- Draw score and time
print("Score: " .. score, 1, 1, 7)
print("Time: " .. flr(time_left)+1, 70, 1, 7)
-- Check if game is over
if time_left <= 0 then
print("Game Over!", 48, 60, 8)
end
end
How to Use the Code:
Copy and paste the code into your Pico-8 editor.
Press 'Run' to start the game.
Use the arrow keys to move the frog around.
Press 'Z' to extend the frog's tongue and catch flies.
This simple game provides a good starting point. You can enhance it with features like increasing difficulty, more elaborate graphics, or additional mechanics to make it more engaging!