src: replace entirely the virtualpad module by the core.input subsystem
This commit is contained in:
parent
afb6fc9464
commit
7908480ec0
|
@ -1,6 +1,5 @@
|
|||
Datas = {}
|
||||
|
||||
Datas.levels = require "datas.levels"
|
||||
Datas.vpad = require "datas.vpad"
|
||||
|
||||
return Datas
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
return {
|
||||
{
|
||||
["left"] = "left",
|
||||
["right"] = "right",
|
||||
["up"] = "up",
|
||||
["down"] = "down",
|
||||
["A"] = "a",
|
||||
["B"] = "z",
|
||||
["C"] = "e",
|
||||
["start"] = "return",
|
||||
}
|
||||
}
|
|
@ -25,7 +25,6 @@ datas = require "datas"
|
|||
utils = require "libs.loveutils"
|
||||
menus = require "modules.menus"
|
||||
assets = require "modules.assets"
|
||||
vpad = require "modules.vpad"
|
||||
|
||||
scenes = require "scenes"
|
||||
|
||||
|
@ -42,7 +41,6 @@ function love.load() -- On charge la scene de départ (pour l'instant le menu, b
|
|||
game.pigmanager:addPig("cochon")
|
||||
|
||||
assets:init()
|
||||
virtualpad = vpad()
|
||||
scenes.MainMenu()
|
||||
end
|
||||
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
local VPad = Object:extend()
|
||||
local defaultVPad = require "datas.vpad"
|
||||
|
||||
function VPad:new()
|
||||
self.keyboard = defaultVPad
|
||||
end
|
||||
|
||||
function VPad:getData(playerID)
|
||||
return self.keyboard[playerID]
|
||||
end
|
||||
|
||||
function VPad:translateAction(playerID, key)
|
||||
local padkey = ""
|
||||
for k,v in pairs(self.keyboard[playerID]) do
|
||||
if v == key then padkey = k end
|
||||
end
|
||||
return padkey
|
||||
end
|
||||
|
||||
function VPad:getKey(playerID, padkey)
|
||||
local padkey = padkey
|
||||
for k,v in pairs(self.keyboard[playerID]) do
|
||||
if (k == padkey) then key = v end
|
||||
end
|
||||
return key
|
||||
end
|
||||
|
||||
function VPad:isDown(playerID, padkey)
|
||||
local isdown = false
|
||||
local key = self:getKey(playerID, padkey)
|
||||
|
||||
isdown = love.keyboard.isDown(key)
|
||||
|
||||
return isdown
|
||||
end
|
||||
|
||||
return VPad
|
|
@ -1,7 +1,5 @@
|
|||
Level = Object:extend() -- On créer la classe des entitées, c'est la classe de base
|
||||
|
||||
require "scenes.levels.controller.virtualpad"
|
||||
|
||||
require "scenes.levels.controller.world"
|
||||
require "scenes.levels.controller.camera"
|
||||
require "scenes.levels.controller.players"
|
||||
|
@ -31,7 +29,6 @@ function Level:reset()
|
|||
self.score = 0
|
||||
self.gold = 0
|
||||
|
||||
self:resetPads()
|
||||
self:setDebugMode(true)
|
||||
end
|
||||
|
||||
|
@ -58,7 +55,6 @@ end
|
|||
|
||||
function Level:launchMission()
|
||||
self:resetPlayers()
|
||||
self:resetPads()
|
||||
--self:resetSpawnAndEntities()
|
||||
assets:silence()
|
||||
assets:playMusic()
|
||||
|
@ -68,16 +64,6 @@ function Level:launchMission()
|
|||
self:addPlayer(1)
|
||||
self:spawnPlayer(1)
|
||||
|
||||
local padid = self:addPad(Pad(1))
|
||||
self.virtualpads[padid]:addKey("up","up")
|
||||
self.virtualpads[padid]:addKey("down","down")
|
||||
self.virtualpads[padid]:addKey("left","left")
|
||||
self.virtualpads[padid]:addKey("right","right")
|
||||
|
||||
self.virtualpads[padid]:addKey("a","A")
|
||||
self.virtualpads[padid]:addKey("z","B")
|
||||
self.virtualpads[padid]:addKey("e","C")
|
||||
|
||||
self.score = 0
|
||||
self.gold = 0
|
||||
end
|
||||
|
@ -85,6 +71,7 @@ end
|
|||
-- UPDATE FUNCTIONS
|
||||
|
||||
function Level:update(dt)
|
||||
self.keys = core.input.keys
|
||||
if (self.pause == false) then
|
||||
self:updatePlayerSystem(dt)
|
||||
self:updateWorld(dt)
|
||||
|
|
|
@ -69,7 +69,6 @@ function Level:playerHaveObject(id)
|
|||
end
|
||||
|
||||
function Level:updatePlayerSystem(dt)
|
||||
self:updatePads(dt)
|
||||
|
||||
if (self.deathTimer > 0) then
|
||||
self.deathTimer = self.deathTimer - dt
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
--[[ scenes.levels.controller.virtualpad
|
||||
|
||||
Ce fichier va contenir le système de détection des touches, indispensables
|
||||
pour pouvoir envoyer les actions au joueur. Il détecte les touches sur lesquels
|
||||
le joueur appue, et les retranscrit en tant que touche megadrive, afin de
|
||||
permettre au joueur de pouvoir agir sur le joueur.
|
||||
|
||||
Chaque "manette virtuelle" est enregistrée séparément, et les moyens de l'activer
|
||||
peuvent être différentes, suivant les touches]
|
||||
|
||||
--]]
|
||||
|
||||
Pad = Object:extend()
|
||||
|
||||
function Level:resetPads()
|
||||
self.virtualpads = {}
|
||||
end
|
||||
|
||||
function Level:addPad(pad)
|
||||
table.insert(self.virtualpads, pad)
|
||||
return #self.virtualpads
|
||||
end
|
||||
|
||||
function Level:updatePads()
|
||||
for i,v in ipairs(self.virtualpads) do
|
||||
local player = self:getPlayerByID(self.activePlayer)
|
||||
if (player ~= nil) then
|
||||
for k, u in pairs(v.keys) do
|
||||
if virtualpad:isDown(1, u.padTouch) then
|
||||
player:padPush(u.padTouch, true)
|
||||
else
|
||||
player:padPush(u.padTouch, false)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Pad:new(playerid)
|
||||
self.keys = {}
|
||||
self.playerID = playerid
|
||||
end
|
||||
|
||||
function Pad:addKey(key, padTouch)
|
||||
local id = #self.keys + 1
|
||||
self.keys[id] = {}
|
||||
self.keys[id].key = key
|
||||
self.keys[id].padTouch = padTouch
|
||||
end
|
||||
|
||||
function Pad:update(dt)
|
||||
|
||||
end
|
|
@ -28,7 +28,6 @@ function Player:new(level, x, y, playerID)
|
|||
self.currentWeapon = 1
|
||||
|
||||
self:initMovement()
|
||||
self:padInit()
|
||||
|
||||
self:setDebugColor(0,255,0)
|
||||
end
|
||||
|
@ -71,48 +70,11 @@ function Player:initAnimations()
|
|||
self.animations["fall"] = 5
|
||||
end
|
||||
|
||||
function Player:padInit()
|
||||
|
||||
self:padReset()
|
||||
|
||||
self:padAddTouch("up")
|
||||
self:padAddTouch("left")
|
||||
self:padAddTouch("right")
|
||||
self:padAddTouch("down")
|
||||
|
||||
self:padAddTouch("A")
|
||||
self:padAddTouch("B")
|
||||
self:padAddTouch("C")
|
||||
|
||||
self:padAddAnalogue()
|
||||
|
||||
self:padAddTouch("select")
|
||||
|
||||
end
|
||||
|
||||
function Player:padReset()
|
||||
self.gamepad = {}
|
||||
self.gamepad.buttons = {}
|
||||
self.gamepad.analogs = {}
|
||||
end
|
||||
|
||||
function Player:padAddTouch(touchname)
|
||||
self.gamepad.buttons[touchname] = {}
|
||||
self.gamepad.buttons[touchname].down = false
|
||||
self.gamepad.buttons[touchname].rel = false
|
||||
self.gamepad.buttons[touchname].press = false
|
||||
end
|
||||
|
||||
function Player:padAddAnalogue()
|
||||
local id = #self.gamepad.analogs + 1
|
||||
self.gamepad.analogs[id] = {}
|
||||
self.gamepad.analogs[id].angle = 0
|
||||
self.gamepad.analogs[id].strenght = 0
|
||||
end
|
||||
|
||||
-- UPDATE and COLLISION functions
|
||||
|
||||
function Player:update(dt)
|
||||
self.keys = self.level.keys
|
||||
self:actionMove(dt)
|
||||
|
||||
self:shoot(dt)
|
||||
|
@ -170,47 +132,11 @@ end
|
|||
|
||||
-- GAMEPLAY functions
|
||||
|
||||
function Player:padPush(touchname, value)
|
||||
if (value == true) then
|
||||
-- Si le bouton est enfoncé, alors on ne peut pas l'avoir relaché
|
||||
self.gamepad.buttons[touchname].rel = false
|
||||
|
||||
|
||||
if (self.gamepad.buttons[touchname].down == true) then
|
||||
-- Si le bouton était déjà pressé au début, alors on indique
|
||||
-- qu'il ne vient pas d'être pressé.
|
||||
self.gamepad.buttons[touchname].down = true
|
||||
self.gamepad.buttons[touchname].press = false
|
||||
else
|
||||
-- Sinon, on indique qu'il viens d'être pressé, et
|
||||
-- qu'il est enfoncé
|
||||
self.gamepad.buttons[touchname].down = true
|
||||
self.gamepad.buttons[touchname].press = true
|
||||
end
|
||||
|
||||
else
|
||||
-- Si le bouton est relaché, alors on ne peut pas l'avoir pressé
|
||||
self.gamepad.buttons[touchname].press = false
|
||||
|
||||
if (self.gamepad.buttons[touchname].down == true) then
|
||||
-- Si le bouton était déjà pressé au début, alors on indique
|
||||
-- qu'il vient d'être relaché, et qu'il n'est plus enfoncé
|
||||
self.gamepad.buttons[touchname].down = false
|
||||
self.gamepad.buttons[touchname].rel = true
|
||||
else
|
||||
-- Sinon, on indique qu'il ne viens plus d'être relaché, et
|
||||
-- qu'il n'est pas enfoncé, au cas ou.
|
||||
self.gamepad.buttons[touchname].down = false
|
||||
self.gamepad.buttons[touchname].rel = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Player:shoot()
|
||||
if self.gamepad.buttons["B"].press then
|
||||
if self.keys["B"].isPressed then
|
||||
self:launchWeapon()
|
||||
end
|
||||
if self.gamepad.buttons["C"].press then
|
||||
if self.keys["C"].isPressed then
|
||||
self:changeWeapon(self.weaponID+1)
|
||||
end
|
||||
end
|
||||
|
@ -218,7 +144,7 @@ end
|
|||
function Player:actionMove(dt)
|
||||
local dx, dy = 0, 0
|
||||
|
||||
if self.gamepad.buttons["right"].down and not (self.gamepad.buttons["left"].down) then
|
||||
if self.keys["right"].isDown and not (self.keys["left"].isDown) then
|
||||
if (self.xsp < self.topsp) then
|
||||
if (self.xsp < 0) then
|
||||
self.xsp = self.xsp + self.dec
|
||||
|
@ -226,7 +152,7 @@ function Player:actionMove(dt)
|
|||
self.xsp = self.xsp + self.acc
|
||||
end
|
||||
end
|
||||
elseif self.gamepad.buttons["left"].down and not (self.gamepad.buttons["right"].down) then
|
||||
elseif self.keys["left"].isDown and not (self.keys["right"].isDown) then
|
||||
if (self.xsp > -self.topsp) then
|
||||
if (self.xsp > 0) then
|
||||
self.xsp = self.xsp - self.dec
|
||||
|
@ -239,9 +165,9 @@ function Player:actionMove(dt)
|
|||
end
|
||||
|
||||
if (self.grav == 0) then
|
||||
if self.gamepad.buttons["down"].down and (self.y < 1000) then
|
||||
if self.keys["down"].isPressed and (self.y < 1000) then
|
||||
self.ysp = 160
|
||||
elseif self.gamepad.buttons["up"].down and (self.y > 0) then
|
||||
elseif self.keys["up"].isPressed and (self.y > 0) then
|
||||
self.ysp = -160
|
||||
end
|
||||
end
|
||||
|
@ -252,14 +178,14 @@ function Player:actionMove(dt)
|
|||
|
||||
multijump = true
|
||||
|
||||
if ((self.onGround == true) or multijump) and self.gamepad.buttons["A"].press then
|
||||
if ((self.onGround == true) or multijump) and self.keys["A"].isPressed then
|
||||
self.ysp = self.jmp
|
||||
self.isJumping = true
|
||||
assets:playSFX("jump")
|
||||
assets.sprites["cochon"]:resetAnimation(self.animations["jump"])
|
||||
end
|
||||
|
||||
if (self.isJumping == true) and (self.ysp < (-4 * 60)) and (not (self.gamepad.buttons["A"].down)) then
|
||||
if (self.isJumping == true) and (self.ysp < (-4 * 60)) and (not (self.keys["A"].isDown)) then
|
||||
self.ysp = -4 * 60
|
||||
end
|
||||
|
||||
|
@ -289,8 +215,8 @@ local animation = 1
|
|||
if (self.xsp == 0) then
|
||||
animation = "idle"
|
||||
else
|
||||
if (self.gamepad.buttons["left"].down and (self.xsp > 0)) or
|
||||
(self.gamepad.buttons["right"].down and (self.xsp < 0)) then
|
||||
if (self.keys["left"].isDown and (self.xsp > 0)) or
|
||||
(self.keys["right"].isDown and (self.xsp < 0)) then
|
||||
animation = "brake"
|
||||
else
|
||||
animation = "walk"
|
||||
|
|
Loading…
Reference in New Issue