04.04.07
Asteroids Completed
Finally got round to uploading my asteroids game for anyone who’s interested in having a play. People seem to like it!
I guess I got a bit carried away and just found myself constantly adding stuff above and beyond the brief. The final version features four different power-ups that appear out of certain large asteroids and a simple health system whereby a single hit from a small asteroid will only damage the ship (reducing its speed and losing the ability to hyperspace). There’s also a fuel variable that depletes according to your speed and when it runs out, you lose the ability to move around the screen, and a timer that gives you only a minute to complete the game. At the end, your score is tallied up taking these things and others into account and you’re given a final score, and a rank, A-E. You get an S Rank if you manage to get 3000 points or over, which I myself have only managed once so far. My top score is 3024 I think, so if you beat that, do let me know!
I know, I’m only going to get like 3 extra marks for all of that extra stuff, but those ideas just kept coming to me and I wanted to see if I could do them.
Well, enjoy!
03.26.07
Asteroids Updates
Been a while since I last updated on this, and I’ve added a lot since my last post, so lets see now..
I’ve got my relatively simple health system in place, whereby a hit from a small asteroid will only change the ship’s state to damaged, rather than destroy it instantly, and it’ll two small ones to lose a life, whereas you lose one instantly when pelted by a big one. Was a bit complex, and some bugs occured that needed fixing, but now it works very well. Frame 5 is the damaged frame, in the ship’s movieclip, and it features some explosions and smoke etc. In the collision with the small asteroid, it simply determines whether the current frame the ship is on is and moves it to 5 if on 1 (after a temporary invincibility animation), then jumps to the dying and regenerating animation if it’s already on frame 5. For both asteroids, if the ship is at a frame other than 1 or 5, it will not affect it, and the asteroid will only explode if it’s shot or causes any damage at all, and only gives you points if you shoot it.
I found an annoying bug where if the ship happens to occupy the same space as an asteroid when it comes out of its temporary invincibility and into frame 1 or 5, it’ll get stuck on the first frame of its exploding animation and will therefore be stuck in an invincible form. Emerging from hyperspace also caused this problem, and it also stopped me from begining the game in temporary invincibility to protect the player from dying straight away. This was eventually solved by sticking a “play();” in the frame actionscript, which it should have been doing anyway, but wasn’t for some reason.
Had a bit of a problem with my arrays as well, specifically removing the asteroids from the array, using the splice method. I could eventually get it to do it correctly in the bullet class, but I also needed to remove them when they collided with the ship too, which wasn’t using a do loop to run through all the known asteroid names. It was all a bit fiddly, and I couldn’t do it, so in the end I just used additional variables to count the number of large and small asteroids, altering on creation of new ones and their removal. This allowed the game to finish when the number of both reached zero.
As an additional feature, I fairly easily implemented a fuel system, where a fuel variable, begining at a value of 1000, declines based on the speed of the ship, divided by a particular amount on every frame. So the faster you move around the area, the faster your fuel is depleted, and when it reaches zero, the moveForward function for playership is disabled, so you lose your ability to travel. Using setInterval, I also created a timer that begins at 99, and counts down the seconds, until you run out of time and the game will be over. It’s actually difficult to make the game last that long, so I think I’ll reduce that amount. It’s all in aid of creatinga more complex scoring system though, as the higher your timer and fuel amounts are at the end of the game, the more bonus points you’ll get, and I want to make sure there are plenty of elements in creating a score that can always be improved upon.
Next, I’m on the xml scoreboard, and it’s proving confusing to say the least. Then, I have the preloader to take care of, and still need to make my stars actually. Then it’s on to more extra stuff, including my final score tally, and powerups!
03.09.07
Asteroids (they explode and everything now!)
That’s right.
Since my last 102 update, my large asteroids now reappear on the opposite sides of the stage whenever they go 50 pixels beyond the boundaries (so you get nice smooth entrances and exits instead of having them just randomly vanish) and they also create two smaller asteroids when hit. This was a bit of bother as at first I wasn’t able to get an array for the smaller asteroids working properly for some reason. Adding them to the existing large asteroid array (as it recommends in the brief, actually) worked but it meant that everytime you shoot a small asteroid, two more appear, which just leads to anarchy. So I went back to the seperate array for them, and I’m not sure what I did differently this time, but it works and I got them to remove themselves when hit, so that’s great.
Today, I also managed to get them exploding too, before removal, which makes quite an aesthetic difference actually. Originally I tried getting the actual bullets to explode on contact, but the large circles they created instantly removed the small asteroids that were created. Making a whole new movieclip just for an explosion didn’t seem to work either, so I scrapped that and just got the two different asteroid sizes to explode, by creating the animations in their respective movie clips, and inserting a label, which is triggered in the bullet actionscript file when it comes into contact with them. I also created a score variable and you get 10 points for the larger ones and 20 for the small ones, as they’re harder to hit. Maybe it makes more sense the other way around though, I don’t know.
I thought that if you complete the game, you’re always going to get the same, maximum score though, so I thought at some point I’d add a timer to the mix which counts the number of seconds your game lasts. At the end, the fewer seconds you took, the bigger bonus score you get, so it should make for a more interesting scoreboard. Next though, I need to get the collision with the ship sorted so lives get knocked down when you hit the asteroids. I also want to make a health system so that it takes two small asteroids to lose a life, not just one. And, because the asteroid positions are all randomly generated, you could theoretically lose a life right at the start of the game if one happens to be put in the middle, so I need a temporary invincibility feature for the start of the game and after you’ve been hit, so that you’re protected for a second or two.
To me this is almost definately the best project yet, and I really think this is the kind of thing I would particularly like to do for a job. I think I might even adapt my own game out of this as a personal project afterwards, and create a scrolling environment beyond the size of the stage. Fortunately, ActionScript has just suddenly clicked for me, and things are actually working properly without too much stress, so I definately want to keep going and try new things with it.
03.02.07
Asteroids
The final assignment for 102 requires us to develop an Asteroids style game in Flash, where the user navigates a small space ship around the stage using the mouse, firing missiles by clicking. The object is to avoid being hit by the asteroids floating around and to destroy them using the missiles. When hit, the asteroids break into two smaller pieces which also need to be destroyed.
Some of this code can be borrowed from the cannon game that we’ve been working on during the lectures, so my first step was to transfer this code into the flash starter file provided, and it contained the necessary actionscript to make the ship rotate according to the position of the cursor, and to fire missiles. My first challenge was to make the ship move towards the cursor, with decreasing speed the closer it gets to it, as shown in the example. This was achieved slightly more easily than expected, and I worked out that for both the y and x coordinates, you subtract the cursor location from the ship location, convert both to a positive value (for when it yields a negative when the mouse is on the other side), add both x and y distances together to get a single figure that represents the distance between the two points. Then state that the speed of the ship is equal to this amount of distance, divided by 50, which ensures a relationship between the two, so the further away the ship is from the mouse, the faster it moves, to catch up to it. Complex stuff, but it’s great when it actually works, and you know you figured it out all by yourself! At first I was trying some sort of complex trigonometry thing, but turns out it wasn’t necessary. Mostly written in the SpaceObject.as file, so it can be reused by something else if necessary.
Today, I started work on the large asteroids, just getting them to rotate and move in a random direction. This would be slightly different code to that used for the ship, because it needs to rotate continually, by itself, yet also move in a single direction, which isn’t influenced by the rotation. In the generate function of the asteroid class, a random number between 1 and 5 is generated which represents both the speed of movement, and speed of rotation. The SpaceObject class then uses a function, called on every frame, to add the current rotation value of the object to this rotation speed. A seperate number between 0 and 359 is also generated to represent a random direction (in degrees) for the asteroid to start moving in, and this is used as a parameter for the moveForward function. The result is 20 asteroids that each hurtle through space at a random speed (rotating accordingly), and in a random direction.
That’s enough for now, but next I’ll be trying to make sure that the asteroids reappear on the other side of the stage when they go off of it, and then start to tackle the collision between missiles and asteroids, and the creation of the smaller ones. So far so good though, and I’m really enjoying this project. Hopefully I’ll have enough time to add extra features such as power ups that make your missiles faster and larger, or perhaps create a health system so that it takes two hits from the smaller asteroids to kill the player, not just one.