Esempio n. 1
0
def main():
    pygame.init()
    if hasattr(eventmodule, 'init'):
        eventmodule.init()
    screen = pygame.display.set_mode((300, 300))

    # send an event when twisted wants attention
    reactor.interleave(postTwistedEvent)
    # make shouldQuit a True value when it's safe to quit
    # by appending a value to it.  This ensures that
    # Twisted gets to shut down properly.
    shouldQuit = []
    reactor.addSystemEventTrigger('after', 'shutdown', shouldQuit.append, True)

    for event in eventIterator():
        if event.type == TWISTEDEVENT:
            event.iterateTwisted()
            if shouldQuit:
                break
        elif event.type == QUIT:
            reactor.stop()
        elif event.type == KEYDOWN and event.key == K_ESCAPE:
            reactor.stop()

    pygame.quit()
Esempio n. 2
0
    def __init__(self, name, size, hide_mouse=True, display_rotate=False):
        # Call init routines
        pygame.init()
        if hasattr(EventModule, 'init'):
            EventModule.init()

        # Window name
        pygame.display.set_caption(name)

        # Hide mouse cursor
        if hide_mouse:
            pygame.mouse.set_cursor(
                *pygame.cursors.load_xbm('transparent.xbm', 'transparent.msk'))

        # Store screen and size
        #self.screen = pygame.display.set_mode(size, pygame.FULLSCREEN)
        self.screen = pygame.display.set_mode(size)

        # Always find the real resolution (e.g., if size==(0,0))
        i = pygame.display.Info()
        self.size = (i.current_w, i.current_h)

        # Should text be rotated 90 degrees counterclockwise?
        self.display_rotate = display_rotate

        # Clear screen
        self.clear()
        self.apply()
Esempio n. 3
0
    def runWithTwisted2(self):
        if hasattr(eventmodule, 'init'):  # for fastevents
            eventmodule.init()

        poster = post_them()

        poster.start()

        while 1:
            #for e in event.get():
            #for x in range(200):
            #    ee = event.Event(USEREVENT)
            #    r = event_module.post(ee)
            #    print r

            #for e in event_module.get():
            event_list = []
            event_list = eventmodule.get()

            for e in event_list:
                if e.type == QUIT:
                    print c.get_fps()
                    poster.stop.append(1)
                    return
                elif e.type == KEYDOWN:
                    if e.key == K_ESCAPE:
                        print c.get_fps()
                        poster.stop.append(1)
                else:  # *** should we instead pass all events and move this
                    #    handling into current event handling?
                    self.handleOneEvent(e)
                    return
            """
Esempio n. 4
0
    def runWithTwisted2(self):
        if hasattr(eventmodule, 'init'):  # for fastevents
            eventmodule.init()

        poster = post_them()

        poster.start()

        while 1:
            #for e in event.get():
            #for x in range(200):
            #    ee = event.Event(USEREVENT)
            #    r = event_module.post(ee)
            #    print r
            
            #for e in event_module.get():
            event_list = []
            event_list = eventmodule.get()

            for e in event_list:
                if e.type == QUIT:
                    print c.get_fps()
                    poster.stop.append(1)
                    return
                elif e.type == KEYDOWN:
                    if e.key == K_ESCAPE:
                        print c.get_fps()
                        poster.stop.append(1)
                else:  # *** should we instead pass all events and move this
                       #    handling into current event handling?
                    self.handleOneEvent(e)
                    return

            """
def main():
    pygame.init()
    if hasattr(eventmodule, 'init'):
        eventmodule.init()
    screen = pygame.display.set_mode((300, 300))

    # send an event when twisted wants attention
    reactor.interleave(postTwistedEvent)
    # make shouldQuit a True value when it's safe to quit
    # by appending a value to it.  This ensures that
    # Twisted gets to shut down properly.
    shouldQuit = []
    reactor.addSystemEventTrigger('after', 'shutdown', shouldQuit.append, True)

    for event in eventIterator():
        if event.type == TWISTEDEVENT:
            event.iterateTwisted()
            if shouldQuit:
                break
        elif event.type == QUIT:
            reactor.stop()
        elif event.type == KEYDOWN and event.key == K_ESCAPE:
            reactor.stop()

    pygame.quit()
