Archived

This topic is now archived and is closed to further replies.

ZadrraS

Tile drawing, why doesn't it work?

Recommended Posts

Heres the function to draw something:
void Draw(SDL_Surface *img, int x, int y) {
	SDL_Rect dest;
	dest.x;
	dest.y;
	SDL_BlitSurface(img, NULL, screen, &dest);
}
And this function draws the whole map:
void DrawMap() {
	for (int y=0; y<20; y++) {
		for (int x=0; x<10; x++) {
			if (map[y][x]==OPEN) {
				Draw(empty, x*40, y*40);				
			}
			else if (map[y][x]==TILE) {
				Draw(tile, x*40, y*40);
			}
		}
	}
}	
But it doesn''t work. i only get a black screen. Why? Heres the other stuff: #define OPEN 0 #define TILE 1 int map[20][10]= { {OPEN, OPEN, OPEN, OPEN, TILE, OPEN, OPEN, OPEN, OPEN, OPEN}, {OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN}, {OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN}, {OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN}, {OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN}, {OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN}, {OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN}, {OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN}, {OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN}, {OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN}, {OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN}, {OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN}, {OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN}, {OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN}, {OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN}, {OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN}, {OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN}, {OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN}, {OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN}, {OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN, OPEN}, };

Share this post


Link to post
Share on other sites
No it doesn''t... and, im sorry, i was a little stupid to post without looking for a way out for myself, i found the problem:
This:

void Draw(SDL_Surface *img, int x, int y) {
SDL_Rect dest;
dest.x;
dest.y;
SDL_BlitSurface(img, NULL, screen, &dest);
}

should be like this :

void Draw(SDL_Surface *img, int x, int y) {
SDL_Rect dest;
dest.x=x;
dest.y=y;
SDL_BlitSurface(img, NULL, screen, &dest);
}

Share this post


Link to post
Share on other sites
I have another question then, i need the tile to move 1 empty tile down every 2 secs, i never used time counting. How do i do it?

Share this post


Link to post
Share on other sites
And another q. is this a good way to move a brick and clean up after it?


void SetMapValues() {
for (int y=0; y<20; y++) {
for (int x=0; x<10; x++) {
if (x==xpos && y==ypos) {
map[y][x]=TILE;
if (map[y-1][x]==TILE) {
map[y-1][x]=OPEN;
}
else if (map[y][x-1]==TILE) {
map[y][x-1]=OPEN;
}
else if (map[y][x+1]==TILE) {
map[y][x+1]=OPEN;
}
else {
}

}
else {

}
}
}

}

Share this post


Link to post
Share on other sites
quote:
Original post by ZadrraS
I have another question then, i need the tile to move 1 empty tile down every 2 secs, i never used time counting. How do i do it?


i dont understand what your trying to do, but you want to use SDL_GetTicks(). SDL_GetTicks() returns how many milliseconds since SDL has been initialized (basically how long the program has been running). to time something, do this:


///very begining of the program, OUTSIDE of ANY loops

int time_start = SDL_GetTicks();

//now start your game loop


while(!gameover)
{

int time_now = SDL_GetTicks();

int time_passed = (time_now - time_start) / 1000;

time_passed now holds how many seconds have passed since your game started. all you have to do is

if(time_passed % 2 == 0)
{
2 seconds have passed since the last game loop
}


return 0;

}


also, about your question on moving a brick. you have to be more descriptive on what your trying to accomplish. hope i helped

[edited by - graveyard filla on April 3, 2004 5:02:12 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by ZadrraS
And another q. is this a good way to move a brick and clean up after it?


void SetMapValues() {
for (int y=0; y<20; y++) {
for (int x=0; x<10; x++) {
if (x==xpos && y==ypos) {
map[y][x]=TILE;
if (map[y-1][x]==TILE) {
map[y-1][x]=OPEN;
}
else if (map[y][x-1]==TILE) {
map[y][x-1]=OPEN;
}
else if (map[y][x+1]==TILE) {
map[y][x+1]=OPEN;
}
else {
}

}
else {

}
}
}

}




No. It''s messy, and will sometimes mess up if you have two adjacent blocks and one of them moves. Also, you''re looping through every square in your grid, but only doing anything when the xpos and ypos values match up, so the for loops are wasted.

Share this post


Link to post
Share on other sites