move repeatedly in direction
This commit is contained in:
parent
e065ab83de
commit
f8e3d78332
5 changed files with 126 additions and 62 deletions
40
input.lua
40
input.lua
|
|
@ -3,8 +3,48 @@ Input = {}
|
||||||
Input.playermovekeys = { up = "up", down = "down", left = "left", right = "right" }
|
Input.playermovekeys = { up = "up", down = "down", left = "left", right = "right" }
|
||||||
Input.playerswitchkeys = { ["1"] = "1", ["2"] = "2", ["3"] = "3"}
|
Input.playerswitchkeys = { ["1"] = "1", ["2"] = "2", ["3"] = "3"}
|
||||||
Input.colorfromkey = {"red", "green", "blue"}
|
Input.colorfromkey = {"red", "green", "blue"}
|
||||||
|
Input.moveRepeatDelay = .28
|
||||||
|
Input.moveRepeatInterval = .09
|
||||||
|
Input.heldMoveKey = nil
|
||||||
|
Input.moveRepeatElapsed = 0
|
||||||
|
Input.moveRepeatStarted = false
|
||||||
|
|
||||||
function Input:handler(dt)
|
function Input:handler(dt)
|
||||||
|
local key = self.heldMoveKey
|
||||||
|
if key and not love.keyboard.isDown(key) then
|
||||||
|
key = nil
|
||||||
|
for _, candidate in ipairs({"up", "down", "left", "right"}) do
|
||||||
|
if love.keyboard.isDown(candidate) then key = candidate; break end
|
||||||
|
end
|
||||||
|
self.heldMoveKey = key
|
||||||
|
self.moveRepeatElapsed = 0
|
||||||
|
self.moveRepeatStarted = false
|
||||||
|
end
|
||||||
|
|
||||||
|
if not key then return nil end
|
||||||
|
self.moveRepeatElapsed = self.moveRepeatElapsed + dt
|
||||||
|
if not self.moveRepeatStarted then
|
||||||
|
if self.moveRepeatElapsed >= self.moveRepeatDelay then
|
||||||
|
self.moveRepeatElapsed = 0
|
||||||
|
self.moveRepeatStarted = true
|
||||||
|
return key
|
||||||
|
end
|
||||||
|
elseif self.moveRepeatElapsed >= self.moveRepeatInterval then
|
||||||
|
self.moveRepeatElapsed = 0
|
||||||
|
return key
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Input:beginMove(key)
|
||||||
|
self.heldMoveKey = key
|
||||||
|
self.moveRepeatElapsed = 0
|
||||||
|
self.moveRepeatStarted = false
|
||||||
|
end
|
||||||
|
|
||||||
|
function Input:stopMoveRepeat()
|
||||||
|
self.heldMoveKey = nil
|
||||||
|
self.moveRepeatElapsed = 0
|
||||||
|
self.moveRepeatStarted = false
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
8
main.lua
8
main.lua
|
|
@ -41,7 +41,12 @@ function love.load()
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
Input:handler(dt)
|
if editorView == "world" then
|
||||||
|
Input:stopMoveRepeat()
|
||||||
|
else
|
||||||
|
local repeatedMove = Input:handler(dt)
|
||||||
|
if repeatedMove then currentRoom:movePlayer(repeatedMove) end
|
||||||
|
end
|
||||||
currentRoom:update(dt)
|
currentRoom:update(dt)
|
||||||
|
|
||||||
-- if love.keyboard.isDown("w") then worldSha = worldSha + 1 end
|
-- if love.keyboard.isDown("w") then worldSha = worldSha + 1 end
|
||||||
|
|
@ -94,6 +99,7 @@ end
|
||||||
|
|
||||||
function love.keypressed(key)
|
function love.keypressed(key)
|
||||||
if editorView ~= "world" and Input.isPlayerMove(key) then
|
if editorView ~= "world" and Input.isPlayerMove(key) then
|
||||||
|
Input:beginMove(key)
|
||||||
currentRoom:movePlayer(key)
|
currentRoom:movePlayer(key)
|
||||||
elseif editorView ~= "world" and Input.isPlayerSwitch(key) then
|
elseif editorView ~= "world" and Input.isPlayerSwitch(key) then
|
||||||
local c = Input.playerColor(key)
|
local c = Input.playerColor(key)
|
||||||
|
|
|
||||||
5
room.lua
5
room.lua
|
|
@ -489,7 +489,10 @@ function Room:switchCheck()
|
||||||
local onSwitches = {}
|
local onSwitches = {}
|
||||||
for _, switch in pairs(switchArray) do
|
for _, switch in pairs(switchArray) do
|
||||||
local targetCell = self:getCellInMatrix(self.collidableMatrices[color], switch:getGridPos())
|
local targetCell = self:getCellInMatrix(self.collidableMatrices[color], switch:getGridPos())
|
||||||
if targetCell then
|
local player = self.player[color]
|
||||||
|
-- Players are not stored in collidableMatrices, but a colour copy
|
||||||
|
-- standing on its matching switch presses it just like a block does.
|
||||||
|
if targetCell or (player and player:occupiesCell(switch:getGridPos())) then
|
||||||
--switch is on
|
--switch is on
|
||||||
switch:activate()
|
switch:activate()
|
||||||
table.insert(onSwitches, switch) --doesn't rly matter what we put here as long as it's true-y
|
table.insert(onSwitches, switch) --doesn't rly matter what we put here as long as it's true-y
|
||||||
|
|
|
||||||
10
rooms/room_11_09.sav
Normal file
10
rooms/room_11_09.sav
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
objects={
|
||||||
|
{
|
||||||
|
y=1,
|
||||||
|
class="player",
|
||||||
|
color="red",
|
||||||
|
x=1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
123
rooms/world.sav
123
rooms/world.sav
|
|
@ -1,146 +1,151 @@
|
||||||
{
|
{
|
||||||
width=18,
|
|
||||||
height=18,
|
|
||||||
rooms={
|
rooms={
|
||||||
{
|
{
|
||||||
y=11,
|
y=11,
|
||||||
x=9,
|
name="start",
|
||||||
name="start"
|
x=9
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
y=10,
|
y=10,
|
||||||
x=10,
|
name="3",
|
||||||
name="3"
|
x=10
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
y=10,
|
y=10,
|
||||||
x=11,
|
name="4",
|
||||||
name="4"
|
x=11
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
y=10,
|
y=10,
|
||||||
x=12,
|
name="5",
|
||||||
name="5"
|
x=12
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
y=9,
|
y=9,
|
||||||
x=12,
|
name="village_1",
|
||||||
name="village_1"
|
x=12
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
y=8,
|
y=8,
|
||||||
x=12,
|
name="village_2",
|
||||||
name="village_2"
|
x=12
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
y=8,
|
y=8,
|
||||||
x=13,
|
name="village_3",
|
||||||
name="village_3"
|
x=13
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
y=8,
|
y=8,
|
||||||
x=11,
|
name="village_4",
|
||||||
name="village_4"
|
x=11
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
y=7,
|
y=7,
|
||||||
x=11,
|
name="yellow_1",
|
||||||
name="yellow_1"
|
x=11
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
y=6,
|
y=6,
|
||||||
x=11,
|
name="yellow_3",
|
||||||
name="yellow_3"
|
x=11
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
y=7,
|
y=7,
|
||||||
x=12,
|
name="yellow_2",
|
||||||
name="yellow_2"
|
x=12
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
y=5,
|
y=5,
|
||||||
x=11,
|
name="yellow_4",
|
||||||
name="yellow_4"
|
x=11
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
y=4,
|
y=4,
|
||||||
x=11,
|
name="yellow_5",
|
||||||
name="yellow_5"
|
x=11
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
y=5,
|
y=5,
|
||||||
x=10,
|
name="yellow_6",
|
||||||
name="yellow_6"
|
x=10
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
y=1,
|
y=1,
|
||||||
x=1,
|
name="default",
|
||||||
name="default"
|
x=1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
y=1,
|
y=1,
|
||||||
x=3,
|
name="old_yellow_3",
|
||||||
name="old_yellow_3"
|
x=3
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
y=1,
|
y=1,
|
||||||
x=5,
|
name="test_patt",
|
||||||
name="test_patt"
|
x=5
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
y=1,
|
y=1,
|
||||||
x=7,
|
name="test_patt_update",
|
||||||
name="test_patt_update"
|
x=7
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
y=1,
|
y=1,
|
||||||
x=9,
|
name="white_asymmetrical",
|
||||||
name="white_asymmetrical"
|
x=9
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
y=1,
|
y=1,
|
||||||
x=11,
|
name="white_ok",
|
||||||
name="white_ok"
|
x=11
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
y=1,
|
y=1,
|
||||||
x=13,
|
name="white_primary",
|
||||||
name="white_primary"
|
x=13
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
y=1,
|
y=1,
|
||||||
x=15,
|
name="yellow_arches",
|
||||||
name="yellow_arches"
|
x=15
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
y=1,
|
y=1,
|
||||||
x=17,
|
name="yellow_asymmetrical",
|
||||||
name="yellow_asymmetrical"
|
x=17
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
y=3,
|
y=3,
|
||||||
x=1,
|
name="yellow_cc_moustache",
|
||||||
name="yellow_cc_moustache"
|
x=1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
y=3,
|
y=3,
|
||||||
x=3,
|
name="yellow_color_changing_levvel_1",
|
||||||
name="yellow_color_changing_levvel_1"
|
x=3
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
y=3,
|
y=3,
|
||||||
x=5,
|
name="yellow_skull",
|
||||||
name="yellow_skull"
|
x=5
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
y=3,
|
y=3,
|
||||||
x=7,
|
name="yellow_smile",
|
||||||
name="yellow_smile"
|
x=7
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
y=10,
|
y=10,
|
||||||
x=9,
|
name="2",
|
||||||
name="2"
|
x=9
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
y=9,
|
||||||
|
name="room_11_09",
|
||||||
|
x=11
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
width=18,
|
||||||
|
height=18
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue