Skip to content

Instantly share code, notes, and snippets.

@Exodus111
Created April 19, 2013 22:02
Show Gist options
  • Save Exodus111/5423533 to your computer and use it in GitHub Desktop.
Save Exodus111/5423533 to your computer and use it in GitHub Desktop.
New bolt class
class Bolt(pygame.sprite.DirtySprite):
def __init__(self, player):
self.player = player
self.image = pygame.image.load("bolt.png").convert_alpha()
self.rect = self.image.get_rect()
self.pos = vec2d(player.rect.center)
self.dirty = 1
self.lvl = 1
self.dmg = int((player.lvl * 0.5) + (self.lvl * 0.5) + 25)
self.speed = 25 + self.lvl
self.state = "Normal"
self.aoe = 0
def update(self, mobs, walls, dt):
self.rect.center = self.pos.inttup()
self.discharge(mobs)
for mob in mobs:
if self.rect.colliderect(mob)
self.state == "Dead"
self.dot(mob, dt)
self.knockback(mob)
self.aoe(mobs)
self.fear(mob, dt)
self.bounce()
for wall in walls:
if self.rect.colliderect(wall)
self.state == "Dead"
self.aoe(mobs)
self.bounce()
if self.state == "Dead":
self.kill()
def aoe(self, mobs):
if self.aoe_lvl > 0:
aoe_range = self.aoe_lvl * 50
dmg = self.aoe_lvl + 50
for mob in mobs:
if mob.pos - self.pos <= aoe_range:
mob.hp -= dmg
def bounce(self):
if self.bounce_lvl > 0:
if self.bounce_counter <= self.bounce_lvl:
self.state = "Firing"
self.pos.x *= -1
self.pos.y *= -1
self.bounce_counter += 1
def discharge(self, mobs):
if self.state == "Firing":
if self.discharge_lvl > 0:
discharge_range = self.discharge_lvl * 5
dmg = self.discharge_lvl + 5
for mob in mobs:
if mob.pos - self.pos <= discharge_range:
mob.hp -= dmg
def dot(self, mob, dt):
if self.dot_lvl > 0:
dot_dmg = self.dot_lvl + 10
mob.dotted(dot_dmg, dt)
def knockback(self, mob):
if self.knockback_lvl > 0:
shove = self.pos - mob.pos
distance = self.knockback_lvl * 32
mob.pos += distance
def fear(self, mob):
if self.fear_lvl > 0:
fear_timer = self.fear_ lvl + 3:
mob.feared(fear_timer, dt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment