flyhigh
06-26-2009, 03:38 AM
Hi all,
I am new to this forum, came across this as a desperate attempt to get help.
This is my flash code game. There should be random signs appearing. You have to move the hand with the mouse to click on the signs. If you clicked successfully, the sign should disappear, and reappear somewhere else randomly, and you gain 10 points. There is a time limit of 60 seconds. If within 60 seconds you are able to gain 100 points, then you win the game. Else, you lose the game. There will also be a random tomato flying at your own sign that you have to move around with the keyboard! If your sign gets hit by the random tomato, the timer will decrease by 5 seconds, making the time limit shorter.
"CODE"
package campaigngame{
import flash.display.MovieClip;
import flash.events.*;
import flash.ui.Mouse;
import fl.transitions.Tween;
//import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
import flash.ui.Keyboard;
import flash.utils.Timer;
import flash.text.TextField;
public class CampaignGame extends MovieClip {
private var myMoveX:Number=0;
private var myMoveY:Number=0;
//private var mySign:MovieClip;
private var myTimer:Timer;
private var num:Number=10;
private var Score:Number=0;
private var mySignTimer:Timer=null;
private var myTween:Tween;
private var myTomatoe:Tomatoe;
public function CampaignGame() {
var startY:Number=40;
var stopX:Number=900;
var stopY:Number=3000;
stage.addEventListener(MouseEvent.MOUSE_MOVE, moveMe);
hand.addEventListener(MouseEvent.MOUSE_DOWN, pressMe);
hand.buttonMode=true;
stage.addEventListener(KeyboardEvent.KEY_DOWN, myKeyPress);
startBtn.addEventListener(MouseEvent.CLICK, Start);
hand.addEventListener(MouseEvent.CLICK, hitSign);
}
private function Start(e:MouseEvent):void {
insPage.visible=false;
gamePlay.visible=true;
ins1.visible=false;
ins2.visible=false;
sign.visible=false;
ins.visible=false;
startBtn.visible=false;
replay.visible=false;
winGame.visible=false;
loseGame.visible=false;
myTimer=new Timer(1000,10);
myTimer.addEventListener(TimerEvent.TIMER, setClock);
myTimer.addEventListener(TimerEvent.TIMER, animate);
myTimer.start();
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE , Stop);
mySignTimer=new Timer(1000);
mySignTimer.addEventListener(TimerEvent.TIMER,hide Sign);
mySignTimer.start();
replay.addEventListener(MouseEvent.CLICK,Replay);
//myTomatoe.start();
//myTomatoe.visible=true;
}
private function Stop(e:TimerEvent):void {
myTimer.stop();
mySignTimer.stop();
winGame.visible=true;
replay.visible=true;
}
private function Replay(e:MouseEvent):void {
myTimer=new Timer(1000,10);
myTimer.addEventListener(TimerEvent.TIMER, setClock);
myTimer.addEventListener(TimerEvent.TIMER, animate);
myTimer.start();
mySignTimer.start();
replay.visible=false;
winGame.visible=false;
}
private function hitSign() {
if (hand.hitTestObject(Sign1)) {
//myTomatoe=new Tomatoe();
//private function myTomatoe(e:MouseEvent) {
//stage.addEventListener(Event.ENTER_FRAME, animate);
//addChild(myTomatoe);
//var startX:Number=Math.random()*300;
//var StopX:Number=Math.random()*300;
//myTween=new Tween(myTomatoe,"x",Regular.easeInOut,0,750,1,true);
//myTween=new Tween(myTomatoe,"y",Regular.easeInOut,0,400,1,true);
trace("hitting");
Sign1.visible=false;
if (Sign1.visible==true&&Sign1.currentFrame==1) {
//Score=Score+1;
}
Sign1.gotoAndStop(2);
} else {
trace("not hitting");
}
if (hand.hitTestObject(Sign2)) {
trace("hitting");
} else {
trace("not hitting");
}
}
private function hideSign(e:TimerEvent):void {
var randomNum:Number = Math.floor(1 +(Math.random() * (4- 1)));
if (randomNum==1) {
if (Sign1.visible==true) {
Sign1.visible=false;
} else {
Sign1.visible=true;
Sign1.gotoAndStop(1);
}
} else if (randomNum == 2) {
if (Sign2.visible==true) {
Sign2.visible=false;
} else {
Sign2.visible=true;
Sign2.gotoAndStop(1);
}
}
}
private function moveMe(e:MouseEvent) {
hand.x=mouseX;
hand.y=mouseY;
}
private function setClock(e:TimerEvent) {
num--;
trace(num);
myText.text=String(num);
if (num==0) {
trace("done");
myText.alpha=0;
}
}
private function pressMe(e:MouseEvent) {
e.target.startDrag(true);
//stage.addEventListener(MouseEvent.MOUSE_UP, dropMe);
}
private function animate(e:TimerEvent) {
hand.x+=myMoveX;
hand.y+=myMoveY;
}
private function myKeyPress(e:KeyboardEvent) {
trace(+ Keyboard.LEFT);
if (e.keyCode==Keyboard.LEFT) {
mySign.x+=-20;
} else if (e.keyCode == Keyboard.RIGHT) {
mySign.x+=20;
}
}
}
}
BELOW ARE THINGS I NEED HELP WITH
-MAKING SIGNS APPEARING AND DISAPPEARING RANDOMLY (somewhat successful?)
-CLICKING ON THE SIGNS AND ADDING 10 POINTS TO THE TOTAL SCORE
-IF SCORE REACHES 100 OR MORE, A “YOU WIN” MESSAGE SHOWS UP AND THE GAME IS FREEZED. THERE WILL BE A REPLAY BUTTON TO RESTART THE GAME AGAIN
-IF SCORE DOESN’T REACHES 100 OR MORE IN 60 SECONDS, A “YOU LOSE” MESSAGE SHOWS UP AND THE GAME FREEZED. A REPLAY BUTTON TO RESTART THE GAME AGAIN
Thanks in advance!
I am new to this forum, came across this as a desperate attempt to get help.
This is my flash code game. There should be random signs appearing. You have to move the hand with the mouse to click on the signs. If you clicked successfully, the sign should disappear, and reappear somewhere else randomly, and you gain 10 points. There is a time limit of 60 seconds. If within 60 seconds you are able to gain 100 points, then you win the game. Else, you lose the game. There will also be a random tomato flying at your own sign that you have to move around with the keyboard! If your sign gets hit by the random tomato, the timer will decrease by 5 seconds, making the time limit shorter.
"CODE"
package campaigngame{
import flash.display.MovieClip;
import flash.events.*;
import flash.ui.Mouse;
import fl.transitions.Tween;
//import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
import flash.ui.Keyboard;
import flash.utils.Timer;
import flash.text.TextField;
public class CampaignGame extends MovieClip {
private var myMoveX:Number=0;
private var myMoveY:Number=0;
//private var mySign:MovieClip;
private var myTimer:Timer;
private var num:Number=10;
private var Score:Number=0;
private var mySignTimer:Timer=null;
private var myTween:Tween;
private var myTomatoe:Tomatoe;
public function CampaignGame() {
var startY:Number=40;
var stopX:Number=900;
var stopY:Number=3000;
stage.addEventListener(MouseEvent.MOUSE_MOVE, moveMe);
hand.addEventListener(MouseEvent.MOUSE_DOWN, pressMe);
hand.buttonMode=true;
stage.addEventListener(KeyboardEvent.KEY_DOWN, myKeyPress);
startBtn.addEventListener(MouseEvent.CLICK, Start);
hand.addEventListener(MouseEvent.CLICK, hitSign);
}
private function Start(e:MouseEvent):void {
insPage.visible=false;
gamePlay.visible=true;
ins1.visible=false;
ins2.visible=false;
sign.visible=false;
ins.visible=false;
startBtn.visible=false;
replay.visible=false;
winGame.visible=false;
loseGame.visible=false;
myTimer=new Timer(1000,10);
myTimer.addEventListener(TimerEvent.TIMER, setClock);
myTimer.addEventListener(TimerEvent.TIMER, animate);
myTimer.start();
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE , Stop);
mySignTimer=new Timer(1000);
mySignTimer.addEventListener(TimerEvent.TIMER,hide Sign);
mySignTimer.start();
replay.addEventListener(MouseEvent.CLICK,Replay);
//myTomatoe.start();
//myTomatoe.visible=true;
}
private function Stop(e:TimerEvent):void {
myTimer.stop();
mySignTimer.stop();
winGame.visible=true;
replay.visible=true;
}
private function Replay(e:MouseEvent):void {
myTimer=new Timer(1000,10);
myTimer.addEventListener(TimerEvent.TIMER, setClock);
myTimer.addEventListener(TimerEvent.TIMER, animate);
myTimer.start();
mySignTimer.start();
replay.visible=false;
winGame.visible=false;
}
private function hitSign() {
if (hand.hitTestObject(Sign1)) {
//myTomatoe=new Tomatoe();
//private function myTomatoe(e:MouseEvent) {
//stage.addEventListener(Event.ENTER_FRAME, animate);
//addChild(myTomatoe);
//var startX:Number=Math.random()*300;
//var StopX:Number=Math.random()*300;
//myTween=new Tween(myTomatoe,"x",Regular.easeInOut,0,750,1,true);
//myTween=new Tween(myTomatoe,"y",Regular.easeInOut,0,400,1,true);
trace("hitting");
Sign1.visible=false;
if (Sign1.visible==true&&Sign1.currentFrame==1) {
//Score=Score+1;
}
Sign1.gotoAndStop(2);
} else {
trace("not hitting");
}
if (hand.hitTestObject(Sign2)) {
trace("hitting");
} else {
trace("not hitting");
}
}
private function hideSign(e:TimerEvent):void {
var randomNum:Number = Math.floor(1 +(Math.random() * (4- 1)));
if (randomNum==1) {
if (Sign1.visible==true) {
Sign1.visible=false;
} else {
Sign1.visible=true;
Sign1.gotoAndStop(1);
}
} else if (randomNum == 2) {
if (Sign2.visible==true) {
Sign2.visible=false;
} else {
Sign2.visible=true;
Sign2.gotoAndStop(1);
}
}
}
private function moveMe(e:MouseEvent) {
hand.x=mouseX;
hand.y=mouseY;
}
private function setClock(e:TimerEvent) {
num--;
trace(num);
myText.text=String(num);
if (num==0) {
trace("done");
myText.alpha=0;
}
}
private function pressMe(e:MouseEvent) {
e.target.startDrag(true);
//stage.addEventListener(MouseEvent.MOUSE_UP, dropMe);
}
private function animate(e:TimerEvent) {
hand.x+=myMoveX;
hand.y+=myMoveY;
}
private function myKeyPress(e:KeyboardEvent) {
trace(+ Keyboard.LEFT);
if (e.keyCode==Keyboard.LEFT) {
mySign.x+=-20;
} else if (e.keyCode == Keyboard.RIGHT) {
mySign.x+=20;
}
}
}
}
BELOW ARE THINGS I NEED HELP WITH
-MAKING SIGNS APPEARING AND DISAPPEARING RANDOMLY (somewhat successful?)
-CLICKING ON THE SIGNS AND ADDING 10 POINTS TO THE TOTAL SCORE
-IF SCORE REACHES 100 OR MORE, A “YOU WIN” MESSAGE SHOWS UP AND THE GAME IS FREEZED. THERE WILL BE A REPLAY BUTTON TO RESTART THE GAME AGAIN
-IF SCORE DOESN’T REACHES 100 OR MORE IN 60 SECONDS, A “YOU LOSE” MESSAGE SHOWS UP AND THE GAME FREEZED. A REPLAY BUTTON TO RESTART THE GAME AGAIN
Thanks in advance!