Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Any other way besides Time.Elapsed... :?:
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Morice




PostPosted: Sat Dec 24, 2005 10:25 pm   Post subject: Any other way besides Time.Elapsed... :?:

Ok i was wondering if ther is another to count time in my game besdies Time.Elapsed because i cant do nothing with it just to display the time....
i need to add stats and i cant do u cause i cant stop Time.Elapsed...
so is ther another way to make time? plz help, cause its really frustrating....
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sat Dec 24, 2005 11:43 pm   Post subject: (No subject)

There's no problem with Time.Elapsed.

You'll have to post some code.
Morice




PostPosted: Sun Dec 25, 2005 1:32 pm   Post subject: (No subject)

ok heres the problem
i have a racing game right
and each track contains of 5 laps and all of it its timed and im using Time.Elapsed....
however i want to have at the end of each track to display the stats like lap 1 u did it in **** secs or lap 2 in **** secs
and i cant use that with time.elapsed because i cant ( or i dont know) assign a variable to it at a certain point ...
do u know wat i mean??
Cervantes




PostPosted: Sun Dec 25, 2005 1:58 pm   Post subject: (No subject)

Time.Elapsed is a function: it returns a value. You can assign that value to a variable.
code:

var time_now := Time.Elapsed


Then you can determine the time between two events by subtracting Time.Elapsed from the value of the variable, time_now:
code:

put "The time between these two events is ", Time.Elapsed - time_now
Morice




PostPosted: Sun Dec 25, 2005 2:16 pm   Post subject: (No subject)

omg lol im so dum i just figured wat i did wrong lol thanks cervantes
Morice




PostPosted: Sun Dec 25, 2005 2:17 pm   Post subject: (No subject)

lol never mind... i cant do it maybe u can help me ... heres the code
code:

%--------------------------------------------------First Good Game-----------------------------------------------------%
%-----------------------------------------------------By Marius--------------------------------------------------------%


setscreen ("graphics:640;480,nobuttonbar,position:192;100,noecho")
var chars : array char of boolean
var score : array 1 .. 5 of int := init (0, 0, 0, 0, 0)
var x, y : int
var x2, y2 : int
var counter4 : int := 0
var counter, counter3 : int := 0
var font, font2, font3, font4 : int
var this : string
var timeRunning : int
var counter2 : int := 0
var endStatement : int


font4 := Font.New ("Comic Sans MS:60:bold")
font := Font.New ("Comic Sans MS:10:bold")
font2 := Font.New ("Comic Sans MS:30:bold")
font3 := Font.New ("Comic Sans MS:13:bold")
x := 285
y := 30
x2 := 285
y2 := 15

%---------------------------------------------------Background----------------------------------------------------------%
proc backgr
    drawfillbox (0, 0, maxx, maxy, 121)

    for i : 1 .. 6
        drawbox (0 + i, 0 + i, maxx - i, maxy - i, 69)
    end for

    drawbox (6, 6, maxx - 6, maxy - 6, black)

end backgr
backgr
drawbox (6, 406, maxx - 6, maxy - 6, black)
drawfillbox (7, 407, maxx - 7, 472, 3)
drawfillbox (90, 427, 95, 472, 69)
drawfillbox (195, 407, 200, 472, 69)
drawline (7, 427, 195, 427, 69)
drawfillbox (1, 400, maxx - 1, 405, 69)

%-------------------------------------------------Background end-------------------------------------------------------%
Font.Draw ("Player 1", 10, 460, font, 69)
Font.Draw ("Lap: ", 10, 430, font, 69)
Font.Draw ("Player 2", 100, 460, font, 69)
Font.Draw ("Lap:", 100, 430, font, 69)
Font.Draw ("Time: ", 67, 410, font3, 69)
proc countdown
    Font.Draw (" 3 ", 285, 80, font4, 69)
    delay (1000)
    drawfillbox (285, 71, 430, 150, 21)
    Font.Draw (" 2 ", 285, 80, font4, 69)
    delay (1000)
    drawfillbox (285, 71, 430, 150, 21)
    Font.Draw (" 1 ", 285, 80, font4, 69)
    delay (1000)
    drawfillbox (285, 71, 430, 150, 21)
    Font.Draw (" Go!!! ", 235, 80, font4, 69)
    delay (1000)
    drawfillbox (270, 71, 430, 150, 21)
end countdown
%-----------------------------------------------------Track------------------------------------------------------------%
proc start
    drawfillbox (300, 11, 304, 40, 0) %
    drawfillbox (300, 16, 304, 22, 7) %<<<<<Start line
    drawfillbox (300, 28, 304, 34, 7) %
