Friday, October 9, 2009

Case 04 - Final

Hello.

This is the final report about the fourth case. I haven't had so many posts for the third and this case, this is because I don't really feel the need of writing about stuffe every other day. As it is getting more difficult, and me not being a born programmer I don't have breakthroughs every day. So I feel it's better is I make an inital post for every case and the sum up how it all went at the end of the week when I've (hopefully) managed to get to the geal :)

So about this case. I'm still having a hard time understanding all the stuff we're going through. Apparently I'm not the born programmer ^^
Anyway, with help from classmates I've managed to get things done. I may not yet fully understand everything, but it feels like I'm slowly learning stuff. I now know that I gotta have a package, I gotta have variables, functions that define the variables, and umm... yeah :)
I'm going to try to explain to you what I've done so far and give you a view of my product so you can test it out for yourself, beacause, yes I was able to make my FlashBob controlable with the arrowkeys :p

First of all I copied my previous case files into an new folder wich I called Case 04. Next up I got rid of fragments of the code that made FlashBob move by himself. Then I had to make new variables. This is what I did:
  • I left the variable for my character be. Then I made variable Booleans (wich basically checks if something is true or not later on). Then I made a variable to define the speed of FlashBob's movement. Set it to 15, wich again means he'll move by 15 pixels, unless I define something else in the function later on.
  • Next up i had to add Event Listeners, these "listen" if any buttons are pressed. And I set it the to check if a KeyIsDown and if a KeyIsUp.
  • Then I added a function that basically stops FlashBob from running out of the stage. This is done by adding conditionals wich ask a question. And the answer decieds what to be done. In this case I told AS that if the position of FlashBob is greater og smaller than the stage width it has to block him.
  • I made a function that decides how FlashBob moves. This is done again by adding coditionals. Since I'll have FlashBob run both to the right and the left I have to add to coditionals, one for each direction. So I got one called leftKeyIsDown and righKeyIsDown.
    • Then I define on what axis I want FlashBob to move, on this case the X axis and then the speed. Since I already have made a variable for that I just refer to it by writing += speed and -=speed. This states that if the left key is down FlashBob will move to the left since it's -= speed, and move to the right if the right key is down because the speed is set to += speed.
    • In the same contitional I also define what frame in my sprite I want to play, my running animation is on the second frame so I tell AS to gotoAndPlay(2).
    • Now, I don't want him to run forward and backward, I want him to always face the direction he's running. This is done by adding another line under the gotoAndPlay. Here I tell AS that then he is running to the left I want to flip FlashBob on the X axis, I do that by writing scaleX = -1. When running to the right i write scaleX = 1. The reason I don't have a + sign is that the original animation of FlashBob is running to the right, so there's no need to flip him over or change his scale.
  • Now I need a function that checks if the keys are pressed. To do this I first make a function that checks if the keys are pressed. And another one to check if the keys arent pressed. I then add the keys I want to use by adding the Key Code of each button. Key Code Overview 
And that's about it. I had a great deal of help on this one... again. I was already having some problems on the previous case, and this was by no means easier. But I've learned a great deal already.
Finally you can check out the product of my hard work here.


Case 04 by ~Elr0hiR on deviantART

On a side note I figured out to add music. You won't hear it it in the preview though. I'm saving this one for the finished game :)

No comments:

Post a Comment