MadeaInaba

MineDwarf v0.03

Jan 13th, 2012
156
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. shell.run('RinAPI')
  2. shell.run('simplemenuapi')
  3.  
  4. --Sprites
  5. psprite = {}
  6. psprite.up = '^'
  7. psprite.down = 'V'
  8. psprite.right = '>'
  9. psprite.left = '<'
  10. psprite.select = '-->'
  11.  
  12. --ENTITIES
  13. player = entity.new('Player', 5, 5, psprite.up, true, true)
  14. entity.addvar(player, 'num', 1)
  15. title = entity.new('title', 1, 1, 'MineDwarf: Beginnings', true, false)
  16. entity.setabs(title, true)
  17. debug = entity.new('Debug', 2, window.h, ' ', true, false)
  18. entity.setabs(debug, true)
  19.  
  20. --MENU
  21. tabmenu = {}
  22. tabmenu[1] = menu.create('Tab Menu', false)
  23. tabmenu[2] = menu.additem(tabmenu[1], 'E: Interact')
  24. tabmenu[3] = menu.additem(tabmenu[1], 'I: Inventory')
  25. tabmenu[4] = menu.additem(tabmenu[1], 'H: Controls')
  26. --menu.startselect(tabmenu[1])
  27. --menu.active = tabmenu[1]
  28.  
  29. conmenu = {}
  30. conmenu.open = 0
  31. conmenu[1] = menu.create('Controls', true)
  32. conmenu[2] = menu.additem(conmenu[1], 'H: Close this menu')
  33. conmenu[3] = menu.additem(conmenu[1], 'WASD: Movement')
  34. conmenu[4] = menu.additem(conmenu[1], 'Backspace: Exit')
  35.  
  36. --Inventory
  37. --invmenu = {}
  38. --invmenu.open = 0
  39. --invmenu[1] = menu.create('Inventory', true)
  40. --inv
  41.  
  42. --Functions
  43.  
  44. wall = {}
  45. wallnum = 1
  46. function wall.new(x,y)
  47.     wall[wallnum] = entity.new('Wall', x, y, '=', true, true )
  48.     wallnum = wallnum+1
  49. end
  50.  
  51. room = {}
  52.  
  53. function room.new(x1,y1,x2,y2)
  54.     write('newroom')
  55.     i=0
  56.     while i < x2-x1+1 do
  57.         wall.new(x1+i,y1)
  58.         i= i+1
  59.     end
  60.     i=0
  61.     while i < x2-x1+1 do
  62.         wall.new(x1+i,y2)
  63.         i= i+1
  64.     end
  65.     i=0
  66.     while i < y2-y1+1 do
  67.         if i ~= 4 then
  68.             wall.new(x1, y1+i)
  69.         end
  70.         i= i+1
  71.     end
  72.     i=0
  73.     while i < y2-y1+1 do
  74.         wall.new(x2, y1+i)
  75.         i= i+1
  76.     end
  77. end
  78.  
  79. room.new(7,7,15,15)
  80.  
  81. --[[||||| KEY EXECUTION |||||]]--
  82. function exec.key(k)
  83.     --Up
  84.     if k == 17 then
  85.         entity.setpos( player, 0, -1, true )
  86.         entity.setvar(player, 'num', entity.getvar(player, 'num') + 1 )
  87.         entity.setchar( player, psprite.up )
  88.     end
  89.     --Down
  90.     if k == 31 then
  91.         entity.setpos( player, 0, 1, true )
  92.         entity.setvar(player, 'num', entity.getvar(player, 'num') + 1 )
  93.         entity.setchar( player, psprite.down )
  94.     end
  95.     --Left
  96.     if k == 30 then
  97.         entity.setpos( player, -1, 0, true )
  98.         entity.setvar(player, 'num', entity.getvar(player, 'num') + 1 )
  99.         entity.setchar( player, psprite.left )
  100.     end
  101.     --Right
  102.     if k == 32 then
  103.         entity.setpos( player, 1, 0, true )
  104.         entity.setvar(player, 'num', entity.getvar(player, 'num') + 1 )
  105.         entity.setchar( player, psprite.right )
  106.     end
  107.    
  108.     if k == 18 then
  109.         check = false
  110.         local x = entity.getposx(player)
  111.         local y = entity.getposy(player)
  112.         local facing = entity.getvar(player, 'Character')
  113.         if facing == psprite.up then
  114.             check = get.locphys(x, y-1)
  115.         elseif facing == psprite.down then
  116.             check = get.locphys(x, y+1)
  117.         elseif facing == psprite.right then
  118.             check = get.locphys(x+1, y)
  119.         elseif facing == psprite.left then
  120.             check = get.locphys(x-1, y)
  121.         end
  122.        
  123.         if check then
  124.             check = entity.getvar(check, 'Name')
  125.             if check == 'Wall' then
  126.                 entity.setchar(debug, "That's a wall")
  127.                 time.text = 1
  128.             end
  129.         end
  130.     end
  131.        
  132.     if k == 35 then
  133.         if conmenu.open == 0 then
  134.             conmenu.open = 1
  135.         else
  136.             conmenu.open = 0
  137.         end
  138.     end
  139.    
  140.     if k == 28 then
  141.         menu.choose()
  142.     end
  143.            
  144.    
  145.     --[[Screen]]--
  146.     --[[Up
  147.     if k == 200 then
  148.         menu.up(tabmenu[1])
  149.     end
  150.     --Down
  151.     if k == 208 then
  152.         menu.down(tabmenu[1])
  153.     end]]--
  154.     --[[Left
  155.     if k == 203 then
  156.         screen.x = screen.x - 1
  157.     end
  158.     --Right
  159.     if k == 205 then
  160.         screen.x = screen.x + 1
  161.     end]]--
  162. end
  163.  
  164. time = {}
  165. time.text = 0
  166. function exec.step()
  167.     if time.text ~= 0 then
  168.         time.text = time.text+1
  169.     end
  170.     if time.text == 50 then
  171.         time.text = 0
  172.         entity.setchar(debug, ' ')
  173.     end
  174.     --[[Window Follow]]--
  175.     screen.x = entity.getposx(player) - window.midw
  176.     screen.y = entity.getposy(player) - window.midh
  177. end
  178.  
  179. function menu.choice(id)
  180.     entity.setchar(debug, id)
  181.     time.text = 1
  182. end
  183.  
  184. function exec.cdraw()
  185.     if conmenu.open == 1 then
  186.         menu.draw(conmenu[1], 1, 2, 0)
  187.     else
  188.         menu.draw(tabmenu[1], 1, 2, 0)
  189.     end
  190. end
  191.  
  192. exec.start()
RAW Paste Data