def loop(g, s):
    sprite.apply_gravity(g, s)
    sprite.apply_standing(g, s)

    #if s._prev != None:
    #if s.rect.x == s._prev.x or sprite.get_code(g,s,sign(s.vx),0) == CODE_BROBO_TURN:
    if sprite.get_code(g, s, sign(s.vx), 0) == CODE_BROBO_TURN:
        s.vx = -s.vx

    s._prev = pygame.Rect(s.rect)

    if s.vx > 0:
        s.facing = 'right'
    elif s.vx < 0:
        s.facing = 'left'
    s.image = 'brobo-%s-%s' % (s.facing, (g.frame / 10) % 2)

    #if s.shoot == 0:
    #    shot = laser.init(g,s.rect,s)
    #    g.sprites.append(shot)
    #    s.shoot = 60

    #s.shoot -= 1

    s.rect.x += sprite.myinc(g.frame, s.vx)
    s.rect.y += sprite.myinc(g.frame, s.vy)
Beispiel #2
0
def loop(g,s):
    sprite.apply_gravity(g,s)
    sprite.apply_standing(g,s)
    
    #if s._prev != None:
        #if s.rect.x == s._prev.x or sprite.get_code(g,s,sign(s.vx),0) == CODE_BROBO_TURN:
    if sprite.get_code(g,s,sign(s.vx),0) == CODE_BROBO_TURN:
            s.vx = -s.vx

    s._prev = pygame.Rect(s.rect)

    if s.vx > 0:
        s.facing = 'right'
    elif s.vx < 0:
        s.facing = 'left'
    s.image = 'brobo-%s-%s' % (s.facing, (g.frame/10)%2)

    
    #if s.shoot == 0:
    #    shot = laser.init(g,s.rect,s)
    #    g.sprites.append(shot)
    #    s.shoot = 60

    #s.shoot -= 1
    
    s.rect.x += sprite.myinc(g.frame,s.vx)
    s.rect.y += sprite.myinc(g.frame,s.vy)
Beispiel #3
0
def loop(g,s):
    sprite.apply_gravity(g,s)
    sprite.apply_standing(g,s)
    
    #if s.rect.x == s._prev.x:
    #    s.vx = -s.vx
    #s._prev = pygame.Rect(s.rect)

    if g.player.rect.centerx > s.rect.centerx:
        s.vx += 0.05
    elif g.player.rect.centerx < s.rect.centerx:
        s.vx -= 0.05

    if s.vx > 0.0:
        s.image = 'robo-right'
    elif s.vx < 0.0:
        s.image = 'robo-left'

    if sprite.get_code(g,s,sign(s.vx),0) == CODE_ROBO_TURN:
        s.vx = 0.0

    s.vx = min(2.0, s.vx)
    s.vx = max(-2.0, s.vx)

    s.rect.x += sprite.myinc(g.frame, s.vx)
    s.rect.y += sprite.myinc(g.frame, s.vy)
Beispiel #4
0
def loop(g, s):
    sprite.apply_gravity(g, s)
    sprite.apply_standing(g, s)

    # if s.rect.x == s._prev.x:
    #    s.vx = -s.vx
    # s._prev = pygame.Rect(s.rect)

    if g.player.rect.centerx > s.rect.centerx:
        s.vx += 0.05
    elif g.player.rect.centerx < s.rect.centerx:
        s.vx -= 0.05

    if s.vx > 0.0:
        s.image = 'robo-right'
    elif s.vx < 0.0:
        s.image = 'robo-left'

    if sprite.get_code(g, s, sign(s.vx), 0) == CODE_ROBO_TURN:
        s.vx = 0.0

    s.vx = min(2.0, s.vx)
    s.vx = max(-2.0, s.vx)

    s.rect.x += sprite.myinc(g.frame, s.vx)
    s.rect.y += sprite.myinc(g.frame, s.vy)
Beispiel #5
0
 def loop(self):
     self.vx *= 0.98
     self.vy *= 0.98
     self.rect.x += sprite.myinc(self.game.frame, self.vx)
     self.rect.y += sprite.myinc(self.game.frame, self.vy)
     self.frame += 1
     if self.frame >= FPS * 2:
         self.active = False
         if random.randint(0, 3) == 1:
             self.game.game.sfx['pop'].play()
Beispiel #6
0
def bub_loop(g, s):
    s.vx *= 0.98
    s.vy *= 0.98
    s.rect.x += sprite.myinc(g.frame, s.vx)
    s.rect.y += sprite.myinc(g.frame, s.vy)
    s.frame += 1
    if s.frame >= FPS * 2:
        s.active = False
        if random.randint(0, 3) == 1:
            g.game.sfx['pop'].play()
Beispiel #7
0
def bub_loop(g,s):
    s.vx *= 0.98
    s.vy *= 0.98
    s.rect.x += sprite.myinc(g.frame,s.vx)
    s.rect.y += sprite.myinc(g.frame,s.vy)
    s.frame += 1
    if s.frame >= FPS*2:
        s.active = False
        if random.randint(0,3) == 1:
            g.game.sfx['pop'].play()
Beispiel #8
0
def loop(g, s):
    if s.dying != None:
        s.image = 'boss/%s-%d' % (s.facing, (g.frame / (FPS / 8)) % 8)
        if s.dying % 15 == 0:
            g.game.sfx['boss_explode'].play()
        if s.dying % 15 > 10:
            s.image = 'boss/%s-damage-%d' % (s.facing,
                                             (g.frame / (FPS / 8)) % 8)
        s.dying += 1
        #if s.dead:
        #    s.active = False
        if s.dying > 450:
            s.dead = True
            #s.active = False
        #if s.dying % 30 == 15:
        return

    #sprite.apply_gravity(g,s)

    #if s._prev != None:
    #if s.rect.x == s._prev.x or sprite.get_code(g,s,sign(s.vx),0) == CODE_PARROT_TURN:
    if sprite.get_code(g, s, sign(s.vx), 0) == CODE_BOSS_TURN:
        s.vx = -s.vx
    #s._prev = pygame.Rect(s.rect)

    if s.phase == 2:
        if s.phase_frames == 240 + 32:
            s.vy = 0
            s.vx = 1.2

    if s.vx > 0: s.facing = 'right'
    else: s.facing = 'left'

    s.rect.x += sprite.myinc(g.frame, s.vx)
    s.rect.y += sprite.myinc(g.frame, s.vy)

    s.image = 'boss/%s-%d' % (s.facing, (g.frame / (FPS / 8)) % 8)
    if s.taking_damage > 0:
        if s.taking_damage % 20 > 10:
            s.image = 'boss/%s-damage-%d' % (s.facing,
                                             (g.frame / (FPS / 8)) % 8)
        s.taking_damage -= 1

    s.phase_frames += 1

    if s.drop == 0:
        if s.vy == 0:  # this is to prevent the boss from bombing you when it's
            # flying up to the second phase
            sprites.fireball.init(g, s.rect, s)
        if s.phase == 1:
            s.drop = 120
        if s.phase == 2:
            s.drop = 90
    s.drop -= 1
Beispiel #9
0
def loop(g,s):
    if s.dying != None:
        s.image = 'boss/%s-%d'%(s.facing,(g.frame/(FPS/8))%8)
        if s.dying % 15 == 0:
            g.game.sfx['boss_explode'].play()
        if s.dying % 15 > 10:
            s.image = 'boss/%s-damage-%d'%(s.facing,(g.frame/(FPS/8))%8)
        s.dying += 1
        #if s.dead:
        #    s.active = False
        if s.dying > 450:
            s.dead = True
            #s.active = False
        #if s.dying % 30 == 15:
        return
            
    #sprite.apply_gravity(g,s)
    
    #if s._prev != None:
        #if s.rect.x == s._prev.x or sprite.get_code(g,s,sign(s.vx),0) == CODE_PARROT_TURN:
    if sprite.get_code(g,s,sign(s.vx),0) == CODE_BOSS_TURN:
        s.vx = -s.vx
    #s._prev = pygame.Rect(s.rect)

    if s.phase == 2:
        if s.phase_frames == 240 + 32:
            s.vy = 0
            s.vx = 1.2

    if s.vx > 0: s.facing = 'right'
    else:        s.facing = 'left'

    s.rect.x += sprite.myinc(g.frame, s.vx)
    s.rect.y += sprite.myinc(g.frame, s.vy)
    
    s.image = 'boss/%s-%d'%(s.facing,(g.frame/(FPS/8))%8)
    if s.taking_damage > 0:
        if s.taking_damage % 20 > 10:
            s.image = 'boss/%s-damage-%d'%(s.facing,(g.frame/(FPS/8))%8)
        s.taking_damage -= 1

    s.phase_frames += 1

    if s.drop == 0:
        if s.vy == 0: # this is to prevent the boss from bombing you when it's
                      # flying up to the second phase
            sprites.fireball.init(g,s.rect,s)
        if s.phase == 1:
            s.drop = 120
        if s.phase == 2:
            s.drop = 90
    s.drop -= 1
