Mar 30, 2016

Entry #4 - Some Code

I was really happy with how this game, Space Fight, turned out. Since I had already worked with GameMaker in the past I didn't really have to waste any time learning how it works, and was able to jump right in designing and building my game. Gamemaker does a lot of functions using a drag-and-drop GUI, but a lot of the stuff I added in had to be hand-coded. One piece of code I liked was the healthbars I added in. GameMaker has a function built in that draws healthbars for an object, and I followed this tutorial to help me, but I was really happy how they turned out. This is the code for them:
This code takes arguments for location and bar size, the variable that the ship object uses for health, in this case health1 and health 2, and then the various colors used in the bar.
And this is what they look like in-game:
The second thing I really liked was the addition of gamepad support. When played on the keyboard my game feels a little cramped and players seemed to focus more on fighting the controls than on the game itself. Gamepads removed that probably and allowed players to just focus on playing. The controls felt natural to me. I used information from this blog post, and some of the code for gamepad support is below:

The first block is code that fires when the system detects a controller is plugged in. It defines the deadzones for the triggers and buttons, and then creates a player object and assigns the controller to the player object.

The second block is the logic for doing 'normal shots'. Pressing the trigger creates the instance and the specified location - the front center of the ship - and then gives it a speed of 15 and a direction of 90, which will make it shoot straight up. It then plays a sound and sets the can_shoot variable to false, which sets a cooldown timer until the player can shoot again.

One other thing that I liked, and something that changed as I worked, was the title screen I made for the game. The original title screen was made before I had gamepad support, and I wasn't a big fan of it. This is the original:

Then, as I worked and added more concepts and depth, I ended up with this:
So as I worked, the main thing I added was the gamepad support. Then I realized that gamepads had 8-directional movement with the analog stick, but keyboard users could only move in 4 directions. So I implemented a velocity variable that allows the player to move in all 8 directions with the keyboard. During playtesting I noticed that players were intentionally moving towards each other to be on the same horizontal level which made the game a stalemate. To combat this I added the black hole, which wounds players if they go near the center of the screen.

There's a few things I'd still like to add. I'd like the players to be able to rotate so they could shoot in any direction. This would make the black hole unnecessary, since players could just turn and shoot. Barring that, I'd like to make the bullets slightly curve towards the black hole to kind of simulate the gravity. I'd also like to add more players to create teams, which I feel would add some more strategy to the game. More levels and ship colors/types are also on the list of changes I'd like to make.