-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.lua
More file actions
95 lines (82 loc) · 2.68 KB
/
player.lua
File metadata and controls
95 lines (82 loc) · 2.68 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
require "basicweapon"
playerWeaponsList = {}
playerWeaponsListRemove = {}
Player = {
timeToNextShot = 0,
bulletImage
}
PlayerBuilder = createClass(Player, Updatable, Drawable)
function Player:new()
self.bulletImage = love.graphics.newImage("dev/smallbullet.png")
self.image = playerImage
end
function Player:collide() -- player death
print("Player died!")
playerLives = playerLives - 1
shotDelay = shotDelayMax
love.timer.sleep(1000)
clearScreen()
resetPlayer()
if playerLives <= 0 then -- game over, print info to console and reset game status to start
accuracy = math.floor((hitCount / shotCount)*100)
gameState = 4
else
drawBackground()
end
end
function Player:update()
self.timeToNextShot = self.timeToNextShot - 1
if love.keyboard.isDown("left") then
if self.x > smallestX then
self.x = self.x - playerSpeed
elseif self.x <= smallestX then
self.x = largestX
end
elseif love.keyboard.isDown("right") then
if self.x < largestX then
self.x = self.x + playerSpeed
elseif self.x >= largestX then
self.x = smallestX
end
end
if love.keyboard.isDown(" ") and self.timeToNextShot <= 0 then
shotCount = shotCount + 1
self.timeToNextShot = shotDelay
local params3 = {
image = love.graphics.newImage("dev/smallbullet.png"),
x = (self.x + self.image:getWidth() / 2 - self.bulletImage:getWidth() / 2),
y = self.y - self.bulletImage:getHeight(),
z = self.z,
collection = playerWeaponsList,
removeCollection = playerWeaponsListRemove
}
if shotDelay <= shotDelayMin then
local params1 = {
image = love.graphics.newImage("dev/smallestbullet.png"),
x = (self.x + self.image:getWidth() / 2 - self.bulletImage:getWidth() / 2)-7,
y = self.y - self.bulletImage:getHeight(),
z = self.z,
collection = playerWeaponsList,
removeCollection = playerWeaponsListRemove
}
BasicWeaponBuilder:new(params1)
--BasicWeaponBuilder:new(params2)
--BasicWeaponBuilder:new(params3)
else
BasicWeaponBuilder:new(params3)
end
end
if love.keyboard.isDown("up") and self.timeToNextShot <= 0 then
shotCount = shotCount + 1
self.timeToNextShot = shotDelay
local params = {
image = love.graphics.newImage("dev/smallbullet.png"),
x = self.x + self.image:getWidth() / 2 - self.bulletImage:getWidth() / 2,
y = self.y - self.bulletImage:getHeight(),
z = self.z,
collection = playerWeaponsList,
removeCollection = playerWeaponsListRemove
}
BasicWeaponBuilder:new(params)
end
end