Friday, 23 August 2013

Is there a better alternative to Timers to increment speed? [migrated]

Is there a better alternative to Timers to increment speed? [migrated]

pI'm making a chaser game in flash, where you would press an arrow key and
the player would move in that direction then stop on another point on a
grid, as the enemy does the same and chases the player. To make the
movement smooth, I have a timer moving the player one pixel each
repetition (50 times to stay on the grid points), having the delay get
smaller every 30 frames to speed up. But after the delay gets to 0 and
can't go any lower, the player can't get faster. What is a better
alternative to use to continue going faster?/p precode var
playerTimer:Timer=new Timer(40,50);
playerTimer.addEventListener(TimerEvent.TIMER,playerMoveTrigger); var
pStatus:String=;
stage.addEventListener(KeyboardEvent.KEY_DOWN,playerMove); function
playerMove(e:KeyboardEvent):void {
if((player.x+15)%50==0amp;amp;(player.y+15)%50==0)//ensures player is on
grid before moving { switch(e.keyCode) { case Keyboard.DOWN: pStatus=down;
break; case Keyboard.UP: pStatus=up; break; case Keyboard.LEFT:
pStatus=left; break; case Keyboard.RIGHT: pStatus=right; break; } }
playerTimer.start() }
playerTimer.addEventListener(TimerEvent.TIMER_COMPLETE,resetTimerP);
function resetTimerP(e:TimerEvent){playerTimer.reset();} function
playerMoveTrigger(e:TimerEvent) {blockMove(player,pStatus);} var
offSet:int=0; function blockMove(block:Shape,dir:String) {
offSet=(block.height==30)?15:10; switch(dir) { case down:
if(block.y+offSetlt;150){block.y+=1;} break; case up:
if(block.y+offSetgt;50){block.y-=1;} break; case left:
if(block.x+offSetgt;50){block.x-=1;} break; case right:
if(block.x+offSetlt;150){block.x+=1;} break; } } /code/pre

No comments:

Post a Comment