-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBullet.lua
More file actions
40 lines (32 loc) · 1014 Bytes
/
Bullet.lua
File metadata and controls
40 lines (32 loc) · 1014 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
38
39
40
-- Import
local math = math
local love = love
local Class = require "Class"
local GameObject = require "GameObject"
local Bullet = Class({}, GameObject)
setfenv(1, Bullet)
local SPEED = 500
function Bullet:init(x, y, angle, body)
GameObject.init(self, x, y)
self.body = body
self.body.position.x = x
self.body.position.y = y
self.body.speed.x = SPEED * math.cos(angle)
self.body.speed.y = SPEED * math.sin(angle)
self.width = 10
self.height = 10
self.body:addCollisionCallback("tilemap", function(a, b)
a:destroy()
self.parentContext:removeObject(self)
end)
self.body:addOverlapCallback("enemy", function(a, b)
a:destroy()
self.parentContext:removeObject(self)
end)
end
function Bullet:draw()
love.graphics.reset()
love.graphics.setColor(255, 255, 0, 255)
love.graphics.circle("fill", self.body.position.x + self.width / 2, self.body.position.y + self.height / 2, self.width / 2, self.width)
end
return Bullet