Well, I wanna run a function for a fixed period of seconds, like 5 seconds or so, how do I go about doing this?
I've looked through ctime reference, and I dunno which of those functions to use for this, or how :S
Any advice?
Thanks in advance!
Well, I wanna run a function for a fixed period of seconds, like 5 seconds or so, how do I go about doing this?
I've looked through ctime reference, and I dunno which of those functions to use for this, or how :S
Any advice?
Thanks in advance!
Currently research OpenGL
Does a single run of the function take more than 5 seconds?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
5 seconds was just some number that got in my head, I'm trying to make the character jump, and I need it to go upwards for a short period of time
Currently research OpenGL
Ah, so not really a specific function then.
Just part of a normal game loop which
do
- detects if there is any key press
- performs actions on the key press
- moves NPC characters
- redraws the screen
- works out alive-or-dead
while !dead
Except now it would be
do
- detects if there is any key press
- performs actions on the key press
- perform any player auto movements (such as jump)
- moves NPC characters
- redraws the screen
- works out alive-or-dead
while !dead
At the start of a jump, you determine a trajectory (didn't you ask about gravity earlier?). The player character continues along this trajectory (one screen refresh at a time) until something interesting happens (say landing on another floor, grabbing a rope, dying horribly etc).
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
ok, I kinda got it working, but not well enough xP
Now the player just spawns up in the air and falls down D:
how can I avoid this? xPCode:void character::goUp(float dt){ float tempY = y; do{ y -= gravityPull + 100 * dt; }while(tempY <= y + 200); }
Currently research OpenGL
Well, look at what it does -- it moves y down by 300 units, I guess. If you want to draw the person going up (I believe in your system y going down is player going up?) then you can't do it all in one function, since the drawCharacter doesn't get a chance to act until this function returns.