# rocket launcher name = 'rocketlauncher' type = 'gif' from basegroundobj import * import objrocket ROCKET_OFFSET_X = 19 ROCKET_OFFSET_Y = 23 LAUNCH_PERCENT = -0.3 DEATH_POINT = -game.arena.width * 0.25 MOVE_INTERVAL = 10 # ticks images = [] def load_game_resources(): global image, name for loop in range(0,6): images.append(gfx.load('%s%d.%s' % (name,loop,type))) class RocketLauncher(GroundObj): """launch_percent = -1.0 to 1.0 - distance to player before rocket launches. distance is expressed as % of screen width, negative means past player, positive means before player """ # Class variables max = 3 count = 0 def __init__(self,airobjectlist,exhaustobj,launch_percent=LAUNCH_PERCENT, *extra_rocket_params): global name,images self.images = images self.imagenum = 0 self.numimages = len(self.images) GroundObj.__init__(self,name,self.images[self.imagenum]) self.airobjectlist = airobjectlist self.exhaustobj = exhaustobj self.rocket_offset_x = ROCKET_OFFSET_X self.rocket_offset_y = ROCKET_OFFSET_Y self.launch_dist = game.arena.width * launch_percent self.death_point = DEATH_POINT #print "extra rocket params:",extra_rocket_params self.extra_rocket_params = extra_rocket_params self.timer = 0 self.launched = 0 def tick(self, speedadjust): self.x += self.dx * speedadjust if self.x < self.death_point: self.dead = 1 self.rect.topleft = [self.x,self.y] self.target() if self.launched == 0: if self.target() == 1: self.timer += 1 if self.timer % MOVE_INTERVAL == 0: self.imagenum += 1 if self.imagenum >= self.numimages-1: self.imagenum = self.numimages-1 self.launch() self.image = self.images[self.imagenum] def target(self): if (self.launched == 0) and (game.player.dead == 0): if (((self.launch_dist >= 0) and (self.x > game.player.x) and (abs(self.x - game.player.x) <= abs(self.launch_dist))) or ((self.launch_dist < 0) and (self.x < game.player.x) and (abs(self.x - game.player.x) > abs(self.launch_dist)))): return 1 else: return 0 def launch(self): self.launched = 1 self.pointvalue = 5 self.airobjectlist.append(apply(objrocket.Rocket, (self.x+self.rocket_offset_x,self.y+self.rocket_offset_y, self.exhaustobj) + self.extra_rocket_params))