• entries
8
3
• views
389

I want to explain my progress of game development in the form of step-by-step instructions for beginners. I hope someone will corrent my progress and message me about big mistakes in English grammar.

## Algorithm Use UML Instead Of Flowcharts

Updated: 2/15/2019

## C++ SortFunctions, TDD, GoogleTest, C++

I made a project for Visual Studio 2015: SortFunctions.zip  This project will show you how set up GoogleTest and run simple unit test. Note. If you have another version of VS than before you will run unit tests you need to select VS 2017, like in this screenshot: This solution include two projects: SortFunctions SortFunctions_UnitTests SortFunctions project has two files: SortFunctions.h #pragma once extern void bubbleSort(int *array, unsigned int amount); extern void countingSort(int *array, unsigned int amount); SortFunctions.cpp #include "SortFunctions.h" void bubbleSort(int *array, unsigned int amount) { } void countingSort(int *array, unsigned int amount) { } SortFunctions_UnitTests project has tests. For example, this is the "bubbleSortTests.cpp" with two tests. The first test is for positive numbers and the second test is for negative numbers: bubbleSortTests.cpp #include <gtest/gtest.h> #include "SortFunctions.h" TEST(bubbleSortTest, AllPositiveElements) { // Arrange const unsigned int amount = 5; int actualArray[amount] = { 5, 3, 10, 2, 7 }; int expectedArray[amount] = { 2, 3, 5, 7, 10 }; // Act bubbleSort(actualArray, amount); // Assert for (size_t i = 0; i < amount; i++) { ASSERT_EQ(expectedArray[i], actualArray[i]); } } TEST(bubbleSortTest, AllNegativeElements) { // Arrange const unsigned int amount = 5; int actualArray[amount] = { -5, -3, -10, -2, -7 }; int expectedArray[amount] = { -10, -7, -5, -3, -2 }; // Act bubbleSort(actualArray, amount); // Assert for (size_t i = 0; i < amount; i++) { ASSERT_EQ(expectedArray[i], actualArray[i]); } }

## GameDev books that I study

Updated 2/12/2019 Writing Games: 2010 - 06 - C# Game Programming: For Serious Game Creation. Source Code: 9781435455566.zip (121 MB) 2015 - 09 - Build your own 2D Game Engine and Create Great Web Games Using HTML5, JavaScript, and WebGL by Kelvin Sung, Jebediah Pavleas, Fernando Arnez, and Jason Pace. Source Code: https://github.com/apress/build-your-own-2d-game-engine 2017 - 10 - Pro HTML5 Games - 2nd Edition - A.R. Shankar. Source Code: https://github.com/apress/pro-html5-games-17 2018 - 04 - Unity in Action - 2nd Edition - J. Hocking. Source Code: https://www.manning.com/books/unity-in-action-second-edition Computer graphics: 2013 - 07 - WebGL Programming Guide - K. Matsuda, R. Lea. Source Code: https://sites.google.com/site/webglbook/ 2013 - 06 - Computer Graphics Principles and Practice - 3rd Edition - John F. Hughes, Andries van Dam, Morgan McGuire, David F. Sklar, James D. Foley, Steven K. Feiner, Kurt Akeley. Source Code: http://cgpp.net/about.xml Multiplayer: 2015 - 05 - Multiplayer Game Development with HTML5 - Rodrigo Silveira. Source Code: https://www.packtpub.com/code_download/21527 2015 - 10 - Multiplayer Game Programming - &nbsp;Josh Glazer, Sanjay Madhav. Source Code: https://github.com/MultiplayerBook/MultiplayerBook

## C# GUI WinForms + OpenGL 3.1

This my example how to use GUI WinForms and OpenTK.GLControl Source for Visual Studio (including DLLs): EditedTriangle_WinFormsOpenGL31CSharp.zip EXE: EditedTrianlge_WinFormsOpenGL31CSharp_EXE.zip Separated DLL's for references: OpenTK.zip, OpenTK.GLControl.zip Standard WinForms Color Dialog:

## C# 101. Snake. WinForms, GDI+

