# bomb import random import pygame from pygame.locals import * import game, gfx from basespriteobj import * STARTIMAGE = 16 MAXIMAGE = 32 bombimages = [] def load_game_resources(): global bombimages for loop in range(0,64): filename = "bomb%02d.gif" % loop bombimages.append(gfx.load(filename)) class Bomb(Sprite): def __init__(self,actor): """create a new bomb, get initial dx and dy from player """ global bombimages Sprite.__init__(self) self.images = bombimages self.imagenum = STARTIMAGE self.maximage = MAXIMAGE self.image = self.images[self.imagenum] self.rect = self.image.get_rect() self.lastrect = self.rect self.friction = game.friction self.gravity = game.gravity self.dx = actor.dx self.dy = actor.dy # where to add the bomb # because we add at the end of a cycle, and have to erase-tick-draw... self.xoffset = actor.bomboffset[0] - self.dx self.yoffset = actor.bomboffset[1] + 0 self.x,self.y = list(actor.rect.topleft) self.x += self.xoffset self.y += self.yoffset self.rect.topleft = [self.x,self.y] # how many frames we wait until dying self.collidetimer = game.collision_timer # timer that governs when we switch images self.turntimer = -15 self.turninterval = game.bomb_turninterval self.exploding = 0 def tick(self, speedadjust): self.turntimer += 1 if (self.turntimer > 0 and self.turntimer % self.turninterval == 0 and self.dy != -self.gravity): self.imagenum += 1 if self.imagenum > self.maximage: self.imagenum = self.maximage self.image = self.images[self.imagenum] self.rect = self.image.get_rect() self.physics() self.x += self.dx self.y += self.dy if self.x < 0 - self.rect.width: self.dead = 1 if self.y > game.groundarena.bottom - self.rect.height: self.y = game.groundarena.bottom - self.rect.height self.dy = 0 self.collidetimer += -1 if self.collidetimer < 0: self.exploding = 1 self.rect.topleft = [self.x,self.y] def physics(self): self.dy = self.dy * self.friction self.dy = self.dy + self.gravity if self.dx < -game.groundspeed: self.dx = -game.groundspeed