def map2screen(self, x, y, z): "Convert from map position to screen coordinates" cx, cy = self.get_screen_center() rx, ry = rotate_xypos(x, y, self.level.xsize-1, self.level.ysize-1, (self.rotation)%4) posx, posy = rotate_xypos(self.position.x, self.position.y, self.level.xsize-1, self.level.ysize-1, (-self.rotation)%4) posz = self.position.z return (cx+self.graphics.block_width//2*(posx-posy-x+y), cy+self.graphics.block_depth//2*(-posx-posy+x+y)-self.graphics.block_height*(z-posz))
def map2screen(self, x, y, z): "Convert from map position to screen coordinates" cx, cy = self.get_screen_center() rx, ry = rotate_xypos(x, y, self.level.xsize - 1, self.level.ysize - 1, (self.rotation) % 4) posx, posy = rotate_xypos(self.position.x, self.position.y, self.level.xsize - 1, self.level.ysize - 1, (-self.rotation) % 4) posz = self.position.z return (cx + self.graphics.block_width // 2 * (posx - posy - x + y), cy + self.graphics.block_depth // 2 * (-posx - posy + x + y) - self.graphics.block_height * (z - posz))
def draw(self): cx, cy = self.get_screen_center() self.screen.fill(BLACK) rect = self.graphics.block_rect self.offscreen_back.fill((0, 0, 0)) entity_positions = [e.position for e in self.soldiers] for z in range(self.level.zsize): for a in range(self.level.xsize + self.level.ysize): if a >= self.level.xsize: c = a - self.level.xsize #self.level.ysize+self.level.xsize-1-a else: c = 0 for y in range(c, a - c): x = a - y - 1 rx, ry = rotate_xypos(x, y, self.level.xsize - 1, self.level.ysize - 1, (self.rotation) % 4) rect.center = self.map2screen(x, y, z) # Check that we're not drawing outside the screen, which would be # a waste of time. if rect.clip(self.screen.get_rect()).size != (0, 0): if (rx, ry, z) in entity_positions: surf = self.blit_block( (rx, ry, z), rect, entity=self.soldiers[entity_positions.index( (rx, ry, z))]) else: surf = self.blit_block((rx, ry, z), rect) if surf is not None: self.offscreen_back.blit(surf, rect) # if (rx, ry, z) == (self.position.x, self.position.y, self.position.z): # print "drawing cursor" # s = self.draw_column((rx, ry, z)) # self.offscreen_back.blit(s, (rect.left, 0)) # #self.offscreen_back.blit(self.graphics.cursor_img, rect) s = self.draw_column(self.position.tuple()) rect.center = self.map2screen(*self.position.tuple()) self.offscreen_back.blit(s, (rect.left, 0)) #print v.position self.screen.blit(self.offscreen_back, (0, 0)) postext = self.font.render("%d, %d, %d" % v.position.tuple(), 1, (255, 255, 0)) self.screen.blit(postext, (10, 10)) pygame.display.update()
def draw(self): cx, cy = self.get_screen_center() self.screen.fill(BLACK) rect=self.graphics.block_rect self.offscreen_back.fill((0,0,0)) entity_positions = [e.position for e in self.soldiers] for z in range(self.level.zsize): for a in range(self.level.xsize+self.level.ysize): if a >= self.level.xsize: c = a - self.level.xsize #self.level.ysize+self.level.xsize-1-a else: c = 0 for y in range(c,a-c): x = a-y-1 rx, ry = rotate_xypos(x, y, self.level.xsize-1, self.level.ysize-1, (self.rotation)%4) rect.center = self.map2screen(x,y,z) # Check that we're not drawing outside the screen, which would be # a waste of time. if rect.clip(self.screen.get_rect()).size != (0,0): if (rx, ry, z) in entity_positions: surf = self.blit_block((rx, ry, z), rect, entity=self.soldiers[ entity_positions.index((rx, ry, z)) ]) else: surf = self.blit_block((rx, ry, z), rect) if surf is not None: self.offscreen_back.blit(surf, rect) # if (rx, ry, z) == (self.position.x, self.position.y, self.position.z): # print "drawing cursor" # s = self.draw_column((rx, ry, z)) # self.offscreen_back.blit(s, (rect.left, 0)) # #self.offscreen_back.blit(self.graphics.cursor_img, rect) s = self.draw_column(self.position.tuple()) rect.center = self.map2screen(*self.position.tuple()) self.offscreen_back.blit(s, (rect.left, 0)) #print v.position self.screen.blit(self.offscreen_back, (0,0)) postext = self.font.render("%d, %d, %d"%v.position.tuple(), 1, (255,255,0)) self.screen.blit(postext, (10,10)) pygame.display.update()