Blame view

bullet.lua 843 Bytes
ca0e8212   Geoffrey PREUD'HOMME   Code original
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
  bullet = class:new()

  

  function bullet:init(x, y, r)

  	self.x = x

  	self.y = y

  	self.r = r

  	gunfire:stop()

  	gunfire:play()

  end

  

  function bullet:update(dt)

  	if not self.kill then

  		self.x = self.x + math.sin(self.r)*500*dt

  		self.y = self.y - math.cos(self.r)*300*dt

  		

  		for i, v in pairs(asteroids) do

  			if v:checkcol(self.x, self.y) and not v.dead then

  				v:hit()

  				self.kill = 0

  			end

  		end

  	end

  	

  	if self.kill then

  		self.kill = self.kill + dt

  	end

  	

  	if self.kill and self.kill >= 0.2 then

  		return true

  	end

  end

  

  function bullet:draw()

  	if self.kill then

  		love.graphics.setColor(255, 255, 255, (1-self.kill/0.2)*255)

  		draw(littleexplosionimg, self.x, self.y, self.r, 1, 1, 8, 4)

  		love.graphics.setColor(255, 255, 255, 255)

  	else

  		draw(bulletimg, self.x, self.y, self.r, 1, 1, 6, 4)

  	end

  end