Beispiel #10
0
def loop(g, s):
    # sprite.apply_gravity(g,s)
    sprite.apply_standing(g, s)

    # if s.rect.x == s._prev.x: # or sprite.get_code(g,s,sign(s.vx),0) == CODE_TOWER_TURN:
    #	s.vx = -s.vx

    s._prev = pygame.Rect(s.rect)

    if g.player.rect.centerx > s.rect.centerx:
        s.vx += 0
    elif g.player.rect.centerx < s.rect.centerx:
        s.vx -= 0

    if s.vx > 0.0:
        s.facing = 'right'
    elif s.vx < 0.0:
        s.facing = 'left'
    if s.shooting == 0:
        s.image = 'tower/tower-%s' % (s.facing)

    # if sprite.get_code(g,s,sign(s.vx),0) == CODE_TOWER_TURN:
    #	s.vx = 0.0

    s.vx = min(1.0, s.vx)
    s.vx = max(-1.0, s.vx)

    if s.shoot == 0:
        # g.sprites.append(shot)
        s.shoot = 120
        s.shooting = 18

    if s.shooting > 0:
        if s.shooting == 18:
            s.image = 'tower/tower-%s-shoot-0' % (s.facing
                                                  )  # , (g.frame / 50) % 2)
            shot = towershoot.init(g, s.rect, s)
        if s.shooting == 9:
            s.image = 'tower/tower-%s-shoot-0' % (s.facing
                                                  )  # , (g.frame / 50) % 2)

        s.shooting -= 1

    s.shoot -= 1

    s.rect.x += sprite.myinc(g.frame, s.vx)
    s.rect.y += sprite.myinc(g.frame, s.vy)
Beispiel #11
0
def loop(g, s):
    sprite.apply_gravity(g, s)
    sprite.apply_standing(g, s)

    if s.bounces > 0 and s.standing:
        sprite.stop_standing(g, s)
        s.vy = -s.bounces * 0.75
        s.bounces -= 1
        if s.bounces == 0:
            s.vx = 0

    s.rect.x += sprite.myinc(g.frame, s.vx)
    s.rect.y += sprite.myinc(g.frame, s.vy)

    s.life -= 1
    if s.life == 0:
        s.active = False
Beispiel #12
0
    def loop(self):
        self.sprite.apply_gravity()
        self.sprite.apply_standing()

        if self.bounces > 0 and self.standing:
            self.stop_standing()
            self.vy = -self.bounces * 0.75
            self.bounces -= 1
            if self.bounces == 0:
                self.vx = 0

        self.rect.x += sprite.myinc(self.game.frame, self.vx)
        self.rect.y += sprite.myinc(self.game.frame, self.vy)

        self.life -= 1
        if self.life == 0:
            self.active = False
Beispiel #13
0
def loop(g, s):
    # sprite.apply_gravity(g,s)
    sprite.apply_standing(g, s)

    # if s.rect.x == s._prev.x: # or sprite.get_code(g,s,sign(s.vx),0) == CODE_DRACO_TURN:
    #	s.vx = -s.vx

    s._prev = pygame.Rect(s.rect)

    if g.player.rect.centerx > s.rect.centerx:
        s.vx += 0
    elif g.player.rect.centerx < s.rect.centerx:
        s.vx -= 0

    if s.vx > 0.0:
        s.facing = 'right'
    elif s.vx < 0.0:
        s.facing = 'left'
    if s.shooting == 0:
        s.image = 'draco/draco-%s' % (s.facing)

    # if sprite.get_code(g,s,sign(s.vx),0) == CODE_DRACO_TURN:
    #	s.vx = 0.0

    s.vx = min(1.0, s.vx)
    s.vx = max(-1.0, s.vx)

    if s.shoot == 0:
        # g.sprites.append(shot)
        s.shoot = 200
        s.shooting = 18

    if s.shooting > 0:
        if s.shooting == 18:
            s.image = 'draco/draco-%s-shoot-0' % (s.facing)  # , (g.frame / 50) % 2)
            shot = dracoshoot.init(g, s.rect, s)
        if s.shooting == 9:
            s.image = 'draco/draco-%s-shoot-1' % (s.facing)  # , (g.frame / 50) % 2)

        s.shooting -= 1

    s.shoot -= 1

    s.rect.x += sprite.myinc(g.frame, s.vx)
    s.rect.y += sprite.myinc(g.frame, s.vy)
Beispiel #14
0
def loop(g, s):
    sprite.apply_gravity(g, s)
    sprite.apply_standing(g, s)

    # if s.rect.x == s._prev.x:
    # s.vx = -s.vx
    # s._prev = pygame.Rect(s.rect)

    s.rect.x += s.vx
    s.rect.y += sprite.myinc(g.frame, s.vy)
Beispiel #15
0
    def loop(self):
        self.apply_gravity()
        self.apply_standing()

        if self.rect.x == self._prev.x:
            self.vx = - self.vx
            self._prev = pygame.Rect(self.rect)

        self.rect.x += self.vx
        self.rect.y += sprite.myinc(self.game.frame, self.vy)
Beispiel #16
0
    def loop(self):
        self.apply_gravity()
        self.apply_standing()

        if ((self.ix != 0 and self.rect.x == self._prev.x)
            or self.get_code(sign(s.vx), 0) == CODE_BROBO_TURN):
                self.vx = - self.vx

        self._prev = pygame.Rect(self.rect)

        if self.vx > 0:
            self.facing = 'right'
        elif self.vx < 0:
            self.facing = 'left'

        self.image = 'brobo-%s-%s' % (self.facing, (self.game.frame / 10) % 2)

        self.ix = sprite.myinc(self.game.frame, self.vx)
        self.rect.x += self.ix
        self.rect.y += sprite.myinc(self.game.frame, self.vy)
Beispiel #17
0
def loop(g,s):
    sprite.apply_gravity(g,s)
    sprite.apply_standing(g,s)
    
    #if s.rect.x == s._prev.x: # or sprite.get_code(g,s,sign(s.vx),0) == CODE_PARASIT_TURN:
    #    s.vx = -s.vx

    s._prev = pygame.Rect(s.rect)

    if g.player.rect.centerx > s.rect.centerx:
        s.vx += 0.02
    elif g.player.rect.centerx < s.rect.centerx:
        s.vx -= 0.02

    if s.vx > 0.0:
        s.facing = 'right'
    elif s.vx < 0.0:
        s.facing = 'left'
    s.image = 'parasit/parasit-%s-%s' % (s.facing, (g.frame / 10) % 4)

    if sprite.get_code(g,s,sign(s.vx),0) == CODE_PARASIT_TURN:
        s.vx = 0.0

    s.vx = min(1.0, s.vx)
    s.vx = max(-1.0, s.vx)
    
    if s.shoot == 0:
        shot = parasitshoot.init(g,s.rect,s)
        #g.sprites.append(shot)
        s.shoot = 120
        s.shooting = 10

    if s.shooting > 0:
        s.image = 'parasit/parasit-%s-shoot' % (s.facing)
        s.shooting -= 1

    s.shoot -= 1
    
    s.rect.x += sprite.myinc(g.frame,s.vx)
    s.rect.y += sprite.myinc(g.frame,s.vy)
Beispiel #18
0
def loop(g, s):
    sprite.apply_gravity(g, s)
    sprite.apply_standing(g, s)

    #if s.rect.x == s._prev.x: # or sprite.get_code(g,s,sign(s.vx),0) == CODE_SHOOTBOT_TURN:
    #    s.vx = -s.vx

    s._prev = pygame.Rect(s.rect)

    if g.player.rect.centerx > s.rect.centerx:
        s.vx += 0.01
    elif g.player.rect.centerx < s.rect.centerx:
        s.vx -= 0.01

    if s.vx > 0.0:
        s.facing = 'right'
    elif s.vx < 0.0:
        s.facing = 'left'
    s.image = 'shootbot-%s-%s' % (s.facing, (g.frame / 10) % 4)

    if sprite.get_code(g, s, sign(s.vx), 0) == CODE_SHOOTBOT_TURN:
        s.vx = 0.0

    s.vx = min(1.0, s.vx)
    s.vx = max(-1.0, s.vx)

    if s.shoot == 0:
        shot = laser.init(g, s.rect, s)
        g.sprites.append(shot)
        s.shoot = 120
        s.shooting = 10

    if s.shooting > 0:
        s.image = 'shootbot-%s-shoot' % (s.facing)
        s.shooting -= 1

    s.shoot -= 1

    s.rect.x += sprite.myinc(g.frame, s.vx)
    s.rect.y += sprite.myinc(g.frame, s.vy)
Beispiel #19
0
    def loop(self):
        self.apply_gravity()
        self.apply_standing()

        if self.game.player.rect.centerx > self.rect.centerx:
            self.vx += 0.2
        elif self.game.player.rect.centerx < self.rect.centerx:
            self.vx -= 0.2

        if self.vx > 0.0:
            self.image = 'robo-right'
        elif s.vx < 0.0:
            self.image = 'robo-left'

        if self.get_code(sign(self.vx),0) == CODE_ROBO_TURN:
            self.vx = 0.0

        self.vx = min(4.0, self.vx)
        self.vx = max(-4.0, self.vx)

        self.rect.x += sprite.myinc(self.game.frame, self.vx)
        self.rect.y += sprite.myinc(self.game.frame, self.vy)
Beispiel #20
0
    def loop(self):
        self.apply_gravity()
        self.apply_standing()

        self._prev = pygame.Rect(self.rect)

        if self.game.player.rect.centerx > self.rect.centerx:
            self.vx += 0.02
        elif self.game.player.rect.centerx < self.rect.centerx:
            self.vx -= 0.02

        if self.vx > 0.0:
            self.facing = 'right'
        elif self.vx < 0.0:
            self.facing = 'left'
        self.image = 'shootbot-%s-%s' % (self.facing,
            (self.game.frame / 10) % 4)

        if self.get_code(sign(self.vx), 0) == CODE_SHOOTBOT_TURN:
            self.vx = 0.0

        self.vx = min(1.0, self.vx)
        self.vx = max(-1.0, self.vx)

        if self.shoot == 0:
            shot = Laser(self.game, self.rect, self)
            self.shoot = 120
            self.shooting = 10

        if self.shooting > 0:
            self.image = 'shootbot-%s-shoot' % (self.facing)
            self.shooting -= 1

        self.shoot -= 1

        self.rect.x += sprite.myinc(self.game.frame, self.vx)
        self.rect.y += sprite.myinc(self.game.frame, self.vy)
Beispiel #21
0
def loop(g,s):
    print 'loop'
    sprite.apply_gravity(g,s)
    sprite.apply_standing(g,s)

    print s.vy

    if s.next_jump == 0 and s.standing:
        s.vy = -6.0
        s.next_jump = FPS * 2
        sprite.stop_standing(g,s)
    if s.next_jump > 0:
        s.next_jump -= 1
    
    #if s.rect.x == s._prev.x:
        #s.vx = -s.vx
    s._prev = pygame.Rect(s.rect)
    
    #s.rect.x += s.vx
    s.rect.y += sprite.myinc(g.frame,s.vy)
def loop(g, s):
    # print 'loop'
    sprite.apply_gravity(g, s)
    sprite.apply_standing(g, s)

    # print s.vy

    if s.next_jump == 0 and s.standing:
        s.vy = -6.0
        s.next_jump = FPS * 2
        sprite.stop_standing(g, s)
    if s.next_jump > 0:
        s.next_jump -= 1

    # if s.rect.x == s._prev.x:
    # s.vx = -s.vx
    s._prev = pygame.Rect(s.rect)

    # s.rect.x += s.vx
    s.rect.y += sprite.myinc(g.frame, s.vy)
Beispiel #23
0
def loop(g,s):
    s.vx += (g.game.random % 100) / 1000.0 - 0.05
    s.vx = max(-0.25,min(0.25,s.vx))
    s.x += s.vx
    #s.y += s.vy

    dx = int(s.x-s.rect.x)
    #s.rect.x = s.x
    #s.rect.y = s.y
    
    #dx = sprite.myinc(g.frame,s.vx)
    dy = sprite.myinc(g.frame,s.vy)
    
    s.rect.x += dx
    s.rect.y += dy

    if s.life == 0:
        die(g,s)
    s.life -= 1
    
    for b in s.carrying:
        b.rect.x += dx
        b.rect.y += dy
Beispiel #24
0
def loop(g, s):
    s.vx += (g.game.random % 100) / 1000.0 - 0.05
    s.vx = max(-0.25, min(0.25, s.vx))
    s.x += s.vx
    #s.y += s.vy

    dx = int(s.x - s.rect.x)
    #s.rect.x = s.x
    #s.rect.y = s.y

    #dx = sprite.myinc(g.frame,s.vx)
    dy = sprite.myinc(g.frame, s.vy)

    s.rect.x += dx
    s.rect.y += dy

    if s.life == 0:
        die(g, s)
    s.life -= 1

    for b in s.carrying:
        b.rect.x += dx
        b.rect.y += dy
Beispiel #25
0
    def loop(self):
        self.apply_gravity()
        self.apply_standing()

        if self.walking:
            if self._prev != None:
                if (self.rect.x == self._prev.x or self.get_code(sign(self.vx),
                    0) == CODE_FROG_TURN):
                    self.vx = -self.vx
                    self.next_frame = 1

            if (self.standing != None and self.get_code(sign(self.vx),
                    1) == CODE_FROG_JUMP):
                self.vy_jump = - 3.6 * 1.22
                if (sprite.get_code(self.game, self, sign(self.vx) * 2, 1)
                        == CODE_FROG_JUMP):
                    self.vy_jump = - 6.0 * 1.22
                    if (sprite.get_code(game, self, sign(self.vx) * 3, 1)
                         == CODE_FROG_JUMP):
                        self.vy_jump = - 8.1 * 1.22

                self.jumping = True
                self.walking = False
                self.next_frame = 20

                if self.vx > 0:
                    self.image = 'frog/prejump-right'
                elif self.vx < 0:
                    self.image = 'frog/prejump-left'

            self._prev = pygame.Rect(self.rect)

            self.rect.x += self.vx
            self.rect.y += self.vy

        else:
            self._prev = pygame.Rect(self.rect)
            if (self.next_frame <= 0):
                if (self.standing != None):
                    self.walking = True
                    self.jumping = not self.walking
                    self.next_frame = 1
                vx = self.vx * 1.8
                self.rect.x += sprite.myinc(self.game.frame, vx)
                self.rect.y += sprite.myinc(self.game.frame, self.vy)

        self.next_frame -= 1
        if self.next_frame == 0:
            if self.jumping:
                sprite.stop_standing(self.game, self)
                self.vy = self.vy_jump
                if self.vx > 0:
                    self.image = 'frog/jump-right'
                elif self.vx < 0:
                    self.image = 'frog/jump-left'
            else:
                self.next_frame = 6
                self.frame += 1
                if self.frame > 4:
                    self.frame = 0
                if self.vx > 0:
                    self.image = 'frog/walk-right-' + str(self.frame)
                elif self.vx < 0:
                    self.image = 'frog/walk-left-' + str(self.frame)
Beispiel #26
0
def loop(g, s):
    # sprite.apply_gravity(g,s)
    sprite.apply_standing(g, s)

    # if s.rect.x == s._prev.x: # or sprite.get_code(g,s,sign(s.vx),0) == CODE_TENTACTUL_TURN:
    #   s.vx = -s.vx

    s._prev = pygame.Rect(s.rect)

    if g.player.rect.centerx > s.rect.centerx:
        s.vx += 0.02
    elif g.player.rect.centerx < s.rect.centerx:
        s.vx -= 0.02

    if s.vx > 0.0:
        s.facing = 'right'
    elif s.vx < 0.0:
        s.facing = 'left'
    s.image = 'tentactul/tentactul-%s-%s' % (s.facing, (g.frame / 10) % 4)

    if sprite.get_code(g, s, sign(s.vx), 0) == CODE_TENTACTUL_TURN:
        s.vx = 0.0

    s.vx = min(1.0, s.vx)
    s.vx = max(-1.0, s.vx)

    if s.idling > 0:
        if s.idling % 40 > 20:
            s.facing = 'left'
        else:
            s.facing = 'right'
        s.idling -= 1
        if s.idling == 0:
            s.moving = 90
            # if g.game.random % 2 == 0:
            if random.randint(0, 1):
                s.vx = -s.speed
                s.facing = 'left'
            else:
                s.vx = s.speed
                s.facing = 'right'
    elif s.moving > 0:
        s.moving -= 1
        if s.moving == 0:
            s.idling = 80
            s.vx = 0
    else:
        s.idling = 80

    if s.vx < 0:
        s.facing = 'left'
    else:
        s.facing = 'right'

    s.image = 'tentactul/tentactul-%s-%s' % (s.facing, (s.frame / 5) % 2)
    s.frame += 1

    if s.shoot == 0:
        shot = tentactulshoot.init(g, s.rect, s)
        # g.sprites.append(shot)
        s.shoot = s.shoot_reload
        s.shooting = 5

    if s.shooting > 0:
        s.image = 'tentactul/tentactul-%s-shoot' % (s.facing)
        s.shooting -= 1

    s.shoot -= 1

    s.rect.x += sprite.myinc(g.frame, s.vx)
    s.rect.y += sprite.myinc(g.frame, s.vy)
Beispiel #27
0
def loop(g, s):

    if s.drone == "guardian":

        sprites = g.sprites[:]

        for enemy in sprites:
            if "enemy" in enemy.groups:
                if s.shoot == 0:
                    shot = droneshoot.init(g, s.rect, s, enemy)
                    s.shoot = 100
                    s.shooting = 5

                if s.shooting > 0:
                    s.shooting -= 1

                s.shoot -= 1

    elif s.drone == "killer":

        sprites = g.sprites[:]

        for enemy in sprites:
            if "enemy" in enemy.groups:
                if s.shoot == 0:
                    shot = droneshoot.init(g, s.rect, s, enemy)
                    s.shoot = 100
                    s.shooting = 5

                if s.shooting > 0:
                    s.shooting -= 1

                s.shoot -= 1

    if g.frame % 30 == 0:
        s.image = "drone/%s-1" % s.drone
    else:
        s.image = "drone/%s-0" % s.drone

    sprite.apply_standing(g, s)
    s._prev = pygame.Rect(s.rect)

    s.x_pid.setPoint(g.player.rect.centerx)
    s.y_pid.setPoint(g.player.rect.centery)

    pid_x = s.x_pid.update(s.rect.centerx + 16)
    pid_y = s.y_pid.update(s.rect.centery + 16)

    s.vx = pid_x
    s.vy = pid_y

    s.vx = min(s.max_speed_x, s.vx)
    s.vx = max(-s.max_speed_x, s.vx)

    s.vy = min(s.max_speed_y, s.vy)
    s.vy = max(-s.max_speed_y, s.vy)

    s.rect.x += sprite.myinc(g.frame, s.vx)
    s.rect.y += sprite.myinc(g.frame, s.vy)

    if s.vx > 0:
        s.facing = "right"
    else:
        s.facing = "left"
Beispiel #28
0
def loop(g, s):
    s._prev2 = pygame.Rect(s.rect)

    if s.powered_up == 'cannon':
        s.weapon = 'cannon'
    elif s.powered_up == 'shootgun':
        s.weapon = 'shootgun'
    elif s.powered_up == 'laser':
        s.weapon = 'laser'
    elif s.powered_up == 'granadelauncher':
        s.weapon = 'granadelauncher'
    else:
        s.weapon = 'player'

    inpt = g.game.input

    if s.vy < 0:
        s.image = s.jetpack + "/" + s.weapon + '/%s-jump' % s.facing
    elif s.shooting > 0:
        if s.shooting > 5:
            s.image = s.jetpack + "/" + s.weapon + '/%s-shoot-1' % s.facing
        else:
            s.image = s.jetpack + "/" + s.weapon + '/%s-shoot-2' % s.facing
        s.shooting -= 1
    elif inpt.right or inpt.left and s.standing:
        s.image = s.jetpack + "/" + s.weapon + '/%s-walk-%s' % (
            s.facing, int(s.walk_frame))
        s.walk_frame += 0.2
        if s.walk_frame > 4:
            s.walk_frame = 1
    else:
        s.image = s.jetpack + "/" + s.weapon + '/%s' % s.facing
    if s.vx > 0:
        s.facing = 'right'
    elif s.vx < 0:
        s.facing = 'left'

    if s.image is not None:
        if s.damaged_transition > 0:
            if (s.damaged_transition % 10) > 5:
                s.image = None
            else:
                if s.vy < 0:
                    s.image = s.jetpack + "/" + s.weapon + '/%s-jump' % s.facing

                elif inpt.right or inpt.left and s.standing:
                    s.image = s.jetpack + "/" + s.weapon + '/%s-walk-%s' % (
                        s.facing, int(s.walk_frame))
                else:
                    s.image = s.jetpack + "/" + s.weapon + '/%s' % (s.facing)

            s.damaged_transition -= 1
        """
        elif s.powerup_transition > 0:
            if (s.powerup_transition % 10) > 5:
                s.image = s.image
            s.powerup_transition -= 1
        elif s.powered_up == '':
            s.image = s.image
            """

    if s.got_hit:
        if s.facing == "right":
            s.rect.x -= 2
        else:
            s.rect.x += 2
        s.got_hit -= 1

    if s.death_counter > 0:
        s.groups = set()
        if not s.no_explode:
            s.exploded += 1
            if s.exploded > FPS / 2:
                s.image = None
        else:
            s.image = None
        s.death_counter -= 1
        return
    if s.death_counter == 0:
        g.status = 'dead'
        return

    if s.exploded > 0:
        s.exploded -= 1
        return

    sprite.apply_gravity(g, s)
    sprite.apply_standing(g, s)

    if s.door_timer is not None:
        if s.door_timer == 0:
            x, y = s.door_pos  # s.rect.centerx/TW,s.rect.centery/TH
            import door
            # door.hit(g,g.layer[y][x],s)
            door.hit(g, (x, y), s)
            # tiles.t_put(g,(x,y), 0x30)
            # tiles.t_put(g,(x,y-1), 0x20)
            s.door_timer = None
        else:
            s.door_timer -= 1
            return

    # if s.standing: s.rect.bottom = s.standing.rect.top

    # check if we hit the ceiling
    if not s.jumping and s.vy < 0 and s.rect.y == s._prev.y:
        s.vy = 0

    # We have universal input code now (>__>)
    # move by keyboard
    # keys = pygame.key.get_pressed()

    if s.jumping:
        # print s.vy
        s.vy -= s.jumping

        if s.vy < -4:
            s.vy = -4

        if s.jetpack == "double_jump":
            s.jump_timer += 5
            s.jumping = max(0, s.jumping - 0.2)

        elif s.jetpack == 'fly':
            s.jumping = max(0, s.jumping)

        else:
            s.jump_timer += 4
            s.jumping = max(0, s.jumping - 0.2)

    if s.jump_timer and not s.jumping:
        s.jump_timer -= 1
        x_speed = 1.0
    else:
        x_speed = 1.0

    if g.frame % s.speed == 0:
        if inpt.right:
            s.vx = x_speed
            s.fancing = 'right'
        elif not inpt.right and s.vx > 0:
            s.vx = 0
        if inpt.left:
            s.vx = -x_speed
            s.facing = 'left'
        elif not inpt.left and s.vx < 0:
            s.vx = 0

        s._prev = pygame.Rect(s.rect)

        vx, vy = s.vx, s.vy
        s.rect.x += vx
        s.rect.y += sprite.myinc(g.frame, s.vy)

    # if keys[K_UP]: vy -= 1
    # if keys[K_DOWN]: vy += 1

    if s.flash_counter > 0:
        if s.flash_timer < 4:
            s.image = None
        if s.flash_timer == 0:
            s.flash_timer = 8
            s.flash_counter -= 1
        s.flash_timer -= 1

    s.looking = False

    if inpt.up:
        s.view_counter += 1
        if s.view_counter >= 60:
            g.view.y -= 2
            s.looking = True

    elif inpt.down:
        s.view_counter += 1
        if s.view_counter >= 60:
            g.view.y += 2
            s.looking = True
    else:
        s.view_counter = 0

    n = sprite.get_code(g, s, 0, 0)
    if n == CODE_EXIT and (g.game.chips[0] and g.game.chips[1]
                           and g.game.chips[2] and g.game.chips[3]):
        g.status = 'exit'
    if n == CODE_DOOR_AUTO:
        x, y = s.rect.centerx / TW, s.rect.centery / TH
        import door
        door.hit(g, (x, y), s)

    # pan_screen(g,s)

    # if (g.frame%FPS)==0: print 'player vy:',s.vy

    if hasattr(g, 'boss'):
        # print g.boss.phase, g.boss.phase_frames
        if g.boss.phase == 2 and g.boss.phase_frames == 60:
            for y in xrange(len(g.layer)):
                for x in xrange(len(g.layer[y])):
                    if g.data[2][y][x] == CODE_BOSS_PHASE2_BLOCK:
                        tiles.t_put(g, (x, y), 0x01)  # solid tile
        if g.boss.dead:
            g.status = 'exit'
            # pygame.mixer.music.load("
            # g.game.music.play('finish',1)

    if hasattr(s, "shoot"):
        s.shoot.cooldown -= 1
        if s.shoot.cooldown == 0:
            s.canshoot = True

    if g.game.drone is not None and s.drone != g.game.drone:
        s.drone = g.game.drone

        if hasattr(s.drone_sprite, "active"):
            s.drone_sprite.active = False
        s.drone_sprite = sprites.drone.init(g, s.rect, s, s.drone)

        if s.drone == "defender" and s.shield is False:
            s.shield_sprite = sprites.shield.init(g, s.rect, s)
            s.shield = True

    if s.drone != "defender" and s.shield is True:
        s.shield_sprite.active = False
        s.shield = False

    if s.shield is False and s.shield_counter:
        if s.shield_counter > 1:
            s.shield_counter -= 1
        else:
            s.shield_counter = 0
            if s.drone == "defender" and s.shield is False:
                s.shield_sprite = sprites.shield.init(g, s.rect, s)
                s.shield = True

    s.jetpack = g.game.jetpack
    s.strength = g.game.strength
    s.powered_up = g.game.powerup
Beispiel #29
0
def loop(g, s):
    sprite.apply_gravity(g, s)
    sprite.apply_standing(g, s)

    # if s.standing != None and s.vx != 0:
    # next_tile = g.layer[s.standing.pos[1]][s.standing.pos[0] + s.direction]
    # next2_tile = g.layer[s.standing.pos[1]][s.standing.pos[0] + s.direction*2]
    # if (next_tile.standable == 0) or (next2_tile.standable == 0):
    # s.rect.x = s._prev.x
    # s.direction = - s.direction
    # s.next_frame = 1


    if g.frame % s.speed == 0:
        if s.walking:
            if s._prev != None:
                if s.rect.x == s._prev.x or sprite.get_code(g, s, sign(s.vx), 0) == CODE_ZOMBIE_TURN:
                    s.vx = -s.vx
                    s.next_frame = 1
                    if s.vx < 0:
                        s.facing = 'left'
                    else:
                        s.facing = 'right'

            if s.standing != None and sprite.get_code(g, s, sign(s.vx), 1) == CODE_ZOMBIE_JUMP:
                # s.vy_jump = -3.1
                """
				if sprite.get_code(g,s,sign(s.vx)*2,1) == CODE_ZOMBIE_JUMP:
					s.vy_jump = -3.0
					if sprite.get_code(g,s,sign(s.vx)*3,1) == CODE_ZOMBIE_JUMP:
						s.vy_jump = -4.1
				"""
                s.jumping = True
                s.walking = False
                s.next_frame = 20
                s.image = 'zombie/prejump-%s' % s.facing

            s._prev = pygame.Rect(s.rect)

            s.rect.x += s.vx
            s.rect.y += s.vy
        else:
            s._prev = pygame.Rect(s.rect)
            if (s.next_frame <= 0):
                if (s.standing != None):
                    s.walking = True
                    s.jumping = False
                    s.next_frame = 1
                # s.vx*1
                vx = s.vx
                s.rect.x += sprite.myinc(g.frame, vx)
                s.rect.y += sprite.myinc(g.frame, s.vy)

        s.next_frame -= 1
        if s.next_frame == 0:
            if s.jumping:
                sprite.stop_standing(g, s)
                s.vy = s.vy_jump
                s.image = 'zombie/jump-%s' % s.facing
            else:
                s.next_frame = s.frame_speed
                s.frame += 1
                if s.frame > 3:
                    s.frame = 0
                s.image = 'zombie/walk-%s-%s' % (s.facing, s.frame)
def loop(g, s):
    # if s.dying == None: s.dying = 1
    if s.dying is not None:
        s.image = 'boss/%s-%d' % (s.facing, (g.frame / (FPS / 8)) % 8)
        if s.dying % 15 == 0:
            g.game.sfx['boss_explode'].play()
        if s.dying % 15 > 10:
            s.image = 'boss/%s-damage-%d' % (s.facing,
                                             (g.frame / (FPS / 8)) % 8)
        s.dying += 1

        mid_frame = FPS * 3 / 2
        end_frame = FPS * 6 / 2

        if s.dying == mid_frame:
            # explode
            g.game.sfx['pop'].play()
            for n in xrange(128):
                r = pygame.Rect(random.randint(s.rect.left, s.rect.right),
                                random.randint(s.rect.top, s.rect.bottom), 1,
                                1)
                s2 = bub_init(g, r)

        if s.dying >= mid_frame:
            s.image = None
        # if s.dead:
        #    s.active = False
        if s.dying > end_frame:
            s.dead = True
            # s.active = False
        # if s.dying % 30 == 15:
        return

    # sprite.apply_gravity(g,s)

    # if s._prev != None:
    # if s.rect.x == s._prev.x or sprite.get_code(g,s,sign(s.vx),0) == CODE_PARROT_TURN:
    if sprite.get_code(g, s, sign(s.vx), 0) == CODE_BOSS_TURN:
        s.vx = -s.vx
    # s._prev = pygame.Rect(s.rect)

    if s.phase == 2:
        if s.phase_frames == 240 + 32:
            s.vy = 0
            s.vx = 1.2

    if s.vx > 0:
        s.facing = 'right'
    else:
        s.facing = 'left'

    s.rect.x += sprite.myinc(g.frame, s.vx)
    s.rect.y += sprite.myinc(g.frame, s.vy)

    s.image = 'boss/%s-%d' % (s.facing, (g.frame / (FPS / 8)) % 8)
    if s.taking_damage > 0:
        if s.taking_damage % 20 > 10:
            s.image = 'boss/%s-damage-%d' % (s.facing,
                                             (g.frame / (FPS / 8)) % 8)
        s.taking_damage -= 1

    s.phase_frames += 1

    if s.drop == 0:
        if s.vy == 0:  # this is to prevent the boss from bombing you when it's
            # flying up to the second phase
            sprites.fireball.init(g, s.rect, s)
        if s.phase == 1:
            s.drop = 120
        if s.phase == 2:
            s.drop = 90
    s.drop -= 1
Beispiel #31
0
def loop(g,s):
    s._prev2 = pygame.Rect(s.rect)
    
    if s.death_counter > 0:
        s.groups = set()
        if not s.no_explode:
            s.exploded += 1
            if s.exploded > FPS/2:
                s.image = None
        else:
            s.image = None
        s.death_counter -= 1
        return
    if s.death_counter == 0:
        g.status = 'dead'
        return 
    
    if s.exploded > 0:
        if s.powered_up:
            s.image = 'player/right'
        else:
            s.image = 'splayer/right'
        s.exploded -=1 
        return
        

        
    sprite.apply_gravity(g,s)
    sprite.apply_standing(g,s)

    if s.door_timer != None:
        if s.door_timer == 0:
            x,y = s.door_pos#s.rect.centerx/TW,s.rect.centery/TH
            import door
            #door.hit(g,g.layer[y][x],s)
            door.hit(g,(x,y),s)
            #tiles.t_put(g,(x,y), 0x30)
            #tiles.t_put(g,(x,y-1), 0x20)
            s.door_timer = None
        else:
            s.door_timer -= 1
            return

    inpt = g.game.input
    
    #if s.standing: s.rect.bottom = s.standing.rect.top
    
    #check if we hit the ceiling
    if not s.jumping and s.vy < 0 and s.rect.y == s._prev.y:
        s.vy = 0
        
    # We have universal input code now (>__>)
    #move by keyboard
    #keys = pygame.key.get_pressed()
    
    if s.jumping:
        #print s.vy
        s.vy -= s.jumping
        s.jumping = max(0,s.jumping-0.2)
    
    inc = 0.5
    mx = 1.0
    if inpt.right and s.vx < mx:
        s.vx += inc
        s.facing = 'right'
    elif not inpt.right and s.vx > 0:    s.vx -= inc
    if inpt.left  and s.vx > -mx:
        s.vx -= inc
        s.facing = 'left'
    elif not inpt.left and s.vx < 0:    s.vx += inc

    
    s._prev = pygame.Rect(s.rect)

    vx,vy = s.vx,s.vy
    s.rect.x += vx
    s.rect.y += sprite.myinc(g.frame,s.vy)
    
    
    #if keys[K_UP]: vy -= 1
    #if keys[K_DOWN]: vy += 1
    
    if s.vy < 0:
        s.image = 'player/%s-jump' % (s.facing)
    elif s.shooting > 0:
        if s.shooting > 5:
            s.image = 'player/%s-shoot-1' % (s.facing)
        else:
            s.image = 'player/%s-shoot-2' % (s.facing)
        s.shooting -= 1
    elif inpt.right or inpt.left and s.standing:
        s.image = 'player/%s-walk-%s' % (s.facing, int(s.walk_frame))
        s.walk_frame += 0.2
        if s.walk_frame > 4:
            s.walk_frame = 1
    else:
        s.image = 'player/%s'%(s.facing)
    if s.flash_counter > 0:
        if s.flash_timer < 4:
            s.image = None
        if s.flash_timer == 0:
            s.flash_timer = 8
            s.flash_counter -= 1
        s.flash_timer -= 1
    if s.image != None:
        if s.powerup_transition > 0:
            if (s.powerup_transition % 10) > 5:
                s.image = 's' + s.image
            s.powerup_transition -= 1
        elif not s.powered_up:
            s.image = 's' + s.image
    
    s.looking = False
    if inpt.up:
        g.view.y -= 2
        s.looking = True
    if inpt.down:
        g.view.y += 2
        s.looking = True
    
    n = sprite.get_code(g,s,0,0) 
    if n == CODE_EXIT:
        g.status = 'exit'
    if n == CODE_DOOR_AUTO:
        x,y = s.rect.centerx/TW,s.rect.centery/TH
        import door
        door.hit(g,(x,y),s)

    
    #pan_screen(g,s)
    
    #if (g.frame%FPS)==0: print 'player vy:',s.vy

    if hasattr(g, 'boss'):
        #print g.boss.phase, g.boss.phase_frames
        if g.boss.phase == 2 and g.boss.phase_frames == 60:
            for y in xrange(len(g.layer)):
                for x in xrange(len(g.layer[y])):
                    if g.data[2][y][x] == CODE_BOSS_PHASE2_BLOCK:
                        tiles.t_put(g,(x,y),0x01) # solid tile
        if g.boss.dead:
            g.status = 'exit'
