Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Speed up with user key input

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Having posted a thread earlier about running in a flash game (thanks for the reply), I've now gone about things in a different way. I've attached the following script to a symbol:

onClipEvent (keyDown) {
if (Key.getCode()==Key.Right) {
_level0.speed = _level0.speed + 1;
}
}
onClipEvent (keyDown) {
if (Key.getCode()==Key.Left) {
_level0.speed = _level0.speed - 1;
}
}
onClipEvent (enterFrame) {
if (_level0.speed < 1) {
_level0.speed = 0;
}
}

This works great - I can speed the object up by pressing the right arrow, and slow it down using the left. However, what I actually want to be able to do is speed the object up based on how quickly the user presses the left and right arrows one after another. Do you remember the Daly Thompson Athletics arcade game? So, if the user is nearly breaking the keyboard hitting 2 keys one after the other, the object will be flying!

Thanks in advance!
 
First off I'd combine all of the statements into one event which will make your game run a little faster...

onClipEvent (keyDown) {
if (Key.getCode() == Key.Right) {
_level0.speed = _level0.speed+1;
} else if (Key.getCode() == Key.Left && _level0.speed>1) {
_level0.speed = _level0.speed-1;
}
}


You'll need to use a getTimer() event to read the button pushes...

onClipEvent (load) {
pushed = false;
maximumSpeed = 10;
}
onClipEvent (keyDown) {
if (pushed==false) {
firstPress = getTimer();
pushed=true;
} else {
pushed = false;
secondPress = getTimer();
elapsedTime = secondPress-firstPress;
speed = maximumSpeed-elapsedTime;
}
}



Gets you close, you'll have to adapt things to suit your different levels and combine the two bits of keyDown script etc....

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top