Wednesday, September 12, 2012

Be able to use Action-Script for game programming

ACTION SCRIPT DEMO ~ Script.
Variable this creates a string variable having no value … //**************VARIABLES**************/ var gameState:String; //*********BEGINNING STUFF**************/ endScreen.visible = false; End screen is a movie clip and it is making the movie screen false. //**************INTRO SCREEN**************/ introScreen.play_btn.addEventListener (MouseEvent.CLICK, clickAway); function clickAway (event:MouseEvent):void { moveScreenOff (introScreen); } First line: A movie clip called intro screen that has a child called Play button. Adding an event listener to add a function called click away. function moveScreenOff (screen:MovieClip):void { screen.x = (screen.width)*-1; gameState = "INITGAME"; addEventListener (Event.ENTER_FRAME, gameLoop); } function moveScreenOff (screen:MovieClip):void It is THE function. Screen. x is the axis. gameState = "INITGAME"; Game state remembers the word- “INITGAME”- Finds a function to run “INITGAME”-Event listener. INITGAME is just the value-name of the variable. //**************STATE_INIT_GAME**************/ function initGame ():void { trace("add stuff to initGame") gameState = "STARTPLAYER"; } //**************STATE_START_PLAYER**************/ function startPlayer ():void { trace("add player stuff") gameState = "PLAYGAME"; } //**************STATE_PLAY_GAME**************/ function playGame ():void { makeEnemies (); testForEnd (); } function makeEnemies ():void { } function testForEnd ():void { gameState = "ENDGAME"; } function showResults ():void { trace ("Show Results"); endScreen.play_btn.addEventListener (MouseEvent.CLICK, clickFinalAway); function clickFinalAway (event:MouseEvent):void { trace ("clickFinalAway"); moveScreenOff (endScreen); } } //**************STATE ENDGAME**************/ function endGame ():void { removeGame (); endScreen.visible = true; removeEventListener (Event.ENTER_FRAME, gameLoop); showResults (); } //**************REMOVE GAME**************/ function removeGame ():void {






No comments:

Post a Comment