Пример #1
0
def loop(g, s):
    # check if we hit a wall...
    if s._prev != None:
        if s.rect.x == s._prev.x or sprite.get_code(g, s, sign(s.vx), 0) == CODE_PLATFORM_TURN:
            s.vx = -s.vx
        if s.rect.y == s._prev.y or sprite.get_code(g, s, 0, sign(s.vy)) == CODE_PLATFORM_TURN:
            s.vy = -s.vy
    s._prev = pygame.Rect(s.rect)

    s.rect.x += s.vx
    s.rect.y += s.vy
    for b in s.carrying:
        b.rect.x += s.vx
        b.rect.y += s.vy
Пример #2
0
def loop(g,s):
    #check if we hit a wall...
    if s._prev != None:
        if s.rect.x == s._prev.x or sprite.get_code(g,s,sign(s.vx),0) == CODE_PLATFORM_TURN:
            s.vx = -s.vx
        if s.rect.y == s._prev.y or sprite.get_code(g,s,0,sign(s.vy)) == CODE_PLATFORM_TURN:
            s.vy = -s.vy
    s._prev = pygame.Rect(s.rect)
    
    s.rect.x += s.vx
    s.rect.y += s.vy
    for b in s.carrying:
        b.rect.x += s.vx
        b.rect.y += s.vy
Пример #3
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)
Пример #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)
Пример #5
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)
Пример #6
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)
Пример #7
0
    def loop(self, game):
        #check if we hit a wall...
        if s._prev != None:
            if (self.rect.x == self._prev.x or sprite.get_code(game, 
                    self, sign(self.vx), 0) == CODE_PLATFORM_TURN):
                self.vx = - self.vx
            if (self.rect.y == self._prev.y or sprite.get_code(game,
                    self, 0, sign(self.vy)) == CODE_PLATFORM_TURN):
                self.vy = - self.vy

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

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

        for b in self.carrying:
            b.rect.x += self.vx
            b.rect.y += self.vy
Пример #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
Пример #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
Пример #10
0
def loop(g,s):
    #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:
            s.vx = -s.vx
            if s.vx > 0: s.facing = 'right'
            else:        s.facing = 'left'
    s._prev = pygame.Rect(s.rect)
    
    s.rect.x += s.vx*1
    s.rect.y += s.vy
    
    s.image = 'parrot/%s-%d'%(s.facing,(g.frame/(FPS/8))%4)
Пример #11
0
def event(g, s, e):
    #print 'player.event',e
    if s.door_timer != None or s.exploded > 0:
        return

    if e.type is USEREVENT and e.action == 'jump' and s.standing != None and s.jumping == 0 and s.vy == 0:
        sprite.stop_standing(g, s)
        #s.vy = -1.8
        s.vy = -0.5
        s.jumping = 1.4
        g.game.sfx['jump'].play()
    if e.type is USEREVENT and e.action == 'stop-jump':
        s.jumping = 0

    if e.type is USEREVENT and (e.action == 'up' or e.action == 'down'):
        if sprite.get_code(g, s, 0, 0) in DOOR_CODES:
            s.vx = 0
            s.vy = 0
            s.door_timer = DOOR_DELAY
            if s.current_door != None:  # It should never be None actually...
                #print "door!"
                s.current_door.open = DOOR_DELAY
            s.image = None
            s.door_pos = s.rect.centerx / TW, s.rect.centery / TH
            #tiles.t_put(g,(x,y), 0x32)
            #tiles.t_put(g,(x,y-1), 0x22)
    if e.type is USEREVENT and e.action == 'bubble':
        if s.powered_up:
            sprites.bubble.init(g, s.rect, s, big=True)
        else:
            sprites.bubble.init(g, s.rect, s, big=False)
        s.shooting = 10

    #MYCODE
    if e.type is USEREVENT and e.action == 'right':
        if s.vx < 2:
            s.vx += 2
        s.facing = 'right'
        #s.vx -= 1
    if e.type is USEREVENT and e.action == 'left':
        if s.vx > -2:
            s.vx -= 2
        s.facing = 'left'

    if e.type is KEYDOWN and e.key == K_F10:
        powerup(g, s)
        s.god_mode = True

    if e.type is KEYDOWN and e.key == K_F12:
        1 / 0
