-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGameMultiplayerPrairieKing.cs
More file actions
1881 lines (1611 loc) · 56.6 KB
/
GameMultiplayerPrairieKing.cs
File metadata and controls
1881 lines (1611 loc) · 56.6 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
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 Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MultiplayerPrairieKing;
using MultiplayerPrairieKing.Components;
using MultiplayerPrairieKing.Entities;
using MultiplayerPrairieKing.Entities.Enemies;
using MultiplayerPrairieKing.Utility;
using StardewModdingAPI;
using StardewValley;
using StardewValley.GameData;
using StardewValley.Minigames;
using StardewValley.SDKs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text.Json;
using System.Xml.Serialization;
using static MultiplayerPrairieKing.Utility.Serialization;
namespace MultiPlayerPrairie
{
[XmlInclude(typeof(AbigailGame.JOTPKProgress))]
[InstanceStatics]
public class GameMultiplayerPrairieKing : IMinigame
{
public delegate void behaviorAfterMotionPause();
public void NETskipLevel(int toLevel = -1)
{
//Cant skip level as non host, i think
if (!IsHost)
{
return;
}
foreach (Enemy monster in monsters)
{
PK_EnemyKilled enemyKilled = new()
{
id = monster.id
};
modInstance.SyncMessage(enemyKilled);
}
monsters.Clear();
OnCompleteLevel(toLevel);
PK_CompleteLevel completeLevel = new()
{
toLevel = toLevel
};
modInstance.SyncMessage(completeLevel);
}
public void NETspawnBullet(bool friendly, Point position, Point motion, int damage)
{
Bullet bullet = new(this, friendly, true, position, motion, damage);
bullets.Add(bullet);
//NET Spawn Bullet
PK_BulletSpawn mBullet = new()
{
id = bullet.id,
position = position,
motion = motion,
damage = damage,
isFriendly = friendly
};
modInstance.SyncMessage(mBullet);
}
public void NETspawnBullet(bool friendly, Point position, int direction, int damage)
{
Bullet bullet = new(this, friendly, true, position, direction, damage);
bullets.Add(bullet);
//NET Spawn Bullet
PK_BulletSpawn mBullet = new()
{
id = bullet.id,
position = position,
motion = bullet.motion,
damage = damage,
isFriendly = friendly
};
modInstance.SyncMessage(mBullet);
}
public void NETmovePlayer(Vector2 pos)
{
PK_PlayerMove message = new()
{
playerId = modInstance.playerID.Value,
position = pos,
id = Game1.player.UniqueMultiplayerID,
shootingDirections = player.shootingDirections,
movementDirections = player.movementDirections
};
modInstance.SyncMessage(message);
}
public void NETspawnPowerup(POWERUP_TYPE type, Point position, int duration = 7500)
{
Powerup powerup = new(this,type,position,duration);
powerups.Add(powerup);
PK_PowerupSpawn mPowerup = new()
{
id = powerup.id,
position = position,
which = (int)type,
duration = duration
};
modInstance.SyncMessage(mPowerup);
modInstance.Monitor.Log("spawning " + mPowerup.which.ToString() + " with id " + mPowerup.id, LogLevel.Debug);
}
public ModMultiPlayerPrairieKing modInstance;
public UI ui;
public Cutscene Cutscene { get; set; }
//Save state that was transmitted by the host to start this match. Seperate from the own savestate that is saved in the mod instance
public SaveState multiplayerSaveState;
public bool IsHost { get; set; }
public const int mapWidth = 16;
public const int mapHeight = 16;
public const int pixelZoom = 3;
public const int baseTileSize = 16;
public const int playerMotionDelay = 100;
public const int deathDelay = 3000;
public static Texture2D shopBubbleTexture;
public DIFFICULTY difficulty = DIFFICULTY.NORMAL;
public Dictionary<long, BasePlayer> playerList = new();
public Player player;
public int newGamePlus;
public const int waveDuration = 80000;
public const int betweenWaveDuration = 5000;
public List<Enemy> monsters = new();
public Rectangle merchantBox;
public Rectangle noPickUpBox;
public int motionPause;
public int lives = 3;
public int Coins { get; set; }
int score;
public List<Bullet> bullets = new();
public Map map;
Map nextMap;
List<SpawnTask>[] spawnQueue = new List<SpawnTask>[4];
public static Vector2 topLeftScreenCoordinate;
public float cactusDanceTimer;
public behaviorAfterMotionPause behaviorAfterPause;
List<Vector2> monsterChances = new()
{
new Vector2(0.014f, 0.4f),
Vector2.Zero,
Vector2.Zero,
Vector2.Zero,
Vector2.Zero,
Vector2.Zero,
Vector2.Zero
};
public Rectangle shoppingCarpetNoPickup;
public Dictionary<POWERUP_TYPE, int> activePowerups = new();
public List<Powerup> powerups = new();
public List<TemporaryAnimatedSprite> temporarySprites = new();
public MAP_TYPE world = MAP_TYPE.desert;
public int gamerestartTimer;
public int waveTimer = 80000;
public int betweenWaveTimer = 5000;
public int currentLevel;
public int monsterConfusionTimer;
public int zombieModeTimer;
int shoppingTimer;
public int newMapPosition;
public int screenFlash;
int gopherTrainPosition;
bool shopping;
public bool gopherRunning;
bool merchantArriving;
bool merchantShopOpen;
bool waitingForPlayerToMoveDownAMap;
public bool scrollingMap;
bool hasGopherAppeared;
public bool shootoutLevel;
public bool gopherTrain;
bool playerJumped;
public bool endCutscene;
public bool gameOver;
readonly Dictionary<Rectangle, ITEM_TYPE> storeItems = new();
public bool quit;
public bool died;
public Rectangle gopherBox;
Point gopherMotion;
//Music
public static ICue overworldSong;
public static ICue outlawSong;
public static ICue zombieSong;
//Input States
readonly HashSet<GameKeys> _buttonHeldState = new();
readonly Dictionary<GameKeys, int> _buttonHeldFrames = new();
public static int TileSize => 48;
public bool IsEnterButtonAssignmentFlipped;
public GameMultiplayerPrairieKing(ModMultiPlayerPrairieKing mod, bool isHost)
{
ui = new(this);
Cutscene = new(this);
for (int k = 0; k < 11; k++)
{
_buttonHeldFrames[(GameKeys)k] = 0;
}
this.modInstance = mod;
this.IsHost = isHost;
Reset(gameLooped: false, gameRestarted: false);
//Access SDKHelper by reflection. Hacky but otherwise controller controls are fucked
Type type = typeof(Program);
FieldInfo info = type.GetField("_sdk", BindingFlags.NonPublic | BindingFlags.Static);
SDKHelper sdkHelper = (SDKHelper)info.GetValue(null);
IsEnterButtonAssignmentFlipped = sdkHelper.IsEnterButtonAssignmentFlipped;
}
public bool LoadGame()
{
SaveState saveState;
if (IsHost) saveState = modInstance.GetSaveState();
else saveState = multiplayerSaveState;
if (saveState == null)
{
modInstance.Monitor.Log("Couldnt Load PrairieKing saveState", LogLevel.Debug);
return false;
}
foreach (PlayerSaveState playerSaveState in saveState.playerSaveStates)
{
modInstance.Monitor.Log("Loading player: " + playerSaveState.PlayerID, LogLevel.Debug);
BasePlayer referencedPlayer = playerList[playerSaveState.PlayerID];
referencedPlayer.ammoLevel = playerSaveState.AmmoLevel;
referencedPlayer.runSpeedLevel = playerSaveState.RunSpeedLevel;
referencedPlayer.fireSpeedLevel = playerSaveState.FireSpeedLevel;
referencedPlayer.bulletDamage = playerSaveState.BulletDamage;
referencedPlayer.spreadPistol = playerSaveState.SpreadPistol;
if (playerSaveState.HeldItem != -100)
{
referencedPlayer.heldItem = new Powerup(this, (POWERUP_TYPE)playerSaveState.HeldItem, Point.Zero, 9999);
}
}
Coins = saveState.Coins;
died = saveState.Died;
lives = saveState.Lives;
score = saveState.Score;
newGamePlus = saveState.WhichRound;
currentLevel = saveState.WhichWave;
waveTimer = saveState.WaveTimer;
world = (MAP_TYPE)saveState.World;
monsterChances = ConvertFromSVector2(saveState.MonsterChances);
ApplyLevelSpecificStates();
if (shootoutLevel)
{
player.position = new Vector2(8 * TileSize, 3 * TileSize);
}
modInstance.Monitor.Log("Loaded gamestate", LogLevel.Info);
return true;
}
public void SaveGame()
{
SaveState saveState = new();
saveState.playerSaveStates = new();
foreach(long playerID in playerList.Keys)
{
BasePlayer bp = playerList[playerID];
PlayerSaveState playerSaveState = new()
{
PlayerID = playerID,
PlayerName = bp.playerName,
AmmoLevel = bp.ammoLevel,
RunSpeedLevel = bp.runSpeedLevel,
FireSpeedLevel = bp.fireSpeedLevel,
BulletDamage = bp.bulletDamage,
SpreadPistol = bp.spreadPistol
};
if (bp.heldItem == null)
{
playerSaveState.HeldItem = -100;
}
else
{
playerSaveState.HeldItem = (int)bp.heldItem.type;
}
modInstance.Monitor.Log("Saving player: " + playerSaveState.PlayerID, LogLevel.Debug);
saveState.playerSaveStates.Add(playerSaveState);
}
saveState.Coins = Coins;
saveState.Died = died;
saveState.Lives = lives;
saveState.Score = score;
saveState.WhichRound = newGamePlus;
saveState.WhichWave = currentLevel;
saveState.WaveTimer = waveTimer;
saveState.World = (int)world;
saveState.MonsterChances = ConvertToSVector2(monsterChances);
modInstance.UpdateSaveState(saveState);
}
public void InstantiatePlayers()
{
//Let players start in a square
List<Vector2> startPositions = new()
{
new Vector2(352f, 352f) + new Vector2(0,0),
new Vector2(352f, 352f) + new Vector2(64,0),
new Vector2(352f, 352f) + new Vector2(0,64),
new Vector2(352f, 352f) + new Vector2(64,64),
};
playerList.Clear();
for(int i=0; i<modInstance.playerList.Value.Count; i++)
{
long pid = modInstance.playerList.Value[i];
BasePlayer p;
if (pid == modInstance.playerID.Value)
{
player = new Player(this);
p = player;
}
else
{
p = new PlayerSlave(this);
}
p.textureBase = new Vector2(i * 64, 0);
p.position = startPositions[i];
p.playerName = Game1.getFarmer(pid).Name;
modInstance.Monitor.Log("playerName set to: " + p.playerName, LogLevel.Info);
playerList.Add(pid, p);
}
//NET Player Move
NETmovePlayer(player.position);
player.boundingBox.X = (int)player.position.X + TileSize / 4;
player.boundingBox.Y = (int)player.position.Y + TileSize / 4;
player.boundingBox.Width = TileSize / 2;
player.boundingBox.Height = TileSize / 2;
if (LoadGame())
{
map = MapLoader.GetMap(currentLevel);
}
}
public void Reset(bool gameLooped, bool gameRestarted)
{
//Reset false only if its an full reset and not loop
if(!gameLooped) died = false;
if(gameLooped)
{
//Actual apply new game plus
monsterChances[0] = new Vector2(0.014f + newGamePlus * 0.005f, 0.41f + newGamePlus * 0.05f);
monsterChances[4] = new Vector2(0.002f, 0.1f);
}
//Only show the start menu when its a fresh new game
ui.onStartMenu = false;
if (!gameLooped && !gameRestarted)
{
ui.onStartMenu = true;
}
//Updates the minigame viewport / topLeftScreenCoordinate
changeScreenSize();
merchantArriving = false;
merchantShopOpen = false;
noPickUpBox = new Rectangle(0, 0, TileSize, TileSize);
merchantBox = new Rectangle(8 * TileSize, 0, TileSize, TileSize);
shopping = false;
zombieModeTimer = 0;
monsterConfusionTimer = 0;
monsters.Clear();
world = 0;
currentLevel = 0;
map = MapLoader.GetDefaultMap();
newMapPosition = 16 * TileSize;
scrollingMap = false;
temporarySprites.Clear();
waitingForPlayerToMoveDownAMap = false;
waveTimer = 80000;
shootoutLevel = false;
betweenWaveTimer = 2500;
gopherRunning = false;
hasGopherAppeared = false;
endCutscene = false;
Cutscene.Reset();
gameOver = false;
powerups.Clear();
overworldSong?.Stop(AudioStopOptions.Immediate);
outlawSong?.Stop(AudioStopOptions.Immediate);
zombieSong?.Stop(AudioStopOptions.Immediate);
outlawSong = null;
overworldSong = null;
Game1.changeMusicTrack("none", track_interruptable: false, MusicContext.MiniGame);
for (int j = 0; j < 4; j++)
{
spawnQueue[j] = new List<SpawnTask>();
}
}
public bool overrideFreeMouseMovement()
{
return Game1.options.SnappyMenus;
}
public void StartGopherTrain(ITEM_TYPE item = ITEM_TYPE.NONE)
{
foreach (BasePlayer p in playerList.Values)
{
p.HoldItem(item, 2000);
}
Game1.playSound("Cowboy_Secret");
gopherTrain = true;
gopherTrainPosition = -TileSize * 2;
}
public void AddGuts(Point position, MONSTER_TYPE whichGuts)
{
switch (whichGuts)
{
case MONSTER_TYPE.orc:
case MONSTER_TYPE.ogre:
case MONSTER_TYPE.mushroom:
case MONSTER_TYPE.spikey:
case MONSTER_TYPE.dracula:
temporarySprites.Add(new TemporaryAnimatedSprite("LooseSprites\\Cursors", new Rectangle(512, 1696, 16, 16), 80f, 6, 0, topLeftScreenCoordinate + new Vector2(position.X, position.Y), flicker: false, Game1.random.NextDouble() < 0.5, 0.001f, 0f, Color.White, 3f, 0f, 0f, 0f, local: true));
temporarySprites.Add(new TemporaryAnimatedSprite("LooseSprites\\Cursors", new Rectangle(592, 1696, 16, 16), 10000f, 1, 0, topLeftScreenCoordinate + new Vector2(position.X, position.Y), flicker: false, Game1.random.NextDouble() < 0.5, 0.001f, 0f, Color.White, 3f, 0f, 0f, 0f, local: true)
{
delayBeforeAnimationStart = 480
});
break;
case MONSTER_TYPE.mummy:
temporarySprites.Add(new TemporaryAnimatedSprite("LooseSprites\\Cursors", new Rectangle(464, 1792, 16, 16), 80f, 5, 0, topLeftScreenCoordinate + new Vector2(position.X, position.Y), flicker: false, Game1.random.NextDouble() < 0.5, 0.001f, 0f, Color.White, 3f, 0f, 0f, 0f, local: true));
break;
case MONSTER_TYPE.ghost:
case MONSTER_TYPE.devil:
temporarySprites.Add(new TemporaryAnimatedSprite("LooseSprites\\Cursors", new Rectangle(544, 1728, 16, 16), 80f, 4, 0, topLeftScreenCoordinate + new Vector2(position.X, position.Y), flicker: false, Game1.random.NextDouble() < 0.5, 0.001f, 0f, Color.White, 3f, 0f, 0f, 0f, local: true));
break;
}
}
public void EndOfGopherAnimationBehavior2(int extraInfo)
{
Game1.playSound("cowboy_gopher");
if (Math.Abs(gopherBox.X - 8 * TileSize) > Math.Abs(gopherBox.Y - 8 * TileSize))
{
if (gopherBox.X > 8 * TileSize)
{
gopherMotion = new Point(-2, 0);
}
else
{
gopherMotion = new Point(2, 0);
}
}
else if (gopherBox.Y > 8 * TileSize)
{
gopherMotion = new Point(0, -2);
}
else
{
gopherMotion = new Point(0, 2);
}
gopherRunning = true;
}
public void EndOfGopherAnimationBehavior(int extrainfo)
{
temporarySprites.Add(new TemporaryAnimatedSprite("LooseSprites\\Cursors", new Rectangle(384, 1792, 16, 16), 120f, 4, 2, topLeftScreenCoordinate + new Vector2(gopherBox.X + TileSize / 2, gopherBox.Y + TileSize / 2), flicker: false, flipped: false, (float)gopherBox.Y / 10000f, 0f, Color.White, 3f, 0f, 0f, 0f, local: true)
{
endFunction = EndOfGopherAnimationBehavior2
});
Game1.playSound("cowboy_gopher");
}
public void UpdateBullets(GameTime time)
{
for (int m = bullets.Count - 1; m >= 0; m--)
{
bullets[m].Update();
if(bullets[m].queuedForDeletion)
{
//NET Despawn Bullet
PK_BulletDespawned mBulletDespawned = new()
{
id = bullets[m].id
};
modInstance.SyncMessage(mBulletDespawned);
bullets.RemoveAt(m);
}
}
}
public void PlayerDie()
{
gopherRunning = false;
hasGopherAppeared = false;
spawnQueue = new List<SpawnTask>[4];
for (int i = 0; i < 4; i++)
{
spawnQueue[i] = new List<SpawnTask>();
}
//enemyBullets.Clear(); Still needed? Might even look cool, and not scary because of invincibility timer
if (!shootoutLevel)
{
powerups.Clear();
monsters.Clear();
}
died = true;
activePowerups.Clear();
if (overworldSong != null && overworldSong.IsPlaying)
{
overworldSong.Stop(AudioStopOptions.Immediate);
}
temporarySprites.Add(new TemporaryAnimatedSprite("LooseSprites\\Cursors", new Rectangle(464, 1808, 16, 16), 120f, 5, 0, player.position + topLeftScreenCoordinate, flicker: false, flipped: false, 1f, 0f, Color.White, 3f, 0f, 0f, 0f, local: true));
waveTimer = Math.Min(80000, waveTimer + 10000);
betweenWaveTimer = 4000;
lives--;
foreach(BasePlayer p in playerList.Values)
{
p.Die();
}
if (lives < 0)
{
temporarySprites.Add(new TemporaryAnimatedSprite("LooseSprites\\Cursors", new Rectangle(464, 1808, 16, 16), 550f, 5, 0, player.position + topLeftScreenCoordinate, flicker: false, flipped: false, 1f, 0f, Color.White, 3f, 0f, 0f, 0f, local: true)
{
alpha = 0.001f,
endFunction = AfterPlayerDeathFunction
});
foreach (BasePlayer p in playerList.Values)
{
p.deathTimer *= 3f;
}
modInstance.UpdateSaveState(null);
}
else if (!shootoutLevel)
{
SaveGame();
}
}
public void AfterPlayerDeathFunction(int extra)
{
if (lives < 0)
{
gameOver = true;
overworldSong?.Stop(AudioStopOptions.Immediate);
outlawSong?.Stop(AudioStopOptions.Immediate);
zombieSong?.Stop(AudioStopOptions.Immediate);
monsters.Clear();
powerups.Clear();
died = false;
Game1.playSound("Cowboy_monsterDie");
}
}
public void StartNewRound()
{
gamerestartTimer = 2000;
Game1.playSound("Cowboy_monsterDie");
newGamePlus++;
}
public void StartLevelTransition()
{
SaveGame();
shopping = false;
merchantArriving = false;
merchantShopOpen = false;
merchantBox.Y = -TileSize;
scrollingMap = true;
nextMap = MapLoader.GetMap(currentLevel);
newMapPosition = 16 * TileSize;
temporarySprites.Clear();
powerups.Clear();
}
protected void UpdateInput()
{
if (Game1.options.gamepadControls)
{
GamePadState pad_state = Game1.input.GetGamePadState();
ButtonCollection button_collection = new(ref pad_state);
if (pad_state.ThumbSticks.Left.X < -0.2) _buttonHeldState.Add(GameKeys.MoveLeft);
if (pad_state.ThumbSticks.Left.X > 0.2) _buttonHeldState.Add(GameKeys.MoveRight);
if (pad_state.ThumbSticks.Left.Y < -0.2) _buttonHeldState.Add(GameKeys.MoveDown);
if (pad_state.ThumbSticks.Left.Y > 0.2) _buttonHeldState.Add(GameKeys.MoveUp);
if (pad_state.ThumbSticks.Right.X < -0.2) _buttonHeldState.Add(GameKeys.ShootLeft);
if (pad_state.ThumbSticks.Right.X > 0.2) _buttonHeldState.Add(GameKeys.ShootRight);
if (pad_state.ThumbSticks.Right.Y < -0.2) _buttonHeldState.Add(GameKeys.ShootDown);
if (pad_state.ThumbSticks.Right.Y > 0.2) _buttonHeldState.Add(GameKeys.ShootUp);
ButtonCollection.ButtonEnumerator enumerator = button_collection.GetEnumerator();
while (enumerator.MoveNext())
{
switch (enumerator.Current)
{
case Buttons.A:
if (gameOver) _buttonHeldState.Add(GameKeys.SelectOption);
else if (IsEnterButtonAssignmentFlipped) _buttonHeldState.Add(GameKeys.ShootRight);
else _buttonHeldState.Add(GameKeys.ShootDown);
break;
case Buttons.Y:
_buttonHeldState.Add(GameKeys.ShootUp);
break;
case Buttons.X:
_buttonHeldState.Add(GameKeys.ShootLeft);
break;
case Buttons.B:
if (gameOver) _buttonHeldState.Add(GameKeys.Exit);
else if (IsEnterButtonAssignmentFlipped) _buttonHeldState.Add(GameKeys.ShootDown);
else _buttonHeldState.Add(GameKeys.ShootRight);
break;
case Buttons.DPadUp:
_buttonHeldState.Add(GameKeys.MoveUp);
break;
case Buttons.DPadDown:
_buttonHeldState.Add(GameKeys.MoveDown);
break;
case Buttons.DPadLeft:
_buttonHeldState.Add(GameKeys.MoveLeft);
break;
case Buttons.DPadRight:
_buttonHeldState.Add(GameKeys.MoveRight);
break;
case Buttons.Start:
case Buttons.LeftShoulder:
case Buttons.RightShoulder:
case Buttons.RightTrigger:
case Buttons.LeftTrigger:
_buttonHeldState.Add(GameKeys.UsePowerup);
break;
case Buttons.Back:
_buttonHeldState.Add(GameKeys.Exit);
break;
}
}
}
if (Game1.input.GetKeyboardState().IsKeyDown(Keys.W)) _buttonHeldState.Add(GameKeys.MoveUp);
if (Game1.input.GetKeyboardState().IsKeyDown(Keys.S)) _buttonHeldState.Add(GameKeys.MoveDown);
if (Game1.input.GetKeyboardState().IsKeyDown(Keys.A)) _buttonHeldState.Add(GameKeys.MoveLeft);
if (Game1.input.GetKeyboardState().IsKeyDown(Keys.D)) _buttonHeldState.Add(GameKeys.MoveRight);
if (Game1.input.GetKeyboardState().IsKeyDown(Keys.Up))
{
if (gameOver) _buttonHeldState.Add(GameKeys.MoveUp);
else _buttonHeldState.Add(GameKeys.ShootUp);
}
if (Game1.input.GetKeyboardState().IsKeyDown(Keys.Down))
{
if (gameOver) _buttonHeldState.Add(GameKeys.MoveDown);
else _buttonHeldState.Add(GameKeys.ShootDown);
}
if (Game1.input.GetKeyboardState().IsKeyDown(Keys.Left)) _buttonHeldState.Add(GameKeys.ShootLeft);
if (Game1.input.GetKeyboardState().IsKeyDown(Keys.Right)) _buttonHeldState.Add(GameKeys.ShootRight);
if (Game1.input.GetKeyboardState().IsKeyDown(Keys.X) || Game1.input.GetKeyboardState().IsKeyDown(Keys.Enter) || Game1.input.GetKeyboardState().IsKeyDown(Keys.Space))
{
if (gameOver) _buttonHeldState.Add(GameKeys.SelectOption);
else _buttonHeldState.Add(GameKeys.UsePowerup);
}
if (Game1.input.GetKeyboardState().IsKeyDown(Keys.Escape)) _buttonHeldState.Add(GameKeys.Exit);
}
public bool tick(GameTime time)
{
//Pause the game for everyone if ALL players are ingame
if (modInstance.playerList.Value.Count == Game1.numberOfPlayers())
{
Game1.gameTimeInterval = 0;
}
//Update and process inputs
_buttonHeldState.Clear();
UpdateInput();
for (int l = 0; l < 11; l++)
{
if (_buttonHeldState.Contains((GameKeys)l))
{
_buttonHeldFrames[(GameKeys)l]++;
}
else
{
_buttonHeldFrames[(GameKeys)l] = 0;
}
}
ProcessInputs();
// Dont process the game anymore if on menu on quitting
if (quit)
{
Game1.stopMusicTrack(MusicContext.MiniGame);
return true;
}
if (gameOver) return false;
if (ui.onStartMenu) return false;
if (gamerestartTimer > 0)
{
gamerestartTimer -= time.ElapsedGameTime.Milliseconds;
if (gamerestartTimer <= 0)
{
if (newGamePlus == 0 || !endCutscene)
{
Reset(gameLooped: false, gameRestarted: true);
}
else
{
Reset(gameLooped: true, gameRestarted: false);
}
}
}
//Process cutscene
if (endCutscene)
{
Cutscene.Tick(time);
return false;
}
if (motionPause > 0)
{
motionPause -= time.ElapsedGameTime.Milliseconds;
if (motionPause <= 0 && behaviorAfterPause != null)
{
behaviorAfterPause();
behaviorAfterPause = null;
}
}
else if (monsterConfusionTimer > 0)
{
monsterConfusionTimer -= time.ElapsedGameTime.Milliseconds;
}
if (zombieModeTimer > 0)
{
zombieModeTimer -= time.ElapsedGameTime.Milliseconds;
}
foreach(BasePlayer p in playerList.Values)
{
p.Tick(time);
}
//Dont stop if the player is still holding up the item?
if (player.IsHoldingItem()) return false;
//Screen flash timer
if (screenFlash > 0)
{
screenFlash -= time.ElapsedGameTime.Milliseconds;
}
//Weird gopher train shit
if (gopherTrain)
{
gopherTrainPosition += 3;
if (gopherTrainPosition % 30 == 0)
{
Game1.playSound("Cowboy_Footstep");
}
if (playerJumped)
{
player.position.Y += 3f;
}
if (Math.Abs(player.position.Y - (float)(gopherTrainPosition - TileSize)) <= 16f)
{
playerJumped = true;
player.position.Y = gopherTrainPosition - TileSize;
}
if (gopherTrainPosition > 16 * TileSize + TileSize)
{
gopherTrain = false;
playerJumped = false;
currentLevel++;
map = MapLoader.GetMap(currentLevel);
player.position = new Vector2(8 * TileSize, 8 * TileSize);
//NET Player Move
NETmovePlayer(player.position);
world = ((world != MAP_TYPE.desert) ? MAP_TYPE.graveyard : MAP_TYPE.woods);
waveTimer = 80000;
betweenWaveTimer = 5000;
waitingForPlayerToMoveDownAMap = false;
shootoutLevel = false;
SaveGame();
}
}
// Shopping lady moving to her place
if ((shopping || merchantArriving || waitingForPlayerToMoveDownAMap) && !player.IsHoldingItem())
{
int oldTimer = shoppingTimer;
shoppingTimer += time.ElapsedGameTime.Milliseconds;
shoppingTimer %= 500;
if (!merchantShopOpen && merchantArriving && shopping && ((oldTimer < 250 && shoppingTimer >= 250) || oldTimer > shoppingTimer))
{
Game1.playSound("Cowboy_Footstep");
}
}
//Move palyers along when moving down to the next map
if (scrollingMap)
{
newMapPosition -= TileSize / 8;
foreach (BasePlayer p in playerList.Values)
{
p.position.Y -= (float)TileSize / 8;
p.position.Y += 3f;
p.boundingBox.X = (int)player.position.X + TileSize / 4;
p.boundingBox.Y = (int)player.position.Y + TileSize / 4;
p.boundingBox.Width = TileSize / 2;
p.boundingBox.Height = TileSize / 2;
p.movementDirections = new List<int> { 2 };
p.motionAnimationTimer += time.ElapsedGameTime.Milliseconds;
p.motionAnimationTimer %= 400;
}
//Swap to the next map once the map is loaded
if (newMapPosition <= 0)
{
scrollingMap = false;
map = nextMap;
newMapPosition = 16 * TileSize;
shopping = false;
betweenWaveTimer = 5000;
waitingForPlayerToMoveDownAMap = false;
player.movementDirections.Clear();
ApplyLevelSpecificStates();
}
}
if (gopherRunning)
{
gopherBox.X += gopherMotion.X;
gopherBox.Y += gopherMotion.Y;
for (int m = monsters.Count - 1; m >= 0; m--)
{
if (gopherBox.Intersects(monsters[m].position))
{
//Net EnemyKilled
PK_EnemyKilled message = new()
{
id = monsters[m].id
};
modInstance.SyncMessage(message);
AddGuts(monsters[m].position.Location, monsters[m].type);
monsters.RemoveAt(m);
Game1.playSound("Cowboy_monsterDie");
}
}
if (gopherBox.X < 0 || gopherBox.Y < 0 || gopherBox.X > 16 * TileSize || gopherBox.Y > 16 * TileSize)
{
gopherRunning = false;
}
}
//Remove temporary sprites whos time have run out (?)
for (int n = temporarySprites.Count - 1; n >= 0; n--)
{
if (temporarySprites[n].update(time))
{
temporarySprites.RemoveAt(n);
}
}
//Move powerups again?
if (motionPause <= 0)
{
for (int i = powerups.Count - 1; i >= 0; i--)
{