Sonic Platformer Game
Technology
-
Visual Studio (2015)
-
C++
-
GLSL (OpenGL)
-
-
Photoshop
Genre Single Player, 2D Side Scrolling Platformer
Platform PC (Windows)
Development Time 2 Months
Resources Used
Table of Contents
Game Summary
This game was an attempt at creating something like the classic 2D Sonic the Hedgehog games. As of February 20th, 2017, this project has had 2 months of development, and may receive 2 more. The present goal of the project thus is to just get Sonic able to walk around, jump, and move on various surfaces.
Considering how this project is, I could think of no sprites that would suit it better than Sonic's original sprites from Sonic the Hedgehog 1. However I am not certain how the licensing stands on it, so I accredited Sega and Sonic Team as the author, and also added credit to the sprite rippers in the comments section of Resources Used. The sprites were used purely for educational purposes only.
The Background Pieces and Baking in Collision
-
Background Pieces are a combination of the associated sprite, and a height map image.
-
The height map uses Red fill amount to indicate whether it is solid at a given pixel or not.
-
The height map also uses Green and Blue to indicate the angle of that particular pixel of ground.
-
-
Collision is on a per pixel basis
This was the sprite for the background piece I first used for testing out Sonic's ability to move.
This is the height map of that first background piece, areas with no Red indicates that the pixel is solid.
This is the second background pieces height map. As you can see, some of the solid pixels have blue in them (this is an attempt to indicate rotation.
This was the sprite for the background piece I first used for testing out Sonic's ability to move.
BackgroundPieceTemplate and BackgroundPiece Header file
Important Functions from BackgroundPieceTemplate
Getting Sonic Able to Stand on the Ground
-
In order to detect that Sonic is on the ground, there are 2 raycasts performed out from him towards the ground
-
Direction of the ground changes based on what mode Sonic is in (Ground, Right Wall, Ceiling, Left Wall)
-
If no collision is detected, gravity is applied to Sonic.
-
If one collision is detected, then Sonic's relative height is set to that position.
-
If two collisions are detected, then Sonic's relative height is set to the highest of the two.
-
-
The raycast type used is Amantides Woo.
-
The raycast distance and position has to be made relative to the tested background piece and scaled down to the relative size of the pixels when testing. Then those transformations have to be reversed when returning the result.
-
This is Sonic Running and Jumping with the BackgroundPiece debug collision, Sonic's Collision, and the Floor Raycasts being rendered.
This is Sonic Running and Jumping with the BackgroundPiece debug collision, Sonic's Collision, and the Floor Raycasts being rendered.
Important Code for Collision from Agent and BackgroundPiece classes