本文整理汇总了Python中pygame.Surface.subsurface方法的典型用法代码示例。如果您正苦于以下问题:Python Surface.subsurface方法的具体用法?Python Surface.subsurface怎么用?Python Surface.subsurface使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygame.Surface
的用法示例。
在下文中一共展示了Surface.subsurface方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Block
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import subsurface [as 别名]
class Block(sprite.Sprite):
"""
Данный класс описывает блоки
"""
def __init__(self, id, x, y, type, DEMAGE):
sprite.Sprite.__init__(self)
self.image = Surface((PLATFORM_WIDTH, PLATFORM_HEIGHT)) # изображение
self.id = id # идентификатор
self.type = type # тип платформы
self.demage = DEMAGE
if type == "-": # разрушаемая
self.image = image.load("blocks/platform.png")
elif type == "*": # НЕразрушаемая
self.image = image.load("blocks/beton.png")
else: # все остальные
self.image.fill(Color(PLATFORM_COLOR))
self.rect = Rect(x, y, PLATFORM_WIDTH, PLATFORM_HEIGHT) # размеры блока
def die(self, shutdirection):
# попадание в блок
if self.type == "-":
# если он разрушаемый
x = self.rect.left
y = self.rect.top
w = self.rect.width
h = self.rect.height
# уменьшаем размер блока с соответсвующего направления
if shutdirection == "left":
self.image = self.image.subsurface((0, 0, w-self.demage, h))
self.rect = Rect(x, y, w-self.demage, h)
elif shutdirection == "right":
self.image = self.image.subsurface((self.demage, 0, w-self.demage, h))
self.rect = Rect(x+self.demage, y, w-self.demage, h)
if shutdirection == "up":
self.image = self.image.subsurface((0, 0, w, h-self.demage))
self.rect = Rect(x, y, w, h-self.demage)
if shutdirection == "down":
self.image = self.image.subsurface((0, self.demage, w, h-self.demage))
self.rect = Rect(x, y+self.demage, w, h-self.demage)
# если блок уничтожен совсем, удаляем его из всех групп
if (self.rect.width == 0) or (self.rect.height == 0):
self.rect.width = self.rect.height = 0
self.kill()
示例2: __init__
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import subsurface [as 别名]
def __init__(self, parentSurface:Surface, rect:pygame.Rect, filmstrip:Surface, borderColor:tuple):
Widget.__init__(self, parentSurface, rect, borderColor, None)
self.images = []
self.numImages = int(filmstrip.get_rect().height / filmstrip.get_rect().width)
self.currentImage = 0
clipRect = pygame.Rect(0, 0, rect.width, rect.height)
for x in range(0, self.numImages):
self.images.append(filmstrip.subsurface(clipRect))
clipRect.move_ip(0, rect.height)
self.draw()
示例3: draw_spectrum
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import subsurface [as 别名]
def draw_spectrum(self, f, x):
draw_area = Surface((1, len(f)), depth=24)
d = surfarray.pixels3d(draw_area)
self.peak = np.maximum(np.amax(f, axis=0), self.peak)
a = (255 * f / self.peak[np.newaxis, :]).astype(np.uint8)
d[0, :, 1:] = a[::-1]
d[0, :, 0] = a[::-1, 1] / 2 + a[::-1, 0] / 2
for m in self.markers:
im = int((2 * m / self.sample_rate) * len(f))
d[0, -im, 0] = 255
del d
it = int((2 * self.top_freq / self.sample_rate) * len(f))
self.surface.blit(smoothscale(draw_area.subsurface((0, len(f) - it - 1, 1, it)), (1, self.size[1])), (x, 0))
self.peak *= 2.0 ** (-1.0 / 100)
示例4: __init__
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import subsurface [as 别名]
def __init__(self, parentSurface:pygame.Surface, rect:pygame.Rect, skin:Skin, sequence:Sequence):
Container.__init__(self, parentSurface, rect, skin)
backgroundColor = skin.guiColor("Background")
parentSurface.fill(backgroundColor, rect)
self.sequence = sequence
gridRect = pygame.Rect(0, rect.top + Padding.GRID,
rect.width,
rect.height - (Padding.GRID * 2))
self.parentSurface = parentSurface.subsurface(gridRect)
self.rect = self.parentSurface.get_rect()
self.background = pygame.Surface((self.rect.width, self.rect.height))
self.background.fill(skin.guiColor("Grid"))
self.parentSurface.blit(self.background, self.rect)
self.gridSprites = GridSpriteGroup(sequence, (gridRect.left, gridRect.top),
self.rect, skin)
self.activePopup = None
示例5: Surface
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import subsurface [as 别名]
from pygame.sprite import *
from factions import *
pygame.init()
screen = display.set_mode((800,600),HWSURFACE)
display.set_caption('Regime Change')
background = Surface(screen.get_size())
background.fill((128,128,128))
text = font.SysFont('Courier', 10)
plot = background.subsurface(Rect(0,
0,
background.get_width(),
background.get_height()/2))
chart = background.subsurface(Rect(0,
plot.get_height(),
background.get_width(),
background.get_height()-plot.get_height()))
values = 'militarism', 'moralism'
society = Society([Faction('aristocracy', (0,0,255), random(), values),
Faction('merchant class', (0,255,0), random(), values),
Faction('populace', (255,0,0), random(), values)])
for f in society.factions:
for v in f.values.keys():
f.values[v] = random()
charts = [chart.subsurface(Rect(i * chart.get_width()/len(society.factions),
示例6: Screen
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import subsurface [as 别名]
class Screen(object):
def __init__(self, size, caption, icon_caption):
pygame.init()
display.set_caption(caption, icon_caption)
self._make_screen(size)
self._controls = []
self._sprites = Group()
self._drag_start = None
self.dragged = lambda start, end: None
self.size_changed = lambda size: None
def _make_screen(self, size):
self._screen = display.set_mode(size, HWSURFACE | RESIZABLE)
@property
def size(self):
return self._screen.get_size()
def step(self, dots, shapes):
for e in event.get():
if e.type == QUIT:
return True
elif e.type == KEYDOWN:
if e.key == K_ESCAPE:
return True
elif e.type == VIDEORESIZE:
self._make_screen(e.size)
self.size_changed(self.size)
elif e.type == MOUSEBUTTONDOWN and e.button == 1:
self._drag_start = mouse.get_pos()
elif e.type == MOUSEMOTION and 1 in e.buttons:
if self._drag_start is not None:
p = mouse.get_pos()
if p != self._drag_start:
self.dragged(self._drag_start, p)
self._drag_start = p
elif e.type == MOUSEBUTTONUP and e.button == 1:
self._drag_start = None
p = mouse.get_pos()
w, h = self.size
dw = 0
for c in self._controls:
dw += c.width
if w - dw <= p[0] < w - dw + c.width:
c.click((p[0] - (w - dw), p[1]))
break
self._sprites.empty()
for dot in dots:
sprite = Sprite()
sprite.image = pygame.Surface((2 * dot.radius, 2 * dot.radius),
flags=SRCALPHA)
draw.circle(sprite.image, dot.color,
(dot.radius,dot.radius), dot.radius)
sprite.rect = Rect(tuple([int(c) - dot.radius for c in dot.location]),
sprite.image.get_size())
self._sprites.add(sprite)
for shape in shapes:
sprite = Sprite()
sprite.image = pygame.Surface((int(shape.width), int(shape.height)),
flags=SRCALPHA)
points = [tuple([int(c) for c in p]) for p in shape.points]
if len(points) > 2:
draw.polygon(sprite.image, shape.color, points)
else:
draw.lines(sprite.image, shape.color, False, points)
sprite.rect = Rect(tuple([int(c) for c in shape.location]),
sprite.image.get_size())
self._sprites.add(sprite)
self._sprites.clear(self._screen, self._background)
self._sprites.draw(self._screen)
display.flip()
return False
def fill_background_rows(self, color, rows):
self._background = Surface(self._screen.get_size())
self._background.fill((128,128,128))
for i in range(len(rows)):
for start, length in rows[i]:
self._background.fill(color, Rect(start, i, length, 1))
def draw_controls(self):
w, h = self.size
dw = 0
for c in self._controls:
dw += c.width
c.draw(self._background.subsurface(Rect(w - dw, 0, c.width, h)))
def paint_background(self):
self._screen.blit(self._background, (0,0))
#.........这里部分代码省略.........