-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbullet.lua
More file actions
47 lines (41 loc) · 1.02 KB
/
bullet.lua
File metadata and controls
47 lines (41 loc) · 1.02 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
--! bullet.lua
Bullet = Object:extend()
function Bullet:new(x ,y)
self.image = love.graphics.newImage("bullet.png")
self.x = x
self.y = y
self.speed = 700
self.width = self.image:getWidth()
self.height = self.image:getHeight()
end
function Bullet:update(dt)
self.y = self.y + self.speed *dt
if self.y > love.graphics.getHeight() then
love.load()
end
end
function Bullet:draw()
love.graphics.draw(self.image,self.x,self.y)
end
function Bullet:checkCollision(obj)
local self_left = self.x
local self_right = self.x + self.width
local self_top = self.y
local self_bottom = self.y + self.height
local obj_left = obj.x
local obj_right = obj.x + obj.width
local obj_top = obj.y
local obj_bottom = obj.y + obj.height
if self_right > obj_left and
self_left < obj_right and
self_bottom > obj_top and
self_top < obj_bottom then
self.dead = true
obj.speed = obj.speed +50
if obj.speed > 0 then
obj.speed = obj.speed + 50
else
obj.speed = obj.speed - 50
end
end
end