|
|
@ -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) |
|
|
|
local offsetX = cos(self.rotation) * self.width * 1.5 |
|
|
|
if self.shot <= 10 then |
|
|
|
local offsetY = sin(self.rotation) * self.height * 1.5 |
|
|
|
self.shot = self.shot + 1 |
|
|
|
local bulletX = self.x + offsetX |
|
|
|
local offsetX = cos(self.rotation) * self.width * 1.5 |
|
|
|
local bulletY = self.y + offsetY |
|
|
|
local offsetY = sin(self.rotation) * self.height * 1.5 |
|
|
|
local newBullet = Bullet(bulletX, bulletY, self.p, bulletSpeed, self.rotation) |
|
|
|
local bulletX = self.x + offsetX |
|
|
|
return newBullet |
|
|
|
local bulletY = self.y + offsetY |
|
|
|
|
|
|
|
local newBullet = Bullet(bulletX, bulletY, self.p, bulletSpeed, self.rotation) |
|
|
|
|
|
|
|
return newBullet |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
function Player:handleKeys(up, down, left, right, dt) |
|
|
|
function Player:handleKeys(up, down, left, right, dt) |
|
|
|