oysuta

Turnip Brothers LD48 Source Code

Apr 25th, 2021
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 53.79 KB | None | 0 0
  1. pico-8 cartridge // http://www.pico-8.com
  2. version 30
  3. __lua__
  4. -- turnip brothers
  5. -- by oysuta
  6.  
  7. --made for ludum dare 48
  8.  
  9. --todo: delete weeb runes
  10. --タアニッフ゜ ★ フ゛ラサ゛アス゛
  11.  
  12.  
  13. function _init()
  14.         level = 0
  15.         screen = {0,0}
  16.         tile = {0,0}
  17.         is_debug = false
  18.         win = false
  19.         powerup = 0
  20.         super_powerup = 0
  21.         x = 4 * 8 --4
  22.         y = 4 * 8 --4
  23.         depth = 5
  24.         speed = .5
  25.         vx = 0
  26.         vy = 0
  27.         drown_depth = 1
  28.         die_depth = 3
  29.         max_breath = 128
  30.         breath = 128
  31.         recovery_pos = {x,y}
  32.         debug = ""
  33.         current_music = ""
  34.         try_music = "overworld"
  35.         タイトル=true
  36. end
  37.  
  38. function _update60()
  39.     if btnp() > 0 then
  40.         タイトル=false
  41.     end
  42.     if current_music == "garden" then
  43.         sfx(-1,3)
  44.     end
  45.     --loops sfx
  46.     if stat(19) ~= 4 and current_music~= "garden" then
  47.         sfx(4,3)
  48.     end
  49.     --ui timers
  50.     try_music = "overworld"
  51.     if powerup > 0 then
  52.         powerup -= 1
  53.     end
  54.    
  55.     if super_powerup > 0 then
  56.         super_powerup -= 1
  57.     end
  58.    
  59.     if win then
  60.         if level>=5 then
  61.             return 
  62.         elseif not btnp(🅾️) then
  63.             return
  64.         else
  65.             level+=1
  66.             load_next_level(level)
  67.         end
  68.     end
  69.    
  70.     screen = {flr(x/128),flr(y/128)}
  71.     tile = {flr((x+4)/8),flr((y+6)/8)}
  72.     debug = tile[1] .. " " .. tile[2]
  73.     player_movement()
  74.     depth = get_depth()
  75. end
  76.  
  77. function load_next_level(level)
  78.     level = levels[level]
  79.     --reinit stuff
  80.     win = false
  81.     drown_depth = 1
  82.     die_depth = 3
  83.    
  84.     x = level.x
  85.     y = level.y
  86.     recovery_pos = {x,y}
  87.    
  88. end
  89.  
  90.  
  91. --music code inspired by eminem
  92. --(mom's spaghetti)
  93. function handle_music(new_music)
  94.     if new_music == current_music then
  95.         return
  96.     end
  97.    
  98.     if new_music == "overworld" then
  99.         music(-1,50)
  100.         music(2,99)
  101.         current_music = "overworld"
  102.     elseif new_music == "secret" then
  103.         music(-1,50)
  104.         music(0,4000)
  105.         current_music = "secret"
  106.     elseif new_music == "garden" then
  107.         music(-1,4000)
  108.         current_music = "garden"
  109.     end
  110. end
  111.  
  112. levels = {
  113.     {
  114.         x=22*8,
  115.         y=5*8
  116.     },
  117.     {
  118.         x=11*8,
  119.         y=29*8
  120.     },
  121.     {
  122.         x=24*8,
  123.         y=50*8
  124.     },
  125.     {
  126.         x=33*8,
  127.         y=50*8
  128.     },
  129.     {
  130.         x=53*8,
  131.         y=38*8
  132.     }
  133. }
  134. -->8
  135. --vector utils
  136. --turnip brothers
  137. function v_normalize(x,y)
  138.     local length = v_length(x,y)
  139.     if length > 0 then
  140.         x/=length
  141.         y/=length
  142.     end
  143.     return x,y
  144. end
  145.  
  146. function v_length(x,y)
  147.     return sqrt((x^2)+(y^2))
  148. end
  149.  
  150. function v_zero()
  151.     return 0,0
  152. end
  153. -->8
  154. --player
  155.  
  156. function player_movement(delta)
  157.     old = {x,y}
  158.     old_depth = get_depth()
  159.     if btn(⬆️) then
  160.         y -= speed
  161.     elseif btn(⬇️) then
  162.         y += speed
  163.     elseif btn(⬅️) then
  164.         x -= speed
  165.     elseif btn(➡️) then
  166.         x += speed
  167.     end
  168.    
  169. --  debug=get_flag()
  170.    
  171.     --consume powerup
  172.     if get_flag() == 1 then
  173.         sfx(32)
  174.         set_tile(17)
  175. --      max_breath += 120
  176.         die_depth+=1
  177.         drown_depth+=1
  178.        
  179.         --powerup text on screen for 180 frames
  180.         powerup = 180
  181.     elseif get_flag() == 16 then
  182.         sfx(34)
  183.         set_tile(17)
  184.         die_depth=9999
  185.         drown_depth=9999
  186.         super_powerup = 180
  187.     elseif get_flag() == 0b10000000 then
  188.         sfx(33)
  189.         win = true
  190.         set_tile(17)
  191.     end
  192.    
  193.     if get_depth() > die_depth then
  194.         x=old[1]
  195.         y=old[2]
  196.     end
  197.    
  198.     if get_depth() > drown_depth then
  199.         if old_depth <= drown_depth then
  200.             recovery_pos = {old[1],old[2]}
  201.         end
  202.         breath-=.7
  203.     else
  204.         breath = max_breath
  205.     end
  206.    
  207.     if breath <= 0 then
  208.         x,y = recovery_pos[1],recovery_pos[2]
  209.     end
  210.    
  211.     if x>= 1023 then
  212.         x=0
  213.     end
  214.     if x<0 then
  215.         x=1022
  216.     end
  217.     if y>= 511 then
  218.         y=0
  219.     end
  220.     if y<0 then
  221.         y=510
  222.     end
  223.    
  224. end
  225.  
  226. function get_depth()
  227. --returns tile index, then
  228. --subracts 16 to get usable value
  229.     return mget((x+4)/8 ,
  230.                                                     (y+6)/8)
  231.                                                     -16
  232. end
  233.  
  234. function get_flag()
  235.     return fget(mget(
  236.                                                     (x+4)/8 ,
  237.                                                     (y+6)/8)
  238.                                                 )
  239. end
  240.  
  241. function set_tile(index)
  242.     mset((x+4)/8,(y+6)/8,index)
  243. end
  244. -->8
  245. --draw
  246. function _draw()
  247.     cls()
  248.     debug=x .. " " ..  y
  249.     if screen[1] == 4 and screen[2] == 3 then
  250.         try_music = "garden"
  251.         pal(5,3)
  252.         pal(1,12)
  253.     else
  254.         try_music = "overworld"
  255.         pal()
  256.     end
  257.     camera(screen[1]*128,screen[2]*128)
  258. --  debug = screen[1] .. " " .. screen[2]
  259.     map(0,0,0,0,128,128)
  260.     if depth > die_depth then
  261.     else
  262.         spr(depth,x,y)
  263.     end
  264.    
  265.     --reset to 0 to draw ui
  266.     camera(0,0)
  267.     --breath meter
  268.     if breath < 128 then
  269.         for i=0,breath do
  270.             rectfill(i,0,i+1,4,6)
  271.         end
  272.     end
  273.     if btn(❎) then
  274.         draw_menu()
  275.     end
  276.    
  277.     check_secret()
  278.    
  279.     print("")
  280.     if is_debug then
  281.         print(debug)
  282.     end
  283.    
  284.     if win then
  285.         draw_win()
  286.     end
  287.    
  288.     if powerup>0 then
  289.         draw_powered_up()
  290.     end
  291.    
  292.     if super_powerup>0 then
  293.         draw_super_powered_up()
  294.     end
  295. --  print(recovery_pos[1] .. " " .. recovery_pos[2])
  296.     handle_music(try_music)
  297.     if タイトル then
  298.         draw_title()
  299.     end
  300. end
  301.  
  302. function print_swimmable(x,y)
  303.     print("can swim: ",x,y,7)
  304.     spr(max_swimmable_tile(),x+36,y)
  305. end
  306.  
  307. function max_swimmable_tile()
  308.     return die_depth+16
  309. end
  310.  
  311. function draw_menu()
  312.     rectfill(16,16,112,112,0)
  313. --  print_swimmable(32,32)
  314.     print("current depth:\n" .. depth,32,32,7)
  315.     print("breathable depth:\n" .. drown_depth, 32,48,7)
  316.     print("traversable depth:\n" .. die_depth, 32,64, 7)
  317. end
  318.  
  319. function check_secret()
  320.     local tx,ty = tile[1],tile[2]
  321.     --if tx==11 and ty==4 then
  322.     if tx==44 and ty==3 then
  323.         draw_secret("the wind whispers about\nthe amber grain\nthat once grew here\nand which will grow\nagain one day")
  324.     end
  325.     if tx==7 and ty ==19 then
  326.         draw_secret("the wisest earthworm\never to live\nonce made her home here")
  327.     end
  328.     if tx==26 and ty== 38 then
  329.         draw_secret("this pond remembers\nthe parched lips of\na hero whose name\neveryone knows")
  330.     end
  331.     if tx==45 and ty==58 then
  332.         draw_secret("one day,\nwhen all hope is lost,\nit will be found again\nin the shadow of a tree\nwhose seed slumbers here")
  333.     end
  334.     if tx==42 and ty==41 then
  335.         draw_secret("a pale radish and his\nabsentminded brother\nonce took root here")
  336.     end
  337.     if tx==60 and ty==30 then
  338.         draw_secret("the mud here is uninteresting,\nbut happy")
  339.     end
  340.     if tx==114 and ty==55 then
  341.         draw_secret("the world is quiet here")
  342.     end
  343. end
  344.  
  345. function draw_secret(text)
  346.     if get_depth() > drown_depth then
  347.         return
  348.     end
  349.     try_music = "secret"
  350.     camera(0,-64)
  351.     rectfill(0,0,128,64,0)
  352.         print("(you found a secret place)",8,8,1)
  353.         print(text,8,16,6)
  354. end
  355.  
  356. function draw_win()
  357.     rectfill(0,0,128,128,1)
  358.     print("\^w\^trescued.",128/10,128/2,7)
  359.     local helptext = ""
  360.     if level >= 5 then
  361.         helptext = "you've completed the game.\nthanks for playing!"
  362.     else
  363.         helptext = "press 🅾️ (z) to continue."
  364.     end
  365.     print(helptext,128/10,128*.8,6)
  366.        
  367. end
  368.  
  369. function draw_powered_up()
  370.     print("\^w\^tdepth tolerance\nincreased.",4,100,7)
  371. end
  372.  
  373. function draw_super_powered_up()
  374.     print("\^w\^tdepth tolerance\nmaximized.",4,100,7)
  375. end
  376.  
  377. function draw_title()
  378. --  local titlex, titley = 112*8, 32*8
  379. --  camera(titlex,titley)
  380. --  map(0,0,0,0,128,128)
  381. --  camera(0,0)
  382.     print("\^tturnip brothers", 8, 8, 6)
  383. --  print("\^t\^woysuta",72, 112,6)
  384. --  print("\^t(press x (z) to start)", 8,8)
  385.  
Advertisement
Add Comment
Please, Sign In to add comment