-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.lua
More file actions
38 lines (30 loc) · 788 Bytes
/
player.lua
File metadata and controls
38 lines (30 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
--! file: player.lua
Player = Object:extend()
function Player:new()
self.image = love.graphics.newImage("panda.png")
self.x = 300
self.y = 20
self.speed = 500
self.width = self.image:getWidth()
end
function Player:update(dt)
if love.keyboard.isDown("left") then
self.x = self.x - self.speed *dt
elseif love.keyboard.isDown("right") then
self.x = self.x + self.speed *dt
end
local window_width = love.graphics.getWidth()
if self.x < 0 then
self.x = 0
elseif self.x + self.width > window_width then
self.x = window_width - self.width
end
end
function Player:keypressed(key)
if key == "space" then
table.insert(listOfBullets, Bullet(self.x,self.y))
end
end
function Player:draw()
love.graphics.draw(self.image,self.x,self.y)
end