def loop(g, s):
    if s.death_counter > 0:
        s.groups = set()
        s.exploded += 1
        if s.exploded > FPS / 2:
            s.image = None
        s.death_counter -= 1
        return
    if s.death_counter == 0:
        g.status = 'dead'
        return

    if s.exploded > 0:
        if s.powered_up:
            s.image = 'player/right'
        else:
            s.image = 'splayer/right'
        s.exploded -= 1
        return

    sprite.apply_gravity(g, s)
    sprite.apply_standing(g, s)

    if s.door_timer != None:
        if s.door_timer == 0:
            x, y = s.door_pos  #s.rect.centerx/TW,s.rect.centery/TH
            import door
            #door.hit(g,g.layer[y][x],s)
            door.hit(g, (x, y), s)
            #tiles.t_put(g,(x,y), 0x30)
            #tiles.t_put(g,(x,y-1), 0x20)
            s.door_timer = None
        else:
            s.door_timer -= 1
            return

    inpt = g.game.input

    #if s.standing: s.rect.bottom = s.standing.rect.top

    #check if we hit the ceiling
    if not s.jumping and s.vy < 0 and s.rect.y == s._prev.y:
        s.vy = 0

    # We have universal input code now (>__>)
    #move by keyboard
    #keys = pygame.key.get_pressed()

    if s.jumping:
        #print s.vy
        s.vy -= s.jumping
        s.jumping = max(0, s.jumping - 0.2)

    inc = 0.5
    mx = 2
    if inpt.right and s.vx < mx:
        s.vx += inc
        s.facing = 'right'
    elif not inpt.right and s.vx > 0:
        s.vx -= inc
    if inpt.left and s.vx > -mx:
        s.vx -= inc
        s.facing = 'left'
    elif not inpt.left and s.vx < 0:
        s.vx += inc

    s._prev = pygame.Rect(s.rect)

    vx, vy = s.vx, s.vy
    s.rect.x += vx
    s.rect.y += sprite.myinc(g.frame, s.vy)

    #if keys[K_UP]: vy -= 1
    #if keys[K_DOWN]: vy += 1

    if s.vy < 0:
        s.image = 'player/%s-jump' % (s.facing)
    elif s.shooting > 0:
        if s.shooting > 5:
            s.image = 'player/%s-shoot-1' % (s.facing)
        else:
            s.image = 'player/%s-shoot-2' % (s.facing)
        s.shooting -= 1
    elif inpt.right or inpt.left and s.standing:
        s.image = 'player/%s-walk-%s' % (s.facing, int(s.walk_frame))
        s.walk_frame += 0.2
        if s.walk_frame > 4:
            s.walk_frame = 1
    else:
        s.image = 'player/%s' % (s.facing)
    if s.flash_counter > 0:
        if s.flash_timer < 4:
            s.image = None
        if s.flash_timer == 0:
            s.flash_timer = 8
            s.flash_counter -= 1
        s.flash_timer -= 1
    if s.image != None:
        if s.powerup_transition > 0:
            if (s.powerup_transition % 10) > 5:
                s.image = 's' + s.image
            s.powerup_transition -= 1
        elif not s.powered_up:
            s.image = 's' + s.image

    if inpt.up:
        g.view.y -= 2
    if inpt.down:
        g.view.y += 2

    n = sprite.get_code(g, s, 0, 0)
    if n == CODE_EXIT:
        g.status = 'exit'
    if n == CODE_DOOR_AUTO:
        x, y = s.rect.centerx / TW, s.rect.centery / TH
        import door
        door.hit(g, (x, y), s)

    #pan_screen(g,s)

    #if (g.frame%FPS)==0: print 'player vy:',s.vy

    if hasattr(g, 'boss'):
        #print g.boss.phase, g.boss.phase_frames
        if g.boss.phase == 2 and g.boss.phase_frames == 60:
            for y in xrange(len(g.layer)):
                for x in xrange(len(g.layer[y])):
                    if g.data[2][y][x] == CODE_BOSS_PHASE2_BLOCK:
                        tiles.t_put(g, (x, y), 0x01)  # solid tile
        if g.boss.dead:
            g.status = 'exit'
Beispiel #33
0
def loop(g, s):
    s._prev2 = pygame.Rect(s.rect)

    if s.powered_up == 'cannon':
        s.weapon = 'cannon'
    elif s.powered_up == 'shootgun':
        s.weapon = 'shootgun'
    elif s.powered_up == 'laser':
        s.weapon = 'laser'
    elif s.powered_up == 'granadelauncher':
        s.weapon = 'granadelauncher'
    else:
        s.weapon = 'player'

    inpt = g.game.input

    if s.vy < 0:
        s.image = s.jetpack + "/" + s.weapon + '/%s-jump' % s.facing
    elif s.shooting > 0:
        if s.shooting > 5:
            s.image = s.jetpack + "/" + s.weapon + '/%s-shoot-1' % s.facing
        else:
            s.image = s.jetpack + "/" + s.weapon + '/%s-shoot-2' % s.facing
        s.shooting -= 1
    elif inpt.right or inpt.left and s.standing:
        s.image = s.jetpack + "/" + s.weapon + '/%s-walk-%s' % (s.facing, int(s.walk_frame))
        s.walk_frame += 0.2
        if s.walk_frame > 4:
            s.walk_frame = 1
    else:
        s.image = s.jetpack + "/" + s.weapon + '/%s' % s.facing
    if s.vx > 0:
        s.facing = 'right'
    elif s.vx < 0:
        s.facing = 'left'

    if s.image is not None:
        if s.damaged_transition > 0:
            if (s.damaged_transition % 10) > 5:
                s.image = None
            else:
                if s.vy < 0:
                    s.image = s.jetpack + "/" + s.weapon + '/%s-jump' % s.facing

                elif inpt.right or inpt.left and s.standing:
                    s.image = s.jetpack + "/" + s.weapon + '/%s-walk-%s' % (s.facing, int(s.walk_frame))
                else:
                    s.image = s.jetpack + "/" + s.weapon + '/%s' % (s.facing)

            s.damaged_transition -= 1
        """
        elif s.powerup_transition > 0:
            if (s.powerup_transition % 10) > 5:
                s.image = s.image
            s.powerup_transition -= 1
        elif s.powered_up == '':
            s.image = s.image
            """

    if s.got_hit:
        if s.facing == "right":
            s.rect.x -= 2
        else:
            s.rect.x += 2
        s.got_hit -= 1

    if s.death_counter > 0:
        s.groups = set()
        if not s.no_explode:
            s.exploded += 1
            if s.exploded > FPS / 2:
                s.image = None
        else:
            s.image = None
        s.death_counter -= 1
        return
    if s.death_counter == 0:
        g.status = 'dead'
        return

    if s.exploded > 0:
        s.exploded -= 1
        return

    sprite.apply_gravity(g, s)
    sprite.apply_standing(g, s)

    if s.door_timer is not None:
        if s.door_timer == 0:
            x, y = s.door_pos  # s.rect.centerx/TW,s.rect.centery/TH
            import door
            # door.hit(g,g.layer[y][x],s)
            door.hit(g, (x, y), s)
            # tiles.t_put(g,(x,y), 0x30)
            # tiles.t_put(g,(x,y-1), 0x20)
            s.door_timer = None
        else:
            s.door_timer -= 1
            return

    # if s.standing: s.rect.bottom = s.standing.rect.top

    # check if we hit the ceiling
    if not s.jumping and s.vy < 0 and s.rect.y == s._prev.y:
        s.vy = 0

    # We have universal input code now (>__>)
    # move by keyboard
    # keys = pygame.key.get_pressed()

    if s.jumping:
        # print s.vy
        s.vy -= s.jumping

        if s.vy < -4:
            s.vy = -4

        if s.jetpack == "double_jump":
            s.jump_timer += 5
            s.jumping = max(0, s.jumping - 0.2)

        elif s.jetpack == 'fly':
            s.jumping = max(0, s.jumping)

        else:
            s.jump_timer += 4
            s.jumping = max(0, s.jumping - 0.2)

    if s.jump_timer and not s.jumping:
        s.jump_timer -= 1
        x_speed = 1.0
    else:
        x_speed = 1.0

    if g.frame % s.speed == 0:
        if inpt.right:
            s.vx = x_speed
            s.fancing = 'right'
        elif not inpt.right and s.vx > 0:
            s.vx = 0
        if inpt.left:
            s.vx = -x_speed
            s.facing = 'left'
        elif not inpt.left and s.vx < 0:
            s.vx = 0

        s._prev = pygame.Rect(s.rect)

        vx, vy = s.vx, s.vy
        s.rect.x += vx
        s.rect.y += sprite.myinc(g.frame, s.vy)


    # if keys[K_UP]: vy -= 1
    # if keys[K_DOWN]: vy += 1

    if s.flash_counter > 0:
        if s.flash_timer < 4:
            s.image = None
        if s.flash_timer == 0:
            s.flash_timer = 8
            s.flash_counter -= 1
        s.flash_timer -= 1

    s.looking = False

    if inpt.up:
        s.view_counter += 1
        if s.view_counter >= 60:
            g.view.y -= 2
            s.looking = True

    elif inpt.down:
        s.view_counter += 1
        if s.view_counter >= 60:
            g.view.y += 2
            s.looking = True
    else:
        s.view_counter = 0

    n = sprite.get_code(g, s, 0, 0)
    if n == CODE_EXIT and (g.game.chips[0] and g.game.chips[1] and g.game.chips[2] and g.game.chips[3]):
        g.status = 'exit'
    if n == CODE_DOOR_AUTO:
        x, y = s.rect.centerx / TW, s.rect.centery / TH
        import door
        door.hit(g, (x, y), s)

    # pan_screen(g,s)

    # if (g.frame%FPS)==0: print 'player vy:',s.vy

    if hasattr(g, 'boss'):
        # print g.boss.phase, g.boss.phase_frames
        if g.boss.phase == 2 and g.boss.phase_frames == 60:
            for y in xrange(len(g.layer)):
                for x in xrange(len(g.layer[y])):
                    if g.data[2][y][x] == CODE_BOSS_PHASE2_BLOCK:
                        tiles.t_put(g, (x, y), 0x01)  # solid tile
        if g.boss.dead:
            g.status = 'exit'
            # pygame.mixer.music.load("
            # g.game.music.play('finish',1)

    if hasattr(s, "shoot"):
        s.shoot.cooldown -= 1
        if s.shoot.cooldown == 0:
            s.canshoot = True

    if g.game.drone is not None and s.drone != g.game.drone:
        s.drone = g.game.drone

        if hasattr(s.drone_sprite, "active"):
            s.drone_sprite.active = False
        s.drone_sprite = sprites.drone.init(g, s.rect, s, s.drone)

        if s.drone == "defender" and s.shield is False:
            s.shield_sprite = sprites.shield.init(g, s.rect, s)
            s.shield = True

    if s.drone != "defender" and s.shield is True:
        s.shield_sprite.active = False
        s.shield = False

    if s.shield is False and s.shield_counter:
        if s.shield_counter > 1:
            s.shield_counter -= 1
        else:
            s.shield_counter = 0
            if s.drone == "defender" and s.shield is False:
                s.shield_sprite = sprites.shield.init(g, s.rect, s)
                s.shield = True

    s.jetpack = g.game.jetpack
    s.strength = g.game.strength
    s.powered_up = g.game.powerup
