Ignore:
Timestamp:
09/06/13 13:18:40 (8 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Phase:
public
Rebase:
63646566303435363637663837313361626164333938396435623963386666643938326439663639
Message:

Split out tiling into utility function

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/utils.py

    r343 r348  
    11import pygame
     2import pygame.locals as pgl
     3
    24from pymunk.vec2d import Vec2d
    35
     
    2527        vec.length = length
    2628    return vec
     29
     30
     31def tile_surface(size, tile_image):
     32    # create a surface, approriately tiled
     33    surface = pygame.surface.Surface(size, pgl.SRCALPHA)
     34    surface.fill(pygame.color.THECOLORS['black'])
     35    x_step = tile_image.get_rect().width
     36    y_step = tile_image.get_rect().height
     37    x_count = size[0] // x_step + 1
     38    y_count = size[1] / y_step + 1
     39    tile_rect = pygame.rect.Rect(0, 0, x_step, y_step)
     40    for x in range(x_count):
     41        tile_rect.x = x * x_step
     42        for y in range(y_count):
     43            tile_rect.y = y * y_step
     44            surface.blit(tile_image, tile_rect)
     45    return surface
Note: See TracChangeset for help on using the changeset viewer.