commit c0f9ebbdb80bc89479d6284b753c6547d312a213 Author: Anna Wiggins Date: Wed Dec 4 18:48:04 2019 -0500 Initial commit. diff --git a/infimap.lua b/infimap.lua new file mode 100644 index 0000000..3a67fb0 --- /dev/null +++ b/infimap.lua @@ -0,0 +1,29 @@ +function _init() + init_movement() + init_mapgen() + generate_map({0, 0}) + debug = true +end + + +function _update() + handle_input() + if (btn(5) and btn(4) and btnp(3)) debug = not debug +end + +function _draw() + rectfill(0, 0, 127, 127, 0) + -- the screen is 128x128 pixels, so we can only draw 16x16 sprites + map(camera_pos[1], camera_pos[2], 0, 0, 16, 16) + draw_player() + debug_me_baby() +end + +function debug_me_baby() + if debug then + clip(0, 0, 32, 8) + rectfill(0, 0, 32, 8, 0) + print(stat(0), 0, 0, 15) + clip() + end +end diff --git a/infimap.p8 b/infimap.p8 new file mode 100644 index 0000000..a6a61c7 --- /dev/null +++ b/infimap.p8 @@ -0,0 +1,15 @@ +pico-8 cartridge // http://www.pico-8.com +version 18 +__lua__ +#include mapgen.lua +#include movement.lua +#include infimap.lua +__gfx__ +000000000000000033333333335555333344443338333333333333e3383333830000000000000000000000000000000000000000000000000000000000000000 +00000000000000003333333335554553344444438a833383333e3e9e888338880000000000000000000000000000000000000000000000000000000000000000 +0070070000000000333333335555555534444443383338a833e9e3e3373333730000000000000000000000000000000000000000000000000000000000000000 +000770000000000033333333554554553344443333333383333e3333333333330000000000000000000000000000000000000000000000000000000000000000 +00077000000000003333333355555555333553333333833333333333333338330000000000000000000000000000000000000000000000000000000000000000 +00700700000000003333333355545555333553333338a8333e333e33333388830000000000000000000000000000000000000000000000000000000000000000 +000000000000000033333333355555533335533333338333e9e3e9e3333337330000000000000000000000000000000000000000000000000000000000000000 +0000000000000000333333333355553333555533333333333e333e33333333330000000000000000000000000000000000000000000000000000000000000000 diff --git a/mapgen.lua b/mapgen.lua new file mode 100644 index 0000000..5dfbb1c --- /dev/null +++ b/mapgen.lua @@ -0,0 +1,64 @@ +--- Procedural generation methods + +function init_mapgen() + uid_seed = 1229 -- arbitrarily chosen number + block_size = 128 + + -- Sprite ratios for different biomes, of the form { "biome_name": {frequency, sprite index} ... } } + -- frequencies don't have to add up to 100, but they should by convention + -- + -- Sprites are: + -- * 2 - grass + -- * 3 - bush + -- * 4 - tree + -- * 5 - red flowers + -- * 6 - pink flowers + -- * 7 - mushrooms + biomes = { grassland = { {40, 2}, {28, 5}, {28, 6}, {3, 3}, {1, 4} }, + forest = { {40, 2}, {50, 4}, {5, 3}, {4, 5}, {1, 7} } } + + build_biome("forest") +end + +-- use biome1 +function build_biome(biome1, biome2, mix) + if mix == true then + else + frequencies = biomes[biome1] + end + + -- global variable used for lookup during mapgen + biome_lookup = {} + for i=1,#frequencies do + local tuple=frequencies[i] + for j=1,tuple[1] do + add(biome_lookup, tuple[2]) + end + end +end + +-- generates a unique identifier for a position +-- uses srand() and rand() to get an unpredictable value (is this too slow?) +function generate_uid(pos) + srand((pos[1] + uid_seed) * (pos[2] + (uid_seed^2))) + return flr(rnd(-1)) +end + +-- determine what sprite to render for a given position +function get_tile(pos) + return biome_lookup[(generate_uid(pos) % #biome_lookup) + 1] +end + +-- generate the map and writes to the map area from 0 - block_size, +-- assuming 'start' as the top-left corner of the map area to generate. +-- writes block_size x block_size tiles +-- after a call to generate_map you should always center the camera/player over the map, i.e. +-- camera at { (block_size / 2) - 8, (block_size / 2) - 8 } +function generate_map(start) + for x=0,block_size-1 do + for y=0,block_size-1 do + mset(x, y, get_tile({start[1]+x, start[2]+y})) + end + end +end + diff --git a/movement.lua b/movement.lua new file mode 100644 index 0000000..c3bf608 --- /dev/null +++ b/movement.lua @@ -0,0 +1,26 @@ +function init_movement() + camera_pos = {0, 0} +end + + +function handle_input() + new_pos = camera_pos + if (btnp(0)) new_pos[1] -= 1 -- move left + if (btnp(1)) new_pos[1] += 1 -- move right + if (btnp(2)) new_pos[2] -= 1 -- move up + if (btnp(3)) new_pos[2] += 1 -- move down + + if legal_move(new_pos) then + camera_pos = new_pos + end + + -- todo: determine whether we need to regen map and what that means +end + +function draw_player() + +end + +function legal_move(pos) + return true +end