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

Username:   Password: 
 RegisterRegister   
 Timer Class
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ericfourfour




PostPosted: Fri Sep 22, 2006 4:43 pm   Post subject: Timer Class

Here is my timer class. I'm going to be using it for the gui I'm working on (ex. scroll bars).

code:

class Timer
    export initialize, time_up

    var attr :
        record
            ending, duration, current : int
            consistant : boolean
        end record

    proc initialize (duration : int, consistant_time : boolean)
        attr.current := Time.Elapsed
        attr.ending := attr.current + duration
        attr.duration := duration
        attr.consistant := consistant_time
    end initialize

    fcn time_up () : boolean
        attr.current := Time.Elapsed
        var overshot := attr.current - attr.ending
        if overshot >= 0 then
            if attr.consistant then
                attr.ending += attr.duration + overshot
            end if
            result true
        end if
        result false
    end time_up
end Timer

var timer : ^Timer
new Timer, timer
timer -> initialize (100, true)
loop
    loop
        exit when timer -> time_up ()
    end loop
end loop


Instructions:
1. Create an instance of the timer.
code:

var timer : ^Timer
new Timer, timer

2. Initialize the timer.
code:

timer -> initialize (100, true)
%The first parameter is the delay.
%The second parameter is hard to explain.
%   -If you want the timer to continue timing when the time is up set the parameter as true.
%       -Used with fps limiters.
%   -If you don't want the timer to reset its values and continue, then set it as false.
%       -Used with things that require different delays (ex. when you hold a key in a text box it has a long delay for the first character outputted).

3. Check if the time is up.
code:

if timer -> time_up () then
    %Do something.
end if

4. If you set the second parameter to true while initializing you don't need to re-initialize the timer to use it again.
Sponsor
Sponsor
Sponsor
sponsor
Hackmaster




PostPosted: Sun Dec 10, 2006 9:55 am   Post subject: (No subject)

this is great! this is not unlike something I made a while back to make a mini game in a large game...


you should advertise this better, eric! there are like 5 million submissions on the help forums about : "How do I make a time that'll start when I want it to?"

great work again! keep it up!
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: