Hi guys!
I am trying to make a Clickomania game using SDL. I think everything should be working, but I am getting some very weird, cryptic compiler/linker errors. I tried changing the order of the lines "#include <vector>" and "using namespace std;" and that changes the error messages. I tried all possible combinations, I think, and none worked. This error is with the code exactly as shown below:
Error 4 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\ze\documents\visual studio 2012\projects\clickomania\clickomania\Header.h 232 1 Clickomania
Error 5 error C2334: unexpected token(s) preceding '{'; skipping apparent function body c:\users\ze\documents\visual studio 2012\projects\clickomania\clickomania\Header.h 233 1 Clickomania
Error 15 error C2228: left of '.end' must have class/struct/union c:\users\ze\documents\visual studio 2012\projects\clickomania\clickomania\Header.h 208 1 Clickomania
Error 25 error C2228: left of '.end' must have class/struct/union c:\users\ze\documents\visual studio 2012\projects\clickomania\clickomania\Header.h 216 1 Clickomania
Error 29 error C2227: left of '->IsAlive' must point to class/struct/union/generic type c:\users\ze\documents\visual studio 2012\projects\clickomania\clickomania\Header.h 218 1 Clickomania
Error 33 error C2227: left of '->GetRow' must point to class/struct/union/generic type c:\users\ze\documents\visual studio 2012\projects\clickomania\clickomania\Header.h 221 1 Clickomania
Error 31 error C2227: left of '->GetColumn' must point to class/struct/union/generic type c:\users\ze\documents\visual studio 2012\projects\clickomania\clickomania\Header.h 220 1 Clickomania
Error 19 error C2227: left of '->Delete' must point to class/struct/union/generic type c:\users\ze\documents\visual studio 2012\projects\clickomania\clickomania\Header.h 210 1 Clickomania
Error 3 error C2143: syntax error : missing ';' before '<' c:\users\ze\documents\visual studio 2012\projects\clickomania\clickomania\Header.h 232 1 Clickomania
Error 17 error C2143: syntax error : missing ';' before '{' c:\users\ze\documents\visual studio 2012\projects\clickomania\clickomania\Header.h 209 1 Clickomania
Error 27 error C2143: syntax error : missing ';' before '{' c:\users\ze\documents\visual studio 2012\projects\clickomania\clickomania\Header.h 217 1 Clickomania
Error 16 error C2143: syntax error : missing ';' before ')' c:\users\ze\documents\visual studio 2012\projects\clickomania\clickomania\Header.h 208 1 Clickomania
Error 26 error C2143: syntax error : missing ';' before ')' c:\users\ze\documents\visual studio 2012\projects\clickomania\clickomania\Header.h 216 1 Clickomania
Error 6 error C2065: 'vector' : undeclared identifier c:\users\ze\documents\visual studio 2012\projects\clickomania\clickomania\Header.h 200 1 Clickomania
Error 10 error C2065: 'vector' : undeclared identifier c:\users\ze\documents\visual studio 2012\projects\clickomania\clickomania\Header.h 208 1 Clickomania
Error 20 error C2065: 'vector' : undeclared identifier c:\users\ze\documents\visual studio 2012\projects\clickomania\clickomania\Header.h 216 1 Clickomania
Error 8 error C2065: 'Neighbors' : undeclared identifier c:\users\ze\documents\visual studio 2012\projects\clickomania\clickomania\Header.h 201 1 Clickomania
Error 9 error C2065: 'Neighbors' : undeclared identifier c:\users\ze\documents\visual studio 2012\projects\clickomania\clickomania\Header.h 202 1 Clickomania
Error 14 error C2065: 'Neighbors' : undeclared identifier c:\users\ze\documents\visual studio 2012\projects\clickomania\clickomania\Header.h 208 1 Clickomania
Error 24 error C2065: 'Neighbors' : undeclared identifier c:\users\ze\documents\visual studio 2012\projects\clickomania\clickomania\Header.h 216 1 Clickomania
Error 13 error C2065: 'iter' : undeclared identifier c:\users\ze\documents\visual studio 2012\projects\clickomania\clickomania\Header.h 208 1 Clickomania
Error 18 error C2065: 'iter' : undeclared identifier
Error 23 error C2065: 'iter' : undeclared identifier
Error 28 error C2065: 'iter' : undeclared identifier
Error 30 error C2065: 'iter' : undeclared identifier
Error 32 error C2065: 'iter' : undeclared identifier Error 1 error C2061: syntax error : identifier 'vector'
Error 2 error C2061: syntax error : identifier 'vector'
Error 7 error C2059: syntax error : '>'
Error 11 error C2059: syntax error : '>'
Error 21 error C2059: syntax error : '>'
Error 12 error C2039: 'iterator' : is not a member of '`global namespace''
Error 22 error C2039: 'iterator' : is not a member of '`global namespace''
This is the main .cpp file:
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
#include <stdio.h>
#include <stdlib.h>
#include "SDL.h"
#include <ctime>
#include <cstdlib>
#include <vector>
using namespace std;
#include "Header.h"
void Slock(SDL_Surface *screen)
{
if ( SDL_MUSTLOCK(screen) )
{
if ( SDL_LockSurface(screen) < 0 )
{
return;
}
}
}
void Sulock(SDL_Surface *screen)
{
if ( SDL_MUSTLOCK(screen) )
{
SDL_UnlockSurface(screen);
}
}
void DrawPixel(SDL_Surface *screen, int x, int y,
Uint8 R, Uint8 G, Uint8 B)
{
Uint32 color = SDL_MapRGB(screen->format, R, G, B);
switch (screen->format->BytesPerPixel)
{
case 1: // Assuming 8-bpp
{
Uint8 *bufp;
bufp = (Uint8 *)screen->pixels + y*screen->pitch + x;
*bufp = color;
}
break;
case 2: // Probably 15-bpp or 16-bpp
{
Uint16 *bufp;
bufp = (Uint16 *)screen->pixels + y*screen->pitch/2 + x;
*bufp = color;
}
break;
case 3: // Slow 24-bpp mode, usually not used
{
Uint8 *bufp;
bufp = (Uint8 *)screen->pixels + y*screen->pitch + x * 3;
if(SDL_BYTEORDER == SDL_LIL_ENDIAN)
{
bufp[0] = color;
bufp[1] = color >> 8;
bufp[2] = color >> 16;
}
else
{
bufp[2] = color;
bufp[1] = color >> 8;
bufp[0] = color >> 16;
}
}
break;
case 4: // Probably 32-bpp
{
Uint32 *bufp;
bufp = (Uint32 *)screen->pixels + y*screen->pitch/4 + x;
*bufp = color;
}
break;
}
}
void Draw(SDL_Surface* screen, Uint32 colors[DEAD], Board* Board)
{
for (int row = 0; row < NUMBER_SIDES; row++)
{
for (int column = 0; column < NUMBER_SIDES; column++)
{
Block* Block = Board->GetBlock(row, column);
switch (Block->GetColor())
{
case BLUE:
SDL_FillRect(screen, Block->GetRect(), colors[BLUE]);
break;
case RED:
SDL_FillRect(screen, Block->GetRect(), colors[RED]);
break;
case GREEN:
SDL_FillRect(screen, Block->GetRect(), colors[GREEN]);
break;
case YELLOW:
SDL_FillRect(screen, Block->GetRect(), colors[YELLOW]);
break;
}
}
}
}
int main(int argc, char *argv[])
{
srand(static_cast<unsigned int>(time(0)));
if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO|SDL_INIT_TIMER) < 0 )
{
printf("Unable to init SDL: %s\n", SDL_GetError());
exit(1);
}
srand(static_cast<unsigned int>(time(0)));
atexit(SDL_Quit);
SDL_Surface *screen;
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT,32,SDL_HWSURFACE|SDL_DOUBLEBUF);
SDL_Rect backgroundRect;
backgroundRect.x = 0;
backgroundRect.y = 0;
backgroundRect.h = screen->h;
backgroundRect.w = screen->w;
Uint32 white = SDL_MapRGB(screen->format, 255, 255, 255);
Uint32 black = SDL_MapRGB(screen->format, 0, 0, 0);
Uint32 colors[DEAD];
colors[RED] = SDL_MapRGB(screen->format, 255, 0, 0);
colors[GREEN] = SDL_MapRGB(screen->format, 0, 255, 0);
colors[BLUE] = SDL_MapRGB(screen->format, 0, 0, 255);
colors[YELLOW] = SDL_MapRGB(screen->format, 0, 255, 255);
Board Board;
SDL_FillRect(screen, &backgroundRect, white);
if ( screen == NULL )
{
printf("Unable to set 640x480 video: %s\n", SDL_GetError());
exit(1);
}
int done = 0;
while(done == 0)
{
SDL_Event event;
while ( SDL_PollEvent(&event) )
{
if ( event.type == SDL_QUIT ) { done = 1; }
if ( event.type == SDL_KEYDOWN )
{
if ( event.key.keysym.sym == SDLK_ESCAPE ) { done = 1; }
}
}
Draw(screen, colors, &Board);
//SDL_FillRect(screen, &backgroundRect, white);
SDL_Flip(screen);
}
return 0;
}
|