本文整理汇总了Python中pygame.Rect.left方法的典型用法代码示例。如果您正苦于以下问题:Python Rect.left方法的具体用法?Python Rect.left怎么用?Python Rect.left使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygame.Rect
的用法示例。
在下文中一共展示了Rect.left方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw_round_border
# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import left [as 别名]
def draw_round_border(surface, width=4, color=None, bounds=None):
"""draw_round_border(Surface, line_width, Color, Rect) => None
only Surface is required"""
h = surface.get_height()
w = surface.get_width()
img = dialog.circle_border_image
if color == None: color = pygame.color.Color("white")
if bounds == None: bounds = surface.get_rect()
r = Rect(0,0,8,8)
border = bounds.inflate(-8,-8)
border.topleft = bounds.topleft
surface.blit(img, border.topleft, r)
r.top = 8
surface.blit(img, border.bottomleft, r)
r.left = 8
surface.blit(img, border.bottomright, r)
r.top = 0
surface.blit(img, border.topright, r)
i = bounds.inflate(-17,-17)
o = bounds.inflate(-3,-3)
o.topleft = bounds.topleft
draw.line(surface, color, (i.left,o.top),(i.right,o.top), 4 )
draw.line(surface, color, (o.left,i.top),(o.left,i.bottom), 4 )
draw.line(surface, color, (i.left,o.bottom),(i.right,o.bottom), 4 )
draw.line(surface, color, (o.right,i.top),(o.right,i.bottom), 4 )
示例2: create_platforms_rect
# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import left [as 别名]
def create_platforms_rect(self, tiles, layer):
""" Create a collision rect for each non-empty tile segment, that is, one or more tiles together """
if len(tiles) < 1:
return False
x, y = tiles.pop(0)
width = self.map.content['tilewidth']
height = self.map.content['tileheight']
rect = Rect((0, 0, 0, 0))
rect.left = x * width
rect.top = y * height
rect.width = width
rect.height = height
# self.platforms.append(Platform(rect, layer))
n_tiles_x, n_tiles_y = 0, 0
# exclude the tiles we're about to create a platform for
excluded_tiles = []
for (n_x, n_y) in tiles:
if abs(n_x - x) == n_tiles_x and n_y == y:
rect.width += width
n_tiles_x += 1
excluded_tiles.append((n_x, n_y))
if abs(n_y - y) == n_tiles_y and n_x == x:
rect.height += height
n_tiles_y += 1
excluded_tiles.append((n_x, n_y))
self.platforms.append(Platform(rect, layer))
self.create_platforms_rect([t for t in tiles if not t in excluded_tiles], layer)
示例3: scroll_left_rect
# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import left [as 别名]
def scroll_left_rect(self):
d = self.scroll_button_size
r = Rect(0, 0, d, d)
m = self.margin
r.bottom = self.height - m
r.left = m
r.inflate_ip(-4, -4)
return r
示例4: test_left
# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import left [as 别名]
def test_left( self ):
"""Changing the left attribute moves the rect and does not change
the rect's width
"""
r = Rect( 1, 2, 3, 4 )
new_left = 10
r.left = new_left
self.assertEqual( new_left, r.left )
self.assertEqual( Rect(new_left,2,3,4), r )
示例5: get_bullet_image
# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import left [as 别名]
def get_bullet_image(index, w=16, h=16):
global bullet_image
if not bullet_image:
bullet_image = image.load(resource_path(config.nbtTreeSettings.bulletFileName.get()))
r = Rect(0, 0, w, h)
line_length = int(bullet_image.get_width() / w)
line = int(index / line_length)
r.top = line * h
r.left = (index - (line * line_length)) * w
return bullet_image.subsurface(r)
示例6: draw
# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import left [as 别名]
def draw(self):
#First draw container rect,then draw text rect inside it
self.text_surface= self.font.render(self.text, True,self.font_color,self.bgcolor)
self.text_size=self.text_surface.get_size()
container_rect=Rect(self.x_y[0]-self.border_width,self.x_y[1] - self.border_width,self.text_size[0] + self.border_width,self.text_size[1]+self.border_width)
container_rect.top=self.x_y[1]
container_rect.left=self.x_y[0]
self.text_dest=self.x_y+(self.border_width,self.border_width)
pygame.draw.rect(self.surface,self.border_color,container_rect)
self.surface.blit(self.text_surface,self.text_dest)
示例7: load_image_array
# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import left [as 别名]
def load_image_array(name):
fullpath = os.path.join(RESOURCE_PATH, name)
image = pygame.image.load(fullpath)
if image.get_alpha() is None:
image = image.convert()
else:
image = image.convert_alpha()
width, height = image.get_size()
if width % height != 0:
raise ValueError, 'Image has invalid dimensions'
image_list = []
rect = Rect((0, 0), (height, height))
for i in xrange(width / height):
rect.left = i * height
image_list.append(image.subsurface(rect))
return image_list
示例8: load_images
# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import left [as 别名]
def load_images():
images = {}
images['Terrain'] = {}
images['Terrain'][False] = load_file('Terrain-Solid.png')
images['Terrain'][True] = load_file('Terrain-Spikes.png')
images['Terrain']['Goal'] = load_file('Goal.png')
images['Player'] = {}
images['Player']['Idle'] = load_file('Player-Idle.png')
images['Player']['Jump'] = load_file('Player-Jump.png')
images['Player']['Fall'] = load_file('Player-Fall.png')
images['Player']['Dead'] = load_file('Player-Dead.png')
images['Player']['Run'] = [load_file(('Player-Run-'+str(frame)+'.png')) for frame in range(1,3)]
images['Player']['Walk'] = [load_file(('Player-Walk-'+str(frame)+'.png')) for frame in range(1,3)]
images['Player']['Run'].insert(0,images['Player']['Idle'])
images['Player']['Walk'].insert(0,images['Player']['Idle'])
images['Digits'] = []
digit_rect = Rect(0,0,5,8)
digit_image = load_file('Digits.png')
for digit_number in range(10):
images['Digits'].append(Surface([5,8],SRCALPHA,32))
images['Digits'][-1].blit(digit_image,[0,0],digit_rect)
digit_rect.left = digit_rect.right
digit_rect.left += 1
images['Splash'] = {}
images['Splash']['Logo'] = load_file('yuriifreire.png')
images['Splash']['Title'] = load_file('Title.png')
images['Splash']['Presents'] = load_file('Presents.png')
images['Splash']['Press-Any-Key'] = load_file('Press-Any-Key.png')
return images
示例9: get_bullet_rect
# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import left [as 别名]
def get_bullet_rect(self, surf, lvl):
r = Rect(0, 0, self.bullet_size, self.bullet_size)
r.left = self.bullet_size * lvl
r.inflate_ip(-4, -4)
return r
示例10: Rect
# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import left [as 别名]
rect = Rect(x - radius, y - radius, radius * 2, radius * 2)
bandit = self.parent.bandit.rect
if rect.colliderect(bandit):
if bandit.left - rect.right > rect.top - bandit.bottom:
angle = -angle
rect.right = bandit.left
else:
angle = pi - angle
rect.top = bandit.bottom
field = self.parent.rect
if rect.right > field.w or rect.left < 0:
angle = -angle
if rect.right > field.w:
rect.right = field.w
else:
rect.left = 0
if rect.top < 0 or rect.bottom > field.h:
angle = pi - angle
if rect.top < 0:
rect.top = 0
else:
rect.bottom = field.h
self.angle = angle
self.center = rect.center
def update_total_elapsed(self):
current_ticks = time.get_ticks()
self.total_elapsed += current_ticks - self.last_ticks
self.last_ticks = current_ticks
def draw_circle(self):
示例11: __contains__
# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import left [as 别名]
def __contains__(self, event):
r = Rect(self._rect)
r.left = 0
r.top = 0
p = self.global_to_local(event.pos)
return r.collidepoint(p)
示例12: resource_path
# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import left [as 别名]
except Exception, e:
print "*** MCEDIT DEBUG: bullets image could not be loaded."
print "*** MCEDIT DEBUG:", e
print "*** MCEDIT DEBUG: bullets image file:", resource_path(config.nbtTreeSettings.bulletFileName.get())
print "*** MCEDIT DEBUG: current directory:", os.getcwd()
from pygame import Surface, draw, SRCALPHA
bullet_image = Surface((64, 64), SRCALPHA)
bullet_image.fill((0, 0, 0, 0))
for i in range(4):
for j in range(4):
bullet_image.fill((255/(i or 1), 255/(j or 1), 255, 255), [16*i, 16*j, 16*i+16, 16*j+16])
r = Rect(0, 0, w, h)
line_length = int(bullet_image.get_width() / w)
line = int(index / line_length)
r.top = line * h
r.left = (index - (line * line_length)) * w
return bullet_image.subsurface(r)
default_bullet_styles = {TAG_Byte: ((20, 20, 200), None, 'circle', 'b'),
TAG_Double: ((20, 200, 20), None, 'circle', 'd'),
TAG_Float: ((200, 20, 20), None, 'circle', 'f'),
TAG_Int: ((16, 160, 160), None, 'circle', 'i'),
TAG_Long: ((200, 20, 200), None, 'circle', 'l'),
TAG_Short: ((200, 200, 20), (0, 0, 0), 'circle', 's'),
TAG_String: ((60, 60, 60), None, 'circle', 's'),
TAG_Compound: (bullet_color_active, None, '', ''),
TAG_Byte_Array: ((20, 20, 200), None, 'square', 'B'),
TAG_Int_Array: ((16, 160, 160), None, 'square', 'I'),
TAG_List: ((200, 200, 200), (0, 0, 0), 'square', 'L'),
TAG_Short_Array: ((200, 200, 20), None, 'square', 'S'),
示例13: main
# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import left [as 别名]
def main():
pygame.init()
pantalla=pygame.display.set_mode((800,600))
pygame.FULLSCREEN
pygame.display.set_caption("ProyectoPygame")
reloj1=pygame.time.Clock()
salir=False
p1 = Personaje()
p1._x = 430
p1._y = 180
p1.x_antes = 50
p1.y_antes = 50
p1.tam_rectangulos((70, 70))
p1.actualizacionRec()
p2 = Personaje()
p2._x = 100
p2._y = 200
p2.tam_rectangulos((100, 100))
p2.actualizacionRec()
plataforma2 = Plataforma()
plataforma2.setXY(250, 200)
plataforma2.setTamRect(300, 100)
p1_antes = Rect(p1.x_antes, p1.y_antes, 70, 70)
motor = MotorVideojuego()
motor.conjuntoPersonajes = [p1, p2]
#motor.start()
start = pygame.time.get_ticks()/1000
iter=0
limit=1000
l = reposicion(p1, plataforma2)
while salir == False:
lista=pygame.event.get()#((pygame.KEYDOWN, pygame.KEYUP, pygame.QUIT, pygame.MOUSEBUTTONDOWN))
for event in lista:
#----------Escuchando Eventos del Usuario-#
if event.type == pygame.QUIT:
salir = True
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
p1.setSalto(True)
print "SAlta"
if event.type == pygame.MOUSEMOTION:
xy=pygame.mouse.get_pos()
p1.x_antes = xy[0]
p1.y_antes = xy[1]
p1_antes.left = xy[0]
p1_antes.top = xy[1]
l = reposicion(p1, plataforma2)
pantalla.fill((0,0,240))
if pygame.time.get_ticks()>limit:
#print iter
limit+=1000
iter=0
iter+=1
pygame.draw.rect(pantalla, green, plataforma2.rectangulo)
pygame.draw.rect(pantalla, red, p1.rectangulo)
pygame.draw.rect(pantalla, red, p1_antes)
for rec in l:
pygame.draw.rect(pantalla, darkBlue, rec)
reloj1.tick(120)
pygame.display.update()
motor.salirJuego = True
pygame.quit()