Player = Entity:New(x,y) -- Player Gun Types 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 } } -- Player Builder function Player:New(x,y) local o = Entity:New(x,y) o.moveSpeed = 3 o.moveSpeedFocused = 2 o.hitbox = 5 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("Simulate") setmetatable(o, self) self.__index = self return o end -- Function to get the player input function Player:Input() -- Gun Switch 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 -- Player Intent to 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 -- Variable moveSpeed when focusing if love.keyboard.isDown("lshift") then self:MoveTowards(self.target.x, self.target.y, self.moveSpeedFocused) else self:MoveTowards(self.target.x, self.target.y, self.moveSpeed) end -- Actually moving the player self.pos.x = math.min(math.max(self.pos.x + self.vel.x,self.hitbox),windowWidth - self.hitbox) self.pos.y = math.min(math.max(self.pos.y + self.vel.y,self.hitbox),windowHeight - self.hitbox) -- Get Ready to shoot if triggered if self.shotTimer > 0 then self.shotTimer = self.shotTimer - current_dt end if self.shotTimer < 0 then self.shotTimer = 0 end -- Shoot if ready and triggered if love.mouse.isDown(1) and self.shotTimer == 0 then local x, y = love.mouse.getPosition() Projectile:New(self.pos.x,self.pos.y,GetAngleFromVector(x - self.pos.x, y - self.pos.y), self.GunType[self.current_gun]) self.shotTimer = self.GunType[self.current_gun].shotCooldown end end function Player:Step() end function Player:Draw() love.graphics.setColor(1,1,1) -- Draw Mouse local x, y = love.mouse.getPosition() love.graphics.circle("line", x, y, self.hitbox/2) -- Draw Gun Name --love.graphics.print("Current Gun: "..self.GunType[self.current_gun].name, 10, 35) -- Draw Self 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 -- Draw Hitbox love.graphics.setColor(1,0,0) if love.keyboard.isDown("lshift") then love.graphics.circle("fill", self.pos.x, self.pos.y, self.hitbox) end love.graphics.setColor(1,1,1) end