Not insulting at all bro, I am fine with critisism.
Just so you know where I am coming form for this project, my coding experience is about 90% uController work with just a little C++ for writing drivers for my hardware and a light mixture of SQL and Python for managing and interpreting data.
My code style sounds like the polar opposite of yours, In my work we put very little emphasis on readability since we need to make the most out of restricted resources (512 bytes of data space, 4KB of code space being fairly typical). So PC coding and Python in particular feels un-natural and wasteful, wasting bytes by the handful even… while I prefer to store 8 different boolean variables in a single byte if I can.
Ultimately I am here to gain more experience and your approach would be much better suited to this enviroment. I will have a read through your code to get a handle on your style and if you have any reference materials I could read, it would be appriciated.
As for my design choices so far:
I had been planning on using a standard object class to be interperted differently in differnent contexts. Eg:
- Enemy objects list containing the prototypes of different enemy types for copying into the active list for spawning,
- Player objects list for storing different player objects that could be swapped out if the player picks up a power-up (Altering sprite, health, and what other attributes eventually get added to the object)
- Misc objects being cosmetic only, with the health attribute decreasing every frame to ultimately timeout and despawn the sprite after the set period of time.
- Bullet objects being assigned move_x and move_y attributes on spawning with no specified AI so that they continue moving in their specified direction. Just like the Misc objects, their health decreases every step to despawn the bullets after a specified period, resulting in bullet range.
In these cases, the context for processing are selected by the specific list the object is loaded in and the behavior string used to vector to different AI functions.
- Player list is not passed into the AI_processing function, is passed into collision detection, is passed into game_update function.
- Enemy list is passed into AI_processing where object behavior attribute vectors the AI function call, is passed into collision detection, is passed into game_update function.
- Bullet is passed into AI_processing function (MISC behavior to decrease health as a timeout), is passed into collision detection (Is basically what bullets do) and is passed into game_update function.
- Misc is passed into AI_processing function (using same AI as bullet to timeout and expire the object), is NOT passed into collision detection as intended for cosmetic sprites, is passed into game_update (for despawning on expiration).
I admit it would probbably be understood better to make seperate classes for these objects.
The file ai.py has been depreciated since I grabbed the relevent functions from there and put them in the processing related file proc.py as the AI functions are all called along side the processing functions (Deciding actions vs Actioning them). For what ever reason it wasn’t removed during the push.
Ultimately I was planning to group functions as modules (Eg Object handling, Processing/AI, etc) together in seperate files with an API allowing their various functions to be called by the higher level code in main.py. This way the files holding the underlying code can be pulled out and replaced provided they use common function calls to make things easier for developing with multiple people.
Eg Collision detection is written by Person-A. We start with a simple method of drawing rectangles around the sprite locations and scanning for overlaps in their boundries as a quick and dirty method. The file collision.py contains definition for the collision detection function call allowing an object to be passed along with the active-object lists returning an ID of a detected collision.
Later in the project, we have time to improve on this by using masking for collision detection for more accurate detection. Person-B writes an alternate collision.py containing the same function call as the one written by Person-A. Once completed and tested, the file is swapped in the master branch replacing the underlying mechanic without needing a re-write to the higher level code.
Edit:
Rechecking the repo, The following files have been depreciated and should be removed:
- objlist - original text file holding object information. Has been replaced by data/object.json
-
init.py - original functions for parsing objlist into game object prototypes. Has been replaced by obj.py
-
ai.py - I don’t see it listed anymore but you mentioned it earlier. relevent functions have been merged into proc.py (Processing functions).