Files
PacManUdon/Assets/Scripts/PacManConstants.cs
2026-06-19 13:35:09 +02:00

414 lines
21 KiB
C#

namespace Marro.PacManUdon
{
using UnityEngine;
public enum PacManFruitType
{
None = -1,
Cherries = 0,
Strawberry = 1,
Peach = 2,
Apple = 3,
Grapes = 4,
Galaxian = 5,
Bell = 6,
Key = 7
}
public enum PacManGameState
{
AttractMode,
AttractModeDemo,
WaitForStart,
InGame,
}
public enum PacManGhostFrozenState
{
Frozen,
FrozenIfNotCaught,
NotFrozen
}
public enum PacManTimeSequence
{
AttractScreenIntroduction,
AttractScreenDemo,
AttractScreenWaitToRestart,
WaitForStart,
WaitForStartTimeout,
StartNewGame,
BoardClear,
StartNewLevel,
GhostCaught,
PacManCaught,
RestartLevel,
GameOver,
Intermission1,
Intermission2,
Intermission3
}
public enum PacManCollisionInfoType
{
Tunnel = 0b00100000,
HorizontalOnly = 0b00010000, // Bit that indicates tiles on which ghosts are only allowed to go horizontal unless they're scared
NoTurn = 0b01000000,
Wall = 0b10000000,
}
public enum PacManConsumableType
{
None = 255,
FruitLeft = 254,
FruitRight = 253,
}
public static class PacManConstants
{
// Jagged or 2D arrays can't be static so we work with 1D arrays
public static byte[] GetMazeCollisionInfo() => new byte[]
{
192, 192, 192, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 192, 192, 192,
192, 192, 200, 009, 076, 076, 076, 076, 076, 076, 076, 076, 076, 076, 013, 076, 076, 013, 076, 076, 076, 076, 076, 076, 076, 076, 076, 076, 005, 196, 192, 192,
192, 192, 200, 067, 134, 194, 194, 194, 194, 194, 194, 194, 194, 138, 067, 134, 138, 067, 134, 194, 194, 194, 194, 194, 194, 194, 194, 138, 067, 196, 192, 192,
192, 192, 200, 067, 133, 193, 193, 193, 193, 192, 192, 193, 193, 137, 067, 196, 200, 067, 133, 193, 193, 192, 192, 193, 193, 193, 193, 137, 067, 196, 192, 192,
192, 192, 200, 010, 076, 013, 076, 076, 005, 196, 200, 009, 076, 076, 006, 196, 200, 010, 076, 076, 005, 196, 200, 009, 076, 076, 013, 076, 006, 196, 192, 192,
192, 192, 192, 194, 138, 067, 134, 138, 067, 196, 200, 067, 134, 194, 194, 192, 192, 194, 194, 138, 067, 196, 200, 067, 134, 138, 067, 134, 194, 192, 192, 192,
192, 192, 192, 193, 137, 067, 196, 200, 067, 133, 137, 067, 133, 193, 193, 193, 193, 193, 193, 137, 067, 133, 137, 067, 196, 200, 067, 133, 193, 192, 192, 192,
192, 192, 200, 009, 076, 006, 196, 200, 011, 076, 076, 014, 076, 076, 029, 076, 076, 029, 076, 076, 014, 076, 076, 007, 196, 200, 010, 076, 005, 196, 192, 192,
192, 192, 200, 067, 134, 194, 192, 200, 067, 134, 194, 194, 194, 138, 067, 134, 138, 067, 134, 194, 194, 194, 138, 067, 196, 192, 194, 138, 067, 196, 192, 192,
192, 192, 200, 067, 133, 193, 193, 137, 067, 133, 193, 193, 193, 137, 067, 196, 200, 067, 133, 193, 193, 193, 137, 067, 133, 193, 193, 137, 067, 196, 192, 192,
192, 192, 200, 010, 076, 076, 076, 076, 015, 076, 076, 013, 076, 076, 006, 196, 200, 010, 076, 076, 013, 076, 076, 015, 076, 076, 076, 076, 006, 196, 192, 192,
192, 192, 192, 194, 194, 194, 194, 138, 067, 134, 138, 067, 134, 194, 194, 192, 192, 194, 194, 138, 067, 134, 138, 067, 134, 194, 194, 194, 194, 192, 192, 192,
192, 192, 192, 192, 192, 192, 192, 200, 067, 196, 200, 067, 133, 193, 193, 193, 193, 193, 193, 137, 067, 196, 200, 067, 196, 192, 192, 192, 192, 192, 192, 192,
192, 192, 192, 192, 192, 192, 192, 200, 067, 196, 200, 011, 076, 076, 076, 076, 076, 076, 076, 076, 007, 196, 200, 067, 196, 192, 192, 192, 192, 192, 192, 192,
192, 192, 192, 192, 192, 192, 192, 200, 067, 196, 200, 067, 134, 194, 194, 194, 194, 194, 194, 138, 067, 196, 200, 067, 196, 192, 192, 192, 192, 192, 192, 192,
193, 193, 193, 193, 193, 193, 193, 137, 067, 133, 137, 067, 196, 192, 192, 192, 192, 192, 192, 200, 067, 133, 137, 067, 133, 193, 193, 193, 193, 193, 193, 193,
108, 108, 108, 108, 108, 108, 108, 076, 015, 076, 076, 007, 196, 192, 192, 192, 192, 192, 192, 200, 011, 076, 076, 015, 076, 108, 108, 108, 108, 108, 108, 108,
194, 194, 194, 194, 194, 194, 194, 138, 067, 134, 138, 067, 196, 192, 192, 192, 192, 192, 192, 200, 067, 134, 138, 067, 134, 194, 194, 194, 194, 194, 194, 194,
192, 192, 192, 192, 192, 192, 192, 200, 067, 196, 200, 067, 133, 193, 193, 193, 193, 193, 193, 137, 067, 196, 200, 067, 196, 192, 192, 192, 192, 192, 192, 192,
192, 192, 192, 192, 192, 192, 192, 200, 067, 196, 200, 010, 076, 076, 029, 076, 076, 029, 076, 076, 006, 196, 200, 067, 196, 192, 192, 192, 192, 192, 192, 192,
192, 192, 192, 192, 192, 192, 192, 200, 067, 196, 192, 194, 194, 138, 067, 134, 138, 067, 134, 194, 194, 192, 200, 067, 196, 192, 192, 192, 192, 192, 192, 192,
192, 192, 192, 193, 193, 193, 193, 137, 067, 196, 192, 193, 193, 137, 067, 196, 200, 067, 133, 193, 193, 192, 200, 067, 133, 193, 193, 193, 193, 192, 192, 192,
192, 192, 200, 009, 076, 076, 076, 076, 007, 196, 200, 009, 076, 076, 006, 196, 200, 010, 076, 076, 005, 196, 200, 011, 076, 076, 076, 076, 005, 196, 192, 192,
192, 192, 200, 067, 134, 194, 194, 138, 067, 196, 200, 067, 134, 194, 194, 192, 192, 194, 194, 138, 067, 196, 200, 067, 134, 194, 194, 138, 067, 196, 192, 192,
192, 192, 200, 067, 133, 193, 193, 137, 067, 133, 137, 067, 133, 193, 193, 193, 193, 193, 193, 137, 067, 133, 137, 067, 133, 193, 193, 137, 067, 196, 192, 192,
192, 192, 200, 011, 076, 076, 076, 076, 015, 076, 076, 014, 076, 076, 013, 076, 076, 013, 076, 076, 014, 076, 076, 015, 076, 076, 076, 076, 007, 196, 192, 192,
192, 192, 200, 067, 134, 194, 194, 138, 067, 134, 194, 194, 194, 138, 067, 134, 138, 067, 134, 194, 194, 194, 138, 067, 134, 194, 194, 138, 067, 196, 192, 192,
192, 192, 200, 067, 196, 192, 192, 200, 067, 196, 192, 192, 192, 200, 067, 196, 200, 067, 196, 192, 192, 192, 200, 067, 196, 192, 192, 200, 067, 196, 192, 192,
192, 192, 200, 067, 133, 193, 193, 137, 067, 133, 193, 193, 193, 137, 067, 196, 200, 067, 133, 193, 193, 193, 137, 067, 133, 193, 193, 137, 067, 196, 192, 192,
192, 192, 200, 010, 076, 076, 076, 076, 014, 076, 076, 076, 076, 076, 006, 196, 200, 010, 076, 076, 076, 076, 076, 014, 076, 076, 076, 076, 006, 196, 192, 192,
192, 192, 192, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 192, 192, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 192, 192, 192,
192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192,
};
public static byte[] GetMazePelletMap() => new byte[]
{
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 021, 022, 023, 024, 025, 026, 027, 028, 029, 030, 031, 032, 033, 034, 035, 036, 037, 038, 039, 040, 041, 042, 043, 044, 045, 046, 255, 255, 255,
255, 255, 255, 020, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 072, 255, 255, 071, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 047, 255, 255, 255,
255, 255, 255, 019, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 073, 255, 255, 070, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 048, 255, 255, 255,
255, 255, 255, 018, 017, 016, 015, 014, 013, 255, 255, 077, 076, 075, 074, 255, 255, 069, 068, 067, 066, 255, 255, 054, 053, 052, 051, 050, 049, 255, 255, 255,
255, 255, 255, 255, 255, 080, 255, 255, 012, 255, 255, 078, 255, 255, 255, 255, 255, 255, 255, 255, 065, 255, 255, 055, 255, 255, 113, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 081, 255, 255, 011, 255, 255, 079, 255, 255, 255, 255, 255, 255, 255, 255, 064, 255, 255, 056, 255, 255, 114, 255, 255, 255, 255, 255,
255, 255, 255, 000, 083, 082, 255, 255, 010, 009, 008, 007, 006, 005, 004, 255, 255, 063, 062, 061, 060, 059, 058, 057, 255, 255, 115, 116, 001, 255, 255, 255,
255, 255, 255, 084, 255, 255, 255, 255, 093, 255, 255, 255, 255, 255, 101, 255, 255, 102, 255, 255, 255, 255, 255, 112, 255, 255, 255, 255, 117, 255, 255, 255,
255, 255, 255, 085, 255, 255, 255, 255, 092, 255, 255, 255, 255, 255, 100, 255, 255, 103, 255, 255, 255, 255, 255, 111, 255, 255, 255, 255, 118, 255, 255, 255,
255, 255, 255, 086, 087, 088, 089, 090, 091, 094, 095, 096, 097, 098, 099, 255, 255, 104, 105, 106, 107, 108, 109, 110, 123, 122, 121, 120, 119, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 243, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 124, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 242, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 125, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 241, 255, 255, 255, 255, 255, 255, 253, 254, 255, 255, 255, 255, 255, 255, 126, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 240, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 127, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 239, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 128, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 238, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 129, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 237, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 130, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 236, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 131, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 235, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 132, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 234, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 133, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 233, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 134, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 225, 226, 227, 228, 229, 232, 255, 255, 207, 208, 209, 210, 255, 255, 170, 169, 168, 167, 255, 255, 135, 136, 137, 138, 139, 140, 255, 255, 255,
255, 255, 255, 224, 255, 255, 255, 255, 231, 255, 255, 206, 255, 255, 255, 255, 255, 255, 255, 255, 166, 255, 255, 161, 255, 255, 255, 255, 141, 255, 255, 255,
255, 255, 255, 223, 255, 255, 255, 255, 230, 255, 255, 205, 255, 255, 255, 255, 255, 255, 255, 255, 165, 255, 255, 160, 255, 255, 255, 255, 142, 255, 255, 255,
255, 255, 255, 218, 219, 220, 221, 222, 199, 200, 201, 202, 203, 204, 185, 184, 183, 173, 172, 171, 164, 163, 162, 155, 156, 157, 158, 159, 143, 255, 255, 255,
255, 255, 255, 217, 255, 255, 255, 255, 198, 255, 255, 255, 255, 255, 186, 255, 255, 174, 255, 255, 255, 255, 255, 154, 255, 255, 255, 255, 144, 255, 255, 255,
255, 255, 255, 003, 255, 255, 255, 255, 197, 255, 255, 255, 255, 255, 187, 255, 255, 175, 255, 255, 255, 255, 255, 153, 255, 255, 255, 255, 002, 255, 255, 255,
255, 255, 255, 216, 255, 255, 255, 255, 196, 255, 255, 255, 255, 255, 188, 255, 255, 176, 255, 255, 255, 255, 255, 152, 255, 255, 255, 255, 145, 255, 255, 255,
255, 255, 255, 215, 214, 213, 212, 211, 195, 194, 193, 192, 191, 190, 189, 255, 255, 177, 178, 179, 180, 181, 182, 151, 150, 149, 148, 147, 146, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
};
public static int[] GetMazePelletIndices() => new int[]
{
227, 252, 892, 867, 238, 237, 236, 235, 234, 233, 232, 200, 168, 136, 135, 134,
133, 132, 131, 099, 067, 035, 036, 037, 038, 039, 040, 041, 042, 043, 044, 045,
046, 047, 048, 049, 050, 051, 052, 053, 054, 055, 056, 057, 058, 059, 060, 092,
124, 156, 155, 154, 153, 152, 151, 183, 215, 247, 246, 245, 244, 243, 242, 241,
212, 180, 148, 147, 146, 145, 113, 081, 078, 110, 142, 141, 140, 139, 171, 203,
165, 197, 229, 228, 259, 291, 323, 324, 325, 326, 327, 328, 296, 264, 329, 330,
331, 332, 333, 334, 302, 270, 273, 305, 337, 338, 339, 340, 341, 342, 343, 311,
279, 186, 218, 250, 251, 284, 316, 348, 347, 346, 345, 344, 375, 407, 439, 471,
503, 535, 567, 599, 631, 663, 695, 727, 728, 729, 730, 731, 732, 764, 796, 828,
860, 924, 956, 955, 954, 953, 952, 951, 919, 887, 855, 823, 824, 825, 826, 827,
791, 759, 822, 821, 820, 788, 756, 724, 723, 722, 721, 819, 818, 817, 849, 881,
913, 945, 946, 947, 948, 949, 950, 816, 815, 814, 846, 878, 910, 942, 941, 940,
939, 938, 937, 936, 904, 872, 840, 808, 809, 810, 811, 812, 813, 779, 747, 715,
716, 717, 718, 935, 934, 933, 932, 931, 899, 835, 803, 804, 805, 806, 807, 771,
739, 707, 708, 709, 710, 711, 776, 744, 712, 680, 648, 616, 584, 552, 520, 488,
456, 424, 392, 360,
};
public static GameObject[] ComponentsToGameObjects(Component[] components, bool skipFirstComponent = false)
{
if (skipFirstComponent)
{
GameObject[] gameObjects = new GameObject[components.Length - 1];
for (int i = 0; i < components.Length - 1; i++)
{
gameObjects[i] = components[i + 1].gameObject;
}
return gameObjects;
}
else
{
GameObject[] gameObjects = new GameObject[components.Length];
for (int i = 0; i < components.Length; i++)
{
gameObjects[i] = components[i].gameObject;
}
return gameObjects;
}
}
public static float GetPowerPelletBlinkToggleInterval()
{
return 0.1666666666f;
}
public static PacManFruitType GetFruitTypeForLevel(int level)
{
PacManFruitType[] FruitTypePerLevel = new PacManFruitType[]
{
PacManFruitType.Cherries,
PacManFruitType.Strawberry,
PacManFruitType.Peach,
PacManFruitType.Peach,
PacManFruitType.Apple,
PacManFruitType.Apple,
PacManFruitType.Grapes,
PacManFruitType.Grapes,
PacManFruitType.Galaxian,
PacManFruitType.Galaxian,
PacManFruitType.Bell,
PacManFruitType.Bell,
PacManFruitType.Key
};
if (level - 1 < 0)
{
return PacManFruitType.None;
}
if (level - 1 >= FruitTypePerLevel.Length)
{
return FruitTypePerLevel[FruitTypePerLevel.Length - 1];
}
return FruitTypePerLevel[level - 1];
}
public static float GetGhostHomeSpeed()
{
return 3.5f;
}
public static float GetPacManDefaultSpeedForLevel(int level)
{
if (level <= 1) return 7.576f;
if (level <= 4) return 8.523f;
if (level <= 20) return 9.470f;
return 8.523f;
}
public static float GetPacManPowerPelletSpeedForLevel(int level)
{
if (level <= 1) return 8.523f;
if (level <= 4) return 8.996f;
return 9.470f;
}
public static float GetGhostDefaultSpeedForLevel(int level)
{
if (level <= 1) return 7.102f;
if (level <= 4) return 8.049f;
return 8.996f;
}
public static float GetGhostTunnelSpeedForLevel(int level)
{
if (level <= 1) return 3.788f;
if (level <= 4) return 4.261f;
return 4.735f;
}
public static float GetBlinkyElroy1SpeedForLevel(int level)
{
if (level <= 1) return 7.576f;
if (level <= 4) return 8.523f;
return 9.470f;
}
public static float GetBlinkyElroy2SpeedForLevel(int level)
{
if (level <= 1) return 8.049f;
if (level <= 4) return 8.996f;
return 9.943f;
}
public static float GetGhostScaredSpeedForLevel(int level)
{
if (level <= 1) return 4.735f;
if (level <= 4) return 5.208f;
return 5.682f;
}
public static int GetElroy1PelletsRemainingForLevel(int level)
{
if (level <= 1) return 20;
if (level <= 2) return 30;
if (level <= 5) return 40;
if (level <= 8) return 50;
if (level <= 11) return 60;
if (level <= 14) return 80;
if (level <= 18) return 100;
return 120;
}
public static int GetElroy2PelletsRemainingForLevel(int level)
{
if (level <= 1) return 10;
if (level <= 2) return 15;
if (level <= 5) return 20;
if (level <= 8) return 25;
if (level <= 11) return 30;
if (level <= 14) return 40;
if (level <= 18) return 50;
return 60;
}
public static float GetGhostHousePelletTimeoutLimitForLevel(int level)
{
if (level <= 4) return 4;
return 3;
}
public static int[] GetGhostHousePrivatePelletCounterLimitForLevel(int level)
{
if (level <= 1) return new int[] { 0, 0, 30, 60 };
if (level <= 2) return new int[] { 0, 0, 0, 50 };
return new int[] { 0, 0, 0, 0 };
}
public static float[] GetScatterPatternForLevel(int level)
{
if (level <= 1) return new float[] { 7, 27, 34, 54, 59, 79, 84 };
if (level <= 4) return new float[] { 7, 27, 34, 54, 59, 1092, 1092.0166667f };
return new float[] { 5, 25, 30, 50, 55, 1092, 1092.0166667f };
}
public static float GetScaredDurationForLevel(int level)
{
float[] scaredDurationPerLevel =
{
6,
5,
4,
3,
2,
5,
2,
2,
1,
5,
2,
1,
1,
3,
1,
1,
0,
1,
0
};
if (level - 1 < 0)
{
return scaredDurationPerLevel[0];
}
if (level - 1 >= scaredDurationPerLevel.Length)
{
return scaredDurationPerLevel[scaredDurationPerLevel.Length - 1];
}
return scaredDurationPerLevel[level - 1];
}
public static float GetScaredNumberOfFlashesForLevel(int level)
{
int[] scaredNumberOfFlashesPerLevel = new int[]
{
5,
5,
5,
5,
5,
5,
5,
5,
3,
5,
5,
3,
3,
5,
3,
3,
0,
3,
0
};
if (level - 1 < 0)
{
return scaredNumberOfFlashesPerLevel[0];
}
if (level - 1 >= scaredNumberOfFlashesPerLevel.Length)
{
return scaredNumberOfFlashesPerLevel[scaredNumberOfFlashesPerLevel.Length - 1];
}
return scaredNumberOfFlashesPerLevel[level - 1];
}
public static int FruitTypeToValue(PacManFruitType fruitType)
{ // I can't get casting from enum to int to work so this is a workaround
switch (fruitType)
{
default:
case PacManFruitType.None:
return -1;
case PacManFruitType.Cherries:
return 0;
case PacManFruitType.Strawberry:
return 1;
case PacManFruitType.Peach:
return 2;
case PacManFruitType.Apple:
return 3;
case PacManFruitType.Grapes:
return 4;
case PacManFruitType.Galaxian:
return 5;
case PacManFruitType.Bell:
return 6;
case PacManFruitType.Key:
return 7;
}
}
}
}