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

223 lines
5.2 KiB

p_x, p_y = 24,16
9 months ago
step_timer = 0
player_sprite_number = 50
the_map = {}
function crystals(story_state)
add(inventory, make_item(library.item_blueprints.crystal))
change_screen(screen_conversation({{ph_p, "you can use these crystals for a lot."}}))
sfx(9)
9 months ago
toast("received crystal!")
end
the_map["5,0"]=crystals
the_map["6,0"]=crystals
function barrel(story_state)
sfx(1)
change_screen(screen_conversation({{ph_p, "it's a barrel!"}}))
end
9 months ago
the_map["2,1"]=barrel
the_map["10,10"]=barrel
the_map["3,1"]=function() -- the atelier!
sfx(4)
change_screen(screen_workbench)
end
the_map["12,1"]=function() --at the well. give us ssome water
add(inventory, make_item(library.item_blueprints.well_water))
change_screen(screen_conversation({{ph_p, "slurp!"}}))
toast("received water!")
sfx(0)
end
the_map["3,10"] = script_charcoal_seller
the_map["11,5"] = script_neighbor
the_map["9,5"] = script_lenore
the_map["9,8"] = script_library
the_map["11,13"] = script_witch
function herbs(story_state)
add(inventory, make_item(library.item_blueprints.herb))
change_screen(screen_conversation({
{ph_p, "ooh, healing herbs! i'll take some. not more than 1/3 the patch though!"}
}))
sfx(8)
toast("received herbs!")
end
the_map["13,12"] = herbs
the_map["14,12"] = herbs
the_map["12,13"] = herbs
the_map["13,13"] = herbs
the_map["14,13"] = herbs
the_map["12,14"] = herbs
the_map["13,14"] = herbs
the_map["14,14"] = herbs
function beach(story_state)
add(inventory, make_item(library.item_blueprints.sand))
change_screen(screen_conversation({
{ph_p, "how many grains of sand does it take before it becomes a pile?"}
}))
sfx(6)
toast("received sand!")
end
the_map["3,15"] = beach
the_map["4,15"] = beach
the_map["5,15"] = beach
the_map["6,15"] = beach
the_map["7,15"] = beach
function interact(x, y)
result = the_map[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(p_x + dx, p_y + dy) & 0x80 == 0 then p_x, p_y = p_x + dx, p_y + dy end
if moved then
t_x, t_y = p_x + 8*dx, p_y + 8*dy
elseif up then
t_x, t_y = p_x, p_y - 8
elseif down then
t_x, t_y = p_x, p_y + 8
elseif flip_x then
t_x, t_y = p_x - 8, p_y
else
t_x, t_y = p_x + 8, p_y
end
if btnp(4) then interact(t_x/8, t_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, p_x-4, p_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({
{ph_p, [[oh, and this is the town! all sorts of things to do here.]]},
{ph_p, [[like i could go get water from the well to the east,]]},
{ph_p, [[or pick up some charcoal from the red house to the southwest!]]},
{ph_p, [[just face a building and press 🅾!]]}
9 months ago
},
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)
if f == nil or f.vx == nil or f.vy == nil or f.x == nil or f.y == nil then return 0 end -- why is this necessary.
local vel = sqrt(f.vx*f.vx + f.vy*f.vy)
9 months ago
f.x += f.vx
f.y += f.vy
f.vx = f.vx*(1-(drag*vel))
f.vy = f.vy*(1-(drag*vel))
9 months ago
return vel
end
function fireworks_update()
walkaround_update()
local new_fireworks = {}
local 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
local v = work(f)
if (v < 0.2 or v > 100) and (f.x ~= nil and f.y ~= nil and f.c ~= nil) 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,
9 months ago
c=f.c
})
end
sfx(8)
else
add(new_fireworks, f)
end
end
for s in all(stars) do
local v = work(s)
if v > 0.2 and v < 100 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