main.lua 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. local chui = require'chui'
  2. local main_panel, options_panel
  3. local is_wireframe = false
  4. local rgb_filter = {true, true, true}
  5. function lovr.load()
  6. local pose = mat4(-0.2, 1.7, -0.4):scale(0.1)
  7. -- Main Menu Buttons
  8. main_panel = chui.panel{ pose=pose, palette=chui.palettes[3] }
  9. playbutton_panel = chui.panel{ frame='none', palette=chui.palettes[1] }
  10. playbutton_panel:button{ text='CONTINUE', thickness=0.3, span={3, 1.4}, callback =
  11. function()
  12. main_panel.visible = false
  13. end }
  14. playbutton_panel:layout()
  15. main_panel:nest(playbutton_panel)
  16. main_panel:row()
  17. main_panel:button{ text='OPTIONS', thickness=0.2, span=3, callback =
  18. function()
  19. main_panel.visible = false
  20. options_panel.visible = true
  21. end }
  22. main_panel:row()
  23. main_panel:row()
  24. main_panel:button{ thickness=0.2, span={3, 0.8}, text='HELP' }
  25. main_panel:row()
  26. main_panel:button{ thickness=0.2, span={3, 0.8}, text='CREDITS' }
  27. main_panel:row()
  28. main_panel:row()
  29. main_panel:button{ thickness=0.2, span={3, 0.6}, text='EXIT »', callback=function() lovr.event.quit() end }
  30. main_panel:layout('left')
  31. -- Options Panel (initially hidden)
  32. options_panel = chui.panel{ pose=mat4(pose):scale(0.6), palette=chui.palettes[3] }
  33. options_panel:label{ text='Video', text_scale=2 }
  34. options_panel:row()
  35. options_panel:label{ text='Wireframe' }
  36. options_panel:toggle{ span={0.8, 0.8}, thickness=0.15, state=false, callback =
  37. function(_, state)
  38. is_wireframe = state
  39. end }
  40. options_panel:layout('left')
  41. options_panel:row()
  42. options_panel:label{ text='Color filtering' }
  43. options_panel:toggle{ span={0.8, 0.8}, thickness=0.15, state=true, text='R', callback=function(_,s) rgb_filter[1] = s end }
  44. options_panel:toggle{ span={0.8, 0.8}, thickness=0.15, state=true, text='G', callback=function(_,s) rgb_filter[2] = s end }
  45. options_panel:toggle{ span={0.8, 0.8}, thickness=0.15, state=true, text='B', callback=function(_,s) rgb_filter[3] = s end }
  46. options_panel:row()
  47. options_panel:label{ text='Audio', text_scale=2 }
  48. options_panel:row()
  49. options_panel:toggle{ span={0.8, 0.8}, thickness=0.15, state=true }
  50. options_panel:slider{ text='Sound', step=1, min=0, max=100, value=80, format='%s %d', span=4 }
  51. options_panel:row()
  52. options_panel:toggle{ span={0.8, 0.8}, thickness=0.15, state=true }
  53. options_panel:slider{ text='Music', step=1, min=0, max=100, value=75, format='%s %d', span=4 }
  54. options_panel:row()
  55. options_panel:row()
  56. options_panel:button{ text='« BACK', thickness=0.15, span={1.4, 0.8}, callback =
  57. function()
  58. main_panel.visible = true
  59. options_panel.visible = false
  60. end }
  61. options_panel:layout('left')
  62. options_panel.visible = false
  63. end
  64. -- a 3D scene placeholder
  65. lovr.graphics.setBackgroundColor(0.059, 0.165, 0.247)
  66. local palette = {{0.031, 0.078, 0.118}, {0.125, 0.224, 0.310}, {0.965, 0.839, 0.741}, {0.765, 0.639, 0.541}, {0.600, 0.459, 0.467}, {0.506, 0.384, 0.443}, {0.306, 0.286, 0.373}}
  67. function sceneDraw(pass)
  68. local t = lovr.timer.getTime()
  69. for x = -64, 64, 4 do
  70. for z = -64, 64, 4 do
  71. z = z + (x % 8) * 0.5
  72. local h = lovr.math.noise(x, z) * 3 + (x*x + z*z) * 5e-3
  73. pass:setColor(palette[1 + math.floor(h * 7) % #palette])
  74. h = h * (1 + 0.05 * math.sin(t * 0.2 + h))
  75. pass:cylinder(x, -3 + h / 2, z, 2.2, h, math.pi/2, 1,0,0, true, nil, nil, 6)
  76. end
  77. end
  78. end
  79. function lovr.draw(pass)
  80. main_panel.pose:rotate(math.sin(lovr.timer.getTime() * 4) * 0.002, 0, 1, 0)
  81. options_panel.pose:rotate(math.sin(lovr.timer.getTime() * 4) * 0.002, 0, 1, 0)
  82. pass:setColorWrite(unpack(rgb_filter))
  83. pass:setWireframe(is_wireframe)
  84. sceneDraw(pass)
  85. chui.draw(pass, true)
  86. end
  87. function lovr.update(dt)
  88. chui.update(dt)
  89. end
  90. function lovr.keypressed(key)
  91. if key == 'escape' then
  92. main_panel.visible = true
  93. options_panel.visible = false
  94. end
  95. end