-
Notifications
You must be signed in to change notification settings - Fork 0
/
tank.lua
60 lines (48 loc) · 1.39 KB
/
tank.lua
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
local global = require "global"
local class = require "middleclass.middleclass"
local Mobile = require "mobile"
local Tank = class("Tank", Mobile)
local Bullet = require "bullet"
local image = love.graphics.newImage("tank.png")
function Tank:initialize(x, y)
Mobile.initialize(self, x, y, 5000)
self.x = x
self.y = y
self.vx = 50
self.vy = 0
self.stopsHumans = true
self.fire_cooldown_max = 0.05
self.fire_cooldown = self.fire_cooldown_max
self.damage = 50
self.hitbox = global.addHitbox(self, x, y, image:getWidth(), image:getHeight())
self.layer = 3
end
function Tank:stopsBullets()
return false
end
function Tank:update(dt)
Mobile.update(self, dt)
self.fire_cooldown = self.fire_cooldown - dt
if self.fire_cooldown <= 0 then
self.fire_cooldown = self.fire_cooldown_max
self:fire()
end
end
function Tank:draw()
love.graphics.setColor(255, 255, 255)
love.graphics.draw(image, self.x, self.y)
end
-- tanks don't really respect collisions
function Tank:onCollision(other, dx, dy)
if other:isInstanceOf(Mobile) then
other:destroy()
end
end
function Tank:fire()
local bx = self.vx + 100
local by = math.random(-20, 20)
global.addDrawable(Bullet(self.x + image:getWidth() + 10,
self.y + image:getHeight()/2,
bx, by, 50))
end
return Tank