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)
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)
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)
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)
def loop(g, s): a.timer -= 1 if a.timer > 0: return if a.timer == 0: g.game.sfx['fally'].play() sprite.apply_gravity(g, s) s.rect.y += s.vy
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 * 1 s.rect.y += s.vy
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)
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
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
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
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)
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
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)
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
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
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
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)
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
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_WIBERT_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 = 'wibert/wibert-%s-%s' % (s.facing, (g.frame / 10) % 4) if sprite.get_code(g, s, sign(s.vx), 0) == CODE_WIBERT_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 = 'wibert/wibert-%s-%s' % (s.facing, (s.frame / 5) % 2) s.frame += 1 if s.shoot == 0: shot = wibertshoot.init(g, s.rect, s) # g.sprites.append(shot) s.shoot = s.shoot_reload s.shooting = 5 if s.shooting > 0: s.image = 'wibert/wibert-%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): 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): 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): 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)
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_WIBERT_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 = 'wibert/wibert-%s-%s' % (s.facing, (g.frame / 10) % 4) if sprite.get_code(g, s, sign(s.vx), 0) == CODE_WIBERT_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 = 'wibert/wibert-%s-%s' % (s.facing, (s.frame / 5) % 2) s.frame += 1 if s.shoot == 0: shot = wibertshoot.init(g, s.rect, s) # g.sprites.append(shot) s.shoot = s.shoot_reload s.shooting = 5 if s.shooting > 0: s.image = 'wibert/wibert-%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): 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'
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
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)