Re: Pygame and graphics?
The coordinates that go to the draw functions should not be (obj.x, obj.y), but rather, (obj.x-camera.x, obj.y-camera.y). Leaving this out is equivalent to leaving the camera at (0, 0).
A class for managing this sort of thing could handle this, so you don't have to type every single draw command that way, when you could just wrap the draw functions once.
Ex:
class Graphics2D :
camera_x, camera_y, scale_x, scale_y = (0, 0, 1.0, 1.0)
backcolor, forecolor = ((0, 0, 0), (255, 255, 255))
drawsurface = None
def __init__ (self, surf) :
self.drawsurface = surf
def reset (self) :
self.camera_x = 0
self.camera_y = 0
self.scale_x = 1.0
self.scale_y = 1.0
def translate (self, x, y) :
"""Position the camera"""
self.camera_x = x
self.camera_y = y
def scale (self, x, y) :
self.scale_x = x
self.scale_y = y
def set_color (self, newcolor) :
"""sets the color for all subsequent draw commands """
self.forecolor = newcolor # todo: make sure this is a 3tuple
def fill_rect (self, x, y, width, height) :
# (I don't remember off the top of my head if pygame.draw.rect takes numbers, or rect objects. I'll assume it's (x, y, w, h, color) for now.
x = (x * self.scale_x) - self.camera_x
y = (y * self.scale_y) - self.camera_y
#todo: negative scale values probably need special handling. You'll probably wind up wanting to flip something at some point.
pygame.draw.rect (self.surf, x, y, width * self.scale_x, height * self.scale_y, self.forecolor)
Etc. I'm pretty sure there are typos in there. It's meant to show the idea.
-- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector