Beispiel #1
0
 class active:
     color = sf.Color(0, 0, 0)
     border = sf.Color(0x67, 0x9F, 0x30, 200)
     #border    = sf.Color (0x97, 0x90, 0xBF, 200)
     thickness = 5
     radius = 15
     text_size = 20
Beispiel #2
0
    def _hit_key(self, key):
        keyinfo = key.keyinfo
        s = self.whitestr.get_string()
        if "extra" in keyinfo:
            e = keyinfo["extra"]
            if 0:
                pass
            elif e == "DEL":
                s = s[:-1]
            elif e == "ENTER":
                # Accepts the string and sends it no observers
                e = signalslot.Event("text_entered",
                                     text=self.whitestr.get_string())
                self.signal_text_entered.call(e)

                uiactions.move_out(self, 50)
            elif e == "SHIFTLEFT" or e == "SHIFTRIGHT":
                self.kconfig.is_shifted ^= True
                value = "key"
                if self.kconfig.is_shifted:
                    value = "shift"
                for key in self.kconfig.keys:
                    if "extra" in key.keyinfo:
                        e = key.keyinfo["extra"]
                        if e == "SHIFTLEFT" or e == "SHIFTRIGHT":
                            if self.kconfig.is_shifted:
                                c = sf.Color(200, 200, 200, 255)
                            else:
                                c = sf.Color(255, 255, 255, 255)
                            key._sprite.SetColor(c)
                        continue
                    if value in key.keyinfo:
                        # BUG this should be automatic
                        u = key
                        k = u.keysprite
                        yfuzz = -4
                        xfuzz = 0
                        k.set_string(key.keyinfo[value])
                        k.SetPosition(u.GetPosition()[0] + \
                                          u._get_width()/2.0 - \
                                          k._get_width()/2.0 + xfuzz,
                                      u.GetPosition()[1] + \
                                          u._get_height()/2.0 - \
                                          k._get_height()/2.0 + yfuzz)
            else:
                assert 0
        else:
            if self.whitestr._get_width() >= self.maxlength:
                return

            s += key.keysprite.get_string()

        self.whitestr.set_string(s)
Beispiel #3
0
 def __init__(self,
              parent = None,
              radius = 10,
              ic = sf.Color (0, 0, 0),
              ot = 2.0,
              oc = sf.Color (255, 255, 255)):
     assert parent
     Component.__init__(self, parent)
     x = radius
     y = radius
     self._sprite = sf.Shape.Circle(x, y, radius, ic, ot, oc)
     self._width = radius * 2
     self._height = radius * 2
Beispiel #4
0
    def __init__ (self,
                  parent = None,
                  model  = None,
                  zoom   = 1.,
                  *a, **k):
        assert parent
        assert model
        super (RegionComponent, self).__init__ (parent = parent,
                                                radius = region_radius,
                                                *a, **k)

        self.on_click = signal.Signal ()
        self.signal_click.add (lambda ev: self.on_click (self))

        self.set_enable_hitting (True)
        
        self.model = model
        model.connect (self)

        self._outline_width = 2.0
        self._outline_color = sf.Color (0, 0, 0)
        self._fill_color    = region_free_color
        self._rebuild_sprite ()

        self._txt_troops = ui.String (self, u"0")
        self._txt_used   = ui.String (self, u"0/0")
        
        self._txt_troops.set_size (25)
        self._txt_troops.set_center_rel (0.5, 0.5)
        self._txt_troops.set_position_rel (0.5, 0.45)
        self._txt_troops.set_color (sf.Color (255, 255, 255))
        self._txt_troops._sprite.SetStyle (sf.String.Bold)
        
        self._txt_used.set_size (20)
        self._txt_used.set_center_rel (0.5, 0.5)
        self._txt_used.set_position_rel (0.5, 0.45)
        self._txt_used.set_color (sf.Color (255, 255, 255))
        self._txt_used.set_visible (False)

        self._txt_name = widget.String (self, model.definition.name.title ())
        self._txt_name.set_center_rel (.5, -1.3)
        self._txt_name.set_position_rel (.5, .45)
        self._txt_name.set_color (sf.Color (255, 255, 255, 128))
        self._txt_name.set_size (15)
        
        self.set_scale (zoom, zoom)
        self.set_center_rel (.5, .5)

        self._update_troops ()
        self._update_owner ()
Beispiel #5
0
    def __init__(self, parent=None, *a, **k):

        mappath = path.join('data', 'map')
        maplist = get_map_list(mappath)
        abslist = map(partial(path.join, mappath), maplist)
        mapmetas = map(load_map, abslist)

        contents = zip(
            map(lambda m: path.join(mappath, m.meta.thumbnail), mapmetas),
            map(
                lambda (n, m): '%%24%%%s\n'
                '%%12%%by %s\n'
                '%%12%%with %i regions.\n'
                '%%8%%\n'
                '%%16%%%s' % (n.translate(string.maketrans('_', ' ')).title(
                ), m.meta.author, len(m.regions), m.meta.description),
                zip(map(lambda m: m[:-4], maplist), mapmetas)), abslist)

        super(MapSelector, self).__init__(parent=parent,
                                          num_slots=4,
                                          button_size=(340, 104),
                                          contents=contents,
                                          *a,
                                          **k)
        for x in self._slots:
            x.string.set_color(sf.Color(255, 255, 255, 200))
Beispiel #6
0
    def __init__(self, parent=None, *a, **k):
        super(CreditsDialog, self).__init__(parent, *a, **k)
        self.width = 1024
        self.height = 768
        self.set_enable_hitting(True)
        self.activate()
        self.signal_click.add(lambda ev: self.on_dialog_exit('credits'))

        self._box = widget.VBox(self)
        self._box.separation = 20

        title_text(self._box, '> The JAGSAT Team')
        ui.MultiLineString(
            self._box,
            unicode("%25%Juan Pedro Bolivar Puente\n"
                    "%15%Main Programmer\n%8%\n"
                    "%25%Aksel Junkkila\n"
                    "%15%Game Designer\n%8%\n"
                    "%25%Guillem Medina\n"
                    "%15%Progammer\n%8%\n"
                    "%25%Sarah Lidstrom\n"
                    "%15%Bussiness Consultant\n%8%\n"
                    "%25%Alberto Villegas Erce\n"
                    "%15%Documentation Manager\n%8%\n"
                    "%25%Thomas Forss\n"
                    "%15%Project Manager\n%8%\n"))

        ui.MultiLineString(
            self._box,
            unicode("%15%(Click to quit or wait 5 seconds)")).set_color(
                sf.Color(255, 255, 0, 200))

        self._box.set_center_rel(.5, .5)
        self._box.set_position_rel(.5, .5)
Beispiel #7
0
    def __init__(self, screen_width, screen_height):
        self.selection = 0
        text_color = sf.Color(220, 220, 20, 255)
        self.spacing = screen_height / 7

        self.title = sf.String("PyWorm!")
        self.title.SetColor(text_color)
        self.title.SetPosition(screen_width / 2 - 80., self.spacing)

        levels = ["Very Easy", "Easy", "Medium", "Hard"]
        x_align = [-80., -50., -70., -50.]
        self.strings = []
        for i in range(0, 4):
            string = sf.String(levels[i])
            string.SetColor(text_color)
            string.SetPosition(screen_width / 2 + x_align[i],
                               (2 + i) * self.spacing + 20)
            self.strings.append(string)

        self.rectangle = sf.Shape.Rectangle(0, 0, screen_width, 40,
                                            sf.Color(50, 50, 10))
Beispiel #8
0
 def _build_continents (self):
     world = self.model
     self._continents = []
     for c in world.map.continents.itervalues ():
         px, py = 0, 0
         for r in c.regions:
             px += (r.shape.center.x + region_radius) * world.map.zoom
             py += (r.shape.center.y + region_radius) * world.map.zoom
         total = float (len (c.regions))
         px /= total
         py /= total
         continent = ui.String (self, c.name.title () + " (%i)" % c.troops)
         continent.set_size (60)
         continent.set_color (sf.Color (255, 255, 255, 50))
         continent.set_center_rel (.5, .5)
         continent.set_position (px, py)
         continent._sprite.SetStyle (sf.String.Bold)
         self._continents.append (continent)
