def __init__(self): super(LadyBug, self).__init__(Vec2D(0, 0)) self._state_thrown = LadyBug.StateThrown2() self.spr_walk = animation.TimedAnimation( self.pos, data.load_image('ladybRwalk_anim.png'), 2, 2, 'loop') self.spr_eat = animation.TimedAnimation( self.pos, data.load_image('ladybugReat_anim.png'), 2, 2, 'loop') self.spr_idle = animation.TimedAnimation( self.pos, data.load_image('ladybugblink_anim.png'), 2, 2) self.spr_fly = animation.TimedAnimation( self.pos, data.load_image('ladybRfly_anim.png'), 2, 10, 'loop') self.spr_fly.play() if have_luck(0.5): self.pos.x = -5 self.vel.x = 0.08 else: self.pos.x = 800 + 5 self.vel.x = -0.1 self.vel.y = 0.008 self.pos.y = randint(150, 350) self._count += 1 self.spr = self.spr_fly self.rect = self.spr.rect self.size = self.rect.h / 2 self.eat_next_time = 0 self.spr.face = self.facing self._walk_target = 0 self.lawnsegments = [] self.steam = randint(400, 800) self.change_state(self._state_fly)
def __init__(self): super(Player, self).__init__((100, 355)) self.spr_carry = animation.TimedAnimation( self.pos, load_image('guywalkhands_animnew.png'), 4, 30, 'loop') self.spr_walk = animation.TimedAnimation( self.pos, load_image('guywalk_animnew.png'), 4, 5, 'loop') self.spr = self.spr_walk self.facing = 1 # 1: right -1: left d = sign(self.vel.x) if d: self.facing = d self.kdir = 0 self.rect = pygame.Rect(self.spr.rect) self.rect.inflate_ip(-self.rect.w / 2, -self.rect.h / 2) self._pickup = None self._pickup_time = 0.0 self.collider = None self.last_thrown = None self.build_up_power = False self.actionkey_walk_l = K_a self.actionkey_walk_r = K_d self.actionkey_pickup = K_s self.actionkey_throw = K_w self.side = -1 # left # crosshair img = pygame.Surface((3, 3)) img.fill((255, 0, 0)) self.crosshair = animation.FrameAnimation(self.pos.clone(), img)
def __init__(self): super(NPCharacter, self).__init__(Vec2D(SCREENWIDTH - 100, 355), self._state_think) self.app = states.TheStateManager.cur_state self.spr_walk = animation.TimedAnimation( self.pos, load_image('guy2walk_animnew.png'), 4, 5, 'loop') self.spr_carry = animation.TimedAnimation( self.pos, load_image('guy2walkhands_animnew.png'), 4, 30, 'loop') self.spr = self.spr_walk self.rect = pygame.Rect(self.spr.rect) self.rect.inflate_ip(-self.rect.w / 2, -self.rect.h / 2) self.pickupable = False self._st = StatsTracker() self._st_lasthealth = 0 self.facing = 1 self._pickup = None self._pickup_time = 0.0 self.build_up_power = False self.target = None self.targetkind = None self.carrypos = None self.carrykind = None self.flipwater = False i = pygame.Surface((3, 3)) i.fill((255, 0, 0)) self.crosshair = animation.FrameAnimation(self.pos.clone(), i)
def __init__(self, pos, *args, **kwargs): super(WateringCan, self).__init__(pos, *args, **kwargs) self.is_on = False img = load_image('watering_can.png') self.spr_normal = animation.TimedAnimation(self.pos, img, 1, 1) img = load_image('watering_can_dispensing.png') self.spr_dispensing = animation.TimedAnimation(self.pos, img, 1, 1) self.spr = self.spr_normal self.next_drop = 0 self.sound = load_sound('water.wav')
def __init__(self): super(Carterpilar, self).__init__() self._state_fly = self._state_eat self.spr_walk = animation.TimedAnimation( self.pos, data.load_image('legpalwalk_animsmall.png'), 2, 2, 'loop') self.spr_eat = animation.TimedAnimation( self.pos, data.load_image('legpaleat_animsmall.png'), 2, 2, 'loop') self.spr_idle = animation.TimedAnimation( self.pos, data.load_image('legpalwalk_animsmall.png'), 1, 1) self.spr_fly = self.spr_eat self.spr = self.spr_eat self.pos.x = randint(10, 800) self.change_state(self._state_thrown)
def __init__(self, *args, **kwargs): super(Mole, self).__init__(Vec2D(-20, random.randint(460, 480))) self.spr_walk_r = animation.TimedAnimation( self.pos, load_image('mole/walk_right.png'), 2, 6, 'loop') self.spr_walk_l = animation.TimedAnimation( self.pos, load_image('mole/walk_left.png'), 2, 6, 'loop') self.spr_walk_u = animation.TimedAnimation( self.pos, load_image('mole/walk_up.png'), 2, 6, 'loop') self.spr_walk_d = animation.TimedAnimation( self.pos, load_image('mole/walk_down.png'), 2, 6, 'loop') self.spr_pop_up = animation.TimedAnimation( self.pos, load_image('mole/pop_up.png'), 2, 1.5, 'loop') self.spr = self.spr_walk_r self.collided = [] self.rect = pygame.Rect(0, 0, self.spr.rect.w / 2, self.spr.rect.h / 2) self.change_state(self._state_walk_h)
def __init__(self, pos): super(LawnSegment, self).__init__(pos) # Setup sprites for state self.type = randint(1, 3) self.frames = [] for t in [ 'healthy%d.png', 'annoyed%d.png', 'hurt%d.png', 'damaged%d.png', 'dead%d.png' ]: self.frames.append( animation.FrameAnimation( self.pos, load_image('grass/' + (t % self.type)))) self.hurt_icon = animation.TimedAnimation( self.pos, load_image('grass/hurt_icon.png'), 10, 10, mode='once') self.heal_icon = animation.TimedAnimation( self.pos, load_image('grass/heal_icon.png'), 6, 10, mode='once') self.state = self.HEALTHY self.hitpoints = self.MAXHEALTH self.image = self.frames[self.state] self.rect = self.image.rect
def __init__(self, *args, **kwargs): super(Bird, self).__init__( Vec2D(random.randint(-BIRDSPAWNDIST, SCREENWIDTH + BIRDSPAWNDIST), random.randint(40, 320))) self.spr_fly_r = animation.TimedAnimation( self.pos, load_image('bird/right_fly.png'), 2, 3, 'loop') self.spr_fly_l = animation.TimedAnimation( self.pos, load_image('bird/left_fly.png'), 2, 3, 'loop') self.vel.y = 0 self.accel.y = 0 self.size = 20 # What's this? We already have randomization of the position # at the top of this function. #self.pos.y = randint(40, 320) if randint(0, 1): # self.pos.x = SCREENWIDTH + BIRDCLIPDIST self.vel.x = -BIRDFLYSPEED self.spr = self.spr_fly_l else: # self.pos.x = -BIRDCLIPDIST self.vel.x = BIRDFLYSPEED self.spr = self.spr_fly_r self.rect = pygame.Rect(0, 0, self.spr.rect.w / 2, self.spr.rect.h / 2) self.rect.center = self.pos self.spr.update(0, 0) self.spr.play() self.collided = [] self.change_state(self._state_fly) self.poop_spr = animation.TimedAnimation(self.pos, load_image('bird/poop.png'), 1, 1)
def __init__(self, pos): super(FlyObj, self).__init__(pos, self._state_thrown) s = rand.randint(20, 40) img = load_image('poop_anim.png') img = pygame.transform.smoothscale(img, (s, s)) self.spr = animation.TimedAnimation(self.pos, img, 2, 3, 'loop') self.rect = pygame.Rect(self.spr.rect) self.weight = s / 40. + 1.5 self.size = s self.pickupable = False self.accel.y = FALLSPEED self.accel.x = 0 self.vel = Vec2D(0, 0) self.lifetime = POOPLIFETIME # 10 sec img = load_image('poopground.png') img = pygame.transform.scale(img, (s, s)) self.ground_spr = animation.FrameAnimation(self.pos, img)