I'm working in a rogue-like and I've manage to implement a camera on the player, the camera shows just the players surroundings and is fixed in the side of the windows.
The problem is, when the player is close to the sides of the map there's a black space in the surface. Like so:
How do I make the camera 'snap' to the side and don't go any further?
To draw the map
- I took the Camera Rect positions [topleft and bottomright];
- Converted it to World Position;
- Iterate over it, with a enumerator too;
- Did any lit/visited FOG calcunations with X and Y;
- And Blited in the screen using the enumerators 'i' and 'j'.
Here's the code:
topleft = Map.toWorld(camera.rect.topleft)
bottomright = Map.toWorld(camera.rect.bottomright)
for i, x in enumerate(xrange(topleft[0], bottomright[0])):
for j, y in enumerate(xrange(topleft[1], bottomright[1])):
tile = mymap.tileAt(x, y)
object = [obj for obj in Object.OBJECTS if obj.pos == (x,y)]
if tile:
lit = field_of_view.lit(x, y)
visited = field_of_view.visited(x, y)
graphic = tile.graphic
if lit:
color = tile.color
elif visited:
color = GRAY
else:
color = BLACK
renderedgraphic = myfont.render(ch, 1, graphic)
screen.blit(renderedgraphic, Map.toScreen((i + 1, j)))
if object:
Draw.drawObject(object[0], Map.toScreen((i + 1, j)))
I'm bashing my head in this problem for the whole day and that's the further I got.
I saw HERE a exemple of this but I couldn't adapt the code to my game because it uses sprites.