flash game development AS3
I am developing a game in flash AS3 in which multiple items are falling d开发者_开发问答own and have to be caught it at the bottom using the mouse.
just want to brief you regarding the game.
This is the link for similar game : http://www.playitontheweb.com/games/Catch-Falling-Fruit-game.htm
At frame 1 > Preloader
At frame 2 > Game front page.
At frame 3 > Game introduction.
At frame 4 > user will b playing the game.
At frame 5 > Final Score.
This is what i want to make it in functionality wise.
Here is the script script(AS3) which plays the game in all frames. From 1 to 5 which i dont want: Please help......
package {
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.utils.Timer;
import flash.utils.getDefinitionByName;
public class CatchingGame extends MovieClip {
var catcher:Catcher;
var nextObject:Timer;
var objects:Array = new Array();
var score:int = 0;
const speed:Number = 7.0;
public function CatchingGame() {
catcher = new Catcher();
catcher.y = 350;
addChild(catcher);
setNextObject();
addEventListener(Event.ENTER_FRAME, moveObjects);
}
public function setNextObject() {
nextObject = new Timer(1000+Math.random()*1000,1);
nextObject.addEventListener(TimerEvent.TIMER_COMPLETE,newObject);
nextObject.start();
}
public function newObject(e:Event) {
var goodObjects:Array = ["Circle1","Circle2"];
var badObjects:Array = ["Square1","Square2"];
if (Math.random() < .5) {
var r:int = Math.floor(Math.random()*goodObjects.length);
var classRef:Class = getDefinitionByName(goodObjects[r]) as Class;
var newObject:MovieClip = new classRef();
newObject.typestr = "good";
} else {
r = Math.floor(Math.random()*badObjects.length);
classRef = getDefinitionByName(badObjects[r]) as Class;
newObject = new classRef();
newObject.typestr = "bad";
}
newObject.x = Math.random()*500;
addChild(newObject);
objects.push(newObject);
setNextObject();
}
public function moveObjects(e:Event) {
for(var i:int=objects.length-1;i>=0;i--) {
objects[i].y += speed;
if (objects[i].y > 400) {
removeChild(objects[i]);
objects.splice(i,1);
}
if (objects[i].hitTestObject(catcher)) {
if (objects[i].typestr == "good") {
score += 5;
} else {
score -= 1;
}
if (score < 0) score = 0;
scoreDisplay.text = "Score: "+score;
removeChild(objects[i]);
objects.splice(i,1);
}
}
catcher.x = mouseX;
}
}
}
Also would like to ask you can we add a timer in that of 60 sec? as soon as the timer gets over it goes to the last frame to shaw the final score.
- call
stop()
to stay within current frame, call nextFrame() to advance to next scene - global function
getTimer()
gives you number of milliseconds passed from swf launch, you can measure time with it.
Use gotoAndStop() to go to the frame you want and stop there. I would recommend that command over stop() simply because it bundles both the frame changing and stop behaviors into one; otherwise they are the same thing.
精彩评论