all repos — Legends-RPG @ a03054accb71fa89eadb61df1441c401d572085e

A fantasy mini-RPG built with Python and Pygame.

Added fade out effect for damage points.
Justin Armstrong justinmeister@gmail.com
Wed, 30 Apr 2014 11:34:59 -0700
commit

a03054accb71fa89eadb61df1441c401d572085e

parent

5d4d09e8ded491a659f167c2e96f001b5a78037e

2 files changed, 31 insertions(+), 9 deletions(-)

jump to
M data/components/attackitems.pydata/components/attackitems.py

@@ -61,12 +61,17 @@ """

def __init__(self, damage, topleft_pos): super(DamagePoints, self).__init__() self.font = pg.font.Font(setup.FONTS[c.MAIN_FONT], 27) - self.image = self.make_surface(damage) - self.rect = self.image.get_rect(x=topleft_pos[0]+20, - bottom=topleft_pos[1]+10) + self.text_image = self.make_surface(damage) + self.rect = self.text_image.get_rect(x=topleft_pos[0]+20, + bottom=topleft_pos[1]+10) + self.image = pg.Surface(self.rect.size).convert() + self.image.set_colorkey(c.BLACK) + self.alpha = 255 + self.image.set_alpha(self.alpha) + self.image.blit(self.text_image, (0, 0)) self.start_posy = self.rect.y self.y_vel = -1 - self.dead = False + self.fade_out = False def make_surface(self, damage): """

@@ -74,17 +79,34 @@ Make the surface for the sprite.

""" if damage > 0: text = "-{}".format(str(damage)) - return self.font.render(text, True, c.RED) + surface = self.font.render(text, True, c.RED) + return surface else: - return self.font.render('Miss', True, c.WHITE) + return self.font.render('Miss', True, c.WHITE).convert_alpha() def update(self): """ Update sprite position or delete if necessary. """ + self.fade_animation() self.rect.y += self.y_vel - if self.rect.y < (self.start_posy - 50): - self.kill() + if self.rect.y < (self.start_posy - 29): + self.fade_out = True + + def fade_animation(self): + """ + Fade score in and out. + """ + if self.fade_out: + self.image = pg.Surface(self.rect.size).convert() + self.image.set_colorkey(c.BLACK) + self.image.set_alpha(self.alpha) + self.image.blit(self.text_image, (0, 0)) + self.alpha -= 15 + if self.alpha <= 0: + self.kill() + +
M data/components/person.pydata/components/person.py

@@ -427,7 +427,7 @@ damage_image.fill((255, 0, 0, self.damage_alpha), special_flags=pg.BLEND_RGBA_MULT)

self.image.blit(damage_image, (0, 0)) if self.fade_in: self.damage_alpha += 25 - if self.damage_alpha >= 255: + if self.damage_alpha >= 255.0: self.fade_in = False self.damage_alpha = 255 elif not self.fade_in: