Ejemplo n.º 1
0
 def serve(self, direction=1):
     if glob.player1.score < 10 and glob.player2.score < 10:
         # Next round
         self.x = self.xstart
         self.y = self.ystart
         self.xvelocity = 2 * direction
         self.yvelocity = 0
     else:
         # Game Over!
         glob.hud_sprite.draw_clear()
         x = glob.hud_sprite.width / 2
         p1score = glob.player1.score
         p2score = glob.player2.score
         p1text = "WIN" if p1score > p2score else "LOSE"
         p2text = "WIN" if p2score > p1score else "LOSE"
         glob.hud_sprite.draw_text(glob.hud_font, p1text, x - 16, 16,
                                   color="white", halign=sge.ALIGN_RIGHT,
                                   valign=sge.ALIGN_TOP)
         glob.hud_sprite.draw_text(glob.hud_font, p2text, x + 16, 16,
                                   color="white", halign=sge.ALIGN_LEFT,
                                   valign=sge.ALIGN_TOP)
         m = "What is the name of the winner?"
         name = sge.get_text_entry(m, 'Nobody')
         if name is not None:
             m = "Congratulations, {0}! You win!".format(name)
             sge.show_message(m)
         self.destroy()
 def do_effect(self):
     # TODO: File selection dialog to make this better.
     m = "Please enter the name of the file to load."
     d = os.path.normpath(os.path.realpath(os.path.join(
         DIRNAME, "data", "rooms", "*.rmj")))
     entry = sge.get_text_entry(m, d)
     if entry is not None:
         room = Room.load(entry)
         room.resume()
Ejemplo n.º 3
0
 def do_effect(self):
     # TODO: File selection dialog to make this better.
     m = "Please enter the name of the file to load."
     d = os.path.normpath(
         os.path.realpath(os.path.join(DIRNAME, "data", "rooms", "*.rmj")))
     entry = sge.get_text_entry(m, d)
     if entry is not None:
         room = Room.load(entry)
         room.resume()
Ejemplo n.º 4
0
    def save(self, fname=None):
        """Save settings to a file."""
        if fname is None:
            if self.fname is not None:
                fname = self.fname
            else:
                # TODO: Create a file selection dialog for this.
                m = "Please enter the name of the file to save to."
                d = os.path.normpath(
                    os.path.realpath(
                        os.path.join(DIRNAME, "data", "rooms", "*.rmj")))
                entry = sge.get_text_entry(m, d)
                if entry is not None:
                    fname = entry
                else:
                    return
        elif os.path.exists(fname):
            m = "{0} already exists. Overwrite?".format(fname)
            if not sge.show_message(m, ("No", "Yes")):
                return

        config = {'views': [], 'objects': []}
        config['class'] = self.cls
        config['width'] = self.width
        config['height'] = self.height
        config['background'] = self.background.id
        config['background_x'] = self.background_x
        config['background_y'] = self.background_y

        for view in self.views:
            config['views'].append({
                'x': view.x,
                'y': view.y,
                'xport': view.xport,
                'yport': view.yport,
                'width': view.width,
                'height': view.height
            })

        for obj in self.objects:
            config['objects'].append({
                'class': obj.cls,
                'x': obj.x,
                'y': obj.y,
                'z': obj.z,
                'args': obj.args,
                'kwargs': obj.kwargs
            })

        with open(fname, 'w') as f:
            json.dump(config, f, indent=4, sort_keys=True)

        self.unchanged = True
    def do_effect(self):
        m = "Enter the horizontal shift amount (in pixels)."
        hshift = sge.get_text_entry(m)

        if hshift is not None:
            m = "Enter the vertical shift amount (in pixels)."
            vshift = sge.get_text_entry(m)

            if vshift is not None:
                try:
                    hshift = float(hshift)
                except ValueError:
                    hshift = 0

                try:
                    vshift = float(vshift)
                except ValueError:
                    vshift = 0

                for obj in sge.game.current_room.real_objects:
                    if len(obj.args) > 0:
                        obj.args[0] += hshift
                        if len(obj.args) > 1:
                            obj.args[1] += vshift
Ejemplo n.º 6
0
    def do_effect(self):
        m = "Enter the horizontal shift amount (in pixels)."
        hshift = sge.get_text_entry(m)

        if hshift is not None:
            m = "Enter the vertical shift amount (in pixels)."
            vshift = sge.get_text_entry(m)

            if vshift is not None:
                try:
                    hshift = float(hshift)
                except ValueError:
                    hshift = 0

                try:
                    vshift = float(vshift)
                except ValueError:
                    vshift = 0

                for obj in sge.game.current_room.real_objects:
                    if len(obj.args) > 0:
                        obj.args[0] += hshift
                        if len(obj.args) > 1:
                            obj.args[1] += vshift
Ejemplo n.º 7
0
    def save(self, fname=None):
        """Save settings to a file."""
        if fname is None:
            if self.fname is not None:
                fname = self.fname
            else:
                # TODO: Create a file selection dialog for this.
                m = "Please enter the name of the file to save to."
                d = os.path.normpath(os.path.realpath(os.path.join(DIRNAME, "data", "rooms", "*.rmj")))
                entry = sge.get_text_entry(m, d)
                if entry is not None:
                    fname = entry
                else:
                    return
        elif os.path.exists(fname):
            m = "{0} already exists. Overwrite?".format(fname)
            if not sge.show_message(m, ("No", "Yes")):
                return

        config = {"views": [], "objects": []}
        config["class"] = self.cls
        config["width"] = self.width
        config["height"] = self.height
        config["background"] = self.background.id
        config["background_x"] = self.background_x
        config["background_y"] = self.background_y

        for view in self.views:
            config["views"].append(
                {
                    "x": view.x,
                    "y": view.y,
                    "xport": view.xport,
                    "yport": view.yport,
                    "width": view.width,
                    "height": view.height,
                }
            )

        for obj in self.objects:
            config["objects"].append(
                {"class": obj.cls, "x": obj.x, "y": obj.y, "z": obj.z, "args": obj.args, "kwargs": obj.kwargs}
            )

        with open(fname, "w") as f:
            json.dump(config, f, indent=4, sort_keys=True)

        self.unchanged = True
    def save(self, fname=None):
        """Save settings to a file."""
        if fname is None:
            if self.fname is not None:
                fname = self.fname
            else:
                # TODO: Create a file selection dialog for this.
                m = "Please enter the name of the file to save to."
                d = os.path.normpath(os.path.realpath(os.path.join(
                    DIRNAME, "data", "rooms", "*.rmj")))
                entry = sge.get_text_entry(m, d)
                if entry is not None:
                    fname = entry
                else:
                    return
        elif os.path.exists(fname):
            m = "{0} already exists. Overwrite?".format(fname)
            if not sge.show_message(m, ("No", "Yes")):
                return

        config = {'views': [], 'objects': []}
        config['class'] = self.cls
        config['width'] = self.width
        config['height'] = self.height
        config['background'] = self.background.id
        config['background_x'] = self.background_x
        config['background_y'] = self.background_y

        for view in self.views:
            config['views'].append(
                {'x': view.x, 'y': view.y, 'xport': view.xport,
                 'yport': view.yport, 'width': view.width,
                 'height': view.height})

        for obj in self.objects:
            config['objects'].append(
                {'class': obj.cls, 'x': obj.x, 'y': obj.y, 'z': obj.z,
                 'args': obj.args, 'kwargs': obj.kwargs})

        with open(fname, 'w') as f:
            json.dump(config, f, indent=4, sort_keys=True)

        self.unchanged = True