Thread: getting input without waiting for it(tetris)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    and you might have to change your timer function (someone verify this).
    Code:
    //Timer Function
    int timer(double t)
    {
        int kp;
        double start=double(clock())/1000,end=double(clock())/1000;
        for (double dif=0;dif<=t;dif=end-start){end=double(clock())/1000;}
        while (kbhit())
        {
        kp=getkeypress();
        return kp;
        break;}
    }
    clock()'s standard, but getkeypress() isn't. BTW, you don't need a while loop, and your casts were wrong:
    Code:
    //Timer Function
    int timer(double t)
    {
        int kp;
        double start=(double)(clock())/1000,end=(double)(clock())/1000;
        for (double dif=0;dif<=t;dif=end-start){end=(double)(clock())/1000;}
        if (kbhit())
        {
        kp=getkeypress();
        return kp;
        }
        return 0;
    }
    Last edited by dwks; 12-10-2005 at 04:23 PM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  2. #2
    Selfteaching c++ student
    Join Date
    Dec 2005
    Location
    good old US of A
    Posts
    15
    The version I have right now (the second that I posted) doesn't use the timer function I was trying to work out how to include the kbhit() function, but I ended up rewriting so the timer is in main. I forgot to delete timer(). And getkeypress() is my own function. Why are the casts wrong? the tutorial gives this as an example:
    Code:
    int main()       
    {
      cout<< char ( 65 ) <<"\n"; 
      cin.get();
    }
    Anyway I've tested it (tetris) and I've got two problems:
    1 The display flickers. The link treenef gave looks like it will help solve this (been kindof busy, so I havn't gotten around to it yet)

    2 The program is choppy. This can be fatal in tetris. Mostly, I push a key and the block moves accordingly, but sometimes it lags, or take several times. I'm not sure why, maybe the way I have it looping isn't the best way to do things

    Oh, yes. On the topic of crossplatforming, how difficult is it to prog for the palm os (4 or less, not 5). I'm kindof curious, cause while its unlikely that I will be programming something I'd actually use much for a while, even this tetris program would be fun if I could make a palm version.
    Last edited by Argentum; 12-10-2005 at 06:30 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Input class project (again)
    By Elysia in forum C++ Programming
    Replies: 41
    Last Post: 02-13-2009, 10:52 AM
  2. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  3. Structure and Linked List User Input Question
    By kevndale79 in forum C Programming
    Replies: 16
    Last Post: 10-05-2006, 11:09 AM
  4. Getting input without waiting for keypress
    By Anon48 in forum C Programming
    Replies: 2
    Last Post: 04-08-2005, 02:18 AM
  5. need help with some input
    By blindleaf in forum C Programming
    Replies: 2
    Last Post: 03-16-2003, 01:50 PM