Ejemplo n.º 1
0
 def sprite(self):
     if self.projo:
         if self.race == ELFE:
             self.spr = sf.Sprite(IMG['d/be'])
         else:
             self.spr = sf.Sprite(IMG['d/bn'])
         self.spr.SetPosition(self.x, self.y)
         return self.spr
     elif self.race == NAIN:
         seq = NAINSEQ
     elif self.race == ELFE:
         seq = ELFESEQ
     else:
         seq = STATICSEQ
     print '!!', self.anim, self.anim_pos
     anim = seq[self.anim][self.anim_pos]
     print '!!', anim
     print '!! >? ', time.time(), self.t, time.time() - self.t
     if time.time() - self.t > anim['d']:
         if self.anim_pos + 1 < self.anim_max:
             print '!!', 'INC'
             self.anim_pos += 1
         else:
             self.anim_pos = 0
             self.anim_finie = True
         self.t = time.time()
         self.spr = sf.Sprite(anim['i'])
         self.spr.FlipX(self.orientation)
     self.spr.SetPosition(self.x - anim['o'][0], self.y - anim['o'][1])
     if (self.orientation == GAUCHE and abs(self.alpha) < 90
             or self.orientation == DROITE and abs(self.alpha) > 90):
         self.orientation = not self.orientation
     self.spr.FlipX(self.orientation)
     print 'ANIMPOS', self.anim_pos
     return self.spr
Ejemplo n.º 2
0
 def __init__(self, parent = None, fname = None):
     Component.__init__(self, parent)
     if fname is not None:
         self.img = ImageFile.new_image(fname)
     else:
         self.img = ImageFile.empty_image
     self._sprite = sf.Sprite(self.img.img)
Ejemplo n.º 3
0
 def __init__(self, msg):
     self.x = msg['x']
     self.y = msg['y']
     self.id = msg['id']
     self.marto = 0
     if 'pr' in msg:
         self.projo = True
     else:
         self.projo = False
     if 'r' in msg:
         self.race = msg['r']
     else:
         self.race = msg['pr']
     if 'n' in msg:
         self.nom = msg['n']
     else:
         self.nom = ''
     self.alpha = 0
     self.spr = sf.Sprite(IMG['n/1'])
     self.t = 0
     self.anim = A_MARCHE
     if 'anim' in msg:
         self.anim = msg['anim']
     self.anim_pos = 0
     if self.race == NAIN:
         self.anim_max = 1
     elif self.race == ELFE:
         self.anim_max = 1
     else:
         self.anim_max = len(STATICSEQ[self.anim])
     self.anim_finie = False
     self.orientation = DROITE
     self.spr = self.sprite()
Ejemplo n.º 4
0
 def arm(self):
     if not self.projo:
         if self.race == NAIN:
             if time.time() - self.marto < 5.0:
                 arme = sf.Sprite(IMG['n/b/m'])
             else:
                 arme = sf.Sprite(IMG['n/b/b'])
             arme.SetCenter(6, 12)
             arme.SetPosition(self.x + STATICOFS['n/b/b'][0],
                              self.y + STATICOFS['n/b/b'][1])
             arme.SetRotation(self.alpha)
             return arme
         elif self.race == ELFE:
             arme = sf.Sprite(IMG['e/b/1'])
             arme.SetCenter(6, 12)
             arme.SetPosition(self.x + STATICOFS['e/b/1'][0],
                              self.y + STATICOFS['e/b/1'][1])
             arme.SetRotation(self.alpha)
             return arme
Ejemplo n.º 5
0
def make_sprite(img, center=None):
    if isinstance(img, str):
        img = load_image(img)
    sp = sf.Sprite(img)
    sp.SetCenter(img.GetWidth() / 2., img.GetHeight() / 2.)
    window_size = get_window_size()
    sp.SetPosition(window_size[0] / 2., window_size[1] / 2.)
    if center is not None:
        sp.SetPosition(*center)
    return sp
