SDL moving map

Pages: 12
My code is:

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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212

#include <iostream>
#include <string>
#include <cstdlib>
#include <windows.h>
#include <fstream>
#include "SDL.h"
#include <map>

using namespace std;

class TileProperties& GetTile(int a, int b);

bool gamestatus;
bool pokemon1yn = false;
bool pokemon2yn = false;
bool pokemon3yn = false;
bool pokemon4yn = false;
bool pokemon5yn = false;
bool pokemon6yn = false;
int x, y;
string PLAYERTOTAL_WIDTH2,PLAYERTOTAL_HEIGHT2, room3;
int PLAYERTOTAL_WIDTH, PLAYERTOTAL_HEIGHT, MAPTOTAL_HEIGHT, MAPTOTAL_WIDTH;


int main( int argc, char *argv[] ) {
    
	SDL_Init(SDL_INIT_EVERYTHING);
	
	Uint8 *key;
	Uint8 *player;
    const int SCREEN_WIDTH = 10;
    const int SCREEN_HEIGHT = 10;
    int PLAYER_WIDTH = 5;
    int PLAYER_HEIGHT = 5;
    const int MAPTOTAL_HEIGHT = 10;
    const int MAPTOTAL_WIDTH = 10;
    int room;
    
	SDL_Surface* image = FALSE;
    SDL_Surface* screen = FALSE;
	gamestatus = true;

	ifstream load("xlocation.txt", ios::ate);
	PLAYERTOTAL_WIDTH2 = "xlocation.txt", ios::ate;
	PLAYERTOTAL_WIDTH = atoi(PLAYERTOTAL_WIDTH2.c_str());
    load.close();

	ifstream file1("ylocation.txt", ios::ate);
	PLAYERTOTAL_HEIGHT2 = "ylocation.txt";
	PLAYERTOTAL_HEIGHT = atoi(PLAYERTOTAL_HEIGHT2.c_str());
	file1.close();

	ifstream roomd("room.txt", ios::ate);
	room3 = "room.txt", ios::ate;
	room = atoi(room3.c_str());
    roomd.close();
	
	SDL_WM_SetCaption("Pokemon", "Pokemon");
	screen = SDL_SetVideoMode( 640, 480, 32, SDL_HWSURFACE );
	
	while (gamestatus = true) {
          
        PLAYERTOTAL_HEIGHT = PLAYER_HEIGHT;
		PLAYERTOTAL_WIDTH = PLAYER_WIDTH;
        
        typdef struct TileProperties
{
    bool wallsolid;
    int  xwall;
    int  ywall;
}TileProperties;
TileProperties myTileset[2] = {
  { true,  0, 0 },
  { false, 10, 0 }
};
int room1[MAPTOTAL_WIDTH * MAPTOTAL_HEIGHT] = {
  1,1,1,1,0,0,1,1,1,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,1,1,1,1,1,1,1,1,1
};

int room2[MAPTOTAL_WIDTH * MAPTOTAL_HEIGHT] = {
  1,1,1,1,1,1,1,1,1,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,1,1,1,0,0,1,1,1,1
};

int b, a;
for(b = 0; b < MAPTOTAL_HEIGHT; b++)
{
    for(a = 0; a < MAPTOTAL_WIDTH; a++)
    {
        const TileProperties& t =GetTile(a, b);
        DrawImage( "walkablefloor.bmp" xwall, ywall );
    }
} 

        DrawImage("player.bmp" PLAYERTOTAL_HEIGHT,PLAYERTOTAL_WIDTH);

	key = SDL_GetKeyState( FALSE );
	
    if (key[SDLK_UP]) {
	    y++; 
if( GetTile(PLAYERTOTAL_HEIGHT, PLAYERTOTAL_WIDTH).wallsolid ){
    y--;
}}
	else if (key[SDLK_DOWN]) {
	    y--; 
        if( GetTile(PLAYERTOTAL_HEIGHT, PLAYERTOTAL_WIDTH).wallsolid ){
    y++;
}}
	else if (key[SDLK_LEFT]) {
	    x--; 
if( GetTile(PLAYERTOTAL_HEIGHT, PLAYERTOTAL_WIDTH).wallsolid ){
    x++;
}}
	else if (key[SDLK_RIGHT]) {
	    x++; 
if( GetTile(PLAYERTOTAL_HEIGHT, PLAYERTOTAL_WIDTH).wallsolid ){
    x--
}}
	else if (key[SDLK_z]) {
	}
	else if (key[SDLK_x]) {
		
	}
	else if (key[SDLK_LSHIFT]) {
		
	}
	
	else if (key[SDLK_s]) {
		ofstream file2( "ylocation.txt", ios::trunc | ios::out );
		ofstream file3( "xlocation.txt", ios::trunc | ios::out );
		ofstream file10( "room.txt", ios::trunc | ios::out );
        x = MAPTOTAL_WIDTH - PLAYERTOTAL_WIDTH;
        y = MAPTOTAL_HEIGHT - PLAYERTOTAL_HEIGHT;
        file3 << x;
        file2 << y;
        file10 << room;
		file2.close();
		file3.close();
		file10.close();
		
		if(pokemon1yn != FALSE){
		ofstream file4( "pokemon1.txt", ios::trunc | ios::out);
		
		file4.close();
	}
		if(pokemon2yn != FALSE) {
		ofstream file5( "pokemon2.txt", ios::trunc | ios::out);
		
		file5.close();
	}
		if(pokemon3yn != FALSE) {
		ofstream file6( "pokemon3.txt", ios::trunc | ios::out);
		
		file6.close();
	}
		if(pokemon4yn != FALSE) {
		ofstream file7( "pokemon4.txt", ios::trunc | ios::out);
		
		file7.close();
	}
		if(pokemon5yn != FALSE) {
		ofstream file8( "pokemon5.txt", ios::trunc | ios::out);
		
		file8.close();
	}
		if(pokemon6yn != FALSE) {
		ofstream file9("pokemon6.txt", ios::trunc | ios::out);
		
		file9.close();
	}
	
		gamestatus = false;
		
	}

		if (room == room1) {
        if (x == -1) {
              if (y == 5 or y == 6) {
                    room = room2;
                    x = 10;
                    }}}
	
}


	SDL_Quit();
	system("PAUSE");
	return 0;
}