end start
proc track
    drawfillbox (7, 7, 633, 11, 21)
    drawfillbox (627, 11, 633, 99, 21)
    drawfillbox (627, 119, 633, 300, 21)
    drawfillbox (627, 321, 633, 397, 21)
    drawfillbox (626, 397, 100, 392, 21)
    drawfillbox (7, 12, 12, 100, 21)
    drawfillbox (60, 40, 580, 60, 21)
    drawfillbox (500, 100, 633, 120, 21)
    drawfillbox (250, 61, 440, 160, 21)
    drawfillbox (100, 160, 580, 180, 21)
    drawfillbox (560, 180, 580, 260, 21)
    drawfillbox (633, 300, 500, 320, 21)
    drawfillbox (500, 220, 520, 300, 21)
    drawfillbox (420, 180, 440, 360, 21)
    drawfillbox (140, 340, 577, 360, 21)
    drawfillbox (7, 280, 100, 397, 21)
    drawfillbox (100, 280, 380, 300, 21)
    drawfillbox (360, 200, 380, 280, 21)
    drawfillbox (150, 200, 360, 220, 21)
    drawfillbox (100, 180, 120, 240, 21)
    drawfillbox (100, 240, 320, 260, 21)
    drawfillbox (7, 100, 53, 279, 21)
    drawfillbox (53, 100, 220, 120, 21)
    %------------------------------Outline of the track------------------------%
    drawline (13, 11, 627, 11, 27)
    drawline (627, 11, 627, 99, 27)
    drawline (627, 121, 627, 299, 27)
    drawline (627, 321, 627, 392, 27)
    drawline (626, 392, 101, 392, 27)
    drawline (12, 11, 12, 99, 27)
    drawline (60, 40, 580, 40, 27)
    drawline (60, 40, 60, 60, 27)
    drawline (60, 60, 250, 60, 27)
    drawline (250, 60, 250, 159, 27)
    drawline (12, 100, 220, 100, 27)
    drawline (220, 100, 220, 120, 27)
    drawline (220, 120, 54, 120, 27)
    drawline (54, 120, 54, 280, 27)
    drawline (54, 280, 360, 280, 27)
    drawline (360, 280, 360, 220, 27)
    drawline (360, 220, 151, 220, 27)
    drawline (151, 220, 151, 200, 27)
    drawline (151, 200, 380, 200, 27)
    drawline (380, 200, 380, 300, 27)
    drawline (380, 300, 101, 300, 27)
    drawline (101, 300, 101, 391, 27)
    drawline (250, 160, 100, 160, 27)
    drawline (100, 160, 100, 260, 27)
    drawline (100, 260, 320, 260, 27)
    drawline (320, 260, 320, 240, 27)
    drawline (320, 240, 120, 240, 27)
    drawline (120, 240, 120, 180, 27)
    drawline (120, 180, 420, 180, 27)
    drawline (420, 180, 420, 340, 27)
    drawline (420, 340, 140, 340, 27)
    drawline (140, 340, 140, 360, 27)
    drawline (140, 360, 577, 360, 27)
    drawline (577, 360, 577, 340, 27)
    drawline (577, 340, 440, 340, 27)
    drawline (440, 340, 440, 180, 27)
    drawline (440, 180, 560, 180, 27)
    drawline (560, 180, 560, 260, 27)
    drawline (560, 260, 580, 260, 27)
    drawline (580, 260, 580, 160, 27)
    drawline (580, 160, 440, 160, 27)
    drawline (440, 160, 440, 60, 27)
    drawline (440, 60, 580, 60, 27)
    drawline (580, 60, 580, 40, 27)
    drawline (500, 100, 627, 100, 27)
    drawline (500, 100, 500, 120, 27)
    drawline (500, 120, 627, 120, 27)
    drawline (520, 300, 627, 300, 27)
    drawline (520, 220, 520, 300, 27)
    drawline (500, 220, 520, 220, 27)
    drawline (500, 220, 500, 320, 27)
    drawline (500, 320, 627, 320, 27)
end track
%---------------------------------------------------Track end----------------------------------------------------------%
track
%------------------------------------------------Speed Boosters--------------------------------------------------------%
proc espeed
    drawfillbox (315, 385, 330, 387, yellow)
    drawfillbox (60, 200, 62, 215, yellow)
