|
|
@ -3,7 +3,7 @@ Player = Object:extend() |
|
|
require("blaster") |
|
|
require("blaster") |
|
|
local playerBullets |
|
|
local playerBullets |
|
|
|
|
|
|
|
|
function Player:new(x, y) |
|
|
function Player:new(x, y, playableArea) |
|
|
self.image = { |
|
|
self.image = { |
|
|
{ "fullHealth", love.graphics.newImage("/assets/player/player01.png") }, |
|
|
{ "fullHealth", love.graphics.newImage("/assets/player/player01.png") }, |
|
|
{ "damaged", love.graphics.newImage("/assets/player/player02.png") }, |
|
|
{ "damaged", love.graphics.newImage("/assets/player/player02.png") }, |
|
|
@ -15,6 +15,8 @@ function Player:new(x, y) |
|
|
self.y = y |
|
|
self.y = y |
|
|
self.width = self.image[1][2]:getWidth() |
|
|
self.width = self.image[1][2]:getWidth() |
|
|
self.height = self.image[1][2]:getHeight() |
|
|
self.height = self.image[1][2]:getHeight() |
|
|
|
|
|
self.playableLeft = playableArea[1] |
|
|
|
|
|
self.playableRight = playableArea[2] |
|
|
|
|
|
|
|
|
self.type = "player" |
|
|
self.type = "player" |
|
|
self.health = 100 |
|
|
self.health = 100 |
|
|
@ -28,6 +30,9 @@ function Player:new(x, y) |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
function Player:update(dt, enemies) |
|
|
function Player:update(dt, enemies) |
|
|
|
|
|
local maximumLeft = self.playableLeft - 8 |
|
|
|
|
|
local maximumRight = self.playableRight - 38 |
|
|
|
|
|
|
|
|
--movement |
|
|
--movement |
|
|
if love.keyboard.isDown("left") then |
|
|
if love.keyboard.isDown("left") then |
|
|
self.x = self.x - self.speed * dt |
|
|
self.x = self.x - self.speed * dt |
|
|
@ -36,6 +41,12 @@ function Player:update(dt, enemies) |
|
|
self.x = self.x + self.speed * dt |
|
|
self.x = self.x + self.speed * dt |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
if self.x < maximumLeft then |
|
|
|
|
|
self.x = maximumLeft |
|
|
|
|
|
elseif self.x > maximumRight then |
|
|
|
|
|
self.x = maximumRight |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
--update bounds |
|
|
--update bounds |
|
|
self.bounds = { (self.x + 8), (self.x + 38), (self.y + 10), (self.y + 36) } |
|
|
self.bounds = { (self.x + 8), (self.x + 38), (self.y + 10), (self.y + 36) } |
|
|
|
|
|
|
|
|
|