-
Help with part of code.
Im currently debugging code for a game I'm writting and there is several errors I can't understand.
I would post this is the game programming forum, but the errors seems to be centered around actually C++ coding errors so I thought here might be better.
The first piece of code I'm getting errors with is:
Code:
// Change the speed of the saucer in response to arrow key presses
if (GetAsyncKeyState(VK_LEFT) < 0)
g_pCraftSprite->SetVelocity_x(--g_pCraftSprite->GetVelocity_x());
else if (GetAsyncKeyState(VK_RIGHT) < 0)
g_pCraftSprite->SetVelocity_x(++g_pCraftSprite->GetVelocity_x());
if (GetAsyncKeyState(VK_UP) < 0)
g_pCraftSprite->SetVelocity_y(--g_pCraftSprite->GetVelocity_y());
else if (GetAsyncKeyState(VK_DOWN) < 0)
g_pCraftSprite->SetVelocity_y(++g_pCraftSprite->GetVelocity_y());
I get the following errors for all 4 key states:
"spaceevade.cpp": E2096 Illegal structure operation in function HandleKeys() at line 274
Any help understanding this error would be appreciated.
My second error is in the code:
Code:
//Increase Velocity of asteriods
for(i=0; i<9; i++)
{
g_pAsteriodSprite[i]->SetVelocity((g_pAsteriodSprite[i]->GetVelocity_x() + (g_iLevel*2)),
(g_pAsteriodSprite[i]->GetVelocity_x() + (g_iLevel*2)));
}
I get the following error:
"spaceevade.cpp": E2094 'operator+' not implemented in type 'tagPOINT' for arguments of type 'int' in function EndLevel() at line 362
Again I don't understand this problem.
I've only posted the parts of the code with problems to save space, but if the rest is needed I can easily post this.
Thanks in advance for any help.
-
I'm not sure about the first error as I've never seen that function. AS for the second one, your error is right here:
Code:
g_pAsteriodSprite[i]->SetVelocity((g_pAsteriodSprite->GetVelocity_x() +=(g_iLevel*2))
Unless that's an array of pointers, which I doubt it is, then you should be using a . operator not a -> operator.
Change it to this and see what happens:
Code:
g_pAsteriodSprite[i].SetVelocity((g_pAsteriodSprite->GetVelocity_x() +=(g_iLevel*2))
-
It is an array of pointers to Bitmap images i believe. Besides every other time I access a member function with g_pAsteriodSprite[i] it used the -> its just that part of code it doesnt like.
As i stated in my post edit i changed that code to:
Code:
for(i=0; i<9; i++)
{
g_pAsteriodSprite[i]->SetVelocity((g_pAsteriodSprite[i]->GetVelocity_x() + (g_iLevel*2)),
(g_pAsteriodSprite[i]->GetVelocity_x() + (g_iLevel*2)));
}
and now i get a compltely different error.
"spaceevade.cpp": E2094 'operator+' not implemented in type 'tagPOINT' for arguments of type 'int' in function EndLevel() at line 362
If that changes things at all?
-
Looks like you have to overload the + operator for the type tagPOINT.
-
Problem fixed.
My GetVelocity_x() function was declared as a POINT instead of an int, so the operators were not working.
Thanks for your help.