class TileProperties& GetTile(int a, int b){
    return myTileset[ room[ (b*MAP_HEIGHT) + Px ] ];
}


Here are the errors:


75 `typdef' undeclared (first use this function)

(Each undeclared identifier is reported only once for each function it appears in.)

75 expected `;' before "struct"


84 elements of array `TileProperties myTileset[2]' have incomplete type

84 storage size of `myTileset' isn't known

117 expected `)' before "xwall"

117 `ywall' undeclared (first use this function)

117 `DrawImage' undeclared (first use this function)

121 expected `)' before "PLAYERTOTAL_HEIGHT"

127 invalid use of undefined type `struct TileProperties'

20 forward declaration of `struct TileProperties'

132 invalid use of undefined type `struct TileProperties'

20 forward declaration of `struct TileProperties'

137 invalid use of undefined type `struct TileProperties'

20 forward declaration of `struct TileProperties'

142 invalid use of undefined type `struct TileProperties'

20 forward declaration of `struct TileProperties'

144 expected `;' before '}' token

202 ISO C++ forbids comparison between pointer and integer

205? invalid conversion from `int*' to `int'

In function `TileProperties& GetTile(int, int)':

218 `myTileset' undeclared (first use this function)

218 `room' undeclared (first use this function)

218 `MAP_HEIGHT' undeclared (first use this function)

218 `Px' undeclared (first use this function)

[Build Error] ["Pokemon.o"] Error 1


What should i do?I think some things are in main that shouldn't be. :p
I made a typo. It should be typedef not typdef.
You need to define TileProperties before the prototype on line 12 instead of in int main.
You also have a lot of undeclared variables.
I noticed you may have forgot commas on line 109 and line 113

All these line numbers are the same as what you posted. They may not match up with you current file, since you have errors going to line 218 and your post does not have 218 lines
Last edited on
now my code is:


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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#include <iostream>
#include <string>
#include <cstdlib>
#include <windows.h>
#include <fstream>
#include "SDL.h"
#include <map>

using namespace std;

typedef struct TileProperties
{
    bool wallsolid;
    int  xwall;
    int  ywall;
}TileProperties;
TileProperties myTileset[2] = {
  { true,  0, 0 },
  { false, 10, 0 }
};

bool gamestatus;
bool pokemon1yn = false;
bool pokemon2yn = false;
bool pokemon3yn = false;
bool pokemon4yn = false;
bool pokemon5yn = false;
bool pokemon6yn = false;
int x, y;
string PLAYERTOTAL_WIDTH2,PLAYERTOTAL_HEIGHT2, room3;
int PLAYERTOTAL_WIDTH, PLAYERTOTAL_HEIGHT, MAPTOTAL_HEIGHT, MAPTOTAL_WIDTH;


int main( int argc, char *argv[] ) {
    
	SDL_Init(SDL_INIT_EVERYTHING);
	
	Uint8 *key;
	Uint8 *player;
    const int SCREEN_WIDTH = 10;
    const int SCREEN_HEIGHT = 11;
    int PLAYER_WIDTH = 5;
    int PLAYER_HEIGHT = 5;
    const int MAPTOTAL_HEIGHT = 11;
    const int MAPTOTAL_WIDTH = 10;
    int room;
    int xwall, ywall;
    
	SDL_Surface* image = FALSE;
    SDL_Surface* screen = FALSE;
	gamestatus = true;

	ifstream load("xlocation.txt", ios::ate);
	PLAYERTOTAL_WIDTH2 = "xlocation.txt", ios::ate;
	PLAYERTOTAL_WIDTH = atoi(PLAYERTOTAL_WIDTH2.c_str());
    load.close();

	ifstream file1("ylocation.txt", ios::ate);
	PLAYERTOTAL_HEIGHT2 = "ylocation.txt";
	PLAYERTOTAL_HEIGHT = atoi(PLAYERTOTAL_HEIGHT2.c_str());
	file1.close();

	
	SDL_WM_SetCaption("Pokemon", "Pokemon");
	screen = SDL_SetVideoMode( 640, 480, 32, SDL_HWSURFACE );
	
	while (gamestatus = true) {
          
        PLAYERTOTAL_HEIGHT = PLAYER_HEIGHT;
		PLAYERTOTAL_WIDTH = PLAYER_WIDTH;
        
int room1[MAPTOTAL_WIDTH * MAPTOTAL_HEIGHT] = {
  1,1,1,1,0,0,1,1,1,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,1,1,1,1,1,1,1,1,1
};

int room2[MAPTOTAL_WIDTH * MAPTOTAL_HEIGHT] = {
  1,1,1,1,1,1,1,1,1,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,1,1,1,0,0,1,1,1,1
};

int b, a;
for(b = 0; b < MAPTOTAL_HEIGHT; b++)
{
    for(a = 0; a < MAPTOTAL_WIDTH; a++)
    {
        const TileProperties& t =GetTile(a, b);
        DrawImage( "walkablefloor.bmp" xwall, ywall );
    }
} 

	ifstream roomd("room.txt", ios::ate);
	room3 = "room.txt", ios::ate;
	if (room3 == "room1")
	room = room1;
    roomd.close();
    
        DrawImage("player.bmp" PLAYERTOTAL_HEIGHT,PLAYERTOTAL_WIDTH);

	key = SDL_GetKeyState( FALSE );
	
    if (key[SDLK_UP]) {
	    y++; 
if( GetTile(PLAYERTOTAL_HEIGHT, PLAYERTOTAL_WIDTH).wallsolid ){
    y--;
}}
	else if (key[SDLK_DOWN]) {
	    y--; 
        if( GetTile(PLAYERTOTAL_HEIGHT, PLAYERTOTAL_WIDTH).wallsolid ){
    y++;
}}
	else if (key[SDLK_LEFT]) {
	    x--; 
if( GetTile(PLAYERTOTAL_HEIGHT, PLAYERTOTAL_WIDTH).wallsolid ){
    x++;
}}
	else if (key[SDLK_RIGHT]) {
	    x++; 
if( GetTile(PLAYERTOTAL_HEIGHT, PLAYERTOTAL_WIDTH).wallsolid ){
    x--;
}}
	else if (key[SDLK_z]) {
	}
	else if (key[SDLK_x]) {
		
	}
	else if (key[SDLK_LSHIFT]) {
		
	}
	
	else if (key[SDLK_s]) {
		ofstream file2( "ylocation.txt", ios::trunc | ios::out );
		ofstream file3( "xlocation.txt", ios::trunc | ios::out );
		ofstream file10( "room.txt", ios::trunc | ios::out );
        x = MAPTOTAL_WIDTH - PLAYERTOTAL_WIDTH;
        y = MAPTOTAL_HEIGHT - PLAYERTOTAL_HEIGHT;
        file3 << x;
        file2 << y;
        file10 << room;
		file2.close();
		file3.close();
		file10.close();
		
		if(pokemon1yn != FALSE){
		ofstream file4( "pokemon1.txt", ios::trunc | ios::out);
		
		file4.close();
	}
		if(pokemon2yn != FALSE) {
		ofstream file5( "pokemon2.txt", ios::trunc | ios::out);
		
		file5.close();
	}
		if(pokemon3yn != FALSE) {
		ofstream file6( "pokemon3.txt", ios::trunc | ios::out);
		
		file6.close();
	}
		if(pokemon4yn != FALSE) {
		ofstream file7( "pokemon4.txt", ios::trunc | ios::out);
		
		file7.close();
	}
		if(pokemon5yn != FALSE) {
		ofstream file8( "pokemon5.txt", ios::trunc | ios::out);
		
		file8.close();
	}
		if(pokemon6yn != FALSE) {
		ofstream file9("pokemon6.txt", ios::trunc | ios::out);
		
		file9.close();
	}
	
		gamestatus = false;
		
	}

		if (room3 == "room1") {
        if (x == -1) {
              if (y == 5 or y == 6) {
                    room = room2;
                    x = 10;
                    }}}
	
}


	SDL_Quit();
	system("PAUSE");
	return 0;
}

class TileProperties& GetTile(int a, int b){
    return myTileset[ room[ (b*MAPTOTAL_HEIGHT) + x ] ];
}


And my errors are:

In function `int SDL_main(int, char**)':

112 `GetTile' undeclared (first use this function)

(Each undeclared identifier is reported only once for each function it appears in.)

113 expected `)' before "xwall"

113 `DrawImage' undeclared (first use this function)

120 invalid conversion from `int*' to `int'

123 expected `)' before "PLAYERTOTAL_HEIGHT"

207 invalid conversion from `int*' to `int'

In function `TileProperties& GetTile(int, int)':

219 `TileProperties& GetTile(int, int)' used prior to declaration

220 `room' undeclared (first use this function)

[Build Error] ["Pokemon.o"] Error 1
How do you even use draw image?
DrawImage is something you still need to write it does not exist. Same with GetTile.
You still have several undeclared variables.
You still have commas missing on line 104 and line 114.
Please at least attempt at fixing what I pointed out earlier to get more help from me.
Like this?


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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#include <iostream>
#include <string>
#include <cstdlib>
#include <windows.h>
#include <fstream>
#include "SDL.h"
#include <map>

using namespace std;

typedef struct TileProperties
{
    bool wallsolid;
    int  xwall;
    int  ywall;
}TileProperties;
TileProperties myTileset[2] = {
  { true,  0, 0 },
  { false, 10, 0 }
};

bool gamestatus;
bool pokemon1yn = false;
bool pokemon2yn = false;
bool pokemon3yn = false;
bool pokemon4yn = false;
bool pokemon5yn = false;
bool pokemon6yn = false;
int x, y;
string PLAYERTOTAL_WIDTH2,PLAYERTOTAL_HEIGHT2, room3;
int PLAYERTOTAL_WIDTH, PLAYERTOTAL_HEIGHT, MAPTOTAL_HEIGHT, MAPTOTAL_WIDTH;


int main( int argc, char *argv[] ) {
    
	SDL_Init(SDL_INIT_EVERYTHING);
	
	Uint8 *key;
	Uint8 *player;
    const int SCREEN_WIDTH = 10;
    const int SCREEN_HEIGHT = 11;
    int PLAYER_WIDTH = 5;
    int PLAYER_HEIGHT = 5;
    const int MAPTOTAL_HEIGHT = 11;
    const int MAPTOTAL_WIDTH = 10;
    int room;
    int xwall, ywall;
    
	SDL_Surface* image = FALSE;
    SDL_Surface* screen = FALSE;
	gamestatus = true;

	ifstream load("xlocation.txt", ios::ate);
	PLAYERTOTAL_WIDTH2 = "xlocation.txt", ios::ate;
	PLAYERTOTAL_WIDTH = atoi(PLAYERTOTAL_WIDTH2.c_str());
    load.close();

	ifstream file1("ylocation.txt", ios::ate);
	PLAYERTOTAL_HEIGHT2 = "ylocation.txt";
	PLAYERTOTAL_HEIGHT = atoi(PLAYERTOTAL_HEIGHT2.c_str());
	file1.close();

	
	SDL_WM_SetCaption("Pokemon", "Pokemon");
	screen = SDL_SetVideoMode( 640, 480, 32, SDL_HWSURFACE );
	
	while (gamestatus = true) {
          
        PLAYERTOTAL_HEIGHT = PLAYER_HEIGHT;
		PLAYERTOTAL_WIDTH = PLAYER_WIDTH;
        
int room1[MAPTOTAL_WIDTH * MAPTOTAL_HEIGHT] = {
  1,1,1,1,0,0,1,1,1,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,1,1,1,1,1,1,1,1,1
};

int room2[MAPTOTAL_WIDTH * MAPTOTAL_HEIGHT] = {
  1,1,1,1,1,1,1,1,1,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,1,1,1,0,0,1,1,1,1
};

int b, a;
for(b = 0; b < MAPTOTAL_HEIGHT; b++)
{
    for(a = 0; a < MAPTOTAL_WIDTH; a++)
    {
        const TileProperties& t =GetTile(a, b);
        DrawImage( "walkablefloor.bmp", xwall, ywall );
    }
} 

	ifstream roomd("room.txt", ios::ate);
	room3 = "room.txt", ios::ate;
	if (room3 == "room1")
	room = room1;
    roomd.close();
    
        DrawImage("player.bmp", PLAYERTOTAL_HEIGHT,PLAYERTOTAL_WIDTH);

	key = SDL_GetKeyState( FALSE );
	
    if (key[SDLK_UP]) {
	    y++; 
if( GetTile(PLAYERTOTAL_HEIGHT, PLAYERTOTAL_WIDTH).wallsolid ){
    y--;
}}
	else if (key[SDLK_DOWN]) {
	    y--; 
        if( GetTile(PLAYERTOTAL_HEIGHT, PLAYERTOTAL_WIDTH).wallsolid ){
    y++;
}}
	else if (key[SDLK_LEFT]) {
	    x--; 
if( GetTile(PLAYERTOTAL_HEIGHT, PLAYERTOTAL_WIDTH).wallsolid ){
    x++;
}}
	else if (key[SDLK_RIGHT]) {
	    x++; 
if( GetTile(PLAYERTOTAL_HEIGHT, PLAYERTOTAL_WIDTH).wallsolid ){
    x--;
}}
	else if (key[SDLK_z]) {
	}
	else if (key[SDLK_x]) {
		
	}
	else if (key[SDLK_LSHIFT]) {
		
	}
	
	else if (key[SDLK_s]) {
		ofstream file2( "ylocation.txt", ios::trunc | ios::out );
		ofstream file3( "xlocation.txt", ios::trunc | ios::out );
		ofstream file10( "room.txt", ios::trunc | ios::out );
        x = MAPTOTAL_WIDTH - PLAYERTOTAL_WIDTH;
        y = MAPTOTAL_HEIGHT - PLAYERTOTAL_HEIGHT;
        file3 << x;
        file2 << y;
        file10 << room;
		file2.close();
		file3.close();
		file10.close();
		
		if(pokemon1yn != FALSE){
		ofstream file4( "pokemon1.txt", ios::trunc | ios::out);
		
		file4.close();
	}
		if(pokemon2yn != FALSE) {
		ofstream file5( "pokemon2.txt", ios::trunc | ios::out);
		
		file5.close();
	}
		if(pokemon3yn != FALSE) {
		ofstream file6( "pokemon3.txt", ios::trunc | ios::out);
		
		file6.close();
	}
		if(pokemon4yn != FALSE) {
		ofstream file7( "pokemon4.txt", ios::trunc | ios::out);
		
		file7.close();
	}
		if(pokemon5yn != FALSE) {
		ofstream file8( "pokemon5.txt", ios::trunc | ios::out);
		
		file8.close();
	}
		if(pokemon6yn != FALSE) {
		ofstream file9("pokemon6.txt", ios::trunc | ios::out);
		
		file9.close();
	}
	
		gamestatus = false;
		
	}

		if (room3 == "room1") {
        if (x == -1) {
              if (y == 5 or y == 6) {
                    room = room2;
                    x = 10;
                    }}}
	
}


	SDL_Quit();
	system("PAUSE");
	return 0;
}

class TileProperties& GetTile(int a, int b){
    return myTileset[ room[ (b*MAPTOTAL_HEIGHT) + x ] ];
} 


Guess so.

now I have:

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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236


#include <iostream>
#include <string>
#include <cstdlib>
#include <windows.h>
#include <fstream>
#include "SDL.h"
#include <map>

using namespace std;

typedef struct TileProperties
{
    bool wallsolid;
    int  xwall;
    int  ywall;
}TileProperties;
TileProperties myTileset[2] = {
  { true,  0, 0 },
  { false, 10, 0 }
};

bool gamestatus;
bool pokemon1yn = false;
bool pokemon2yn = false;
bool pokemon3yn = false;
bool pokemon4yn = false;
bool pokemon5yn = false;
bool pokemon6yn = false;
int x, y;
string PLAYERTOTAL_WIDTH2,PLAYERTOTAL_HEIGHT2, room3;

int PLAYERTOTAL_WIDTH, PLAYERTOTAL_HEIGHT, MAPTOTAL_HEIGHT, MAPTOTAL_WIDTH;

void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination ){
    SDL_Rect offset;
    offset.x = x;
    offset.y = y;
SDL_BlitSurface( source, NULL, destination, &offset );
}
    
int main( int argc, char *argv[] ) {
    
	SDL_Init(SDL_INIT_EVERYTHING);
	
	Uint8 *key;
	Uint8 *player;
    const int SCREEN_WIDTH = 10;
    const int SCREEN_HEIGHT = 11;
    int PLAYER_WIDTH = 5;
    int PLAYER_HEIGHT = 5;
    const int MAPTOTAL_HEIGHT = 11;
    const int MAPTOTAL_WIDTH = 10;
    int room;
    int xwall, ywall;
    
	SDL_Surface* image = FALSE;
	SDL_Surface* image2 = FALSE;
    SDL_Surface* screen = FALSE;
    
	gamestatus = true;

	ifstream load("xlocation.txt", ios::ate);
	PLAYERTOTAL_WIDTH2 = "xlocation.txt", ios::ate;
	PLAYERTOTAL_WIDTH = atoi(PLAYERTOTAL_WIDTH2.c_str());
    load.close();

	ifstream file1("ylocation.txt", ios::ate);
	PLAYERTOTAL_HEIGHT2 = "ylocation.txt";
	PLAYERTOTAL_HEIGHT = atoi(PLAYERTOTAL_HEIGHT2.c_str());
	file1.close();

	
	SDL_WM_SetCaption("R's Pokemon", "R's Pokemon");
	screen = SDL_SetVideoMode( 640, 480, 32, SDL_HWSURFACE );
	
	while (gamestatus = true) {
          
        PLAYERTOTAL_HEIGHT = PLAYER_HEIGHT;
		PLAYERTOTAL_WIDTH = PLAYER_WIDTH;
        
int room1[MAPTOTAL_WIDTH * MAPTOTAL_HEIGHT] = {
  1,1,1,1,0,0,1,1,1,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,1,1,1,1,1,1,1,1,1
};

int room2[MAPTOTAL_WIDTH * MAPTOTAL_HEIGHT] = {
  1,1,1,1,1,1,1,1,1,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,1,1,1,0,0,1,1,1,1
};

int b, a;
for(b = 0; b < MAPTOTAL_HEIGHT; b++)
{
    for(a = 0; a < MAPTOTAL_WIDTH; a++)
    {
        const TileProperties& t =GetTile(a, b);
        SDL_Surface* loadedImage = FALSE;
    SDL_Surface* optimizedImage = FALSE;
    loadedImage = SDL_LoadBMP( "walkablefloor".c_str() );
    if( loadedImage != NULL ) {
        optimizedImage = SDL_DisplayFormat( loadedImage );
        SDL_FreeSurface( loadedImage );
        apply_surface( xwall, ywall, image, screen );
    }
} 
}

	ifstream roomd("room.txt", ios::ate);
	room3 = "room.txt", ios::ate;
	if (room3 == "room1")
	room = room1;
    roomd.close();
    
        SDL_Surface* loadedImage = FALSE;
    SDL_Surface* optimizedImage = FALSE;
    loadedImage = SDL_LoadBMP( "player.bmp".c_str() );
    if( loadedImage != NULL ) {
        optimizedImage = SDL_DisplayFormat( loadedImage );
        SDL_FreeSurface( loadedImage );
        apply_surface( PLAYERTOTAL_HEIGHT, PLAYERTOTAL_WIDTH, image2, screen );
}
	key = SDL_GetKeyState( FALSE );
	
    if (key[SDLK_UP]) {
	    y++; 
if( GetTile(PLAYERTOTAL_HEIGHT, PLAYERTOTAL_WIDTH).wallsolid ){
    y--;
}}
	else if (key[SDLK_DOWN]) {
	    y--; 
        if( GetTile(PLAYERTOTAL_HEIGHT, PLAYERTOTAL_WIDTH).wallsolid ){
    y++;
}}
	else if (key[SDLK_LEFT]) {
	    x--; 
if( GetTile(PLAYERTOTAL_HEIGHT, PLAYERTOTAL_WIDTH).wallsolid ){
    x++;
}}
	else if (key[SDLK_RIGHT]) {
	    x++; 
if( GetTile(PLAYERTOTAL_HEIGHT, PLAYERTOTAL_WIDTH).wallsolid ){
    x--;
}}
	else if (key[SDLK_z]) {
	}
	else if (key[SDLK_x]) {
		
	}
	else if (key[SDLK_LSHIFT]) {
		
	}
	
	else if (key[SDLK_s]) {
		ofstream file2( "ylocation.txt", ios::trunc | ios::out );
		ofstream file3( "xlocation.txt", ios::trunc | ios::out );
		ofstream file10( "room.txt", ios::trunc | ios::out );
        x = MAPTOTAL_WIDTH - PLAYERTOTAL_WIDTH;
        y = MAPTOTAL_HEIGHT - PLAYERTOTAL_HEIGHT;
        file3 << x;
        file2 << y;
        file10 << room;
		file2.close();
		file3.close();
		file10.close();
		
		if(pokemon1yn != FALSE){
		ofstream file4( "pokemon1.txt", ios::trunc | ios::out);
		
		file4.close();
	}
		if(pokemon2yn != FALSE) {
		ofstream file5( "pokemon2.txt", ios::trunc | ios::out);
		
		file5.close();
	}
		if(pokemon3yn != FALSE) {
		ofstream file6( "pokemon3.txt", ios::trunc | ios::out);
		
		file6.close();
	}
		if(pokemon4yn != FALSE) {
		ofstream file7( "pokemon4.txt", ios::trunc | ios::out);
		
		file7.close();
	}
		if(pokemon5yn != FALSE) {
		ofstream file8( "pokemon5.txt", ios::trunc | ios::out);
		
		file8.close();
	}
		if(pokemon6yn != FALSE) {
		ofstream file9("pokemon6.txt", ios::trunc | ios::out);
		
		file9.close();
	}
	
		gamestatus = false;
		
	}

		if (room3 == "room1") {
        if (x == -1) {
              if (y == 5 or y == 6) {
                    room = room2;
                    x = 10;
                    }}}
	
}


	SDL_Quit();
	system("PAUSE");
	return 0;
}

class TileProperties& GetTile(int a, int b){
    return myTileset[ room[ (b*MAPTOTAL_HEIGHT) + x ] ];
}


My errors are:

In function `int SDL_main(int, char**)':

