示例#1
0
    def SetTexture(self, texture, forcedSize=None, shaderPass=None):
        self.sprite = Sprite(texture)
        self.shaderPass = shaderPass

        self.forcedSize = Vec2(forcedSize)

        self.sprite.origin = Vec2(texture.size) / 2
示例#2
0
 def Step(self):
     if self.target:
         diff = Vec2(self.target.position) - Vec2(self.entity.position)
         dist = max(
             self.entity.position.get_distance(self.target.position)**2, 3)
         direction = diff.normalized()
         self.entity.FetchComponent(
             VelocityComponent).velocity = self.entity.FetchComponent(
                 VelocityComponent).velocity + direction * (
                     (self.factor * self.core.time.GetDelta()) / (dist))
示例#3
0
    def __init__(self, position=Vec2(0, 0), rotation=0.0, size=Vec2(100, 100)):
        """Constructor

        :param position: Coordinates at which entity will be created
        :type position: Vec2
        :param rotation: Initial entity rotation, degrees
        :type rotation: float
        :param size: Size of entities' bounding box
        :type size: Vec2"""
        Entity.__init__(self, position, rotation, size)
        self.components = []
示例#4
0
 def SetTexture(self, texture, shaderPass=None, hasDirectionSheet=False):
     self.sprite = Sprite(
         texture,
         Rectangle((0, 0),
                   (texture.size.x /
                    (8 if hasDirectionSheet else 1), texture.size.y)))
     self.shaderPass = shaderPass
     self.hasDirectionSheet = hasDirectionSheet
     self.sprite.ratio = Vec2(self.scale, self.scale)
     self.sprite.origin = Vec2(
         texture.size.x /
         (8 if hasDirectionSheet else 1), texture.size.y) / 2
示例#5
0
    def __init__(self, size, position=(0, 0), angle=0.0):
        """Constructor

        :param size: The size of the rectangle
        :type size: :class:`PyNARGE.Vec2`
        :param position: Where the physics body should be spawned
        :type position: :class:`PyNARGE.Vec2`
        :param angle: The body's initial rotation, degrees
        :type angle: float"""
        self.size = Vec2(size)
        self.position = Vec2(position)
        self.angledeg = angle
        self.anglerad = 3.141 * float(angle) / 180.0
示例#6
0
    def __init__(self, size, position=(0, 0), friction=0.3, density=1.0):
        """Constructor

        :param size: The size of the rectangle
        :type size: :class:`PyNARGE.Vec2`
        :param position: Where the physics body should be spawned
        :type position: :class:`PyNARGE.Vec2`
        :param friction: How much friction the object will experience [0-1]
        :type friction: float
        :param density: How dense the object will be
        :type density: float"""
        self.size = Vec2(size)
        self.position = Vec2(position)
        self.body = None
        self.friction = friction
        self.density = density
示例#7
0
 def __init__(self, core):
     self.core = core
     self.window = None
     self.size = Vec2(0, 0)
     self.shaderpasses = []
     self.cameraView = None
     self.uiView = None
示例#8
0
    def SetCameraPosition(self, position):
        """Set the camera's position in world coordinates

        :param position: The camera's position
        :type position: :class:`PyNARGE.Vec2`"""
        self.cameraView.center = Vec2(position)
        for p in self.shaderpasses:
            p.SetCenter(position)
示例#9
0
    def __init__(self, texture, shaderPass=None, hasDirectionSheet=False):
        self.sprite = Sprite(
            texture,
            Rectangle((0, 0),
                      (texture.size.x /
                       (8 if hasDirectionSheet else 1), texture.size.y)))
        self.shaderPass = shaderPass
        self.alpha = 255
        self.scale = pixelDoubleFactor
        self.hasDirectionSheet = hasDirectionSheet

        self.sprite.origin = Vec2(
            texture.size.x /
            (8 if hasDirectionSheet else 1), texture.size.y) / 2

        self.sprite.color = Color(255, 255, 255, self.alpha)
        self.sprite.ratio = Vec2(self.scale, self.scale)
示例#10
0
    def _Init(self):
        self.Build()

        if self.core.settings.label_entity_types:
            self.AddComponent(
                TextComponent(str(type(self).__name__),
                              self.core.resourceManager.FetchDefaultFontMono(),
                              12, Vec2(0, -10)))

        for component in self.components:
            component.Init()
        self.Init()
示例#11
0
 def __init__(self,
              text,
              font=None,
              size=20,
              color=Color.WHITE,
              offset=Vec2(0, 0)):
     self.message = text
     self.offset = offset
     self.size = size
     self.font = font
     self.color = color
     self.scale = 1.0
示例#12
0
    def __init__(self,
                 texture,
                 forcedSize=None,
                 shaderPass=None,
                 offset=(0, 0)):
        self.sprite = Sprite(texture)
        self.shaderPass = shaderPass
        self.offset = Vec2(offset)
        self.alpha = 255
        self.scale = 1
        self.forcedSize = None
        if forcedSize != None:
            self.forcedSize = Vec2(forcedSize)

        self.sprite.origin = Vec2(texture.size) / 2

        self.sprite.color = Color(255, 255, 255, self.alpha)

        self.sprite.ratio = Vec2(self.scale, self.scale)
        if self.forcedSize != None:
            self.sprite.scale(
                (float(self.forcedSize.x) / float(self.sprite.texture.size.x),
                 float(self.forcedSize.y) / float(self.sprite.texture.size.y)))
示例#13
0
    def __init__(self, radius, position=(0, 0), friction=0.3, density=1.0):
        """Constructor

        :param radius: The radius of the circular body
        :type radius: float
        :param position: Where the physics body should be spawned
        :type position: :class:`PyNARGE.Vec2`
        :param friction: How much friction the object will experience [0-1]
        :type friction: float
        :param density: How dense the object will be
        :type density: float"""
        self.radius = float(radius)
        self.position = Vec2(position)
        self.body = None
        self.friction = friction
        self.density = density
示例#14
0
    def Initialize(self,
                   title="PyNARGE Window",
                   size_x=800,
                   size_y=600,
                   fullscreen=False,
                   antialiasing=False):
        print "Creating render window..."
        self.size = Vec2(size_x, size_y)
        self.window = sfml.RenderWindow(
            sfml.VideoMode(size_x, size_y), title, sfml.window.Style.FULLSCREEN
            if fullscreen else sfml.window.Style.DEFAULT,
            sfml.window.ContextSettings(0, 0, 8) if antialiasing else None)
        self._draw = self.window.draw

        self.cameraView = self.window.default_view
        self.uiView = self.window.default_view

        if self.core.settings.limit_framerate:
            self.window.framerate_limit = 60
示例#15
0
    def Draw(self):
        self.sprite.position = Vec2(
            1 + pixelDoubleFactor *
            int(self.entity.position.x / pixelDoubleFactor),
            pixelDoubleFactor *
            int(self.entity.position.y / pixelDoubleFactor))
        self.sprite.rotation = -self.entity.rotation + 22.5
        self.sprite.rotation %= 360

        if self.hasDirectionSheet:
            index = int(self.sprite.rotation / 45)
            self.sprite.rotation = 0
            self.sprite.texture_rectangle = Rectangle(
                (index * self.sprite.texture.size.x / 8, 0),
                (self.sprite.texture.size.x / 8, self.sprite.texture.size.y))
        else:
            self.sprite.rotation = int(self.sprite.rotation / 90) * 90

        self.core.renderer.Draw(self.sprite, self.shaderPass)
示例#16
0
 def ReCenter(self):
     self.text.origin = Vec2(self.text.local_bounds.size.x / 2,
                             self.size / 2)
示例#17
0
    def GetCameraPosition(self):
        """Get the camera's position in world coordinates

        :returns: :class:`PyNARGE.Vec2` - The camera's position"""
        return Vec2(self.cameraView.center)
示例#18
0
 def SetVelocity(self, velocity):
     self.velocity = Vec2(velocity)
示例#19
0
 def Init(self, startingVelocity=Vec2(0, 0)):
     self.velocity = startingVelocity
示例#20
0
 def SetOffset(self, offset):
     self.offset = Vec2(offset)
示例#21
0
 def __init__(self, target=None, offset=Vec2(0, 0)):
     self.target = target
     self.offset = Vec2(offset)
示例#22
0
 def LocalToScreen(self, coords):
     return Vec2(
         float(coords.x) * self.physicsScale,
         float(coords.y) * self.physicsScale)
示例#23
0
 def LocalToWorld(self, coords):
     return Vec2(
         float(coords.x) / self.physicsScale,
         float(coords.y) / self.physicsScale)
示例#24
0
 def GlobalToScreen(self, coords):
     return Vec2(
         float(coords.x) * self.physicsScale +
         self.core.renderer.window.size.x / 2,
         self.core.renderer.window.size.y / 2 -
         float(coords.y) * self.physicsScale)
示例#25
0
 def GlobalToWorld(self, coords):
     return Vec2((float(coords.x) - self.core.renderer.window.size.x / 2) /
                 self.physicsScale,
                 (self.core.renderer.window.size.y / 2 - float(coords.y)) /
                 self.physicsScale)