Two Enemies

Leave a comment

April 6, 2013 by jonmillymiles

It’s Easter break for us at University but I missed the last session for our Interactivity for games module. The thought of my tutor stood at the front of the class looking despondently out towards a sea of young faces and finding none his own age. So as I felt guilty I wanted to make up some of the time that I should have spent in class staring back.

Lots has been done, in fact I am having to compare my latest prototype with my old blog post to see just how far I have come.

Suddenly – I have a game.

It’s not refined or robust enough yet to satisfy me. It needs a front end, hi-score table and possibly some other stuff before I am happy, not to mention in-game features that I will add but not dwell on here – you can work most of them out if you know shooters well enough. But… it is a game. It has conflict, goals, rules and interaction. Think of a game without any of these elements… I can’t. Yes there are more that you may wish to add… fun? Do we need fun in a game? Are all games fun? Well… that’s a question for another day.

So far I have a ship, two if you count the drone, movement, weapons, unlimited bullets, engine mechanics, a health mechanism to plug into. But there is something missing… conflict. I need some bad guys!!

I’ve taken my first two bad guys from my Photoshop module that I did last year. I’ve also included the concept for the Player ship.

Player Ship 1

Concept art for a player ship

Enemy Ship 2

Concept art for an enemy ship

Enemy Ship 1
Concept art for an enemy ship
Flash art for my first enemy in my game.

Flash art for my first enemy in my game.

From my experience with the creation of the Player ship I understood that a lot of the detail would be lost in the conversion from Photoshop to Flash so I trimmed a lot of the detail down in production they ended up looking like the one to the right. I opted for the shorter more menacing variant primarily because the shorter form allowed me to increase its size to show more detail. I also added an extra engine in the game which looks quite effective.

Flash art for my second enemy in my game.

Flash art for my second enemy in my game.

I learned a new technique making the purple ship – you can paint using a graphics tablet with Flash. This meant that I could add in the flesh detail much quicker, easier and more importantly with a more natural feel akin to that of the original. What I have noticed with this ship is that the collision detection that I use (which uses a bounding box methodology) does not  work too well with the tail. There is a method using the hitTest function of a movie clip but it only has two modes – inflexible bounding box where the collision area cannot be altered and point test within a shape. The second option is more accurate but will only work for a single point, meaning that complex shapes or those that move rapidly (like some of my bullets do) may not register a hit when needed.

On to my prototypes, or I’ll still be writing this come next Easter…

Just a quick aside on the development – I am also rewriting movie clip code into functions as I go so that I can synchronise and order events properly.

Drone Fire – I began by fixing some of the buggy bullet code in the last prototype, while doing this I also got my lower gun drone to fire and my player controlled drone to fire. This means that at present the player can have in excess of 30 (ish) bullets on the screen at a time… I think I may have a name for my game coming!!

Diagram of the if logic

Sequence of if statements for the bounding box test for a bullet.

Rewrite – This was where I began “functioning” code in earnest. I also added an entity to act as a target so that I could begin to work on the collision detection for the bullets. This was structured in such a manner as to minimise the number of “if” statements that would be processed. By stringing multiple conditions into a single statement you always carry out all statements, my aim was to optimise this process as there would be so many bullets on-screen.  So I set the order as per the picture to the right.

On reflection, looking at the diagram this needs to be changed. the bullet will spend most of its life in front of an enemy, if it is not then technically it has already missed it. Therefore condition 2 should be the last. 3 should also not be grouped together as it compounds statements – I need to do a test with a simple hitTest function to see if there is any noticeable improvement in speed. There may not be, but when it comes to enemy bullets hitting the player I want there to be a level of forgiveness with the detection so this is not wasted code.

Collision Detection and Score – In this prototype I got the collision detection working effectively and to output this I then created a score system. It’s a simple mechanic but it gives achievement and a goal. I also made the target move to random coordinates so that it wouldn’t just rack up the score and I could test some of the logic out in a more robust fashion. Finally I moved the interface around slightly, neatening it all up at the bottom of the screen. I’m not sure if I like it there yet, but for the moment it will do.

Enemy Ship – This is the prototype that I introduced the two enemy ships discussed above. The first acts as a target the second was just there to see how it looked and cannot be interacted with. However I have altered the target code so that the ship moves across the screen and that the ship disappears when hit and returns at a random y-value. I have noticed though that there is an annoying “stutter” to the bullets as they hit the target or move off-screen. I couldn’t work out what caused it though, at this point.

Enemy Ship Functions + Player Collision – You could argue that this should be two, or more, separate prototypes. I could argue that I got carried away and forgot to save a new version: either way we would both be right 😀 In this version I transferred the code for the enemy ship into functions which then allowed me to use a game timer to call the enemy ships at set intervals. I also created a player collision model so that the enemy ship would cause damage if they hit the ship – in time this will be expanded to include enemy bullets. Finally I tested the code for the gun drones by turning them off. This enabled me to check that I could and to control the number of bullets being fired at the enemy at once so that I could test effectively.

I forgot to change the name!!! – In this prototype I reused my code for using arrays to create multiple bullets to give me an engine to create multiple enemies. I now have instances where there are two enemies on the screen at once. The game also randomized which enemy appears and it is now only a small step to give each enemy their own attack profile. I also fixed the stuttering bullets. The problem was in the code for processing the array of bullets. When a bullet was destroyed it would remove an element and then advance to the next value, effectively skipping a bullet out and causing it to stutter as it moved.

Please download the Flash files and have a play… constructive feedback is warmly received.

Wow. When I look back at what I have done over the past couple of weeks I can say that I am quite proud of myself. But there is never time to rest on ones laurels… there are always other people who could apply for “my job” 😀


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog Stats

  • 11,659 hits

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 580 other followers


%d bloggers like this: