Intel sponsors gamedev.net search:   
Adventures in Text-modeBy Twisol      
In order of no progress to done: Red, Orange, Yellow, Blue, Light blue, Green, Light green.

Last updated 2/12/09 at 12:01 am PST

Cripes! 2.0 -- See the Class Layout

Arenamatic Code w/ cConsole


Friday, May 30, 2008
Tonight I worked through my implementation of "timers" a little bit, and fleshed out how I want the game to run a little more. My "delay" techinque, quite simply, was restrictive. Luckily, I found out about the SetTimer function. I had to rework the main loop of my program (as seen in my last journal entry), but I think it was definitely worth it.

My current approach leaves the keypress checking to the main loop, and moves the actual HUD updates to a TimerProc function. I have to create a timer with SetTimer and pass it the address of TimerProc, so during my main loop I also check for messages, and translate/dispatch the WM_TIMER messages. Dispatching the WM_TIMER message, if it was caused by the timer I created, will call TimerProc!

Below is my new and improved main() function, as well as my current TimerProc function.

void CALLBACK TimerProc(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
    static bool timestatinc = false;
    //Because this function is called every 500ms, I need to keep track
    //of whena full second has passed. Only then do I update the time data.
        
    if (timestatinc)
        ++GameInfo.time;
    
    GameInfo.score += 10;
    
    hud.Draw(0, 0);
    
    timestatinc = !timestatinc;
}

int main()
{
    Init();
    hud.Draw(0, 0);
        
    if (!SetTimer(NULL, 1, 500, &TimerProc))
        return 1;
    
    while (true)
    {
        int vkey = CheckForKeypress();
        if (vkey == VK_ESCAPE)
            break;
    
        MSG msg;
    
        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            if (msg.message == WM_TIMER)
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }
    }
    
    KillTimer(NULL, 1);
}





I'm still not sure what the commenters meant in my last post, but I'm pretty sure this approach will be sufficient for Cripes!. Thanks for the input though, always great to have! *hint hint*


EDIT: In other news, my grandmother let me pick out and buy three books, which totalled to $140 total. I know, it's mean for me to do that, but she let me AND she said it would be an early birthday present. "As long as you read them and learn from them, I'm fine!" So, yeah. I'm now the proud-to-semi-proud owner of World of Warcraft Programming (addons and such), Breaking Into the Game Industry (my favorite so far!), and Windows From C/C++ (at $70, I should like this best, but... I don't. It's handy though, and I got the SetTimer idea from it!)

Comments: 0 - Leave a Comment

Link



Tuesday, May 27, 2008
First, a thanks to EasilyConfused for his much appreciated comment. :D

Today I coded in a timed delay thing into the game's main loop. This way things don't go lightning-fast on the player... it's limited to doing stuff once every 500 miliseconds now. I guess you could call each interval the game does stuff in a "frame", yes? I also added a keyboard input function, to check if there was a valid keypress, and return its virtual key identifier (for example, VK_ESCAPE)

Here's my main() function, to show you how the main loop looks so far. I think I just need to work on the actual gameplay now...

int main()
{
    Init(); // Sets up the HUD details and console title
    
    bool quit = false;
    int timestat = 0; // Because each frame is half a second, I need
                      // a way to know when to increment the HUD's time
                      // field - that is, once every two frames.
    
    while (!quit)
    {
        unsigned long currtime = GetTickCount();
        hud.Draw(0, 0); // The arguments specify the x,y coord of the
                        // top-left corner of the HUD.
    
        GameInfo.score += 10;
    
        if (timestat == 0) timestat = 1;
        else if (timestat == 1) { timestat = 0; GameInfo.time += 1; }
    
        // During the delay time, when nothing is being done, I watch for
        // keypresses. I used to have it outside the while, but there was
        // a visible delay between pressing and exiting when the key was
        // pressed after the check and during the delay. Placing it in the
        // loop lets me check as many times as the while iterates per frame,
        // and because the game doesn't take long to process what I have so
        // far, there's no visible delay in quitting.
    
        while (currtime+500 > GetTickCount())
            if (CheckForKeypress() == VK_ESCAPE)
            {
                quit = true;
                break;
            }
    }	
}




EDIT: If you're wondering, and I'm sure you are, the game looks no different now than a month ago. The only differences are internal, except that I'm actually displaying the game's data in the HUD, not just the "static" lines. Nothing new though, just zeroes! (Although I use a line of six zeroes as a static to the right of the Score line, so it looks like we've got a sort of zerofilled score going on when the score is drawn on top of it. I likey.)

Comments: 5 - Leave a Comment

Link



Sunday, May 25, 2008
I finished task two of my to-do list today, so now my HUD's data is all stored in files for easy modification. I have the single lines of info (like "Score" and the smiley face characters) in "statics.txt", and the actual data in "layout.txt". The format for the statics is one static per line, in the form "<color #> <x coord> <y coord> <string of characters>".

For the layout file, things are a little different, because there's a specific number of data items that the game needs to place. There's nine data fields on the HUD, so there has to be a corresponding line for each. The format is just like the statics.txt, but in the form "<alignright boolean (1 or 0)> <color> <x coord> <y coord>".

In the end, a chunk of code for laying out the HUD has been taken out. Yay clean code. I think I'm going to work on the timer class next...

(I haven't had comments in ages! A simple "hey, looks good" would be nice XD)

Comments: 1 - Leave a Comment

Link


All times are ET (US)

 
S
M
T
W
T
F
S
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
26
28
29

OPTIONS
Track this Journal

 RSS 

ARCHIVES
August, 2009
July, 2009
March, 2009
February, 2009
December, 2008
November, 2008
October, 2008
August, 2008
July, 2008
June, 2008
May, 2008
April, 2008
November, 2007
July, 2007
June, 2007
May, 2007
April, 2007
March, 2007
February, 2007
December, 2006
October, 2006
September, 2006
July, 2006
May, 2006
April, 2006