This repository was archived by the owner on Mar 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 438
/
Copy pathPlayer.cs
5471 lines (4632 loc) · 182 KB
/
Player.cs
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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections;
using System.Collections.Generic;
using Monocle;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
namespace Celeste
{
[Tracked]
public class Player : Actor
{
#region Constants
public static ParticleType P_DashA;
public static ParticleType P_DashB;
public static ParticleType P_CassetteFly;
public static ParticleType P_Split;
public static ParticleType P_SummitLandA;
public static ParticleType P_SummitLandB;
public static ParticleType P_SummitLandC;
public const float MaxFall = 160f;
private const float Gravity = 900f;
private const float HalfGravThreshold = 40f;
private const float FastMaxFall = 240f;
private const float FastMaxAccel = 300f;
public const float MaxRun = 90f;
public const float RunAccel = 1000f;
private const float RunReduce = 400f;
private const float AirMult = .65f;
private const float HoldingMaxRun = 70f;
private const float HoldMinTime = .35f;
private const float BounceAutoJumpTime = .1f;
private const float DuckFriction = 500f;
private const int DuckCorrectCheck = 4;
private const float DuckCorrectSlide = 50f;
private const float DodgeSlideSpeedMult = 1.2f;
private const float DuckSuperJumpXMult = 1.25f;
private const float DuckSuperJumpYMult = .5f;
private const float JumpGraceTime = 0.1f;
private const float JumpSpeed = -105f;
private const float JumpHBoost = 40f;
private const float VarJumpTime = .2f;
private const float CeilingVarJumpGrace = .05f;
private const int UpwardCornerCorrection = 4;
private const float WallSpeedRetentionTime = .06f;
private const int WallJumpCheckDist = 3;
private const float WallJumpForceTime = .16f;
private const float WallJumpHSpeed = MaxRun + JumpHBoost;
public const float WallSlideStartMax = 20f;
private const float WallSlideTime = 1.2f;
private const float BounceVarJumpTime = .2f;
private const float BounceSpeed = -140f;
private const float SuperBounceVarJumpTime = .2f;
private const float SuperBounceSpeed = -185f;
private const float SuperJumpSpeed = JumpSpeed;
private const float SuperJumpH = 260f;
private const float SuperWallJumpSpeed = -160f;
private const float SuperWallJumpVarTime = .25f;
private const float SuperWallJumpForceTime = .2f;
private const float SuperWallJumpH = MaxRun + JumpHBoost * 2;
private const float DashSpeed = 240f;
private const float EndDashSpeed = 160f;
private const float EndDashUpMult = .75f;
private const float DashTime = .15f;
private const float DashCooldown = .2f;
private const float DashRefillCooldown = .1f;
private const int DashHJumpThruNudge = 6;
private const int DashCornerCorrection = 4;
private const int DashVFloorSnapDist = 3;
private const float DashAttackTime = .3f;
private const float BoostMoveSpeed = 80f;
public const float BoostTime = .25f;
private const float DuckWindMult = 0f;
private const int WindWallDistance = 3;
private const float ReboundSpeedX = 120f;
private const float ReboundSpeedY = -120f;
private const float ReboundVarJumpTime = .15f;
private const float ReflectBoundSpeed = 220f;
private const float DreamDashSpeed = DashSpeed;
private const int DreamDashEndWiggle = 5;
private const float DreamDashMinTime = .1f;
public const float ClimbMaxStamina = 110;
private const float ClimbUpCost = 100 / 2.2f;
private const float ClimbStillCost = 100 / 10f;
private const float ClimbJumpCost = 110 / 4f;
private const int ClimbCheckDist = 2;
private const int ClimbUpCheckDist = 2;
private const float ClimbNoMoveTime = .1f;
public const float ClimbTiredThreshold = 20f;
private const float ClimbUpSpeed = -45f;
private const float ClimbDownSpeed = 80f;
private const float ClimbSlipSpeed = 30f;
private const float ClimbAccel = 900f;
private const float ClimbGrabYMult = .2f;
private const float ClimbHopY = -120f;
private const float ClimbHopX = 100f;
private const float ClimbHopForceTime = .2f;
private const float ClimbJumpBoostTime = .2f;
private const float ClimbHopNoWindTime = .3f;
private const float LaunchSpeed = 280f;
private const float LaunchCancelThreshold = 220f;
private const float LiftYCap = -130f;
private const float LiftXCap = 250f;
private const float JumpThruAssistSpeed = -40f;
private const float InfiniteDashesTime = 2f;
private const float InfiniteDashesFirstTime = .5f;
private const float FlyPowerFlashTime = .5f;
private const float ThrowRecoil = 80f;
private static readonly Vector2 CarryOffsetTarget = new Vector2(0, -12);
private const float ChaserStateMaxTime = 4f;
public const float WalkSpeed = 64f;
public const int StNormal = 0;
public const int StClimb = 1;
public const int StDash = 2;
public const int StSwim = 3;
public const int StBoost = 4;
public const int StRedDash = 5;
public const int StHitSquash = 6;
public const int StLaunch = 7;
public const int StPickup = 8;
public const int StDreamDash = 9;
public const int StSummitLaunch = 10;
public const int StDummy = 11;
public const int StIntroWalk = 12;
public const int StIntroJump = 13;
public const int StIntroRespawn = 14;
public const int StIntroWakeUp = 15;
public const int StBirdDashTutorial = 16;
public const int StFrozen = 17;
public const int StReflectionFall = 18;
public const int StStarFly = 19;
public const int StTempleFall = 20;
public const int StCassetteFly = 21;
public const int StAttract = 22;
public const string TalkSfx = "player_talk";
#endregion
#region Vars
public Vector2 Speed;
public Facings Facing;
public PlayerSprite Sprite;
public PlayerHair Hair;
public StateMachine StateMachine;
public Vector2 CameraAnchor;
public bool CameraAnchorIgnoreX;
public bool CameraAnchorIgnoreY;
public Vector2 CameraAnchorLerp;
public bool ForceCameraUpdate;
public Leader Leader;
public VertexLight Light;
public int Dashes;
public float Stamina = ClimbMaxStamina;
public bool StrawberriesBlocked;
public Vector2 PreviousPosition;
public bool DummyAutoAnimate = true;
public Vector2 ForceStrongWindHair;
public Vector2? OverrideDashDirection;
public bool FlipInReflection = false;
public bool JustRespawned; // True if the player hasn't moved since respawning
public bool Dead { get; private set; }
private Level level;
private Collision onCollideH;
private Collision onCollideV;
private bool onGround;
private bool wasOnGround;
private int moveX;
private bool flash;
private bool wasDucking;
private float idleTimer;
private static Chooser<string> idleColdOptions = new Chooser<string>().Add("idleA", 5f).Add("idleB", 3f).Add("idleC", 1f);
private static Chooser<string> idleNoBackpackOptions = new Chooser<string>().Add("idleA", 1f).Add("idleB", 3f).Add("idleC", 3f);
private static Chooser<string> idleWarmOptions = new Chooser<string>().Add("idleA", 5f).Add("idleB", 3f);
public int StrawberryCollectIndex = 0;
public float StrawberryCollectResetTimer = 0f;
private Hitbox hurtbox;
private float jumpGraceTimer;
public bool AutoJump;
public float AutoJumpTimer;
private float varJumpSpeed;
private float varJumpTimer;
private int forceMoveX;
private float forceMoveXTimer;
private int hopWaitX; // If you climb hop onto a moving solid, snap to beside it until you get above it
private float hopWaitXSpeed;
private Vector2 lastAim;
private float dashCooldownTimer;
private float dashRefillCooldownTimer;
public Vector2 DashDir;
private float wallSlideTimer = WallSlideTime;
private int wallSlideDir;
private float climbNoMoveTimer;
private Vector2 carryOffset;
private Vector2 deadOffset;
private float introEase;
private float wallSpeedRetentionTimer; // If you hit a wall, start this timer. If coast is clear within this timer, retain h-speed
private float wallSpeedRetained;
private int wallBoostDir;
private float wallBoostTimer; // If you climb jump and then do a sideways input within this timer, switch to wall jump
private float maxFall;
private float dashAttackTimer;
private List<ChaserState> chaserStates;
private bool wasTired;
private HashSet<Trigger> triggersInside;
private float highestAirY;
private bool dashStartedOnGround;
private bool fastJump;
private int lastClimbMove;
private float noWindTimer;
private float dreamDashCanEndTimer;
private Solid climbHopSolid;
private Vector2 climbHopSolidPosition;
private SoundSource wallSlideSfx;
private SoundSource swimSurfaceLoopSfx;
private float playFootstepOnLand;
private float minHoldTimer;
public Booster CurrentBooster;
private Booster lastBooster;
private bool calledDashEvents;
private int lastDashes;
private Sprite sweatSprite;
private int startHairCount;
private bool launched;
private float launchedTimer;
private float dashTrailTimer;
private List<ChaserStateSound> activeSounds = new List<ChaserStateSound>();
private FMOD.Studio.EventInstance idleSfx;
private readonly Hitbox normalHitbox = new Hitbox(8, 11, -4, -11);
private readonly Hitbox duckHitbox = new Hitbox(8, 6, -4, -6);
private readonly Hitbox normalHurtbox = new Hitbox(8, 9, -4, -11);
private readonly Hitbox duckHurtbox = new Hitbox(8, 4, -4, -6);
private readonly Hitbox starFlyHitbox = new Hitbox(8, 8, -4, -10);
private readonly Hitbox starFlyHurtbox = new Hitbox(6, 6, -3, -9);
private Vector2 normalLightOffset = new Vector2(0, -8);
private Vector2 duckingLightOffset = new Vector2(0, -3);
private List<Entity> temp = new List<Entity>();
// hair
public static readonly Color NormalHairColor = Calc.HexToColor("AC3232");
public static readonly Color FlyPowerHairColor = Calc.HexToColor("F2EB6D");
public static readonly Color UsedHairColor = Calc.HexToColor("44B7FF");
public static readonly Color FlashHairColor = Color.White;
public static readonly Color TwoDashesHairColor = Calc.HexToColor("ff6def");
private float hairFlashTimer;
public Color? OverrideHairColor;
private Vector2 windDirection;
private float windTimeout;
private float windHairTimer;
// level-start intro
public enum IntroTypes { Transition, Respawn, WalkInRight, WalkInLeft, Jump, WakeUp, Fall, TempleMirrorVoid, None }
public IntroTypes IntroType;
private MirrorReflection reflection;
#endregion
#region constructor / added / removed
public Player(Vector2 position, PlayerSpriteMode spriteMode)
: base(new Vector2((int)position.X, (int)position.Y))
{
Depth = Depths.Player;
Tag = Tags.Persistent;
// sprite
Sprite = new PlayerSprite(spriteMode);
Add(Hair = new PlayerHair(Sprite));
Add(Sprite);
Hair.Color = NormalHairColor;
startHairCount = Sprite.HairCount;
// sweat sprite
sweatSprite = GFX.SpriteBank.Create("player_sweat");
Add(sweatSprite);
// physics
Collider = normalHitbox;
hurtbox = normalHurtbox;
onCollideH = OnCollideH;
onCollideV = OnCollideV;
// states
StateMachine = new StateMachine(23);
StateMachine.SetCallbacks(StNormal, NormalUpdate, null, NormalBegin, NormalEnd);
StateMachine.SetCallbacks(StClimb, ClimbUpdate, null, ClimbBegin, ClimbEnd);
StateMachine.SetCallbacks(StDash, DashUpdate, DashCoroutine, DashBegin, DashEnd);
StateMachine.SetCallbacks(StSwim, SwimUpdate, null, SwimBegin, null);
StateMachine.SetCallbacks(StBoost, BoostUpdate, BoostCoroutine, BoostBegin, BoostEnd);
StateMachine.SetCallbacks(StRedDash, RedDashUpdate, RedDashCoroutine, RedDashBegin, RedDashEnd);
StateMachine.SetCallbacks(StHitSquash, HitSquashUpdate, null, HitSquashBegin, null);
StateMachine.SetCallbacks(StLaunch, LaunchUpdate, null, LaunchBegin, null);
StateMachine.SetCallbacks(StPickup, null, PickupCoroutine, null, null);
StateMachine.SetCallbacks(StDreamDash, DreamDashUpdate, null, DreamDashBegin, DreamDashEnd);
StateMachine.SetCallbacks(StSummitLaunch, SummitLaunchUpdate, null, SummitLaunchBegin, null);
StateMachine.SetCallbacks(StDummy, DummyUpdate, null, DummyBegin, null);
StateMachine.SetCallbacks(StIntroWalk, null, IntroWalkCoroutine, null, null);
StateMachine.SetCallbacks(StIntroJump, null, IntroJumpCoroutine, null, null);
StateMachine.SetCallbacks(StIntroRespawn, null, null, IntroRespawnBegin, IntroRespawnEnd);
StateMachine.SetCallbacks(StIntroWakeUp, null, IntroWakeUpCoroutine, null, null);
StateMachine.SetCallbacks(StTempleFall, TempleFallUpdate, TempleFallCoroutine);
StateMachine.SetCallbacks(StReflectionFall, ReflectionFallUpdate, ReflectionFallCoroutine, ReflectionFallBegin, ReflectionFallEnd);
StateMachine.SetCallbacks(StBirdDashTutorial, BirdDashTutorialUpdate, BirdDashTutorialCoroutine, BirdDashTutorialBegin, null);
StateMachine.SetCallbacks(StFrozen, FrozenUpdate, null, null, null);
StateMachine.SetCallbacks(StStarFly, StarFlyUpdate, StarFlyCoroutine, StarFlyBegin, StarFlyEnd);
StateMachine.SetCallbacks(StCassetteFly, CassetteFlyUpdate, CassetteFlyCoroutine, CassetteFlyBegin, CassetteFlyEnd);
StateMachine.SetCallbacks(StAttract, AttractUpdate, null, AttractBegin, AttractEnd);
Add(StateMachine);
// other stuff
Add(Leader = new Leader(new Vector2(0, -8)));
lastAim = Vector2.UnitX;
Facing = Facings.Right;
chaserStates = new List<ChaserState>();
triggersInside = new HashSet<Trigger>();
Add(Light = new VertexLight(normalLightOffset, Color.White, 1f, 32, 64));
Add(new WaterInteraction(() => { return StateMachine.State == StDash || StateMachine.State == StReflectionFall; }));
//Wind
Add(new WindMover(WindMove));
Add(wallSlideSfx = new SoundSource());
Add(swimSurfaceLoopSfx = new SoundSource());
Sprite.OnFrameChange = (anim) =>
{
if (Scene != null && !Dead)
{
// footsteps
var frame = Sprite.CurrentAnimationFrame;
if ((anim.Equals(PlayerSprite.RunCarry) && (frame == 0 || frame == 6)) ||
(anim.Equals(PlayerSprite.RunFast) && (frame == 0 || frame == 6)) ||
(anim.Equals(PlayerSprite.RunSlow) && (frame == 0 || frame == 6)) ||
(anim.Equals(PlayerSprite.Walk) && (frame == 0 || frame == 6)) ||
(anim.Equals(PlayerSprite.RunStumble) && frame == 6) ||
(anim.Equals(PlayerSprite.Flip) && frame == 4) ||
(anim.Equals(PlayerSprite.RunWind) && (frame == 0 || frame == 6)) ||
(anim.Equals("idleC") && Sprite.Mode == PlayerSpriteMode.MadelineNoBackpack && (frame == 3 || frame == 6 || frame == 8 || frame == 11)) ||
(anim.Equals("carryTheoWalk") && (frame == 0 || frame == 6)))
{
var landed = SurfaceIndex.GetPlatformByPriority(CollideAll<Platform>(Position + Vector2.UnitY, temp));
if (landed != null)
Play(Sfxs.char_mad_footstep, SurfaceIndex.Param, landed.GetStepSoundIndex(this));
}
// climbing (holds)
else if ((anim.Equals(PlayerSprite.ClimbUp) && (frame == 5)) ||
(anim.Equals(PlayerSprite.ClimbDown) && (frame == 5)))
{
var holding = SurfaceIndex.GetPlatformByPriority(CollideAll<Solid>(Center + Vector2.UnitX * (int)Facing, temp));
if (holding != null)
Play(Sfxs.char_mad_handhold, SurfaceIndex.Param, holding.GetWallSoundIndex(this, (int)Facing));
}
else if (anim.Equals("wakeUp") && frame == 19)
Play(Sfxs.char_mad_campfire_stand);
else if (anim.Equals("sitDown") && frame == 12)
Play(Sfxs.char_mad_summit_sit);
else if (anim.Equals("push") && (frame == 8 || frame == 15))
Dust.BurstFG(Position + new Vector2(-(int)Facing * 5, -1), new Vector2(-(int)Facing, -0.5f).Angle(), 1, 0);
}
};
Sprite.OnLastFrame = (anim) =>
{
if (Scene != null && !Dead && Sprite.CurrentAnimationID == "idle" && !level.InCutscene && idleTimer > 3f)
{
if (Calc.Random.Chance(0.2f))
{
var next = "";
if (Sprite.Mode == PlayerSpriteMode.Madeline)
next = (level.CoreMode == Session.CoreModes.Hot ? idleWarmOptions : idleColdOptions).Choose();
else
next = idleNoBackpackOptions.Choose();
if (!string.IsNullOrEmpty(next))
{
Sprite.Play(next);
if (Sprite.Mode == PlayerSpriteMode.Madeline)
{
if (next == "idleB")
idleSfx = Play(Sfxs.char_mad_idle_scratch);
else if (next == "idleC")
idleSfx = Play(Sfxs.char_mad_idle_sneeze);
}
else if (next == "idleA")
idleSfx = Play(Sfxs.char_mad_idle_crackknuckles);
}
}
}
};
// cancel special idle sounds if the anim changed
Sprite.OnChange = (last, next) =>
{
if ((last == "idleB" || last == "idleC") && next != null && !next.StartsWith("idle") && idleSfx != null)
Audio.Stop(idleSfx);
};
Add(reflection = new MirrorReflection());
}
public override void Added(Scene scene)
{
base.Added(scene);
level = SceneAs<Level>();
lastDashes = Dashes = MaxDashes;
if (X > level.Bounds.Center.X && IntroType != IntroTypes.None)
Facing = Facings.Left;
switch (IntroType)
{
case IntroTypes.Respawn:
StateMachine.State = StIntroRespawn;
JustRespawned = true;
break;
case IntroTypes.WalkInRight:
IntroWalkDirection = Facings.Right;
StateMachine.State = StIntroWalk;
break;
case IntroTypes.WalkInLeft:
IntroWalkDirection = Facings.Left;
StateMachine.State = StIntroWalk;
break;
case IntroTypes.Jump:
StateMachine.State = StIntroJump;
break;
case IntroTypes.WakeUp:
Sprite.Play("asleep");
Facing = Facings.Right;
StateMachine.State = StIntroWakeUp;
break;
case IntroTypes.None:
StateMachine.State = StNormal;
break;
case IntroTypes.Fall:
StateMachine.State = StReflectionFall;
break;
case IntroTypes.TempleMirrorVoid:
StartTempleMirrorVoidSleep();
break;
}
IntroType = IntroTypes.Transition;
StartHair();
PreviousPosition = Position;
}
public void StartTempleMirrorVoidSleep()
{
Sprite.Play("asleep");
Facing = Facings.Right;
StateMachine.State = StDummy;
StateMachine.Locked = true;
DummyAutoAnimate = false;
DummyGravity = false;
}
public override void Removed(Scene scene)
{
base.Removed(scene);
level = null;
Audio.Stop(conveyorLoopSfx);
foreach (var trigger in triggersInside)
{
trigger.Triggered = false;
trigger.OnLeave(this);
}
}
public override void SceneEnd(Scene scene)
{
base.SceneEnd(scene);
Audio.Stop(conveyorLoopSfx);
}
#endregion
#region Rendering
public override void Render()
{
var was = Sprite.RenderPosition;
Sprite.RenderPosition = Sprite.RenderPosition.Floor();
if (StateMachine.State == StIntroRespawn)
{
DeathEffect.Draw(Center + deadOffset, Hair.Color, introEase);
}
else
{
if (StateMachine.State != StStarFly)
{
if (IsTired && flash)
Sprite.Color = Color.Red;
else
Sprite.Color = Color.White;
}
// set up scale
if (reflection.IsRendering && FlipInReflection)
{
Facing = (Facings)(-(int)Facing);
Hair.Facing = Facing;
}
Sprite.Scale.X *= (int)Facing;
// sweat scale
if (sweatSprite.LastAnimationID == "idle")
sweatSprite.Scale = Sprite.Scale;
else
{
sweatSprite.Scale.Y = Sprite.Scale.Y;
sweatSprite.Scale.X = Math.Abs(Sprite.Scale.X) * Math.Sign(sweatSprite.Scale.X);
}
// draw
base.Render();
// star fly transform
if (Sprite.CurrentAnimationID == PlayerSprite.StartStarFly)
{
var p = (Sprite.CurrentAnimationFrame / (float)Sprite.CurrentAnimationTotalFrames);
var white = GFX.Game.GetAtlasSubtexturesAt("characters/player/startStarFlyWhite", Sprite.CurrentAnimationFrame);
white.Draw(Sprite.RenderPosition, Sprite.Origin, starFlyColor * p, Sprite.Scale, Sprite.Rotation, 0);
}
// revert scale
Sprite.Scale.X *= (int)Facing;
if (reflection.IsRendering && FlipInReflection)
{
Facing = (Facings)(-(int)Facing);
Hair.Facing = Facing;
}
}
Sprite.RenderPosition = was;
}
public override void DebugRender(Camera camera)
{
base.DebugRender(camera);
{
Collider was = Collider;
Collider = hurtbox;
Draw.HollowRect(Collider, Color.Lime);
Collider = was;
}
}
#endregion
#region Updating
public override void Update()
{
//Infinite Stamina variant
if (SaveData.Instance.AssistMode && SaveData.Instance.Assists.InfiniteStamina)
Stamina = ClimbMaxStamina;
PreviousPosition = Position;
//Vars
{
// strawb reset timer
StrawberryCollectResetTimer -= Engine.DeltaTime;
if (StrawberryCollectResetTimer <= 0)
StrawberryCollectIndex = 0;
// idle timer
idleTimer += Engine.DeltaTime;
if (level != null && level.InCutscene)
idleTimer = -5;
else if (Speed.X != 0 || Speed.Y != 0)
idleTimer = 0;
//Underwater music
if (!Dead)
Audio.MusicUnderwater = UnderwaterMusicCheck();
//Just respawned
if (JustRespawned && Speed != Vector2.Zero)
JustRespawned = false;
//Get ground
if (StateMachine.State == StDreamDash)
onGround = OnSafeGround = false;
else if (Speed.Y >= 0)
{
Platform first = CollideFirst<Solid>(Position + Vector2.UnitY);
if (first == null)
first = CollideFirstOutside<JumpThru>(Position + Vector2.UnitY);
if (first != null)
{
onGround = true;
OnSafeGround = first.Safe;
}
else
onGround = OnSafeGround = false;
}
else
onGround = OnSafeGround = false;
if (StateMachine.State == StSwim)
OnSafeGround = true;
//Safe Ground Blocked?
if (OnSafeGround)
{
foreach (SafeGroundBlocker blocker in Scene.Tracker.GetComponents<SafeGroundBlocker>())
{
if (blocker.Check(this))
{
OnSafeGround = false;
break;
}
}
}
playFootstepOnLand -= Engine.DeltaTime;
//Highest Air Y
if (onGround)
highestAirY = Y;
else
highestAirY = Math.Min(Y, highestAirY);
//Flashing
if (Scene.OnInterval(.05f))
flash = !flash;
//Wall Slide
if (wallSlideDir != 0)
{
wallSlideTimer = Math.Max(wallSlideTimer - Engine.DeltaTime, 0);
wallSlideDir = 0;
}
//Wall Boost
if (wallBoostTimer > 0)
{
wallBoostTimer -= Engine.DeltaTime;
if (moveX == wallBoostDir)
{
Speed.X = WallJumpHSpeed * moveX;
Stamina += ClimbJumpCost;
wallBoostTimer = 0;
sweatSprite.Play("idle");
}
}
//After Dash
if (onGround && StateMachine.State != StClimb)
{
AutoJump = false;
Stamina = ClimbMaxStamina;
wallSlideTimer = WallSlideTime;
}
//Dash Attack
if (dashAttackTimer > 0)
dashAttackTimer -= Engine.DeltaTime;
//Jump Grace
if (onGround)
{
dreamJump = false;
jumpGraceTimer = JumpGraceTime;
}
else if (jumpGraceTimer > 0)
jumpGraceTimer -= Engine.DeltaTime;
//Dashes
{
if (dashCooldownTimer > 0)
dashCooldownTimer -= Engine.DeltaTime;
if (dashRefillCooldownTimer > 0)
dashRefillCooldownTimer -= Engine.DeltaTime;
else if (SaveData.Instance.AssistMode && SaveData.Instance.Assists.DashMode == Assists.DashModes.Infinite && !level.InCutscene)
RefillDash();
else if (!Inventory.NoRefills)
{
if (StateMachine.State == StSwim)
RefillDash();
else if (onGround)
if (CollideCheck<Solid, NegaBlock>(Position + Vector2.UnitY) || CollideCheckOutside<JumpThru>(Position + Vector2.UnitY))
if (!CollideCheck<Spikes>(Position) || (SaveData.Instance.AssistMode && SaveData.Instance.Assists.Invincible))
RefillDash();
}
}
//Var Jump
if (varJumpTimer > 0)
varJumpTimer -= Engine.DeltaTime;
//Auto Jump
if (AutoJumpTimer > 0)
{
if (AutoJump)
{
AutoJumpTimer -= Engine.DeltaTime;
if (AutoJumpTimer <= 0)
AutoJump = false;
}
else
AutoJumpTimer = 0;
}
//Force Move X
if (forceMoveXTimer > 0)
{
forceMoveXTimer -= Engine.DeltaTime;
moveX = forceMoveX;
}
else
{
moveX = Input.MoveX.Value;
climbHopSolid = null;
}
//Climb Hop Solid Movement
if (climbHopSolid != null && !climbHopSolid.Collidable)
climbHopSolid = null;
else if (climbHopSolid != null && climbHopSolid.Position != climbHopSolidPosition)
{
var move = climbHopSolid.Position - climbHopSolidPosition;
climbHopSolidPosition = climbHopSolid.Position;
MoveHExact((int)move.X);
MoveVExact((int)move.Y);
}
//Wind
if (noWindTimer > 0)
noWindTimer -= Engine.DeltaTime;
//Facing
if (moveX != 0 && InControl
&& StateMachine.State != StClimb && StateMachine.State != StPickup && StateMachine.State != StRedDash && StateMachine.State != StHitSquash)
{
var to = (Facings)moveX;
if (to != Facing && Ducking)
Sprite.Scale = new Vector2(0.8f, 1.2f);
Facing = to;
}
//Aiming
lastAim = Input.GetAimVector(Facing);
//Wall Speed Retention
if (wallSpeedRetentionTimer > 0)
{
if (Math.Sign(Speed.X) == -Math.Sign(wallSpeedRetained))
wallSpeedRetentionTimer = 0;
else if (!CollideCheck<Solid>(Position + Vector2.UnitX * Math.Sign(wallSpeedRetained)))
{
Speed.X = wallSpeedRetained;
wallSpeedRetentionTimer = 0;
}
else
wallSpeedRetentionTimer -= Engine.DeltaTime;
}
//Hop Wait X
if (hopWaitX != 0)
{
if (Math.Sign(Speed.X) == -hopWaitX || Speed.Y > 0)
hopWaitX = 0;
else if (!CollideCheck<Solid>(Position + Vector2.UnitX * hopWaitX))
{
Speed.X = hopWaitXSpeed;
hopWaitX = 0;
}
}
// Wind Timeout
if (windTimeout > 0)
windTimeout -= Engine.DeltaTime;
// Hair
{
var windDir = windDirection;
if (ForceStrongWindHair.Length() > 0)
windDir = ForceStrongWindHair;
if (windTimeout > 0 && windDir.X != 0)
{
windHairTimer += Engine.DeltaTime * 8f;
Hair.StepPerSegment = new Vector2(windDir.X * 5f, (float)Math.Sin(windHairTimer));
Hair.StepInFacingPerSegment = 0f;
Hair.StepApproach = 128f;
Hair.StepYSinePerSegment = 0;
}
else if (Dashes > 1)
{
Hair.StepPerSegment = new Vector2((float)Math.Sin(Scene.TimeActive * 2) * 0.7f - (int)Facing * 3, (float)Math.Sin(Scene.TimeActive * 1f));
Hair.StepInFacingPerSegment = 0f;
Hair.StepApproach = 90f;
Hair.StepYSinePerSegment = 1f;
Hair.StepPerSegment.Y += windDir.Y * 2f;
}
else
{
Hair.StepPerSegment = new Vector2(0, 2f);
Hair.StepInFacingPerSegment = 0.5f;
Hair.StepApproach = 64f;
Hair.StepYSinePerSegment = 0;
Hair.StepPerSegment.Y += windDir.Y * 0.5f;
}
}
if (StateMachine.State == StRedDash)
Sprite.HairCount = 1;
else if (StateMachine.State != StStarFly)
Sprite.HairCount = (Dashes > 1 ? 5 : startHairCount);
//Min Hold Time
if (minHoldTimer > 0)
minHoldTimer -= Engine.DeltaTime;
//Launch Particles
if (launched)
{
var sq = Speed.LengthSquared();
if (sq < LaunchedMinSpeedSq)
launched = false;
else
{
var was = launchedTimer;
launchedTimer += Engine.DeltaTime;
if (launchedTimer >= .5f)
{
launched = false;
launchedTimer = 0;
}
else if (Calc.OnInterval(launchedTimer, was, .15f))
level.Add(Engine.Pooler.Create<SpeedRing>().Init(Center, Speed.Angle(), Color.White));
}
}
else
launchedTimer = 0;
}
if (IsTired)
{
Input.Rumble(RumbleStrength.Light, RumbleLength.Short);
if (!wasTired)
{
wasTired = true;
}
}
else
wasTired = false;
base.Update();
//Light Offset
if (Ducking)
Light.Position = duckingLightOffset;
else
Light.Position = normalLightOffset;
//Jump Thru Assist
if (!onGround && Speed.Y <= 0 && (StateMachine.State != StClimb || lastClimbMove == -1) && CollideCheck<JumpThru>() && !JumpThruBoostBlockedCheck())
MoveV(JumpThruAssistSpeed * Engine.DeltaTime);
//Dash Floor Snapping
if (!onGround && DashAttacking && DashDir.Y == 0)
{
if (CollideCheck<Solid>(Position + Vector2.UnitY * DashVFloorSnapDist) || CollideCheckOutside<JumpThru>(Position + Vector2.UnitY * DashVFloorSnapDist))
MoveVExact(DashVFloorSnapDist);
}
//Falling unducking
if (Speed.Y > 0 && CanUnDuck && Collider != starFlyHitbox && !onGround)
Ducking = false;
//Physics
if (StateMachine.State != StDreamDash && StateMachine.State != StAttract)
MoveH(Speed.X * Engine.DeltaTime, onCollideH);
if (StateMachine.State != StDreamDash && StateMachine.State != StAttract)
MoveV(Speed.Y * Engine.DeltaTime, onCollideV);
//Swimming
if (StateMachine.State == StSwim)
{
//Stay at water surface
if (Speed.Y < 0 && Speed.Y >= SwimMaxRise)
{
while (!SwimCheck())
{
Speed.Y = 0;
if (MoveVExact(1))
break;
}
}
}
else if (StateMachine.State == StNormal && SwimCheck())
StateMachine.State = StSwim;
else if (StateMachine.State == StClimb && SwimCheck())
{
var water = CollideFirst<Water>(Position);
if (water != null && Center.Y < water.Center.Y)
{
while (SwimCheck())
if (MoveVExact(-1))
break;
if (SwimCheck())
StateMachine.State = StSwim;
}
else
StateMachine.State = StSwim;
}
// wall slide SFX
{
var isSliding = Sprite.CurrentAnimationID != null && Sprite.CurrentAnimationID.Equals(PlayerSprite.WallSlide) && Speed.Y > 0;
if (isSliding)
{
if (!wallSlideSfx.Playing)
Loop(wallSlideSfx, Sfxs.char_mad_wallslide);
var platform = SurfaceIndex.GetPlatformByPriority(CollideAll<Solid>(Center + Vector2.UnitX * (int)Facing, temp));
if (platform != null)
wallSlideSfx.Param(SurfaceIndex.Param, platform.GetWallSoundIndex(this, (int)Facing));
}
else
Stop(wallSlideSfx);
}
// update sprite
UpdateSprite();
//Carry held item
UpdateCarry();
//Triggers
if (StateMachine.State != StReflectionFall)
{
foreach (Trigger trigger in Scene.Tracker.GetEntities<Trigger>())
{
if (CollideCheck(trigger))
{
if (!trigger.Triggered)
{
trigger.Triggered = true;
triggersInside.Add(trigger);