121 `GetTile' undeclared (first use this function)

(Each undeclared identifier is reported only once for each function it appears in.)

124 request for member `c_str' in `"walkablefloor"', which is of non-class type `const char[14]'

136 invalid conversion from `int*' to `int'

141 request for member `c_str' in `"player.bmp"', which is of non-class type `const char[11]'

229 invalid conversion from `int*' to `int'

In function `TileProperties& GetTile(int, int)':

241 `TileProperties& GetTile(int, int)' used prior to declaration

242 `room' undeclared (first use this function)

Makefile.win [Build Error] ["R Pokemon.o"] Error 1
now I have:

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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#include <iostream>
#include <string>
#include <cstdlib>
#include <windows.h>
#include <fstream>
#include "SDL.h"
#include <map>

using namespace std;


int b, a, roomnum;

class TileProperties& GetTile(int a, int b);
int firstroom();
void secondroom();

typedef struct TileProperties
{
    bool wallsolid;
    int  xwall;
    int  ywall;
}TileProperties;
TileProperties myTileset[2] = {
  { true,  0, 0 },
  { false, 10, 0 }
};

bool gamestatus;
bool pokemon1yn = false;
bool pokemon2yn = false;
bool pokemon3yn = false;
bool pokemon4yn = false;
bool pokemon5yn = false;
bool pokemon6yn = false;
int x, y;
    const int SCREEN_WIDTH = 10;
    const int SCREEN_HEIGHT = 11;
    int PLAYER_WIDTH = 5;
    int PLAYER_HEIGHT = 5;
    const int MAPTOTAL_HEIGHT = 11;
    const int MAPTOTAL_WIDTH = 10;
    
	SDL_Surface* image = FALSE;
	SDL_Surface* image2 = FALSE;
    SDL_Surface* screen = FALSE;
    int room;
    int xwall, ywall;
string PLAYERTOTAL_WIDTH2,PLAYERTOTAL_HEIGHT2, room3;

int PLAYERTOTAL_WIDTH, PLAYERTOTAL_HEIGHT;

void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination ){
    SDL_Rect offset;
    offset.x = x;
    offset.y = y;
SDL_BlitSurface( source, NULL, destination, &offset );
}
    
int main( int argc, char *argv[] ) {
    
	SDL_Init(SDL_INIT_EVERYTHING);
	
	Uint8 *key;
	Uint8 *player;
    
	gamestatus = true;

	ifstream load("xlocation.txt", ios::ate);
	PLAYERTOTAL_WIDTH2 = "xlocation.txt", ios::ate;
	PLAYERTOTAL_WIDTH = atoi(PLAYERTOTAL_WIDTH2.c_str());
    load.close();

	ifstream file1("ylocation.txt", ios::ate);
	PLAYERTOTAL_HEIGHT2 = "ylocation.txt";
	PLAYERTOTAL_HEIGHT = atoi(PLAYERTOTAL_HEIGHT2.c_str());
	file1.close();

	
	SDL_WM_SetCaption("R's Pokemon", "R's Pokemon");
	screen = SDL_SetVideoMode( 640, 480, 32, SDL_HWSURFACE );
	
	while (gamestatus = true) {
          
        PLAYERTOTAL_HEIGHT = PLAYER_HEIGHT;
		PLAYERTOTAL_WIDTH = PLAYER_WIDTH;



	ifstream roomd("room.txt", ios::ate);
	room3 = "room.txt", ios::ate;
	if (room3 == "room1")
	firstroom();
    roomd.close();
    
        SDL_Surface* loadedImage = FALSE;
    SDL_Surface* optimizedImage = FALSE;
    loadedImage = SDL_LoadBMP( string("player.bmp").c_str() );
    if( loadedImage != NULL ) {
        optimizedImage = SDL_DisplayFormat( loadedImage );
        SDL_FreeSurface( loadedImage );
        apply_surface( PLAYERTOTAL_HEIGHT, PLAYERTOTAL_WIDTH, image2, screen );
}
	key = SDL_GetKeyState( FALSE );
	
    if (key[SDLK_UP]) {
	    y++; 
if( GetTile(PLAYERTOTAL_HEIGHT, PLAYERTOTAL_WIDTH).wallsolid ){
    y--;
}}
	else if (key[SDLK_DOWN]) {
	    y--; 
        if( GetTile(PLAYERTOTAL_HEIGHT, PLAYERTOTAL_WIDTH).wallsolid ){
    y++;
}}
	else if (key[SDLK_LEFT]) {
	    x--; 
if( GetTile(PLAYERTOTAL_HEIGHT, PLAYERTOTAL_WIDTH).wallsolid ){
    x++;
}}
	else if (key[SDLK_RIGHT]) {
	    x++; 
if( GetTile(PLAYERTOTAL_HEIGHT, PLAYERTOTAL_WIDTH).wallsolid ){
    x--;
}}
	else if (key[SDLK_z]) {
	}
	else if (key[SDLK_x]) {
		
	}
	else if (key[SDLK_LSHIFT]) {
		
	}
	
	else if (key[SDLK_s]) {
		ofstream file2( "ylocation.txt", ios::trunc | ios::out );
		ofstream file3( "xlocation.txt", ios::trunc | ios::out );
		ofstream file10( "room.txt", ios::trunc | ios::out );
        x = MAPTOTAL_WIDTH - PLAYERTOTAL_WIDTH;
        y = MAPTOTAL_HEIGHT - PLAYERTOTAL_HEIGHT;
        file3 << x;
        file2 << y;
        file10 << room;
		file2.close();
		file3.close();
		file10.close();
		
		if(pokemon1yn != FALSE){
		ofstream file4( "pokemon1.txt", ios::trunc | ios::out);
		
		file4.close();
	}
		if(pokemon2yn != FALSE) {
		ofstream file5( "pokemon2.txt", ios::trunc | ios::out);
		
		file5.close();
	}
		if(pokemon3yn != FALSE) {
		ofstream file6( "pokemon3.txt", ios::trunc | ios::out);
		
		file6.close();
	}
		if(pokemon4yn != FALSE) {
		ofstream file7( "pokemon4.txt", ios::trunc | ios::out);
		
		file7.close();
	}
		if(pokemon5yn != FALSE) {
		ofstream file8( "pokemon5.txt", ios::trunc | ios::out);
		
		file8.close();
	}
		if(pokemon6yn != FALSE) {
		ofstream file9("pokemon6.txt", ios::trunc | ios::out);
		
		file9.close();
	}
	
		gamestatus = false;
		
	}

		if (room3 == "room1") {
        if (x == 11) {
              if (y == 5 or y == 6) {
                    secondroom();
                    x = 10;
                    }}}
	
}


	SDL_Quit();
	system("PAUSE");
	return 0;
}

class TileProperties& GetTile(int a, int b, int roomnum){
    if (roomnum == 1) {
    return myTileset[ firstroom()[ (b*MAPTOTAL_HEIGHT) + x ] ]; }
}


int firstroom() { 
int room1[MAPTOTAL_WIDTH * MAPTOTAL_HEIGHT] = {
  1,1,1,1,0,0,1,1,1,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,1,1,1,1,1,1,1,1,1
  };
  roomnum=1;
for(b = 0; b < MAPTOTAL_HEIGHT; b++)
{
    for(a = 0; a < MAPTOTAL_WIDTH; a++)
    {
        const TileProperties& t =GetTile(a, b);
        SDL_Surface* loadedImage = FALSE;
    SDL_Surface* optimizedImage = FALSE;
    loadedImage = SDL_LoadBMP( string("walkablefloor").c_str() );
    if( loadedImage != NULL ) {
        optimizedImage = SDL_DisplayFormat( loadedImage );
        SDL_FreeSurface( loadedImage );
        apply_surface( xwall, ywall, image, screen );
    }
} 
}
return 0; }


void secondroom(){
int room2[MAPTOTAL_WIDTH * MAPTOTAL_HEIGHT] = {
  1,1,1,1,1,1,1,1,1,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,0,0,0,0,0,0,0,0,1,
  1,1,1,1,0,0,1,1,1,1
};
for(b = 0; b < MAPTOTAL_HEIGHT; b++)
{
    for(a = 0; a < MAPTOTAL_WIDTH; a++)
    {
        const TileProperties& t =GetTile(a, b);
        SDL_Surface* loadedImage = FALSE;
    SDL_Surface* optimizedImage = FALSE;
    loadedImage = SDL_LoadBMP( string("walkablefloor").c_str() );
    if( loadedImage != NULL ) {
        optimizedImage = SDL_DisplayFormat( loadedImage );
        SDL_FreeSurface( loadedImage );
        apply_surface( xwall, ywall, image, screen );
    }
} 
}
return; }



With the error:

invalid types `int[int]' for array subscript

for the code

return myTileset[ firstroom()[ (b*MAPTOTAL_HEIGHT) + x ] ]; }
Well?
Well?


Deep subject.

One of the indispensable skills of a programmer is the ability to read error messages when compiling code. This one tells you exactly what's wrong with your code. Read it, comprehend it and change your code.

First, we look for an array subscript. There are two of them in the line in question. The first is:
firstroom()[(b*MAPTOTAL_HEIGHT) + x]
and the second is:
(b*MAPTOTAL_HEIGHT)+x

Start with the second, since it's shorter. It's type is int. Let's rewrite the code with the type substituted for the expression:
return myTileset[firstroom()[int]];

which means the first subscript we listed above, if we substitute type for expression again, would be:
firstroom()[int]

Now, what does firstroom() return? Is it an int? So, substituting the type of the expression for the actual expression makes that:
int[int]

or return myTileSet[ int[int] ];

Look familiar? When do you think it's appropriate to index an int? An int isn't an array is it? I hope you see where this is going.
Topic archived. No new replies allowed.
Pages: 12