-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathchicagoToaster.lua
More file actions
executable file
·133 lines (106 loc) · 3.77 KB
/
chicagoToaster.lua
File metadata and controls
executable file
·133 lines (106 loc) · 3.77 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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
----------------------------------
-- THE BIG 3 VIDEO GAME ---
-- andrew@langleycreations.com ---
----------------------------------
-- Script controls the toaster behaviors and properties
-- for the Chicago endless runner level
local toasters = {
}
local function doQuadraticBezierCurve(point1, point2, point3, t)
local a = (1.0 - t) * (1.0 - t);
local b = 2.0 * t * (1.0 - t);
local c = t * t;
local x = math.floor( a * point1.x + b * point2.x + c * point3.x )
local y = math.floor( a * point1.y + b * point2.y + c * point3.y )
return x,y
end
local function update(toaster, mainScene)
if( not toaster.bRemove and toaster.health > 0 ) then
toaster.t = toaster.t+ (0.0175 * mainScene.timeScale )
if ( toaster.t > 1 ) then
toaster.t = 1
end
toaster.x, toaster.y = doQuadraticBezierCurve( toaster.origin,toaster.midPoint, toaster.destination, toaster.t )
end
end
function toasters:spawn(scene)
if ( not self.sound ) then
self.sound1 = scene.sound:loadEnemyImpactSound( "toaster1.wav" )
self.sound2 = scene.sound:loadEnemyImpactSound( "toaster2.wav" )
self.sound3 = scene.sound:loadEnemyImpactSound( "toaster3.wav" )
end
mainScene = scene
display.setDefault( "magTextureFilter", "nearest" )
display.setDefault( "minTextureFilter", "nearest" )
local toaster = display.newImageRect( "images/toaster.png", 31, 30 )
local hat = display.newImageRect( "images/toasterHat.png", 21, 18 )
toaster.hat = hat
toaster.collisionDistance = 25
--toaster.bPerciseCollisionDetection = true
display.setDefault( "magTextureFilter", "linear" )
display.setDefault( "minTextureFilter", "linear" )
local x = mainScene.city:getGroundSpawnCoordinate()
toaster.x = x + toaster.width
toaster.y = mainScene.groundY - 2
toaster.anchorX=0.5;toaster.anchorY=1
mainScene.city.displayGroup:insert( toaster )
mainScene.city.displayGroup:insert( toaster.hat )
local hatUpdate = function()
local bRemoveHat = false
if( hat.x ) then
if( toaster.health <= 0 and not hat.bCollided ) then
local num = math.random(3)
if( num == 1 ) then
mainScene.sound:playEnemyImpactSound( self.sound1 )
elseif( num == 2 ) then
mainScene.sound:playEnemyImpactSound( self.sound2 )
else
mainScene.sound:playEnemyImpactSound( self.sound3 )
end
hat.bCollided = true
local d = math.random(20)*.1+1.5
mainScene:setPhysics( true )
physics.addBody( hat, { density=d, friction=0.2, bounce=0.3, shape= self.bodyShape } )
local lx = 0
local ly = 1 - (math.random(5) )
if( mainScene.player.bDashing ) then
lx = 10
ly = 5
end
if( hat.applyLinearImpulse ) then
hat:applyLinearImpulse( lx,ly, hat.x+20, hat.y )
hat:applyAngularImpulse( math.random(70)+70 )
end
hat.explosionScale = 0.2
mainScene.obstacles:addMisc(hat,true)
end
if( not mainScene ) then
hat:removeSelf()
else
if( hat.contentBounds.xMax < mainScene.leftEdge and not hat.bCollided ) then
hat:removeSelf()
bRemoveHat = true
end
end
else
bRemoveHat = true
end
if( bRemoveHat ) then
timer.cancel( hat.timer )
hat = nil
end
end
hat.timer = timer.performWithDelay( 20, hatUpdate, 0 )
toaster.update = function()
end
toaster.bGroundSpawn = true
toaster.health = 1
toaster.xChoke = -20
toaster.yChoke = -50
toaster.explosionScale = 1
toaster.hat.x = toaster.x - 8
toaster.hat.y = toaster.y - 33
toaster.name = "toaster"
return toaster
end
return toasters