SDL and map issues

closed account (NUj6URfi)
How can I fix this 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
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
265

#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();
int 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("Pokemon", "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(myTileset[ firstroom()[ (b*MAPTOTAL_HEIGHT) + x ] ]) { 
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.bmp").c_str() );
    if( loadedImage != NULL ) {
        optimizedImage = SDL_DisplayFormat( loadedImage );
        SDL_FreeSurface( loadedImage );
        apply_surface( xwall, ywall, image, screen );
    }
} 
}
return myTileset[2]; }


int 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 0; }


I get the errors:

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

201 invalid types `int[int]' for array subscript

201At global scope:

205 `int firstroom' redeclared as different kind of symbol

16 previous declaration of `int firstroom()'

205 declaration of `int firstroom'

16 conflicts with previous declaration `int firstroom()'

205 invalid types `int[int]' for array subscript

205 expected `,' or `;' before '{' token
Last edited on
closed account (NUj6URfi)
Bump.
Line 201: firstroom() returns a integer, yet you are trying to index into it with [].

Line 205: Erm, what is this supposed to be? Some kind of function declaration...?
closed account (NUj6URfi)
Line 205 is a function. How do I fix 201?
closed account (Dy7SLyTq)
the parameter for it is really really wrong
closed account (NUj6URfi)
And????
closed account (Dy7SLyTq)
fix it. you are honestly telling me you cant figure out what is wrong with the functions parameter?
closed account (N36fSL3A)
Why the hell are you using a multidimensional array for maps?

I think I already explained how difficult that is to manage. I have some code from an old RPG you can look at. It's made in SDL.
closed account (Dy7SLyTq)
Why the hell are you using a multidimensional array for maps?


what are you talking about? hes only using vector arrays
closed account (N36fSL3A)
http://prntscr.com/1q7ad8
closed account (Dy7SLyTq)
thats not a multidemensional array. thats a vector array

edit: can i call it a vector array, because doesnt it represent a mathematical vector?
Last edited on
closed account (NUj6URfi)
Sure. I know how to pass and return variables just not arrays. Also my book didn't say anything. It's not just an array but

 
myTileset[ firstroom()[ (b*MAPTOTAL_HEIGHT) + x ] ]
closed account (NUj6URfi)
Sure. I know how to pass and return variables just not arrays. Also my book didn't say anything. It's not just an array but

 
myTileset[ firstroom()[ (b*MAPTOTAL_HEIGHT) + x ] ]
closed account (N36fSL3A)
Well, since it's a pokemon game, I'm guessing you don't need layers. My map files for an old project will be pmed to you.
closed account (NUj6URfi)
I need a zip
closed account (N36fSL3A)
Why don't you download winwar
closed account (Dy7SLyTq)
*winrar and i wouldnt get that. i dont really like it. i would personally use 7zip, but if your on linux, there is a builtin unpackager. just fire up the terminal navigate to the directory where the file is and just tar file_name
closed account (NUj6URfi)
I don't want to download a rar thing.
closed account (N36fSL3A)
Why not?

You'll need winwar to download many files. It's pretty lightweight.
Topic archived. No new replies allowed.