First Assignment for Harvard's CS50 Course - Developing the Enemy AI & Player Controller.
Harvard's CS50 spring term has just started, and the first assignment has come and gone. The assignment tasked students with creating an engaging and creative experience using MIT's Scratch tool. Specifically, we were told to implement a project of our choice (be it an animation, a game, interactive art, or anything else), subject only to the following requirements.
- Your project must have at least two sprites, at least one of which must resemble something other than a cat.
- Your project must have at least three scripts total (i.e., not necessarily three per sprite).
- Your project must use at least one condition, one loop, and one variable.
- Your project must use at least one sound.
- Your project should be more complex than most of those demonstrated in lecture (many of which, though instructive, were quite short) but it can be less complex than Oscartime. As such, your project should probably use a few dozen puzzle pieces overall.
With these requirements in mind I set off on creating a game inspired by an arcade favorite of mine, Strikers 1945.
I began the problem set by outlining the scope of my project. I constrained myself to three distinct enemy AI, and focused on executing the core actions available to the player (move and shoot) in order to meet my deadline. Once I had these components completed, I would then move onto more visual aspects of the game (scrolling background, game introduction/tutorial, scoring system, etc).
The first aspect of the game introduced was the player sprite, movement and shooting mechanics. I leveraged publicly available art assets in an effort to maintain a cohesive visual style, as well as a means to provide additional time on refining game mechanics.
Player movement was achieved through a series of conditionally executed statements, iterating within a constant while loop. By checking for arrow key input I was able to determine the corresponding axis to direct the player sprite. The player shooting mechanic followed a similar method of continually checking for a corresponding key press and instantiating a bullet sprite at the current player position. If at any point the player sprite intersected with a defined enemy or bullet sprite, the player would be killed, and a message would be broadcast to end the game.
There are three variations of enemy AI in this game. A base enemy which moves linearly down the y axis, moving at a fixed rate from its point of origin. When the base enemy receives a broadcast message to start the game, a cloned variant of the sprite is created at a random x position and glides to corresponding x positions at the other side of the screen. A secondary "dive bomber" enemy, which as the name suggests dives towards the player. Upon spawning, the dive bomber moves in a fixed line until N distance to player is reached, at which point the AI points towards the player and a dive bomber sound is played. If the AI surpasses a y axis threshold, then the player tracking is disengaged. To implement this, a series of conditional statements are used, checking against the difference between the current player and AI position.
The final enemy variant is a large scale boss encounter. This sprite is spawned only when a threshold score is reached, S % (F + t) = 0, whereby S is the current score, F is a predetermined score threshold (ie. 10 kills) and the number of times the boss has been killed t. This algorithm results in an ever scaling boss encounter system which increases in rarity as the player progresses further into the game.
Upon instantiation, the boss moves horizontally across the screen to various randomly chosen x positions, while shooting a burst of bullets at varying frequencies. This movement and combat system was implemented to provide a more entertaining and dynamic encounter, while maintaining a manageable challenge. To further enhance the encounter a list containing quotes is used for creating taunting boss dialog. Every time the boss completes a movement action a random quote is obtained from the list.
Finally, for all enemies, a continuous while loop determines if any collisions have occurred and responds accordingly (kill clone, play sound, etc).
A link to the game can be found below.