Results 1 to 5 of 5
  1. #1
    765891 is offline Member
    Join Date
    Jan 2013
    Location
    'Murica
    Posts
    25
    Rep Power
    0

    Unhappy Timed object generation/ for guitar hero game

    Hello and thank you for your patience, time, effort, and energy.

    I want to generate a new tile every 1,5,10,15 (please check the code to gain an understanding of where I'm going) the session last for 4m :20 sec, I need help using the date package, I tried using the sleep method however I don't want to pause the whole thread, so I need help setting up the time aspect of the key generation (assume all other code works).

    Thank you so much you! Drink Coffee happy coding.

    Java Code:
    mport info.gridworld.actor.*;
    import info.gridworld.grid.*;
    import java.awt.*;
    import java.util.*;
    //importations, just in case you were wondering
    
    
    //locations and actor world are set up
    //assume all other code works
            long start = System.currentTimeMillis( );     
             long end = System.currentTimeMillis( );
             long diff = end - start;
            while(diff<260)// 4*60 + 20
            {
                
                 if(diff%1==0)
                    world.add(new Location(0,0), new Red());
                if(diff%5==0)
                    world.add(new Location(0,1), new Green());
                if(diff%10==0)
                    world.add(new Location(0,2), new Yellow());
                if(diff%150==0)
                    world.add(new Location(0,3), new Blue());
                world.show();
    
                end = System.currentTimeMillis( );
                diff = end - start;
    
                
            }
    I'm using grid world to set up the locations, the tiles are actors that move south every turn
    Last edited by 765891; 05-22-2014 at 06:23 AM.

  2. #2
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    1

    Default Re: Timed object generation/ for guitar hero game

    Hmm. I am a little confused: you get the time in milliseconds not seconds!
    So if you want to do something every second then you should check the seconds part.

    And then you can add a small sleep, too. If you know how many miliseconds your code took, you can quickly calculate a small sleep duration. (Or just add a small sleep)

    And you must remember the second you did something. Else you do something multiple times.

    Konrad

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,785
    Blog Entries
    7
    Rep Power
    21

    Default Re: Timed object generation/ for guitar hero game

    Have a look at the java.util.Timer class; it can fire TimerTasks at regular intervals.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    765891 is offline Member
    Join Date
    Jan 2013
    Location
    'Murica
    Posts
    25
    Rep Power
    0

    Default Re: Timed object generation/ for guitar hero game

    Jackpot! THANK YOU! Didn't realize the flaw in my code.


    Quote Originally Posted by kneitzel View Post
    Hmm. I am a little confused: you get the time in milliseconds not seconds!
    So if you want to do something every second then you should check the seconds part.

    And then you can add a small sleep, too. If you know how many miliseconds your code took, you can quickly calculate a small sleep duration. (Or just add a small sleep)

    And you must remember the second you did something. Else you do something multiple times.

    Konrad

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: Timed object generation/ for guitar hero game

    Good that you know what the problem is, that's a learning moment. But don't ignore Jos's suggestion either; why reinvent the wheel when you can just use existing standard APIs.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. [Video Tutorials] Java-School ~ From Zero to Hero
    By CTucker1327 in forum Forum Lobby
    Replies: 0
    Last Post: 11-27-2013, 11:12 PM
  2. Replies: 0
    Last Post: 11-27-2013, 03:04 PM
  3. Replies: 0
    Last Post: 12-14-2011, 10:08 PM
  4. Game Object mapping
    By Hikilaka in forum Java Gaming
    Replies: 2
    Last Post: 10-03-2011, 01:55 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •