コード例 #1
0
ファイル: main.py プロジェクト: mkeeter/pysfml2-cython
    def test_eq(self):
        def r():
            return random.randint(0, 100)

        equal = [(sf.IntRect(l, t, w, h), sf.IntRect(l, t, w, h))
                 for l, t, w, h in [(r(), r(), r(), r()) for i in range(100)]]

        for r1, r2 in equal:
            self.assertEqual(r1, r2)
コード例 #2
0
ファイル: main.py プロジェクト: mkeeter/pysfml2-cython
    def test_neq(self):
        not_equal = [(sf.IntRect(0, 0, 0, 0), sf.IntRect(0, 0, 0, 10)),
                     (sf.IntRect(0, 0, 0, 0), sf.IntRect(0, 0, 10, 0)),
                     (sf.IntRect(0, 0, 0, 0), sf.IntRect(0, 10, 0, 0)),
                     (sf.IntRect(0, 0, 0, 0), sf.IntRect(10, 0, 0, 0))]

        for r1, r2 in not_equal:
            self.assertNotEqual
コード例 #3
0
    def __init__(
        self, dData
    ):  #sComponentID, textureGrid, fDelay, iFrameWidth, iFrameHeight, iFramesWide, iFramesHigh):
        Component.__init__(self, "ANSPRITE:%s" % (dData['componentID']), True,
                           True)

        #This animation starts off as inactive and will await a trigger from a system function
        self._bActive = False

        #This will denote the time in-between each frame of the animation in the textureGrid.
        self._fDelay = dData['delay']

        #This will tell us when it is time to update the frame.
        self._fAnim_Time = 0.0

        #The current frame on the texture grid (top-left)
        self._iCurrent_Frame = [0, 0]

        #The texture grid details
        self._iFrame_Width = dData['frameWidth']
        self._iFrame_Height = dData['frameHeight']
        self._iFrames_Wide = dData['framesWide']
        self._iFrames_High = dData['framesHigh']

        #This holds the texture for the animation!
        self._Animation_Sprite = sf.Sprite(dData['Texture'][0])

        self._Animation_Sprite.set_texture_rect(
            sf.IntRect(0, 0, self._iFrame_Width, self._iFrame_Height))
コード例 #4
0
ファイル: Animated_Sprite.py プロジェクト: jawaff/TileGame
    def __init__(
            self, dData
    ):  #sComponentID, iFrameWidth, iFrameHeight, dTextureStripData):
        Component.__init__(self,
                           "STATE_ANIMATIONS:%s" % (dData['componentID']),
                           True, 2)

        self._bActive = True

        #This will denote the time in-between each frame of the animation in the textures
        self._fDelay = float(dData['Delay'])

        #This will tell us when it is time to update the frame.
        self._anim_Time = sf.Time(0.0)

        #The current animation is set to its default (which there should be...)
        #   The first item is the animation, the second is the frame.
        self._lCurrent_Frame = ['DEFAULT', 0]

        self._iFrame_Width = int(dData['FrameWidth'])
        self._iFrame_Height = int(dData['FrameHeight'])

        self._dAnimated_Sprites = {}

        windPos = dData["WindPos"].split(",")

        for sTextureName in dData["Texture"].keys():

            #This holds the textures for the animations!
            #It being in a dictionary allows systems to switch to animations easier.
            #Each sAnimation will have a list of the sprite and some data for flexible lengthed animations to be allowed.
            #The list will include [sprite, iFramesWide]
            ##only the width is needed because this is a one-dimensional strip (I think this is all we need... Unless we're dealing with LARGE frame dimensions...)
            self._dAnimated_Sprites[sTextureName] = [sf.Sprite(dData["Texture"][sTextureName]),     \
                                                     int(dData["Texture"][sTextureName].width)/self._iFrame_Width]

            self._dAnimated_Sprites[sTextureName][0].x = float(windPos[0])
            self._dAnimated_Sprites[sTextureName][0].y = float(windPos[1])

            self._dAnimated_Sprites[sTextureName][0].origin = (
                self._iFrame_Width / 2, self._iFrame_Height / 2)

            #print "The sprite's origin is", (self._iFrame_Width/2, self._iFrame_Height/2)

        #Each animation strip gets
        for key in self._dAnimated_Sprites.keys():
            self._dAnimated_Sprites[key][0].set_texture_rect(
                sf.IntRect(0, 0, self._iFrame_Width, self._iFrame_Height))
コード例 #5
0
ファイル: Animated_Sprite.py プロジェクト: jawaff/TileGame
    def _Update_Frame(self):
        """This simply will be used to update the frame of the animation within the SFML sprite based off of the data in this class."""

        #print int(self._lCurrent_Frame[1])*self._iFrame_Width,     \
        #0,                                                  \
        #self._iFrame_Width,                                 \
        #self._iFrame_Height

        if (self._dAnimated_Sprites.get(self._lCurrent_Frame[0], None) !=
                None):

            self._dAnimated_Sprites[self._lCurrent_Frame[0]][0].set_texture_rect(sf.IntRect(int(self._lCurrent_Frame[1])*self._iFrame_Width,     \
                                                                                            0,                                                  \
                                                                                            self._iFrame_Width,                                 \
                                                                                            self._iFrame_Height))
        else:
            print "There is no %s animation for %s" % (self._lCurrent_Frame[0],
                                                       self._Get_Name())
コード例 #6
0
def main():
    window = sf.RenderWindow(sf.VideoMode(640, 480), 'Image example')
    window.framerate_limit = 60
    logo = sf.Image.load_from_file('python-logo.png')
    princess = sf.Image.load_from_file('princess.png')
    logo.copy(princess, 0, 0, sf.IntRect(0, 0, 0, 0), True)
    texture = sf.Texture.load_from_image(logo)
    sprite = sf.Sprite(texture)
    running = True

    while running:
        for event in window.iter_events():
            if event.type == sf.Event.CLOSED:
                running = False

        window.clear(sf.Color.WHITE)
        window.draw(sprite)
        window.display()

    window.close()
コード例 #7
0
ファイル: main.py プロジェクト: mkeeter/pysfml2-cython
 def random_rect(self):
     return sf.IntRect(random.randint(0, 100), random.randint(0, 100),
                       random.randint(0, 100), random.randint(0, 100))