Christmas Game – Final Touches (part 3)

I brought my game into class on Monday for some help with the mechanics, since I was having issues with the timer not working correctly and causing the frames to glitch out while trying to run. I thought it would be a good idea to ask for a little help; trying to find information online wasn’t providing the results I needed.

Ant ended up showing me an easier way to count the seconds down on the timer by using the frames themselves – this way, I wouldn’t even need a timer event, which seemed to be the source of the issue.

I needed to add a new variable and EventListener for this, however:

var framesLeft: int = 8 * stage.frameRate;

addEventListener(Event.ENTER_FRAME, update);

Here, it shows that the game will last for 8 frames – I can edit this as I go, depending on how difficult I want to make the game. Of course, since the game is set at 30fps, I needed to slow down the framerate to count in actual seconds, otherwise everything is over before the player even has a chance to do anything. This was done with the function written below:

function update (event: Event): void {
framesLeft = framesLeft – 1;
myTime.text = “” + int(framesLeft / stage.frameRate);
if (framesLeft < 0) {
removeEventListener(Event.ENTER_FRAME, update);
gotoAndStop(130);
}
}

I could show the seconds by dividing the framesLeft by the stage’s framerate, making it an integer and showing it in the text box I’d already had. Once the framesLeft was less than 0, the timer would stop and the game would more to frame 130 (where the game over text was located). All of this worked perfectly, so I’m very glad for this information – hopefully it’ll help others in class with their games when we all have a chance to speak about them again.

Of course, this was all only the beginning. I needed to make the assets and art. I thought the easiest thing to start with was the bear, so I used a reference photo and vector’d the toy in a way that I could easily separate the parts for the player to put together. I then duplicated the layers of the bear parts and created an outlined version for the player to match the parts up to.

 

 

I needed to make sure I edited the code from the primitive shapes I used in the original testing to the parts of the bear. This was easily done by converting the 10 parts to symbols and naming them accordingly. Ie, the part “head” would match up to “targethead”, in the same fashion “green” would have matched up to “targetgreen”.

body.buttonMode = true;
body.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
body.addEventListener(MouseEvent.MOUSE_UP, dropObject);

rightarm.buttonMode = true;
rightarm.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
rightarm.addEventListener(MouseEvent.MOUSE_UP, dropObject);

leftarm.buttonMode = true;
leftarm.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
leftarm.addEventListener(MouseEvent.MOUSE_UP, dropObject);

head.buttonMode = true;
head.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
head.addEventListener(MouseEvent.MOUSE_UP, dropObject);

leftleg.buttonMode = true;
leftleg.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
leftleg.addEventListener(MouseEvent.MOUSE_UP, dropObject);

rightleg.buttonMode = true;
rightleg.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
rightleg.addEventListener(MouseEvent.MOUSE_UP, dropObject);

I followed the same pattern as the code in testing and it all seemed to work without any errors. The pieces dropped into place and the timer caused the scene to end. Eventually, I completed the scene assets:

finalscene

The player would have 8 seconds to drag and drop the bear parts into the corresponding spaces. This sounds like an easy task, but the parts have to match up very closely and they’re quite spaced out across the shelves; just enough to make it a challenge, in my opinion. I’ll have to see what others think on Friday if/when we’re given time to work on the games in class.

Finally, someone suggested to add in a countdown into the game, but I also needed a way to tell the player they’d won, rather than just a game over. I thought about the best way to alter my script and decided to add in an if/else condition for the update function. If the framesLeft was less than zero, it would go to the game over screen (indicating you lost). However, if the framesLeft was greater than -1 (so the timer would hit zero on-screen) and all of the bear parts matched the x coordinates of the target locations, then the player would be taken to the “you win” frame.

function update (event: Event): void {
framesLeft = framesLeft – 1;
myTime.text = “” + int(framesLeft / stage.frameRate);
if (framesLeft < 0) {
removeEventListener(Event.ENTER_FRAME, update);
gotoAndStop(130);
} else if (framesLeft > -1 && head.x == targethead.x && body.x == targetbody.x && rightarm.x == targetrightarm.x && leftarm.x == targetleftarm.x && rightleg.x == targetrightleg.x && leftleg.x == targetleftleg.x) {
removeEventListener(Event.ENTER_FRAME, update);
gotoAndStop(136);
}
}

I think the quick game works quite well, but I’ll have to wait for further feedback from the class to see what everyone thinks. In the meantime, I’ll put up a link to the game as it is:

http://www.fastswf.com/872_Bow

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s