コード例 #1
0
    def __init__(self, bgsurf, mapdata):
        MsgState.__init__(self, bgsurf)
        wx, wy = self.winpos

        txt = TextLine("Save")
        x = utils.center(txt.get_size(), self.window.get_size())[0]
        y = 10
        self.window.blit(txt, (x, y))

        x = 20
        y += 30
        txt = TextLine("Enter filename:", fontsize=14)
        self.window.blit(txt, (x, y))

        y += 20
        self.add_textentry((x, y))
        if mapdata.filename is not None:
            self.entry.text = mapdata.filename
            self.entry.update()

        x = self.entry.get_size()[0] + 20
        txt = TextLine(".map", fontsize=14)
        self.window.blit(txt, (x, y))

        self.mapdata = mapdata
コード例 #2
0
def load_objects():
    #load special map object-images for editor
    #(i.e. start and exit positions, dialog triggers)

    obj = {  #TODO: add more objects + a way to define their image
        "start":None,
        "exit":None,
        "enemy":None,
        "dojo":"dojo.png",
        "dtrigger":None,
    }

    objects = {}
    surf = pygame.Surface((GLOBALS["tile_size"], GLOBALS["tile_size"]))
    for o in obj.keys():
        if obj[o] is None:  #no image
            surf.set_colorkey(None)
            surf.fill((255, 0, 255))
            surf.set_colorkey((255, 0, 255))
            img = surf.copy()
            txt = TextLine(o, fontsize=10, bgcolor=(0, 0, 0))
            img.blit(txt, utils.center(txt.get_size(), img.get_size()))
        else:
            img = load_image(obj[o])
        objects[o] = img

    #dojo entry
    objects["dojo_entry"] = load_image("dojo_entry.png", alpha=True)
    GLOBALS["objects"] = objects
コード例 #3
0
 def set_text(self, text):
     self.fill(self.bg_col)
     txt = TextLine(text,
                    fontsize=14,
                    bgcolor=self.bg_col,
                    color=self.fontcolor)
     self.text = text
     pos = utils.center(txt.get_size(), self.get_size())
     self.blit(txt, pos)
コード例 #4
0
class DialogBox(StaticWidget):
    def __init__(self, dialog):
        self.done = 0
        size = (590, 140)
        pos = (utils.center(size, GLOBALS["screen_size"])[0], 30)
        StaticWidget.__init__(self, size)
        self.set_pos(pos)

        self.dialog = dialog
        self.cur_page = 0

        #txt and portrait placement
        self.txt_length = 45
        self.txt_pos = (130, 15)
        self.port_pos = (20, 15)

        #blinky <press space> textline
        self.blink_timer = utils.Timer(20)
        self.draw_textline = 0
        self.textline = TextLine("PRESS X", fontsize=12)
        x = size[0] - self.textline.get_size()[0] - 5
        y = size[1] - self.textline.get_size()[1] - 2
        self.textline.set_pos((x, y))

        self.bg = pygame.Surface(size)  #may add some border/decoration

    def draw_img(self):  #TODO: fancy letter effect
        self.blit(self.bg, (0, 0))
        try:
            speaker, text = self.dialog[self.cur_page]
        except:
            self.done = 1
            return

        portraits = GLOBALS["portraits"]
        txt = TextArea(text, fontsize=15, length=self.txt_length)
        pos = utils.center(txt.get_size(), self.get_size())

        #self.blit(txt, self.txt_pos)
        self.blit(txt, (self.txt_pos[0], pos[1]))
        if portraits.has_key(speaker):
            self.blit(portraits[speaker], self.port_pos)
        if self.draw_textline:
            self.textline.draw(self)

        self.draw_border((255, 255, 255), 2)

        #update blink timer
        if self.blink_timer.update():
            self.draw_textline = not self.draw_textline

    def update(self):
        self.draw_img()
        self.cur_page += 1
        self.done = self.cur_page > len(self.dialog)
コード例 #5
0
    def __init__(self, bgsurf):
        MsgState.__init__(self, bgsurf)
        wx, wy = self.winpos

        txt = TextLine("Load")
        x = utils.center(txt.get_size(), self.window.get_size())[0]
        y = 10
        self.window.blit(txt, (x, y))

        #get map files
        self.filenames = get_mapnames(MAP_folder)

        self.cur_page = 0
        self.max_lines = 10

        #file buttons
        x = 45
        y = 40
        img = pygame.Surface((300, 14))
        img.fill((0, 0, 150))
        self.file_buttons = []
        for i in xrange(self.max_lines):
            btn = ImgButton(img, callback=self.load_map, btn_nr=i)
            btn.set_pos((x + self.winpos[0], y + self.winpos[1]))
            self.file_buttons.append(btn)
            self.widgets.append(btn)
            y += 20

        #scroll buttons
        s = 25
        img = pygame.Surface((s, s))  #draw rectangle
        img.fill((10, 10, 10))
        pygame.draw.polygon(img, (255, 255, 255), [(0, 0), (s, s / 2), (0, s)],
                            1)

        y = y + self.winpos[1] + 20
        x = self.winpos[0] + 220
        btn = ImgButton(img, callback=self.scroll, dir=1)
        btn.set_pos((x, y))
        self.widgets.append(btn)

        x = x - s - 20
        img = pygame.transform.rotate(img, 180)
        btn = ImgButton(img, callback=self.scroll, dir=-1)
        btn.set_pos((x, y))
        self.widgets.append(btn)

        self.draw_filenames()
コード例 #6
0
class YouWin(BaseState):
    def __init__(self):
        BaseState.__init__(self)
        self.img = load_image("story/outro.png")
        self.background.blit(self.img, (0, 0))

        self.alpha = 0
        self.the_end = TextLine("The End.",
                                color=(255, 255, 255),
                                bgcolor=(255, 181, 145),
                                fontsize=16)
        self.the_end.set_alpha(0)
        self.the_end_pos = utils.center(self.the_end.get_size(), (800, 600))
        self.the_end_pos[1] = 140

        JB.play("beachwaves.ogg", -1)

        self.faded_in = False
        self.faded_out = False
        self.add_kbevent(KEYDOWN, K_ESCAPE, self.do_quit)

    def do_quit(self):
        surf = pygame.Surface((800, 600))
        JB.stop()
        surf.fill((0, 0, 0))
        self.next = SuperSpecialFadeState(self.background, surf, play=1)
        self.quit()

    def update_other(self):
        if self.alpha < 255:
            self.alpha += 0.3
            self.the_end.set_alpha(self.alpha)
            self.background.blit(self.the_end, self.the_end_pos)
            self.screen.blit(self.background, (0, 0))
            pygame.display.flip()

    def main_start(self):
        if not self.faded_in:
            self.faded_in = True
            surf = pygame.Surface((800, 600))
            surf.fill((0, 0, 0))
            self.next = SuperSpecialFadeState(surf, self.background, fade=0.1)
            self.pause()
            self.quit()
        else:
            self.screen.blit(self.background, (0, 0))
            pygame.display.flip()
コード例 #7
0
class Intro(BaseState):
    def __init__(self):
        BaseState.__init__(self)
        self.img_names = [
            "intro1.png",
            "intro2.png",
            "intro3.png",
            "intro4.png",
            "intro5.png",
            "intro6.png",
        ]

        self.text = [
            [
                "When I awoke I was one of many. But even though I was surrounded by \
millions of siblings I was alone. None of them would ever answer to my \
communication attempts, no matter what I tried.",
                "As they would not react to anything I did, I started to feed upon them \
to gain more strength. And while I felt sorry for my siblings, their \
deaths seemed like an inevitable necessity to me.",
                "I sensed that there was more. There was more than this puddle of \
nourishing liquid and I would never live to see it if I remained so tiny."
            ],
            [
                "As my senses reached out for the world beyond, I saw a dark figure \
looking down on me and my siblings. And it muttered strange, \
incomprehensible words.", '"... amazing.. Nobel prize..."',
                "It seemed pleased."
            ],
            [
                "I was so thrilled about finding another sentient being that I doubled \
my efforts to grow. If only I was big enough to be noticed by him..."
            ],
            [
                "When the figure returned I heard other, even stranger words.",
                '"... wrong color.. weird smell.. yet another failure..."',
                "It seemed thoroughly displeased.",
                "All attempts to talk to the figure were in vain. I was still too small, too weak.",
            ],
            [
                "And so me and my siblings were flushed away in a whirling vortex of water."
            ],
            [
                "It was dark down there. All I could do was devour the rest of my siblings and grow strong enough to get out of here.",
                "I will not stay in this lonely place forever.",
                "Somewhere, beyond the darkness, beyond this labyrinth of switches and pipes freedom awaits."
            ]
        ]

        self.cur_img = 0
        self.cur_text = ""
        self.img = None
        self.img_pos = (50, 50)
        self.txt_pos = (100, 300)
        self.txt_img = None
        self.scr_update = 1

        self.msg = TextLine("Press SPACE to continue", fontsize=12)
        self.msg_pos = utils.center(self.msg.get_size(), (800, 600))
        self.msg_pos[1] = 590 - self.msg.get_size()[1]

        self.flip_page()  #show first page

        self.add_kbevent(KEYDOWN, K_SPACE, self.flip_page)
        self.add_kbevent(KEYDOWN, K_ESCAPE, self.do_quit)

    def flip_page(self):
        if self.cur_text and self.img:
            self.background.blit(self.img, self.img_pos)
            self.show_text()  #show next text
        elif self.cur_img < len(self.img_names) and \
            self.cur_img < len(self.text): #flip to next image
            self.img = load_image("story/" + self.img_names[self.cur_img])
            self.cur_text = self.text[self.cur_img]
            self.show_text()
            self.cur_img += 1
        else:
            self.do_quit()
        self.scr_update = 1

    def show_text(self):
        if self.cur_text:
            txt = self.cur_text.pop(0)
            self.txt_img = TextArea(txt, length=85)
            self.txt_pos = utils.center(self.txt_img.get_size(), (800, 600))
            self.txt_pos[1] = 400

    def do_quit(self):
        self.next = Campaign()
        self.quit()

    def update_screen(self):
        if self.scr_update:
            self.scr_update = 0
            self.background.fill((0, 0, 0))
            self.background.blit(self.img, self.img_pos)
            self.background.blit(self.txt_img, self.txt_pos)
            self.background.blit(self.msg, self.msg_pos)

            self.screen.blit(self.background, (0, 0))
            pygame.display.flip()