Step-by-step instruction of Snake 2D using C#, WinForms, GDI+ Let's make a very simple classic snake game. For example, if we have a snake head with 10x10 pixels then we will move our snake by a step with 10 pixels using timer. This is the result of our work: Note. I take ideas from this tutorial: Python Snake Game We can set a game field size like this: // Set a game field size ClientSize = new Size(200, 200); Let's create a method for drawing of a rectangle: private void DrawRect(int x, int y, Color color, int size = 10) { Graphics g = CreateGraphics(); SolidBrush brush = new SolidBrush(color); g.FillRectangle(brush, new Rectangle(x, y, size, size)); brush.Dispose(); g.Dispose(); } Each game must have a game loop that will be called by timer. I created the GameLoop method that just prints "Hello, World!" to the debug console every 500 ms: public Form1() { InitializeComponent(); // Set a game field size ClientSize = new Size(200, 200); // Create a timer for the GameLoop method var timer = new Timer(); timer.Tick += GameLoop; timer.Interval = 500; timer.Start(); } private void GameLoop(object sender, System.EventArgs e) { System.Console.WriteLine("Hello, World!"); } For a while our GameLoop will have only two called methods Update() and Draw(). The Update() method will have updates for snake cell coordinates and etc. The Draw() method will have only draw methods for game entities.

For example: private void GameLoop(object sender, System.EventArgs e) { Update(); Draw(); } private void Update() { Console.WriteLine("Game entities coords was updated"); } private void Draw() { DrawFood(); DrawSnake(); } private void DrawSnake() { Console.WriteLine("Snake was drawn"); } private void DrawFood() { Console.WriteLine("Food was drawn"); } List data structure is ideal for keeping snake cells coordinates: // Snake list of (x, y) positions private List<Point> _snake = new List<Point>() { new Point(10, 10) }; Point (10, 10) - it is position of the head.

This is a result code: using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; namespace Snake { public partial class Form1 : Form { // Snake list of (x, y) positions private List<Point> _snake = new List<Point>() { new Point(10, 10) }; // Snake movement direction private Point _snakeDir = new Point(10, 0); // Food private Point _food = new Point(); // Random generator private Random _rnd = new Random(); // Game field size private int _fieldWidth = 200; private int _fieldHeight = 200; // Snake step private int _snakeStep = 10; public Form1() { InitializeComponent(); // Centers the form on the current screen CenterToScreen(); // Set a game field size ClientSize = new Size(_fieldWidth, _fieldHeight); // Generate an initial random position for the food GenerateFood(); // Create a timer for the GameLoop method var timer = new Timer(); timer.Tick += GameLoop; timer.Interval = 200; timer.Start(); } private void Form1_Paint(object sender, PaintEventArgs e) { Draw(); } private void GameLoop(object sender, System.EventArgs e) { Update(); Invalidate(); } private void Update() { // Calc a new position of the head Point newHeadPosition = new Point( _snake[0].X + _snakeDir.X, _snake[0].Y + _snakeDir.Y ); // Insert new position in the beginning of the snake list _snake.Insert(0, newHeadPosition); // Remove the last element _snake.RemoveAt(_snake.Count - 1); // Check collision with the food if (_snake[0].X == _food.X && _snake[0].Y == _food.Y) { // Add new element in the snake _snake.Add(new Point(_food.X, _food.Y)); // Generate a new food position GenerateFood(); } } private void Draw() { DrawFood(); DrawSnake(); } private void DrawSnake() { foreach (var cell in _snake) { DrawRect(cell.X, cell.Y, Color.Green); } } private void DrawFood() { DrawRect(_food.X, _food.Y, Color.OrangeRed); } private void DrawRect(int x, int y, Color color, int size = 10) { Graphics g = CreateGraphics(); SolidBrush brush = new SolidBrush(color); g.FillRectangle(brush, new Rectangle(x, y, size, size)); brush.Dispose(); g.Dispose(); } private void GenerateFood() { _food.X = 10 * _rnd.Next(0, _fieldHeight / 10 - 1); _food.Y = 10 * _rnd.Next(0, _fieldHeight / 10 - 1); } private void Form1_KeyPress(object sender, KeyPressEventArgs e) { switch (e.KeyChar) { case 'w': _snakeDir.X = 0; _snakeDir.Y = -_snakeStep; break; case 'a': _snakeDir.X = -_snakeStep; _snakeDir.Y = 0; break; case 's': _snakeDir.X = 0; _snakeDir.Y = _snakeStep; break; case 'd': _snakeDir.X = _snakeStep; _snakeDir.Y = 0; break; } } } }