Cube clicker
Cube Clicker is an instructive example using the Stride game engine, showcasing several key features:
- Game Data Management: Utilizes the
NexVYaml
serializer for saving and loading game data, demonstrating effective data persistence techniques. - Stride UI Demonstration: Illustrates the use of Stride's UI elements, specifically Grid, TextBlock, and Button, to create interactive and user-friendly interfaces.
- Scripting in Stride: Employs both
SyncScript
andAsyncScript
, providing examples of how to implement synchronous and asynchronous logic in a Stride game. - Separation of Concerns: The game's architecture demonstrates good practice in separating different areas of logic, making the code more maintainable and scalable.
When the game starts, it automatically loads the click data and cube positions from the previous session. The player interacts with dynamically generated cubes, with the game tracking left and right mouse clicks.
View on GitHub.
To explore the entire project, follow the link above. Below is the Program.cs
file from the project for a quick overview.
using Example07_CubeClicker.Managers;
using Example07_CubeClicker.Scripts;
using NexVYaml;
using Stride.CommunityToolkit.Bullet;
using Stride.CommunityToolkit.Engine;
using Stride.CommunityToolkit.Skyboxes;
using Stride.Engine;
using Stride.Graphics;
// This example demonstrates how to load and save game data. When the game starts,
// it automatically loads the click data and cube positions from the previous session.
// The player interacts with dynamically generated cubes, with the game tracking left
// and right mouse clicks.
// In case of a corrupted Yaml file, navigate to the \bin\Debug\net8.0\data\
// directory and delete the file manually.
using var game = new Game();
// Register all DataContracted Types
NexYamlSerializerRegistry.Init();
game.Run(start: Start);
void Start(Scene rootScene)
{
game.SetupBase3DScene();
game.AddSkybox();
game.AddGroundGizmo(showAxisName: true);
CreateAndRegisterGameManagerUI(rootScene);
}
void CreateAndRegisterGameManagerUI(Scene rootScene)
{
var font = game.Content.Load<SpriteFont>("StrideDefaultFont");
var gameManager = new GameManager(font);
game.Services.AddService(gameManager);
var uiEntity = gameManager.CreateUI();
uiEntity.Add(new ClickHandlerComponent());
uiEntity.Scene = rootScene;
}