本文整理汇总了Python中pygame.Surface.convert方法的典型用法代码示例。如果您正苦于以下问题:Python Surface.convert方法的具体用法?Python Surface.convert怎么用?Python Surface.convert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygame.Surface
的用法示例。
在下文中一共展示了Surface.convert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Player
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import convert [as 别名]
class Player(Sprite):
def __init__(self, x, y):
super().__init__()
self.xvel = 0
self.yvel = 0
self.onGround = True
self.image = Surface((32, 32))
self.image.fill(Color("#00FFFF"))
self.image.convert()
self.rect = Rect(x, y, 32, 32)
def update(self):
self.rect = self.rect.move(3, 0)
示例2: GameMap
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import convert [as 别名]
class GameMap(object):
def __init__(self, gameClient, mapWidth, mapHeight):
self.mapWidth = mapWidth
self.mapHeight = mapHeight
self.gameClient = gameClient
self.updated = True
self.tilesize = TILESIZE
self.widthInPixels = self.mapWidth*self.tilesize
self.heightInPixels = self.mapHeight*self.tilesize
self.backgroundLayer = TileLayer(gameClient, self.mapWidth, self.mapHeight, "01")
self.foregroundLayer = TileLayer(gameClient, self.mapWidth, self.mapHeight, "02")
self.spriteLayer = SpriteLayer(gameClient, self.mapWidth, self.mapHeight)
self.mapSurface = Surface((self.mapWidth * self.tilesize, self.mapHeight * self.tilesize))
self.updateMapSurface()
def clearTileLayers(self):
self.backgroundLayer.clearSurface()
self.foregroundLayer.clearSurface()
def updateMapSurface(self):
if self.updated:
self.backgroundLayer.blitTiles(self.gameClient)
self.foregroundLayer.blitTiles(self.gameClient)
self.updated = False
self.mapSurface.blit(self.backgroundLayer.getSurface(), self.backgroundLayer.getSurface().get_rect())
#self.mapSurface.blit(self.foregroundLayer.getSurface(), self.foregroundLayer.getSurface().get_rect())
self.mapSurface.convert()
def getWidthInPixels(self):
return self.widthInPixels
def getHeightInPixels(self):
return self.heightInPixels
def getSizeInPixels(self):
return (gameClient.gameMap.getWidthInPixels(), gameClient.gameMap.getHeightInPixels)
示例3: load_base
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import convert [as 别名]
def load_base(self):
""" Load the base (back surface) for the world
"""
width, height = (WORLD_MAP_SIZE[0] * TILE_SIZE, WORLD_MAP_SIZE[1] * TILE_SIZE)
image = Surface((TILE_SIZE, TILE_SIZE))
image.convert()
base = pygame.Surface((width, height))
base.convert()
# Fill in sky with blue
base.fill(Color(0, 0, 255), Rect(0, 0, width, height / 2))
# Fill in ground with brown
base.fill(Color("#573B0C"), Rect(0, height / 2, width, height / 2))
return base
示例4: void_frame
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import convert [as 别名]
def void_frame(size, bck):
surface = Surface(size)
try:
surface.fill(bck)
surface.set_colorkey(bck, RLEACCEL)
except TypeError:
surface.fill(WHITE)
surface.set_colorkey(constants.WHITE, RLEACCEL)
return surface.convert()
示例5: __init__
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import convert [as 别名]
def __init__(self, x, y, **kwargs):
img = Surface((50,50))
img = img.convert()
img.fill(PINK_TRANSPARENT)
img.set_colorkey(PINK_TRANSPARENT)
col_rect = Rect(24,24,2,2)
TryParticle.__init__(self, x=x, y=y, gravity = 0.5, has_gravity=True, image = img, col_rect=col_rect, life_time=100, collides=True)
FadeOutParticle.__init__(self, fade_out_time = 30, life_time = 30)
RandomSpeedParticle.__init__(self, max_speed = 10, delta_ang = 360, min_speed=5)
示例6: get_tile
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import convert [as 别名]
def get_tile(self, name, colorkey=None, tile_pos=None):
key = (name, tile_pos)
if not self.tiles.has_key( key ):
image = util.load_image(TILES_DIR, name)
image = util.load_image(TILES_DIR, name).convert()
if tile_pos is not None:
tmp = Surface( (TILE_SIZE, TILE_SIZE) )
rect = Rect(tile_pos[0]*TILE_SIZE, tile_pos[1]*TILE_SIZE,TILE_SIZE,TILE_SIZE)
tmp.blit(image, (0,0), rect)
image = tmp.convert()
self.tiles[key] = image
return self.tiles[key]
示例7: Organism
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import convert [as 别名]
class Organism(Entity):
def __init__(self, x, y, level, color = None):
Entity.__init__(self)
self.image = Surface((16, 16))
if color: self.image.fill(color)
self.image.convert()
self.rect = Rect(x, y, 16, 16)
self.level = level
def random_adjacent_coords(self, clear = False):
x, y = self.tile_coords()
off_x, off_y = 0, 0
while (off_x == 0 and off_y == 0) or not self.level.clear_at_tile(x + off_x, y + off_y):
off_x = 1 - randint(0, 2)
off_y = 1 - randint(0, 2)
return x + off_x, y + off_y
def adjacent_entities(self):
adjacent_entities = []
x, y = self.tile_coords()
for d in DIRECTIONS:
entity = self.level.entity_at(x + d[0], y + d[1])
if entity: adjacent_entities.append(entity)
return adjacent_entities
示例8: shadowed_frame
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import convert [as 别名]
def shadowed_frame(size, pressed=False, thick=1,
color=constants.BRAY, light=None, dark=None):
"""Returns a sdl surface.
Function used as default design for elements."""
if size[1] < 1:
size = (size[0], 16)
surface = Surface(size)
shadowed_frame_blit(
surface,
pygame.Rect(
(0,
0),
size),
pressed,
thick,
color,
light,
dark)
return surface.convert()
示例9: regular_polygon
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import convert [as 别名]
def regular_polygon(
radius,
sides,
thickness=0,
angle=0.,
color=constants.BLACK):
"""Angle is the offset angle in degrees"""
surface = Surface((2 * radius, 2 * radius))
different = different_color(color)
surface.fill(different)
surface.set_colorkey(different, RLEACCEL)
angle = radians(angle)
alpha = 2 * pi / sides # constant
# building points
points = list()
for i in range(sides):
ai = i * alpha + angle
pix = cos(ai) * radius + radius
piy = sin(ai) * radius + radius
points.append((pix, piy))
pygame.draw.polygon(surface, color, points, thickness)
return surface.convert()
示例10: load_graphics
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import convert [as 别名]
def load_graphics(self):
degrees = [-90, -65, -45, -20, 0, 20, 45, 65, 90]
degree_images = []
for degree in degrees:
image = data.load_image('tman_arm_%d.png' % degree)
degree_images.append(image)
twisters = range(4)
twister_images = []
for twister in twisters:
image = data.load_image('tman_twister_%d.png' % (twister + 1))
twister_images.append(image)
torso_image = data.load_image('tman_torso.png')
size = torso_image.get_rect().width, torso_image.get_rect().height
self.frames = {}
for degree_image, degree in zip(degree_images, degrees):
self.frames[degree] = {}
for twister_image, twister in zip(twister_images, twisters):
self.frames[degree][twister] = {}
image = Surface(size)
image = image.convert()
image.fill(COLORKEY)
image.set_colorkey(COLORKEY)
image.blit(torso_image, (0,0))
image.blit(twister_image, (0,0))
image.blit(degree_image, (0,0))
self.frames[degree][twister]['right'] = image
image = pygame.transform.flip(image, True, False)
self.frames[degree][twister]['left'] = image
self.degree = 0
self.side = 'right'
self.twister = 0
self.image = self.frames[self.degree][self.twister][self.side]
self.rect = self.image.get_rect()
示例11: load_pygame
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import convert [as 别名]
def load_pygame(filename):
"""
load a tiled TMX map for use with pygame
"""
from pygame import Surface
import pygame, os
tiledmap = load_tmx(filename)
# cache will find duplicate tiles to reduce memory usage
# mostly this is a problem in the blank areas of a tilemap
cache = {}
# just a precaution to make sure tileset images are added in the correct order
for firstgid, t in sorted([(t.firstgid, t) for t in tiledmap.tilesets]):
path = os.path.join(os.path.dirname(tiledmap.filename), t.source)
image = pygame.image.load(path)
w, h = image.get_rect().size
tile_size = (t.tilewidth, t.tileheight)
# some tileset images may be slightly larger than the tiles area
# ie: may include a banner, copyright, etc. this compensates for that
for y in range(0, int(h / t.tileheight) * t.tileheight, t.tileheight):
for x in range(0, int(w / t.tilewidth) * t.tilewidth, t.tilewidth):
# somewhat handle transparency, though colorkey handling is not tested
if t.trans is None:
tile = Surface(tile_size, pygame.SRCALPHA)
else:
tile = Surface(tile_size)
# blit the smaller portion onto a new image from the larger one
tile.blit(image, (0, 0), ((x, y), tile_size))
# make a unique id for this image, not sure if this is the best way, but it works
key = pygame.image.tostring(tile, "RGBA")
# make sure we don't have a duplicate tile
try:
tile = cache[key]
except KeyError:
if t.trans is None:
tile = tile.convert_alpha()
else:
tile = tile.convert()
tile.set_colorkey(t.trans)
# update the cache
cache[key] = tile
tiledmap.images.append(tile)
# correctly handle transformed tiles. currently flipped tiles
# work by creating a new gid for the flipped tile and changing the gid
# in the layer to the new gid.
for layer in tiledmap.tilelayers:
for x, y, gid, trans in layer.flipped_tiles:
fx = trans & FLIP_X == FLIP_X
fy = trans & FLIP_Y == FLIP_Y
tile = pygame.transform.flip(tiledmap.images[gid], fx, fy)
tiledmap.images.append(tile)
# change the original gid in the layer data to the new gid
layer.data[y][x] = len(tiledmap.images) - 1
del layer.flipped_tiles
del cache
return tiledmap
示例12: sleep
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import convert [as 别名]
screen.blit(background, (0, 0))
display.flip()
sleep(0.1)
if i >= 2 :
_linux_set_time(dt.timetuple())
urlopen("http://127.0.0.1/functions/cron.php?change=" + dr.strftime("%s")).read()
break
# Initialisation
display.init()
font.init()
screen = display.set_mode([320, 240])
background = Surface(screen.get_size())
background = background.convert()
# Récupération de la config
conf_file = open("../conf/wake.json")
conf = jload(conf_file)
# Définition des polices
font_filename = font.match_font(conf["general"]["font"])
font = font.Font(font_filename, 135)
#font_time = font.Font(font_filename, 135)
# Definition et coloration des images
image_temp = image.load("images/misc/temp.png")
示例13: basic_bckgr
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import convert [as 别名]
def basic_bckgr(size, color=constants.BLACK):
surface = Surface(size)
surface.fill(color)
return surface.convert()
示例14: simple_frame
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import convert [as 别名]
def simple_frame(size, color=constants.BRAY):
surface = Surface(size)
surface.fill(color)
return surface.convert()
示例15: Bar
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import convert [as 别名]
class Bar(Sprite):
def __init__(self, factor, height, *groups):
Sprite.__init__(self, *groups)
self.factor = factor
self.height = height
self.put(0, 0)
self.create_image()
def update(self, *args):
self.create_image()
self.update_color()
self.update_size()
self.create_bar()
self.fill_image()
def get_max_value(self):
pass
def get_value(self):
pass
def create_image(self):
self.size = (self.get_max_value() * self.factor)
self.image = Surface((self.size, self.height))
self.image = self.image.convert()
self.image.set_colorkey(COLORKEY)
self.rect = self.image.get_rect()
self.rect.left = self.x
self.rect.bottom = self.y
def update_color(self):
color_value = int(255 * self.get_value() / self.get_max_value() )
if 200 <= color_value <= 255:
self.color = (0, color_value, 0)
elif 90 <= color_value < 200:
self.color = (255, color_value + 55, 0)
else:
self.color = (255-color_value, 0, 0)
def update_size(self):
self.size = int(self.size * self.get_value() / self.get_max_value() )
def create_bar(self):
self.bar = Surface((self.size, 10))
self.bar.fill(self.color)
def fill_image(self):
self.image.fill(COLORKEY)
rect = self.bar.get_rect()
rect.bottom = self.image.get_rect().bottom
self.image.blit(self.bar, rect)
self.draw_border()
def put(self, x, y):
self.x = x
self.y = y
def draw_border(self):
rect = self.image.get_rect()
pygame.draw.rect(self.image, (0, 0, 0), rect, 1)