Exemple #1
0
 def validate_entity_location(self, entity):
     """Entities should call when they change their own location.
     
     Has a side effect of correcting entity locations at the boundaries,
     something entities shouldn't have to know about, as well as updating
     spatial indexes (something entities also shouldn't have to know about).
     
     This is experimental. This makes me want to rethink how objects are
     managed in the world and how movement occurs.
     
     entity {Entity} An entity with a location.
     """
     # Operate to speed up the writing.
     entity.location[0] = mmval(self.width, entity.location[0])
     entity.location[1] = mmval(self.height, entity.location[1])
     
     self.spatial_index.update(entity)
    def zoom_level(self, value):
        """{int}
        """
        # Boundary check.
        self._zoom_level = mmval(len(self.zoom_level_dims)-1, value, 0)

        # Resize the viewable area.
        self.rect.width = self.zoom_area_width
        self.rect.height = self.zoom_area_height
        
        # Correct the center point.
        self.move(*self.rect.center)
    def move(self, x=None, y=None):
        """Moves the viewport and adjusts the dimensions of the bounding
        rectangle.
        
        (x, y) make up the new center coordinate for the viewport.
        
        Needs to be called to to after zoom level changes, too.
        """
        
        max_width = self.maximim_zoom_dims[0]
        max_height = self.maximim_zoom_dims[1]
        
        # Default to the center of the largest view.
        x = x if x != None else max_width/2
        y = y if y != None else max_height/2

        # Test to see if viewport center is out of range after the the zoom, 
        # if so, fix'um up.  This can happen if you're at the edge of the 
        # screen and then zoom out - the center will be close to the edge.
        x = mmval(max_width - self.zoom_area_width/2, x, self.zoom_area_width/2)
        y = mmval(max_height - self.zoom_area_height/2, y, self.zoom_area_height/2)

        # Update the visible area.
        self.rect.center = (x, y)
Exemple #4
0
 def process(self, time_passed):
     """Manage velocity.
     """
     if self.target_speed != None and self.target_speed != self.speed:
         direction = 1 if self.target_speed > self.speed else -1
         delta = time_passed * self.acceleration
         speed = self.speed + math.copysign(delta, direction)
         self.speed = mmval(self.target_speed, speed)
     
     if self.target_course != None and self.target_course != self.course:
         angleto = self.course.angleto(self.target_course)
         direction = -1 if angleto <= 0 else 1
         delta = direction * time_passed * self.rotation_speed
         if abs(delta) <= abs(angleto):
             self.course += delta
         else:
             self.course = self.target_course
             
     loc = self.entity.location
     dx, dy = self.deltaxy
     self.entity.location = loc[0]+dx*time_passed, loc[1]+dy*time_passed
Exemple #5
0
 def target_speed(self, value):
     self._target_speed = mmval(self.max_speed, float(value)) if value is not None else None
Exemple #6
0
 def val(self, value):
     self._val = mmval(self.max, value, self.min)