end espeed
espeed
%----------------------------------------------Speed Boosters end------------------------------------------------------%
%----------------------------------------------------Player------------------------------------------------------------%
drawfillbox (x, y, x + 10, y + 5, 4)
drawfillbox (x2, y2, x2 + 10, y2 + 5, blue)
start
countdown
Pic.ScreenLoad ("Game logo 2.jpg", 255, 60, picMerge)
loop
    View.Update
    %------------------------------------------------Player control--------------------------------------------------------%
    Input.KeyDown (chars)
    if chars (KEY_RIGHT_ARROW) then
        x := x + 1
        drawfillbox (x, y, x + 10, y + 5, 4)
        drawfillbox (x - 1, y - 1, x + 10, y + 5, 121)
    end if
    if chars (KEY_LEFT_ARROW) then
        x := x - 1
        drawfillbox (x, y, x + 10, y + 5, 4)
        drawfillbox (x - 1, y - 1, x + 11, y + 5, 121)
    end if
    if chars (KEY_UP_ARROW) then
        y := y + 1
        drawfillbox (x, y, x + 10, y + 5, 4)
        drawfillbox (x - 1, y - 1, x + 10, y + 5, 121)
    end if
    if chars (KEY_DOWN_ARROW) then
        y := y - 1
        drawfillbox (x, y, x + 10, y + 5, 4)
        drawfillbox (x - 1, y - 1, x + 10, y + 6, 121)
    end if
    if whatdotcolor (x, y + 6) = 27 or whatdotcolor (x + 11, y + 6) = 27 or whatdotcolor (x, y + 6) = 21 or whatdotcolor (x + 11, y + 6) = 21 then
        y -= 1
    end if
    if whatdotcolor (x, y - 2) = 27 or whatdotcolor (x + 11, y - 2) = 27 or whatdotcolor (x, y - 2) = 21 or whatdotcolor (x + 11, y - 2) = 21 then
        y += 1
    end if
    if whatdotcolor (x - 2, y) = 27 or whatdotcolor (x - 2, y + 6) = 27 or whatdotcolor (x - 2, y) = 21 or whatdotcolor (x - 2, y + 6) = 21 then
        x += 1
    end if
    if whatdotcolor (x + 12, y) = 27 or whatdotcolor (x + 12, y + 6) = 27 or whatdotcolor (x + 12, y) = 21 or whatdotcolor (x + 12, y + 6) = 21 then
        x -= 1
    end if
    %-------------------------------------------Player 2------------------------------------------------------------%
    Input.KeyDown (chars)
    if chars ('d') then
        x2 := x2 + 1
        drawfillbox (x2, y2, x2 + 10, y2 + 5, blue)
        drawfillbox (x2 - 1, y2 - 1, x2 + 10, y2 + 5, 121)
    end if
    if chars ('a') then
        x2 := x2 - 1
        drawfillbox (x2, y2, x2 + 10, y2 + 5, blue)
        drawfillbox (x2 - 1, y2 - 1, x2 + 11, y2 + 5, 121)
    end if
    if chars ('w') then
        y2 := y2 + 1
        drawfillbox (x2, y2, x2 + 10, y2 + 5, blue)
        drawfillbox (x2 - 1, y2 - 1, x2 + 10, y2 + 5, 121)
    end if
    if chars ('s') then
        y2 := y2 - 1
        drawfillbox (x2, y2, x2 + 10, y2 + 5, blue)
        drawfillbox (x2 - 1, y2 - 1, x2 + 10, y2 + 6, 121)
    end if
    if whatdotcolor (x2, y2 + 6) = 27 or whatdotcolor (x2 + 11, y2 + 6) = 27 or whatdotcolor (x2, y2 + 6) = 21 or whatdotcolor (x2 + 11, y2 + 6) = 21 then
        y2 -= 1
    end if
    if whatdotcolor (x2, y2 - 2) = 27 or whatdotcolor (x2 + 11, y2 - 2) = 27 or whatdotcolor (x2, y2 - 2) = 21 or whatdotcolor (x2 + 11, y2 - 2) = 21 then
        y2 += 1
    end if
    if whatdotcolor (x2 - 2, y2) = 27 or whatdotcolor (x2 - 2, y2 + 6) = 27 or whatdotcolor (x2 - 2, y2) = 21 or whatdotcolor (x2 - 2, y2 + 6) = 21 then
        x2 += 1
    end if
    if whatdotcolor (x2 + 12, y2) = 27 or whatdotcolor (x2 + 12, y2 + 6) = 27 or whatdotcolor (x2 + 12, y2) = 21 or whatdotcolor (x2 + 12, y2 + 6) = 21 then
        x2 -= 1
    end if
    %------------------------------------------Player control end----------------------------------------------------%
    if whatdotcolor (x, y - 2) = blue or whatdotcolor (x + 10, y - 2) = blue then
        y += 1
    end if
    if whatdotcolor (x, y + 2) = blue or whatdotcolor (x + 10, y + 2) = blue then
        y -= 1
    end if
    if whatdotcolor (x - 2, y) = blue or whatdotcolor (x - 2, y + 7) = blue then
        x += 1
    end if
    if whatdotcolor (x + 12, y) = blue or whatdotcolor (x + 12, y + 7) = blue then
        x -= 1
    end if


    if whatdotcolor (x2, y2 - 2) = 4 or whatdotcolor (x2 + 10, y2 - 2) = 4 then
        y2 += 1
    end if
    if whatdotcolor (x2, y2 + 2) = 4 or whatdotcolor (x2 + 10, y2 + 2) = 4 then
        y2 -= 1
    end if
    if whatdotcolor (x2 - 2, y2) = 4 or whatdotcolor (x2 - 2, y2 + 7) = 4 then
        x2 += 1
    end if
    if whatdotcolor (x2 + 12, y2) = 4 or whatdotcolor (x2 + 12, y2 + 7) = 4 then
        x2 -= 1
    end if
    %---------------------------------------------Speed Boosters-----------------------------------------------------%
    if whatdotcolor (x - 2, y) = yellow or whatdotcolor (x - 2, y + 5) = yellow then
        x -= 50
    elsif whatdotcolor (x, y - 2) = yellow or whatdotcolor (x + 5, y - 2) = yellow then
        y -= 50
    end if
    if whatdotcolor (x2 - 2, y2) = yellow or whatdotcolor (x2 - 2, y2 + 5) = yellow then
        x2 -= 50
    elsif whatdotcolor (x2, y2 - 2) = yellow or whatdotcolor (x2 + 5, y2 - 2) = yellow then
        y2 -= 50
    end if
    %---------------------------------------------Speed Boosters-----------------------------------------------------%

    drawfillbox (x, y, x + 10, y + 5, 4)
    drawfillbox (x2, y2, x2 + 10, y2 + 5, blue)
    %---------------------------------------Border Restrictions end--------------------------------------------------%
    %------------------------------------------------Winning player 1------------------------------------------------%
    if x = 300 and y >= 7 and y <= 40 and chars (KEY_RIGHT_ARROW) then
        drawfillbox (40, 430, 50, 440, 3)
        counter := counter + 1
        Font.Draw ("Player 1", 10, 460, font, 69)
        Font.Draw ("Lap:", 10, 430, font, 69)
        this := intstr (counter)
        Font.Draw (this, 40, 430, font, 69)
    end if
    %----------------------------------------------Winning end-------------------------------------------------------%
    %---------------------------------------------Winning player 2---------------------------------------------------%
    if x2 = 300 and y2 >= 7 and y2 <= 40 and chars ('d') then
        drawfillbox (130, 430, 185, 440, 3)
        counter3 := counter3 + 1
        Font.Draw ("Player 2", 100, 460, font, 69)
        Font.Draw ("Lap:", 100, 430, font, 69)
        this := intstr (counter3)
        Font.Draw (this, 130, 430, font, 69)
    end if
    drawfillbox (120, 410, 150, 425, 3)
    endStatement := round ((Time.Elapsed / 1000) - 4)
    this := intstr (endStatement)
    Font.Draw (this, 120, 410, font3, 69)
    start
    espeed
    if counter3 = 1 and x = 300 and y >= 7 and y <= 40 and chars (KEY_RIGHT_ARROW) then
        score (counter3) := endStatement
    end if
    if counter3 >= 2 and x = 300 and y >= 7 and y <= 40 and chars (KEY_RIGHT_ARROW) then
        score (counter3) := endStatement - score (counter3 - 1)
    end if
    exit when counter3 = 6 or counter = 6
