Writing a timer in jack

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Writing a timer in jack

ScarySheep
Hello, I am trying to make a game in Jack which requires a countdown timer while the player is playing.
Something like this https://www.youtube.com/watch?v=IYAt9o9tWJY
While looking at the default library, I can't think of a way to support multithreading.
Maybe there is some way of doing it?
Thanks!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Writing a timer in jack

cadet1620
Administrator
The documented OS library is all there is. The OS is designed to be as simple as possible so that students can implement it completely in project 12.

Your program will need to have a main loop that runs continuously, calling the required services periodically. If all you need is keyboard, continuing movement and countdown it would be something like
method void run() {
    var int t_move, t_count;
    while (true) {
        if (Keyboard.keyPressed()) {
            do processKey();
        }
        let t_move = t_move+1;
        if (t_move > 100) {
            do processMove();
            let t_move = 0;
        }
        let t_count = t_count +1;
        if (t_count > 2500) {
            do processCount();
            let t_count = 0;
        }
    }
Notice that this loop does not use Sys.wait() because it is a blocking delay—it does not return until the requested time elapses.

--Mark
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Writing a timer in jack

ScarySheep
Thanks a lot for the help. It clear things up.
At first I was trying to use Sys.wait() but I knew it might not work.
I'll definitely try your solution.
Loading...