Beispiel #34
0
def loop(g, s):
    sprite.apply_gravity(g, s)
    sprite.apply_standing(g, s)

    # if s.standing != None and s.vx != 0:
    # next_tile = g.layer[s.standing.pos[1]][s.standing.pos[0] + s.direction]
    # next2_tile = g.layer[s.standing.pos[1]][s.standing.pos[0] + s.direction*2]
    # if (next_tile.standable == 0) or (next2_tile.standable == 0):
    # s.rect.x = s._prev.x
    # s.direction = - s.direction
    # s.next_frame = 1

    if s.flying:
        if s._prev != None:
            if s.rect.x == s._prev.x or sprite.get_code(g, s, sign(s.vx),
                                                        0) == CODE_BAT_TURN:
                s.vx = -s.vx
                s.next_frame = 1
                if s.vx < 0:
                    s.facing = 'left'
                else:
                    s.facing = 'right'

        if s.standing != None and sprite.get_code(g, s, sign(s.vx),
                                                  1) == CODE_BAT_ATTACK:
            s.vy_attack = -4
            """
			if sprite.get_code(g,s,sign(s.vx)*2,1) == CODE_BAT_ATTACK:
				s.vy_attack = -3.0
				if sprite.get_code(g,s,sign(s.vx)*3,1) == CODE_BAT_ATTACK:
					s.vy_attack = -4.1
			"""
            s.attacking = True
            s.flying = False
            s.next_frame = 20
            s.image = 'bat/preattack-%s' % s.facing

        s._prev = pygame.Rect(s.rect)

        s.rect.x += s.vx
        s.rect.y += s.vy
    else:
        s._prev = pygame.Rect(s.rect)
        if (s.next_frame <= 0):
            if (s.standing != None):
                s.flying = True
                s.attacking = False
                s.next_frame = 1
            # s.vx*1
            vx = s.vx
            s.rect.x += sprite.myinc(g.frame, vx)
            s.rect.y += sprite.myinc(g.frame, s.vy)

    s.next_frame -= 1
    if s.next_frame == 0:
        if s.attacking:
            sprite.stop_standing(g, s)
            s.vy = s.vy_attack
            s.image = 'bat/attack-%s' % s.facing
        else:
            s.next_frame = 6
            s.frame += 1
            if s.frame > 2:
                s.frame = 0
            s.image = 'bat/fly-%s-%s' % (s.facing, s.frame)
Beispiel #35
0
def loop(g,s):
    sprite.apply_gravity(g,s)
    sprite.apply_standing(g,s)
    
    #if s.standing != None and s.vx != 0:
        #next_tile = g.layer[s.standing.pos[1]][s.standing.pos[0] + s.direction]
        #next2_tile = g.layer[s.standing.pos[1]][s.standing.pos[0] + s.direction*2]
        #if (next_tile.standable == 0) or (next2_tile.standable == 0):
            #s.rect.x = s._prev.x    
            #s.direction = - s.direction
            #s.next_frame = 1
    if s.walking:
        if s._prev != None:
            if s.rect.x == s._prev.x or sprite.get_code(g,s,sign(s.vx),0) == CODE_FROG_TURN:
                s.vx = -s.vx
                s.next_frame=1
                
        if s.standing != None and sprite.get_code(g,s,sign(s.vx),1) == CODE_FROG_JUMP:
            #s.vy_jump = -4.0
            s.vy_jump = -1.8
            if sprite.get_code(g,s,sign(s.vx)*2,1) == CODE_FROG_JUMP:
                #s.vy_jump = -6.5
                s.vy_jump = -3.0
                if sprite.get_code(g,s,sign(s.vx)*3,1) == CODE_FROG_JUMP:
                    #s.vy_jump = -8.5
                    s.vy_jump = -4.1
                
            s.jumping = True
            s.walking = False
            s.next_frame = 20
            if s.vx > 0:
                s.image = 'frog/prejump-right'
            elif s.vx < 0:
                s.image = 'frog/prejump-left' 
            
        s._prev = pygame.Rect(s.rect)
        
        s.rect.x += s.vx*1
        s.rect.y += s.vy
    else:
        s._prev = pygame.Rect(s.rect)
        if (s.next_frame <= 0): 
            if (s.standing != None):
                s.walking=True
                s.jumping=False
                s.next_frame=1
            #s.vx*1
            vx = s.vx*1.5
            s.rect.x += sprite.myinc(g.frame,vx)
            s.rect.y += sprite.myinc(g.frame,s.vy)
            
    s.next_frame -= 1
    if s.next_frame == 0:
        if s.jumping:
            sprite.stop_standing(g,s)
            s.vy = s.vy_jump
            if s.vx > 0:
                s.image = 'frog/jump-right'
            elif s.vx < 0:
                s.image = 'frog/jump-left' 
        else: 
            s.next_frame = 6
            s.frame += 1
            if s.frame > 4:
                s.frame = 0
            if s.vx > 0:
                s.image = 'frog/walk-right-' + str(s.frame)
            elif s.vx < 0:
                s.image = 'frog/walk-left-' + str(s.frame)