Пример #12
0
    def loop(self):
        self.apply_gravity()
        self.apply_standing()

        if (
            self.moving
            and self.rect.x == self._prev.x
            or (sprite.get_code(self.game, self, sign(self.vx), 0) == CODE_FIREGUY_TURN)
        ):
            self.vx = -self.vx

            if self.vx < 0:
                self.facing = "left"
            else:
                self.facing = "right"

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

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

        if self.idling > 0:
            if self.idling % 120 > 60:
                self.facing = "left"
            else:
                self.facing = "right"
            self.idling -= 1

            if self.idling == 0:
                self.moving = 90

                if random.randint(0, 1):
                    self.vx = -2
                    self.facing = "left"
                else:
                    self.vx = 2
                    self.facing = "right"

        elif self.moving > 0:
            self.moving -= 1
            if self.moving == 0:
                self.idling = 240
                self.vx = 0

        else:
            self.idling = 240

        self.image = "fireguy-%s-%s" % (self.facing, (self.frame / 5) % 2)
        self.frame += 1
Пример #13
0
def loop(g, s):
    #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:
            s.vx = -s.vx
            if s.vx > 0: s.facing = 'right'
            else: s.facing = 'left'
    s._prev = pygame.Rect(s.rect)

    s.rect.x += s.vx * 1
    s.rect.y += s.vy

    s.image = 'parrot/%s-%d' % (s.facing, (g.frame / (FPS / 8)) % 4)
Пример #14
0
def loop(g, s):
    sprite.apply_gravity(g, s)
    sprite.apply_standing(g, s)

    if s.moving and s.rect.x == s._prev.x or sprite.get_code(
            g, s, sign(s.vx), 0) == CODE_SENTINEL_TURN:
        s.vx = -s.vx
        if s.vx < 0:
            s.facing = 'left'
        else:
            s.facing = 'right'
    s._prev = pygame.Rect(s.rect)

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

    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 = 'sentinel/sentinel-%s-%s' % (s.facing, (s.frame / 5) % 2)
    s.frame += 1
Пример #15
0
def loop(g, s):
    sprite.apply_gravity(g, s)
    sprite.apply_standing(g, s)

    if s.moving and s.rect.x == s._prev.x or sprite.get_code(g, s, sign(s.vx), 0) == CODE_SENTINEL_TURN:
        s.vx = -s.vx
        if s.vx < 0:
            s.facing = 'left'
        else:
            s.facing = 'right'
    s._prev = pygame.Rect(s.rect)

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

    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 = 'sentinel/sentinel-%s-%s' % (s.facing, (s.frame / 5) % 2)
    s.frame += 1
Пример #16
0
def loop(g, s):
    if s.facing == 'left':
        if s.vx > 0:
            speed = 3
        else:
            speed = 1
    else:
        if s.vx > 0:
            speed = 1
        else:
            speed = 3

    if g.frame % speed == 0:
        if s._prev != None:
            if s.rect.x == s._prev.x or sprite.get_code(g, s, sign(s.vx), 0) == CODE_ROCK_TURN:
                s.vx = -s.vx
        s._prev = pygame.Rect(s.rect)

        s.rect.x += s.vx * 1
        s.rect.y += s.vy
Пример #17
0
def loop(g, s):
    sprite.apply_gravity(g, s)
    sprite.apply_standing(g, s)

    if s.moving and s.rect.x == s._prev.x or sprite.get_code(
            g, s, sign(s.vx), 0) == CODE_SENTINEL_TURN:
        s.vx = -s.vx
        if s.vx < 0:
            s.facing = 'left'
        else:
            s.facing = 'right'
    s._prev = pygame.Rect(s.rect)

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

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

    s.image = 'zombie/zombie-%s-%s' % (s.facing, (s.frame / 8) % 4)
    s.frame += 1
Пример #18
0
def loop(g, s):
    if s.facing == 'left':
        if s.vx > 0:
            speed = 3
        else:
            speed = 1
    else:
        if s.vx > 0:
            speed = 1
        else:
            speed = 3

    if g.frame % speed == 0:
        if s._prev != None:
            if s.rect.x == s._prev.x or sprite.get_code(g, s, sign(s.vx),
                                                        0) == CODE_ROCK_TURN:
                s.vx = -s.vx
        s._prev = pygame.Rect(s.rect)

        s.rect.x += s.vx * 1
        s.rect.y += s.vy
Пример #19
0
def loop(g, s):
    sprite.apply_gravity(g, s)
    sprite.apply_standing(g, s)

    if s.moving and s.rect.x == s._prev.x or sprite.get_code(g, s, sign(s.vx), 0) == CODE_SENTINEL_TURN:
        s.vx = -s.vx
        if s.vx < 0:
            s.facing = 'left'
        else:
            s.facing = 'right'
    s._prev = pygame.Rect(s.rect)

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

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

    s.image = 'zombie/zombie-%s-%s' % (s.facing, (s.frame / 8) % 4)
    s.frame += 1
Пример #20
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)
Пример #21
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)
def loop(g, s):
    sprite.apply_gravity(g, s)
    sprite.apply_standing(g, s)

    if s.moving and s.rect.x == s._prev.x or sprite.get_code(
            g, s, sign(s.vx), 0) == CODE_FIREGUY_TURN:
        s.vx = -s.vx
        if s.vx < 0:
            s.facing = 'left'
        else:
            s.facing = 'right'
    s._prev = pygame.Rect(s.rect)

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

    if s.idling > 0:
        if s.idling % 120 > 60:
            s.facing = 'left'
        else:
            s.facing = 'right'
        s.idling -= 1
        if s.idling == 0:
            s.moving = 90
            if g.game.random % 2 == 0:
                s.vx = -1
                s.facing = 'left'
            else:
                s.vx = 1
                s.facing = 'right'
    elif s.moving > 0:
        s.moving -= 1
        if s.moving == 0:
            s.idling = 240
            s.vx = 0
    else:
        s.idling = 240

    s.image = 'fireguy-%s-%s' % (s.facing, (s.frame / 5) % 2)
    s.frame += 1
Пример #23
0
def event(g,s,e):
    #print 'player.event',e
    if s.door_timer != None or s.exploded > 0:
        return

    if s.death_counter >= 0:
        return
    
    if e.type is USEREVENT and e.action == 'jump' and s.standing != None and s.jumping == 0 and s.vy == 0:
        sprite.stop_standing(g,s)
        #s.vy = -1.8
        s.vy = -0.1
        s.jumping = 1.2
        g.game.sfx['jump'].play()
    if e.type is USEREVENT and e.action == 'stop-jump':
        s.jumping = 0
        
    if e.type is USEREVENT and (e.action == 'up' or e.action == 'down'):
        if sprite.get_code(g,s,0,0) in DOOR_CODES:
            s.vx = 0
            s.vy = 0
            s.door_timer = DOOR_DELAY
            if s.current_door != None: # It should never be None actually...
                #print "door!"
                s.current_door.open = DOOR_DELAY
            s.image = None
            s.door_pos = s.rect.centerx/TW,s.rect.centery/TH
            #tiles.t_put(g,(x,y), 0x32)
            #tiles.t_put(g,(x,y-1), 0x22)
    if e.type is USEREVENT and e.action == 'shoot':
        if s.powered_up:
            sprites.shoot.init(g,s.rect,s,big=True)
        else:
            sprites.shoot.init(g,s.rect,s,big=False)
        s.shooting = 10
        
    if e.type is KEYDOWN and e.key == K_F10:
        powerup(g,s)
        s.god_mode = True
Пример #24
0
def loop(g,s):
    sprite.apply_gravity(g,s)
    sprite.apply_standing(g,s)
    
    if s.moving and s.rect.x == s._prev.x or sprite.get_code(g,s,sign(s.vx),0) == CODE_FIREGUY_TURN:
        s.vx = -s.vx
        if s.vx < 0:
            s.facing = 'left'
        else:
            s.facing = 'right'
    s._prev = pygame.Rect(s.rect)
    
    s.rect.x += s.vx
    s.rect.y += s.vy

    if s.idling > 0:
        if s.idling % 120 > 60:
            s.facing = 'left'
        else:
            s.facing = 'right'
        s.idling -= 1
        if s.idling == 0:
            s.moving = 90
            if g.game.random % 2 == 0:
                s.vx = -1
                s.facing = 'left'
            else:
                s.vx = 1
                s.facing = 'right'
    elif s.moving > 0:
        s.moving -= 1
        if s.moving == 0:
            s.idling = 240
            s.vx = 0
    else:
        s.idling = 240
        
    s.image = 'fireguy-%s-%s' % (s.facing, (s.frame / 5) % 2)
    s.frame += 1
Пример #25
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'
Пример #26
0
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'
Пример #27
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)
Пример #28
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)
Пример #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)
Пример #30
0
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
Пример #31
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)
Пример #32
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)
Пример #33
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)
Пример #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.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)
Пример #35
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
Пример #36
0
def event(g, s, e):
    # print 'player.event',e

    enemy_sprites = g.sprites[:]

    if s.door_timer is not None or s.exploded > 0:
        return

    if s.death_counter >= 0:
        return

    if s.jetpack == "double_jump":
        if e.type is USEREVENT and e.action == 'jump' and s.standing is not None and s.jumping == 0 and s.vy == 0:
            sprite.stop_standing(g, s)

            s.double_jumping = 1

            s.jumping = 1.18

            g.game.sfx['jump'].play()
        elif e.type is USEREVENT and e.action == 'jump' and s.double_jumping == 1:
            sprite.stop_standing(g, s)

            s.double_jumping = 0

            if s.vy > 0:
                #print("Down timer = %d" % s.jump_timer)
                if s.jump_timer >= 8:
                    s.jumping = 1.20
                elif 8 > s.jump_timer >= 2:
                    s.jumping = 1.25
                elif s.jump_timer < 2:
                    s.jumping = 1.60
            else:
                #print("UP timer = %d" % s.jump_timer)
                s.jumping = 0.60

            g.game.sfx['jump'].play()

    elif s.jetpack == "fly":
        if e.type is USEREVENT and e.action == 'jump':
            sprite.stop_standing(g, s)

            # s.vy = 0
            s.jumping = 0.4
            g.game.sfx['jump'].play()

    else:
        if e.type is USEREVENT and e.action == 'jump' and s.standing is not None and s.jumping == 0 and s.vy == 0:
            sprite.stop_standing(g, s)

            # s.vy = 0
            s.jumping = 1.21
            g.game.sfx['jump'].play()

    if e.type is USEREVENT and e.action == 'stop-jump':
        s.jumping = 0

    if e.type is USEREVENT and (e.action == 'up' or e.action == 'down'):
        if sprite.get_code(g, s, 0, 0) in DOOR_CODES:
            s.vx = 0
            s.vy = 0
            s.door_timer = DOOR_DELAY
            if s.current_door is not None:  # It should never be None actually...
                # print "door!"
                s.current_door.open = DOOR_DELAY
            s.image = None
            s.door_pos = s.rect.centerx / TW, s.rect.centery / TH
            # tiles.t_put(g,(x,y), 0x32)
            # tiles.t_put(g,(x,y-1), 0x22)

    if e.type is USEREVENT and e.action == 'shoot':
        enemy_objective = None
        for enemy in enemy_sprites:
            if "enemy" in enemy.groups:
                enemy_objective = enemy
        if s.canshoot:
            if s.powered_up == 'granadelauncher':
                s.shoot = sprites.shoot.init(g,
                                             s.rect,
                                             s,
                                             s.powered_up,
                                             enemy_objective,
                                             granade=1)
                s.shoot = sprites.shoot.init(g,
                                             s.rect,
                                             s,
                                             s.powered_up,
                                             enemy_objective,
                                             granade=2)
                s.shoot = sprites.shoot.init(g,
                                             s.rect,
                                             s,
                                             s.powered_up,
                                             enemy_objective,
                                             granade=3)
            else:
                s.shoot = sprites.shoot.init(g, s.rect, s, s.powered_up,
                                             enemy_objective)
            s.shooting = 10
            s.canshoot = False
    """
    if e.type is USEREVENT and e.action == 'stop-shoot':
        if s.powered_up == "granadelauncher" and s.shoot.active is True:
            explosion.init(g, s.shoot.rect, s.shoot)
            s.shoot.active = False
    """

    if e.type is KEYDOWN and e.key == K_F10:

        g.game.chips = [True, True, True, True]

        g.game.powerup = "laser"

        g.game.weapons[0] = 'gun'
        g.game.weapons[1] = 'shootgun'
        g.game.weapons[2] = 'cannon'
        g.game.weapons[3] = 'granadelauncher'
        g.game.weapons[4] = 'laser'

        g.game.drone = "killer"

        g.game.drones[0] = "guardian"
        g.game.drones[1] = "defender"
        g.game.drones[2] = "killer"

        g.game.jetpack = "fly"

        g.game.jetpacks[0] = "jump"
        g.game.jetpacks[1] = "double_jump"
        g.game.jetpacks[2] = "fly"

        s.god_mode = True
