Tank game! (and questions)

I thought it'd be nice to keep you guys up to date on my game 🙂. Have fun!

http://tank.noio.nl/view.php?src=tank_game%202008-05-27.swf
[edit] I'm sorry, I've taken the development versions offline. I'll put a new website up soon. [/edit]

Might take a long time for next version because development has branched off in so many directions now 😀
  • saving the map in some nice format
  • adding sound
  • adding GUI
  • developing gameplay
  • triggers


1) By the way, is there a standard/efficient method for processing triggers? Ofcourse I don't want to hard code a bunch of if-statements in the code, but triggers should be part of the map.
2) Also, do you think it would be efficient to encode all my game/map data into a byte-array, then save this byte array as a PNG file, and import that into flash? In stead of just leaving a bunch of const arrays in some static class?
1) Events and Event listeners.
2) If you're talking about file size efficiency, then probably yes. A byte per pixel (if you're using an 8 Bit color palette) is smaller than however many bytes Flash uses to store ints and Numbers. I'm not sure how many bytes Flash's primitives require as consts in the .swf, but they are no less than 4 bytes. Although .swfs are typically compressed, which might help if you have lots of consts that only use the lowest bytes.

...That tank does a lot of wheelies. 😮
that tank had a really nice and spongy feeling =) But it flips over way to easy, if you limit how much it can rotate, one could probably force it up tougher slopes at the same time.
Not sure quite what you want with respect to triggers. If you mean unique scripted events in your game, hard coding is probably the way to go. (though if you want to encapsulate your triggers with your level data, rather than hard coding them, you could have a separate swf for each level containing that sort of stuff). If you mean stuff like "lose 50 health if enemy bullet hits player", then an event framework probably works best (say with an event called on every body for every collision it has with another). Then attach appropriate events to appropriate bodies, based on the bodies categories or whatever. If you mean "the door doesn't open until you hit the button", I would add this as map data, in some simple domain specific language/format. But these are personal choices, and it's a matter of style/your read:write ratio, etc.

I'm sure pngs are a pretty compact way of storing data, but when I tried this (for tile based data, no less), I found it was actually pretty tedious assembling the pngs, which I did manually. Admittedly, nowadays you can create pngs from Flash, so I suppose you can more easily support two formats without writing lots of auxiliary programs.
But I would still recommend loading external text files for map data. Assuming the http stream is compressed, I doubt they are significantly larger than the corresponding png, and they are much easier to work with. Not to mention you don't have to load the levels up front.

By the way the tank game is really shaping up. The controls make it unplayable as a game, but it is good as a tech demo. It's satisfying to not only blow chunks of scenery up, but see those chunks fly all over the place.
Actually, I've read that embedded bitmaps in Flash are stored in a proprietary-ish format, rather than PNG or JPG. I don't know anything about that format other than the fact that it definitely supports alpha channels. It might not be as efficient I thought.

Alternatively, characters in a text file are a byte each, as long as it's not using unicode, so if bytes are your preferred data type, text files might be a useful format.
BorisTheBrave wrote:
Not sure quite what you want with respect to triggers. If you mean unique scripted events in your game, hard coding is probably the way to go. [....] If you mean "the door doesn't open until you hit the button", I would add this as map data, in some simple domain specific language/format. But these are personal choices, and it's a matter of style/your read:write ratio, etc.

Yes, that's more like what I want, My problem is that I don't know how to link the abstract spawning from the map, to the entities that are created when the spawning happens. (like "spawn *a* button" and then "when *that* button is pressed", but it has to be dynamical, and I can't keep too many references to box2d bodies/actors )
Quote:
But I would still recommend loading external text files for map data. Assuming the http stream is compressed, I doubt they are significantly larger than the corresponding png, and they are much easier to work with. Not to mention you don't have to load the levels up front.

I don't think I can load level data over http, as I don't know where the file will be hosted, and some hosts do not allow external data to be loaded right? (newgrounds? deviantart? do they allow you to load data from another site?)
Quote:
By the way the tank game is really shaping up. The controls make it unplayable as a game, but it is good as a tech demo. It's satisfying to not only blow chunks of scenery up, but see those chunks fly all over the place.

Please tell me what you mean with the controls, any suggestions? 😀 I know it's kind of hard to maneuver over steep hills though.
android wrote:
My problem is that I don't know how to link the abstract spawning from the map, to the entities that are created when the spawning happens. (like "spawn *a* button" and then "when *that* button is pressed", but it has to be dynamical, and I can't keep too many references to box2d bodies/actors )

Inside your map data, you can assign unique IDs to various objects, and then use those ids as references rather than Object references. Weak Dictionaries are perfect for this sort of thing.
So, e.g. your (unserialized) map data might look like the following
Code:
[
  {id: "mykey", shapedata: ..., sprite: "KeySprite", keyfor: "mydoor"},
  {id: "mydoor", shapedata: ..., sprite: "DoorSprite"},
...];

Using simple properties like "keyfor" is what I mean by domain specific language. It sounds more like you want buttons to do a range of things, but that's still easily solved with, say "buttontarget", "buttonaction", for a few preset actions like "spawn", "destroy". Obviously, there's limitations to what you can do like that though. And this doesn't solve your problem of what to do when you've got the key, but the door is halfway across the map and hasn't been created yet.


android wrote:
I don't think I can load level data over http, as I don't know where the file will be hosted, and some hosts do not allow external data to be loaded right? (newgrounds? deviantart? do they allow you to load data from another site?)

Yes, this is true. But Flash files themselves should be compressed (in release), so I'd still consider dispensing with images.

android wrote:
Please tell me what you mean with the controls, any suggestions? 😀 I know it's kind of hard to maneuver over steep hills though.

I don't know, this very much affects the nature of the game you want at the end. But what is making it difficult to control at the moment is the suddenness of the acceleration. I expect tanks to take a while to get up to speed, but it goes at full belt almost immediately, usually flipping, for me. To solve the hill problem, you might want to apply some sort of stabilizing force to the tank, so it tends to rock back to a level position.

Original thread: https://box2d.org/forum/viewtopic.php?t=935