Esempio n. 6
0
 def __init__(self):
     display.init()
     fastevent.init()
     self.tela = display.set_mode((640, 640))
     display.set_caption("ClayMan")
     self.FPS_TICK = time.Clock()
     self.GAMELOOP = True
     self.map_generator = OgmoMap("res/map/NewLevel0.json",
                                  "res/CreyMan.png")
Esempio n. 7
0
    def runWithTwisted(self, verbose=False):
        if hasattr(eventmodule, 'init'):
            eventmodule.init()

        # send an event when twisted wants attention
        reactor.interleave(postTwistedEvent)

        # make shouldQuit a True value when it's safe to quit
        # by appending a value to it.  This ensures that
        # Twisted gets to shut down properly.
        shouldQuit = []
        reactor.addSystemEventTrigger('after', 'shutdown', shouldQuit.append,
                                      True)

        # Have our main "app" iteration called repeatedly
        #    pygame events are handled in the loop below, so also don't have
        #    the mainLoop iteration handle pygame events.
        reactor.callLater(
            .0, self.twistedOutside_mainLoopIterationDontHandleEvents)

        self._running = 1
        while self._running:
            #self._tickClock()
            #if not self._paused:
            #    self.updateObjects() # move
            # **** organize this so it integrates with non-twisted events.
            for event in self.eventIterator():  # this is an infinite loop
                if event.type == TWISTEDEVENT:
                    event.iterateTwisted()
                    if shouldQuit:
                        self._running = 0
                        break
                #elif event.type == QUIT:
                #    reactor.stop()
                else:  # *** should we instead pass all events and move this
                    #    handling into current event handling?
                    self.handleOneEvent(event)
            #self.renderer.draw()
            #pygame.display.flip()
        if verbose:
            print "mainloop in app.runWithTwisted done"
            pygame.quit()
            print "pygame.quit done"
        print "app.runWithTwisted done"
Esempio n. 8
0
    def __init__(self, name, size):
        # Call init routines
        pygame.init()
        if hasattr(EventModule, 'init'):
            EventModule.init()

        # Window name
        pygame.display.set_caption(name)

        # Hide mouse cursor
        pygame.mouse.set_cursor(*pygame.cursors.load_xbm('transparent.xbm','transparent.msk'))

        # Store screen and size
        self.size = size
        self.screen = pygame.display.set_mode(size, pygame.FULLSCREEN)

        # Clear screen
        self.clear()
        self.apply()
Esempio n. 9
0
    def runWithTwisted(self, verbose=False):
        if hasattr(eventmodule, 'init'):
            eventmodule.init()

        # send an event when twisted wants attention
        reactor.interleave(postTwistedEvent)

        # make shouldQuit a True value when it's safe to quit 
        # by appending a value to it.  This ensures that
        # Twisted gets to shut down properly.
        shouldQuit=[]
        reactor.addSystemEventTrigger('after', 'shutdown', shouldQuit.append, True)

        # Have our main "app" iteration called repeatedly
        #    pygame events are handled in the loop below, so also don't have
        #    the mainLoop iteration handle pygame events.
        reactor.callLater(.0, self.twistedOutside_mainLoopIterationDontHandleEvents)

        self._running = 1
        while self._running:
            #self._tickClock()
            #if not self._paused:
            #    self.updateObjects() # move
            # **** organize this so it integrates with non-twisted events.
            for event in self.eventIterator():  # this is an infinite loop
                if event.type == TWISTEDEVENT:
                    event.iterateTwisted()
                    if shouldQuit:
                        self._running = 0
                        break
                #elif event.type == QUIT:
                #    reactor.stop()
                else:  # *** should we instead pass all events and move this
                       #    handling into current event handling?
                    self.handleOneEvent(event)
            #self.renderer.draw()
            #pygame.display.flip()
        if verbose:
            print "mainloop in app.runWithTwisted done"
            pygame.quit()
            print "pygame.quit done"
        print "app.runWithTwisted done"
Esempio n. 10
0
    def test_init(self):
        # Test if module initialized after multiple init() calls.
        fastevent.init()
        fastevent.init()

        self.assertTrue(fastevent.get_init())
Esempio n. 11
0
 def setUp(self):
     pygame.display.init()
     fastevent.init()
     event.clear()
