Weapon Pickups
Currently I have just two guns in my game, a revolver and a shotgun. The task for the first part of today was to make these weapons into pickups, so that the player could change weapon from one to the other. To do this I created two new objects, 'objShotgunPickup' and 'objRevolverPickup'. These are the objects that will lay on the floor, and which will spawn when an enemy drops a weapon or the player opens a chest. When the player collides with these pickup objects, they will be able to press 'E' to change weapon. This destroys both the player's current weapon and the pickup they just interacted with, and creates a new weapon on the player that corresponds with the pickup (eg. objShotgunPickup' will be destroyed and the player will spawn a new 'objShotgun' that they can shoot). This weapon pickup code has been stored in a script, so that when it comes to adding the other weapons I want to incorporate into my game, it will be a simple task.
 |
| The script for weapon pickups - 'argument0' is a variable stored in each weapon object's Create event |
Shotgun Spread
The next task was to make the shotgun into a proper shotgun, and give it bullet spread. My first port of call for this was to use the
random_range function on the direction on each bullet. I found this spread the bullets well, but that it wasn't consistent (obviously, it's random) and the bullets would often clump together in direction. Whilst real shotguns may have an element of unpredictability in the spread of the shot, this makes for frustrating use of the shotgun in a game, as the player doesn't feel that they can trust the weapon and line up their shots properly, and as a result they just won't use it. The solution I settled on was to use a
while loop.
 |
| Shotgun firing code, using 'spreadAngle' variable in conjunction with the while loop to create bullet spread |
The
while loop will check the expression at the top (whileNumberOfBullets...) and will run the code inside the curly braces for every step that that statement is true. In this case, our shotgun can shoot 5 bullets each shot, so the loop is checking every frame whether all 5 shots have been fired. If not, the loop will run, and will create a new bullet. It is important with loops to make sure they have break statements, or they will 'hang' your game and it will crash. The break statement in this case is the 'numberOfBulletsFired' variable, which every time a bullet is fired has +1 added to it. Then, the if statement below the loop is waiting for all of the bullets to have been fired, breaking the loop, and stopping any more bullets being fired. This loop allowed for multiple shots to be fired out almost simultaneously.
To make the bullets spread evenly, that is where the 'spreadAngle' variable is used with the loop. In the shotgun object, the 'spreadAngle' variable is created with a value of -5. When the first bullet is fired, it's direction is the gun's direction -5 degrees. Then, 2.5 is added to 'spreadAngle', so when the loop runs next time the direction of that bullet is the gun's direction - 2.5 degrees. This continues, and the effect is that each bullet is fired slightly to the right of the last, creating a bullet spread effect. The values can be tweaked so that the spread is even if necessary. When the alarm[0] is triggered, the 'spreadAngle' is reset to it's original value, so that next time you fire the same spread will occur. This gives consistent bullet spread that is fair and predictable for the player, making the shotgun a viable choice.
Reloading
At this point, each weapon had a fire rate alarm, meaning a shotgun can only be fired once every second, or a revolver three times a second, however these guns can shoot indefinitely without the need for reloading. I implemented a reload system,
 |
| Reload system flow through different actions and events |
The first box, the 'objShotgun Create' event, establishes the variables for how much ammo the gun has and how long it takes to reload. The second box is the 'Step' event for the shotgun, and this is checking firstly that the player is pressing the reload key, and then if there are any empty slots that need reloading. If this is true, then the 'scrReload' script is run, the next box down. This script takes the 'reloadTimeInSeconds' variable from the create event, and multiplies this by
room_speed to set the alarm time. Then, when the alarm is triggered after two seconds, the gun is reloaded by setting the current ammo to the maximum allowed for that gun.
The aim is to have an 'active reload' system in Gun Smoke, a system made popular by the Gears of War franchise. This is where you hit reload once to start the reload, and there is a point during the reload where if you hit the button again you will reload quicker and also gain a damage boost for the next clip of bullets, however if you screw up and hit the button too early or too late, then your gun jams and it takes even longer to reload than usual. It is a risk/reward decision, but importantly it adds a skill element to reloading, an otherwise frustrating and boring formality of shooters, whereby if you master the active reload you can mow down enemies more efficiently than ever. My game is going to be simple in terms of scope, so I think it's important to have elements like this in there in order to increase the skill ceiling wherever I can.
 |
| A diagram of the active reload system in Gears Of War |
Tidying Up
The last thing I did today was tidy up my code. I tried to eliminate breaks and blank spaces between code lines, I indented the nested elements of
if statements to make it clear which part of the statement was the outcome and which was the trigger, and I commented everywhere I could. Commenting is important for working on projects such as this, where you will be coming and going between different areas of your code. For example if I came back to my room generation code in four weeks time, I might look at it and not be able to make sense of it, whereas if every line is commented, explaining what it is doing and why, then it'll make it much easier to pick up where I left off and find the areas I am looking for specifically.
 |
| A GIF showing weapon pickups, from revolver to shotgun. The long pause between shots is the reloading |