Monday, November 30, 2009

Final Post about the Final Case

So, here we are at the end of the road. After about three months. It has been a fun journey, and very educational for my part. I started out not knowing anything about Flash, ActionScript or programming i general. Now I have a nice idea of how things work. By doing all these cases every week i've gathered a lot of info about programming in the ActionScript 3.0 language. From time to time it has been very, very, very frustrating. But I guess that's part of the life of a programmer. And when that time comes, the only thing you can do is sit down before the code and reed through it 'til you find the errors. Well, dunno really if anyone has followed this blog, but if you actually have, I hope it has been worthwhile your time. And maybe learned something yourself. Who knows.. Enough about this. Let me get to the point of this last case. And that is how to put the startmenu, win and game over screens into the game and make the work. In my opinion the most ballbusting and frustrating case, but also a fun one. At least until you run into problems that is ;)

Okay, so let's get down and dirty. I just said that I was going to put all the sreens into the game. But before one takes on such a task you must think of how you want the menus to behave and in how they're stacked. I didn't draw anything, but I made a picture in my head of how I wanted the menu to be. We're talking about a studen making a game in Flash, so the complexity of the menus is rather low. Well, keeping all this is mind, the code itself needs a major overhaulin' because 'til now the game was in the constructor, wich started the game as soon as I pressed Alt+Enter. Now instead of the game staring right off the bat, you want the Start Menu to appear. So basically I had to remove everything I had in the constructor, and make a new function. I called it creatGame, and basically do what the constructor did before. Then I made another new function, that creates the start menu and add eventlisteners for the how to play screen. Then enable the startbutton to run the createGame function. Basically I had to rearrage all my code, and make about 6-7 new functions that intertwined make the menus work. I don't think I'll bother wriing the code here. It'll suffice to say that it was a lot of work. And to my joy I was able to make the start menu and the how to play menu work perfectly. The game over / win screen were more a pain. To make the game over screen work I just added an if in the update function and said that if the players life is zero, or if he falls of the level he dies and the game over screen is to be created, and the game, with all it's objects is to be removed. The win screen on the other had has been everything but cooperative. I almost set it up to work identically to the game over screen, exept that for the win screen to appear the time must run out without the player dying. This oddly enough didn't seem to work. Just the occasional random time from time. I had fellow studens look at my code, I had fellow labassistants look at it. But everything seemed right. Finally I just gave up. My time was running out, and besides turning in the game for evaluation and not flunking the course, I have exams and other stuff to tend to. So I just let it be, 'couse after almost a week of fiddling with that screen I ended up making more bugs. Thankfully I had the code copied before I tried to fix stuff. So, I just hope it's enough to pass. I got everything else down. And I've learned a great deal, so I'm happy with what I've accomplished so far.

Thanks for reading my blog, and maybe I'll keep on writing about school stuff the next semester, who knows.

Thursday, November 26, 2009

Case 10

This is the final case in this project. Once I've completed it I'll be done with the game.

Unfortunatley, I had a setback, so I haven't yet got to this point. I'll post more about it later though.

Ahh! Maybe I should tell you what the case is about :) It is about putting in all the screens. The start screen, win/loss screen, controls etc.

Since I haven't been able to show you previews is a while, I thought I'd upload one now. Just keep in mind that there is still stuff to be fixed :)


Case -- WIP preview by ~Elr0hiR on deviantART

Tuesday, November 24, 2009

Case 09

I'll sum up this case in one post since it is a pretty simple one. And the idea here is to add sound to the game.

This is a pretty straightforward process. You just find the music and sounds you want and import it to your flash file library. Then you prep the sounds to get exported to ActionScript. Coding-wise you just add media at the top like this import flash.meda.Sound; and import.media.SoundChannel; and finally import flash.media.SoundTransform; (for cleaness sake I just added import flash.media.*; the star just means that you import everything from media).
Now, I'll first tell you what these three thing do. Basically it makes it possible to use sounds. The first one enables the soundfiles you want to use, the second one is used to layer the sounds. For instance, you want to have a soundchannel for the themesong and other ingame effects. Then you can use a second channel for the soundeffects you character make. And thid for you enemies.
The last thing you imported was the transform functions wich makes it possible to transform the sounds, like turning the volume up and down. This especially practical when you have soundchannels. Let's say that you really can't hear the soundeffects you'r character makes while ingame due to the theme music. Then you can simply increase the volume on the character soundchannel. And voilá, you fixed the problem, nice and easy.

Let's get back to the code. After importing the media, I added variables for each sound, channel and transform.
Then you just add the variable where you want the sound to appear. Like adding the jump sound in the function that makes you character jump. The themesong at the beginning of the constructor so it starts playing when the scene is created.

This was in my opinion a pretty simple case, and was solved fast without any major problems. I would add a preview, but since I'm revamping the game, things don't quite work as they're supposed to. You'll have wait for the final game to be finished. I wouln't hold my breath though. Even though I'm pretty sure I'm going to have it finished by a week.

Thanks for reading! :)

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

Saturday, November 21, 2009

Case 08

Arrays and timers. What are these you may ask. Well I'll tell ya. Say you want multiple objectes to be created in the scene. In stead of writing 3134 lines of code, you can simply bake one array on a couple of lines that create a set number of objects. Timers are just that; timers. If you want to make something happen for a period of time you need a timer, if you need something to happen after a period of time you ned a timer.
Timers are basically stopwatches you can attach to things, and give them a duration, or whatever you want.

The thing I wanna use this stuff for if for my newly created enemy class. I'm gonna try to use arrays to spawn a set number of enemies on random locations each time.
I'm then going to try to make the player character blink a couple of times when hit by enemies by using timers.

Case 07 - Final

This is kinda late, I know.. Been buisy doing other school stuff so I kinda forgot to blog =_=

So this case was about mutiple classes divided on different actionscipt files. This is called OOP(Object Oriented Programming) and means you write several codes in different files. This makes it easier to arrange stuff, and you can use different classas you create on different elemtents. A nice exaple is veihicles, say you make a base class for different cars, they all share the same base properties, like they drive forward, can turn to the left or rigth. But you might want to make some cars faster than others, and some that can withstand more than others. By making a base class you can just change the properties on the different cars, instead of writing code from scratch for each car.
OOP also gives you a better overview of your code, because instead of having 1000+ lines, you split it up in several files.

That being said, this case was about making a new class for the game, namlely an enemy class. What we're supposed to do here is make a new ActionScript file and start from scratch to write the code. When this is done you can use the enemy class you've created and import it from the main ActionScript code. This saves space in the document, and you can easily browse through the classes and change stuff.

I won't bother writing all the code of my enemy, but I'll tell you roughly what I've done so far. So, I wanted enemies to spawn in the air and fall down to the ground and attack/follow the player. This is done by telling the enemy that if it's value of X is greater that the players, it is to reduce the X value by diminishing the value. In other words, the enemy stive to have the same X vale as the player. This is the most basic enemy AI you can get. But it is enough. At least for me :)
Finally I had to add object detection, wich means that the enemy doesn't go through walls. I did this more or less the same way I added gravity and hitTestPoint to the player. This means that when the enemy hits the ground, he doesn't go through it.

Here's a preview of the game so far.


Case 07 by ~Elr0hiR on deviantART

Monday, November 2, 2009

Case 07

Short about the case:
Case seven is about classes and how we can work with more than one .as file to get more organized. To test this out I'm going to create an enemy class and hopefully make the enemy follow the main character/player.

Sunday, November 1, 2009

Case 06

Game development/design.
The previous week's I've been pondering about the design of the game. Basically figuring out the story behind the game, and the scope.
It's not final but I think I got the disgn pretty much down. The game is going to be a pretty much straightforward platform game, where you gotta pick up points and save the world(nothing less!) :D