After a good discussion with a friend of mine, I decided to take a stab at rewriting, once again, Project Squares, not renamed Project Shooter. So far it’s only ~600 lines, including white space and comments, but it’s quite a bit cleaner, neater, and more compact, not to mention commented to bits!
What it is right now is one character instance moving around, but only in one direction. The direction can be changed to west or southwest right now, but as soon as I get back to it, I think I’ll be able to make mouse control a possibilty, allowing for 360degree movement, which will be really nice. It was really important for me to get that character rotation down, as my old code had really gone to hell, and so I wasn’t able to go through it and make changes to it without a ton of headaches. Rewriting and refactoring was definitely the right choice here for me.
I have several things to implement left though, until I’m back to where I was, pre-rewrite: mouse movement, shooting component, which contains hp, damage dealing, kill tracking among other stats. I have to re-implement a display for the frames per second, incidentally, I created a question over at /r/learnpython and got some great responses, as usual. There’s also the AI component I have to re-implement; all that was was a timer that went off every 1/2 second and either moved or rotated the NPCs. If it saw the player during the rotation phase, it would stop rotating and start firing until the next movement phase. There was still never really a high risk of being hit though, since the enemies still fired in a straight line ahead of themselves, unless there was a high amount of enemies. Addionally, I had made use of a module called txtlib which allows PyGame to print on multiline, as well as color, if I’m not mistaken.
I used the builtin glob package, which crawls along folders, but my understanding of it is embarrassingly limited, but I assume should the need to crawl my folders arise again, I will be able to quickly gain a better understanding.
New in this iteration is the simple function that gives each instance of a character a random name, chosen randomly, using the random module, from a list of American Male Names. It’s only a few lines long, but I still feel pretty smart writing it.
I’ll end this entry with a before and after picture of my shooter.