an atelier fangame for the pico-8
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
atelier_phoebe/screen_walkaround.lua

209 lines
5.1 KiB

player_sprite_number = 48
player_x, player_y = 24,16
9 months ago
step_timer = 0
locations = {}
function crystals(story_state)
add(inventory, make_item(library.item_blueprints.crystal))
9 months ago
change_screen(screen_conversation({{phoebe_portrait, "you can use these crystals for a lot."}}))
toast("received crystal!")
end
locations["5,0"]=crystals
locations["6,0"]=crystals
function barrel(story_state)
sfx(1)
change_screen(screen_conversation({{phoebe_portrait, "it's a barrel!"}}))
end
9 months ago
locations["2,1"]=barrel
locations["10,10"]=barrel
locations["3,1"]=function() -- the atelier!
sfx(4)
change_screen(screen_workbench)
end
locations["12,1"]=function() --at the well. give us ssome water
add(inventory, make_item(library.item_blueprints.well_water))
change_screen(screen_conversation({{phoebe_portrait, "slurp!"}}))
toast("received water!")
sfx(0)
end
locations["3,10"] = script_charcoal_seller
locations["11,5"] = script_neighbor
locations["9,5"] = script_lenore
locations["9,8"] = script_library
locations["11,13"] = script_witch
function herbs(story_state)
add(inventory, make_item(library.item_blueprints.herb))
change_screen(screen_conversation({
{phoebe_portrait, "ooh, healing herbs! i'll take some. not more than 1/3 the patch though!"}
}))
toast("received herbs!")
end
locations["14,12"] = herbs
locations["14,13"] = herbs
locations["13,13"] = herbs
locations["13,14"] = herbs
function beach(story_state)
add(inventory, make_item(library.item_blueprints.sand))
change_screen(screen_conversation({
{phoebe_portrait, "how many grains of sand does it take before it becomes a pile?"}
}))
toast("received sand!")
end
locations["3,15"] = beach
locations["4,15"] = beach
locations["5,15"] = beach
locations["6,15"] = beach
locations["7,15"] = beach
function interact(x, y)
result = locations[flr(x) .. "," .. flr(y)]
if result ~= nil then result(story) end
end
function flags_from_xy(x, y)
return fget(mget(x/8, 16+y/8))
end
function walkaround_update()
moved=false
dx, dy = 0, 0
if btn(0) then dx = -1 end
if btn(1) then dx = 1 end
if btn(2) then dy = -1 end
if btn(3) then dy = 1 end
if dx == -1 then flip_x, up, down = true, false, false end
if dx == 1 then flip_x, up, down = false, false, false end
if dy == -1 then up, down = true, false end
if dy == 1 then up, down = false, true end
if dx ~= 0 or dy ~= 0 then moved = true end
if flags_from_xy(player_x + dx, player_y + dy) & 0x80 == 0 then player_x, player_y = player_x + dx, player_y + dy end
if moved then
test_x, test_y = player_x + 8*dx, player_y + 8*dy
elseif up then
test_x, test_y = player_x, player_y - 8
elseif down then
test_x, test_y = player_x, player_y + 8
elseif flip_x then
test_x, test_y = player_x - 8, player_y
else
test_x, test_y = player_x + 8, player_y
end
if btnp(4) then interact(test_x/8, test_y/8) end
end
function walkaround_draw()
cls()
rectfill(8,8,120,120,3)
map(0,16,0,0,16,16) -- draw the town map
update_player_sprite()
spr(player_sprite_number, player_x-4, player_y-8, 1,1, flip_x)
map(0,16,0,0,16,16, 0x40) -- redraw the tiles which are supposed to appear over the player! (flag 6)
end
function update_player_sprite()
if up then player_sprite_number = 52 + (player_sprite_number % 2)
elseif down then player_sprite_number = 50 + (player_sprite_number % 2)
else player_sprite_number = 48 + (player_sprite_number % 2) end
if moved then
step_timer += 1
9 months ago
if step_timer > 4 then
step_timer = 0
if player_sprite_number % 2 == 0 then player_sprite_number += 1
elseif player_sprite_number % 2 ~= 0 then player_sprite_number -= 1 end
end
end
end
screen_walkaround = {update=walkaround_update, draw=walkaround_draw}
9 months ago
screen_walkaround = screen_conversation({
{phoebe_portrait, [[oh, and this is the town! all sorts of things to do here.]]},
{phoebe_portrait, [[like i could go get water from the well to the east,]]},
{phoebe_portrait, [[or go pick up some charcoal from the red house to the southwest!]]},
{phoebe_portrait, [[just face a building and press ❎!]]}
},
function()
screen_walkaround = {draw=walkaround_draw, update=walkaround_update}
change_screen(screen_walkaround)
end,
screen_walkaround)
fireworks = {}
stars = {}
drag = 0.1
fireworks_frequency = 8
9 months ago
function work(f)
local vel = sqrt(f.vx*f.vx+f.vy*f.vy)
f.x += f.vx
f.y += f.vy
f.vx = f.vx*(1-drag*velocity)
f.vy = f.vy*(1-drag*velocity)
return vel
end
function fireworks_update()
walkaround_update()
new_fireworks = {}
new_stars = {}
9 months ago
if rnd(100) < fireworks_frequency then add(new_fireworks, {
x=rnd(128),
y=rnd(112)+16,
vx=rnd(0.4)-0.2,
vy=-5+rnd(1),
c=rnd({10, 8, 7})
}) end
for f in all(fireworks) do
9 months ago
if work(f) < 0.2 then
for i=1,10 do
9 months ago
local theta = rnd(2)
add(new_stars,{
x=f.x,
y=f.y,
vx = sin(theta)*2,
vy = cos(theta)*2,
c=f.c
})
end
else
add(new_fireworks, f)
end
end
for s in all(stars) do
9 months ago
if work(f) > 0.2 then
add(new_stars, s)
end
end
fireworks = new_fireworks
stars = new_stars
end
function fireworks_draw()
walkaround_draw()
for f in all(fireworks) do
circfill(f.x, f.y, 1, f.c)
end
for s in all(stars) do
circfill(s.x, s.y, 1, s.c)
end
end