Ejemplo n.º 6
0
 def __init__(self, parent, fname, width_in_images):
     Component.__init__(self)
     self.images = []
     self._sprites = []
     self.width_in_images = width_in_images
     self.maxwidth = 0
     self.maxheight = 0
     i = 0
     while True:
         try:
             img = ImageFile.new_image(fname % i)
         except:
             print sys.exc_value
             break
         self.images.append(img)
         i += 1
     if i == 0:
         print "tf: Could not find", fname, "bigimage, error!"
         assert i > 0
     i = 0
     for i, img in enumerate(self.images):
         self._sprites.append(sf.Sprite(img.img))
     self.reposition()
Ejemplo n.º 7
0
    def __init__(self, filename, animation_name, image_folder, x=0, y=0):
        # file name / animation_name
        self.filename = filename.rstrip(os.path.sep)
        self.animation_name = animation_name

        # background image
        self.image = sf.Image()
        fullfilename = os.path.join(image_folder, animation_name, filename)
        if not self.image.LoadFromFile(fullfilename):
            raise RuntimeError("Image '%s' couldn't be loaded" % filename)
        width, height = self.image.GetWidth(), self.image.GetHeight()

        # background sprite
        self.sprite = sf.Sprite(self.image)
        self.sprite.SetCenter(width / 2., height / 2.)
        self.sprite.SetPosition(x, y)

        # information string
        string_repr = os.path.join(self.animation_name, self.filename)
        self.string = sf.String(string_repr)
        self.string.SetCenter(self.string.GetRect().GetWidth() / 2., 0.)
        self.string.SetPosition(x, y + height / 2.)

        # sprite outline rect
        self.rect = sfml_make_rect_from_def(x - width / 2.,
                y - height / 2., width, height)
        self.rect.EnableOutline(True)
        self.rect.EnableFill(False)
        self.rect.SetOutlineWidth(1)
        self.rect = sfml_set_rect_outline_color(self.rect, sf.Color.White)

        # offset for hitboxes
        self.offsetX, self.offsetY = x, y

        # hitboxes
        self.drawable_list = DrawableHitboxList()
Ejemplo n.º 8
0
import threading, time, sys
import reseau.client as net
from PySFML import sf
from pdb import set_trace as rrr
from twisted.internet import reactor
import animenv, persoclient, son
import random, sys

# globaux
FREQ = 30.0
APPW, APPH = 1920, 1080

_FOND = sf.Image()
_FOND.LoadFromFile("./img/map.bmp")
FOND = sf.Sprite(_FOND)
FOND.SetPosition(0, 0)  #(APPW/2, APPH/2)
FOND.Resize(APPW, APPH)

KEYS = {
    ord('z'): 'z',
    ord('s'): 's',
    ord('q'): 'q',
    ord('d'): 'd',
    277: ' ',
}

GLOB = {}
GLOB['objets'] = {}