end loop
cls
backgr
drawbox (250, 197, 400, 350, 69)
Font.Draw ("Player 1", 295, 330, font3, 69)
drawline (250, 328, 400, 328, 69)
Font.Draw (" Lap ", 269, 310, font3, 69)
drawline (325, 328, 325, 197, 69)
Font.Draw (" Time ", 335, 310, font3, 69)
drawline (250, 308, 400, 308, 69)
Font.Draw (" 1 ", 278, 290, font3, 69)
this := intstr (score (1))
Font.Draw (this, 330, 290, font3, 69)
drawline (250, 284, 400, 284, 69)
Font.Draw (" 2 ", 278, 267, font3, 69)
this := intstr (score (2))
Font.Draw (this, 330, 267, font3, 69)
drawline (250, 261, 400, 261, 69)
Font.Draw (" 3 ", 278, 243, font3, 69)
this := intstr (score (3))
Font.Draw (this, 330, 243, font3, 69)
drawline (250, 237, 400, 237, 69)
Font.Draw (" 4 ", 278, 222, font3, 69)
this := intstr (score (4))
Font.Draw (this, 330, 222, font3, 69)
drawline (250, 216, 400, 216, 69)
Font.Draw (" 5 ", 278, 200, font3, 69)
this := intstr (score (5))
Font.Draw (this, 330, 200, font3, 69)

Albrecd




PostPosted: Sun Dec 25, 2005 9:32 pm   Post subject: (No subject)

As an alternative to Time.Elapsed, you could use a delay of (1000) followed by adding one to a variable to count seconds (but you should avoid delays whenever possible and Time.Elapsed is much better than this method)
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: