Example #1
0
 def calc_apex(self):
     if self.facing >= 0:
         dir = Vec2D(100.0, -160.0)
     else:
         dir = Vec2D(-100.0, -160.0)
     dir.normalize()
     vel = self._pickup_time * (dir / self._pickup.weight)
     pos = self._pickup.pos.clone()
     # FIXME: The acceleration (gravity) should be handled better.
     # The original solution broke when I made birds throwable, but
     # of course the new solution of hard coding the value here isn't much
     # better. I don't think the original solution is very sensible either
     # though, because at the time of throwing, the throwable item naturally
     # isn't moving and has no acceleration.
     #accel = self._pickup.accel.clone()
     accel = Vec2D(0, 0.0005)
     oldpos = pos
     #   dt = 1
     t = -vel.y / accel.y
     pos.x = pos.x + vel.x * t
     pos.y = pos.y + 0.5 * t * t * accel.y + vel.y * t
     #        while oldpos.y >= pos.y:
     #           oldpos = pos.clone()
     #          vel += dt * accel
     #         pos += dt * vel
     #        dt += 1
     self.crosshair.pos.values = pos
Example #2
0
 def update(_self, self, dt, t, *args, **kwargs):
     if have_luck(0.5):
         if have_luck(0.5):
             self.pos.values = Vec2D(-BIRDSPAWNDIST,
                                     random.randint(20, 300))
             self.vel.x = BIRDSPEED
         else:
             self.pos.values = Vec2D(SCREENWIDTH + BIRDSPAWNDIST,
                                     random.randint(20, 300))
             self.vel.x = -BIRDSPEED
         self.change_state(self._state_fly)
Example #3
0
 def enter_takeoff(self_, self):
     self.pos.y -= 15
     self.rect.center = self.pos
     self.spr = self.spr_fly
     self.spr.face = self.facing
     speed = -0.08 + randint(0, 20) * 0.001
     if self.pos.x > FENCEMIDDLE:
         self.vel.values = Vec2D(0, speed).rotated(randint(-5, 50))
     else:
         self.vel.values = Vec2D(0, speed).rotated(randint(-50, 5))
     self.steam = randint(500, 1000)
Example #4
0
    def throw(self):
        if self._pickup:
            if self.facing >= 0:
                dir = Vec2D(100.0, -160.0)
            else:
                dir = Vec2D(-100.0, -160.0)
            dir.normalize()
            self._pickup.vel.values = self._pickup_time * (dir /
                                                           self._pickup.weight)
            self._pickup.throw()
            self.calc_apex()
            self._pickup = None
            self._pickup_time = 0.0

            soundsystem.grunt()
Example #5
0
    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)
Example #6
0
    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)
Example #7
0
 def enter(_self, self):
     states.TheStateManager.cur_state.add_entity(
         Poop(self.pos + Vec2D(-20, 0) * self.facing))
     self.spr = self.poop_spr
     self.spr.face = self.facing
     self.enter_time = None
     self.rect.center = self.spr.rect.center
     soundsystem.poop()
Example #8
0
 def throw(self):
     if self._pickup:
         self.spr = self.spr_walk
         self.spr.face = self.facing
         if gamelib.DEBUG:
             print self._pickup, self._pickup.cur_state, self._pickup.pickupable
         if self.facing >= 0:
             dir = Vec2D(100.0, -160.0)
         else:
             dir = Vec2D(-100.0, -160.0)
         dir.normalize()
         self._pickup.vel.values = self._pickup_time * (dir /
                                                        self._pickup.weight)
         self._pickup.throw()  # just sets the state
         self.calc_apex()
         self.last_thrown = self._pickup
         self._pickup = None
         self._pickup_time = 0.0
Example #9
0
    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)
Example #10
0
 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)
Example #11
0
    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)
Example #12
0
class Bird(FlyObj):  #(StateMachine):
    CLIPDIST = 80
    SPAWNDIST = 10

    class StateIdle(StateMachine.State):
        def update(_self, self, dt, t, *args, **kwargs):
            if have_luck(0.5):
                if have_luck(0.5):
                    self.pos.values = Vec2D(-BIRDSPAWNDIST,
                                            random.randint(20, 300))
                    self.vel.x = BIRDSPEED
                else:
                    self.pos.values = Vec2D(SCREENWIDTH + BIRDSPAWNDIST,
                                            random.randint(20, 300))
                    self.vel.x = -BIRDSPEED
                self.change_state(self._state_fly)

    class StateFly(StateMachine.State):
        def enter(_self, self):
            if self.pos.y > 320:
                self.change_state(self._state_revive)

        def checkScreenClipping(_self, self):
            if self.pos.x < -BIRDCLIPDIST:
                self.vel.x *= -1.0
                self.pos.x += 10
                self.spr = self.spr_fly_r
            elif self.pos.x > SCREENWIDTH + BIRDCLIPDIST:
                self.vel.x *= -1.0
                self.pos.x -= 10
                self.spr = self.spr_fly_l

        def update(_self, self, dt, t, *args, **kwargs):
            super(StateMachine, self).update(dt, t)
            _self.checkScreenClipping(self)
            if self.pos.x > 10 and self.pos.x < SCREENWIDTH - 10:
                if have_luck(BIRDPOOPCHANCE) and (
                        self.pos.x < FENCELEFT - 40
                        or self.pos.x > FENCERIGHT + 40):
                    self.change_state(self._state_poop)

                elif have_luck(BIRDTURNCHANCE):
                    self.vel.x *= -1
                    if sign(self.vel.x) > 0:
                        self.spr = self.spr_fly_r
                    else:
                        self.spr = self.spr_fly_l
                    self.spr.play()
                if self.vel.y:
                    if have_luck(BIRDSTOPCHANCE) and self.pos.y < 350:
                        self.accel.y = 0
                        self.vel.y = 0
                    if self.pos.y < 0:
                        self.pos.y = 10
                        self.accel.y = 0
                        self.vel.y = 0
            self.spr.update(dt, t)
            self.rect.center = self.pos

        def render(_self, self, screen, dt, t, *args, **kwargs):
            self.spr.render(screen, dt, t)

        def collision_response(_self, self, other):

            if not isinstance(other, Bird):
                if isinstance(other, FlyObj) and self.pos.y < 350:
                    if gamelib.DEBUG:
                        print "------------------", other.cur_state
                    if isinstance(other.cur_state, FlyObj.StateThrown):
                        if gamelib.DEBUG:
                            print ")))))))))))))))))))) BIRD COLLISION ((((((((((((((((("
                        self.change_state(self._state_fall)

    class StateRevive(StateMachine.State):
        def enter(_self, self):
            self.vel.y = BIRDRISESPEED
            self.vel.x = BIRDFLYSPEED * self.facing
            self.pos.y = 390
            self.accel.y = 0
            self.target = randint(40, 320)

            self.rect.center = self.pos
            if self.facing == 1:
                self.spr = self.spr_fly_r
            else:
                self.spr = self.spr_fly_l
            self.spr.update(0, 0)
            self.spr.play()

        def update(_self, self, dt, t, *args, **kwargs):
            if gamelib.DEBUG: print self.vel.y
            super(StateMachine, self).update(dt, t)
            self.spr.update(dt, t)
            self.rect.center = self.pos

            if self.pos.y < self.target:
                self.change_state(self._state_fly)

        def render(_self, self, screen, dt, t, *args, **kwargs):
            self.spr.render(screen, dt, t)

    class StateThrown(StateMachine.State):
        def enter(_self, self):
            self.accel = Vec2D(0, FALLSPEED)  # because 0,0 is at the top
            self.pickupable = False

        def update(_self, self, dt, t, *args, **kwargs):
            if self.pos.x > FENCELEFT and self.pos.x < FENCERIGHT:
                if self.pos.y > FENCETOP:
                    self.vel.x *= FENCEBOUNCE  # bounce from fence
                    self.pos.x += self.vel.x * FENCESPEED
            super(StateMachine, self).update(dt, t)
            ground_limit = GROUNDLIMIT - (self.size / 2.0)
            if self.pos.y >= ground_limit:
                self.pos.y = ground_limit
                self.vel.y *= GROUNDBOUNCEY
                self.vel.x *= GROUNDBOUNCEX
                self.change_state(self._state_still)
            # Constrain to screen width
            self.pos.x = max(0, min(SCREENWIDTH, self.pos.x))
            self.spr.update(dt, t)
            self.spr.rect.center = self.pos
            self.rect.center = self.pos

        def render(self_, self, screen, dt, t):
            self.spr.render(screen, dt, t)

        def collision_response(_self, self, other):
            if isinstance(other, LawnSegment) and other not in self.collided:
                other.hurt(BIRDGRASSDAMAGE)
                self.collided.append(other)

    class StateFall(StateMachine.State):
        def enter(_self, self):
            self.spr.stop()
            self.rect.center = self.spr.rect.center
            self.vel.x = 0
            self.accel.y = FALLSPEED

        def update(_self, self, dt, t, *args, **kwargs):
            super(StateMachine, self).update(dt, t)
            ground_limit = GROUNDLIMIT - (self.size / 2.0)
            if self.pos.y >= ground_limit:
                self.pos.y = ground_limit
                self.accel.y = 0
                self.vel.y = 0
                if have_luck(BIRDREVIVECHANCE):
                    self.change_state(self._state_revive)
                else:
                    # changed from _state_still.
                    # makes birds unthrowable again
                    self.change_state(self._state_idle)
            self.spr.update(dt, t)
            self.rect.center = self.pos

        def collision_response(_self, self, other):
            if isinstance(other, LawnSegment) and other not in self.collided:
                other.hurt(BIRDGRASSDAMAGE)
                self.collided.append(other)

        def render(_self, self, screen, dt, t, *args, **kwargs):
            self.spr.render(screen, dt, t)

    class StatePoop(StateMachine.State):
        def update(_self, self, dt, t, *args, **kwargs):
            super(StateMachine, self).update(dt, t)
            if not self.enter_time:
                self.enter_time = t
            duration = 500.0
            if t - self.enter_time > duration:
                self.change_state(self._state_fly)
            self.spr.rect.center = self.pos

        def render(_self, self, screen, dt, t, *args, **kwargs):
            self.spr.render(screen, dt, t)

        def enter(_self, self):
            states.TheStateManager.cur_state.add_entity(
                Poop(self.pos + Vec2D(-20, 0) * self.facing))
            self.spr = self.poop_spr
            self.spr.face = self.facing
            self.enter_time = None
            self.rect.center = self.spr.rect.center
            soundsystem.poop()

        def leave(_self, self):
            if self.facing == 1:
                self.spr = self.spr_fly_r
            else:
                self.spr = self.spr_fly_l

    _state_fly = StateFly(Vec2D(20, 0))
    _state_idle = StateIdle()
    _state_fall = StateFall()
    _state_poop = StatePoop()
    _state_revive = StateRevive()
    _state_thrown = StateThrown()

    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)
Example #13
0
 def enter(_self, self):
     self.accel = Vec2D(0, FALLSPEED)  # because 0,0 is at the top
     self.pickupable = False
Example #14
0
 def __init__(self, pos=Vec2D(0, 0)):
     super(StateMachine.State, self).__init__(pos)