Esempio n. 12
0
chirp_y = []
sound = []
start_idx = 0
canvas = 0
raw_graph = 0
buffer = []

# --Initialize Pygame
pygame.mixer.pre_init(frequency=int(samplerate),
                      size=-16,
                      channels=2,
                      buffer=blocksize)
pygame.init()
pygame.mouse.set_visible(False)
Lcd = pygame.display.set_mode(LCD_SIZE)
fastevent.init()  # Initialize fastevents for multithreaded GPIO detect
pygame.event.set_blocked(pygame.MOUSEMOTION)
pygame.event.set_blocked(pygame.MOUSEBUTTONUP)
pygame.font.init()

sweep_gen()

# -Initialize pygame timer events
# Initialize the pygame time event and variables for recording purposes
Timeval = 0  # start sample rate at first entry in list
Tinterval = Timevals[Timeval]  # set the timer interval in msec
# Define  a pygame user event for the recording timer
pygame.time.set_timer(USEREVENT + 1,
                      Tinterval * 1000)  # create a timer event #1

# -Initialize a pygame timer event to update the time/temperature display
Esempio n. 13
0
 def setUp(self):
     pygame.display.init()
     fastevent.init()
     event.clear()
     self.assert_(not event.get())
Esempio n. 14
0
    def __init__(self, width=640, height=480, fps=30, scale=1, initmixer=True):
        """Create a basic game structure.

            @param width: The width of the game window (default 640).
            @param height: The height of the game window (default 480).
            @param fps: The framerate of the game in frames per second
                (default 30).
            @param scale: The scale factor of the game's graphics (default 1).
            @param initmixer: Whether to set up the mixer module for
                high-quality sounds (default True).
        """

        # pre-initialize the mixer module to use 44.1kHz sampling
        # the defaults are:
        # frequency = 22050 (22.050 kHz)
        # size = -16 (16-bit signed integers)
        # channels = 2 (stereo sound)
        # buffer = 4096
        # TODO: make a way to support arbitary mixing values
        if initmixer:
            pygame.mixer.pre_init(frequency=44100)

        # initialize pygame and the fastevent module
        pygame.init()
        pgevent.init()

        # create the main screen (we'll fill this in once the game starts)
        self.screen = None

        # initialize event handlers
        self._evtHandlers = []
        for etype in xrange(pygame.NUMEVENTS):
            self._evtHandlers.append([])

        # initialize "update" list
        self._updates = []

        # this will hold a list of "dirty" rectangles to repaint
        self._rectList = None

        # make a clock to limit CPU usage
        self.clock = pygame.time.Clock()

        # this is the time elapsed in the current frame
        self.frameTime = 0.0

        # this is the scale factor from "real time" to "game time"
        self.timeScale = 1

        # copy constructor arguments into properties
        self.width = width
        self.height = height
        self.fps = fps

        # the scale factor of graphics
        # (all graphics will be scaled by this amount in both x and y directions)
        self.scale = scale

        # copy some useful properties into the global structure

        # A pointer to the game world
        Game.world = self

        # A pointer to the game clock (a Clock object)
        Game.clock = self.clock

        # The time spent in the previous frame (used for e.g., velocity)
        Game.elapsed = self.frameTime

        # The game's frames per second setting (not necessarily the _actual_ FPS)
        Game.fps = self.fps

        # The current state of the keyboard, updated each frame
        Game.keys = pygame.key.get_pressed()

        # The current key modifiers (SHIFT, CTRL, etc.), updated each frame
        Game.keymods = pygame.key.get_mods()

        # The current position of the mouse, updated each frame
        Game.mousepos = (0, 0)

        # The current state of the mouse buttons, updated each frame
        # Note: This only covers the three main mouse buttons, not the
        # scroll wheel or other buttons.
        Game.mousebuttons = (0, 0, 0)

        # The default Pyrge font (you can change this in your own classes)
        Game.defaultFont = pygame.font.SysFont('arial', 16)

        # The total "scroll factor", which is applied to every Image to move
        # the screen around. On single-screen games (i.e., those inheriting from
        # GameLoop instead of World), we still have a scroll factor, but it
        # is always set to (0,0).
        Game.scroll = point.Point()

        # The width and height of the game window
        Game.width, Game.height = self.width, self.height

        # A surface representing the background
        self.background = pygame.Surface((self.width, self.height))

        # This is the "display list": all the drawable objects
        self._entities = pygame.sprite.LayeredDirty()
        self.addUpdater(self.update)

        # the game can set this to pause the game logic,
        # while still handling events
        self.paused = False
Esempio n. 15
0
 def __new__(cls, *args, **kwargs):
     self = super(PyGameDriver, cls).__new__(cls, *args, **kwargs)
     event.init()
     return self
Esempio n. 16
0
 def __new__(cls, *args, **kwargs):
     self = super(PyGameDriver, cls).__new__(cls, *args, **kwargs)
     event.init()
     return self
Esempio n. 17
0
 def setUp(self):
     pygame.display.init()
     fastevent.init()
     event.clear()
     self.assert_(not event.get())
Esempio n. 18
0
    def __init__(self, width=640, height=480, fps=30, scale=1, initmixer=True):
        """Create a basic game structure.

            @param width: The width of the game window (default 640).
            @param height: The height of the game window (default 480).
            @param fps: The framerate of the game in frames per second
                (default 30).
            @param scale: The scale factor of the game's graphics (default 1).
            @param initmixer: Whether to set up the mixer module for
                high-quality sounds (default True).
        """

        # pre-initialize the mixer module to use 44.1kHz sampling
        # the defaults are:
        # frequency = 22050 (22.050 kHz)
        # size = -16 (16-bit signed integers)
        # channels = 2 (stereo sound)
        # buffer = 4096
        # TODO: make a way to support arbitary mixing values
        if initmixer:
            pygame.mixer.pre_init(frequency=44100)

        # initialize pygame and the fastevent module
        pygame.init()
        pgevent.init()

        # create the main screen (we'll fill this in once the game starts)
        self.screen = None

        # initialize event handlers
        self._evtHandlers = []
        for etype in xrange(pygame.NUMEVENTS):
            self._evtHandlers.append([])

        # initialize "update" list
        self._updates = []

        # this will hold a list of "dirty" rectangles to repaint
        self._rectList = None

        # make a clock to limit CPU usage
        self.clock = pygame.time.Clock()

        # this is the time elapsed in the current frame
        self.frameTime = 0.0

        # this is the scale factor from "real time" to "game time"
        self.timeScale = 1

        # copy constructor arguments into properties
        self.width = width
        self.height = height
        self.fps = fps

        # the scale factor of graphics
        # (all graphics will be scaled by this amount in both x and y directions)
        self.scale = scale

        # copy some useful properties into the global structure

        # A pointer to the game world
        Game.world = self

        # A pointer to the game clock (a Clock object)
        Game.clock = self.clock

        # The time spent in the previous frame (used for e.g., velocity)
        Game.elapsed = self.frameTime

        # The game's frames per second setting (not necessarily the _actual_ FPS)
        Game.fps = self.fps

        # The current state of the keyboard, updated each frame
        Game.keys = pygame.key.get_pressed()

        # The current key modifiers (SHIFT, CTRL, etc.), updated each frame
        Game.keymods = pygame.key.get_mods()

        # The current position of the mouse, updated each frame
        Game.mousepos = (0,0)

        # The current state of the mouse buttons, updated each frame
        # Note: This only covers the three main mouse buttons, not the
        # scroll wheel or other buttons.
        Game.mousebuttons = (0,0,0)

        # The default Pyrge font (you can change this in your own classes)
        Game.defaultFont = pygame.font.SysFont('arial', 16)

        # The total "scroll factor", which is applied to every Image to move
        # the screen around. On single-screen games (i.e., those inheriting from
        # GameLoop instead of World), we still have a scroll factor, but it
        # is always set to (0,0).
        Game.scroll = point.Point()

        # The width and height of the game window
        Game.width, Game.height = self.width, self.height

        # A surface representing the background
        self.background = pygame.Surface((self.width, self.height))

        # This is the "display list": all the drawable objects
        self._entities = pygame.sprite.LayeredDirty()
        self.addUpdater(self.update)

        # the game can set this to pause the game logic,
        # while still handling events
        self.paused = False