Tile based Array 2d game

This is the first time I have tried making a tile based array for a game and I'm getting a few errors I don't know how to fix. I also don't know if I did the clipping of my tile set bitmap. But if you could help me so I can move on with my game then it would be greatly appreciated.

These are the errors:

c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\waffle warrior2\waffle warrior2\main.cpp(5) : error C2143: syntax error : missing '}' before 'constant'
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\waffle warrior2\waffle warrior2\main.cpp(5) : error C2143: syntax error : missing ';' before 'constant'
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\waffle warrior2\waffle warrior2\main.cpp(5) : error C2059: syntax error : 'constant'
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\waffle warrior2\waffle warrior2\main.cpp(10) : error C2143: syntax error : missing ';' before '}'
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\waffle warrior2\waffle warrior2\main.cpp(10) : error C2059: syntax error : '}'

This is the code:
(
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
167
168
169
#include "DarkGDK.h"
#include "player.h"

int test[5*5]={
	0 1 3 5 6
	5 2 3 1 5
	2 3 2 5 6
	3 2 4 5 7
	1 2 3 4 5
};


void mapsetup(int map[], int width, int height);
void MenuControl();

//===== GAME CONTROLL ENUM =====
enum cGameState {Menu, Game_Setup, Game1P, Game_End, Exit};
cGameState Game_State = Menu;
	

void DarkGDK ( void )
{
	dbSetDisplayMode (1024,768,32);
	dbSyncOn   ( );
	dbSyncRate ( 60 );
	dbMaximizeWindow ();
	dbSetImageColorKey ( 255, 0, 255 );


	player player(50,220,15,.01,1);

	while ( LoopGDK ( ) )
	{
		switch (Game_State)
		{
		case Menu:
			MenuControl();
			break;
		case Game_Setup:
			dbCLS(dbRGB(0,0,0));
			mapsetup(test,5,5);
			Game_State = Game1P;
			break;
		case Game1P:
			player.setup();
			player.movement();
			player.gravity();
			break;
		case Game_End:
			break;
		case Exit:
			return;
			break;
		}
		
		if ( dbEscapeKey ( ) )
			break;
		dbSync ( );
	}

	for ( int i = 1; i < 30; i++ )
	{
	dbDeleteSprite ( i );
	dbDeleteImage ( i );
	}
	return;
}

void mapsetup(int map[], int width, int height)
{
	dbLoadImage("backgroundtiletest.bmp",11);

	int cell = 1;	
	for(int H = 0; H < height; H++)
		for(int W = 0; W < width; W++)
		{
			dbSprite ( cell, 32 * W, 32 * H, map[cell - 1]);
			// All the math is done here:
			int cellValue = map[cell - 1] - 1;
			int iX = cellValue % 3;
			int iY = cellValue / 3;
			float fOffset = 1.0f / 3.0f;
			float U = iX * fOffset;
			float V = iY * fOffset;

			// And here the math is used to clip the sprites:
			dbSetSpriteTextureCoord (cell, 0, U, V);
			dbSetSpriteTextureCoord (cell, 1, U + fOffset, V);
			dbSetSpriteTextureCoord (cell, 2, U + fOffset*2, V);		
			dbSetSpriteTextureCoord (cell, 3, U, V + fOffset);
			dbSetSpriteTextureCoord (cell, 4, U + fOffset, V + fOffset);
			dbSetSpriteTextureCoord (cell, 5, U + fOffset*2, V + fOffset);
			dbSetSpriteTextureCoord (cell, 6, U, V + fOffset*2);
			dbSetSpriteTextureCoord (cell, 7, U + fOffset, V + fOffset*2);
			dbSetSpriteTextureCoord (cell, 8, U + fOffset*2, V + fOffset*2);

			dbSizeSprite (cell, 32, 32);

			cell++;
		}
}

void MenuControl()
{	
	static int MENU_STATE = 2;
	static bool KeyPressed = false;

	dbCLS(dbRGB(0,0,0));
	
	//DRAWING TITLE
	dbSetTextFont("Pristina");
	dbSetTextToBold ();
	dbSetTextSize(100);
	dbInk(dbRGB(141,47,155),dbRGB(141,47,155));
	dbCenterText(512, 78, "Waffle Warrior!!!");
	dbSetTextSize(90);
	dbInk(dbRGB(243,248,71),dbRGB(243,248,71));
	dbCenterText(512, 75, "Waffle Warrior!!!");


	//DRAWING MENU BOXES
	dbInk(dbRGB(243, 248, 71),dbRGB(243, 248, 71));
	dbBox(362-5, 325-5, 662-5, 400-5);	// 200x150 px
	dbBox(362-5, 450-5, 662-5, 525-5);	// 200x150 px
	dbInk(dbRGB(255, 255, 255),dbRGB(255, 255, 255));
	dbBox(362, 325, 662, 400);	// 200x150 px
	dbBox(362, 450, 662, 525);	// 200x150 px
	
	//DRAWING CHOSEN MENU BOX
	switch(MENU_STATE)
	{
	case 2:
		dbInk(dbRGB(0, 0, 0),dbRGB(0, 0, 0));
		dbBox(362, 325, 662, 400);	// 200x150 px
	break;
	case 1:
		dbInk(dbRGB(0, 0, 0),dbRGB(0, 0, 0));
		dbBox(362, 450, 662, 525);	// 200x150 px
	break;
	}

	//INSERT TEXT ON MENU BOXES
	dbInk(dbRGB(255, 255, 255),dbRGB(255, 255, 255));
	dbSetTextSize(40);	
	dbCenterText(512, 350, "START GAME");
	dbCenterText(512, 475, "EXIT GAME");

	//CONTROLING MENU
	if( (dbKeyState(200))&&(KeyPressed == false) )
	{
		MENU_STATE += 1;
		KeyPressed = true;
	}
	if( (dbKeyState(208))&&(KeyPressed == false) )
	{
		MENU_STATE -= 1;
		KeyPressed = true;
	}
	if(MENU_STATE > 2) {MENU_STATE = 1;}
	if(MENU_STATE < 1) {MENU_STATE = 2;}
	if( (dbKeyState(200)==0)&&(dbKeyState(208)==0) ) {KeyPressed = false;}

	//CHOOSING...
	if(dbKeyState(28))
	{
		if(MENU_STATE == 2){Game_State = Game_Setup;}
		if(MENU_STATE == 1){Game_State = Exit;}
	}
}
)
Last edited on
When you initialize the array you need to separate the values by comma. And please use code tags ([ code ] [ /code ]) and indent it properly.
Last edited on
Duh, I feel stupid with the commas. But I don't really know what you mean by code tags. This is my first game :D, but I've made a little bit of practice programs. Not much though.
All I need now is a way to make each tile from my tile set to equal a number. I have the tile clipping process, but I have no idea how to make each of the tiles that I've clipped equal a number. If you would look at the code at the dbSetSpriteTextureCoord(int iID, int iVertex, float tu, float tv); and I wrote what each thing was for those of you who dn't know dark gdk. That and the equations above it are my tile clipping things. If you could figure out a way to make the tiles I have clipped equal a number for my array that would be greatly appreciated. Thank you in advance.
Also I did indent properly in my code, but when I copied it it didn't copy the indents for some reason.
Yeah, I know. When you post code put it inside code tags, like this:

[code]
#include <iostream>
using namespace std;

int main()
{

/*...*/

return 0;
}
[/code]

and it will show up like this:

1
2
3
4
5
6
7
8
9
10
#include <iostream>
using namespace std;

int main()
{

/*...*/

return 0;
}

You can also edit your posts. Try editing your original post and re-paste the properly indented code and use code tags. Using code tags preserves indentation.
Last edited on
Topic archived. No new replies allowed.