Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package {
- import flash.display.MovieClip;
- import flash.events.Event;
- import flash.events.KeyboardEvent;
- import flash.events.MouseEvent;
- import flash.text.TextField;
- import flash.text.TextFormat;
- public class finalGameCode extends MovieClip {
- public function finalGameCode() {
- //VARIABLES~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- var dir:String = "stop";
- var prevDir:String = "down"; //checks the previous/current direction and stores it (used in invisCheck fun)
- //set to "down" because boi is facing down u kno
- var walkCheck:Boolean;
- var mapspeed:Number = 4;
- var gameOneOn:Boolean=false; //sets the stage for game 1/establishes that the game can now start
- var gameOneStart:Boolean=false; //actually makes the game itself start
- //ON LOAD~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- var m:mapbg = new mapbg();
- addChild(m);
- var mg:mapguideline=new mapguideline();
- addChild(mg);
- // R O O M O N E ELEMENTS----------------
- var f1:r1flower=new r1flower();
- addChild(f1);
- // a painting
- // R O O M T W O ELEMENTS-----------------
- var t2:r2trigger = new r2trigger();
- addChild (t2);
- //a couple of desks / canvases
- var gbg:gamebg=new gamebg();
- addChild(gbg);
- gbg.x=550/2
- gbg.y=-1000;
- //CHARACTER MOVEMENT -----------------
- var a:MovieClip=new MovieClip();
- addChild(a);
- var left:leftwalk=new leftwalk;
- a.addChild(left);
- left.x = 550/2;
- left.y = 200;
- left.stop();
- left.visible = false;
- var right:rightwalk=new rightwalk;
- a.addChild(right);
- right.x = 550/2;
- right.y= 200;
- right.stop();
- right.visible = false;
- var down:downwalk=new downwalk;
- a.addChild(down);
- down.x=550/2;
- down.y=200;
- down.stop();
- var up:upwalk=new upwalk;
- a.addChild(up);
- up.x=550/2;
- up.y=200;
- up.stop();
- up.visible = false;
- //GAME 1 ELEMENTS =================================
- //game one will be a game where 5 nooses fall at random speeds and you simply have to avoid them as they fall
- //if they happen to hit you, you will have to keep retrying until you can avoid all 5 as they hit the ground
- var nArray:Array = new Array();
- for (var i:Number = 0; i < 7; i++)
- {
- var n:noose = new noose ();
- nArray.push(n);
- addChild(nArray[nArray.length-1]);
- nArray[nArray.length - 1].x = i * 80;
- //the array will be off the screen and will only come when the game starts
- nArray[nArray.length - 1].y -= 50;
- nArray[nArray.length - 1].x += 40;
- }
- //diff speeds for each noose
- var n1speed:Number=Math.random()*2+10;
- var n2speed:Number=Math.random()*4+10;
- var n3speed:Number=Math.random()*6+10;
- var n4speed:Number=Math.random()*3+10;
- var n5speed:Number=Math.random()*2+15;
- var n6speed:Number=Math.random()*2+10;
- var n7speed:Number=Math.random()*11+10;
- var G1t:TextField = new TextField ();
- addChild(G1t);
- //the text will start off the screen and will come when game 1 starts
- G1t.x=55;
- G1t.y=18000;
- G1t.text = "Click to start. Avoid the falling objects. If you are hit, click to try again until you succeed."
- G1t.width = 500;
- G1t.height=200;
- var G1tf:TextFormat = new TextFormat ();
- G1tf.size=12;
- G1tf.color=0xFFFFFF;
- G1t.setTextFormat(G1tf);
- addEventListener(Event.ENTER_FRAME,mainFun);
- function mainFun (evt:Event)
- {
- invisCheck(); // constantly checks if invis
- //directionCommands();
- //walkIntoWall();
- G1setStage();
- G1startGame();
- G1startOver();
- G1beatGame();
- }
- stage.addEventListener(KeyboardEvent.KEY_DOWN, dFun)
- function dFun(evt:KeyboardEvent):void
- {
- if (evt.keyCode==39) //RIGHT KEY---------------------
- {
- prevDir = "right";
- right.play();
- dir = "right"
- if (gameOneOn==false)
- {
- m.x-=mapspeed;
- mg.x-=mapspeed;
- f1.x-=mapspeed;
- t2.x-=mapspeed;
- }
- if (gameOneOn==true) a.x+=4;
- }
- if (evt.keyCode == 37) //LEFT KEY--------------------
- {
- dir = "left";
- prevDir = "left";
- left.play();
- if (gameOneOn==false)
- {
- m.x+=mapspeed;
- mg.x+=mapspeed;
- f1.x+=mapspeed;
- t2.x+=mapspeed;
- }
- if (gameOneOn==true) a.x-=4;
- }
- if (evt.keyCode == 38) // UP KEY--------------------
- {
- if (gameOneOn==false)
- {
- dir = "up";
- prevDir = "up";
- up.play();
- m.y+=mapspeed;
- mg.y+=mapspeed;
- f1.y+=mapspeed;
- t2.y+=mapspeed;
- }
- }
- if (evt.keyCode == 40) //DOWN KEY------------------------
- {
- if (gameOneOn==false)
- {
- dir = "down";
- prevDir = "down";
- down.play();
- m.y-=mapspeed;
- mg.y-=mapspeed;
- f1.y-=mapspeed;
- t2.y-=mapspeed;
- }
- }
- }
- stage.addEventListener(KeyboardEvent.KEY_UP, uFun)
- function uFun (evt:KeyboardEvent)
- {
- if (evt.keyCode == 39)
- {
- dir = "stop";
- right.gotoAndStop(1);
- }
- if (evt.keyCode == 37)
- {
- dir = "stop";
- left.gotoAndStop(1);
- }
- if (evt.keyCode == 38)
- {
- dir = "stop";
- up.gotoAndStop(1);
- }
- if (evt.keyCode == 40)
- {
- dir = "stop";
- down.gotoAndStop(1);
- }
- }
- stage.addEventListener(MouseEvent.CLICK, clickFun)
- function clickFun (evt:MouseEvent):void
- {
- if (gameOneOn==true)
- {
- gameOneStart=true;
- }
- }
- // FUNCTIONS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- function invisCheck() //checks what the previous direction is and makes the other directions invisible
- {
- if (prevDir == "right")
- {
- right.visible = true;
- left.visible = false;
- up.visible = false;
- down.visible = false;
- }
- else if (prevDir == "left")
- {
- left.visible= true;
- right.visible = false;
- up.visible = false;
- down.visible = false;
- }
- else if (prevDir == "up")
- {
- up.visible = true;
- left.visible = false;
- right.visible = false;
- down.visible = false;
- }
- else if (prevDir == "down")
- {
- down.visible = true;
- left.visible = false;
- right.visible = false;
- up.visible = false;
- }
- }
- //function that makes it so the avatar cant walk further if it bumps into any walls
- function walkIntoWall():void
- {
- if (a.hitTestObject(mg))
- {
- trace("hello");
- if (dir == "right")
- {
- //opposite of direction command function
- m.x+=4;
- mg.x+=4;
- }
- if (dir == "left")
- {
- m.x-=4;
- mg.x-=4;
- }
- if (dir == "up")
- {
- m.y-=4;
- mg.y-=4;
- }
- if (dir == "down")
- {
- m.y+=4;
- mg.y+=4;
- }
- }
- }
- function G1setStage():void
- {
- //if the avatar steps on the trigger tile, game one gets setup
- if (a.hitTestObject(t2))
- {
- gameOneOn=true;
- gbg.y=200;
- mapspeed=0;
- a.y=100;
- //bring the instruction text onto the stage
- G1t.y=180;
- }
- }
- function G1startGame():void
- {
- //if game one is setup and you have clicked, game one is able to start, and the noose begin falling
- if (gameOneStart==true)
- {
- //move the text off the screen
- G1t.y=180000;
- for (var i:Number=0; i < nArray.length; i++)
- {
- if (i==0) nArray[i].y+=n1speed;
- if (i==1) nArray[i].y+=n2speed;
- if (i==2) nArray[i].y+=n3speed;
- if (i==3) nArray[i].y+=n4speed;
- if (i==4) nArray[i].y+=n5speed;
- if (i==5) nArray[i].y+=n6speed;
- if (i==6) nArray[i].y+=n7speed;
- //make a hit test object with the person
- }
- }
- }
- function G1startOver():void
- {
- for (var i:Number=0; i < nArray.length; i++)
- {
- if (nArray[i].hitTestObject(a))
- {
- gameOneStart=false
- nArray[nArray.length-1].y-= 50;
- a.y=100;
- }
- }
- //if - hit test object with a and nArray elements
- //-all of the elements of the array go back to the top
- //-text that says click again to restart
- //-then when you click it will loop back to g1startgame function
- }
- function G1beatGame():void
- {
- for (var i:Number=0; i < nArray.length; i++)
- {
- if (nArray[i].y > 400 && gameOneStart==true)
- {
- trace ("hi kill me");
- gameOneStart=false;
- gameOneOn=false;
- a.y=0;
- gbg.x=-10000;
- t2.x=-10000;
- }
- }
- //if all of the elements of the array are off the screen then:
- //-the a returns to a.y returns to 0
- //-the black screen goes off
- //-t2 goes off the screen
- //gameOneStart and GameOneOn = false
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement