本文整理汇总了Python中pygame.Surface.get_width方法的典型用法代码示例。如果您正苦于以下问题:Python Surface.get_width方法的具体用法?Python Surface.get_width怎么用?Python Surface.get_width使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygame.Surface
的用法示例。
在下文中一共展示了Surface.get_width方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ingredient_count
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_width [as 别名]
def ingredient_count(self, items, money):
# sides are at 650 and 675
# /1200 /900
# 13/24 27/36
ingredient_block = Surface((self.game_engine.width * 11/24,
self.game_engine.height * 9/36))
ingredient_block.fill((255, 255, 255))
icon_size = int(ingredient_block.get_width() / (len(items) * 1.5))
icon_width = ingredient_block.get_width() / len(items)
j = icon_size / 3
render_top = 15 + icon_size
for name, count in items.items():
icon = image.load("images/icon-%s.gif" % name).convert()
icon = transform.scale(icon, (icon_size, icon_size))
ingredient_block.blit(icon, (j, 10))
# Put an item count under the icon.
ren = self.__font.render(str(count), True, (0, 0, 0))
fw, fh = ren.get_size()
render_left = j + (icon_size / 2) - (fw / 2)
ingredient_block.blit(ren, (render_left, render_top))
j += icon_width
ren = self.__font.render("Funds: %s" % format_money(money), True, (0, 0, 0))
fw, fh = ren.get_size()
render_left = ingredient_block.get_width() / 2 - fw / 2
render_top = (ingredient_block.get_height() - render_top) / 2 + render_top
ingredient_block.blit(ren, (render_left, render_top))
return ingredient_block
示例2: _drawbranch
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_width [as 别名]
def _drawbranch(self, indent, branch):
result = []
truths = []
boxoffset = 0
for key, name, expanded, value in branch:
space = self._font.render(' '*4*indent, False, (0,0,0))
title = self._font.render(name, True, (255,255,255))
if hasattr(value, '__iter__'):
arrow = self._exp if expanded else self._col
lines, suboffset, allsame = self._drawbranch(indent+1, value)
selected = allsame
boxoffset = max(boxoffset, suboffset)
else:
arrow = None
lines = []
selected = value
width = (space.get_width() +
(arrow.get_width() if arrow else 0) +
title.get_width())
height = title.get_height()
image = Surface((width, height), flags=SRCALPHA)
image.blit(space, (0,0))
if arrow:
loc = space.get_width(), 0
image.blit(arrow, loc)
buttons = [(Rect(loc, arrow.get_size()), 0,
self._arrowhandler(branch, key, not expanded))]
else:
buttons = []
image.blit(title, (image.get_width()-title.get_width(), 0))
if selected:
boxes = self._y, self._emp
actions = None, False
elif selected == False:
boxes = self._emp, self._n
actions = True, None
else:
boxes = self._emp, self._emp
actions = True, False
boxbuttons, boximage = self._drawboxes(branch, key,
*(boxes + actions))
buttons.extend(boxbuttons)
result.append((image, buttons, boximage))
if expanded:
result.extend(lines)
truths.append(selected)
boxoffset = max(boxoffset, image.get_width())
allsame = (True if all(truths) else
False if all([t == False for t in truths]) else
None)
return result, boxoffset, allsame
示例3: create_dialog
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_width [as 别名]
def create_dialog(self):
f = font.Font(font.get_default_font(), 30)
text = f.render(self.text, True, (255, 255, 255))
dialog = Surface((text.get_width() + 20, text.get_height() + 20))
self.stroke(dialog, (255, 0, 0))
dialog.blit(text, ((dialog.get_width() - text.get_width()) / 2, (dialog.get_height() - text.get_height()) / 2))
return dialog
示例4: make_background
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_width [as 别名]
def make_background(self,img_file,desktop_size):
in_img = image.load(img_file)
out_img = Surface(desktop_size)
for x in range((out_img.get_width() // in_img.get_width()) + 1):
for y in range((out_img.get_height() // in_img.get_height()) + 1):
out_img.blit(in_img, (in_img.get_width() * x, in_img.get_height() * y))
return out_img
示例5: make_background
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_width [as 别名]
def make_background(self, img_file, desktop_size):
in_img = image.load(img_file)
out_img = Surface(desktop_size)
out_img.fill((0, 0, 0))
left = (out_img.get_width() - in_img.get_width()) / 2
top = (out_img.get_height() - in_img.get_height()) / 2
out_img.blit(in_img, (left, top))
return out_img
示例6: InfoTab
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_width [as 别名]
class InfoTab():
def __init__(self):
self.surface_inside = Surface((295, 128)).convert()
self.surface = Surface((300, 130)).convert()
self.surface_inside.fill((255, 255, 255))
self.surface.fill((0, 0, 0))
self.font = font.Font(None, 15)
self.l_font = font.Font(None, 25)
def update(self, obj=None):
self.surface_inside.fill((255, 255, 255))
self.surface.fill((0, 0, 0))
if obj is not None:
self.surface_inside.blit(transform.scale(obj.image, (20, 20)), (5, 5))
self.surface_inside.blit(self.l_font.render(obj.name, 1, (0, 0, 0)), (30, 25-self.l_font.get_height()))
cost_str = "$"+str(obj.cost)
self.surface_inside.blit(self.l_font.render(cost_str, 1, (0, 255, 0)),
(self.surface_inside.get_width() - self.l_font.size(cost_str)[0] - 10, 5))
y_val = 30
for line in self.length_splitter(self.font, obj.description, self.surface_inside.get_width()-10):
self.surface_inside.blit(self.font.render(line, 1, (0, 0, 0)), (5, y_val))
y_val += self.font.size(line)[1]+5
self.surface.blit(self.surface_inside, (1, 1))
# Word-wrap function
@staticmethod
def length_splitter(font, text, max_length):
ret_list = []
explode = text.split()
t_str = ""
while len(explode) > 0:
if font.size(t_str + explode[0])[0] > max_length:
ret_list.append(t_str)
t_str = ""
else:
t_str += explode.pop(0) + " "
if len(explode) == 0:
ret_list.append(t_str)
return ret_list
示例7: IonField
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_width [as 别名]
class IonField(Sprite):
"""Sprite that draws a bunch of random horizontal lines inside a rectangle."""
def __init__(self, left, top, width, height, noise_width, noise_height, delay):
Sprite.__init__(self)
self.top = top
self.left = left
self.width = width
self.height = height
self.image = Surface((self.width, self.height))
self.rect = Rect(left, top, self.width, self.height)
self.rect = Rect(left, top, 0, 0)
self.mask = Mask((self.width, self.height))
self.mask.fill()
self.noise_width = noise_width
self.noise_height = noise_height
self.tick = 0
self.delay = delay
def update(self):
self.tick = self.tick + 1
if self.tick % self.delay == 0:
self.generate_noise()
def draw(self, screen):
screen.blit(self.image, self.rect)
def generate_noise(self):
for col in range(0, self.image.get_width(), self.noise_width):
for row in range(0, self.image.get_height(), self.noise_height):
c = choice(COLORS)
draw.rect(self.image, c, Rect(col, row, self.noise_width, self.noise_height))
示例8: draw
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_width [as 别名]
def draw(self, time, settings, screen : Surface, scale, bottomypos : float, cursoroffset = 0, currentxscroll = 0, drawcursorindex = None, nodraw = False):
# first draw wood
if not nodraw:
self.drawwood(time, settings, screen, scale, currentxscroll, bottomypos)
xspace = screen.get_width()/50
currentx = xspace
cursordrawpos = None
for i in range(cursoroffset, len(self.plants)):
currentpos = (currentx, bottomypos)
if not nodraw:
self.plants[i].draw(time, settings, screen, scale,
currentpos)
if drawcursorindex == i:
potpos = self.plants[i].pot_pos(currentpos, scale)
cursordrawpos = Rect(potpos[0]-xspace, potpos[1]-xspace,
xspace, xspace)
gfxdraw.box(screen, cursordrawpos, (211, 214, 64))
currentx += self.plants[i].plantwidth*scale + xspace
return cursordrawpos
示例9: randint
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_width [as 别名]
mdx = randint(-2048,2048)
mdy = randint(-2048,2048)
def spouses(x, y):
global mdx
global mdy
m = noise.snoise2((x+mdx),(y+mdy),1,1)
m = max(0, m)
return int(4*m) + 1
shownoise = '-shownoise' in [a.lower() for a in argv]
background = Surface(screen.get_size())
if shownoise:
background.lock()
for y in range(0, background.get_height()):
for x in range(0, background.get_width()):
background.set_at((x,y), grayvalue(noiseat(x,y)))
background.unlock()
else:
background.fill((255,255,255))
screen.blit(background, (0,0))
sprites = Group()
def personat(x,y):
return noiseat(x*8,y*8) <= 0.95
for x in range(0, background.get_width(), 8):
for y in range(0, background.get_height(), 8):
present = personat(x/8, y/8)
示例10: Surface
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_width [as 别名]
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),
示例11: TowerFrame
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_width [as 别名]
class TowerFrame():
""" Creates a frame full of information for the selected tower """
def __init__(self, tower, extra_attributes=None):
self.tower = tower
self.image = Surface((200, 300)).convert()
self.image.fill((200, 115, 0))
self.s_width = self.image.get_width()
self.s_height = self.image.get_height()
# Can't divide by 0
if self.tower.fire_rate == 0:
dps_calc = 0
else:
dps_calc = self.tower.damage/self.tower.fire_rate
tower_attributes = {"Name": self.tower.name,
"Fire Rate": self.tower.fire_rate,
"Damage": self.tower.damage,
"DPS": dps_calc,
"Damage Done": self.tower.damage_done}
if extra_attributes is None:
extra_attributes = dict()
self.t_attributes = dict(tower_attributes.items() + extra_attributes.items())
# Upgrades
self.font = font.Font(None, 18)
self.upgrade_button = Surface((100, 50)).convert()
self.upgrade_button.fill((0, 255, 0))
self.upgrade_button.blit(self.font.render("Upgrade", 1, (0, 0, 0)),
(self.upgrade_button.get_width()/2 - self.font.size("Upgrade")[0]/2,
self.upgrade_button.get_height()/2 - self.font.size("Upgrade")[1]/2))
self.image.blit(self.upgrade_button, (self.image.get_width() - self.upgrade_button.get_width(),
self.image.get_height() - self.upgrade_button.get_height()))
level_text = "Level: " + str(self.tower.level)
self.image.blit(self.font.render(level_text, 1, (0, 0, 0)),
(self.image.get_width() - self.upgrade_button.get_width(),
self.image.get_height() - self.upgrade_button.get_height() - self.font.size(level_text)[1]))
self.image.blit(self.tower.image, (self.s_width/2 - self.tower.image.get_width()/2, 2))
y_value = self.tower.image.get_width() + 7
# Blits the tower description
for desc in self.length_splitter(self.font, self.tower.description, self.image.get_width() - 5):
self.image.blit(self.font.render(desc, 1, (0, 0, 0)), (5, y_value))
y_value += self.font.get_height() + 1
y_value += 5
# Blits the tower's attributes in this order, tacking all extra stuff at the end
for attr in ["Name", "Fire Rate", "Damage", "DPS", "Damage Done"]+extra_attributes.keys():
value = self.t_attributes[attr]
self.image.blit(self.font.render(attr + ": " + str(value), 1, (0, 0, 0)), (5, y_value))
y_value += self.font.get_height() + 1
#self.image = OutlinedSurface(self.image, 5).surface
@staticmethod
# Used to split text up into lines that will fit the surface
def length_splitter(font, text, maxlength):
ret_list = []
explode = text.split()
t_str = ""
while len(explode) > 0:
if font.size(t_str + explode[0])[0] > maxlength:
ret_list.append(t_str)
t_str = ""
else:
t_str += explode.pop(0) + " "
if len(explode) == 0:
ret_list.append(t_str)
return ret_list
示例12: Gameboard
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_width [as 别名]
#.........这里部分代码省略.........
def draw(self):
self.gameSurface.fill((0,0,0))
#self.gameSurface.fill((217,62,245))
origin = (0, 0)
# this_scroll = 0
self.scroll_amount = 0
if self.last_frame_time > 0:
cur_time = self.default_timer()
self.gap_time = cur_time - self.last_frame_time
# print "Pixels per second: {0}\nGap Time: {1}\nScrollAmount: {2}".format(self.pixels_per_second, self.gap_time, this_scroll)
self.last_frame_time = cur_time
else:
self.gap_time = 0
self.last_frame_time = self.default_timer()
this_scroll = self.pixels_per_second * self.gap_time
self.frac_scroll += this_scroll
if self.frac_scroll >= 1:
self.scroll_amount = math.floor(self.frac_scroll)
self.pixel_offset += self.scroll_amount
# print "Now scrolling {0} pixel(s)".format(whole_part)
self.frac_scroll -= self.scroll_amount
if self.pixel_offset > 96:
self.pixel_offset = self.pixel_offset - 96
if self.pixel_offset < 0:
self.pixel_offset = 0
self.gameSurface.blit(self.mainScreenBackground, origin)
window_rect = Rect(self.pixel_offset, 0, self.gameSurface.get_width(), self.gameSurface.get_height())
# print window_rect
self.gameSurface.blit(self.backgroundSurface, origin, window_rect)
#All other drawing
self.bridge_group.update(self.scroll_amount)
self.bridge_group.draw(self.gameSurface)
self.mine_group.update(self.scroll_amount)
self.mine_group.draw(self.gameSurface)
self.enemy_group.update(self.scroll_amount)
self.enemy_group.draw(self.gameSurface)
self.samurai_sprite_group.update()
self.samurai_sprite_group.draw(self.gameSurface)
self.healthpack_group.update(self.scroll_amount)
self.healthpack_group.draw(self.gameSurface)
self.ki_potion_group.update(self.scroll_amount)
self.ki_potion_group.draw(self.gameSurface)
self.shield_group.update(self.scroll_amount)
self.shield_group.draw(self.gameSurface)
self.sword_group.update(self.scroll_amount)
self.sword_group.draw(self.gameSurface)
#self.testSword = VerticalSlash(400,400)
#self.attack_group.add(self.testSword)
self.attack_group.update()
self.attack_group.draw(self.gameSurface)
示例13: Shop
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_width [as 别名]
class Shop():
def __init__(self, name, inventory, price_mod, group_inventory,
group_money, item_prices, position, blit_position, money, resource_path):
self.yvalue = 40
self.group_inventory = group_inventory
self.group_money = group_money
self.price_mod = price_mod
self.item_prices = item_prices
self.inventory = inventory
self.position = position
self.blit_position = blit_position
self.resource_path = resource_path
self.buy_button_list = []
self.sell_button_list = []
# TODO: figure out what these magic numbers mean
self.x_pos = (-self.position * 40) + 1280
# Gui stuff #
# Main Window
self.shop_surface = Surface((500, 300)).convert()
# Separator Line
self.sep_line = Surface((self.shop_surface.get_width(), 10)).convert()
self.sep_line.fill((0, 0, 0))
# Inventory container box
self.inv_container = Surface((self.shop_surface.get_width()-20,
self.shop_surface.get_height()/2 - 35)).convert()
self.inv_container.fill((255, 255, 255))
# Font creation
self.title_font = font.Font(None, 30)
self.text_font = font.Font(None, 20)
# Random name generation
if name == "":
self.name = capitalize(choice(SHOP_NAME_PREFIX) + "'s " + choice(SHOP_NAME_SUFFIX))
else:
self.name = name
# Random inventory generation
if self.inventory == {}:
# TODO: The shop should have random items, not just what the group currently has
inventory_random = copy(self.group_inventory)
# Assign a random value between 1,10 to each inventory item
for key in list(inventory_random.keys()):
inventory_random[key] = randint(0, 10)
# Inflate food count
inventory_random["Food"] *= 20
self.inventory = inventory_random
# Random money generation
if money is None:
self.money = randint(200, 500)
else:
self.name = name
self.render()
# Used to get the surface created in self.render()
def get_surface(self):
self.render()
return self.shop_surface
# Updates the group_inv and group_money to blit in self.render
def update(self, group_inv, group_m):
self.group_inventory = group_inv
self.group_money = group_m
self.render()
def move(self, move_value):
self.x_pos += (2 * move_value)
self.render()
def render(self):
self.yvalue = 40
self.shop_surface.fill((133, 94, 66))
self.shop_surface.blit(self.title_font.render(self.name + " - $"+str(self.money), 1, (0, 0, 255)), (10, 5))
self.shop_surface.blit(self.inv_container, (10, 25))
self.shop_surface.blit(self.inv_container, (10, self.shop_surface.get_height()/2 + 30))
self.shop_surface.blit(self.text_font.render("Inventory", 1, (255, 0, 0)), (10, 25))
self.shop_surface.blit(self.text_font.render("Amount", 1, (255, 0, 0)), (130, 25))
self.shop_surface.blit(self.text_font.render("Price", 1, (255, 0, 0)), (200, 25))
#Blit the shop's inventory
for key in list(self.inventory.keys()):
self.shop_surface.blit(self.text_font.render(key+":", 1, (0, 0, 0)), (10, self.yvalue))
self.shop_surface.blit(self.text_font.render(str(self.inventory[key]), 1,
(0, 0, 0)), (150, self.yvalue))
self.shop_surface.blit(self.text_font.render("$"+str(self.item_prices[key]*self.price_mod), 1,
(0, 0, 0)), (200, self.yvalue))
if len(self.buy_button_list) < len(self.inventory.keys()):
button_pos = tuple(map(sum, zip(self.blit_position, (250, self.yvalue))))
self.buy_button_list.append(TransactionButton(transaction="buy",
item=key,
image_position=(250, self.yvalue),
rect_position=button_pos,
resource_path=self.resource_path))
self.yvalue += 30
# Shows each button
for button in self.buy_button_list:
#.........这里部分代码省略.........
示例14: Weapon
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_width [as 别名]
class Weapon(Item):
def __init__(self, game, name):
"""
Slightly depreciated weapon class. Will need major rewriting.
Used for loading and applying weapon characteristics to the player.
"""
self.game = game
#setup base vars of all weapon(s)
self.type = None
self.shown = True
self.range = 10
self.damage = 1
self.cooldown = 500 # in MS
self.speed = 4
self.projectile = None
self.loadWeapon(name)
# attack based vars
self.attacking = False
def loadWeapon(self, name):
"""
Uses the weapon config file to load all weapon characteristics.
"""
config_file = open(os.path.join('rec', 'weapon', name, 'config.py')).read()
exec(config_file)
self.hold_image = img_load(os.path.join('rec', 'weapon', name, 'hold.png')).convert_alpha()
if os.path.exists(os.path.join('rec', 'weapon', name, 'attack.png')):
self.attack_image = img_load(os.path.join('rec', 'weapon', name, 'attack.png')).convert_alpha()
else:
self.attack_image = Surface([1, 1])
def getSurface(self, name):
fi_name = name.lower().replace(' ', '_') + '.png'
return img_load(os.path.join(self.game.main_path, 'rec', 'weapon', name, fi_name))
def preUpdate(self, ttime):
"""
Called before the update function, can be overriden for new functionality.
"""
pass
def update(self, ttime):
"""
Main weapon update, should not be overriden.
"""
self.preUpdate(ttime)
if self.type == 'short':
self.shortUpdate()
elif self.type == 'long':
self.longUpdate()
elif self.type == 'ranged':
self.rangedUpdate()
else:
pass
def shortAttack(self):
self.attacking = True
if self.game.Player.player_face == 'front':
# I do not know why this vector needs to be 0 while the others are like, 1
self.directional_attack_image = rotate(self.attack_image, 180)
self.sub_vector = [0, 0]
elif self.game.Player.player_face == 'left':
self.directional_attack_image = rotate(self.attack_image, 90)
self.sub_vector = [-1, 0]
elif self.game.Player.player_face == 'back':
self.directional_attack_image = rotate(self.attack_image, 0)
self.sub_vector = [0, -1]
elif self.game.Player.player_face == 'right':
self.directional_attack_image = rotate(self.attack_image, 270)
self.sub_vector = [0.8, 0] # editing this seems to change the speed of the right dagger swing a bit
self.game.Player.can_move = False
self.receding = False
self.potent = True
self.weapon_rect = Rect(1, 1, 1, 1)
p_coords = [self.game.Player.player_r.x, self.game.Player.player_r.y]
a_coords = [p_coords[0] + self.game.Player.getRigging()[0], p_coords[1] + self.game.Player.getRigging()[1]]
if self.game.Player.player_face == 'right' or self.game.Player.player_face == 'left':
a_coords = [a_coords[0] - self.attack_image.get_height(), a_coords[1] - self.attack_image.get_width()]
self.blit_pos = a_coords
self.attack_ticks = self.range
def shortUpdate(self):
if self.attacking:
for repeats in xrange(self.speed):
self.game.Player.player_state = 3
self.blit_pos[0] += self.sub_vector[0]
self.blit_pos[1] += self.sub_vector[1]
if self.receding:
self.attack_ticks += 1
elif not self.receding:
self.attack_ticks -= 1
# check all monsters for touching weapon
for index, monster in enumerate(self.game.EntityHandler.monsters):
if monster.rect.colliderect(self.weapon_rect):
if self.potent:
monster.takeDamage(index, self.damage)
self.potent = False
#.........这里部分代码省略.........
示例15: Buffalo
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_width [as 别名]
class Buffalo():
def __init__(self, posX, posY, picture, size, resourcePath):
self.picture = picture
self.size = size
self.resourcePath = resourcePath
self.maxHealth = 100 * self.size
self.health = self.maxHealth
self.preimage = image.load(self.resourcePath + "img/" + self.picture + "_buffalo.png")
self.image = scale(self.preimage, (int(self.preimage.get_width() * self.size),
int(self.preimage.get_height() * self.size)))
self.healthFont = font.Font(None, 20)
self.healthBarContainer = Surface((int(75 * self.size), int(12 * self.size))).convert()
self.healthBarShader = Surface((self.healthBarContainer.get_width() + 6,
self.healthBarContainer.get_height() + 6)).convert()
self.healthNumber = self.healthFont.render(str(self.health), 1, (0, 0, 0))
self.healthBarShader.fill((175, 175, 175))
self.healthBar = Surface(self.healthBarContainer.get_size()).convert()
self.healthColour = ()
if (self.health >= 50):
self.healthColour = (float((self.maxHealth - self.health) * 2 / self.maxHealth * 255), 255, 0)
else:
self.healthColour = (255, float(self.health * 2 / self.maxHealth * 255), 0)
try:
self.healthBar.fill(self.healthColour)
except TypeError:
self.healthBar.fill((0, 0, 0))
self.healthBarContainer.blit(self.healthBar, (0, 0))
self.value = 20 * self.size
self.rect = Rect((0, 0), self.image.get_size())
self.rect.x = posX
self.rect.y = posY
self.status = "alive"
self.targetY = posY
def update(self):
self.preimage = image.load(self.resourcePath + "img/" + self.status + "_buffalo.png")
self.image = scale(self.preimage, (int(self.preimage.get_width() * self.size),
int(self.preimage.get_height() * self.size)))
self.healthBarContainer = Surface((int(75 * self.size), int(12 * self.size))).convert()
self.healthNumber = self.healthFont.render(str(int(self.health)), 1, (255, 255, 255))
self.healthBarShader = Surface((self.healthBarContainer.get_width() + 6,
self.healthBarContainer.get_height() + 6)).convert()
self.healthBarShader.fill((175, 175, 175))
if (self.health <= 0):
self.healthBar = Surface((0, 0)).convert()
else:
self.healthBar = Surface((int(self.healthBarContainer.get_width() / self.maxHealth * self.health),
self.healthBarContainer.get_height())).convert()
if (self.health >= 50):
self.healthColour = (float((self.maxHealth - self.health) * 2 / self.maxHealth * 255), 255, 0)
else:
self.healthColour = (255, float(self.health * 2 / self.maxHealth * 255), 0)
try:
self.healthBar.fill(self.healthColour)
except TypeError:
self.healthBar.fill((0, 0, 0))
self.healthBarContainer.blit(self.healthBar, (0, 0))
self.healthBarContainer.blit(self.healthNumber, (self.healthBarContainer.get_width() / 2 -
self.healthNumber.get_width() / 2,
self.healthBarContainer.get_height() / 2 -
self.healthNumber.get_height() / 2))
self.healthBarShader.blit(self.healthBarContainer, (3, 3))
if (self.status == "alive"):
self.rect.x += float(3 - self.size)
if (self.rect.y != self.targetY):
if (self.rect.y < self.targetY):
self.rect.y += float(3 - self.size)
elif (self.rect.y > self.targetY):
self.rect.y -= float(3 - self.size)
return self.rect.center