This is the first lump of code I'm actually kind of sort of a tiny bit proud of.rPhalanx2
A pretty simple semi-bullet hell engine in the sirit of R-Type and Phalanx, which is steals its name and graphics from.
I pretty much re-wrote this whole thing after realizing I was hitting a wall with the way I was doing my game's objects. I followed jlnr's advice/method of using gamestates and gameobjects in a way that makes it much easier for all objects to interact with each other. I wanted to take it a step further, though, so I added an array to all gameobjects called "tags", which just contains simple strings. Things like "shot", "player_shot", "enemy_ship", and so on. This way I can do...
self.game.objects.each do |object|
if object.tags include? "some_tag"
...and I can be sure I'm only hitting the objects I want with my callbacks. It also makes it easy to do things like count how many bullets there are, and how many belong to the player or to enemies without having to keep a running tally. Ruby's arrays seem reasonably fast. We can get up to about 150 enemies all firing shots at the player before we start to get any slowdown, having about 300 bullets on screen, give or take. I also have a lot of debug display code running over the gameobjects each frame, so that's probably bogging it a little bit too.
I was inspired by Unity3D, as it makes use of a very similar tagging system that lets you find and act on gameobjects using their tags, though I think the way it does it is that when you tag an object it's registered into a list for that tag, rather then the tag being search for on-the-fly.
I'm sure this can be improve a lot. There are a lot of things that don't need to use the tag system, like things that search for just the player, and other misc ways to make it more efficient. But for small games this should be fine. It's of course still missing a lot, like shots connecting or enemy movement. Just wanted to share.Update:
Holy smokes. Just making enemy fire more efficient by breaking after it finds the player let me go from about 300 bullets at a time at 55fps to nearly a thousand with 60fps and no stutter at all when new volleys are fired. And this is with the player now checking to see if they're hit. A simple distance check, but still. Pretty sure I'm going to be using Ruby and Gosu for any future game jams.Update 2:
Code is a bit cleaner, and enemies now spawn and can be destroyed, with an animation and everything. It's getting to the point it could be turned into an actual game, but I think I'm ready to move on. I tried/learned a lot of things with this mini-project, and I'll apply those going forward. Some things worked well, some didn't, but it was all good learning.