Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Game Delays

citpescitpes Posts: 18Member
Wazzup people? I'm making a game in QBasic. I have only 1 problem though, The enemy delay. Unfortunatly the way I make the delay the enemys move at different speeds depending on the computer. There has to be a way to make the delay the same for all computers? Please help. this is how I so it now:

delay = delay + 1
IF delay = 5000 THEN
move the enemy
delay = 1
END IF

HELP HELP HELP!!

«1

Comments

  • KDivad LeahcimKDivad Leahcim Posts: 3,948Member
    : Wazzup people? I'm making a game in QBasic. I have only 1 problem though, The enemy delay. Unfortunatly the way I make the delay the enemys move at different speeds depending on the computer. There has to be a way to make the delay the same for all computers? Please help. this is how I so it now:
    :
    : delay = delay + 1
    : IF delay = 5000 THEN
    : move the enemy
    : delay = 1
    : END IF
    :
    : HELP HELP HELP!!
    :
    :

    I've never tried it, but you I suppose could use On Timer to trigger move events somehow...

    Another option that many apps I've seen use is to just let the user set the delay...
  • citpescitpes Posts: 18Member
    I briefly let the user give the delays but it sucks. The user can make the enemys move slow and complete the game in an hour. I've tried using the TIMER but then the users movements are delayed.
  • KDivad LeahcimKDivad Leahcim Posts: 3,948Member
    : I briefly let the user give the delays but it sucks. The user can make the enemys move slow and complete the game in an hour. I've tried using the TIMER but then the users movements are delayed.
    :

    Nah, use a loop for the user movements and On Timer for frame rate and enemy updates:

    On Timer Goto LabelName
    Do
    'User movements. InKey, etc.
    Loop

    LabelName
    'Frame update and enemy movements
    'Resume back into the loop to continue monitoring for user input.
  • citpescitpes Posts: 18Member
    I've tried that but the problem is I can't use fractions of a second.
  • KDivad LeahcimKDivad Leahcim Posts: 3,948Member
    : I've tried that but the problem is I can't use fractions of a second.
    :

    How about a normal loop and check the time using Timer? It's been a while since I used QB (can you tell? ) and I don't have a copy installed to check, but I think you can check the time (including fractions of a second) with Timer.
  • mercman2000mercman2000 Posts: 80Member
    : delay = delay + 1
    : IF delay = 5000 THEN
    : move the enemy
    : delay = 1
    : END IF

    You have a good idea going here, and you are correct in thinking it'll be faster. That's why old games run really fast on modern computers; they did for loops and counted instead of syncronising the event with the timer.

    start! = TIMER: DO WHILE TIMER < start! + 1: LOOP

    What does this do?

    First, it assigns start = timer. In my case, timer is now 49907.82. Then, it will stay in the loop until timer is >= to 49908.82, even though it says less than. Put in code, the effect is that it will wait 1 second, indicated by the 1 before the :loop statement. To wait 2 seconds, you'd put a 2 in there, to wait an entire minute, you'd put 60 in there. To wait half a second, you'd put .5 there. See? Hope it helps. Let me know how it goes, ok? Oh, and don't forget the ! after start. Because the timer can go above 32k, it's best to put it in single precision, it holds any timer value, as well as not sucking up too much memory.
    ---------------------------------------------
    I've got a plan, but I'm going to need a dead monkey, some empty liquor bottles, and a vacuum cleaner.

  • PrzemekG_PrzemekG_ Posts: 595Member
    Using timer
    [code]
    start!=timer
    do while timer>=strat!+1:loop
    [/code]
    It's work fine until it's 24:00, the the timer reset, so to end the loop you will have to wait 24 hours.

    use:
    [code]
    for i = 0 to TimeToWait
    start!=timer
    do while int(start!) <> int(timer)
    loop
    next
    [/code]
    Ther is a maximum error of 0.8 second in the first second, all the other(2 to ...) will go fine.
    if you want a smaller delay than 1 sec :
    [code]
    for i = 0 to TimerToWait
    start!=timer
    do while int(start!*10!) <> int(timer * 10!)
    loop
    next
    [/code]
    the delay can be each .1 second

  • citpescitpes Posts: 18Member
    Thanks for all you help ppl. I've finally got it to work. Thanks again!!
  • citpescitpes Posts: 18Member
    Sorry to bug you guys again, but, I got a small problem again. In the game that I'm writing I edit the autoexec.bat file to delete some tempary files in the games directory. I've used the following syntax in the autoexec.bat:

    del c:gamedirectory emp*.*

    The problem is that it asks for confirmation. ie: press y/n
    I know there is a way around this, I've seen it somewhere before.

  • mercman2000mercman2000 Posts: 80Member
    : Sorry to bug you guys again, but, I got a small problem again. In the game that I'm writing I edit the autoexec.bat file to delete some tempary files in the games directory. I've used the following syntax in the autoexec.bat:
    :
    : del c:gamedirectory emp*.*
    :
    : The problem is that it asks for confirmation. ie: press y/n
    : I know there is a way around this, I've seen it somewhere before.
    :
    :

    Try del /q C:gamedirectory emp*.*

    if that doesn't work,

    echo y | del C:gamedirectory emp*.*

    if that doesn't work,

    I'm out of ideas. :)

    Hope it helps.

    ---------------------------------------------
    I've got a plan, but I'm going to need a dead monkey, some empty liquor bottles, and a vacuum cleaner.

«1
Sign In or Register to comment.