|
|
@ -35,16 +35,24 @@ function Player:new(p, x, y, health, image, speed, max) |
|
|
|
--Velocity |
|
|
|
--Velocity |
|
|
|
self.vx = 0 |
|
|
|
self.vx = 0 |
|
|
|
self.vy = 0 |
|
|
|
self.vy = 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Bullets shot |
|
|
|
|
|
|
|
self.shot = 0 |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
-- Method to handle shooting |
|
|
|
-- Method to handle shooting |
|
|
|
function Player:shoot(bulletSpeed) |
|
|
|
function Player:shoot(bulletSpeed) |
|
|
|
|
|
|
|
if self.shot <= 10 then |
|
|
|
|
|
|
|
self.shot = self.shot + 1 |
|
|
|
local offsetX = cos(self.rotation) * self.width * 1.5 |
|
|
|
local offsetX = cos(self.rotation) * self.width * 1.5 |
|
|
|
local offsetY = sin(self.rotation) * self.height * 1.5 |
|
|
|
local offsetY = sin(self.rotation) * self.height * 1.5 |
|
|
|
local bulletX = self.x + offsetX |
|
|
|
local bulletX = self.x + offsetX |
|
|
|
local bulletY = self.y + offsetY |
|
|
|
local bulletY = self.y + offsetY |
|
|
|
local newBullet = Bullet(bulletX, bulletY, self.p, bulletSpeed, self.rotation) |
|
|
|
local newBullet = Bullet(bulletX, bulletY, self.p, bulletSpeed, self.rotation) |
|
|
|
return newBullet |
|
|
|
return newBullet |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
function Player:handleKeys(up, down, left, right, dt) |
|
|
|
function Player:handleKeys(up, down, left, right, dt) |
|
|
|