示例#1
0
def main():
    # Create Game object
    game = Game(delta=True)

    # Load sprites
    sge.Sprite('rotator')
    fence_sprite = sge.Sprite('fence')

    # Load backgrounds
    layers = (sge.BackgroundLayer(fence_sprite, 0, 380, 0, yrepeat=False),)
    background = sge.Background(layers, 0xffffff)

    # Create objects
    circle = Circle(game.width // 2, game.height // 2)
    circle2 = Circle(22, 48)
    circle3 = Circle(486, 301)
    circle4 = Circle(50, 400)
    objects = (circle, circle2, circle3, circle4)

    # Create view
    views = (sge.View(0, 0),)

    # Create rooms
    room1 = sge.Room(objects, views=views, background=background)

    game.start()
示例#2
0
def main():
    # Create Game object
    Game(width=640, height=480)

    # Load sprites
    sge.Sprite('circle', width=32, height=32, origin_x=16, origin_y=16)
    fence = sge.Sprite('fence')

    # Load backgrounds
    layers = (sge.BackgroundLayer(fence, 0, 0, 0), )
    background = sge.Background(layers, 'white')

    # Create objects
    objects = []
    for i in xrange(4):
        circle = Circle(64, 64, i)
        objects.append(circle)

    # Create views
    views = []
    for x in xrange(2):
        for y in xrange(2):
            views.append(sge.View(0, 0, 320 * x, 240 * y, 320, 240))

    # Create rooms
    sge.Room(tuple(objects), 1280, 1024, tuple(views), background)

    sge.game.start()
示例#3
0
def main():
    # Create Game object
    game = Game()

    # Load sprites
    circle_sprite = sge.Sprite('circle',
                               width=64,
                               height=64,
                               origin_x=32,
                               origin_y=32)
    fence_sprite = sge.Sprite('fence')

    # Load backgrounds
    layers = (sge.BackgroundLayer(fence_sprite, 0, 380, 0, yrepeat=False), )
    background = sge.Background(layers, 0xffffff)

    # Create objects
    circle = Circle(game.width // 2, game.height // 2)
    objects = [circle]

    # Create view
    views = (sge.View(0, 0), )

    # Create rooms
    room1 = sge.Room(tuple(objects), views=views, background=background)

    game.start()
示例#4
0
def main():
    # Create Game object
    game = Game()

    # Load sprites
    circle_sprite = sge.Sprite('circle',
                               width=64,
                               height=64,
                               origin_x=32,
                               origin_y=32)
    circle_pop_sprite = sge.Sprite('circle_pop',
                                   width=64,
                                   height=64,
                                   origin_x=32,
                                   origin_y=32,
                                   fps=60)
    fence_sprite = sge.Sprite('fence')

    # Load backgrounds
    layers = (sge.BackgroundLayer(fence_sprite, 0, 380, 0, yrepeat=False), )
    layers2 = (sge.BackgroundLayer(fence_sprite, 0, 0, 0), )
    background = sge.Background(layers, 0xffffff)
    background2 = sge.Background(layers2, 'white')

    # Load fonts
    glob.font = sge.Font('Liberation Serif', 20)

    # Load sounds
    glob.pop_sound = sge.Sound('pop.ogg')

    # Load music
    glob.music = sge.Music('WhereWasI.ogg')

    # Create objects
    circle = Circle(game.width // 2, game.height // 2)
    circle2 = Circle(22, 48)
    circle3 = Circle(486, 301)
    circle4 = Circle(50, 400)
    circle5 = Circle(game.width // 2, game.height // 2)
    circle6 = Circle(52, 120)
    objects = (circle, circle2, circle3, circle4)
    objects2 = (circle5, circle6)

    # Create view
    views = (sge.View(0, 0), )

    # Create rooms
    room1 = Room('I am the first room!',
                 objects,
                 views=views,
                 background=background)
    room2 = Room('Second room on the house!', objects2, background=background2)

    game.start()
示例#5
0
    def __init__(self,
                 objects=(),
                 width=None,
                 height=None,
                 views=None,
                 background=None,
                 background_x=0,
                 background_y=0):
        """Constructor method.

        Arguments:

        - ``views`` -- A list containing all :class:`sge.View` objects
          in the room.  If set to :const:`None`, a new view will be
          created with ``x=0``, ``y=0``, and all other arguments
          unspecified, which will become the first view of the room.
        - ``background`` -- The :class:`sge.Background` object used.  If
          set to :const:`None`, a new background will be created with no
          layers and the color set to ``"black"``.

        All other arguments set the respective initial attributes of the
        room.  See the documentation for :class:`sge.Room` for more
        information.

        """
        self.width = width if width is not None else sge.game.width
        self.height = height if height is not None else sge.game.height
        self._start_width = self.width
        self._start_height = self.height
        self.background_x = background_x
        self.background_y = background_y

        if views is not None:
            self.views = list(views)
        else:
            self.views = [sge.View(0, 0)]
        self._start_views = self.views[:]

        if background is not None:
            self.background = background
        else:
            self.background = sge.Background((), 'black')
        self._start_background = self.background

        self.room_number = len(sge.game.rooms)
        sge.game.rooms.append(self)

        self._started = False

        self.objects = ()
        self.add(sge.game.mouse)
        for obj in objects:
            self.add(obj)
        self._start_objects = self.objects
示例#6
0
    def __init__(self,
                 objects=(),
                 width=None,
                 height=None,
                 views=None,
                 background=None,
                 background_x=0,
                 background_y=0,
                 object_area_width=None,
                 object_area_height=None):
        """
        Arguments:

        - ``views`` -- A list containing all :class:`sge.View` objects
          in the room.  If set to :const:`None`, a new view will be
          created with ``x=0``, ``y=0``, and all other arguments
          unspecified, which will become the first view of the room.
        - ``background`` -- The :class:`sge.Background` object used.  If
          set to :const:`None`, a new background will be created with no
          layers and the color set to black.

        All other arguments set the respective initial attributes of the
        room.  See the documentation for :class:`sge.Room` for more
        information.
        """
        self.rd = {}
        self.width = width if width is not None else sge.game.width
        self.height = height if height is not None else sge.game.height
        self.rd["swidth"] = self.width
        self.rd["sheight"] = self.height

        if object_area_width is None:
            object_area_width = sge.game.width
        if object_area_height is None:
            object_area_height = sge.game.height

        self.__object_area_width = object_area_width
        self.__object_area_height = object_area_height
        self.background_x = background_x
        self.background_y = background_y
        self.alarms = {}
        self.rd["new_objects"] = []
        self.rd["projections"] = []

        if views is not None:
            self.views = list(views)
        else:
            self.views = [sge.View(0, 0)]

        if background is not None:
            self.background = background
        else:
            self.background = sge.Background((), sge.Color("black"))

        self.rd["started"] = False

        self.objects = []
        r_set_object_areas(self)

        self.add(sge.game.mouse)
        for obj in objects:
            self.add(obj)
示例#7
0
    def __init__(self,
                 objects=(),
                 width=None,
                 height=None,
                 views=None,
                 background=None,
                 background_x=0,
                 background_y=0):
        self.fname = None
        self.empty = True
        self.unchanged = True
        self.opened = True
        self.name = ""
        self.cls = "sge.Room"
        self.real_objects = objects
        self.real_width = width if width is not None else 640
        self.real_height = height if height is not None else 480
        self.real_views = views

        self.grid = GRID_DEFAULT
        self.zoom = ZOOM_DEFAULT
        self.tool = TOOL_DEFAULT

        # TODO: Create buttons and other GUI elements

        w = self.get_width()
        h = self.get_height()

        width = w + SIDE_BAR_SIZE[0]
        height = h + TOP_BAR_SIZE[1]

        main_view = sge.View(0, 0, SIDE_BAR_SIZE[0], TOP_BAR_SIZE[1])
        sidebar_view = sge.View(self.get_width(), TOP_BAR_SIZE[1], 0,
                                TOP_BAR_SIZE[1], SIDE_BAR_SIZE[0],
                                SIDE_BAR_SIZE[1] - TOP_BAR_SIZE[1])
        topbar_view = sge.View(0, self.get_height(), 0, 0, *TOP_BAR_SIZE)
        views = [main_view, sidebar_view, topbar_view]

        super(Room, self).__init__(objects, width, height, views, background,
                                   background_x, background_y)

        obj = SaveButton(w + BUTTON_SAVE_POS[0], h + BUTTON_SAVE_POS[1])
        self.add(obj)
        obj = SaveAllButton(w + BUTTON_SAVE_ALL_POS[0],
                            h + BUTTON_SAVE_ALL_POS[1])
        self.add(obj)
        obj = LoadButton(w + BUTTON_LOAD_POS[0], h + BUTTON_LOAD_POS[1])
        self.add(obj)
        obj = GridTypeButton(w + BUTTON_GRID_POS[0], h + BUTTON_GRID_POS[1])
        self.add(obj)
        obj = ShiftButton(w + BUTTON_SHIFT_POS[0], h + BUTTON_SHIFT_POS[1])
        self.add(obj)
        obj = ReloadResourcesButton(w + BUTTON_RELOAD_RESOURCES_POS[0],
                                    h + BUTTON_RELOAD_RESOURCES_POS[1])
        self.add(obj)
        obj = BackgroundButton(w + BUTTON_BACKGROUND_POS[0],
                               h + BUTTON_BACKGROUND_POS[1])
        self.add(obj)
        obj = ViewsButton(w + BUTTON_VIEWS_POS[0], h + BUTTON_VIEWS_POS[1])
        self.add(obj)
        obj = SettingsButton(w + BUTTON_SETTINGS_POS[0],
                             h + BUTTON_SETTINGS_POS[1])
        self.add(obj)
        obj = ZoomResetButton(w + BUTTON_ZOOM_RESET_POS[0],
                              h + BUTTON_ZOOM_RESET_POS[1])
        self.add(obj)
        obj = ZoomOutButton(w + BUTTON_ZOOM_OUT_POS[0],
                            h + BUTTON_ZOOM_OUT_POS[1])
        self.add(obj)
        obj = ZoomInButton(w + BUTTON_ZOOM_IN_POS[0],
                           h + BUTTON_ZOOM_IN_POS[1])
        self.add(obj)
        obj = PreviousRoomButton(w + BUTTON_PREVIOUS_ROOM_POS[0],
                                 h + BUTTON_PREVIOUS_ROOM_POS[1])
        self.add(obj)
        obj = NextRoomButton(w + BUTTON_NEXT_ROOM_POS[0],
                             h + BUTTON_NEXT_ROOM_POS[1])
        self.add(obj)
        obj = CloseRoomButton(w + BUTTON_CLOSE_ROOM_POS[0],
                              h + BUTTON_CLOSE_ROOM_POS[1])
        self.add(obj)
        obj = ToolButton(w + BUTTON_TOOL_POS[0], h + BUTTON_TOOL_POS[1])
        self.add(obj)
        obj = ObjectClassButton(w + BUTTON_CLASS_POS[0],
                                h + BUTTON_CLASS_POS[1])
        self.add(obj)
        obj = ObjectImageIndexButton(w + BUTTON_IMAGE_INDEX_POS[0],
                                     h + BUTTON_IMAGE_INDEX_POS[1])
        self.add(obj)
        obj = ObjectImageAlphaButton(w + BUTTON_IMAGE_ALPHA_POS[0],
                                     h + BUTTON_IMAGE_ALPHA_POS[1])
        self.add(obj)
        obj = ObjectImageBlendButton(w + BUTTON_IMAGE_BLEND_POS[0],
                                     h + BUTTON_IMAGE_BLEND_POS[1])
        self.add(obj)
        obj = ObjectVisibleButton(w + BUTTON_VISIBLE_POS[0],
                                  h + BUTTON_VISIBLE_POS[1])
        self.add(obj)
        obj = ObjectActiveButton(w + BUTTON_ACTIVE_POS[0],
                                 h + BUTTON_ACTIVE_POS[1])
        self.add(obj)
        obj = ObjectDetectsCollisionsButton(
            w + BUTTON_DETECTS_COLLISIONS_POS[0],
            h + BUTTON_DETECTS_COLLISIONS_POS[1])
        self.add(obj)
        obj = ObjectArgsButton(w + BUTTON_ARGS_POS[0], h + BUTTON_ARGS_POS[1])
        self.add(obj)