开发者

Countdown and Points, AS3

This all works perfectly, but one thing. How do I count in ones now?

Thanks

OUTPUT OF LIFE LOSS

580 560 540 520 500 480 460 ect...

OUTPUT NEEDS TO BE

600 599 598 597 596 595 ect...'and ending with time left counter if there is no win'

SCREENSHOT OF COUNTDOWN

alt text http://poizenpoprecords.com/myspace/videodnd/deltaTime.jpg

ActionScript

//Starts with 600 life points, counts from 30-0
//game will be more intricate and retotal scores, this is just a sketch
var EQUATION:int;
var TIME:int = 30;
var COUNTDOWN:Number = 600;
var COUNTUP:Number = 0;
var START:int = getTimer();
var DELTATIME:int;
var lucky:int;

var myTimer:Timer = new Timer(1000,30);
myTimer.addEventListener(TimerEvent.TIMER,someFunction);
myTimer.start();

function someFunction(event:TimerEvent) {
DELTATIME = (getTimer() - START)/1000;
//trace(DELTATIME);
//lucky = Math.floor(Math.random()*55);
//trace(lucky);
EQUATION = COUNTDOWN - (DELTATIME*COUNTDOWN/TIME) + COUNTUP; 
var str:String = String (Math.abs (EQUATION));
//var sub:String = ("000000")+ str.substr(0, 4);
//tx.text = String (sub);
tx.text = String ("YOU HAVE  ")+(EQUATION)+("  POINTS");
txt.text = String(Math.floor(30 - DELTATIME))+("  SECONDS LEFT");
trace(EQUATION);
if(lucky==16){
myTimer.stop(); 
var mtInter:uint = setInterval (blk, 222);
function blk():void {
txt.visible = !txt.visibl开发者_Go百科e;
tx.visible = !tx.visible;
txt.text = String("You're Lucky This Time");
tx.text = String("You Get 100 Life Points!");
}
}
if(EQUATION==0){
myTimer.stop(); 
var mtIntv:uint = setInterval (blink, 222);
function blink():void {
txt.visible = !txt.visible;
tx.visible = !tx.visible;
txt.text = String("Time's Up!");
tx.text = String("You're Dead!");
}
}
}

SCREENSHORT OF WIN


Your update function is only being called every second so at most you can display 30 values. You want your timer to call your update function at least once for every life point. Also you used an int for the DELTA value, which rounds the number down to the nearest whole number. Changing that to the type Number let's you get decimals.

Here is your code updated to count by one although now your lucky function will be calculated more often so you will need to adjust that:

    //Starts with 600 life points, counts from 30-0
//game will be more intricate and retotal scores, this is just a sketch
var EQUATION:int;
var TIME:int = 30;
var COUNTDOWN:Number = 600;
var COUNTUP:Number = 0;
var START:int = getTimer();
var DELTATIME:Number;//<-- Changed this to a Number to you get more than 30 values out of it
var lucky:int;

var myTimer:Timer = new Timer(25); //<-- Changed the timer to repeat every 25 milliseconds and infinitely
myTimer.addEventListener(TimerEvent.TIMER,someFunction);
myTimer.start();

function someFunction(event:TimerEvent) {
DELTATIME = (getTimer() - START)/1000;
//trace(DELTATIME);
//lucky = Math.floor(Math.random()*55);
//trace(lucky);
EQUATION = COUNTDOWN - (DELTATIME*COUNTDOWN/TIME) + COUNTUP; 
var str:String = String (Math.abs (EQUATION));
//var sub:String = ("000000")+ str.substr(0, 4);
//tx.text = String (sub);
tx.text = String ("YOU HAVE  ")+(EQUATION)+("  POINTS");
txt.text = String(Math.floor(30 - DELTATIME))+("  SECONDS LEFT");
trace(EQUATION);
if(lucky==16){
myTimer.stop(); 
var mtInter:uint = setInterval (blk, 222);
function blk():void {
txt.visible = !txt.visible;
tx.visible = !tx.visible;
txt.text = String("You're Lucky This Time");
tx.text = String("You Get 100 Life Points!");
}
}
if(EQUATION==0){
myTimer.stop(); 
var mtIntv:uint = setInterval (blink, 222);
function blink():void {
txt.visible = !txt.visible;
tx.visible = !tx.visible;
txt.text = String("Time's Up!");
tx.text = String("You're Dead!");
}
}
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