player_sprite_number = 48 player_x, player_y = 24,16 step_timer, stride_length = 0, 4 locations = {} function crystals(story_state) add(inventory, make_item(library.item_blueprints.crystal)) change_screen(screen_conversation({{phoebe_portrait, "my family makes things out of these crystals! i'll take one."}})) 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 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) if testing then toast(x .. "," .. y) end 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 testing then dx, dy = 2*dx, 2*dy 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 testing then dx, dy = dx/2, dy/2 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 if step_timer > stride_length 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} if not testing then 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) end fireworks = {} stars = {} drag = 0.1 fireworks_frequency = 8 function fireworks_update() walkaround_update() new_fireworks = {} new_stars = {} if rnd(100) < fireworks_frequency then add(new_fireworks, new_firework()) end for f in all(fireworks) do velocity = sqrt(f.vx*f.vx + f.vy*f.vy) f.x = f.x + f.vx f.y = f.y + f.vy f.vx = f.vx*(1-drag*velocity) f.vy = f.vy*(1-drag*velocity) if velocity < 0.2 then for i=1,10 do add(new_stars,new_star(f)) end else add(new_fireworks, f) end end for s in all(stars) do velocity = sqrt(s.vx*s.vx + s.vy*s.vy) s.x = s.x + s.vx s.y = s.y + s.vy s.vx = s.vx*(1-drag*velocity) s.vy = s.vy*(1-drag*velocity) if velocity > 0.2 then add(new_stars, s) end end fireworks = new_fireworks stars = new_stars end function new_firework() return { alive=true, x=rnd(128), y=rnd(112)+16, vx=rnd(0.4)-0.2, vy=-5+rnd(1), c=rnd({10, 8, 7}) } end function new_star(t) z = rnd(2) return { alive=true, x=t.x, y=t.y, vx = sin(z)*2, vy = cos(z)*2, c=t.c } 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