# balloon name = 'balloon' type = 'gif' from baseairobj import * images = [] import random DY_CHANGE_INTERVAL = 20 DY = 0.2 WIND = -0.05 TOP = game.arena.top BOTTOM = game.arena.bottom IMAGE_CHANGE_INTERVAL = 30 MAX_BALLOONS = 5 BALLOON_SPEED = -1.5 * game.groundspeed def load_game_resources(): global image, name for index in xrange(0,4): images.append(gfx.load('%s%d.%s' % (name,index,type))) class Balloon(AirObj): # Class variables max = MAX_BALLOONS count = 0 xspeed = BALLOON_SPEED def __init__(self,x,y,dx,dy): global name,images self.images = images self.image = images[0] AirObj.__init__(self,name,self.image) self.x = x self.y = y self.rect.topleft = self.x,self.y self.dx = Balloon.xspeed sign = random.randrange(0,3) - 1 self.dy = DY * sign self.timer = 0 self.index = 0 self.lastimage = len(self.images) - 1 def tick(self, speedadjust): self.x += self.dx * speedadjust if self.x < 0 - self.rect.width: self.dead = 1 self.timer += 1 if self.timer % IMAGE_CHANGE_INTERVAL == 0: self.index += 1 if self.index > self.lastimage: self.index = self.lastimage self.image = self.images[self.index] if self.timer % DY_CHANGE_INTERVAL == 0: sign = random.randrange(0,3) - 1 self.dy += DY * sign self.y += self.dy * speedadjust if self.y < TOP - self.rect.height: self.dead = 1 if self.y > BOTTOM: self.y = BOTTOM self.dy = 0 self.dx += WIND if self.dx < Balloon.xspeed: self.dx = Balloon.xspeed self.rect.topleft = [self.x,self.y]