Beispiel #9
0
    def step_action(self):
        brk = 0
        for i in range(len(self.color_now)):
            self.color_now[i] += self.speed[i]
            if self.speed[i] <= 0 and self.color_now[i] < self.color_end[i]:
                self.color_now[i] = self.color_end[i]
            elif self.speed[i] >= 0 and self.color_now[i] > self.color_end[i]:
                self.color_now[i] = self.color_end[i]

            if self.color_now[i] == self.color_end[i]:
                brk += 1
        c = sf.Color(self.color_now[0], self.color_now[1], self.color_now[2],
                     self.color_now[3])
        if hasattr(self.component, "_sprite"):
            if hasattr(self.component._sprite, "GetNbPoints"):
                for i in range(self.component._sprite.GetNbPoints()):
                    self.component._sprite.SetPointColor(i, c)
            self.component._sprite.SetColor(c)
        self.component.set_color(c)

        if brk == 4:
            return True
Beispiel #10
0
def Main():
    Buffer = sf.SoundBuffer()
    if not Buffer.LoadFromFile("data/fart.wav"):  # Loads the sound
        return
    Fart = sf.Sound(Buffer, False)

    WindowWidth, WindowHeight = 640, 480
    App = sf.RenderWindow(sf.VideoMode(WindowWidth, WindowHeight, 32),
                          "Sound with PySFML", sf.Style.Close,
                          sf.ContextSettings(24, 8, 0))
    App.SetFramerateLimit(30)

    EventHandler = sf.Event()
    InputHandler = App.GetInput()

    Text = sf.Text(
        "Turn the sound on.\nClick anywhere on the screen.\nMove the mouse. Click again.\nTry clicking in the corners."
    )
    Text.SetX(30.)
    Text.SetY(20.)
    Text.SetColor(sf.Color(150, 100, 10, 255))

    while App.IsOpened():  # Main loop
        while App.GetEvent(EventHandler):  # Event Handler
            if EventHandler.Type == sf.Event.Closed:
                App.Close()
            if EventHandler.Type == sf.Event.KeyPressed and EventHandler.Key.Code == sf.Key.Escape:
                App.Close()
            if EventHandler.Type == sf.Event.MouseButtonPressed and EventHandler.MouseButton.Button == sf.Mouse.Left:
                Fart.SetPitch(1.5 -
                              1. * InputHandler.GetMouseY() / WindowHeight)
                Fart.SetPosition(
                    1. * (InputHandler.GetMouseX() - WindowWidth / 2) /
                    (WindowWidth / 20), 2., -2.)
                Fart.Play()
        App.Draw(Text)
        App.Display()
        App.Clear(sf.Color.Black)
Beispiel #11
0
    def __init__(self):
        # Initialize the window
        self.win = sf.RenderWindow(sf.VideoMode(800, 600, 32), "PyWorm",
                                   sf.Style.Close)  # Creates the window
        self.win.EnableKeyRepeat(False)
        background_color = sf.Color(100, 100, 0, 255)
        self.win.SetFramerateLimit(30)
        event = sf.Event()
        self.keys = {}  # keys to watch
        self.menu_begin()

        # Boucle principale
        while self.win.IsOpened():
            while self.win.GetEvent(event):  # Event Handler
                if event.Type == sf.Event.Closed:
                    self.win.Close()
                elif event.Type == sf.Event.KeyPressed or event.Type == sf.Event.KeyReleased:
                    if event.Key.Code in self.keys:
                        self.keys[event.Key.Code](
                            event.Type == sf.Event.KeyPressed)
            self.win.Display()
            self.win.Clear(background_color)
            self.next_frame(self.win)
Beispiel #12
0
def blend(c1, c2):
    a1 = (255 - c2.a) / 255.0

    r1 = c1.r * a1
    g1 = c1.g * a1
    b1 = c1.b * a1

    a2 = c2.a / 255.0
    r2 = c2.r * a2
    g2 = c2.g * a2
    b2 = c2.b * a2

    r = r1 + r2
    g = g1 + g2
    b = b1 + b2

    if r > 255:
        r = 255
    if g > 255:
        g = 255
    if b > 255:
        b = 255

    return sf.Color(r, g, b)
