I get the following errors.
Severity Code Description Project File Line Suppression State
Error (active) E0020 identifier "Rect1" is undefined Project95 C:\Users\Owner\source\repos\Project95\Project95\struct.cpp 16
Error (active) E0020 identifier "Rect2" is undefined Project95 C:\Users\Owner\source\repos\Project95\Project95\struct.cpp 16
Error (active) E0135 class "SDL_Rect" has no member "left" Project95 C:\Users\Owner\source\repos\Project95\Project95\struct.cpp 43
Error (active) E0020 identifier "SDL_RenderImage" is undefined Project95 C:\Users\Owner\source\repos\Project95\Project95\struct.cpp 46
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int Project95 c:\users\owner\source\repos\project95\project95\struct.cpp 16
Error C2143 syntax error: missing ',' before '&' Project95 c:\users\owner\source\repos\project95\project95\struct.cpp 16
Error C2065 'rect1': undeclared identifier Project95 c:\users\owner\source\repos\project95\project95\struct.cpp 18
Error C2065 'rect2': undeclared identifier Project95 c:\users\owner\source\repos\project95\project95\struct.cpp 18
Error C2065 'rect1': undeclared identifier Project95 c:\users\owner\source\repos\project95\project95\struct.cpp 19
Error C2065 'rect2': undeclared identifier Project95 c:\users\owner\source\repos\project95\project95\struct.cpp 19
here is my code I really like what jjoe has presented, it should work well with breakout bricks.
#include <iostream>
#include <SDL.h>
using namespace std;
class Rect
{
public:
float x = 0;
float y = 0;
float w = 0;
float h = 0;
};
bool intersectRect(const Rect1& rect1, const Rect2& rect2)
{
return rect1.x < rect2.x + rect2.w && rect1.x + rect1.w > rect2.x &&
rect1.y < rect2.y + rect2.h && rect1.y + rect1.h > rect2.y;
}
int main(int argc, char* args[])
{
Rect r[5 * 4];
for (int y = 0; y < 4; y++)
{
for (int x = 0; x < 5; x++)
{
int index = y * 5 + x;
r[index].x = x * 30;
r[index].y = y * 20;
r[index].w = 20;
r[index].h = 10;
}
}
while (true) // gameloop pseudocode
{
for (int index = 0; index < 5 * 4; index++)
{
SDL_Rect renderRect;
renderRect.left = r[index].x;
//...
SDL_RenderImage(renderRect);
}
}
return 0;
}