Sunday, November 22, 2009

Case 08 - Final

In this case with arrays and timers I decided to use them on my enemy class. What I did was make an array that creates 5 enemies at the top of the screen, but placed randomly each time. Then I added gravity to them so that when they spawn, they fall to the ground and follow the player. In my head this worked better, so I donæt think I'll be using this for the final game. But I did get to implement both arrays and timers for the case so I'm pretty content with that. I would upload a preview but as I started to work on the next case I accidently started working on my case 08 so for the time being a lot of stuff is screwed and not working >_>

Anyway, I'll tell you a little bit aout arrays and timers. At least what I've understood 'til now.

Basically when you make an array, input a number and then you can manipulate it. Like adding more to it, subtract og make it go through the numbers and start again from zero. You can do this by using the .push, .splice and .pop commands. You use this command under the array when you descibe what you want to create with the array.
In my case I wanted enemies, so I wrote the basic code to place an object in the scene;
blobb = new BlobbMain();
blobb.x = math.Random/1000; // this gives me random numbers from 0 to 1000, wich is the width of the scene
blobb.y = 0; // I want them to spawn at the top of the screen.
blobbArray.push(blobb) // blobbArray is the name of the array, and (blobb) is the object I want pushed in the array.

I still don't fully understand the arrays, but I'm getting an good idea to what it can be used for. I'll move on to timers. I wanted my character to blink when struck by enemies or when dying. I decided to go with the latter.
To do this I made a timer called "blink" like this:
var blink:Timer = new Timer(150, 20);
The numbers are the time - I want the character to blink - in milliseconds. When this is done I also make a new boolean and basically make a function to check if the player hits the enemy, if it does and looses all life, it starts to blink and then disappears, and you're dead. :)

And that's it for now :D

No comments:

Post a Comment