Nanotrasen Block Game is here (#2131)

* tetris!

* softdropping & left,right key holding

* started work on the ui

* playable state

* there you go exp

* multiuser rework

* ui update refactor

* blockgame™️

* highscores, keybindings, ui refactor

* speed adjusts
leveling

* highscorebackground tweak
speed tweak

* NULLABLE

* yes
This commit is contained in:
Paul Ritter
2020-09-26 15:25:22 +02:00
committed by GitHub
parent 4eb5891c4a
commit 84ce845ea3
14 changed files with 2013 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
using System;
using Robust.Shared.Maths;
using Robust.Shared.Serialization;
namespace Content.Shared.Arcade
{
[Serializable, NetSerializable]
public struct BlockGameBlock
{
public Vector2i Position;
public readonly BlockGameBlockColor GameBlockColor;
public BlockGameBlock(Vector2i position, BlockGameBlockColor gameBlockColor)
{
Position = position;
GameBlockColor = gameBlockColor;
}
[Serializable, NetSerializable]
public enum BlockGameBlockColor
{
Red,
Orange,
Yellow,
Green,
Blue,
LightBlue,
Purple
}
}
public static class BlockGameVector2Extensions{
public static BlockGameBlock ToBlockGameBlock(this Vector2i vector2, BlockGameBlock.BlockGameBlockColor gameBlockColor)
{
return new BlockGameBlock(vector2, gameBlockColor);
}
public static Vector2i AddToX(this Vector2i vector2, int amount)
{
return new Vector2i(vector2.X + amount, vector2.Y);
}
public static Vector2i AddToY(this Vector2i vector2, int amount)
{
return new Vector2i(vector2.X, vector2.Y + amount);
}
public static Vector2i Rotate90DegreesAsOffset(this Vector2i vector)
{
return new Vector2i(-vector.Y, vector.X);
}
}
}

View File

@@ -0,0 +1,141 @@
#nullable enable
using System;
using System.Collections.Generic;
using Robust.Shared.GameObjects.Components.UserInterface;
using Robust.Shared.Serialization;
namespace Content.Shared.Arcade
{
public static class BlockGameMessages
{
[Serializable, NetSerializable]
public class BlockGamePlayerActionMessage : BoundUserInterfaceMessage
{
public readonly BlockGamePlayerAction PlayerAction;
public BlockGamePlayerActionMessage(BlockGamePlayerAction playerAction)
{
PlayerAction = playerAction;
}
}
[Serializable, NetSerializable]
public class BlockGameVisualUpdateMessage : BoundUserInterfaceMessage
{
public readonly BlockGameVisualType GameVisualType;
public readonly BlockGameBlock[] Blocks;
public BlockGameVisualUpdateMessage(BlockGameBlock[] blocks, BlockGameVisualType gameVisualType)
{
Blocks = blocks;
GameVisualType = gameVisualType;
}
}
public enum BlockGameVisualType
{
GameField,
HoldBlock,
NextBlock
}
[Serializable, NetSerializable]
public class BlockGameScoreUpdateMessage : BoundUserInterfaceMessage
{
public readonly int Points;
public BlockGameScoreUpdateMessage(int points)
{
Points = points;
}
}
[Serializable, NetSerializable]
public class BlockGameUserStatusMessage : BoundUserInterfaceMessage
{
public readonly bool IsPlayer;
public BlockGameUserStatusMessage(bool isPlayer)
{
IsPlayer = isPlayer;
}
}
[Serializable, NetSerializable]
public class BlockGameUserUnregisterMessage : BoundUserInterfaceMessage{}
[Serializable, NetSerializable]
public class BlockGameSetScreenMessage : BoundUserInterfaceMessage
{
public readonly BlockGameScreen Screen;
public readonly bool isStarted;
public BlockGameSetScreenMessage(BlockGameScreen screen, bool isStarted = true)
{
Screen = screen;
this.isStarted = isStarted;
}
}
[Serializable, NetSerializable]
public class BlockGameGameOverScreenMessage : BlockGameSetScreenMessage
{
public readonly int FinalScore;
public readonly int? LocalPlacement;
public readonly int? GlobalPlacement;
public BlockGameGameOverScreenMessage(int finalScore, int? localPlacement, int? globalPlacement) : base(BlockGameScreen.Gameover)
{
FinalScore = finalScore;
LocalPlacement = localPlacement;
GlobalPlacement = globalPlacement;
}
}
[Serializable, NetSerializable]
public enum BlockGameScreen
{
Game,
Pause,
Gameover,
Highscores
}
[Serializable, NetSerializable]
public class BlockGameHighScoreUpdateMessage : BoundUserInterfaceMessage
{
public List<HighScoreEntry> LocalHighscores;
public List<HighScoreEntry> GlobalHighscores;
public BlockGameHighScoreUpdateMessage(List<HighScoreEntry> localHighscores, List<HighScoreEntry> globalHighscores)
{
LocalHighscores = localHighscores;
GlobalHighscores = globalHighscores;
}
}
[Serializable, NetSerializable]
public class HighScoreEntry : IComparable
{
public string Name;
public int Score;
public HighScoreEntry(string name, int score)
{
Name = name;
Score = score;
}
public int CompareTo(object? obj)
{
if (!(obj is HighScoreEntry entry)) return 0;
return Score.CompareTo(entry.Score);
}
}
[Serializable, NetSerializable]
public class BlockGameLevelUpdateMessage : BoundUserInterfaceMessage
{
public readonly int Level;
public BlockGameLevelUpdateMessage(int level)
{
Level = level;
}
}
}
}

View File

@@ -0,0 +1,24 @@
using System;
using Robust.Shared.Serialization;
namespace Content.Shared.Arcade
{
[Serializable, NetSerializable]
public enum BlockGamePlayerAction
{
NewGame,
StartLeft,
EndLeft,
StartRight,
EndRight,
Rotate,
CounterRotate,
SoftdropStart,
SoftdropEnd,
Harddrop,
Pause,
Unpause,
Hold,
ShowHighscores
}
}

View File

@@ -0,0 +1,11 @@
using System;
using Robust.Shared.Serialization;
namespace Content.Shared.Arcade
{
[Serializable, NetSerializable]
public enum BlockGameUiKey
{
Key
}
}