Blizzard Demo

This is a discussion on Blizzard Demo within the C++ Programming forums, part of the General Programming Boards category; I have a problem with a blizzard demo I am writing. It is from gaming programming book by michael morrison. ...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    2

    Blizzard Demo

    I have a problem with a blizzard demo I am writing. It is from gaming programming book by michael morrison. I'm using dev-c++ ide. It involves drawing icons to a window in random locations. I did search the forums and found most people call it the skeleton program that draws skeletons not snowflakes. Anyway here is the main code.


    Code:
    #include "Blizzard.h"
    
    #include <stdlib.h>
    
    bool GameInitialize(HINSTANCE hInstance)
    {
    //create game engine
        g_pGame = new GameEngine(hInstance, TEXT("Blizzard"),
        TEXT("Blizzard"), IDI_BLIZZARD, IDI_BLIZZARD_SM);
        if (g_pGame == NULL)
        return FALSE;
    
    // set frame rate
    
        g_pGame ->SetFrameRate(1);
    
        return TRUE;
    
    }
    
    void GameStart(HWND hWindow)
    {
        // seed random number generator
        srand(GetTickCount());
    }
    
    void GameEnd()
    {
        // game clean up engine
        delete g_pGame;
    }
    
    void GameActivate(HWND hWindow)
    {
        HDC hDC;
        RECT rect;
    
        // draw activation text on game screen
        GetClientRect(hWindow, &rect);
        hDC = GetDC(hWindow);
        DrawText(hDC, TEXT("Here comes the Blizzard!"), -1, &rect, DT_SINGLELINE|DT_CENTER|DT_VCENTER);
        ReleaseDC(hWindow, hDC);
    }
    
    void GameDeactivate(HWND hWindow)
    {
        HDC hDC;
        RECT rect;
    
        // draw deactivation text on game screen
        GetClientRect(hWindow, &rect);
        hDC = GetDC(hWindow);
        DrawText(hDC, TEXT("The Blizzard has passed."), -1, &rect, DT_SINGLELINE|DT_CENTER|DT_VCENTER);
        ReleaseDC(hWindow, hDC);
    }
    
    void GamePaint(HDC hDC)
    {
    }
    
    void GameCycle()
    {
        HDC hDC;
        HWND hWindow = g_pGame ->GetWindow();
    
        // draw snowflake at random positisons on screen
        hDC = GetDC(hWindow);
        DrawIcon(hDC, rand() &#37; g_pGame->GetWidth(), g_pGame->GetHeight(), (HICON)(WORD)GetClassLong(hWindow, GCL_HICON));
        ReleaseDC(hWindow, hDC);
    
    }
    I hope the above is readable. Tried to follow the sticky FAQ

    The error I get is
    warning: cast to pointer from integer of different size related to the line DrawIcon etc, hopefully in bold above.
    It compiles but when run I get a small icon in titlebar but no sign of any snowflakes appearing on the screen. Interestingly if I minimise the window and then maximise it displays text called "here comes the blizzard!". This must be invoking msg handler GameActivate.
    Any help would be greatly appreciated (if you need to see other headers/resource let me know).
    Last edited by dazza33; 08-23-2007 at 07:55 PM.

  2. #2
    Registered User
    Join Date
    Aug 2007
    Posts
    13
    A good idea is to look online for a working example of DrawIcon, just google it, and find out whether your casting is correct. I don't quite understand the problem you are having, but I'm sure if you were to find a better DrawIcon example code you can fix this problem easily.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,261
    Am I the only one that got duped into thinking this was going to be about a game demo from Blizzard Entertainment?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    No, you're not. I actually only clicked this because I wondered what the thread was doing in this board.

    Anyway, now that I'm here ...
    Code:
     (HICON)(WORD)GetClassLong(hWindow, GCL_HICON));
    Should be
    Code:
    (HICON)GetClassLongPtr(hWindow, GCLP_HICON));
    I've no idea what possessed the book author to first cast the value to a WORD.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User
    Join Date
    Aug 2007
    Posts
    2

    Thanks

    Thanks for replies. Sorry for misleading title with blizzard entertainment.
    Decided to try ArseNic suggestion and simply made one snowflake appear on the screen. Once that worked I set up a loop with rand inside to generate x,y coordinates. This actually worked and produced a pretty good pattern. Was great full my skills taught me to problem solve.

    Code:
     int x=10;
        int y = 10;
        int z =0;
        
       while (z< 700)
       {
        
        // draw snowflake at random positisons on screen
        hDC = GetDC(hWindow);
        DrawIcon(hDC, rand() % x, rand() % y, (HICON)(WORD)GetClassLong(hWindow, GCL_HICON));
        ReleaseDC(hWindow, hDC);
        x=x+ rand() % 300;
        y=y+ rand() % 300;
        z++;
    That's it. Not sure if it's very optimised but works!
    Thanks CornedBee for suggestion. Tried altering original with that code but it halted with GetClassLongPtr , GCLP underfined.

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    Hmm ... probably because Dev-C++ comes with an old version of the SDK. Recent Code::Blocks releases would be better, there.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Forming RTS Demo Team Sixth Extinction
    By SteelRain4eva in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 06-08-2006, 08:47 PM
  2. Adventurers and Outlaws and new Demo
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 11-07-2004, 04:06 AM
  3. Matrix Demo
    By Carlos in forum Game Programming
    Replies: 7
    Last Post: 04-23-2003, 10:00 AM
  4. Second MoA Demo Tomorrow
    By harryP in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-30-2002, 07:22 PM
  5. SkyLock graphics engine demo
    By jdinger in forum Game Programming
    Replies: 18
    Last Post: 06-26-2002, 07:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21