124 lines
3.4 KiB
Lua
124 lines
3.4 KiB
Lua
Player = Entity:New(x,y)
|
|
|
|
Player.GunType = {
|
|
{
|
|
name = "Plasma Machine Gun",
|
|
shotCooldown = 0.05,
|
|
hits = 1,
|
|
damage = 1,
|
|
moveSpeed = 8,
|
|
animation = Animation.projectilePlasma,
|
|
friendly = true
|
|
},
|
|
{
|
|
name = "Piercing Blaster",
|
|
shotCooldown = 0.5,
|
|
hits = 3,
|
|
damage = 5,
|
|
moveSpeed = 5,
|
|
animation = Animation.projectilePiercing,
|
|
friendly = true
|
|
},
|
|
{
|
|
name = "Rocket Launcher",
|
|
shotCooldown = 1,
|
|
hits = 1,
|
|
damage = 10,
|
|
moveSpeed = 3,
|
|
animation = Animation.projectileRocket,
|
|
friendly = true
|
|
}
|
|
}
|
|
|
|
function Player:New(x,y)
|
|
local o = Entity:New(x,y)
|
|
|
|
o.moveSpeed = 3
|
|
o.hitbox = 10
|
|
o.sprite = love.graphics.newImage("assets/heart.png")
|
|
o.draw_scale = 3
|
|
|
|
-- gun properties
|
|
o.shotTimer = 0
|
|
o.current_gun = 1
|
|
o.gunSwitchTimer = 0
|
|
o.gunSwitchTime = 0.2
|
|
|
|
o.max_health = 100
|
|
o.health = 100
|
|
-- lists
|
|
o:AddList(List.Simulate)
|
|
|
|
setmetatable(o, self)
|
|
self.__index = self
|
|
return o
|
|
end
|
|
|
|
function Player:Input()
|
|
if self.sprite ~= nil then
|
|
-- gun control
|
|
if love.keyboard.isDown("q") then self.gunSwitchTimer = self.gunSwitchTimer - current_dt
|
|
elseif love.keyboard.isDown("e") then self.gunSwitchTimer = self.gunSwitchTimer + current_dt
|
|
else self.gunSwitchTimer = 0
|
|
end
|
|
|
|
if math.abs(self.gunSwitchTimer) > self.gunSwitchTime then
|
|
self.current_gun = self.current_gun + math.sign(self.gunSwitchTimer)
|
|
self.gunSwitchTimer = 0
|
|
end
|
|
|
|
if self.current_gun < 1 then self.current_gun = #self.GunType end
|
|
if self.current_gun > #self.GunType then self.current_gun = 1 end
|
|
|
|
-- basic movement
|
|
if love.keyboard.isDown("a") then self.target.x = self.pos.x - 1
|
|
elseif love.keyboard.isDown("d") then self.target.x = self.pos.x + 1
|
|
else self.target.x = self.pos.x end
|
|
|
|
if love.keyboard.isDown("w") then self.target.y = self.pos.y - 1
|
|
elseif love.keyboard.isDown("s") then self.target.y = self.pos.y + 1
|
|
else self.target.y = self.pos.y end
|
|
|
|
self:MoveTowards(self.target.x, self.target.y, self.moveSpeed)
|
|
|
|
self.pos.x = math.min(math.max(self.pos.x + self.vel.x,self.hitbox),window_width - self.hitbox)
|
|
self.pos.y = math.min(math.max(self.pos.y + self.vel.y,self.hitbox),window_height - self.hitbox)
|
|
|
|
-- shoot
|
|
local x, y = love.mouse.getPosition()
|
|
|
|
if self.shotTimer > 0 then self.shotTimer = self.shotTimer - current_dt end
|
|
if self.shotTimer < 0 then self.shotTimer = 0 end
|
|
|
|
if love.mouse.isDown(1) and self.shotTimer == 0 then
|
|
gunBullet:New(self.pos.x,self.pos.y,GetAngle(x - self.pos.x, y - self.pos.y), self.GunType[self.current_gun])
|
|
self.shotTimer = self.GunType[self.current_gun].shotCooldown
|
|
end
|
|
else
|
|
TimeDone = true
|
|
end
|
|
end
|
|
|
|
function Player:Step()
|
|
|
|
end
|
|
|
|
function Player:Draw()
|
|
--love.graphics.circle("line", self.pos.x, self.pos.y, self.hitbox)
|
|
|
|
local x, y = love.mouse.getPosition()
|
|
love.graphics.circle("line", x, y, self.hitbox/2)
|
|
|
|
--love.graphics.line(self.pos.x, self.pos.y, x, y)
|
|
love.graphics.print("Current Gun: "..self.GunType[self.current_gun].name, 10, 35)
|
|
if self.sprite ~= nil then
|
|
love.graphics.draw(
|
|
self.sprite,
|
|
self.pos.x-self.sprite:getPixelWidth()/2*self.draw_scale,
|
|
self.pos.y-self.sprite:getPixelHeight()/2*self.draw_scale,
|
|
0,
|
|
self.draw_scale
|
|
)
|
|
end
|
|
end
|