Beispiel #36
0
    def loop(self):
        if self.dying != None:
            self.image = 'boss/%s-%d' % (self.facing,
                (self.game.frame / (FPS / 8)) % 8)
            if self.dying % 15 == 0:
                self.game.game.sfx['boss_explode'].play()
            if self.dying % 15 > 10:
                self.image = 'boss/%s-damage-%d' % (self.facing,
                    (self.game.frame / (FPS / 8)) % 8)
            self.dying += 1

            mid_frame = FPS * 3 / 2
            end_frame = FPS * 6 / 2

            if self.dying == mid_frame:
                # explode
                self.game.game.sfx['pop'].play()
                for n in xrange(128):
                    rect = pygame.Rect(random.randint(self.rect.left,
                        self.rect.right), random.randint(self.rect.top,
                        self.rect.bottom), 1, 1)
                    Bub(self.game, rect)

            if self.dying >= mid_frame:
                self.image = None

            if self.dying > end_frame:
                self.dead = True

            return

        if sprite.get_code(self.game, self, sign(self.vx), 0) == CODE_BOSS_TURN:
            self.vx = - self.vx

        if self.phase == 2:
            if self.phase_frames == 240 + 32:
                self.vy = 0
                self.vx = 1.2

        if self.vx > 0:
            self.facing = 'right'
        else:
            self.facing = 'left'

        self.rect.x += sprite.myinc(self.game.frame, self.vx)
        self.rect.y += sprite.myinc(self.game.frame, self.vy)

        self.image = 'boss/%s-%d' % (self.facing,
            (self.game.frame / (FPS / 8)) % 8)

        if self.taking_damage > 0:
            if self.taking_damage % 20 > 10:
                self.image = 'boss/%s-damage-%d' % (self.facing,
                (self.game.frame / (FPS / 8)) % 8)
            self.taking_damage -= 1

        self.phase_frames += 1

        if self.drop == 0:
            if self.vy == 0: # no bombing when flying up to the second phase
                Fireball(self.game, self.rect, self)
            if self.phase == 1:
                self.drop = 120
            if self.phase == 2:
                self.drop = 90
        s.drop -= 1
Beispiel #37
0
def loop(g, s):
    # sprite.apply_gravity(g,s)
    sprite.apply_standing(g, s)

    # if s.rect.x == s._prev.x: # or sprite.get_code(g,s,sign(s.vx),0) == CODE_RAIDER_TURN:
    #   s.vx = -s.vx

    s._prev = pygame.Rect(s.rect)

    if g.player.rect.centerx > s.rect.centerx:
        s.vx += 0.02
    elif g.player.rect.centerx < s.rect.centerx:
        s.vx -= 0.02

    if s.vx > 0.0:
        s.facing = 'right'
    elif s.vx < 0.0:
        s.facing = 'left'
    s.image = 'raider/raider-%s-%s' % (s.facing, (g.frame / 10) % 4)

    if sprite.get_code(g, s, sign(s.vx), 0) == CODE_RAIDER_TURN:
        s.vx = 0.0

    s.vx = min(1.0, s.vx)
    s.vx = max(-1.0, s.vx)

    if s.idling > 0:
        if s.idling % 40 > 20:
            s.facing = 'left'
        else:
            s.facing = 'right'
        s.idling -= 1
        if s.idling == 0:
            s.moving = 90
            # if g.game.random % 2 == 0:
            if random.randint(0, 1):
                s.vx = -s.speed
                s.facing = 'left'
            else:
                s.vx = s.speed
                s.facing = 'right'
    elif s.moving > 0:
        s.moving -= 1
        if s.moving == 0:
            s.idling = 80
            s.vx = 0
    else:
        s.idling = 80

    if s.vx < 0:
        s.facing = 'left'
    else:
        s.facing = 'right'

    s.image = 'raider/raider-%s-%s' % (s.facing, (s.frame / 5) % 2)
    s.frame += 1

    if s.shoot == 0:
        shot = raidershoot.init(g, s.rect, s)
        # g.sprites.append(shot)
        s.shoot = s.shoot_reload
        s.shooting = 5

    if s.shooting > 0:
        s.image = 'raider/raider-%s-shoot' % (s.facing)
        s.shooting -= 1

    s.shoot -= 1

    s.rect.x += sprite.myinc(g.frame, s.vx)
    s.rect.y += sprite.myinc(g.frame, s.vy)
Beispiel #38
0
def loop(g, s):
    sprite.apply_gravity(g, s)
    sprite.apply_standing(g, s)

    # if s.standing != None and s.vx != 0:
    # next_tile = g.layer[s.standing.pos[1]][s.standing.pos[0] + s.direction]
    # next2_tile = g.layer[s.standing.pos[1]][s.standing.pos[0] + s.direction*2]
    # if (next_tile.standable == 0) or (next2_tile.standable == 0):
    # s.rect.x = s._prev.x
    # s.direction = - s.direction
    # s.next_frame = 1

    if s.flying:
        if s._prev != None:
            if s.rect.x == s._prev.x or sprite.get_code(g, s, sign(s.vx), 0) == CODE_BAT_TURN:
                s.vx = -s.vx
                s.next_frame = 1
                if s.vx < 0:
                    s.facing = 'left'
                else:
                    s.facing = 'right'

        if s.standing != None and sprite.get_code(g, s, sign(s.vx), 1) == CODE_BAT_ATTACK:
            s.vy_attack = -4
            """
			if sprite.get_code(g,s,sign(s.vx)*2,1) == CODE_BAT_ATTACK:
				s.vy_attack = -3.0
				if sprite.get_code(g,s,sign(s.vx)*3,1) == CODE_BAT_ATTACK:
					s.vy_attack = -4.1
			"""
            s.attacking = True
            s.flying = False
            s.next_frame = 20
            s.image = 'bat/preattack-%s' % s.facing

        s._prev = pygame.Rect(s.rect)

        s.rect.x += s.vx
        s.rect.y += s.vy
    else:
        s._prev = pygame.Rect(s.rect)
        if (s.next_frame <= 0):
            if (s.standing != None):
                s.flying = True
                s.attacking = False
                s.next_frame = 1
            # s.vx*1
            vx = s.vx
            s.rect.x += sprite.myinc(g.frame, vx)
            s.rect.y += sprite.myinc(g.frame, s.vy)

    s.next_frame -= 1
    if s.next_frame == 0:
        if s.attacking:
            sprite.stop_standing(g, s)
            s.vy = s.vy_attack
            s.image = 'bat/attack-%s' % s.facing
        else:
            s.next_frame = 6
            s.frame += 1
            if s.frame > 2:
                s.frame = 0
            s.image = 'bat/fly-%s-%s' % (s.facing, s.frame)
Beispiel #39
0
def loop(g, s):
    sprite.apply_gravity(g, s)
    sprite.apply_standing(g, s)

    # if s.standing != None and s.vx != 0:
    # next_tile = g.layer[s.standing.pos[1]][s.standing.pos[0] + s.direction]
    # next2_tile = g.layer[s.standing.pos[1]][s.standing.pos[0] + s.direction*2]
    # if (next_tile.standable == 0) or (next2_tile.standable == 0):
    # s.rect.x = s._prev.x
    # s.direction = - s.direction
    # s.next_frame = 1

    if g.frame % s.speed == 0:
        if s.walking:
            if s._prev != None:
                if s.rect.x == s._prev.x or sprite.get_code(
                        g, s, sign(s.vx), 0) == CODE_ZOMBIE_TURN:
                    s.vx = -s.vx
                    s.next_frame = 1
                    if s.vx < 0:
                        s.facing = 'left'
                    else:
                        s.facing = 'right'

            if s.standing != None and sprite.get_code(g, s, sign(s.vx),
                                                      1) == CODE_ZOMBIE_JUMP:
                # s.vy_jump = -3.1
                """
				if sprite.get_code(g,s,sign(s.vx)*2,1) == CODE_ZOMBIE_JUMP:
					s.vy_jump = -3.0
					if sprite.get_code(g,s,sign(s.vx)*3,1) == CODE_ZOMBIE_JUMP:
						s.vy_jump = -4.1
				"""
                s.jumping = True
                s.walking = False
                s.next_frame = 20
                s.image = 'zombie/prejump-%s' % s.facing

            s._prev = pygame.Rect(s.rect)

            s.rect.x += s.vx
            s.rect.y += s.vy
        else:
            s._prev = pygame.Rect(s.rect)
            if (s.next_frame <= 0):
                if (s.standing != None):
                    s.walking = True
                    s.jumping = False
                    s.next_frame = 1
                # s.vx*1
                vx = s.vx
                s.rect.x += sprite.myinc(g.frame, vx)
                s.rect.y += sprite.myinc(g.frame, s.vy)

        s.next_frame -= 1
        if s.next_frame == 0:
            if s.jumping:
                sprite.stop_standing(g, s)
                s.vy = s.vy_jump
                s.image = 'zombie/jump-%s' % s.facing
            else:
                s.next_frame = s.frame_speed
                s.frame += 1
                if s.frame > 3:
                    s.frame = 0
                s.image = 'zombie/walk-%s-%s' % (s.facing, s.frame)