Пример #37
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
Пример #38
0
def event(g, s, e):
    # print 'player.event',e

    enemy_sprites = g.sprites[:]

    if s.door_timer is not None or s.exploded > 0:
        return

    if s.death_counter >= 0:
        return

    if s.jetpack == "double_jump":
        if e.type is USEREVENT and e.action == 'jump' and s.standing is not None and s.jumping == 0 and s.vy == 0:
            sprite.stop_standing(g, s)

            s.double_jumping = 1

            s.jumping = 1.18

            g.game.sfx['jump'].play()
        elif e.type is USEREVENT and e.action == 'jump' and s.double_jumping == 1:
            sprite.stop_standing(g, s)

            s.double_jumping = 0

            if s.vy > 0:
                #print("Down timer = %d" % s.jump_timer)
                if s.jump_timer >= 8:
                    s.jumping = 1.20
                elif 8 > s.jump_timer >= 2:
                    s.jumping = 1.25
                elif s.jump_timer < 2:
                    s.jumping = 1.60
            else:
                #print("UP timer = %d" % s.jump_timer)
                s.jumping = 0.60

            g.game.sfx['jump'].play()

    elif s.jetpack == "fly":
        if e.type is USEREVENT and e.action == 'jump':
            sprite.stop_standing(g, s)

            # s.vy = 0
            s.jumping = 0.4
            g.game.sfx['jump'].play()

    else:
        if e.type is USEREVENT and e.action == 'jump' and s.standing is not None and s.jumping == 0 and s.vy == 0:
            sprite.stop_standing(g, s)

            # s.vy = 0
            s.jumping = 1.21
            g.game.sfx['jump'].play()

    if e.type is USEREVENT and e.action == 'stop-jump':
        s.jumping = 0

    if e.type is USEREVENT and (e.action == 'up' or e.action == 'down'):
        if sprite.get_code(g, s, 0, 0) in DOOR_CODES:
            s.vx = 0
            s.vy = 0
            s.door_timer = DOOR_DELAY
            if s.current_door is not None:  # It should never be None actually...
                # print "door!"
                s.current_door.open = DOOR_DELAY
            s.image = None
            s.door_pos = s.rect.centerx / TW, s.rect.centery / TH
            # tiles.t_put(g,(x,y), 0x32)
            # tiles.t_put(g,(x,y-1), 0x22)

    if e.type is USEREVENT and e.action == 'shoot':
        enemy_objective = None
        for enemy in enemy_sprites:
            if "enemy" in enemy.groups:
                enemy_objective = enemy
        if s.canshoot:
            if s.powered_up == 'granadelauncher':
                s.shoot = sprites.shoot.init(g, s.rect, s, s.powered_up, enemy_objective, granade=1)
                s.shoot = sprites.shoot.init(g, s.rect, s, s.powered_up, enemy_objective, granade=2)
                s.shoot = sprites.shoot.init(g, s.rect, s, s.powered_up, enemy_objective, granade=3)
            else:
                s.shoot = sprites.shoot.init(g, s.rect, s, s.powered_up, enemy_objective)
            s.shooting = 10
            s.canshoot = False
    """
    if e.type is USEREVENT and e.action == 'stop-shoot':
        if s.powered_up == "granadelauncher" and s.shoot.active is True:
            explosion.init(g, s.shoot.rect, s.shoot)
            s.shoot.active = False
    """

    if e.type is KEYDOWN and e.key == K_F10:

        g.game.chips = [True, True, True, True]

        g.game.powerup = "laser"

        g.game.weapons[0] = 'gun'
        g.game.weapons[1] = 'shootgun'
        g.game.weapons[2] = 'cannon'
        g.game.weapons[3] = 'granadelauncher'
        g.game.weapons[4] = 'laser'

        g.game.drone = "killer"

        g.game.drones[0] = "guardian"
        g.game.drones[1] = "defender"
        g.game.drones[2] = "killer"

        g.game.jetpack = "fly"

        g.game.jetpacks[0] = "jump"
        g.game.jetpacks[1] = "double_jump"
        g.game.jetpacks[2] = "fly"

        s.god_mode = True
Пример #39
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)
Пример #40
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