It sounds like transforms could help you out here.
Basically, you have a 900x600 display (al_create_display(900, 600)
), but let your objects have positions anywhere in the 5000x5000 space.
When your player moves, you shift the camera transformation along with them. Your draw loop might look like this:
al_clear_to_color(al_map_rgb(0,0,0));
ALLEGRO_TRANSFORM trans;
al_identity_transform(&trans);
al_translate_transform(&trans, -player_x, -player_y);
al_use_transform(&trans);
// draw the player
al_draw_filled_circle(player_x + SCREEN_W / 2, player_y + SCREEN_H / 2,
32, al_map_rgb(255,0,0));
// draw all other entities
// ....
al_flip_display();
Note that the camera is shifted by -player_x,-player_y
. If the player is at
(1000, 1000), an object at (1500, 1500) should be drawn at
(1500-1000,1500-1000), or (500,500) relative to the player. An object at (500,
500) would be drawn at (500-1000,500-1000) or (-500,-500); it will be
off-screen.
We don't actually have to perform this subtracion for every object though. You just draw every object at its absolute position, and the transform will translate it to a position relative to the player (the player's 'local' space).
Note also that we add half the screen size so the player is centered.
There are a number of ways to approach this, but the above should give you a
good start. As a bonus, using transforms makes it easy to add things like zoom
and rotation.