Friday 27 May 2011

Code explanation

I thought I'd firstly explain the basic structure of my code. There's quite a lot of it now and printscreening it all and putting it into this blog might be a bit of a challenge! I'll try my best though. 

I've added a lot of comments into my code which has been a great help for myself when coming back to the code after a break. A lot of my tasks can only happen under certain scenarios or if a specific item has been collected, it has been very confusing to work with at times. The majority of my game runs through if statements and booleans, which are simple enough. But like I mentioned since there's so many specific circumstances that things can happen, it's been difficult for me to get my head around at times. I'm very pleased I made my flowchart at the beginning of this assignment, as it has been a huge help! I crossed off each task as I completed them. 

Collecting items -
When you click on an item, the alpha is lowered and it's coodinates are moved. (this applies to closing down menus too)
If the item is collectable then it goes into the pocket inventory, into it's corresponding box.  
The first frames of these boxes are blank, the second show the item that has been collected.
Two of my items (strawberries and herbs) have counters on them, 
so when you collect an item it adds one to the correspondong number. (herbbox + berrybox)
I also have an award menu that pops up as an extra bit of feedback so that you know when you've collected an item. 

I had an issue with collectable items reappearing once you leave the room and come back. 
To fix this issue I added in variables for each item, so when the variable is true the item stays off stage and alpha: 0 

Here is an example of how the award menu and collecting a herb works:

function fridgeherb3(evt:MouseEvent):void {
herbhave++; // plus 1 to herb counter 
herbfridgecollect=true; // refers to variable, this stops the herb from being recollected and reappearing
environment.fridge.fridgeherb.x+=1000; 
environment.fridge.fridgeherb.y+=1000; //moves herbs coordinates
award.gotoAndStop("herb");//moves to herb award popup 
award.alpha=1;//makes awards visible
award.x=stage.stageWidth/2;//moves award to halfway point on stage
award.y=164; //moves awards to this y coordinate point
if (pocketinventory.box6.currentFrame==1) { // if you haven't collected a herb yet then
pocketinventory.box6.gotoAndStop(2);//switch to second frame so that herb appears in inventory
}

}

Talking to characters - 
This was by far one of the most confusing parts. I have just one movieclip with all character dialogue listed- and an animation previous to show the speech bubble pop up. I didn't originally have this animation pasted in at the front of every piece of speech, but I ended up getting a bug where it struggled to find the spoken text after playing the animation. To fix the problem I added the animation at the beginning so that it wouldn't have to fuss around looking for 2 separate things. 

I also have all the close speech code inside this movieclip, which ended up causing a few extra issues since the rest of my code was on the main timeline. If I ever made another game on this scale I'd definitely stick to keeping all the code on the main timeline. When looking for a null object error, I found it a nightmare looking around so many pieces of code dotted around all over the place.

This is an example of how the character dialogue code works:

function pom1(evt:MouseEvent):void {
if (strawberryhave >=10 && henclick == true) { //if you have 10 strawberries and eggs
environment.speech8.gotoAndPlay(302); //talk to pom- she'll ask what colour cake you'd like
} else {
environment.speech8.gotoAndPlay(130);//talk to pom - she asks for 10 strawberries and eggs
}
}




No comments:

Post a Comment