Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: myPong

  1. #11
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    Version 3 is out.
    Thanks again to wargamer and I would like to thank users from GD that assisted me.

    Updates:

    Game can be paused by pressing the pause button on the keyboard OR if your window looses focus it automatically pauses as well and resumes when it gets its focus back.
    The background transitioning works great now
    Fixed an issue with the screen going white after some time (thanks to wargamer)
    Added a scoreboard to keep your score, however I'm running into 2 problems, and I'm not sure why. 1. It doesn't center properly 2. It prints a bunch of random characters after the computer score. This should be fixed in the next release along with other updates.

    Here is the scoreboard function that is a bit glitchy.

    PHP Code:
    void scoringBoard(HDC hdcRECTr)
    {
        
    char szBuffer[50];
        
    RECT rec initRecArea(r.leftr.topscreenWidthscreenHeight);
        
    GetClientRect(hWnd, &rec); 
        
    screenWidth = (rec.right rec.left);

        
    _stprintf_s(szBuffer,"Player: %i Computer: %i\n"playerScorecompScore);
        
    SetBkModehdcTRANSPARENT );
        
    TextOut(hdc, (screenWidth 2), 0szBuffersizeof(szBuffer));


  2. #12
    Banned
    Join Date
    May 2010
    Location
    fuck off?
    Posts
    1,145

    Default

    szBuffer deleted? after that function, and thus, nothing to display.


    how is text out printing to the centre? ..as its getting the centre, is it then managing to find the centre of a fixed width font?

  3. #13
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    PHP Code:
    char szBuffer[50];
        
    RECT rec initRecArea(r.leftr.topscreenWidthscreenHeight);
        
    GetClientRect(hWnd, &rec); 
        
    screenWidth = (rec.right rec.left); 
    This code gets the rectangular area of our parent window which is hWnd.
    Width is then calculated by by getting the difference from the right side of the rectangle to the left side.

    PHP Code:
     _stprintf_s(szBuffer,"Player: %i Computer: %i\n"playerScorecompScore); 
    We put the scores into the buffer and player & comp scores are globally defined. The values change accordingly as well so the computation is correct when the paddle scores.

    PHP Code:
    SetBkModehdcTRANSPARENT ); 
    This piece of code simply tells the application to render the text on the background as opposed to it's default background which is white.

    PHP Code:
    TextOut(hdc, (screenWidth 2), 0szBuffersizeof(szBuffer)); 
    Here is the function on MSDN: http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    The 2nd parameter is the x value (location on screen), so naturally it should be
    (screenWidth / 2) - string length

    Although this doesn't seem to work, and I'm not sure why. I will go ahead and try SetTextAlign().

    EDIT:
    SetTextAlign() doesn't seem to work for me either I'll have to take a different approach.

  4. #14
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    I updated the scoreboard and got it centered now and it seems to be printing correctly for most part, but for some odd reason it's not outputting a new line using "\n"???
    PHP Code:
    void scoringBoard(HDC hdcRECTr)
    {
        
    char szBuffer[50];

        
    _stprintf_s(szBuffer,"Player: %i\nComputer: %i"playerScorecompScore);
        
    SetBkMode(hdcTRANSPARENT);
        
    SetTextAlign(hdc,TA_CENTER);
        
    TextOut(hdc, ((r.right r.left - (strlen(szBuffer))) / 2), 0szBuffer, (strlen(szBuffer)));

    EDIT Fixed! I'll overwrite the v3 with this new one. This now has a working scoreboard along with all the previous additions in v3. Enjoy!

  5. #15
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    Noticed the link was wrong, it's fixed now :P

  6. #16
    Banned
    Join Date
    May 2010
    Location
    fuck off?
    Posts
    1,145

    Default

    this is direct x? didnt even know there was a text align. Good work though.

  7. #17
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    nah it's not opengl or directx the colors and everything is hand coded using nothing other than Win32 API. That's the cool thing!

Posting Permissions

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