I have these 2 movieclips called Monkey and Dustbin.
Both Movieclips would come out from the right side middle of the stage and starts moving horizontally to the left. They would move to 3/4 of the stage and disappear if they are not being pressed down by the directional keys of right directional key for the Monkey and left directional key for the Dustbin respectively.
The 2 Movieclips would keep spawn(spawn rate at random) and move towards the 3/4 of the stage and keep move(moving rate random) horizontally.
there is a start game button at the first frame called frontstage and the main game lies at the frame called middlestage and the ending is called backstage.
After 60s it would show the end of the game, thus gotoAndPlay(“backstage”);
There will be a restart button at the “backstage”
Currently i know how to make restart button and start game button but i do not know how to make both the movieclips and the directional keys to work hand in hand.
i have tried doing in my methods which i tink its correct…
But its not… So i am asking for help.thank you.
Can someone help??
FLA format file is current too big to be uploaded…Hope someone can help me and i will send my FLA file via email to u (:
Thanks (:
Game Code:
package
{
import flash.display.MovieClip;
import flash.events.*;
import flash.text.*;
import flash.ui.Keyboard;
import flash.utils.Timer;
public class Gametwo extends MovieClip
{
public var clickScore:Number = 0;
public var count:uint;
//Timer
public var timer:Timer;
public var countTime:Number = 3;
public var myTimer:Timer = new Timer(2000,countTime);
public var monkey:Monkey = new Monkey();
public var db:Dustbin = new Dustbin();
public var go:gameover = new gameover();
public var ta:tryagain = new tryagain();
public var instruct:Instructions = new Instructions();
public var sBtn:StartBtn = new StartBtn();
public var msg:Message = new Message();
public var nx:Next = new Next();
public function Gametwo()
{
addChild(instruct);
addChild(sBtn);
sBtn.addEventListener(MouseEvent.CLICK, gameBtn);
}
public function gameBtn(e:MouseEvent)
{
gotoAndPlay("middlestage");
removeChild(sBtn);
stage.removeEventListener(MouseEvent.CLICK, gameBtn);
stage.addEventListener(MouseEvent.CLICK , clickgameBtn);
}
public function clickgameBtn(e:MouseEvent)
{
if(e.target is StartBtn)
{
gotoAndPlay("middlestage");
removeChild(instruct);
trace(gotoAndPlay("middlestage"));
}
}
public function setting ()
{
myTimer.addEventListener (TimerEvent.TIMER, countdown);
myTimer.start();
txtTimer.text = String((countTime) - myTimer.currentCount + "s");
addChild(monkey);
addChild(db);
function keyDownHandler(e:KeyboardEvent)
{
if(e.keyCode == Keyboard.LEFT)
{trace(removeChild(monkey));
removeChild(monkey);
}
}
}
public function countdown(e:TimerEvent)
{
txtTimer.text = String((countTime) - myTimer.currentCount + "s");
trace(String((countTime) - myTimer.currentCount + "s"));
if (txtTimer.text == "0s")
{
myTimer.reset();
myTimer.stop();
gotoAndPlay ("backstage");
addChild(msg);
addChild(ta);
addChild(nx);
stage.addEventListener(MouseEvent.CLICK, restart);
}
}
public function restart(e:MouseEvent)
{
if(e.target is tryagain)
{gotoAndPlay("frontstage");
removeChild(ta);
removeChild(msg);
removeChild(nx);
}
}
/* public function enterFrame( ev:Event ):void
{
if( key.isDown( Keyboard.LEFT ) )
{
}
if( key.isDown( Keyboard.RIGHT ) )
{
}
}*/
/*
private function movements()
{
var monkey:Monkey = new Monkey();
stage.addChild(Monkey);
var dusbin:Dustbin = new Dustbin();
stage.addChild(Dustbin);
monkey.x += 10;
dustbin.x += 10;
var vanishBoundary : int = stage.stageWidth / 4 * 3 ;
if (monkey.x >= vanishBoundary )
{
parent.removeChild(monkey);
var vanishBoundary1 : int = stage.stageWidth / 4 * 3 ;
if (dustbin.x >= vanishBoundary1 )
{
parent.removeChild(dustbin);
}
}
}
}*/
}
}
Monkey
package
{
import flash.display.MovieClip;
import flash.events.*;
public dynamic class Monkey extends MovieClip
{
var xSpeed:Number = Math.random() * 4;
//var ySpeed:Number = Math.random() * 4;
public function Monkey()
{
this.addEventListener(Event.ENTER_FRAME, moveandstop);
//this.gotoAndStop(Math.ceil(Math.random()*4));
}
public function moveandstop (e:Event)
{
if (this.x > 450 || this.x < 0)
{
this.xSpeed *= -1;
}
/*if (this.y < 0 || this.y > 400)
{
this.ySpeed *= -1;
}*/
this.x += this.xSpeed;
//this.y += this.ySpeed;
}
public function die()
{
this.removeEventListener(Event.ENTER_FRAME, moveandstop);
parent.removeChild(this);
}
}
}
Dustbin
package
{
import flash.display.MovieClip;
import flash.events.*;
public dynamic class Dustbin extends MovieClip
{
var xSpeed:Number = Math.random() * 4;
//var ySpeed:Number = Math.random() * 4;
public function Dustbin()
{
this.addEventListener(Event.ENTER_FRAME, moveandstop);
//this.gotoAndStop(Math.ceil(Math.random()*4));
}
public function moveandstop (e:Event)
{
if (this.x >450 || this.x < 0)
{
this.xSpeed *= -1;
}
/*if (this.y < 0 || this.y > 400)
{
this.ySpeed *= -1;
}*/
this.x += this.xSpeed;
//this.y += this.ySpeed;
}
public function die()
{
this.removeEventListener(Event.ENTER_FRAME, moveandstop);
parent.removeChild(this);
}
}
}