-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathents.lua
More file actions
120 lines (93 loc) · 1.95 KB
/
Copy pathents.lua
File metadata and controls
120 lines (93 loc) · 1.95 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
Entity = {
x = 0, y = 0, angle = -math.pi / 2
}
function Entity:new(t)
t = t or {}
setmetatable(t, self)
self.__index = self
return t
end
function Entity:setPos(x, y)
self.x = x
self.y = y
end
function Entity:getPos()
return self.x, self.y
end
function Entity:setAng(val)
self.angle = val
end
function Entity:getAng()
return self.angle
end
--Bullet
Bullet = Entity:new{damage = 20, texture = nil}
function Bullet:init(x, y, ang, speed, damage, texture)
self.x, self.y = x, y
self.angle = ang
if speed ~= nil then
self.speed = speed
else
self.speed = config.BULLET_SPEED
end
if damage ~= nil then
self.damage = damage
else
self.damage = config.BULLET_DAMAGE
end
if texture ~= nil then
self.texture = texture
else
self.texture = textures.bullet
end
end
function Bullet:getNextPos(dt)
local x = self.x + self.speed * math.cos(self.angle) * dt
local y = self.y + self.speed * math.sin(self.angle) * dt
return x, y
end
function Bullet:updatePos(dt)
self:setPos(self:getNextPos(dt))
end
function Bullet:draw()
local xoff, yoff = funcs.GetImageCenter(self.texture)
local x, y = camera.ToScreen(self:getPos())
funcs.DrawEx(self.texture, x, y, self.angle)
end
--Ammo
AmmoStack = Entity:new()
function AmmoStack:init(x, y, v, texture)
self.x = x
self.y = y
if v ~= nil then
self.value = v
else
self.value = config.PLAYER_AMMO
end
if texture ~= nil then
self.texture = texture
else
self.texture = textures.ammo
end
end
function AmmoStack:draw()
local x, y = camera.ToScreen(self:getPos())
funcs.DrawEx(self.texture, x, y, nil)
end
--Spawnpoint
Spawnpoint = Entity:new{kind = 'player'} --player by default
function Spawnpoint:spawn()
if self.kind == 'player' then
local p = LocalPlayer:new()
p:init(self.x, self.y, config.PLAYER_HEALTH, config.PLAYER_AMMO)
return p
end
if self.kind == 'enemy' then --TODO
end
end
return {
Entity = Entity,
Bullet = Bullet,
AmmoStack = AmmoStack,
Spawnpoint = Spawnpoint
}