This post is all about taking control. Both of the player character, and of the way the game window is presented to the player. You’ll also see a basic game screen setup I’ll be using for upcoming tests.
For this test, I’ve used the Caged Wave logo as a simple game test room, divided into two zones (thanks to a colleague for the idea). The total resolution of the game screen is 432 by 240 pixels, which is a ratio of 16:9 and should look good on most modern displays.
I’ve added five basic test sprites to the background. The first sprite is a floating head to represent the player, followed by some gold that the player has to collect by solving a basic puzzle, two states of a button that will open a (not so secret) door and a box that the player has to push on top of the button to hold the door open.
These sprites were saved as .PNG files and imported as SDL2-textures in the C++ program that will run this test.
I like to move it, move it
Then, I added some basic code to check for different inputs. Right now, the program checks if the player presses any of the W, A, S, or D keys on the keyboard and moves the sprite up (W), down (S), left (A) or right (D) accordingly.
At this point, there is not yet any collision detection in the code, so the player sprite can move wherever it likes. These limits to player movement will of course be added in a future update.
Sizing up the screen
To get to grips with window scaling options in SDL2, I also added a few zoom states to the test. The game window can be shown in the original (tiny) 432 x 240 pixel resolution, or two zoomed in modes (2x and 3x) that will perform perfect integer scales of the entire game window and all movement within. These zoom modes can be selected by pressing either the 1, 2, or 3 key on the keyboard. Pressing the F-key will toggle a full screen mode.
Below, you can see a video of all the movement and screen options working in this test. In the next blogpost, I aim to have collision detection working and some simple player interaction.
Until next time, take care!