timer issue in game
Author |
Message |
tidusraven
|
Posted: Fri Jan 22, 2010 10:33 am Post subject: timer issue in game |
|
|
the issue im having with this program is that the timer goes crazy, it goes everywhere
Turing: |
var chars : array char of boolean
var y, yy, xcounter, x, xx, balls : int
var choice : string
var turn : int := 1
y := maxy div 2 - 140
yy := maxy div 2 - 190
var x2 := 50
var y2 := maxy
var ball : int := 0
var timelimit : int
View.Set ("graphics")
drawfillbox (0, 0, 900, 605, black)
colorback (black)
color (14)
Mouse.ButtonChoose ("multibutton")
setscreen ("nocursor")
put "Type in the difficulty (easy,medium,hard) or type in anything else to view the info."
get choice
xcounter := maxx div 2 - 25
if choice = "easy" then
xx := 70
y := 30
yy := 0
elsif choice = "medium" then
xx := 50
y := 20
yy := 0
elsif choice = "hard" then
xx := 25
y := 15
yy := 0
else
put "To move side to use, use arrow keys ( <- -> ), collect as much balls as you can before the time limit runs out" ..
get choice
end if
View.Set ("graphics")
Draw.FillBox (xcounter, y, xcounter + xx, yy, yellow)
View.Set ("offscreenonly")
process counter
timelimit := 60
for x : 1 .. 60
color (yellow)
colorback (black)
timelimit := timelimit - 1
delay (1000)
end for
end counter
loop
timelimit := 60
y2 := maxy
randint (x2, 10, 600)
fork counter
loop
cls
y2 := y2 - 1
drawfillbox (0, 0, 900, 605, black)
Input.KeyDown (chars )
if chars (KEY_RIGHT_ARROW) then
xcounter := xcounter + 1
elsif chars (KEY_LEFT_ARROW) then
xcounter := xcounter - 1
end if
Draw.FillBox (xcounter, y, xcounter + xx, yy, yellow)
Draw.FillBox (xcounter, y, xcounter + xx, yy, yellow)
drawfilloval (x2, y2, 10, 10, black)
delay (10)
drawfilloval (x2, y2, 10, 10, yellow)
color (yellow)
put "timer: ", timelimit
View.Update
if y2 = - 10 then
exit
end if
end loop
end loop
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
TheGuardian001
|
Posted: Fri Jan 22, 2010 12:03 pm Post subject: Re: timer issue in game |
|
|
tidusraven wrote:
there's your problem(or at least one of them). If you aren't doing music, you should never be using a process. Essentially every time you repeat your loop, you will restart the timer process and the timer will screw up. This isn't specifically because you're using a process, but the process will screw up other things (like it not waiting a full second sometimes.) Timers can be done properly by using Time.Elapsed.
Simply have two variables, one to hold the starting time, and one to hold the current, then compare the two.
code: |
%initial stuff
%like getting difficulty.
%When the game starts
var startTime : int := Time.Elapsed %gets the current time and stores it, so we know when the game started
var current : int
loop
%Game is here
current := Time.Elapsed %gets the time each time the loop repeats, so we have something to compare to.
locate(1,1)
put "The game has been running for ", (current-startTime) div 1000 %subtract the start time from the current to get the running time.
end loop
|
|
|
|
|
|
|
|
|