Пример #1
0
    def __init__(self, *args, **kwargs):
##        super(Entity, self).__init__(x,y,w,h)
        super(Entity, self).__init__(*args, **kwargs)
        
        # The maximum velocity of this object (as a vector) in pixels/second
        self.maxVelocity = None

        # The maximum angular speed of this object in degrees/second
        self.maxAngularVelocity = None

        # motion properties
        # (Be careful setting these directly, since they're used as if they
        # were Vector objects!)
        self._velocity = point.Vector(0,0)
        self._accel = point.Vector(0,0)
        self._drag = point.Vector(0,0)

        # We define angular velocity as a scalar, not a vector, but we still
        # need a getter and setter, so that we can clamp to maxAngularVelocity.
        self._angular = 0.0

        # The angular acceleration of this object in degrees/second^2
        # (we don't really need a property for this, since it's a scalar)
        self.angularAcceleration = 0.0

        # rotating sprites use more CPU, so leave this cleared if this sprite
        # isn't rotating, leaving more time for other rendering
        self.rotating = False

        # does this sprite move?
        self.fixed = False
Пример #2
0
    def _set_velocity(self, val):
        if self.maxVelocity:
            _vx, _vy = val

            if abs(self.maxVelocity.x) < abs(_vx):
                _vx = self.maxVelocity.x * util.sign(_vx)
            if abs(self.maxVelocity.y) < abs(_vy):
                _vy = self.maxVelocity.y * util.sign(_vy)

            self._velocity = point.Vector(_vx, _vy)
        else:
            self._velocity = point.Vector(val)
        self.redraw()
Пример #3
0
def vectorFromAngle(theta):
    """Returns a vector pointing away from the origin at a specific angle
       (in degrees). This is essentially the same as converting the polar
       coordinates (1,theta) to rectangular.

       @param theta: The angle in degrees.
    """
    rad = math.radians(theta)
    # polar-to-rectangular is (r cos \theta, r sin \theta)
    # pygame's y-coordinate grows downward, hence the minus sign
    return point.Vector(math.cos(rad), -math.sin(rad))
Пример #4
0
 def effect(self):
     """Update the effect by moving sprites around. Non-scrolling sprites
        (such as overlays) are unaffected, since it is assumed that those
        sprites are meant to be stationary.
     """
     # the "quake" effect is simply moving the camera by a random amount
     # each frame, the intensity value is just how big the random numbers
     # are relative to the screen size
     rx = random.uniform(-self.intensity * Game.width,
                         self.intensity * Game.width)
     ry = random.uniform(-self.intensity * Game.height,
                         self.intensity * Game.height)
     Game.scroll = self.__origscroll + point.Vector(rx, ry)
Пример #5
0
    def followBounds(self, followMin=None, followMax=None):
        """Sets the range in which the camera is allowed to move.

           If both parameters, C{followMin} and C{followMax}, are None,
           then the game world's extents are set to be the same as the screen.
           
           @param followMin: The top-left corner of the game world.
           @param followMax: The bottom-right corner of the game world.
        """
        if followMin is None:
            followMin = point.Vector(0, 0)
        if followMax is None:
            followMax = point.Vector(self.width, self.height)

        # The minimum follow value is the top-left corner of the game world,
        # and the maximum is the bottom-right. We can just use followMin as is,
        # but we have to adjust followMax to take into account the size of the
        # screen. We do this _after_ setting the world boundaries, though,
        # because it saves typing and it might be slightly faster.
        self._followMin = point.Vector(followMin)
        self._followMax = point.Vector(followMax)
        self._bounds = Game.Rect(followMin, self._followMax - self._followMin)
        self._followMax -= (self.width, self.height)
        self._doCameraFollow()
Пример #6
0
    def _doCameraFollow(self):
        """Helper function to move the camera to follow an object."""
        if self.focus is not None:
            _target = point.Vector(self.focus.position -
                                   self.getScreenCenter())

            if self._focusLead:
                _target += self.velocity * self._focusLead

            Game.scroll += (_target - Game.scroll
                            ) * self._followSpeed * Game.elapsed / 1000.0

            # _followMin/_followMax are the camera boundaries
            if self._followMin is not None:
                if Game.scroll.x < self._followMin.x:
                    Game.scroll.x = self._followMin.x
                if Game.scroll.y < self._followMin.y:
                    Game.scroll.y = self._followMin.y
            if self._followMax is not None:
                if Game.scroll.x > self._followMax.x:
                    Game.scroll.x = self._followMax.x
                if Game.scroll.y > self._followMax.y:
                    Game.scroll.y = self._followMax.y
Пример #7
0
 def __get_size(self):
     return point.Vector(self._w, self._h)
Пример #8
0
 def _get_pos(self):
     return point.Vector(self.x, self.y)
Пример #9
0
 def _set_drag(self, val):
     self._drag = point.Vector(val)
Пример #10
0
 def _set_accel(self, val):
     self._accel = point.Vector(val)
     self.redraw()