-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy path2hot.hxc
409 lines (342 loc) · 10.3 KB
/
2hot.hxc
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.math.FlxBasePoint;
import flixel.tweens.FlxEase;
import flixel.tweens.FlxTween;
import flixel.util.FlxTimer;
import funkin.audio.FunkinSound;
import funkin.Conductor;
import funkin.graphics.adobeanimate.FlxAtlasSprite;
import funkin.graphics.FunkinSprite;
import funkin.modding.base.ScriptedFlxAtlasSprite;
import funkin.Paths;
import funkin.play.cutscene.CutsceneType;
import funkin.play.cutscene.VideoCutscene;
import funkin.play.GameOverSubState;
import funkin.play.PlayState;
import funkin.play.PlayStatePlaylist;
import funkin.play.song.Song;
import funkin.play.stage.StageProp;
import funkin.save.Save;
// We have to use FlxBasePoint in scripts because FlxPoint is inlined and not available in scripts
class TwoHOTSong extends Song
{
var hasPlayedCutscene:Bool = false;
//var tempConductor:Conductor;
var cutsceneMusic:FunkinSound;
function new()
{
super('2hot');
hasPlayedCutscene = false;
}
/**
* Health lost when hit by can.
*/
var HEALTH_LOSS = 0.25 * 2;
public function listDifficulties(variationId:String, variationIds:Array<String>, showLocked:Bool):Array<String> {
if (showLocked || Save.instance.hasBeatenLevel('weekend1')) {
return super.listDifficulties(variationId, variationIds);
}
// Hide all difficulties if the player has not beaten the week.
return [];
}
public override function onCountdownStart(event:CountdownScriptEvent):Void {
super.onCountdownStart(event);
}
function onSongRetry(event:ScriptEvent)
{
super.onSongRetry(event);
removeCans();
gunCocked = false;
}
public override function onSongEnd(event:CountdownScriptEvent):Void {
super.onSongEnd(event);
if (!PlayStatePlaylist.isStoryMode) hasPlayedCutscene = true;
if (!hasPlayedCutscene) {
hasPlayedCutscene = true;
event.cancel();
// start the video cutscene and hide it so the other stuff can happen after
startCutscene();
} else {
// Make sure the cutscene can play again next time!
hasPlayedCutscene = false;
// DO NOT CANCEL THE EVENT!
}
}
// the Other stuff
function endCutscene(){
VideoCutscene.onVideoStarted.removeAll();
VideoCutscene.hideVideo();
new FlxTimer().start(1, function(tmr)
{
PlayState.instance.tweenCameraToPosition(1539, 833.5, 2, FlxEase.quadInOut);
PlayState.instance.tweenCameraZoom(0.69, 2, true, FlxEase.quadInOut);
});
// Since no music plays at this part I'm too lazy to hook Nene up to a conductor,
// so we just dance on a timer here.
new FlxTimer().start(0.5, function(tmr)
{
PlayState.instance.currentStage.getGirlfriend().dance(true);
}, 10);
new FlxTimer().start(2, function(tmr)
{
PlayState.instance.currentStage.getBoyfriend().playAnimation('intro1', true, true);
});
new FlxTimer().start(2.5, function(tmr)
{
PlayState.instance.currentStage.getDad().playAnimation('pissed', true, true);
});
new FlxTimer().start(6, function(tmr)
{
// video would play around here
//PlayState.instance.endSong(true);
trace('Pausing ending to play a video cutscene (`2hot`)');
// Add a black background behind the cutscene to fix a transition bug!
trace('Adding black background behind cutscene over UI');
var bgSprite = new FunkinSprite(-100, -100);
bgSprite.makeSolidColor(2000, 2500, 0xFF000000);
bgSprite.cameras = [PlayState.instance.camHUD]; // Show over the HUD.
bgSprite.zIndex = 1000000;
PlayState.instance.add(bgSprite);
PlayState.instance.refresh();
VideoCutscene.showVideo();
});
}
function startCutscene(){
VideoCutscene.onVideoStarted.add(endCutscene);
PlayState.instance.camHUD.visible = false;
PlayState.instance.isInCutscene = true;
hasPlayedCutscene = true;
PlayState.instance.currentStage.getBoyfriend().danceEvery = 0;
PlayState.instance.currentStage.getDad().danceEvery = 0;
startVideo();
}
function startVideo() {
VideoCutscene.play(Paths.videos('2hotCutscene'), CutsceneType.ENDING);
}
function removeCans()
{
for (can in spawnedCans)
{
can.kill();
}
spawnedCans = [];
}
function onStateChangeEnd(event:StateChangeScriptEvent)
{
super.onStateChangeEnd(event);
if ((Std.isOfType(event.targetState, PlayState)))
{
return;
}
hardClear();
}
function hardClear()
{
removeCans();
gunCocked = false;
}
var gunCocked:Bool = false;
var spawnedCans:Array<ScriptedFlxAtlasSprite> = [];
function onNoteHit(event:HitNoteScriptEvent)
{
super.onNoteHit(event);
if (PlayState.instance.currentStage == null) return;
switch (event.note.kind)
{
case "weekend-1-lightcan":
// Do nothing, but place this such that the animation plays at the right time.
case "weekend-1-kickcan":
// This creates the can and starts the animation.
// We define the behavior of the can in a separate scripted class,
// which allows the can to track and manage its own properties.
var newCan:ScriptedFlxAtlasSprite = ScriptedFlxAtlasSprite.init('SpraycanAtlasSprite', 0, 0);
var spraycanPile = PlayState.instance.currentStage.getNamedProp('spraycanPile');
newCan.x = spraycanPile.x - 430;
newCan.y = spraycanPile.y - 840;
newCan.zIndex = spraycanPile.zIndex - 1;
newCan.scriptCall('playCanStart');
PlayState.instance.currentStage.add(newCan);
PlayState.instance.currentStage.refresh(); // Apply z-index.
spawnedCans.push(newCan);
case "weekend-1-kneecan":
// Do nothing, but place this such that the animation plays at the right time.
case "weekend-1-cockgun": // lol
gunCocked = true;
new FlxTimer().start(1.0, function()
{
gunCocked = false;
});
case "weekend-1-firegun":
if (gunCocked)
{
trace('Firing gun!');
shootNextCan();
}
else
{
trace('Cannot fire gun!');
// The player cannot hit this note.
event.cancelEvent();
}
}
}
public var STATE_ARCING:Int = 2; // In the air.
public var STATE_SHOT:Int = 3; // Hit by the player.
public var STATE_IMPACTED:Int = 4; // Impacted the player.
function getNextCanWithState(desiredState:Int)
{
for (index in 0...spawnedCans.length)
{
var can = spawnedCans[index];
var canState = can.scriptGet('currentState');
if (canState == desiredState)
{
// Return the can we found.
return can;
}
}
return null;
}
function onUpdate(event:UpdateScriptEvent) {
super.onUpdate(event);
}
function darkenStageProps()
{
// Darken the background, then fade it back.
for (stageProp in PlayState.instance.currentStage.members)
{
// Determine if the stage prop is something that should be excluded from darkening.
if (Std.isOfType(stageProp, StageProp)) {
if (stageProp.name == "bf" || stageProp.name == "dad" || stageProp.name == "gf") // This refers to the player.
{
// Exclude.
continue;
}
}
// Select cans.
if (spawnedCans.contains(stageProp)) {
// Exclude.
continue;
}
// Hacky way of selecting PicoPlayable.picoFade.
if (stageProp.zIndex == (PlayState.instance.currentStage.getBoyfriend().zIndex - 3)) {
// Exclude.
continue;
}
// If not excluded, darken.
stageProp.color = 0xFF111111;
new FlxTimer().start(1/24, (tmr) ->
{
stageProp.color = 0xFF222222;
FlxTween.color(stageProp, 1.4, 0xFF222222, 0xFFFFFFFF);
});
}
}
function blackenStageProps()
{
// Blacken the background (also Darnell and Nene) entirely, then restore it once the gameOverSubState is up.
for (stageProp in PlayState.instance.currentStage.members)
{
// Determine if the stage prop is something that should be excluded from blackening.
if (Std.isOfType(stageProp, StageProp)) {
if (stageProp.name == "bf") // This refers to the player.
{
// Exclude.
continue;
}
}
// Select cans.
if (spawnedCans.contains(stageProp)) {
// Exclude.
continue;
}
// If not excluded, blacken.
stageProp.color = 0xFF000000;
new FlxTimer().start(1.0, (tmr) ->
{
stageProp.color = 0xFFFFFFFF;
});
}
}
function shootNextCan()
{
var can = getNextCanWithState(STATE_ARCING);
if (can != null)
{
can.scriptSet('currentState', STATE_SHOT);
can.scriptCall('playCanShot');
new FlxTimer().start(1/24, function(tmr)
{
darkenStageProps();
});
}
}
function missNextCan()
{
var can = getNextCanWithState(STATE_ARCING);
if (can != null)
{
can.scriptSet('currentState', STATE_IMPACTED);
}
}
function spawnImpactParticle()
{
var impactParticle = FunkinSprite.createSparrow(0, 0, 'CanImpactParticle');
impactParticle.animation.addByPrefix('idle', 'CanImpactParticle0', 24, false);
impactParticle.animation.play('idle');
impactParticle.x = PlayState.instance.currentStage.getBoyfriend().x + 400;
impactParticle.y = PlayState.instance.currentStage.getBoyfriend().y - 200;
PlayState.instance.currentStage.add(impactParticle);
impactParticle.animation.finishCallback = function()
{
impactParticle.kill();
};
}
function onNoteMiss(event:NoteScriptEvent)
{
super.onNoteMiss(event.note);
trace('Missed note on 2hot stage...' + event.note.noteData);
switch (event.note.kind)
{
case "weekend-1-cockgun":
event.healthChange = 0.0; // We cause health loss later.
case "weekend-1-firegun":
gunCocked = false;
event.healthChange = 0.0; // We cause health loss elsewhere.
missNextCan();
takeCanDamage();
case "weekend-1-firegun-hip":
gunCocked = false;
event.healthChange = 0.0; // We cause health loss elsewhere.
missNextCan();
takeCanDamage();
case "weekend-1-firegun-far":
gunCocked = false;
event.healthChange = 0.0; // We cause health loss elsewhere.
missNextCan();
takeCanDamage();
}
}
function takeCanDamage():Void {
trace('Taking damage from can exploding!');
PlayState.instance.health -= HEALTH_LOSS;
// TODO: This is jank as hell! Add some better way to prevent onNoteMiss's normal health loss.
// PlayState.instance.health += 0.0775;
if (PlayState.instance.health <= 0) {
trace('Died to the can! Use special death animation.');
// Reset to standard death animation.
GameOverSubState.musicSuffix = '-pico-explode';
GameOverSubState.blueBallSuffix = '-pico-explode';
blackenStageProps();
}
}
/**
* Replay the cutscene after leaving the song.
*/
function onCreate(event:ScriptEvent):Void
{
super.onCreate(event);
hasPlayedCutscene = false;
}
}