# storage tank 1 import random import pygame from pygame.locals import * import game, gfx from basespriteobj import Sprite blastimages = [] def load_game_resources(): global blastimages for loop in range(0,4): blastimages.append(gfx.load('blast%d.gif'%loop)) class Blast(Sprite): def __init__(self,actor): global blastimages Sprite.__init__(self) self.imagenum = 0 self.maximages = len(blastimages) self.image = blastimages[0] self.rect = self.image.get_rect() self.lastrect = self.rect self.dx = actor.blastspeed self.dy = 0 # where to start firing. # because we add at the end of a cycle, and have to erase-tick-draw... self.xoffset = actor.blastoffset[0] - self.dx self.yoffset = actor.blastoffset[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] self.timer = 0 self.lengthdelay = game.blast_length_delay def tick(self, speedadjust): self.x += self.dx self.y += self.dy if self.x > game.arena.right + self.rect.width or self.x < game.arena.left - self.rect.width: self.dead = 1 elif self.y > game.arena.bottom + self.rect.height or self.y < game.arena.top - self.rect.height : self.dead = 1 self.rect.topleft = [self.x,self.y] # make the laser blast longer by switching images if self.imagenum < self.maximages: self.timer = (self.timer + 1) % self.lengthdelay #print "blast timer: %d" % self.timer if self.timer == 0: #print "blast imagenum: %d self.maximages:%d" % (self.imagenum,self.maximages) if self.imagenum < self.maximages-1: #print "changing blast image" self.imagenum += 1 self.image = blastimages[self.imagenum] self.rect = self.image.get_rect() self.rect.topleft = [self.x,self.y] def playercollide(self, rect): return 0