Python Project

About This Section

This thread documents the progress on my Python sci-fi themed game project. This project is being developed in an informal setting, used to test out my programming capabilities of object-oriented programming and sub-routines in Python. The current game version can be downloaded from this link if you'd like to test it out yourself: Spacecraft Defence Game GitHub Repo. The performance of the game seems to run without any major bugs, perhaps only with the exception of some sub-standard path-finding algorithms for procedurally generated sprites. If you have any thoughts or adjustments you would like to share with me, feel free to drop me a message on Instagram, or send me an email at anthony.wk.ma@gmail.com. I'd greatly appreciate any constructive input!

- - - - -

Creating an Executable

demo 5

16/04/2022

After a number of small additions, the first version of the game was ready for use. I created an executable file which contains all the packages the user would require to run the application. The executable was placed as a downloadable in a public GitHub repo for all to access and install.

- - - - -

New Enemies, Ability Buttons, and Pausing

demo 4

14/03/2022

Since the last update, a number of features have been implemented:

  • A main menu is added, reached by using the [ESCAPE] key. The game will automatically pause when this menu is open. The game will open to this menu automatically.
  • A new building Docking Port was added, which procedurally produces a Starling sprite upon placement. This sprite will move towards enemies within the building's range, and attack when within its maximum range.
  • Repositioned the animations of the avatar, enemies, and avatar turret to have a point of reference to their centres.
  • Fixed a glitch where moving sprites would appear to vibrate when positioned close to either the same axis positioning as the avatar.
  • Buttons now light up when the player's cursor hovers over them.
  • Enemy health bars now centre above elongated enemy dimensions.
  • On the main menu, the Play button converts to Resume once a game has started.
  • The ability to reset the game is created.
  • The game now ends when the player's avatar health meets zero. They have the option to either quit, or play again. If the latter, the game resets itself.
  • A provisional kill count was added to tally up the number of enemies killed during the game. The presentation and format is currently subject to change.
  • A range of audio sound effects were also added. Some proved a little harder to implement, as they were required to play only once while its primary condition remained true for a prolongued duration of time. The work-around was to create a secondary condition that would act as a toggle, stored as a variable evaluated either in the main loop, or as a class attribute. The range of behaviours for these sounds required having to form multiple solutions for each sound effect.

- - - - -

New Enemies, Ability Buttons, and Pausing

assets

14/03/2022

Over the past few days, more features have been included into the game, consisting of:

  • Fixed Taurus Cannon firing animation: the cannon originally fired from the centre of its image frame. The animation now draws from the ends of both its cannon barrels. This required an additional few lines of basic trigonometry.
  • Added smaller versions of ability/upgrade buttons to the screen when the construction menu is closed. These are listed down the height of the screen's left side to minimise the ocerall screen occupancy. They also only appear when there is a sufficient amount of resources for the corresponding button.
demo 3

Pausing was also implemented. A 'Paused' tag was added, situated either above the top right of the construction menu when it is open, or relocated to the bottom right of the screen when the menu is closed. Only certain parts of the code are intended to be restricted by this pausing condition, as the progression of animations are still preserved, despite taking no effect on the game objects. This allows for certain pausing effect which I particularly liked. Construction menu functionalities are also required to work when the game is paused. The following aspects are halted by the pausing feature:

  • Damage inflicted by the avatar turret, avatar drone, towers, and enemies.
  • Avatar's auto-regeneration.
  • Rotation of idle towers.
  • Decrementation of drone timer.
  • Incrementation of enemy generation interval.
  • Accumulation of credits.

- - - - -

Upgrades, Building Costs, and More

demo 2

Updated construction interface, with drone deployed.

06/03/2022

A large amount of progress has been made since the last update. These include:

  • New 'Dreadnought' enemy has been created.
  • When in range, enemies will stop moving to fire.
  • A contruction menu has been fixed: The building selected will not change if the player drags their cursor along the different menu options after already selecting a building.
  • Impact animations were created for all firing objects.
  • Upgrade buttons were added to the construction interface, and light up when sufficient resources are reached.
  • Health-related upgrade costs increment by 500 credits each time they are purchased.
  • Build costs for each type of building double each time they are placed.
  • Doubling is undone when the respective type of building is demolished.
  • Abilities include increasing auto-regeneration rate, and increasing maximum health capacity.
  • Abilities also include a drone that is deployed for a limited amount of time. Attainment cost does not change each time it is deployed.

- - - - -

Refactoring, Avatar Health, and Enemy Attack Range

01/03/2022

Some light work was made today regarding this project. Firstly, the code in the main game file was refactored, and some variables and parameters were adapted for reusability and readability purposes. I also allowed for enemies to had different attack ranges, depending on their variation. Since they do not have any unique functions, enemies can easily be created using only one class for now. I have also set up the features to upgrade the avatar's auto-regeneration [1] and maximum health [2] attributes, given that the player has sufficient credits.

- - - - -

Game Logic, Aesthetics, and More Fixes

28/02/2022

Today's variety of tasks completed included the following:

  • Outlines of asset drawings were changed to black.
  • The main avatar and its turret were completely redrawn.
  • A new enemy type was added to the game.
  • The turrets will now stop firing at enemies who manage to travel back out of range.
  • The main avatar, turrets, and enemies have been given animations.
  • Power is now properly deducted whever a power plant is demolished.
  • The main avatar can now receive damage, and health is displayed in a health bar at the top of the screen.
  • During low-power mode, turrets will be subjected to a penalty, which reduces their damage output.

- - - - -

Avatar Attacking Capabilities, Tower Variants, and Fixing Refineries

26/02/2022

The avatar can now attack enemies. When the player fires at a certain coordinate, enemies whose hitboxes overlap this position will have health deducted from them.

taurus cannon

Taurus Cannon
This is the standard type of cannon. It requires the least amount of credits and power to operate.

rail cannon

Rail Cannon
This cannon deals more damage than the Taurus Cannon, but will require more credits to build, and more power to maintain.

plasma cannon

Plasma Cannon
This cannon inflicts the largest amount of damange to enemies, but currently requires the most resources to build and maintain.

Introducing these variants of towers required some refactoring in the building classes, rehousing the more specific characteristics of these towers into subclasses. New buttons were also added to the construction menu.

There was also an issue with refineries still remaining active, despite them being deleted from the map. This was because the mechanisms monitoring the presence of refinery buildings were independent of the accumulation of credits. As a result, the number of refineries were monitored by scanning the placed buildings for the specific Refinery class type, which now act as a scale factor for incrementing credits for each cycle.

- - - - -

Building Demolition

demolition

Class method for a 'Buildings.py' class.

23/02/2022

The focus this time was implementing the feature of deleting existing buildings [T] on the map. The first task was to create a new class method which would delete the class object from the relevant array which contained these instances, and removes the coordinates which the building occupied from the array which stores all occupied coordinates. The class method ultimately returns two values: the power required for the building to run, and a discounted sum of credits as a proportion of its initial build cost. The discount was made to become a fixed and global variable for standardisation. The option to build from the construction menu was restricted to not being in demolition mode. When in demolition mode, the cursor is also reskinned to a new icon.

There were also a few bug fixes for the existing code, which allowed buildings to be built, despite having insufficient credits. This issue has also been resolved. I also added a health bar above each enemy, which appears only once they have received at least one hit of damage.

- - - - -

Previous Progress

demo 1

Demo image of current state of game.

Prior to logging my progress on this site, here are the following capabilities that were accomplished:

  • Player avatar is able to move freely across two dimensions.
  • Avatar turret rotates corresponding to the relative position of the player's cursor.
  • Player is able to pull up a construction menu [E] and select a variety of animated building options to place onto the map.
  • When player hovers over a building option, building info is displayed.
  • Player is able to pull up a grid [R] as a guide to see where building placements are valid.
  • Buildings clip to grid co-ordinates when player places a building anywhere on the map.
  • Buildings placed on the map have animations.
  • Map positions are rendered invalid if the centre of the candidate building to be placed is over an occupied grid co-ordinate.
  • Player can remove all additional options such as construction menu and grid display [Q].
  • Production buildings are able to accumulate resources (power and credits).
  • Starts of the resources display are present (power and credits are displayed on screen).
  • Enemy pathing is created, such that they will always travel towards the player's avatar.
  • Turrets will lock onto the nearest enemies in range and deduct health from them.
  • When an enemy has no more health, they are deleted.
  • When player incurs insufficient power, production is slowed down by a factor of 0.5.

* * * * *