def main():
global FPSCLOCK
FPSCLOCK = pygame.time.Clock()
cam = Camera(WORLDWIDTH/4,WORLDHEIGHT/4)
world_in_cam_surf = WORLDSURF .subsurface((cam.x,cam.y,WINDOWWIDTH,WINDOWHEIGHT))
CAMERASURF.blit(world_in_cam_surf,(0,0))
print cam.x,cam.y
sq = Sq(WINDOWWIDTH/2,WINDOWHEIGHT/2,cam)
cam.follow(sq)
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
elif event.type == KEYDOWN:
if event.key in (K_LEFT, K_a) :
print "left pressed"
cam.update(LEFT)
elif event.key in (K_RIGHT, K_d) :
print "right pressed"
cam.update(RIGHT)
elif event.key in (K_UP, K_w) :
cam.update(UP)
print "up pressed"
elif event.key in (K_DOWN, K_w) :
cam.update(DOWN)
print "down pressed"
world_in_cam_surf = WORLDSURF .subsurface((cam.x,cam.y,WINDOWWIDTH,WINDOWHEIGHT))
CAMERASURF.blit(world_in_cam_surf,(0,0))
CAMERASURF.blit(sq.surf,(sq.x,sq.y))
pygame.display.update()
FPSCLOCK.tick(FPS)
if __name__ == "__main__":
main()
global FPSCLOCK
FPSCLOCK = pygame.time.Clock()
cam = Camera(WORLDWIDTH/4,WORLDHEIGHT/4)
world_in_cam_surf = WORLDSURF .subsurface((cam.x,cam.y,WINDOWWIDTH,WINDOWHEIGHT))
CAMERASURF.blit(world_in_cam_surf,(0,0))
print cam.x,cam.y
sq = Sq(WINDOWWIDTH/2,WINDOWHEIGHT/2,cam)
cam.follow(sq)
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
elif event.type == KEYDOWN:
if event.key in (K_LEFT, K_a) :
print "left pressed"
cam.update(LEFT)
elif event.key in (K_RIGHT, K_d) :
print "right pressed"
cam.update(RIGHT)
elif event.key in (K_UP, K_w) :
cam.update(UP)
print "up pressed"
elif event.key in (K_DOWN, K_w) :
cam.update(DOWN)
print "down pressed"
world_in_cam_surf = WORLDSURF .subsurface((cam.x,cam.y,WINDOWWIDTH,WINDOWHEIGHT))
CAMERASURF.blit(world_in_cam_surf,(0,0))
CAMERASURF.blit(sq.surf,(sq.x,sq.y))
pygame.display.update()
FPSCLOCK.tick(FPS)
if __name__ == "__main__":
main()