本文整理汇总了Python中pygame.surface.Surface.get_height方法的典型用法代码示例。如果您正苦于以下问题:Python Surface.get_height方法的具体用法?Python Surface.get_height怎么用?Python Surface.get_height使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygame.surface.Surface
的用法示例。
在下文中一共展示了Surface.get_height方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _createSurfaceImage
# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import get_height [as 别名]
def _createSurfaceImage(self, surfaceHeight):
"""
Make the ground surface image.
IDEA: Try changing the color of the ground, or maybe even add a texture to it.
"""
LunarSurface.image = pygame.Surface(
[screen_width_pixels, surfaceHeight + self._groundElevation], pygame.SRCALPHA, 32
).convert_alpha()
initialY = y = (
Surface.get_height(LunarSurface.image) - self._pointsY[0] + self._drop_amount - self._groundElevation
)
polyCoords = [(0, y)]
for i in range(1, len(self._pointsX)):
y -= self._pointsY[i]
polyCoords.append((self._pointsX[i], y))
surfaceCoords = list(polyCoords)
polyCoords.append([screen_width_pixels, Surface.get_height(LunarSurface.image)])
polyCoords.append([0, Surface.get_height(LunarSurface.image)])
polyCoords.append([0, initialY])
pygame.draw.polygon(LunarSurface.image, (64, 64, 64, 128), polyCoords, 0)
for i in range(0, len(surfaceCoords) - 1):
if self._flatCoordinates.count(i) or self._flatEasyCoordinates.count(i):
# NAM change color: color = 0, 255, 255
color = 255, 0, 0
width = 3
else:
color = 128, 128, 128
width = 1
pygame.draw.line(LunarSurface.image, color, surfaceCoords[i], surfaceCoords[i + 1], width)
self._plotlandingScores(surfaceCoords)
示例2: __init__
# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import get_height [as 别名]
def __init__(self, initialFuel):
self._tardisFrame = []
self._tardisFrame.append(pygame.image.load("Resources/tardis0.png").convert_alpha())
self._tardisFrame.append(pygame.image.load("Resources/tardis1.png").convert_alpha())
self._tardisFrame.append(pygame.image.load("Resources/tardis2.png").convert_alpha())
self._tardisFrame.append(pygame.image.load("Resources/tardisLand0.png").convert_alpha())
self._tardisFrame.append(pygame.image.load("Resources/tardisLand1.png").convert_alpha())
self._tardisFrame.append(pygame.image.load("Resources/tardisLand2.png").convert_alpha())
self.tardisHeight = Surface.get_height(self._tardisFrame[0]) * self._imageResample
self.tardisWidth = Surface.get_width(self._tardisFrame[0]) * self._imageResample
self.altitude = screen_height_pixels - self.tardisHeight * 1 # NAM: Adjust start height
self._landingStickLength = max(self.tardisHeight, self.tardisWidth)
self.x = 50
self.angle = 0
self.angleDelta = 0
self.velocityX = 0.1
self.velocityY = 0
self.thrusting = False
self.image = pygame.transform.rotozoom(self._tardisFrame[0], 0, self._imageResample)
self.rotate(45)
self.thrustSound = pygame.mixer.Sound("Resources/tardisthrust.ogg")
self.thrustSound.set_volume(0.5)
self.fuel = initialFuel
pygame.sprite.Sprite.__init__(self)
self.rect = Rect(self.x, 0, self.tardisWidth, self.tardisWidth)
self.maxHeight = math.sqrt(self.tardisHeight * self.tardisHeight + self.tardisWidth * self.tardisWidth)
self.rotationsPerSec = 0.2
self.recalculateRect()
示例3: __init__
# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import get_height [as 别名]
def __init__(self, surface: Surface, rows, cols,
frame_time=.1):
self.surface = surface
self.rows = rows
self.cols = cols
self.frame_width = surface.get_width() / rows
self.frame_height = surface.get_height() / cols
self.row = 0
self._col = 0
self.frame_time = frame_time
self.time = 0
self.image = Surface((self.frame_width, self.frame_height))
self.image.set_colorkey(Animation.colorkey)
self.valid = False
示例4: ButtonWidget
# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import get_height [as 别名]
class ButtonWidget(Widget):
""" clickable widget with text in it """
def __init__(
self, evManager, text, rect=None, onDownClickEvent=None, onUpClickEvent=None, onMouseMoveOutEvent=None
):
Widget.__init__(self, evManager)
# Widget init sets dirty to true, hence the actual text rendering
# will be done in ButtonWidget.update(), called by the view renderer.
self._em.reg_cb(DownClickEvent, self.on_downclick)
self._em.reg_cb(UpClickEvent, self.on_upclick)
self._em.reg_cb(MoveMouseEvent, self.on_mousemove)
# the events to be triggered when the button is clicked or mouse moved
self.onDownClickEvent = onDownClickEvent
self.onUpClickEvent = onUpClickEvent
self.onMouseMoveOutEvent = onMouseMoveOutEvent
self.text = text
self.font = Font(None, config_get_fontsize()) # default font, 40 pixels high
if rect:
self.rect = rect
self.image = Surface(self.rect.size) # container size from specified rect
# if txtimg does not fit in rect, it'll get cut (good thing)
else:
txtimg = self.font.render(self.text, True, (0, 0, 0))
self.rect = txtimg.get_rect()
self.image = Surface(self.rect.size) # container size from rendered text
# if txt changes, the size of the button will stay the same
def update(self, duration):
if self.dirty == 0:
return
if self.focused:
color = config_get_focusedbtn_txtcolor()
bgcolor = config_get_focusedbtn_bgcolor()
else:
color = config_get_unfocusedbtn_txtcolor()
bgcolor = config_get_unfocusedbtn_bgcolor()
# TODO: is bliting on existing faster than creating a new surface?
self.image = Surface(self.rect.size) # rectangle container for the text
self.image.fill(bgcolor)
txtimg = self.font.render(self.text, True, color)
txtimg = txtimg.convert()
textpos = txtimg.get_rect(centerx=self.image.get_width() / 2, centery=self.image.get_height() / 2)
self.image.blit(txtimg, textpos)
# self.dirty is set to 0 by LayeredDirty.update
def on_downclick(self, event):
""" button down focuses and triggers eventual behavior """
if self.rect.collidepoint(event.pos):
self.dirty = 1
self.set_focus(True)
if self.onDownClickEvent:
self._em.post(self.onDownClickEvent)
def on_upclick(self, event):
""" button up loses focus and triggers eventual behavior """
if self.rect.collidepoint(event.pos):
if self.focused:
self.dirty = 1
self.set_focus(False)
if self.onUpClickEvent:
self.log.debug("Clicked on button widget " + self.text)
self._em.post(self.onUpClickEvent)
def on_mousemove(self, event):
""" if focused, lose focus when the mouse moves out """
if self.rect.collidepoint(event.pos): # mouse moved in
pass
else: # mouse moved out
if self.focused:
if not self.onMouseMoveOutEvent: # default behavior
self.set_focus(False)
示例5: blitTextCentered
# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import get_height [as 别名]
pygame.init()
pygame.display.set_caption("Tardis Lander")
# NAM: kill fullscreen screen=pygame.display.set_mode((screen_width_pixels, screen_height_pixels), pygame.FULLSCREEN, 32)
screen = pygame.display.set_mode((screen_width_pixels, screen_height_pixels), 32)
pygame.mouse.set_visible(0)
screen.fill((255, 255, 255))
pygame.display.update()
background = pygame.image.load("Resources/background.png").convert()
background2 = pygame.image.load("Resources/background2.png").convert()
titleImage = pygame.image.load("Resources/titleimage.jpg").convert()
uiFont = pygame.font.SysFont("monospace", 12)
uiFontBig = pygame.font.SysFont("monospace", 48)
background_image_height = Surface.get_height(background)
screenScroll = 0
def blitTextCentered(font, text, surface, color):
""" Utility function for drawing text at the centre of a 'Surface'. """
label = font.render(text, True, color)
textRect = label.get_rect()
textRect.center = surface.get_rect().center
surface.blit(label, textRect)
def blitTextHorizontalCentered(font, text, y, leftX, width, surface, color):
""" Utility function for drawing text at the horizontal centre of the screen. """
label = font.render(text, True, color)
textRect = label.get_rect()