Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import flash.display.MovieClip;
- import flash.events.Event;
- import fl.motion.MotionEvent;
- import flash.events.KeyboardEvent;
- var batspeed:Number = 10;
- //Regra 4
- var velocidade:Number=4;
- var up: Boolean = false;
- var down: Boolean = false;
- var up2: Boolean = false;
- var down2: Boolean = false;
- //Regra 1
- var Bola:MovieClip= new Ball();
- stage.addChild(Bola);
- var BolaX:Number=1;
- var BolaY:Number=1;
- //Regra 2
- Bola.x = 275;
- Bola.y = 200;
- //Regra 1
- var Start:MovieClip = new Begins();
- stage.addChild(Start);
- Start.x = 275;
- Start.y = 200;
- //Bola pelo stage
- stage.addEventListener(Event.ENTER_FRAME, OnEnFr);
- function OnEnFr (e:Event):void
- {
- //Regra 4 e Regra 5
- Bola.x += BolaX * velocidade;
- Bola.y += BolaY * velocidade;
- if (Bola.y >= stage.stageHeight - Bola.height)
- {
- BolaY = -BolaY;
- }
- if(Bola.y <= 0)
- {
- BolaY = -BolaY;
- }
- if (Bola.x >= stage.stageWidth - Bola.width)
- {
- BolaX = -BolaX;
- }
- if(Bola.x <= 0)
- {
- BolaX = -BolaX;
- }
- }
- //Regra 1
- var Batedor1:MovieClip= new Player1();
- var Batedor2:MovieClip= new Player2();
- stage.addEventListener(MouseEvent.CLICK, OnCl);
- //Funcao que vai adicionar batedores, placares zerados
- function OnCl (e:MouseEvent) : void
- {
- stage.removeEventListener(Event.ENTER_FRAME, OnEnFr);
- stage.removeChild(Start);
- stage.removeChild(Bola);
- stage.addChild(Batedor1);
- //Regra 7
- Batedor1.x = 4;
- Batedor1.y = 200;
- stage.addChild(Batedor2);
- //Regra 8
- Batedor2.x = 546;
- Batedor2.y = 200;
- stage.addChild(Bola);
- //Regra 2
- Bola.x = 275;
- Bola.y = 200;
- BolaX = 1;
- BolaY = 1;
- }
- //Código para movimento de bola, colisão e limites
- stage.addEventListener(Event.ENTER_FRAME, BallIG);
- stage.addEventListener(Event.ENTER_FRAME, placares);
- function BallIG (e:Event) : void
- {
- //Velocidade Inicial da Bola
- Bola.x += BolaX * 4;
- Bola.y += BolaY * 4;
- //Limite da Bola no Stage
- if (Bola.y > stage.stageHeight || Bola.y < 0)
- {
- //Regra 9 e 10
- BolaY = -BolaY;
- }
- //Colisão no Batedor 1 e 2
- //Regra 11 e 12
- if (Bola.hitTestObject(Batedor1) || Bola.hitTestObject(Batedor2))
- {
- BolaX = -BolaX;
- }
- }
- //Mudar o Placar e fazer Bola Retornar ao centro do stage
- function placares (e:Event) : void
- {
- //Regra 6
- if (Bola.x < 0 - Bola.width)
- {
- //Regra 18
- ScorePl2.text = (int(ScorePl2.text) +1).toString();
- Bola.x = 275;
- Bola.y = 200;
- //Regra 13
- if(BolaY < 0)
- {
- BolaY = (BolaY * -1);
- }
- BolaX = BolaX - 1;
- BolaY = BolaY + 1;
- }
- if (Bola.x > stage.stageWidth + Bola.width)
- {
- //Regra 18
- ScorePl1.text = (int(ScorePl1.text)+1).toString();
- Bola.x = 275;
- Bola.y = 200;
- //Regra 13
- if(BolaY < 0)
- {
- BolaY = BolaY * -1;
- }
- BolaX = BolaX + 1;
- BolaY = BolaY + 1;
- }
- //Regra 19
- if (ScorePl1.text == "10")
- {
- stage.removeEventListener(Event.ENTER_FRAME, BallIG);
- var Victory1:MovieClip= new Victory1MC();
- stage.addChild(Victory1);
- Victory1.x = 275;
- Victory1.y = 200;
- }
- //Regra 19
- if (ScorePl2.text == "10")
- {
- stage.removeEventListener(Event.ENTER_FRAME, BallIG);
- var Victory2:MovieClip= new Victory2MC();
- stage.addChild(Victory2);
- Victory2.x = 275;
- Victory2.y = 200;
- }
- }
- //Movimento do Batedor 1
- stage.addEventListener(KeyboardEvent.KEY_UP, OnKeUp);
- stage.addEventListener(KeyboardEvent.KEY_DOWN, OnKeDo);
- stage.addEventListener(KeyboardEvent.KEY_UP, OnKeUp2);
- stage.addEventListener(KeyboardEvent.KEY_DOWN, OnKeDo2);
- function OnKeDo (e:KeyboardEvent) : void
- {
- //Regra 14
- if (e.keyCode == 87)
- {
- up = true;
- }
- if (e.keyCode == 83)
- {
- down = true;
- }
- if(Batedor1.y < 0)
- {
- Batedor1.y = 0
- }
- if (Batedor1.y > stage.stageHeight - Batedor1.height)
- {
- Batedor1.y = stage.stageHeight - Batedor1.height;
- }
- }
- function OnKeUp (e:KeyboardEvent) : void
- {
- if (e.keyCode == 87)
- {
- up = false;
- }
- if (e.keyCode == 83)
- {
- down = false;
- }
- }
- stage.addEventListener(Event.ENTER_FRAME, OnEnFrPl1);
- stage.addEventListener(Event.ENTER_FRAME, OnEnFrPl2);
- function OnEnFrPl1 (e:Event) : void
- {
- if (up && (Batedor1.y - (Batedor1.height / 2)) > 0)
- {
- Batedor1.y -= batspeed;
- }
- if (down && (Batedor1.y + (Batedor1.height / 2)) < stage.stageHeight )
- {
- Batedor1.y += batspeed;
- }
- }
- //Movimento do Batedor 2
- function OnKeDo2 (e:KeyboardEvent) : void
- {
- //Regra 15
- if (e.keyCode == 38)
- {
- up2 = true;
- }
- if (e.keyCode == 40)
- {
- down2 = true;
- }
- }
- function OnKeUp2 (e:KeyboardEvent) : void
- {
- if (e.keyCode == 38)
- {
- up2 = false;
- }
- if (e.keyCode == 40)
- {
- down2 = false;
- }
- }
- function OnEnFrPl2 (e:Event) : void
- {
- //Regra 16
- if (up2 && (Batedor2.y - (Batedor2.height / 2)) > 0)
- {
- Batedor2.y -= batspeed;
- }
- if (down2 && (Batedor2.y + (Batedor2.height / 2)) < stage.stageHeight )
- {
- Batedor2.y += batspeed;
- }
- }
- //Regra 17 está no Stage
Advertisement
Add Comment
Please, Sign In to add comment