Beispiel #13
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
Beispiel #14
0
def _persistent_load(pid):
    if pid[:9] == "sf.Color:":
        return sf.Color(*map(int, pid[9:].split(',')))
    raise pickle.UnpicklingError, 'Invalid persistent id'
Beispiel #15
0
 class active:
     color = sf.Color(0, 0, 0, 200)
     border = sf.Color(150, 150, 70, 255)
     thickness = 2
     radius = 15
     text_size = 16
Beispiel #16
0
 def select (self):
     self._outline_color = sf.Color (255, 255, 255)
     self._outline_width = 5.0
     self._rebuild_sprite ()
Beispiel #17
0
 def unhighlight (self):
     self._outline_color = sf.Color (0, 0, 0)
     self._outline_width = 2.0
     self._rebuild_sprite ()
Beispiel #18
0
 class inactive(active):
     color = sf.Color(0, 0, 0, 100)
     border = sf.Color(0, 0, 0, 0)
Beispiel #19
0
 def highlight (self):
     self._outline_color = sf.Color (255, 255, 96)
     self._outline_width = 3.0
     self._rebuild_sprite ()
Beispiel #20
0
def set_attacker_text_style(txt):
    txt.set_size(16)
    txt.set_color(sf.Color(255, 150, 150))
Beispiel #21
0
 class whitebox(button.active):
     thickness = 2
     #border    = sf.Color (255, 100, 100, 64)
     color = sf.Color(255, 255, 255, 44)
Beispiel #22
0
def set_defender_text_style(txt):
    txt.set_size(16)
    txt.set_color(sf.Color(150, 150, 255))
Beispiel #23
0
    def __init__(self, parent=None, player=None, *a, **k):
        super(PlayerComponent, self).__init__(parent, center=True, *a, **k)

        self.player = player
        self._can_change_cards = False
        self._menu_enabled = False
        move_to_player_position(self, player)

        # Area for windows
        self._menu_area = ui.FreeformContainer(self)
        self._menu_area.width = 1024  # HACK
        self._menu_area.height = 768

        # The main button
        self._but_theme = theme.copy_button_theme(theme.small_button)
        pc = theme.player_color[player.color]
        self._but_theme.active.color = pc
        if (pc.r + pc.g + pc.b) / 3. > 64:
            self._but_theme.active.border = sf.Color(pc.r * .4, pc.g * .4,
                                                     pc.b * .4)
        else:
            self._but_theme.active.border = sf.Color(pc.r + 40, pc.g + 40,
                                                     pc.b + 40)

        self._but_main = widget.Button(self,
                                       None,
                                       'data/icon/small.png',
                                       theme=self._but_theme)
        self._but_main.on_click += lambda ev: self.on_toggle_menu(self)

        self._txt_troops = ui.String(self._but_main, player.troops or '')
        self._txt_troops.set_center_rel(0.5, 0.5)
        self._txt_troops.set_position(28, 26)
        self._txt_troops.set_size(20)
        self._txt_troops._sprite.SetStyle(sf.String.Bold)

        player.on_set_player_troops += self._on_set_player_troops
        player.on_add_player_card += self._on_cards_change
        player.on_del_player_card += self._on_cards_change

        # The main menu
        self._menu_main = widget.VBox(self._menu_area)
        self._but_pass = widget.SmallButton(self._menu_main, None,
                                            'data/icon/next-small.png')
        self._but_cards = widget.SmallButton(self._menu_main, None,
                                             'data/icon/troops-small.png')
        self._but_mission = widget.SmallButton(self._menu_main, None,
                                               'data/icon/world-small.png')
        # self._but_undo = widget.SmallButton (
        #    self._menu_main, None, 'data/icon/undo-small.png')

        self.padding_bottom = 0
        self._menu_main.padding_bottom = 6
        self._menu_main.set_visible(self._menu_enabled)
        self._position_menu(self._menu_main)

        self._but_mission.on_click += self._on_show_mission
        self._but_cards.on_click += self._on_show_cards

        self._but_pass.deactivate()

        self._but_pass.on_click += self.on_toggle_menu
        self._current_menu = self._menu_main
Beispiel #24
0
def title_text(parent, text):
    txt = ui.String(parent, unicode(text))
    txt.set_size(25)
    txt.set_color(sf.Color(255, 255, 255, 70))
    txt._sprite.SetStyle(sf.String.Bold)
    return txt
Beispiel #25
0
 def make_fade_task(self, fade_task):
     return fade_task(
         lambda x: self.ui_text.set_color(sf.Color(255, 255, 255, x * 255)),
         init=True,
         duration=.75)
Beispiel #26
0
SOUTH = (0.5, 1.0)
EAST = (1.0, 0.5)

CENTER = (0.5, 0.5)

NORTHEAST = (1.0, 0.0)
SOUTHEAST = (1.0, 1.0)
SOUTHWEST = (0.0, 1.0)
NORTHWEST = (0.0, 0.0)

from OpenGL.GL import *
from OpenGL.GLU import *


Color = sf.Color
Transparent = sf.Color(255, 0, 255, 0)


class Window:
    """The main window that contains views."""

    def __init__(self, sfwindow):
        """
        Wrap a window into the TF system.

        @sfwindow - An SFML RenderWindow object as parameter.
        """
        self.window = sfwindow
        self.views = []

    def add_view(self, view):
Beispiel #27
0
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#  JAGSAT Development Team is:
#    - Juan Pedro Bolivar Puente
#    - Alberto Villegas Erce
#    - Guillem Medina
#    - Sarah Lindstrom
#    - Aksel Junkkila
#    - Thomas Forss
#

from PySFML import sf

player_color = {
    0: sf.Color.Blue,
    1: sf.Color(0, 230, 0),
    2: sf.Color.Red,
    3: sf.Color(255, 220, 0),
    4: sf.Color.Black,
    5: sf.Color.Magenta
}

background_music = [
    'data/sfx/background/right-of-freedom.ogg',
    'data/sfx/background/the-age-of-innocence.ogg',
    'data/sfx/background/les-lois-du-ciel.ogg',
    'data/sfx/background/scene-pour-orchestre.ogg',
    'data/sfx/background/confrontation.ogg',
    'data/sfx/background/apprentissage.ogg',
    'data/sfx/background/angel-needs-pollution-to-breathe.ogg',
    'data/sfx/background/nebulous-notions.ogg'
Beispiel #28
0
 class selected(small_button.active):
     border = sf.Color(220, 50, 50, 255)
     color = sf.Color(50, 0, 0, 200)
Beispiel #29
0
from base.log import get_log
from core import task

from model.world import RegionListener
import theme
import widget
import player

import math

from os import path

_log = get_log (__name__)

region_radius     = 17
region_free_color = sf.Color (128, 128, 128)

class map_op:
    none, move, rotate, zoom = range (4)

def shortest_angle (old_rot, new_rot):
    inv_rot = new_rot + (360 if old_rot > new_rot else -360)
    if abs (old_rot - inv_rot) < abs (old_rot - new_rot):
        new_rot = inv_rot
    return new_rot

class WorldComponent (ui.Image, object):

    def __init__ (self,
                  parent = None,
                  world  = None,
Beispiel #30
0
Resolution = (800, 600)

wnd = sf.RenderWindow(sf.VideoMode(Resolution[0], Resolution[1], 32),
                      "Hello SFML!")
wnd.UseVerticalSync(True)

# Load a fancy font.
cheese = sf.Font()
cheese.LoadFromFile("data/cheeseburger.ttf")

# Create a text.
text = sf.Text(u"Hello SFML from Python!", cheese, 50)
text.SetOrigin(text.GetRect().GetSize()[0] / 2,
               text.GetRect().GetSize()[1] / 2)
text.SetPosition(400, 300)
text.SetColor(sf.Color(0, 100, 0, 100))

# Create a text for FPS display.
fpstext = sf.Text(u"FPS: --", cheese)
fpstext.SetColor(sf.Color(0, 0, 0))
currentfps = 0
fpsclock = sf.Clock()

# Load apple image from file.
appleimage = sf.Image()
appleimage.LoadFromFile("data/apple.png")

# Create some apples with random position, speed, rotation and color.
apples = [Apple(appleimage) for num in range(0, 100)]
for apple in apples:
    apple.sprite.SetOrigin(appleimage.GetWidth() / 2,