Beispiel #1
0
 def update( self, timestep):
     Activity.update( self, timestep)
     for x in self._widgets:
         x.update(timestep)
Beispiel #2
0
    def update(self, timestep):
        Activity.update(self, timestep)
 
        self.time += timestep
        pos = pygame.mouse.get_pos()
        self.mousepos = Vec2d( pos[0], 750-pos[1])
        pressed = pygame.mouse.get_pressed()
        self.update_status_text( timestep)
        self.victory_anim.cycle( timestep)
        self.enemy_anim.cycle( timestep)

        #deal with status text/images
        if self.status_offset < 0.0:
            self.status_offset += STATUS_SCROLL_SPEED*timestep
        
        #bail out now if the game is paused (or the player won)
        if self.game_mode == GAME_PAUSE or self.game_mode == GAME_WON:
            return None        
        
        #check for player off map
        if self.game_mode != GAME_OVER:
            pos = self.player.position
            if pos[0] < -200 or pos[1] < -200 or pos[0] > self.screen_size[0]+200 or pos[1] > self.screen_size[1]+200:
                self.kill_player()
        
        #enforce terminal velocity on player
        speed = self.player.velocity.get_length()
        self.max_speed = max(self.max_speed, speed)
        if speed > 1000.0:
            newspeed = (1-timestep)*1000.+timestep*speed
            self.player.velocity *= newspeed/speed
        
        if self.player_impact > 0.0:
            self.player_impact -= timestep
        
        #charge up the players launch speed
        if self.charging:
            self.charge_cap += CHARGERATE*timestep
            if self.charge_cap > MAXCHARGE:
                self.charge_cap = MAXCHARGE
            vec = self.mousepos - self.player.position
            if vec[0] > 0:
                self.player.facing = "right"
            else:
                self.player.facing = "left"
            self.charge = min(self.charge_cap, vec.get_length()/LAUNCH_IND_LEN)

        #handle dragging spinners
        if self.grabbed is not None:
            normvec = Vec2d(0,1)
            posvec = self.mousepos - self.grabbed.position
            self.drag_body.position = self.mousepos
            self.drag_body.velocity = 0, 0
            self.drag_body.reset_forces()

        for e in self.enemies:
            if (e.dir > 0 and e.position[0] > e.limits[1]) or (e.dir < 0 and e.position[0] < e.limits[0]):
                e.dir *= -1
            e.velocity = Vec2d( e.dir*100, e.velocity[1])
            
        #do forcefield updates
        for ff in self.forcefields:
            ff.imgoffset += ff.fieldforce*5*timestep
            if ff.point_query( self.player.position):
                self.player_launchable = True
                self.player.apply_impulse( ff.fieldforce*FORCEFIELD_STRENGTH*timestep*self.player.mass)
            
            if PARTICLE_PHYSICS:
                for p in self.particles:
                    if ff.point_query( p.position):
                        p.apply_impulse( ff.fieldforce*FORCEFIELD_STRENGTH*timestep*p.mass)

        #do particle decay
        #print len(self.particles)
        for p in self.particles:
            p.life -= timestep
            if p.life <= 0:
                self.space.remove( p, p.shape)
                self.particles.remove( p)

        
        for s in self.spinners:
            #force any draggable spinners to stop moving, reduces jitter and stuff
            if s.mode == "drag" and s != self.grabbed:
                s.angular_velocity = 0.0
                s.position = s.home_pos
                s.velocity = Vec2d(0,0)
            elif s.mode == "free":
                s.angular_velocity -= timestep*SPINNER_DAMPENING*s.angular_velocity
                

        #deal with gravity balls
        self.player_floating = False
        for g in self.gravballs:
            if g.shutdown:
                g.life += timestep
                if g.life > GRAVBALL_LIFE:
                    g.shutdown = False
                    g.life = GRAVBALL_LIFE            
                continue
        
            diff = g.position - self.player.position
            dist = diff.get_length()

            if dist < g.wellsize:
                g.life -= timestep
                if g.life < 0.0:
                    g.life = 0.0
                    g.shutdown = True

                d = max( math.pow(dist,1.25), 150)
                mag = (g.strength)/d*timestep
                force = self.player.mass*diff*mag/dist
                self.player.apply_impulse( force)
                self.player_launchable = True
                self.player_floating = True

            if PARTICLE_PHYSICS:
                for p in self.particles:
                    diff = p.position - g.position
                    dist = diff.get_length()
                    
                    if dist < g.wellsize:
                        d = max( math.pow(dist,1.25), 150)
                        mag = (g.strength)/d*timestep
                        force = p.mass*diff*mag/dist
                        p.apply_impulse( -force)
        
        #if the player is in a gravity well apply an impulse to cancel normal gravity
        if SPECIAL_GRAVITY and self.player_floating:
            self.player.apply_impulse( (0, self.player_float*timestep))

        self.space.step( timestep)