|
|
@ -1,17 +1,27 @@ |
|
|
--! file: player.lua |
|
|
--! file: player.lua |
|
|
Player = Object:extend() |
|
|
Player = Object:extend() |
|
|
require("blaster") |
|
|
require("blaster") |
|
|
|
|
|
local listOfBullets |
|
|
|
|
|
|
|
|
function Player:new(x, y) |
|
|
function Player:new(x, y) |
|
|
|
|
|
self.image = { |
|
|
|
|
|
{ "fullHealth", love.graphics.newImage("/assets/player/player01.png") }, |
|
|
|
|
|
{ "damaged", love.graphics.newImage("/assets/player/player02.png") }, |
|
|
|
|
|
{ "halfHealth", love.graphics.newImage("/assets/player/player03.png") }, |
|
|
|
|
|
{ "nearDeath", love.graphics.newImage("/assets/player/player04.png") }, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
self.x = x |
|
|
self.x = x |
|
|
self.y = y |
|
|
self.y = y |
|
|
|
|
|
self.width = self.image[1][2]:getWidth() |
|
|
|
|
|
self.height = self.image[1][2]:getHeight() |
|
|
self.health = 100 |
|
|
self.health = 100 |
|
|
self.speed = 200 |
|
|
self.speed = 200 |
|
|
|
|
|
|
|
|
listOfBullets = {} |
|
|
listOfBullets = {} |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
function Player:update(dt) |
|
|
function Player:update(dt, enemies) |
|
|
--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 |
|
|
@ -31,16 +41,17 @@ function Player:update(dt) |
|
|
table.remove(listOfBullets, i) |
|
|
table.remove(listOfBullets, i) |
|
|
print("Bullet Destroyed! Bullets in Table: ", #listOfBullets) |
|
|
print("Bullet Destroyed! Bullets in Table: ", #listOfBullets) |
|
|
end |
|
|
end |
|
|
|
|
|
--recieve the list of enemies and check to see if the bullets hit |
|
|
|
|
|
for _, j in ipairs(enemies) do |
|
|
|
|
|
v:checkCollision(j) |
|
|
|
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
function Player:draw() |
|
|
function Player:draw() |
|
|
--local vert = { self.x, self.y, (self.x - 70), (self.y + 70), (self.x + 70), (self.y + 70) } |
|
|
--local vert = { self.x, self.y, (self.x - 70), (self.y + 70), (self.x + 70), (self.y + 70) } |
|
|
--love.graphics.polygon("fill", vert) |
|
|
--love.graphics.polygon("fill", vert) |
|
|
local fullHealth = love.graphics.newImage("/assets/player/player01.png") |
|
|
local fullHealth = self.image[1][2] |
|
|
local damaged = love.graphics.newImage("/assets/player/player02.png") |
|
|
|
|
|
local halfHealth = love.graphics.newImage("/assets/player/player03.png") |
|
|
|
|
|
local nearDeath = love.graphics.newImage("/assets/player/player04.png") |
|
|
|
|
|
|
|
|
|
|
|
love.graphics.draw(fullHealth, self.x, self.y) |
|
|
love.graphics.draw(fullHealth, self.x, self.y) |
|
|
|
|
|
|
|
|
|