Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pico-8 cartridge // http://www.pico-8.com
- version 30
- __lua__
- -- turnip brothers
- -- by oysuta
- --made for ludum dare 48
- --todo: delete weeb runes
- --タアニッフ゜ ★ フ゛ラサ゛アス゛
- function _init()
- level = 0
- screen = {0,0}
- tile = {0,0}
- is_debug = false
- win = false
- powerup = 0
- super_powerup = 0
- x = 4 * 8 --4
- y = 4 * 8 --4
- depth = 5
- speed = .5
- vx = 0
- vy = 0
- drown_depth = 1
- die_depth = 3
- max_breath = 128
- breath = 128
- recovery_pos = {x,y}
- debug = ""
- current_music = ""
- try_music = "overworld"
- タイトル=true
- end
- function _update60()
- if btnp() > 0 then
- タイトル=false
- end
- if current_music == "garden" then
- sfx(-1,3)
- end
- --loops sfx
- if stat(19) ~= 4 and current_music~= "garden" then
- sfx(4,3)
- end
- --ui timers
- try_music = "overworld"
- if powerup > 0 then
- powerup -= 1
- end
- if super_powerup > 0 then
- super_powerup -= 1
- end
- if win then
- if level>=5 then
- return
- elseif not btnp(🅾️) then
- return
- else
- level+=1
- load_next_level(level)
- end
- end
- screen = {flr(x/128),flr(y/128)}
- tile = {flr((x+4)/8),flr((y+6)/8)}
- debug = tile[1] .. " " .. tile[2]
- player_movement()
- depth = get_depth()
- end
- function load_next_level(level)
- level = levels[level]
- --reinit stuff
- win = false
- drown_depth = 1
- die_depth = 3
- x = level.x
- y = level.y
- recovery_pos = {x,y}
- end
- --music code inspired by eminem
- --(mom's spaghetti)
- function handle_music(new_music)
- if new_music == current_music then
- return
- end
- if new_music == "overworld" then
- music(-1,50)
- music(2,99)
- current_music = "overworld"
- elseif new_music == "secret" then
- music(-1,50)
- music(0,4000)
- current_music = "secret"
- elseif new_music == "garden" then
- music(-1,4000)
- current_music = "garden"
- end
- end
- levels = {
- {
- x=22*8,
- y=5*8
- },
- {
- x=11*8,
- y=29*8
- },
- {
- x=24*8,
- y=50*8
- },
- {
- x=33*8,
- y=50*8
- },
- {
- x=53*8,
- y=38*8
- }
- }
- -->8
- --vector utils
- --turnip brothers
- function v_normalize(x,y)
- local length = v_length(x,y)
- if length > 0 then
- x/=length
- y/=length
- end
- return x,y
- end
- function v_length(x,y)
- return sqrt((x^2)+(y^2))
- end
- function v_zero()
- return 0,0
- end
- -->8
- --player
- function player_movement(delta)
- old = {x,y}
- old_depth = get_depth()
- if btn(⬆️) then
- y -= speed
- elseif btn(⬇️) then
- y += speed
- elseif btn(⬅️) then
- x -= speed
- elseif btn(➡️) then
- x += speed
- end
- -- debug=get_flag()
- --consume powerup
- if get_flag() == 1 then
- sfx(32)
- set_tile(17)
- -- max_breath += 120
- die_depth+=1
- drown_depth+=1
- --powerup text on screen for 180 frames
- powerup = 180
- elseif get_flag() == 16 then
- sfx(34)
- set_tile(17)
- die_depth=9999
- drown_depth=9999
- super_powerup = 180
- elseif get_flag() == 0b10000000 then
- sfx(33)
- win = true
- set_tile(17)
- end
- if get_depth() > die_depth then
- x=old[1]
- y=old[2]
- end
- if get_depth() > drown_depth then
- if old_depth <= drown_depth then
- recovery_pos = {old[1],old[2]}
- end
- breath-=.7
- else
- breath = max_breath
- end
- if breath <= 0 then
- x,y = recovery_pos[1],recovery_pos[2]
- end
- if x>= 1023 then
- x=0
- end
- if x<0 then
- x=1022
- end
- if y>= 511 then
- y=0
- end
- if y<0 then
- y=510
- end
- end
- function get_depth()
- --returns tile index, then
- --subracts 16 to get usable value
- return mget((x+4)/8 ,
- (y+6)/8)
- -16
- end
- function get_flag()
- return fget(mget(
- (x+4)/8 ,
- (y+6)/8)
- )
- end
- function set_tile(index)
- mset((x+4)/8,(y+6)/8,index)
- end
- -->8
- --draw
- function _draw()
- cls()
- debug=x .. " " .. y
- if screen[1] == 4 and screen[2] == 3 then
- try_music = "garden"
- pal(5,3)
- pal(1,12)
- else
- try_music = "overworld"
- pal()
- end
- camera(screen[1]*128,screen[2]*128)
- -- debug = screen[1] .. " " .. screen[2]
- map(0,0,0,0,128,128)
- if depth > die_depth then
- else
- spr(depth,x,y)
- end
- --reset to 0 to draw ui
- camera(0,0)
- --breath meter
- if breath < 128 then
- for i=0,breath do
- rectfill(i,0,i+1,4,6)
- end
- end
- if btn(❎) then
- draw_menu()
- end
- check_secret()
- print("")
- if is_debug then
- print(debug)
- end
- if win then
- draw_win()
- end
- if powerup>0 then
- draw_powered_up()
- end
- if super_powerup>0 then
- draw_super_powered_up()
- end
- -- print(recovery_pos[1] .. " " .. recovery_pos[2])
- handle_music(try_music)
- if タイトル then
- draw_title()
- end
- end
- function print_swimmable(x,y)
- print("can swim: ",x,y,7)
- spr(max_swimmable_tile(),x+36,y)
- end
- function max_swimmable_tile()
- return die_depth+16
- end
- function draw_menu()
- rectfill(16,16,112,112,0)
- -- print_swimmable(32,32)
- print("current depth:\n" .. depth,32,32,7)
- print("breathable depth:\n" .. drown_depth, 32,48,7)
- print("traversable depth:\n" .. die_depth, 32,64, 7)
- end
- function check_secret()
- local tx,ty = tile[1],tile[2]
- --if tx==11 and ty==4 then
- if tx==44 and ty==3 then
- draw_secret("the wind whispers about\nthe amber grain\nthat once grew here\nand which will grow\nagain one day")
- end
- if tx==7 and ty ==19 then
- draw_secret("the wisest earthworm\never to live\nonce made her home here")
- end
- if tx==26 and ty== 38 then
- draw_secret("this pond remembers\nthe parched lips of\na hero whose name\neveryone knows")
- end
- if tx==45 and ty==58 then
- draw_secret("one day,\nwhen all hope is lost,\nit will be found again\nin the shadow of a tree\nwhose seed slumbers here")
- end
- if tx==42 and ty==41 then
- draw_secret("a pale radish and his\nabsentminded brother\nonce took root here")
- end
- if tx==60 and ty==30 then
- draw_secret("the mud here is uninteresting,\nbut happy")
- end
- if tx==114 and ty==55 then
- draw_secret("the world is quiet here")
- end
- end
- function draw_secret(text)
- if get_depth() > drown_depth then
- return
- end
- try_music = "secret"
- camera(0,-64)
- rectfill(0,0,128,64,0)
- print("(you found a secret place)",8,8,1)
- print(text,8,16,6)
- end
- function draw_win()
- rectfill(0,0,128,128,1)
- print("\^w\^trescued.",128/10,128/2,7)
- local helptext = ""
- if level >= 5 then
- helptext = "you've completed the game.\nthanks for playing!"
- else
- helptext = "press 🅾️ (z) to continue."
- end
- print(helptext,128/10,128*.8,6)
- end
- function draw_powered_up()
- print("\^w\^tdepth tolerance\nincreased.",4,100,7)
- end
- function draw_super_powered_up()
- print("\^w\^tdepth tolerance\nmaximized.",4,100,7)
- end
- function draw_title()
- -- local titlex, titley = 112*8, 32*8
- -- camera(titlex,titley)
- -- map(0,0,0,0,128,128)
- -- camera(0,0)
- print("\^tturnip brothers", 8, 8, 6)
- -- print("\^t\^woysuta",72, 112,6)
- -- print("\^t(press x (z) to start)", 8,8)
Advertisement
Add Comment
Please, Sign In to add comment