Esempio n. 1
0
    def levelstart_start(self):
        self.skipping = game.timeleft > 0.0
        self.levelnum += 1
        del self.boxobjs[:]
        self.newboxes, self.startpos, msg, num = levels.makelevel(
            self.levelnum)
        random.shuffle(self.newboxes)
        self.calcboxes = num
        self.addtime = 2
        if game.clock.get_fps() < 25:
            self.addtime = 1
        self.hud.drawlevel(self.levelnum)
        if game.comments >= 2:
            self.textobjs.append(objtext.Text(msg))
        self.grabbedboxes = 0
        self.numdeaths = 0
        for b in self.guardobjs:
            b.nofire()

        if self.levelnum > game.player.score:
            game.player.score = self.levelnum
        if not self.newcontinue and game.player.start_level(
        ) > self.startlevel:
            self.newcontinue = 1

        for i in range(
                levels.numrocks(self.levelnum) - len(self.asteroidobjs)):
            self.asteroidobjs.append(objasteroid.Asteroid())

        for p in self.powerupobjs:
            p.extendtime()

        if self.skipping: self.skiptime = 20

        #teleport in dead guards
        for g in self.guardobjs:
            if g.killed == 1:
                self.smokeobjs.append(objguard.TeleGuard(g))
                g.killed = 2

        #make spikes
        if self.levelnum >= 30:
            numspikes = min(
                int((self.levelnum - 30) // 5) + 1,
                len(self.newboxes) - 5)
            self.secretspikes = self.newboxes[-numspikes:]
        elif self.levelnum >= 10:
            numspikes = int((self.levelnum - 10) // 7) + 1
            spikes = self.newboxes[-numspikes:]
            self.newboxes = self.newboxes[:-numspikes]
            for b in spikes:
                s = objbox.Spike(b.rect.topleft)
                self.spikeobjs.append(s)
            self.secretspikes = []
            self.touchingsecretspike = None
        else:
            self.secretspikes = []
            self.touchingsecretspike = None

        #rotate music
        if pygame.time.get_ticks() - self.songtime > game.musictime:
            songs = list(Songs)
            songs.remove(self.song)
            self.song = random.choice(songs)
            snd.playmusic(*self.song)
            self.songtime = pygame.time.get_ticks()
Esempio n. 2
0
    def normal_tick(self):
        #fire the guards
        shootchance = game.guard_fire * self.speedadjust
        if self.player.active and random.random() < shootchance:
            self.powerupcount += 0.3
            baddy = random.choice(self.guardobjs)
            baddy.fire()  #only requests a shot
        for baddy in self.guardobjs:
            shotspot, shotdir = baddy.shotinfo()
            if shotspot:
                s = objshot.Shot(shotspot, shotdir)
                self.shotobjs.append(s)
                snd.play('shoot', 1.0, shotspot[0])

        #add a powerup if ready
        if self.powerupcount >= game.powerupwait:
            self.powerupcount = 0.0
            p = objpowerup.newpowerup(self.levelnum)
            self.powerupobjs.append(p)
            snd.play('spring', 0.6)
            gamehelp.help("powerup", p.rect.topleft)
        if self.grabbedboxes >= 50:
            self.grabbedboxes = 0
            if game.comments >= 1:
                self.textobjs.append(
                    objtext.Text(game.Complements[self.complement]))
            self.complement = int(
                (self.complement + 1) % len(game.Complements))
        elif self.grabbedboxes >= 20:
            self.numdeaths = 0

        self.tickleveltime(self.speedadjust)

        playerrect = self.player.rect.inflate(-1, -1)
        playercollide = playerrect.colliderect
        #collide player to boxes
        if self.touchingsecretspike:
            if not playercollide(self.touchingsecretspike.rect):
                #self.boxobjs.remove(self.touchingsecretspike)
                self.spikeobjs.append(
                    objbox.Spike(self.touchingsecretspike.rect.topleft))
                self.boxobjs.remove(self.touchingsecretspike)
                self.touchingsecretspike = None
        for b in self.boxobjs:
            status = b.playercollide(playerrect)
            if status:
                self.grabbedboxes += 1
                self.powerupcount += 0.6
                if b in self.secretspikes:
                    self.touchingsecretspike = b
                    self.secretspikes.remove(b)
                    snd.play('klank2', 0.7, self.player.rect.centerx)
                elif status == 1:
                    self.powerupcount += 0.3
                    self.boxobjs.remove(b)
                    self.popobjs.append(b)
        #collide player to powerups
        for p in self.powerupobjs:
            if playercollide(p.rect):
                p.dead = 1
                effect = p.effect()
                if game.comments >= 2:
                    self.textobjs.append(
                        objtext.Text('"' + effect.__doc__ + '"'))
                self.powereffects.append(effect)
                gamehelp.help(effect.__doc__, self.player.rect.center)
        playerrect = playerrect.inflate(-6, -6)
        playercollide = playerrect.colliderect
        asteroidrects = [o.colliderect for o in self.asteroidobjs]
        hitbullet = 0
        #collide player and asteroids to bullets
        for s in self.shotobjs:
            r = s.rect
            if playercollide(r):
                s.dead = 1
                if not self.player.shield:
                    self.changestate('playerdie')
                    hitbullet = 1
                else:
                    self.popobjs.append(objpopshot.PopShot(s.rect.center))
            for ar in asteroidrects:
                if ar.colliderect(r) and not s.dead:
                    s.dead = 1
                    self.popobjs.append(objpopshot.PopShot(s.rect.center))
                    break
        #collide player to spikes
        for s in self.spikeobjs:
            if s.armed and playercollide(s.rect):
                s.dead = 1
                self.changestate('playerdie')
                hitbullet = 1
        #collide player to asteroids
        if not hitbullet:
            for a, r in zip(self.asteroidobjs, asteroidrects):
                if playercollide(r):
                    self.changestate('playerdie')
                    a.dead = 1
                    self.popobjs.append(objpopshot.PopShot(r.center))

        if not self.boxobjs:
            self.changestate('levelend')

        #blow smoke (turbo)
        self.clocks += 1
        if self.player.turbo and (self.player.move[0] or self.player.move[1]
                                  ) and gfx.surface.get_bytesize() > 1:
            self.smokeobjs.append(objsmoke.Smoke(self.player.rect.center))
            if game.clock.get_fps() > 35.0:
                self.smokeobjs.append(objsmoke.Smoke(self.player.rect.center))

        self.runobjects(self.objlists)