-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbull.lua
116 lines (105 loc) · 3.3 KB
/
bull.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
require "lib/SECS"
require "lib/AnAL"
local speed = 200
local capturedspeed = 600
local normalAnim
local caughtAnim
bull = class:new()
function bull:init(x, y, a, p)
self.x = x or 0
self.y = y or 0
self.dir = math.random() * math.pi
self.dirX = math.cos(self.dir)
self.dirY = math.sin(self.dir)
self.dur = math.random(1,3)
self.r = 0
self.caught = false
self.arena = a
self.player = p
self.hitwall = false
if not normalAnim then
normalAnim = newAnimation(images.bulls, 76, 167, 0.1, 8)
normalAnim:play()
end
if not caughtAnim then
caughtAnim = newAnimation(images.bulls_caught, 76, 167, 0.1, 8)
caughtAnim:play()
end
self.dustParticles = love.graphics.newParticleSystem(images.dust, 25)
self.dustParticles:setSpeed(5, 10)
self.dustParticles:setSpread(math.rad(180))
self.dustParticles:setSize(0.9, 1.1, 1)
self.dustParticles:setPosition(self.x, self.y)
self.dustParticles:setDirection(self.r+math.pi)
self.dustParticles:setLifetime(-1)
self.dustParticles:setEmissionRate(6)
self.dustParticles:setParticleLife(1.50)
self.dustParticles:setSpin(0.1, 1.0, 1)
self.dustParticles:setColor(255, 255, 255, 225, 255, 255, 255, 0)
self.dustParticles:start()
end
function bull:update(dt)
self.dur = self.dur - dt
normalAnim:update(dt)
caughtAnim:update(dt)
self.dustParticles:update(dt)
if not self.caught then
if self.dur <= 0 or self.hitwall then
local x, y, r
if math.random(1, 7) > 4 then
x, y = self.arena:center()
r = math.atan2(y-self.y, x-self.x)
self.dir = r + (math.random()-0.5)*math.pi
else
x, y = self.player.x, self.player.y
r = math.atan2(y-self.y, x-self.x)
self.dir = r + 0.05*math.random()
end
self.dirX = math.cos(self.dir)
self.dirY = math.sin(self.dir)
self.dur = math.random(3,7)
self.hitwall = false
end
self.x = self.x + self.dirX*speed*dt
self.y = self.y + self.dirY*speed*dt
self.r = self.dir + (math.pi * 0.5)
else
self.dur = 1
local p = self.caught
self.dir = math.atan2(p.y-self.y, p.x-self.x)+0.5*math.pi
self.dirX, self.dirY = math.cos(self.dir), math.sin(self.dir)
self.x = self.x + self.dirX*capturedspeed*dt
self.y = self.y + self.dirY*capturedspeed*dt
self.r = self.dir+0.5*math.pi
end
local x, y = self.x, self.y
--constrain to arena
self.x = math.max(self.x, self.arena:left()+38)
self.x = math.min(self.x, self.arena:right()-38)
self.y = math.max(self.y, self.arena:top()+70)
self.y = math.min(self.y, self.arena:bottom()-70)
self.dustParticles:setPosition(self.x, self.y)
self.dustParticles:setDirection(self.r+math.pi)
if self.x ~= x or self.y ~= y then
--we ran into a wall
self.hitwall = true
--player loses control now
if self.caught then
self.caught.gripping = false
self.caught.cb(false)
self.caught = false
end
end
end
function bull:draw()
local anim = normalAnim
if self.caught then anim = caughtAnim end
love.graphics.draw(self.dustParticles, 0, 0)
anim:draw(self.x, self.y, self.r, 1, 1, 25, 25)
end
function bull:getbodybox()
return { x = self.x-20, y = self.y, w = 66, h = 96, r = self.r, ox = 20, oy = 0 }
end
function bull:getheadbox()
return { x = self.x-15, y = self.y-25, w = 56, h = 25, r = self.r, ox = 15, oy = 25 }
end