Hello all! I have been learning how to use the win32 api from a book, but I've encountered an error that I can not seem to fix. Before I go any further, here is the functions giving me errors, along with all of my include files
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
// UFO C++ Source
// Include Files
#include "Ufo.h"
#include <algorithm>
void GameCycle()
{
// Update the saucer position
_iSaucerX = min(500 - _pSaucer->GetWidth(), max(0, _iSaucerX + _iSpeedX));
_iSaucerY = std::min(320, std::max(0, _iSaucerY + _iSpeedY));
// Force a repaint to redraw the saucer
InvalidateRect(_pGame->GetWindow(), NULL, FALSE);
}
void HandleKeys()
{
// Change the speed of the saucer in responce to arrow key presses
if(GetAsyncKeyState(VK_LEFT) < 0)
_iSpeedX = max(-_iMAXSPEED, _iSpeedX - 2);
else if (GetAsyncKeyState(VK_RIGHT) < 0)
_iSpeedX = min(_iMAXSPEED, _iSpeedX + 2);
else
_iSpeedX *= .95;
if (GetAsyncKeyState(VK_UP) < 0)
_iSpeedY = max(-_iMAXSPEED, _iSpeedY - 2);
else if (GetAsyncKeyState(VK_DOWN) < 0)
_iSpeedY = min(_iMAXSPEED, _iSpeedY + 2);
else
_iSpeedY = min(_iMAXSPEED, _iSpeedY += .5);
}
|
And here is the header file for that, which may help:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#pragma once
// Include Files
#include <windows.h>
//#include <cstring>
#include <algorithm>
#include "Resource.h"
#include "GameEngine.h"
#include "Bitmap.h"
// Global Variables
HINSTANCE _hInstance;
GameEngine* _pGame;
const int _iMAXSPEED = 8;
Bitmap* _pBackground;
Bitmap* _pSaucer;
double _iSaucerX, _iSaucerY, _iSpeedX, _iSpeedY;
//char _cDebug[256];
|
Now, when this code was copied verbatim from the book, I had no error. However, when I added some friction (
_iSpeedX *= .95;
) and gravity (
_iSpeedY = min(_iMAXSPEED, _iSpeedY += .5);
), all of a sudden every single instance of
min()
and
max
gives the error "error: 'max' was not declared in this scope". I think that this is related to the namespace, as putting
std::
in front of the operations sometimes helps. I have done some researching, yet I can't seem to find a related instance. Does anybody know what the problem could be?