Best controls

This commit is contained in:
Andros Fenollosa
2017-01-03 22:05:46 +01:00
parent 0bf3f6926e
commit 0182767625
257 changed files with 61 additions and 50819 deletions

View File

@ -1,4 +1,5 @@
local controls = {}
local buttons = {}
function controls.load(game)
controls.padding = 50
@ -8,19 +9,7 @@ function controls.load(game)
end
function controls.update(dt)
control_up, control_right, control_left, control_quit = false, false, false, false
-- Keyboard
if love.keyboard.isDown('escape') or love.keyboard.isDown('q') then
control_quit = true
end
if love.keyboard.isDown('right') then
control_right = true
elseif love.keyboard.isDown('left') then
control_left = true
end
if love.keyboard.isDown('up') then
control_up = true
end
-- Keyboard
-- Mouse
if love.mouse.isDown(1) then
local x, y = love.mouse.getPosition()
@ -41,4 +30,28 @@ function controls.draw()
love.graphics.draw(controls.img_right, controls.right_x, controls.right_y)
end
function controls.keypressed(key, scancode, isrepeat)
if key == 'escape' or key == 'q' then
CONTROL_QUIT = true
end
if key == 'right' then
CONTROL_RIGHT = true
elseif key == 'left' then
CONTROL_LEFT = true
end
if key == 'up' then
CONTROL_UP = true
end
end
function controls.keyreleased(key, scancode)
CONTROL_UP, CONTROL_RIGHT, CONTROL_LEFT, CONTROL_QUIT = false, false, false, false
end
function controls.mousepressed(x, y, button, istouch)
end
function controls.mousereleased(x, y, button, istouch)
end
return controls

View File

@ -14,8 +14,6 @@ function game.load()
local gravity = 2
love.physics.setMeter(world_meter) -- Height earth in meters
game.world = love.physics.newWorld(0, gravity * world_meter, true) -- Make earth
-- Collisions
--game.collisions = HC.new(150)
end
return game

View File

@ -80,18 +80,18 @@ function spaceship.update(dt, game)
-- Explosion
explosion.animation:update(dt)
-- Controls
if control_up then
if CONTROL_UP then
body.body:applyForce(0, -body.power)
press_button = true
end
if control_right then
if CONTROL_RIGHT then
body.body:applyForce(body.power, 0)
press_button = true
elseif control_left then
elseif CONTROL_LEFT then
body.body:applyForce(-body.power, 0)
press_button = true
end
if control_quit then
if CONTROL_QUIT then
love.event.push('quit')
end
-- Collision