Darasimi Makinde Student number 12819403 Registration number w1281940 MODULE: EIGA401.2 FUNDAMENTALS OF (COMPUTER) ANIMATION (EIGA401.2) Coursework assignment 2 Contents Darasimi Makinde ................................................................................................................................... 1 Report: .................................................................................................................................................... 2 Menu ................................................................................................................................................... 2 Game ................................................................................................................................................... 4 Bird Controls ....................................................................................................................................... 6 Bird Function ....................................................................................................................................... 7 Gamestart Function ............................................................................................................................ 9 CaughtfishFunction ........................................................................................................................... 10 MusicPlayer ....................................................................................................................................... 12 External files...................................................................................................................................... 17 Report: Menu The game starts with a menu depicting the title of the game, a summary of the instructions on how to play and a button to actually play the game. This menu is maintained in a movie clip that is placed on the same frame as the game itself. The menu movie clip (referred to as instructions_mc) is simply a movie clip that contains key text as well as another movie clip in the form of the play game button. Pressing said button makes the parent movie clip invisible and starts the timer. Making the movie clip invisible meant that the main game was no longer obscured. I initially tried making a function that simply unloaded the movie clip from the flash movie however numerous errors caused me to simply compromise by making a function that deactivates the play button and makes the movie clip invisible. This presented another problem however in which the music button could not be properly clicked. Again this was resolved by putting the music buttons on the top layer, making it invisible then making it visible after clicking the play button. All of which was accomplished with the following code Object(root).jukebox_mc.alpha = 0 // starting the music buttons out as invisible btnPlay.addEventListener(MouseEvent.CLICK, playFunc); var startSound:clickfx = new clickfx(); btnPlay.buttonMode = true; function playFunc(event:MouseEvent):void { Object(root).timer.start(); //starts the timer btnPlay.buttonMode = false; //deactivates the button Object(root).instructions_mc.alpha = 0; //makes the entire movie clip invisible Object(root).jukebox_mc.alpha = 1; //music buttons are now visible //Object(root).gotoAndStop("gamestart"); } Game The actual game takes place on the same frame but it temporarily obscured by the instructions layer. To remedy this, the timer is deactivated until the player is ready to actually start the game. Apart from the instructions movie clip the game frame contains the bird that you are in control of, a pond full of fish, as well as ambient grass and foliage. On a layer on top of all this there is a frame containing elements of a graphical user interface. This interface contains an indication of the bird’s speed, a mini jukebox (that allows the player to play, pause, stop, increase and decrease the volume of the music track), an indication of the player’s current score and remaining time before the game is over. All the graphics seen in this game were made by me with inspirations from relevant subject matter. The fish for example were taken from pictures of the clown fish. The ambient flowers however were drawn using the art deco tool that flash provides. (the GUI contains the score, speed indication, juke box and remaining time) On a coding level there is a lot going on. It got to the point that I had to separate the game into several functions to make the task seem less irksome. I made a function that establishes the bird controls, the behaviour of the bird, behaviour of the game objectives, the actions to be carried out if a fish is caught, the actions to be carried out to return the caught fish and the count down timer. There is no real win/lose condition for this game. The objective is to simply catch as many fish as you can before the one minute timer expires. The bird moves at a set speed and changes direction whenever it reaches the edge of the screen boundary. The arrow keys speed up and slow down the bird’s acceleration. Pressing the down arrow causes the bird to dive down. If it catches a fish, it carries that fish on its way back to the top of the screen and the position of the fish promptly resets back to where it was before. Bird Controls This function is called using a key down event listener that is attached to the stage. stage.addEventListener(KeyboardEvent.KEY_DOWN, birdControls); The function itself manages the key presses and sets variables that are utilised by the bird in its respective function function birdControls(event:KeyboardEvent ):void { if (event.keyCode == 40 && birdDown == false && birdReturn == false) //down arrow event { birdDown = true; } if (event.keyCode == 39 && birdDown == false && birdVelocity != 15) //right arrow event (has a limit on 15 to //avoid perpetual acceleration { birdVelocity += 1; } if (event.keyCode == 37 && birdDown == false && birdVelocity != 5) //left arrow event (has a limit on 5 to avoid //perpetual deceleration and thus making the speed so low that it goes to negative and actually reverses the direction { birdVelocity -= 1; } } Bird Function This function is called using an enter frame event listener that is attached to the bird movie clip. bird_mc.addEventListener(Event.ENTER_FRAME,birdFunc); This function utilises variables set earlier on in the game do direct the bird’s movement if (birdDir == "right") { if (bird_mc.x > block1.x) { bird_mc.gotoAndStop(1); bird_mc.scaleX = 1; birdDir = "left"; } else { bird_mc.x += birdVelocity; } } As well as managing the direction that the bird moves in, it also utilises a variable that is manipulated by the controls function to determine the bird’s speed (birdVelocity) as well as when to dive. if (birdDown == true) { if (bird_mc.hitTestObject(blockfloor)) { bird_mc.y -= birdVelocity; birdReturn = true; birdDown = false; bird_mc.gotoAndStop(5); } else { bird_mc.y += birdVelocity; bird_mc.gotoAndStop(3); } } birdFlowchart HERE Gamestart Function This is another enter frame function that is attached onto the stage and is arguably one of the more important functions as it assigns the score, and bird speed indicator to its respective dynamic text boxes. It also sets the movement pattern of the fish velocity_txt.text = birdVelocity; score_txt.text = score; { if (fish1direction == "right") { if (fish1.x >= 608) { fish1direction = "left"; fish1.scaleX = -1; } else { fish1.scaleX = 1; fish1.rotation = 0; fish1.x += Math.floor(Math.random() * 10) + 1; //a random number between one // and 10 to keep the movement speed random } } CaughtfishFunction This is another enter frame function that is attached onto the stage that handles the catching of the fish. This was initially put on the game start function but because of an earlier decision to not use arrays, I realised that the function was getting too big to manage, so instead I put it into its own function. if (fish1.hitTestObject(bird_mc) && caughtaFish == false) { fish1direction = "caught"; caughtaFish = true; splashSound.play(); trace("fish1 caught"); } Similarly this was also applied to the function that returned the fish to their starting positions and adding onto the score variable. if (birdReturn == true) { bird_mc.y -= birdVelocity; if (bird_mc.hitTestObject(blockroof)) { if (fish1direction == "caught") { caughtaFish = false; fish1direction = "right"; fish1.rotation = 0; fish1.x = 128; fish1.y = 471; score += 10; } the countdown function is a specific timer event that is attached to the respective timer variable. It creates a countdown timer that starts from 60 and also displays the time on a dynamic text box. When the timer reaches 0 is plays frame two of the flash movie. function countdown(event:TimerEvent) { time_txt.text = String(60 - timer.currentCount); if (timer.currentCount >= 60) { gotoAndStop("gameover"); trace("time's up"); } } MusicPlayer The music player is a self-contained movie clip with its own set of actions applied on to it. //sound.play(resumeTime); var clickSound:clickfx = new clickfx(); var soundReq:URLRequest = new URLRequest("w1281940_music.mp3"); var sound:Sound = new Sound(); var soundControl:SoundChannel = new SoundChannel(); var volumeControl:SoundTransform = new SoundTransform(); var resumeTime:Number = 0; sound.load(soundReq); sound.addEventListener(Event.COMPLETE, onComplete); btnUp.addEventListener(MouseEvent.CLICK, increaseVolume); btnDown.addEventListener(MouseEvent.CLICK, decreaseVolume); function onComplete(event:Event):void { btnPlay.addEventListener(MouseEvent.CLICK, playSound); btnStop.addEventListener(MouseEvent.CLICK, stopSound); } function playSound(event:MouseEvent):void { soundControl = sound.play(resumeTime); btnPause.visible = true; btnPause.addEventListener(MouseEvent.CLICK, pauseSound); btnPlay.visible = false; btnPlay.removeEventListener(MouseEvent.CLICK, playSound); } function pauseSound(event:MouseEvent):void { clickSound.play(); resumeTime = soundControl.position; soundControl.stop(); btnPlay.visible = true; btnPlay.addEventListener(MouseEvent.CLICK, playSound); btnPause.visible = false; btnPause.removeEventListener(MouseEvent.CLICK, pauseSound); } function stopSound(event:MouseEvent):void { clickSound.play(); soundControl.stop(); btnPlay.visible = true; btnPlay.addEventListener(MouseEvent.CLICK, playSound); btnPause.visible = false; btnPause.removeEventListener(MouseEvent.CLICK, pauseSound); } function increaseVolume(event:MouseEvent):void { clickSound.play(); volumeControl.volume += .5; soundControl.soundTransform = volumeControl; } function decreaseVolume(event:MouseEvent):void { clickSound.play(); if (volumeControl.volume > 0) { volumeControl.volume -= .5; soundControl.soundTransform = volumeControl; } } btnPause.visible = false; Ending the game The game ends when the timer has reached 0. When that happens the flash movie progresses to frame two in which there is a game over screen that depicts the players score and an option to replay the game. External files The game also makes use of numerous external files, ranging from the mp3 file depicted in the music player function to parts of the ambient animation such as the background clouds and birds //loading said SWFs this.addChildAt(clouds, 3); // the number next to the variable determines the visual layer for the swf to be generated on var cloudsSWF:URLRequest = new URLRequest("extclouds.swf"); clouds.load(cloudsSWF); this.addChildAt(ambientBids, 4); var birdsSWF:URLRequest = new URLRequest("extbirds.swf"); ambientBids.load(birdsSWF);
© Copyright 2024 Paperzz