Sign in to follow this  
KG_Brad

Problem Drawing Level

Recommended Posts

Hey, I've been having problems getting levels in my game drawn on the screen. They're stored in a 2D array. Here's my code for my "run_map" function:
void run_map(int map)
{
	clear(buffer);
	
	if (map == 0)
	{
		for (i=0;i<38;++i)
		{
			for (t=0;t<60;++t)
			{
				if (techdemo_map0[i][t] == 1) draw_sprite(buffer,techdemo_tile[1],t*16,i*16);
				else if (techdemo_map0[i][t] == 2) draw_sprite(buffer,techdemo_tile[2],t*16,i*16);
				else if (techdemo_map0[i][t] == 3) draw_sprite(buffer,techdemo_tile[3],t*16,i*16);
				else if (techdemo_map0[i][t] == 4) draw_sprite(buffer,techdemo_tile[4],t*16,i*16);
				else if (techdemo_map0[i][t] == 5) draw_sprite(buffer,techdemo_tile[5],t*16,i*16);
				
				move_player();
			}
		}
	}
}
"move_player" function:
void move_player()
{	
	//Check for keyboard input
	while (!key[KEY_ESC])
	{
		playerDef.oX = playerDef.x;
		playerDef.oY = playerDef.y;
		
		if (key[KEY_LEFT])
  		{
    			--playerDef.x;
    			facing == 0;
		}
		else if (key[KEY_RIGHT]) 
  		{
    			++playerDef.x;
    			facing == 1;
		}
		else if (key[KEY_ESC])
		{
			sleep();
			exit_message();
		}
		
		//Draw player at new position
		draw_player();
	}
}
And, finally, the "draw_player" function:
void draw_player()
{		
	if (key[KEY_LEFT])
	{
		draw_sprite_h_flip(buffer,player[1],playerDef.x,playerDef.y);
		draw_sprite(screen,buffer,0,0);
	}
	if (key[KEY_RIGHT])
	{
		draw_sprite(buffer,player[1],playerDef.x,playerDef.y);
		draw_sprite(screen,buffer,0,0);
	}
}
So why can't I get the tiles to draw on the screen? I'm drawing the tiles on a double-buffer, but then that's being drawn on the screen in my "draw_player" function. I've tried everything I could think of and nothing seems to work!

Share this post


Link to post
Share on other sites
Are you sure that the draw_sprite() function works? Are it's arguments/variables valid? (e.g., is buffer initialized?). What about the run_map() function - are you passing it zero? (the function only draws something if map == 0)

These are just quick thoughts, but maybe they will help. Also, are you posting the complete code to run_map()? I ask because the loop indices are not declared properly (there's no int before i and t) so this shouldn't compile.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this