Jump to content
  • Advertisement
Sign in to follow this  
KG_Brad

Problem Drawing Level

This topic is 4124 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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[t] == 1) draw_sprite(buffer,techdemo_tile[1],t*16,i*16);
				else if (techdemo_map0[t] == 2) draw_sprite(buffer,techdemo_tile[2],t*16,i*16);
				else if (techdemo_map0[t] == 3) draw_sprite(buffer,techdemo_tile[3],t*16,i*16);
				else if (techdemo_map0[t] == 4) draw_sprite(buffer,techdemo_tile[4],t*16,i*16);
				else if (techdemo_map0[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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!