mirror of
https://gitea.com/SweetSea-ButImNotSweet/tromi_mobile.git
synced 2025-01-08 17:33:09 +08:00
Moving VCTRL related calls and adding buttons for name entry screen
This commit is contained in:
@@ -13,6 +13,8 @@ local Piece = require 'game.piece'
|
|||||||
local GameMode = Object:extend()
|
local GameMode = Object:extend()
|
||||||
|
|
||||||
function GameMode:new(player_name, input_file, replay_grade)
|
function GameMode:new(player_name, input_file, replay_grade)
|
||||||
|
VCTRL.toggle(true)
|
||||||
|
|
||||||
if player_name == nil then self.training = true else self.training = false end
|
if player_name == nil then self.training = true else self.training = false end
|
||||||
if input_file ~= nil then
|
if input_file ~= nil then
|
||||||
input_file = love.filesystem.newFile(REPLAY_DIR..input_file, 'r'):read()
|
input_file = love.filesystem.newFile(REPLAY_DIR..input_file, 'r'):read()
|
||||||
@@ -308,15 +310,6 @@ function GameMode:getReplayInputs(input_file)
|
|||||||
local replay_inputs = {}
|
local replay_inputs = {}
|
||||||
local semicolon_position = string.find(input_file, ';', 1, true)
|
local semicolon_position = string.find(input_file, ';', 1, true)
|
||||||
|
|
||||||
-- for _=1,1e99 do
|
|
||||||
-- local c = string.sub(input_file,_,_)
|
|
||||||
-- if c == ';' then
|
|
||||||
-- reached_inputs = true
|
|
||||||
-- i = _ + 1
|
|
||||||
-- end
|
|
||||||
-- if reached_inputs then break end
|
|
||||||
-- end
|
|
||||||
|
|
||||||
if semicolon_position then
|
if semicolon_position then
|
||||||
for i = semicolon_position + 1, #input_file, 3 do
|
for i = semicolon_position + 1, #input_file, 3 do
|
||||||
local input_list = {right = false, rotate_right2 = false, up = false, rotate_left = false, left = false, down = false, rotate_right = false, rotate_left2 = false}
|
local input_list = {right = false, rotate_right2 = false, up = false, rotate_left = false, left = false, down = false, rotate_right = false, rotate_left2 = false}
|
||||||
@@ -346,12 +339,6 @@ function GameMode:getInputPieceSeq(input_file)
|
|||||||
input_file, string_start,
|
input_file, string_start,
|
||||||
string.find(input_file, ';', string_start, true) - 1
|
string.find(input_file, ';', string_start, true) - 1
|
||||||
) -- seed
|
) -- seed
|
||||||
-- for i = string_start, #input_file do
|
|
||||||
-- local c = string.sub(input_file, i, i)
|
|
||||||
-- if c == ';' then break
|
|
||||||
-- else seed = seed..c
|
|
||||||
-- end
|
|
||||||
-- end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function GameMode:update(inputs, ruleset)
|
function GameMode:update(inputs, ruleset)
|
||||||
@@ -936,19 +923,19 @@ end
|
|||||||
|
|
||||||
function GameMode:drawInputDisplay(left, top)
|
function GameMode:drawInputDisplay(left, top)
|
||||||
if self.replay_inputs[self.frames] ~= nil then
|
if self.replay_inputs[self.frames] ~= nil then
|
||||||
drawText("+", left+10, top+8, 1000, "left")
|
drawText("·", left+10, top+8, 1000, "left")
|
||||||
drawText("v", left+10, top+18, 1000, "left",{1-boolToInt(self.replay_inputs[self.frames]['down']),1,1-boolToInt(self.replay_inputs[self.frames]['down']),1})
|
drawText("↓", left+10, top+18, 1000, "left",{1-boolToInt(self.replay_inputs[self.frames]['down']),1,1-boolToInt(self.replay_inputs[self.frames]['down']),1})
|
||||||
drawText("<", left, top+8, 1000, "left",{1-boolToInt(self.replay_inputs[self.frames]['left']),1,1-boolToInt(self.replay_inputs[self.frames]['left']),1})
|
drawText("←", left, top+8, 1000, "left",{1-boolToInt(self.replay_inputs[self.frames]['left']),1,1-boolToInt(self.replay_inputs[self.frames]['left']),1})
|
||||||
drawText(">", left+20, top+8, 1000, "left",{1-boolToInt(self.replay_inputs[self.frames]['right']),1,1-boolToInt(self.replay_inputs[self.frames]['right']),1})
|
drawText("→", left+20, top+8, 1000, "left",{1-boolToInt(self.replay_inputs[self.frames]['right']),1,1-boolToInt(self.replay_inputs[self.frames]['right']),1})
|
||||||
drawText("L", left+35, top+8, 1000, "left",{1-boolToInt(self.replay_inputs[self.frames]['rotate_left']),1,1-boolToInt(self.replay_inputs[self.frames]['rotate_left']),1})
|
drawText("L", left+35, top+8, 1000, "left",{1-boolToInt(self.replay_inputs[self.frames]['rotate_left']),1,1-boolToInt(self.replay_inputs[self.frames]['rotate_left']),1})
|
||||||
drawText("R", left+50, top+8, 1000, "left",{1-boolToInt(self.replay_inputs[self.frames]['rotate_right']),1,1-boolToInt(self.replay_inputs[self.frames]['rotate_right']),1})
|
drawText("R", left+50, top+8, 1000, "left",{1-boolToInt(self.replay_inputs[self.frames]['rotate_right']),1,1-boolToInt(self.replay_inputs[self.frames]['rotate_right']),1})
|
||||||
drawText("L", left+65, top+8, 1000, "left",{1-boolToInt(self.replay_inputs[self.frames]['rotate_left2']),1,1-boolToInt(self.replay_inputs[self.frames]['rotate_left2']),1})
|
drawText("L", left+65, top+8, 1000, "left",{1-boolToInt(self.replay_inputs[self.frames]['rotate_left2']),1,1-boolToInt(self.replay_inputs[self.frames]['rotate_left2']),1})
|
||||||
drawText("R", left+80, top+8, 1000, "left",{1-boolToInt(self.replay_inputs[self.frames]['rotate_right2']),1,1-boolToInt(self.replay_inputs[self.frames]['rotate_right2']),1})
|
drawText("R", left+80, top+8, 1000, "left",{1-boolToInt(self.replay_inputs[self.frames]['rotate_right2']),1,1-boolToInt(self.replay_inputs[self.frames]['rotate_right2']),1})
|
||||||
else
|
else
|
||||||
drawText("+", left+10, top+8, 1000, "left")
|
drawText("·", left+10, top+8, 1000, "left")
|
||||||
drawText("v", left+10, top+18, 1000, "left")
|
drawText("↓", left+10, top+18, 1000, "left")
|
||||||
drawText("<", left, top+8, 1000, "left")
|
drawText("←", left, top+8, 1000, "left")
|
||||||
drawText(">", left+20, top+8, 1000, "left")
|
drawText("→", left+20, top+8, 1000, "left")
|
||||||
drawText("L", left+35, top+8, 1000, "left")
|
drawText("L", left+35, top+8, 1000, "left")
|
||||||
drawText("R", left+50, top+8, 1000, "left")
|
drawText("R", left+50, top+8, 1000, "left")
|
||||||
drawText("L", left+65, top+8, 1000, "left")
|
drawText("L", left+65, top+8, 1000, "left")
|
||||||
|
|||||||
@@ -73,44 +73,48 @@ end
|
|||||||
function control_type.button:reset()
|
function control_type.button:reset()
|
||||||
self.pressed=false
|
self.pressed=false
|
||||||
self.lastPressTime=-1e99
|
self.lastPressTime=-1e99
|
||||||
|
self.pressingID=false
|
||||||
end
|
end
|
||||||
function control_type.button:press()
|
function control_type.button:press(_,_,id)
|
||||||
self.pressed=true
|
self.pressed=true
|
||||||
self.lastPressTime=love.timer.getTime()
|
self.lastPressTime=love.timer.getTime()
|
||||||
|
self.pressing=id
|
||||||
-- love.keypressed(self.key, love.keyboard.getScancodeFromKey(self.key))
|
-- love.keypressed(self.key, love.keyboard.getScancodeFromKey(self.key))
|
||||||
SCENE:onInputPress{input=self.key,type="virtual"}
|
SCENE:onInputPress{input=self.key,type="virtual"}
|
||||||
end
|
end
|
||||||
function control_type.button:release()
|
function control_type.button:release()
|
||||||
self.pressed=false
|
self.pressed=false
|
||||||
|
self.pressingID=false
|
||||||
-- love.keyreleased(self.key,love.keyboard.getScancodeFromKey(self.key))
|
-- love.keyreleased(self.key,love.keyboard.getScancodeFromKey(self.key))
|
||||||
SCENE:onInputRelease{input=self.key,type="virtual"}
|
SCENE:onInputRelease{input=self.key,type="virtual"}
|
||||||
end
|
end
|
||||||
function control_type.button:drag(dx,dy)
|
function control_type.button:drag(dx,dy)
|
||||||
self.x,self.y=self.x+dx,self.y+dy
|
self.x,self.y=self.x+dx,self.y+dy
|
||||||
end
|
end
|
||||||
function control_type.button:draw(forceLight)
|
function control_type.button:draw(forceAlpha)
|
||||||
|
local alpha = forceAlpha or self.alpha
|
||||||
love.graphics.setLineWidth(4)
|
love.graphics.setLineWidth(4)
|
||||||
if self.shape=='circle' then
|
if self.shape=='circle' then
|
||||||
love.graphics.setColor(0,0,0,self.alpha)
|
love.graphics.setColor(0,0,0,alpha)
|
||||||
love.graphics.circle('fill',self.x,self.y,self.r-4)
|
love.graphics.circle('fill',self.x,self.y,self.r-4)
|
||||||
|
|
||||||
love.graphics.setColor(1,1,1,self.pressed and .5 or .05)
|
love.graphics.setColor(1,1,1,self.pressed and .5 or 0)
|
||||||
love.graphics.circle('fill',self.x,self.y,self.r-4)
|
love.graphics.circle('fill',self.x,self.y,self.r-4)
|
||||||
|
|
||||||
love.graphics.setColor(1,1,1)
|
love.graphics.setColor(1,1,1,alpha)
|
||||||
love.graphics.circle('line',self.x,self.y,self.r-2)
|
love.graphics.circle('line',self.x,self.y,self.r-2)
|
||||||
elseif self.shape=='square' then
|
elseif self.shape=='square' then
|
||||||
love.graphics.setColor(0,0,0,self.alpha)
|
love.graphics.setColor(0,0,0,alpha)
|
||||||
love.graphics.rectangle('fill',self.x-self.r-4,self.y-self.r-4,self.r*2+8,self.r*2+8)
|
love.graphics.rectangle('fill',self.x-self.r-4,self.y-self.r-4,self.r*2+8,self.r*2+8)
|
||||||
|
|
||||||
love.graphics.setColor(1,1,1,self.pressed and .5 or .05)
|
love.graphics.setColor(1,1,1,self.pressed and .5 or 0)
|
||||||
love.graphics.rectangle('fill',self.x-self.r-4,self.y-self.r-4,self.r*2+8,self.r*2+8)
|
love.graphics.rectangle('fill',self.x-self.r-4,self.y-self.r-4,self.r*2+8,self.r*2+8)
|
||||||
|
|
||||||
love.graphics.setColor(1,1,1)
|
love.graphics.setColor(1,1,1,alpha)
|
||||||
love.graphics.rectangle('line',self.x-self.r-2,self.y-self.r-2,self.r*2+4,self.r*2+4)
|
love.graphics.rectangle('line',self.x-self.r-2,self.y-self.r-2,self.r*2+4,self.r*2+4)
|
||||||
end
|
end
|
||||||
if self.iconSize>0 and self.quad then
|
if self.iconSize>0 and self.quad then
|
||||||
love.graphics.setColor(1,1,1,forceLight and 1 or self.alpha)
|
love.graphics.setColor(1,1,1,alpha)
|
||||||
local _,_,w,h=self.quad:getViewport()
|
local _,_,w,h=self.quad:getViewport()
|
||||||
mDrawQ(
|
mDrawQ(
|
||||||
virtual_texture,
|
virtual_texture,
|
||||||
@@ -133,8 +137,7 @@ local global_toggle=false
|
|||||||
VCTRL={}
|
VCTRL={}
|
||||||
VCTRL.focus=nil -- Focusing buttons
|
VCTRL.focus=nil -- Focusing buttons
|
||||||
|
|
||||||
---@param ... table
|
---@class VCTRL.data
|
||||||
---@class data
|
|
||||||
---@field type string
|
---@field type string
|
||||||
---@field x number
|
---@field x number
|
||||||
---@field y number
|
---@field y number
|
||||||
@@ -143,6 +146,8 @@ VCTRL.focus=nil -- Focusing buttons
|
|||||||
---@field iconSize number
|
---@field iconSize number
|
||||||
---@field alpha number
|
---@field alpha number
|
||||||
---@field show boolean
|
---@field show boolean
|
||||||
|
|
||||||
|
---@param ... VCTRL.data
|
||||||
---Adding (multiple) virtual button(s)
|
---Adding (multiple) virtual button(s)
|
||||||
function VCTRL.new(...)
|
function VCTRL.new(...)
|
||||||
for _,d in pairs(...) do
|
for _,d in pairs(...) do
|
||||||
@@ -156,7 +161,7 @@ end
|
|||||||
---Enabling virtual control or not
|
---Enabling virtual control or not
|
||||||
function VCTRL.toggle(toggle)
|
function VCTRL.toggle(toggle)
|
||||||
if not toggle then
|
if not toggle then
|
||||||
-- Release all buttons to prevent ghost keys
|
-- Release all buttons to prevent button ghost situation
|
||||||
for id, b in pairs(touches) do
|
for id, b in pairs(touches) do
|
||||||
b:release(id)
|
b:release(id)
|
||||||
touches[id]=nil
|
touches[id]=nil
|
||||||
@@ -165,11 +170,19 @@ function VCTRL.toggle(toggle)
|
|||||||
global_toggle=toggle
|
global_toggle=toggle
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function VCTRL.clearAll()
|
||||||
|
local toggle = global_toggle
|
||||||
|
VCTRL.toggle(false)
|
||||||
|
global_toggle = toggle
|
||||||
|
|
||||||
|
for i=#VCTRL,1,-1 do VCTRL[i] = nil end
|
||||||
|
collectgarbage()
|
||||||
|
end
|
||||||
|
|
||||||
function VCTRL.press(x,y,id)
|
function VCTRL.press(x,y,id)
|
||||||
if not global_toggle then return end
|
if not global_toggle then return end
|
||||||
local obj,closestDist=false,1e99
|
local obj,closestDist=false,1e99
|
||||||
for i=1,#VCTRL do
|
for _, w in ipairs(VCTRL) do
|
||||||
local w=VCTRL[i]
|
|
||||||
if w.show then
|
if w.show then
|
||||||
local d=w:getDistance(x,y)
|
local d=w:getDistance(x,y)
|
||||||
if d<=1 and d<closestDist then
|
if d<=1 and d<closestDist then
|
||||||
@@ -201,13 +214,14 @@ function VCTRL.drag(dx,dy,id)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function VCTRL.draw(forceLight)
|
function VCTRL.draw(forceAlpha)
|
||||||
if not global_toggle then return end
|
if not global_toggle then return end
|
||||||
for i=1,#VCTRL do
|
for _, w in ipairs(VCTRL) do
|
||||||
if VCTRL[i].show then
|
if w.show then w:draw(forceAlpha) end
|
||||||
VCTRL[i]:draw(forceLight)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function VCTRL.export(K) return K:export() end
|
function VCTRL.exportAll()
|
||||||
|
local t = {}
|
||||||
|
for o, k in ipairs(VCTRL) do t[o] = k:export() end
|
||||||
|
end
|
||||||
@@ -65,6 +65,7 @@ local button = {
|
|||||||
|
|
||||||
_hovering = false,
|
_hovering = false,
|
||||||
_pressed = false,
|
_pressed = false,
|
||||||
|
_touchID = false,
|
||||||
}; button.__index = button
|
}; button.__index = button
|
||||||
function button:draw()
|
function button:draw()
|
||||||
love.graphics.setLineWidth(self.borderWidth)
|
love.graphics.setLineWidth(self.borderWidth)
|
||||||
@@ -112,17 +113,30 @@ function button:isHovering(x,y)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
---Trigger press action, only when ``self._hovering`` is true
|
---Trigger press action, only when ``self._hovering`` is true
|
||||||
function button:press(x, y)
|
function button:press(x, y, touchID)
|
||||||
if self:isHovering(x, y) and not self._pressed then
|
if (touchID and self:isHovering(x, y) or self._hovering) and not self._pressed then
|
||||||
self._pressed = true
|
|
||||||
self.codeWhenPressed()
|
self.codeWhenPressed()
|
||||||
|
|
||||||
|
self._touchID = touchID
|
||||||
|
self._pressed = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
---Trigger release action, don't need ``self._hovering`` to ``true``
|
---Trigger release action, don't need ``self._hovering`` to ``true``
|
||||||
function button:release(x, y)
|
function button:release(x, y, touchID)
|
||||||
if self:isHovering(x, y) and self._pressed then
|
local valid = true
|
||||||
self._pressed = false
|
if touchID then valid = touchID == self._touchID end
|
||||||
|
|
||||||
|
if valid then
|
||||||
self.codeWhenReleased()
|
self.codeWhenReleased()
|
||||||
|
|
||||||
|
self._pressed = false
|
||||||
|
self._touchID = false
|
||||||
|
|
||||||
|
if touchID then
|
||||||
|
self._hovering = false
|
||||||
|
else
|
||||||
|
self._hovering = self:isHovering(x, y)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -235,16 +249,14 @@ end
|
|||||||
---@param list table<BUTTON.button>
|
---@param list table<BUTTON.button>
|
||||||
---@param x number # Mouse position
|
---@param x number # Mouse position
|
||||||
---@param y number # Mouse position
|
---@param y number # Mouse position
|
||||||
function BUTTON.press(list, x, y)
|
function BUTTON.press(list, x, y, touchID)
|
||||||
for _, v in pairs(list) do v:press(x, y) end
|
for _, v in pairs(list) do v:press(x, y, touchID) end
|
||||||
end
|
end
|
||||||
|
|
||||||
---Trigger the release action
|
---Trigger the release action
|
||||||
---@param list table<BUTTON.button>
|
---@param list table<BUTTON.button>
|
||||||
---@param x number # Mouse position
|
function BUTTON.release(list, x, y, touchID)
|
||||||
---@param y number # Mouse position
|
for _, v in pairs(list) do v:release(x, y, touchID) end
|
||||||
function BUTTON.release(list, x, y)
|
|
||||||
for _, v in pairs(list) do v:release(x, y) end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return BUTTON
|
return BUTTON
|
||||||
13
main.lua
13
main.lua
@@ -97,8 +97,6 @@ function love.draw()
|
|||||||
love.graphics.push()
|
love.graphics.push()
|
||||||
|
|
||||||
SCENE:render()
|
SCENE:render()
|
||||||
VCTRL.draw()
|
|
||||||
|
|
||||||
-- -- Grid system
|
-- -- Grid system
|
||||||
-- local grid_width, grid_height = 40, 20
|
-- local grid_width, grid_height = 40, 20
|
||||||
-- love.graphics.replaceTransform(GLOBAL_TRANSFORM)
|
-- love.graphics.replaceTransform(GLOBAL_TRANSFORM)
|
||||||
@@ -114,10 +112,6 @@ function love.draw()
|
|||||||
-- love.graphics.line(0, grid_height * iy, 640, grid_height * iy)
|
-- love.graphics.line(0, grid_height * iy, 640, grid_height * iy)
|
||||||
-- end
|
-- end
|
||||||
|
|
||||||
love.graphics.setColor(0, 0, 0, 0.8)
|
|
||||||
love.graphics.rectangle("fill", 10, 445, 400, 30)
|
|
||||||
drawText("X: "..(LAST_X_POSITION or "--------").."; Y: "..(LAST_Y_POSITION or "--------"), 10, 455, 400, "left")
|
|
||||||
|
|
||||||
love.graphics.pop()
|
love.graphics.pop()
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -142,22 +136,15 @@ end
|
|||||||
|
|
||||||
function love.touchpressed(id,x,y)
|
function love.touchpressed(id,x,y)
|
||||||
local x,y=GLOBAL_TRANSFORM:inverseTransformPoint(x,y)
|
local x,y=GLOBAL_TRANSFORM:inverseTransformPoint(x,y)
|
||||||
if not VCTRL.press(x,y,id) then
|
|
||||||
SCENE:onInputPress{type = "touch", x = x, y = y, dx = 0, dy = 0, id = id}
|
SCENE:onInputPress{type = "touch", x = x, y = y, dx = 0, dy = 0, id = id}
|
||||||
end
|
|
||||||
end
|
end
|
||||||
function love.touchdragged(id,x,y,dx,dy)
|
function love.touchdragged(id,x,y,dx,dy)
|
||||||
local x,y=GLOBAL_TRANSFORM:inverseTransformPoint(x,y)
|
local x,y=GLOBAL_TRANSFORM:inverseTransformPoint(x,y)
|
||||||
if not VCTRL.drag(x,y,id) then
|
|
||||||
SCENE:onInputDrag{type = "touch", x = x, y = y, dx = dx, dy = dy, id = id}
|
SCENE:onInputDrag{type = "touch", x = x, y = y, dx = dx, dy = dy, id = id}
|
||||||
end
|
|
||||||
end
|
end
|
||||||
function love.touchreleased(id,x,y)
|
function love.touchreleased(id,x,y)
|
||||||
local x,y=GLOBAL_TRANSFORM:inverseTransformPoint(x,y)
|
local x,y=GLOBAL_TRANSFORM:inverseTransformPoint(x,y)
|
||||||
if not VCTRL.release(id) then
|
|
||||||
SCENE:onInputRelease{type = "touch", x = x, y = y, dx = 0, dy = 0, id = id}
|
SCENE:onInputRelease{type = "touch", x = x, y = y, dx = 0, dy = 0, id = id}
|
||||||
LAST_X_POSITION, LAST_Y_POSITION = x, y
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.keypressed(key, scancode)
|
function love.keypressed(key, scancode)
|
||||||
|
|||||||
@@ -69,10 +69,13 @@ end
|
|||||||
|
|
||||||
function GameScene:render()
|
function GameScene:render()
|
||||||
self.game:draw(self.paused)
|
self.game:draw(self.paused)
|
||||||
|
VCTRL.draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
function GameScene:onInputPress(e)
|
function GameScene:onInputPress(e)
|
||||||
if (self.game.game_over or self.game.completed) and (e.input == "menu_decide" or e.input == "menu_back" or e.input == "rotate_right") and self.game.game_over_frames > 50 then
|
if e.type == "touch" then VCTRL.press(e.x, e.y, e.id)
|
||||||
|
|
||||||
|
elseif (self.game.game_over or self.game.completed) and (e.input == "menu_decide" or e.input == "menu_back" or e.input == "rotate_right") and self.game.game_over_frames > 50 then
|
||||||
SCENE = TitleScene()
|
SCENE = TitleScene()
|
||||||
elseif tas and e.input == "menu_decide" then
|
elseif tas and e.input == "menu_decide" then
|
||||||
self:update(false, true)
|
self:update(false, true)
|
||||||
@@ -110,7 +113,9 @@ function GameScene:onInputPress(e)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function GameScene:onInputRelease(e)
|
function GameScene:onInputRelease(e)
|
||||||
if e.input and string.sub(e.input, 1, 5) ~= "menu_" then
|
if e.type == "touch" then
|
||||||
|
VCTRL.release(e.id)
|
||||||
|
elseif e.input and string.sub(e.input, 1, 5) ~= "menu_" then
|
||||||
self.inputs[e.input] = false
|
self.inputs[e.input] = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,20 +3,38 @@ NameEntryScene.title = "Game Start"
|
|||||||
|
|
||||||
local buttonList = {
|
local buttonList = {
|
||||||
BUTTON.new{
|
BUTTON.new{
|
||||||
text = "<\nCHAR", font = FONT_big,
|
text = "←\nCHAR", font = FONT_big,
|
||||||
x = 40, y = 160, w = 70, h = 70,
|
x = 25, y = 120, w = 80, h = 80,
|
||||||
|
codeWhenPressed = function() SCENE:onInputPress {input = "left"} end,
|
||||||
|
codeWhenReleased = function() SCENE:onInputRelease{input = "left"} end,
|
||||||
},
|
},
|
||||||
BUTTON.new{
|
BUTTON.new{
|
||||||
text = ">\nCHAR", font = FONT_big,
|
text = "→\nCHAR", font = FONT_big,
|
||||||
x = 130, y = 160, w = 70, h = 70,
|
x = 115, y = 120, w = 80, h = 80,
|
||||||
}
|
codeWhenPressed = function() SCENE:onInputPress {input = "right"} end,
|
||||||
|
codeWhenReleased = function() SCENE:onInputRelease{input = "right"} end,
|
||||||
|
},
|
||||||
|
BUTTON.new{
|
||||||
|
text = "↑\nESC", font = FONT_big,
|
||||||
|
x = 25, y = 210, w = 80, h = 80,
|
||||||
|
codeWhenPressed = function() SCENE:onInputPress {input = "menu_back"} end,
|
||||||
|
codeWhenReleased = function() SCENE:onInputRelease{input = "menu_back"} end,
|
||||||
|
},
|
||||||
|
BUTTON.new{
|
||||||
|
text = "↓\nENTER", font = FONT_big,
|
||||||
|
x = 115, y = 210, w = 80, h = 80,
|
||||||
|
codeWhenPressed = function() SCENE:onInputPress {input = "menu_decide"} end,
|
||||||
|
codeWhenReleased = function() SCENE:onInputRelease{input = "menu_decide"} end,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
local Grid = require 'game.grid'
|
local Grid = require 'game.grid'
|
||||||
local bitser = require 'libs.bitser'
|
local bitser = require 'libs.bitser'
|
||||||
|
|
||||||
function NameEntryScene:new()
|
function NameEntryScene:new()
|
||||||
self.hars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890."
|
VCTRL.toggle(false)
|
||||||
|
|
||||||
|
self.chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890."
|
||||||
self.char_pos = 1
|
self.char_pos = 1
|
||||||
self.name_entry = {'A','A','A'}
|
self.name_entry = {'A','A','A'}
|
||||||
self.entry_pos = 1
|
self.entry_pos = 1
|
||||||
@@ -129,11 +147,12 @@ end
|
|||||||
|
|
||||||
function NameEntryScene:onInputPress(e)
|
function NameEntryScene:onInputPress(e)
|
||||||
if e.type == "mouse" or e.type == "touch" then
|
if e.type == "mouse" or e.type == "touch" then
|
||||||
BUTTON.press(buttonList, e.x, e.y)
|
BUTTON.press(buttonList, e.x, e.y, e.id)
|
||||||
elseif e.input == "menu_decide" or e.input == "rotate_left" or e.scancode == "return" then
|
elseif e.input == "menu_decide" or e.input == "rotate_left" or e.scancode == "return" then
|
||||||
self.delete_confirm = false
|
self.delete_confirm = false
|
||||||
self.delete_input_count = 0
|
self.delete_input_count = 0
|
||||||
if self.entry_pos == 4 then
|
if self.entry_pos == 4 then
|
||||||
|
BUTTON.release(buttonList, e.x, e.y, e.id)
|
||||||
SETTINGS['last_entry'] = name:upper()
|
SETTINGS['last_entry'] = name:upper()
|
||||||
SCENE = GameScene(name:lower())
|
SCENE = GameScene(name:lower())
|
||||||
else
|
else
|
||||||
@@ -164,6 +183,7 @@ function NameEntryScene:onInputPress(e)
|
|||||||
self.delete_confirm = false
|
self.delete_confirm = false
|
||||||
self.delete_input_count = 0
|
self.delete_input_count = 0
|
||||||
if self.entry_pos == 1 then
|
if self.entry_pos == 1 then
|
||||||
|
BUTTON.release(buttonList, true)
|
||||||
SCENE = TitleScene()
|
SCENE = TitleScene()
|
||||||
else
|
else
|
||||||
self.name_entry[self.entry_pos] = 'A'
|
self.name_entry[self.entry_pos] = 'A'
|
||||||
@@ -199,7 +219,7 @@ end
|
|||||||
|
|
||||||
function NameEntryScene:onInputRelease(e)
|
function NameEntryScene:onInputRelease(e)
|
||||||
if e.type == "mouse" or e.type == "touch" then
|
if e.type == "mouse" or e.type == "touch" then
|
||||||
BUTTON.release(buttonList, e.x, e.y)
|
BUTTON.release(buttonList, e.x, e.y, e.id)
|
||||||
elseif e.input == "left" or e.scancode == "left" or e.input == "right" or e.scancode == "right" then
|
elseif e.input == "left" or e.scancode == "left" or e.input == "right" or e.scancode == "right" then
|
||||||
self.direction = nil
|
self.direction = nil
|
||||||
self.repeat_counter = self.repeat_limit-1
|
self.repeat_counter = self.repeat_limit-1
|
||||||
|
|||||||
@@ -58,7 +58,6 @@ function TitleScene:render()
|
|||||||
love.graphics.setColor(0,0,0,0.7)
|
love.graphics.setColor(0,0,0,0.7)
|
||||||
love.graphics.rectangle("fill", 14, 174, 260, 210, 10, 10)
|
love.graphics.rectangle("fill", 14, 174, 260, 210, 10, 10)
|
||||||
love.graphics.setColor(0.4, 1, 1, 0.5)
|
love.graphics.setColor(0.4, 1, 1, 0.5)
|
||||||
love.graphics.rectangle("fill", 14, 40, 260, 120, 10, 10)
|
|
||||||
love.graphics.rectangle("fill", 20, 198 + 20 * self.main_menu_state, 240, 22)
|
love.graphics.rectangle("fill", 20, 198 + 20 * self.main_menu_state, 240, 22)
|
||||||
--
|
--
|
||||||
drawBigText('Tromi', 30, 180, 120, "left")
|
drawBigText('Tromi', 30, 180, 120, "left")
|
||||||
@@ -93,7 +92,33 @@ end
|
|||||||
|
|
||||||
function TitleScene:onInputPress(e)
|
function TitleScene:onInputPress(e)
|
||||||
if e.type == "touch" then
|
if e.type == "touch" then
|
||||||
|
if -- PENTO mode
|
||||||
|
e.x >= 14 and
|
||||||
|
e.y >= 40 and
|
||||||
|
e.x <= 274 and
|
||||||
|
e.y <= 160
|
||||||
|
then
|
||||||
|
if e.x >= 137 then -- Right
|
||||||
|
table.remove(self.code, 8)
|
||||||
|
table.insert(self.code, 1, 1)
|
||||||
|
else -- Left
|
||||||
|
table.remove(self.code, 8)
|
||||||
|
table.insert(self.code, 1, -1)
|
||||||
|
end
|
||||||
|
else -- Select option from menu
|
||||||
|
local selecting = math.floor((e.y - 198) / 20)
|
||||||
|
|
||||||
|
if (e.x >= 20 and e.x <= 260) and
|
||||||
|
(selecting > 0 and selecting <= #main_menu_screens)
|
||||||
|
then
|
||||||
|
if self.main_menu_state ~= selecting then
|
||||||
|
self.main_menu_state = selecting
|
||||||
|
else
|
||||||
|
VCTRL.toggle(true)
|
||||||
|
SCENE = main_menu_screens[selecting]()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
if e.input == "menu_decide" or e.input == "rotate_left" or e.scancode == "return" then
|
if e.input == "menu_decide" or e.input == "rotate_left" or e.scancode == "return" then
|
||||||
SCENE = main_menu_screens[self.main_menu_state]()
|
SCENE = main_menu_screens[self.main_menu_state]()
|
||||||
@@ -112,32 +137,6 @@ function TitleScene:onInputPress(e)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function TitleScene:onInputRelease(e)
|
function TitleScene:onInputRelease(e)
|
||||||
if e.type ~= "touch" then return end
|
|
||||||
local selecting = math.floor((e.y - 198) / 20)
|
|
||||||
if
|
|
||||||
(e.x >= 20 and e.x <= 260) and
|
|
||||||
(selecting > 0 and selecting <= #main_menu_screens)
|
|
||||||
then
|
|
||||||
if self.main_menu_state ~= selecting then
|
|
||||||
self.main_menu_state = selecting
|
|
||||||
else
|
|
||||||
VCTRL.toggle(true)
|
|
||||||
SCENE = main_menu_screens[selecting]()
|
|
||||||
end
|
|
||||||
elseif
|
|
||||||
e.x >= 14 and
|
|
||||||
e.y >= 40 and
|
|
||||||
e.x <= 274 and
|
|
||||||
e.y <= 160
|
|
||||||
then
|
|
||||||
if e.x >= 137 then -- Right
|
|
||||||
table.remove(self.code, 8)
|
|
||||||
table.insert(self.code, 1, 1)
|
|
||||||
else -- Left
|
|
||||||
table.remove(self.code, 8)
|
|
||||||
table.insert(self.code, 1, -1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return TitleScene
|
return TitleScene
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ TouchConfigScene.title = "Touchscreen config\n(you can tap anywhere on touch scr
|
|||||||
2. Add behaviors
|
2. Add behaviors
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
local focusingButton
|
||||||
|
local selectingButton
|
||||||
|
|
||||||
local buttonList = {
|
local buttonList = {
|
||||||
select_button = BUTTON.new{
|
select_button = BUTTON.new{
|
||||||
text = "Select key\n[Rotate right 2]",
|
text = "Select key\n[Rotate right 2]",
|
||||||
@@ -56,6 +59,9 @@ local buttonList = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function TouchConfigScene:new()
|
function TouchConfigScene:new()
|
||||||
|
VCTRL.toggle(true)
|
||||||
|
focusingButton = false
|
||||||
|
selectingButton = nil
|
||||||
-- TODO
|
-- TODO
|
||||||
end
|
end
|
||||||
function TouchConfigScene:update()
|
function TouchConfigScene:update()
|
||||||
@@ -78,13 +84,13 @@ end
|
|||||||
function TouchConfigScene:onInputPress(e)
|
function TouchConfigScene:onInputPress(e)
|
||||||
if e.input == 'menu_back' then SCENE = InputConfigScene() end
|
if e.input == 'menu_back' then SCENE = InputConfigScene() end
|
||||||
if e.type == "mouse" or e.type == "touch" then
|
if e.type == "mouse" or e.type == "touch" then
|
||||||
BUTTON.press(buttonList, e.x, e.y)
|
BUTTON.press(buttonList, e.x, e.y, e.type == "touch")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
---@param e SCENE_onInput
|
---@param e SCENE_onInput
|
||||||
function TouchConfigScene:onInputRelease(e)
|
function TouchConfigScene:onInputRelease(e)
|
||||||
if e.type == "mouse" or e.type == "touch" then
|
if e.type == "mouse" or e.type == "touch" then
|
||||||
BUTTON.release(buttonList, e.x, e.y)
|
BUTTON.release(buttonList, e.x, e.y, e.type == "touch")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -38,10 +38,12 @@ end
|
|||||||
|
|
||||||
function TrainingScene:render()
|
function TrainingScene:render()
|
||||||
self.game:draw(self.paused)
|
self.game:draw(self.paused)
|
||||||
|
VCTRL.draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
function TrainingScene:onInputPress(e)
|
function TrainingScene:onInputPress(e)
|
||||||
if (self.game.game_over or self.game.completed) and (e.input == "menu_decide" or e.input == "menu_back" or e.input == "rotate_right") and self.game.game_over_frames > 50 then
|
if e.type == "touch" then VCTRL.press(e.x, e.y, e.id)
|
||||||
|
elseif (self.game.game_over or self.game.completed) and (e.input == "menu_decide" or e.input == "menu_back" or e.input == "rotate_right") and self.game.game_over_frames > 50 then
|
||||||
SCENE = TitleScene()
|
SCENE = TitleScene()
|
||||||
elseif (e.input == "menu_back") then
|
elseif (e.input == "menu_back") then
|
||||||
SCENE = TitleScene()
|
SCENE = TitleScene()
|
||||||
@@ -51,7 +53,8 @@ function TrainingScene:onInputPress(e)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function TrainingScene:onInputRelease(e)
|
function TrainingScene:onInputRelease(e)
|
||||||
if e.input and string.sub(e.input, 1, 5) ~= "menu_" then
|
if e.type == "touch" then VCTRL.release(e.id)
|
||||||
|
elseif e.input and string.sub(e.input, 1, 5) ~= "menu_" then
|
||||||
self.inputs[e.input] = false
|
self.inputs[e.input] = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user