I have a project due in a weeks time, and I have almost completed it. I have got one more issue I need to work out and I am stumped.
I will paste the code I have so far below.
If you could also explain what the code is doing so I know what it's doing if it's not too much trouble, the code was taken from an in class activity and I changed the identifiers to match what my graphics are called. I am trying to implement a timer in my drop and catch game that every 15 seconds, it increases the speed of the falling objects. The timer will start from 60 seconds, and when it hits 0 seconds, it should go onto a separate page.
Could someone please explain how I would do this? I am not that good at understanding the code in flash, so if you could keep it as simple as possible I would be greatly appreciative.
The code that I have is as follows. It works perfectly, I just need to change a section to the timer :
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;
}
}
}
thank you for taking the time to read my issue and any help given
speed
variable, you'll want it avar
not aconst
, for starters. Here is a tutorial on thetimer
class in AS3: republicofcode.com/tutorials/flash/as3timer – Ronnie