# plane 1 name = 'plane1' type = 'gif' import random from baseairobj import * from objballoon import Balloon image = None BALLOON_INTERVAL = 50 DX_CHANGE_INTERVAL = 100 DY_CHANGE_INTERVAL = 50 XTHRUST = 0.01 YTHRUST = 0.01 MAX_DX = 1.5 MIN_DX = -MAX_DX MAX_DY = 1.5 MIN_DY = -MAX_DY CHANGE_ACCEL_CHANCE = 0.01 TOP = game.arena.top BOTTOM = game.arena.bottom-40 LEFT = game.arena.left RIGHT = game.arena.right def load_game_resources(): global image, name image = gfx.load('%s.%s' % (name,type)) class Plane1(AirObj): # class variables max = 4 count = 0 def __init__(self, airobjs): global name,image AirObj.__init__(self,name,image) # where to add the balloons self.airobjs = airobjs self.dx = -1 * game.groundspeed * random.uniform(0.5,1.0) self.thrust_change_point = game.arena.width * random.uniform(0.3,1.0) self.xthrust = XTHRUST self.ythrust = (random.randrange(0,3) - 1) * YTHRUST * random.random() self.timer = 0 def tick(self, speedadjust): self.x += self.dx * speedadjust if self.x < game.arena.left - self.rect.width: self.dead = 1 elif self.x > game.arena.right + 2 * self.rect.width : self.dead = 1 self.timer += 1 if self.timer % DY_CHANGE_INTERVAL == 0: sign = random.randrange(0,3) - 1 self.ythrust = YTHRUST * sign if self.timer % DX_CHANGE_INTERVAL == 0: if random.random() < CHANGE_ACCEL_CHANCE: self.xthrust = 2 * XTHRUST # no thrust until we pass the change point if self.x < self.thrust_change_point: self.thrust_change_point = 10000 self.dx += self.xthrust if self.x < game.arena.right + self.rect.width: self.xthrust = self.xthrust self.dy += self.ythrust if self.dy > MAX_DY: self.dy = MAX_DY elif self.dy < MIN_DY: self.dy = MIN_DY if self.dx > MAX_DX: self.dx = MAX_DX elif self.dx < MIN_DX: self.dx = MIN_DX self.y += self.dy * speedadjust if self.y > BOTTOM: self.y = BOTTOM self.dy = 0 self.ythrust = -YTHRUST self.x += self.dx * speedadjust self.rect.topleft = [self.x,self.y] # add balloons if self.timer % BALLOON_INTERVAL == 0: if self.dx > -game.groundspeed/2: if Balloon.count <= Balloon.max: self.airobjs.append(Balloon(self.x-5,self.y+5,self.dx,self.dy))