PDA

View Full Version : Interval check for player input?



symbiote01
06-15-2010, 02:36 PM
I'd like to know if there is a (relatively fast) way of determining how much time has elapsed since the last time the player pressed a key. The importance of this is manifold:
1.) A custom enemy can be made to move only after Link has 'stopped' for a certain length of time, and 'freeze' again after Link moves (with a slight delay, perhaps). Great for turtles that go into their shell or crabs digging into the ground!
2.) The environment (or an enemy) can be made to move only when Link does, like an angry plant 'feeling' his motion and thrashing it's vines around. Or, a countdown timer that only counts down when Link is moving!
3.) After Link pauses for a certain length of time, we can call up a 'Bored' animation (make Link invisible, plop an animation over his location that runs until Link moves again or takes damage). If we're really on the ball, we can have several animations (one for Injured Link, a few other random ones) for every suit change.

I hope someone can help!

Mega Link
06-15-2010, 10:26 PM
I might be wrong, but the fps (frames per second) is usually 60. So just have a counter keep track of each frame that passes, and divide that value by 60 to get how many seconds passed. Like this:

int frames = 0;

int SecPassed() {
return frames / 60;
}

while(true) {
//Insert the following line where your script checks for a keypress.
frames = 0;

//Add more code here.

frames++;
Waitframe();
}