本文整理汇总了Python中pygame.draw.rect函数的典型用法代码示例。如果您正苦于以下问题:Python rect函数的具体用法?Python rect怎么用?Python rect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rect函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: draw
def draw(self, surface):
from pygame.draw import rect
#surface dimensions
w = surface.get_width()
h = surface.get_height()
padding = 0.05 #decimal percent
#calculate the exact board height
(self.bw, self.bh) = fit((self.height, self.width), (h, w))
#calculate the offsets to centre everything
self.offset = ((w/2)-(self.bw/2), (h/2)-(self.bh/2))
#draw board outline
rect(surface, (128, 200, 255), (self.offset[0], self.offset[1], self.bw, self.bh), 5)
#loop round holes drawing each of them
#print self.holes
for hole in self.holes:
hole.draw(surface)
return self
开发者ID:AnnanFay,项目名称:pyge-solitaire,代码行数:25,代码来源:board.py
示例2: draw_my_hp
def draw_my_hp(pkmn):
"""
function
"""
maxhp = pkmn.maxhp
hp = pkmn.hp
bar_len = floor(hp / float(maxhp) * 399)
if bar_len < 100:
color = RED
elif bar_len < 200:
color = YELLOW
else:
color = GREEN
if 10 <= maxhp < 100:
maxhp = ' ' + str(maxhp)
elif maxhp < 10:
maxhp = ' ' + str(maxhp)
else:
maxhp = str(maxhp)
if 10 <= hp < 100:
hp = ' ' + str(hp)
elif hp < 10:
hp = ' ' + str(hp)
else:
hp = str(hp)
draw.rect(SCREEN, WHITE, MYHP_RECT)
if hp > 0:
draw.rect(
SCREEN, color, [MYHP_RECT[0], MYHP_RECT[1], bar_len, MYHP_RECT[3]])
retval = []
retval.append(MYHP_RECT)
retval.append(
word_builder('{0}/{1}'.format(hp, maxhp), SIZE[0] - 570, SIZE[1] - 445))
return retval
开发者ID:nimbian,项目名称:pokepong,代码行数:34,代码来源:util.py
示例3: draw
def draw(self, surface):
frame = self.get_margin_rect()
fg = self.fg_color
font = self.font
focused = self.has_focus()
text, i = self.get_text_and_insertion_point()
if focused and i is None:
if self.selection_start is None or self.selection_end is None:
surface.fill(self.sel_color, frame)
else:
startStep = self.selection_start
endStep = self.selection_end
if startStep > endStep:
x1, h = font.size(text[0:endStep])[0], font.get_linesize()
x2, h = font.size(text[0:startStep])[0], font.get_linesize()
x1 += frame.left
x2 += frame.left
y = frame.top
selRect = pygame.Rect(x1, y, (x2 - x1), h)
else:
x1, h = font.size(text[0:startStep])[0], font.get_linesize()
x2, h = font.size(text[0:endStep])[0], font.get_linesize()
x1 += frame.left
x2 += frame.left
y = frame.top
selRect = pygame.Rect(x1, y, (x2 - x1), h)
draw.rect(surface, self.sel_color, selRect)
image = font.render(text, True, fg)
surface.blit(image, frame)
if focused and i is not None:
x, h = font.size(text[:i]) #[0], font.get_linesize()
x += frame.left
y = frame.top
draw.line(surface, fg, (x, y), (x, y + h - 1))
开发者ID:cosmoharrigan,项目名称:MCEdit-Unified,代码行数:35,代码来源:fields.py
示例4: refresh
def refresh(self):
self._padding = self.style['padding']
itemheight = self.style['item-height']
maxItemWidth = self.size[0]
for item in self.items:
itemWidth = self.style['font'].size(str(item))[0]
if itemWidth > maxItemWidth:
maxItemWidth = itemWidth
if self.style['autosize']:
self.size = (maxItemWidth, len(self.items) * itemheight)
listsize = (self.size[0], len(self.items) * itemheight)
if not self.surf or self.surf.get_size() != listsize:
self.surf = pygame.Surface(listsize, pygame.SRCALPHA)
self.surf.fill(self.style['bg-color'])
for i in xrange(len(self.items)):
drawRect = True
if i == self.overedIndex == self.selectedIndex and self.mouseover:
fontcolor = self.style['font-color']
bgcolor = mixColors(self.style['bg-color-over'], self.style['bg-color-selected'])
if i == self.overedIndex and self.mouseover:
fontcolor = self.style['font-color']
bgcolor = self.style['bg-color-over']
elif i == self.selectedIndex:
fontcolor = self.style['font-color-selected']
bgcolor = self.style['bg-color-selected']
else:
fontcolor = self.style['font-color']
bgcolor = self.style['bg-color']
drawRect = False
if drawRect:
draw.rect(self.surf, bgcolor, Rect(0, i * itemheight, self.surf.get_width(), itemheight))
render = self.style['font'].render(str(self.items[i]), True, fontcolor, bgcolor)
self.surf.blit(render, (2, i * itemheight + itemheight / 2 - render.get_height() / 2))
开发者ID:249550148,项目名称:mygame,代码行数:34,代码来源:gui.py
示例5: draw
def draw(self, screen):
draw.rect(screen, (0, 0, 0), (0, 0, self.width, self.size))
screen.blit(self.current_block, (self.width-self.size*2, self.y, self.size, self.size))
screen.blit(COIN, (0, 0))
screen.blit(self.draw_msg(self.gold), (self.size, self.size//4))
screen.blit(self.draw_msg(self.current_i), (self.size*4, self.size//4))
screen.blit(self.draw_msg('HP ' + str(int(self.level.heart_hp))), (self.width-self.size*6, self.size//4))
if self.paused:
screen.blit(self.draw_msg('GAME PAUSED'), (self.size*8, self.size//4))
if self.splash > 0:
screen.blit(self.draw_msg(self.splash_msg), (self.size*7, self.size*2))
if self.gold_cooldown > 0:
screen.blit(self.draw_msg(self.gold_msg), (self.size*1.5, self.size))
if self.level.heart_hp <= 0:
lost_msg = 'Your kingdom has fallen on:'
day_msg = 'DAY:' + str(self.level.game_clock.days)
restart_msg1 = 'Press R to restart'
restart_msg2 = 'Press Q to return to menu'
screen.blit(self.draw_msg(lost_msg), (self.size*2, self.size*3))
screen.blit(self.draw_msg(day_msg), (self.size*7, self.size*4))
screen.blit(self.draw_msg(restart_msg1), (self.size*4, self.size*5))
screen.blit(self.draw_msg(restart_msg2), (self.size*3, self.size*6))
开发者ID:erikjuhani,项目名称:thefortressheart,代码行数:25,代码来源:gui.py
示例6: draw
def draw(self,screen):
#draw listcontrol as white? box
#draw listitems as text, icons available
#current item as marked?
if self._background != None:
screen.blit(self._background,self._pos)
else:
draw.rect(screen, (205,202,255), Rect(self._pos,self._size))
if self._curindex != None and self._displayselection:
draw.rect(screen, (88,100,241), Rect( (self._pos[0] + 10), (self._pos[1]+6 + self._yOffset + (self._curindex * 18)),self._size[0]-20,20))
for y,item in enumerate(self._listitems[self._topDisplayItem: (self._topDisplayItem + self._itemsPerPage)]):
if type(item) is str:
item = [item]
for i,x in enumerate(self._columnstarts):
if i + 1 > len(self._columnstarts) - 1:
stop = self._size[0] - 10
else:
stop = self._columnstarts[i+1] - x - 10
tmp = item[i]
while self._fonten.size(tmp)[0] > stop:
tmp= tmp[0:-1]
tmpfont = self._fonten.render(tmp,True,(0,0,0))
screen.blit(tmpfont, (self._pos[0]+x, self._pos[1]+10 + self._yOffset + (y * 18)))
开发者ID:nojan1,项目名称:Caros,代码行数:28,代码来源:control.py
示例7: draw_graph_box_and_legend
def draw_graph_box_and_legend(self):
x_end = self.left_bottom_corner_of_graph[0] + self.graph_box_length
# y_end = self.left_bottom_corner_of_graph[1] - self.graph_box_length
color = (30,30,30)
draw.line(self.screen, color,
self.left_bottom_corner_of_graph,
(self.left_bottom_corner_of_graph[0] + self.graph_box_length,
self.left_bottom_corner_of_graph[1]))
draw.line(self.screen, color,
self.left_bottom_corner_of_graph,
(self.left_bottom_corner_of_graph[0],
self.left_bottom_corner_of_graph[1] - self.graph_box_length))
# legend
x = self.field_length+padding_graph
y = 10
if not compare_wv_counts:
rectsize = 15
for legend_item_name, (legend_item_color,_) in self.legend_items.items():
draw.rect(self.screen, Color(legend_item_color), [x,y, rectsize,rectsize])
x += rectsize + 10
x_size_text = self.draw_text(legend_item_name, x, y)
x += x_size_text + 20
elif compare_avg_qual_per_wv==1:
self.draw_text("Average quality per WV",x,y)
else:
self.draw_text("WV distribution",x,y)
开发者ID:Arnatar,项目名称:ideas-papo2014,代码行数:26,代码来源:draw.py
示例8: render
def render(self):
# ~ draw magnetradius
if self.magnetradius:
# ~ gfxdraw.aacircle(scr,self.centerx,self.centery,int(self.magnetradius),(150,130,110,int(self.magnetradius)))
m = image.load("img/magnetichalo.png")
m = transform.smoothscale(m, [int(self.magnetradius * 2)] * 2)
scr.blit(m, m.get_rect(center=self.center))
# ~ draw shieldbar
r = draw.rect(scr, (50, 50, 50), (10, 500, 380, 18), 1)
osdlayer.fill((100, 100, 200, self.shieldfxttl * 4 + 150), (10, 0, self.shield_ / self.shieldmax * 380, 18))
# scr.blit(self.SHIELDTEXT,self.SHIELDRECT)
# ~ draw lazerstate
r = draw.rect(scr, (50, 50, 50), (10, 520, 380, 18), 1)
osdlayer.blit(self.lazertempfx, (10, 20), (0, 0, DoubleLazer.temper / DoubleLazer.tempmax * 380, 18))
# scr.blit(self.LAZERTEXT,self.LAZERRECT)
# ~ draw bonusbar
self.settingbonus_.render()
self.loader1_.render()
# ~ draw shieldcircle
if self.shieldfxttl:
self.shieldcolor.a = int(4 * self.shieldfxttl)
gfxdraw.filled_circle(scr, self.centerx, self.centery, self.w, self.shieldcolor)
self.shieldfxttl -= 1
if self.foo:
self.foo -= 1
scr.blit(self.img2, ship)
return
# ~ draw ship
scr.blit(self.img, ship)
开发者ID:strin,项目名称:curriculum-deep-RL,代码行数:29,代码来源:ship.py
示例9: draw
def draw(self):
"""
Method called each frame to (re)draw the objects and UI
:return:
"""
if not self.overlay_drawn:
overlay = Surface((self.scaled_width, LEVEL_HEIGHT))
overlay.set_alpha(128)
overlay.fill((0, 0, 0))
self.overlay_drawn = True
self.screen.blit(overlay, (0, 0))
o_max_width = max([option.get_rect().width for option in self.menu_options])
width = o_max_width + MENU_PADDING[0] * 2
height = self.menu_options[0].get_rect().height + MENU_PADDING[1] * 2
x = self.scaled_width / 2 - width / 2
y = LEVEL_HEIGHT / 2 - (height * len(self.menu_options)) / 2
counter = 0
for option in self.menu_options:
if counter == self.menu_option:
used_color = MENU_COLORS[1]
else:
used_color = MENU_COLORS[0]
draw.rect(self.screen, used_color, (x, y + counter * height, width, height), 0)
option_x = x + MENU_PADDING[0] + (o_max_width - option.get_rect().width) / 2
self.screen.blit(option, (option_x, y + height * counter + MENU_PADDING[1]))
counter += 1
开发者ID:Kranek,项目名称:BlockBuster,代码行数:27,代码来源:GameStatePauseMenu.py
示例10: draw
def draw(self, surf):
if self.visible:
if not self.enabled:
suffix = '-disabled'
elif self.mousedown:
suffix = "-down"
elif self.mouseover:
suffix = "-over"
else:
suffix = "-normal"
if self.value:
prefix = "checked"
else:
prefix = "unchecked"
centerPoint = ((self.style)['spacing'] * 1 + (self.position)[0] +
(self.style)['checked-normal'].get_width(),
center(self.position, self.size, self.textsurf.get_size())[1])
image = (self.style)[prefix + suffix]
imagePoint = ((self.position)[0], center(self.position, self.size,
image.get_size())[1])
surf.blit(image, imagePoint)
surf.blit(self.textsurf, centerPoint, Rect((0, 0), self.size))
if (self.style)['border-width']:
draw.rect(surf, (self.style)['border-color'], self.rect,
(self.style)['border-width'])
开发者ID:EssEf,项目名称:Regnancy,代码行数:30,代码来源:gui.py
示例11: update
def update(self, plitki=[]):
if len(plitki) > 1:
for pl in plitki:
if self != pl:
if collide_rect(self, pl):
if self.rect.x < pl.rect.x:
self.rect.x -= 1
pl.rect.x += 1
elif self.rect.x > pl.rect.x:
self.rect.x += 1
pl.rect.x -= 1
if self.rect.y < pl.rect.y:
self.rect.y -= 1
pl.rect.y += 1
elif self.rect.y > pl.rect.y:
self.rect.y += 1
pl.rect.y -= 1
surf = get_surface()
if self.rect.x <= 0:
self.rect.x += 1
if self.rect.y <= 0:
self.rect.y += 1
if self.rect.x+self.rect.w >= surf.get_width():
self.rect.x -= 1
if self.rect.y+self.rect.h >= surf.get_height():
self.rect.y -= 1
if self.mouse_on_button():
self.image.fill((255-self.color[0], 255-self.color[1], 255-self.color[2]))
rect(self.image, (125, 125, 125), (0, 0, self.rect.width, self.rect.height), 1)
self.image.blit(self.font.render(self.text, 1, self.color), (3, 3))
else:
self.image.fill(self.color)
rect(self.image, (255, 255, 255), (0, 0, self.rect.width, self.rect.height), 1)
self.image.blit(self.font.render(self.text, 1, (255-self.color[0], 255-self.color[1], 255-self.color[2])), (3, 3))
开发者ID:LoganStalker,项目名称:second_season,代码行数:35,代码来源:Buttons.py
示例12: bar
def bar(self, surface, text, pos, w=300):
rect = Rect(pos, (w, 60))
draw.rect(surface, (0, 200, 200), rect)
sf = font.SysFont('blah', 60, bold=False, italic=False)
txt = sf.render(text, True, (0, 0, 0))
surface.blit(txt, rect.inflate(-10, -10))
开发者ID:keltoff,项目名称:Demiurge,代码行数:7,代码来源:screen.py
示例13: render
def render(self, component, entity, event):
rect = self.rect
position = entity.handle("get_position")
rect.center = position
surf = entity.mode.game.screen
draw.rect(surf, self.color, self.rect)
开发者ID:zerosalife,项目名称:bunnies-dont-surf,代码行数:7,代码来源:rect.py
示例14: activate
def activate(self):
xsize = 300
ysize = 70
bkg = Surface((xsize, ysize))
bkg.lock()
bkg.fill((128,128,128))
for i in range(1, 4):
draw.rect(bkg,(i*32,i*32,i*32),(4-i,4-i,xsize+(i-4)*2,ysize+(i-4)*2),3)
corner = (64,64,64)
bkg.set_at((0,0), corner)
bkg.set_at((xsize,0), corner)
bkg.set_at((xsize,ysize), corner)
bkg.set_at((0,ysize), corner)
bkg.unlock()
bkg.set_alpha(64)
self.bkg = bkg
if self.title != None:
banner = OutlineTextBanner(self.title, (200,200,200), 20)
self.title_image = banner.render()
self.title_image.set_alpha(96)
self.arrow = res.loadImage("wait_arrow.png", colorkey=1)
开发者ID:bitcraft,项目名称:lpc1,代码行数:27,代码来源:dialog.py
示例15: drawRects
def drawRects(self, surface):
"""
Draws the contours of the collision rect and the image rect.
Usefuf for debuging.
"""
_draw.rect(surface, (0, 0, 0), self.rect, 2)
_draw.rect(surface, (200, 50, 200), self.crect, 2)
开发者ID:giselher,项目名称:perpege,代码行数:7,代码来源:Object.py
示例16: show
def show(self, screen):
W, H = self.wc, self.hc
sx , sy = self.sx, self.sy
#Print background cells
for cell in self.cases:
screen.blit(cell.background.surf, cell.background.pos)
#Generates lines of walls
for y in range(self.h - 1):
for x in range(self.w - 1):
c = self.get_cell(x, y)
if c.gate[const.right]:
draw.line(screen, const.gray, (sx + ((x + 1) * W), (sy + (y * H))), (sx + ((x + 1) * W), sy + ((y+1) * H)), 3)
if c.gate[const.down]:
draw.line(screen, const.gray, ((sx + (x * W)), (sy + ((y+1) * H))), (sx + ((x + 1) * W), sy + ((y+1) * H)), 3)
x = self.w - 1
#Creates walls from buttom to top
for y in range(self.h - 1):
c = self.get_cell(x, y)
if c.gate[const.down]:
draw.line(screen, const.gray, ((sx + (x * W)), (sy + ((y+1) * H))), (sx + ((x + 1) * W), sy + ((y+1) * H)), 3)
y = self.h - 1
#Creates walls from left to right
for x in range(self.w - 1):
c = self.get_cell(x, y)
if c.gate[const.right]:
draw.line(screen, const.gray, (sx + ((x + 1) * W), (sy + (y * H))), (sx + ((x + 1) * W), sy + ((y+1) * H)), 3)
#Draws outline
draw.rect(screen, const.gray, (sx, sy, W * self.w, H * self.h), 3)
开发者ID:annie60,项目名称:Xilarius,代码行数:34,代码来源:Class.py
示例17: show
def show(self, screen):
W, H = self.wc, self.hc
sx , sy = self.sx, self.sy
for y in range(self.h - 1):
for x in range(self.w - 1):
c = self.get_cell(x, y)
if c.gate[const.right]:
draw.line(screen, const.black, (sx + ((x + 1) * W), (sy + (y * H))), (sx + ((x + 1) * W), sy + ((y+1) * H)), 2)
if c.gate[const.down]:
draw.line(screen, const.black, ((sx + (x * W)), (sy + ((y+1) * H))), (sx + ((x + 1) * W), sy + ((y+1) * H)), 2)
x = self.w - 1
for y in range(self.h - 1):
c = self.get_cell(x, y)
if c.gate[const.down]:
draw.line(screen, const.black, ((sx + (x * W)), (sy + ((y+1) * H))), (sx + ((x + 1) * W), sy + ((y+1) * H)), 2)
y = self.h - 1
for x in range(self.w - 1):
c = self.get_cell(x, y)
if c.gate[const.right]:
draw.line(screen, const.black, (sx + ((x + 1) * W), (sy + (y * H))), (sx + ((x + 1) * W), sy + ((y+1) * H)), 2)
draw.rect(screen, const.black, (sx, sy, W * self.w, H * self.h), 2)
开发者ID:tbourg,项目名称:perso,代码行数:32,代码来源:Classe.py
示例18: draw
def draw(self):
"""
Method called each frame to (re)draw UI
:return:
"""
self.screen.blit(Assets.background, (0, 0))
self.screen.blit(self.title, (LEVEL_WIDTH / 2 - self.title.get_rect().width / 2, 30))
o_max_width = max([option.get_rect().width for option in self.menu_options])
width = o_max_width + MENU_PADDING[0] * 2
height = self.menu_options[0].get_rect().height + MENU_PADDING[1] * 2
x = LEVEL_WIDTH / 2 - width / 2
y = LEVEL_HEIGHT / 2 - (height * len(self.menu_options)) / 2
counter = 0
for option in self.menu_options:
if counter == self.menu_option:
used_color = MENU_COLORS[1]
else:
used_color = MENU_COLORS[0]
draw.rect(self.screen, used_color, (x, y + counter * height, width, height), 0)
option_x = x + MENU_PADDING[0] + (o_max_width - option.get_rect().width) / 2
self.screen.blit(option, (option_x, y + height * counter + MENU_PADDING[1]))
counter += 1
authors_rect = self.authors.get_rect()
self.screen.blit(self.authors, (LEVEL_WIDTH - authors_rect.width,
LEVEL_HEIGHT - authors_rect.height))
开发者ID:Kranek,项目名称:BlockBuster,代码行数:27,代码来源:GameStateMenu.py
示例19: get_image
def get_image(self):
"""Draw the rectange on a transparent surface."""
img = Surface(self.rect.size).convert_alpha()
img.fill((0, 0, 0, 0), special_flags=pg.BLEND_RGBA_MULT)
draw.rect(img, self.model.color, img.get_rect(), 1)
img.fill((255, 255, 255, 128), special_flags=pg.BLEND_RGBA_MULT)
return img
开发者ID:YoannQDQ,项目名称:pyweek-dojo,代码行数:7,代码来源:view.py
示例20: refresh
def refresh(self):
#Reposition of the closebutton if visible
if self.closeable:
self.closebutton.visible = True
self.closebutton.position = (self.size[0] - self.style['offset'][0] - self.closebutton.size[0],
self.style['offset'][1])
else:
self.closebutton.visible = False
if self.shadeable:
self.shadebutton.visible = True
self.shadebutton.position = (self.size[0] - 2*(self.style['offset'][0] + self.shadebutton.size[0]),
self.style['offset'][1])
else:
self.shadebutton.visible = False
#If I don't have a surface or surface size is different from my size, i create a new one
temp='shaded-' if self.shaded else ''
if not self.surf or self.size != self.surf.get_size():
del self.surf
self.surf = pygame.Surface(self.size, pygame.SRCALPHA)
if self.style[temp+'bg-color']:
self.surf.fill(self.style[temp+'bg-color'])
if self.style['border-width']:
draw.rect(self.surf, self.style['border-color'], Rect((0,0), self.size), self.style['border-width'])
self.surf.blit(self.style['font'].render(self.text, True, self.style[temp+'font-color']), self.style['offset'])
开发者ID:danielz360,项目名称:Maya,代码行数:29,代码来源:gui.py
注:本文中的pygame.draw.rect函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论