Mercurial > nagslang
view nagslang/utils.py @ 387:ca89d566f9ef
Drop unused alpha bit from tile_surface helper
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Sat, 07 Sep 2013 00:10:20 +0200 |
parents | d0aeb893967d |
children | ae8eb7c0f7bb |
line wrap: on
line source
import pygame import pygame.locals as pgl from pymunk.vec2d import Vec2d def convert_colour(colour): if isinstance(colour, pygame.Color): return colour if isinstance(colour, tuple): return pygame.Color(*colour) if isinstance(colour, basestring): return pygame.Color(colour) raise ValueError() def vec_from_angle(angle, length=1): vec = Vec2d(length, 0) vec.angle = angle return vec def vec_with_length(coords, length=1): vec = Vec2d(coords) # Don't crash if we're created a zero length vector if vec.length != 0: vec.length = length return vec def tile_surface(size, tile_image): # create a surface, approriately tiled surface = pygame.surface.Surface(size, pgl.SRCALPHA) x_step = tile_image.get_rect().width y_step = tile_image.get_rect().height x_count = size[0] // x_step + 1 y_count = size[1] / y_step + 1 tile_rect = pygame.rect.Rect(0, 0, x_step, y_step) for x in range(x_count): tile_rect.x = x * x_step for y in range(y_count): tile_rect.y = y * y_step surface.blit(tile_image, tile_rect) return surface