bjornbytes 9 年 前
コミット
63dbac00dd
2 ファイル変更34 行追加10 行削除
  1. 28 7
      app/mobile.lua
  2. 6 3
      main.lua

+ 28 - 7
app/mobile.lua

@@ -1,4 +1,5 @@
 local controllers = require 'app/controllers'
+local sea = require 'app/sea'
 local vec3 = require('lib/cpml').vec3
 local mat4 = require('lib/cpml').mat4
 
@@ -22,30 +23,36 @@ function mobile:init()
       position = { 0, 0, 0 },
       isEntered = false,
       angle = 0,
-      color = { 200, 0, 0 }
+      color = { 200, 0, 0 },
+      target = sea
     },
     plane = {
       scale = 1,
       position = { 0, 0, 0 },
       isEntered = false,
       angle = 0,
-      color = { 200, 200, 0 }
+      color = { 200, 200, 0 },
+      target = sea
     },
     train = {
       scale = 1,
       position = { 0, 0, 0 },
       isEntered = false,
       angle = 0,
-      color = { 0, 200, 200 }
+      color = { 0, 200, 200 },
+      target = sea
     },
     rocketship = {
       scale = 1,
       position = { 0, 0, 0 },
       isEntered = false,
       angle = 0,
-      color = { 200, 0, 200 }
+      color = { 200, 0, 200 },
+      target = sea
     }
   }
+
+  self.transitionFactor = 0
 end
 
 function mobile:update(dt)
@@ -108,7 +115,8 @@ function mobile:handleToyInput(dt)
   local controller = controllers.list[1]
   if not controller then return end
 
-  local isEntered = false
+  local trigger = controller:getAxis('trigger')
+  local activeToy = nil
 
   _.each(self.toys, function(toy)
     local wasEntered = toy.isEntered
@@ -116,7 +124,7 @@ function mobile:handleToyInput(dt)
     if toy.isEntered then
       toy.scale = _.lerp(toy.scale, 1.25, 8 * dt)
       toy.angle = toy.angle + dt
-      isEntered = true
+      activeToy = toy
     else
       toy.scale = _.lerp(toy.scale, 1, 8 * dt)
     end
@@ -126,7 +134,20 @@ function mobile:handleToyInput(dt)
     end
   end)
 
-  self.isEntered = isEntered
+  if activeToy and trigger > .9 then
+    self.transitionFactor = math.min(self.transitionFactor + dt, 1)
+    if self.transitionFactor >= 1 then
+      setState(activeToy.target)
+    end
+  else
+    self.transitionFactor = math.max(self.transitionFactor - dt, 0)
+  end
+
+  if self.transitionFactor > 0 then
+    controller:vibrate(self.transitionFactor^2 * .0035)
+  end
+
+  self.isEntered = activeToy ~= nil
   self.rotateSpeed = _.lerp(self.rotateSpeed, self.isEntered and 0 or .5, 4 * dt)
 end
 

+ 6 - 3
main.lua

@@ -1,8 +1,6 @@
 _ = require 'lib.lume'
 g = lovr.graphics
-local artichoke = require 'app/artichoke'
 local sea = require 'app/sea'
-local mobile = require 'app/mobile'
 local menu = require 'app/menu'
 local controllers = require 'app/controllers'
 local state = menu
@@ -10,7 +8,8 @@ local state = menu
 function lovr.load()
   -- lovr.graphics.setCullingEnabled(true)
   controllers:init()
-  state:init()
+  menu:init()
+  sea:init()
 end
 
 function lovr.update(dt)
@@ -28,3 +27,7 @@ end
 function lovr.controllerremoved(...)
   controllers:remove(...)
 end
+
+function setState(newState)
+  state = newState
+end