-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbullet.lua
executable file
·42 lines (33 loc) · 999 Bytes
/
bullet.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
local global = require 'global'
local class = require 'middleclass.middleclass'
local Collidable = require 'collidable'
local Bullet = class('Bullet', Collidable)
function Bullet:initialize(x, y, dx, dy, damage)
Collidable.initialize(self, x, y)
self.hitbox = global.addHitbox(self, x, y, 2, 2)
self.dx = dx
self.dy = dy
self.damage = damage
self.layer = 2
self.stopsHumans = false
end
function Bullet:hurt()
end
function Bullet:onCollision(other, dx, dy)
if (other:isInstanceOf(Collidable) and other:stopsBullets()) or
(other.class.name == "Human" and love.math.random() < other.bulletChance) then
other:hurt(self.damage)
self:destroy()
end
end
function Bullet:update(dt)
self.x = self.x + self.dx * dt
self.y = self.y + self.dy * dt
Collidable.update(self)
end
function Bullet:draw()
love.graphics.setPointSize(2)
love.graphics.setColor(50, 100, 150)
love.graphics.point(self.x, self.y)
end
return Bullet