# code
Ejemplo n.º 9
0
def main():

    # Create main window
    App = sf.RenderWindow(sf.VideoMode(800, 600), "SFML OpenGL")
    App.SetActive()

    # Create a sprite for the background
    BackgroundImage = sf.Image()
    if not BackgroundImage.LoadFromFile(
            "../../samples/bin/datas/opengl/background.jpg"):
        return
    Background = sf.Sprite(BackgroundImage)

    # Load an OpenGL texture.
    # We could directly use a sf.Image as an OpenGL texture (with its Bind() member function),
    # but here we want more control on it (generate mipmaps, ...) so we create a new one

    Image = sf.Image()
    if not Image.LoadFromFile("../../samples/bin/datas/opengl/texture.jpg"):
        return
    # The next line is a bit different from the C++ version
    Texture = glGenTextures(1)  # instead of glGenTextures(1, &Texture);
    glBindTexture(GL_TEXTURE_2D, Texture)
    # It is almost the same line there, except in C++, the last argument was Image.GetPixelsPtr().
    # In python, GetPixels simply returns a string.
    gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, Image.GetWidth(),
                      Image.GetHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
                      Image.GetPixels())
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                    GL_LINEAR_MIPMAP_LINEAR)

    # Enable Z-buffer read and write
    glEnable(GL_DEPTH_TEST)
    glDepthMask(GL_TRUE)
    glClearDepth(1.)

    # Setup a perspective projection
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    gluPerspective(90., 1., 1., 500.)

    # Bind our texture
    glEnable(GL_TEXTURE_2D)
    glBindTexture(GL_TEXTURE_2D, Texture)
    glColor4f(1., 1., 1., 1.)

    # Create a clock for measuring the time elapsed
    Clock = sf.Clock()

    # Start game loop
    while App.IsOpened():
        # Process events
        Event = sf.Event()
        while App.GetEvent(Event):
            # Close window : exit
            if Event.Type == sf.Event.Closed:
                App.Close()

            # Escape key : exit
            if (Event.Type == sf.Event.KeyPressed) and (Event.Key.Code
                                                        == sf.Key.Escape):
                App.Close()

            # Adjust the viewport when the window is resized
            if Event.Type == sf.Event.Resized:
                glViewport(0, 0, Event.Size.Width, Event.Size.Height)

        # Draw background
        App.Draw(Background)

        # Active window to be able to perform OpenGL commands.
        App.SetActive()

        # Clear depth buffer
        glClear(GL_DEPTH_BUFFER_BIT)

        # Apply some transformations
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
        glTranslatef(0, 0, -200)
        glRotatef(Clock.GetElapsedTime() * 50, 1, 0, 0)
        glRotatef(Clock.GetElapsedTime() * 30, 0, 1, 0)
        glRotatef(Clock.GetElapsedTime() * 90, 0, 0, 1)

        # Draw a cube
        glBegin(GL_QUADS)

        glTexCoord2f(0, 0)
        glVertex3f(-50., -50., -50.)
        glTexCoord2f(0, 1)
        glVertex3f(-50., 50., -50.)
        glTexCoord2f(1, 1)
        glVertex3f(50., 50., -50.)
        glTexCoord2f(1, 0)
        glVertex3f(50., -50., -50.)

        glTexCoord2f(0, 0)
        glVertex3f(-50., -50., 50.)
        glTexCoord2f(0, 1)
        glVertex3f(-50., 50., 50.)
        glTexCoord2f(1, 1)
        glVertex3f(50., 50., 50.)
        glTexCoord2f(1, 0)
        glVertex3f(50., -50., 50.)

        glTexCoord2f(0, 0)
        glVertex3f(-50., -50., -50.)
        glTexCoord2f(0, 1)
        glVertex3f(-50., 50., -50.)
        glTexCoord2f(1, 1)
        glVertex3f(-50., 50., 50.)
        glTexCoord2f(1, 0)
        glVertex3f(-50., -50., 50.)

        glTexCoord2f(0, 0)
        glVertex3f(50., -50., -50.)
        glTexCoord2f(0, 1)
        glVertex3f(50., 50., -50.)
        glTexCoord2f(1, 1)
        glVertex3f(50., 50., 50.)
        glTexCoord2f(1, 0)
        glVertex3f(50., -50., 50.)

        glTexCoord2f(0, 1)
        glVertex3f(-50., -50., 50.)
        glTexCoord2f(0, 0)
        glVertex3f(-50., -50., -50.)
        glTexCoord2f(1, 0)
        glVertex3f(50., -50., -50.)
        glTexCoord2f(1, 1)
        glVertex3f(50., -50., 50.)

        glTexCoord2f(0, 1)
        glVertex3f(-50., 50., 50.)
        glTexCoord2f(0, 0)
        glVertex3f(-50., 50., -50.)
        glTexCoord2f(1, 0)
        glVertex3f(50., 50., -50.)
        glTexCoord2f(1, 1)
        glVertex3f(50., 50., 50.)

        glEnd()

        # Draw some text on top of our OpenGL object
        Text = sf.Text("This is a rotating cube")
        Text.SetPosition(230., 300.)
        Text.SetColor(sf.Color(128, 0, 128))
        App.Draw(Text)

        # Finally, display the rendered frame on screen
        App.Display()

# Don't forget to destroy our texture
    # In C++, the call to this function was a bit different
    glDeleteTextures(Texture)  # instead of glDeleteTextures(1, &Texture);

    return
Ejemplo n.º 10
0
 def __init__(self, image):
     self.sprite = sf.Sprite(image)
     self.sprite.SetOrigin(image.GetWidth() / 2, image.GetHeight() / 2)