Пример #1
0
def launch():
	spyral.init()
	
	#this function is in game.py
	init()
	spyral.director.push(Menu(player.Player()))
	spyral.director.push(Tablet())
	

	pygame.mouse.set_visible(False)
Пример #2
0
    def init(self,
             size=(0, 0),
             max_ups = 30,
             max_fps = 30,
             fullscreen = False,
             caption = "spyral"):
        """
        Initializes the director.

        | *size* is the resolution of the display. (0,0) uses the screen resolution
        | *max_ups* sets the number of times scene.update() should be
           called per frame. This will remain the same, even if fps drops.
        | *max_fps* sets the fps cap on the game.
        | *fullscreen* determines whether the display starts fullscreen
        | *caption* is the window caption
        """
        if self._initialized:
            print('Warning: Tried to initialize the director twice. Ignoring.')
        spyral.init()

        flags = 0
        # These flags are going to be managed better or elsewhere later
        resizable = False
        noframe = False

        if resizable:
            flags |= pygame.RESIZABLE
        if noframe:
            flags |= pygame.NOFRAME
        if fullscreen:
            flags |= pygame.FULLSCREEN
        self._screen = pygame.display.set_mode(size, flags)

        self._initialized = True

        self._camera = spyral.camera.Camera(virtual_size=size, root=True)
        pygame.display.set_caption(caption)

        self._stack = []
        self._tick = 0

        self._max_ups = max_ups
        self._max_fps = max_fps
Пример #3
0
    def init(self,
             size=(0, 0),
             max_ups = 30,
             max_fps = 30,
             fullscreen = False,
             caption = "spyral"):
        """
        Initializes the director.

        | *size* is the resolution of the display. (0,0) uses the screen resolution
        | *max_ups* sets the number of times scene.update() should be
           called per frame. This will remain the same, even if fps drops.
        | *max_fps* sets the fps cap on the game.
        | *fullscreen* determines whether the display starts fullscreen
        | *caption* is the window caption
        """
        if self._initialized:
            print('Warning: Tried to initialize the director twice. Ignoring.')
        spyral.init()

        flags = 0
        # These flags are going to be managed better or elsewhere later
        resizable = False
        noframe = False

        if resizable:
            flags |= pygame.RESIZABLE
        if noframe:
            flags |= pygame.NOFRAME
        if fullscreen:
            flags |= pygame.FULLSCREEN
        self._screen = pygame.display.set_mode(size, flags)

        self._initialized = True

        self._camera = spyral.camera.Camera(virtual_size=size, root=True)
        pygame.display.set_caption(caption)

        self._stack = []
        self._tick = 0

        self._max_ups = max_ups
        self._max_fps = max_fps
Пример #4
0
        # More setup here

    def render(self):
        """
        The render function should call .draw() on the scene's group(s).
        Unless your game logic should be bound by framerate,
        logic should go elsewhere.
        """
        self.group.draw()

    def update(self, dt):
        """
        The update function should contain or call out to all the logic.
        Here is where group.update() should be called for the groups, where
        event handling should be taken care of, etc.
        """
        for event in self.event_handler.get():
            if event['type'] == 'QUIT':
                spyral.quit()
                sys.exit()

        self.group.update(dt)


if __name__ == "__main__":
    spyral.init()  # Always call spyral.init() first
    spyral.director.init(SIZE)  # the director is the manager for your scenes
    spyral.director.push(Game())  # push means that this Game() instance is
    # on the stack to run
    spyral.director.run()  # This will run your game. It will not return.
Пример #5
0
        
        # Register all event handlers
        self.register('system.quit', sys.exit)
        self.register('input.keyboard.down.p', self.previous)
        self.register('input.keyboard.down.n', self.next)
        self.register('input.keyboard.down.q', sys.exit)
        self.register('input.keyboard.down.escape', sys.exit)

                                
    def set_animation(self):
        self.title.render(ANIMATIONS[self.index][0])
        self.block.stop_all_animations()
        self.block.y = 300 # Reset the y-coordinate.
        a = ANIMATIONS[self.index][1] + DELAY
        a.loop = True
        self.block.animate(a)
        
    def next(self):
        self.index += 1
        self.index %= len(ANIMATIONS)
        self.set_animation()
        
    def previous(self):
        self.index -= 1
        self.index %= len(ANIMATIONS)
        self.set_animation()

if __name__ == "__main__":
    spyral.init()
    spyral.director.init(SIZE)
    spyral.director.run(scene=AnimationExamples())
Пример #6
0
            self.group.add(self.ball)
        if self.ball.bounce_right(self.right_paddle.rect):
            self.ball.kill()
            self.ball = Ball()
            self.score.r += 1
            self.score.render()
            self.left_paddle.rect.center = (geom['paddle_in_width'],
                                            geom['height'] / 2)
            self.right_paddle.rect.midright = (geom['width'] -
                                               geom['paddle_in_width'],
                                               geom['height'] / 2)
            self.group.add(self.ball)


if __name__ == "__main__":
    spyral.init()
    colors['bg'] = (0, 0, 0)
    colors['paddle'] = (255, 255, 255)
    colors['ball'] = (255, 255, 255)
    colors['score'] = (255, 255, 255)
    colors['menu'] = (255, 255, 255)

    geom['size'] = (640, 480)
    geom['width'] = 640
    geom['height'] = 480
    geom['paddle'] = (int(.02 * geom['width']), int(.3 * geom['height']))
    geom['paddle_in_width'] = int(.03 * geom['width'])
    geom['paddle_speed'] = geom['height'] / (TICKS_PER_SECOND * 1.5)
    geom['ball'] = int(.02 * geom['width'])
    geom['ball_speed'] = geom['paddle_speed'] / 1.1
    geom['score_in_height'] = int(.03 * geom['height'])
Пример #7
0
        # Anything more advanced will want to make new cameras on top of this
        self.group = spyral.sprite.Group(self.camera)
        bg = spyral.util.new_surface(SIZE)
        bg.fill(BG_COLOR)
        self.camera.set_background(bg)
        # More setup here
                
    def render(self):
        """
        The render function should call .draw() on the scene's group(s) and
        camera(s). Unless your game logic should be bound by framerate,
        logic should go elsewhere.
        """
        self.group.draw()
        self.camera.draw()
        
    def update(self, tick):
        """
        The update function should contain or call out to all the logic.
        Here is where group.update() should be called for the groups, where
        event handling should be taken care of, etc.
        """
        self.group.update()

if __name__ == "__main__":
    spyral.init() # Always call spyral.init() first
    spyral.director.init(SIZE) # the director is the manager for your scenes
    spyral.director.push(Game()) # push means that this Game() instance is
                                 # on the stack to run
    spyral.director.run() # This will run your game. It will not return.
Пример #8
0
 def __init__(self):
     spyral.init()
     spyral.director.init((100, 100))
     spyral.Scene.__init__(self, (100, 100))