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
class TextEntry(StaticWidget):
    def __init__(self, max=15):
        size = (max * 14, 20)
        StaticWidget.__init__(self, size)
        self.fill((0, 0, 0))

        self.text_line = TextLine(" " * max, 14)
        self.max = max
        self.text = ""

    def add_character(self, keynr):
        if keynr is None:
            self.rem_character()
            return

        keyname = pygame.key.name(keynr)

        if (keyname in string.ascii_letters or \
            keyname in string.digits) and \
            len(self.text) < self.max:
            self.text = self.text + keyname
            self.update()

    def rem_character(self):
        if self.text:
            self.text = self.text[:-1]
            self.update()

    def update(self):
        self.fill((0, 0, 0))
        self.text_line.update(self.text)
        self.blit(self.text_line, (0, 0))
示例#3
0
 def show_msg(self, txt):
     #show text on bottom of screen
     self.background.blit(self.no_msg, self.no_msg_pos)
     text = TextLine(txt, fontsize=12)
     pos = utils.center(text.get_size(), ((800, 600)))
     pos[1] = 590 - text.get_size()[1]
     self.background.blit(text, pos)
示例#4
0
 def __init__(self,
              text,
              fontsize=20,
              color=(255, 242, 0),
              bgcolor=(0, 0, 0),
              font="courier-bold"):
     OldTextLine.__init__(self, text, fontsize, (255, 242, 0), bgcolor,
                          font)
    def __init__(self, max=15):
        size = (max * 14, 20)
        StaticWidget.__init__(self, size)
        self.fill((0, 0, 0))

        self.text_line = TextLine(" " * max, 14)
        self.max = max
        self.text = ""
 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)
示例#7
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)
示例#8
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()
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()
示例#10
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
    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)
示例#12
0
    def draw_filenames(self):
        self.scr_update = 1
        min = self.cur_page * self.max_lines

        for i in xrange(self.max_lines):
            btn = self.file_buttons[i]
            btn.fill((0, 0, 150))
            nr = i + min
            if nr < len(self.filenames):
                txt = TextLine(self.filenames[nr],
                               fontsize=14,
                               bgcolor=(0, 0, 150))
                btn.blit(txt, (0, 0))
示例#13
0
    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 __init__(self, lvl_map="tutorial.map", testing=False, prev=None):
        State.__init__(self)
        self.fps = 60
        self.prev = prev
        tsize = GLOBALS["tile_size"]
        self.trigger = None
        self.exit_timer = Timer(50)
        self.exit_timer.deactivate()
        pygame.mixer.music.set_volume(1)
        GLOBALS["jb"].play("bgm.xm", -1)

        player_data["health"] = 9  #always full health on map start
        #player_data["lives"] = #for gameover testing

        #scrolling background - maybe later XD
        #bg_back = GLOBALS["backgrounds"]["fuji.png"]
        #bg_front = GLOBALS["backgrounds"]["trees.png"]
        #self.scroll_bg = Background(bg_back, bg_front)

        #non-scrolling background
        self.bg = GLOBALS["backgrounds"]["fuji.png"]

        #map
        self.map_filename = lvl_map
        self.map = Map(lvl_map)
        self.lvl_map = self.map["tilemap"]
        x, y = self.map["max"]
        self.lvl_img, self.blocks = self.map.draw(editing=False)
        self.lvl_layer = pygame.Surface(self.lvl_img.get_size())

        #other spritegroups
        self.bullets = pygame.sprite.Group()

        #player
        self.player = Nanji(None)
        self.player.set_pos((self.map["start"][0]*tsize, self.map["start"][1]*tsize))
        self.sprites.add(self.player)

        #camera
        self.camera = Camera(self.player)
        screen_x, screen_y = GLOBALS["screen_size"]
        mx = self.map["max"][0] * tsize - screen_x
        my = self.map["max"][1] * tsize - screen_y + 4*tsize
        self.camera.set_max(mx,my)
        self.player.camera = self.camera
        self.camera.update()

        #add enemies
        self.enemies = pygame.sprite.Group()
        clan = self.map["options"]["clan"]
        for e in self.map.enemies:
            ninjat = Ninjat(self.camera, clan)
            ninjat.set_pos((e[0]*tsize, e[1]*tsize-32))#FIXME:enemies are spawned too low..?
            self.enemies.add(ninjat)
            self.sprites.add(ninjat)

        #ui layer
        self.ui_layer = StaticWidget((GLOBALS["screen_size"][0], 30))
        self.ui_layer.fill((255,0,255))
        self.ui_layer.set_colorkey((255,0,255))
        self.ui_layer.set_pos((0,0))
        self.heart_img = GLOBALS["ui_stuff"]["heart"]
        self.heart_empty_img = GLOBALS["ui_stuff"]["heart_empty"]
        self.life_img = GLOBALS["ui_stuff"]["life"]
        self.fontholder = TextLine("", fontsize=16)
        self.update_ui()

        #keyboard events
        self.key_pressed = {
            "up": 0, "down": 0, "left": 0, "right": 0,
            "jump":0, "sprint":0, "throw": 0, "shuriken": 0,
        }

        self.add_kbevent(KEYDOWN, K_LEFT, self.set_keypress, k="left", v=1)  #move
        self.add_kbevent(KEYDOWN, K_RIGHT, self.set_keypress, k="right", v=1)
        self.add_kbevent(KEYDOWN, K_UP, self.set_keypress, k="up", v=1)
        self.add_kbevent(KEYDOWN, K_DOWN, self.set_keypress, k="down", v=1)
        self.add_kbevent(KEYDOWN, K_SPACE, self.set_keypress, k="jump", v=1)  #jump
        self.add_kbevent(KEYDOWN, K_LSHIFT, self.set_keypress, k="sprint", v=1)  #sprint
        self.add_kbevent(KEYDOWN, K_RSHIFT, self.set_keypress, k="sprint", v=1)
        self.add_kbevent(KEYDOWN, K_RCTRL, self.set_keypress, k="throw", v=1)  #throw
        self.add_kbevent(KEYDOWN, K_LCTRL, self.set_keypress, k="throw", v=1)

        self.add_kbevent(KEYUP, K_LEFT, self.set_keypress, k="left", v=0)
        self.add_kbevent(KEYUP, K_RIGHT, self.set_keypress, k="right", v=0)
        self.add_kbevent(KEYUP, K_UP, self.set_keypress, k="up", v=0)
        self.add_kbevent(KEYUP, K_DOWN, self.set_keypress, k="down", v=0)
        self.add_kbevent(KEYUP, K_SPACE, self.set_keypress, k="jump", v=0)
        self.add_kbevent(KEYUP, K_LSHIFT, self.set_keypress, k="sprint", v=0)
        self.add_kbevent(KEYUP, K_RSHIFT, self.set_keypress, k="sprint", v=0)
        self.add_kbevent(KEYUP, K_RCTRL, self.set_keypress, k="throw", v=0)
        self.add_kbevent(KEYUP, K_LCTRL, self.set_keypress, k="throw", v=0)

        if testing:
            self.add_kbevent(KEYUP, K_ESCAPE, self.quit)
    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 __init__(self):
        State.__init__(self)
        self.buttons = {}

        #tileset area
        self.tileset_area = StaticWidget((1020, 280))
        self.tileset_area.set_pos((2, 485))
        self.tileset_area.pos = (2, 485)
        ca = ClickArea(pygame.Rect([2, 485, 1024, 280]), self.choose_tiletype)
        self.widgets.append(ca)
        self.tileset_id = "ts_tileset"
        self.marked_type = None
        self.load_tileset()

        #set clan
        buttons = [
            "wood", "day", "fire", "life", "earth", "night", "metal", "water",
            "death"
        ]

        x, y = 900, 50
        for clan in buttons:
            btn = ImgButton(GLOBALS["signets"][clan][1], \
                self.set_clan, clan=clan)
            btn.set_pos((x, y))
            self.widgets.append(btn)
            self.buttons[clan] = btn
            btn.draw(self.background)
            y = y + btn.get_size()[1] + 5
        self.clan = "fire"

        #Camera
        self.camera = Camera(None)

        #load empty map
        self.filename = ""
        self.load_map(new=True)

        #map area
        self.map_area = StaticWidget((640, 480))
        self.map_area.set_pos((0, 0))
        self.map_area_rect = pygame.Rect([0, 0, 640, 480])
        self.widgets.append(ca)

        #grid overlay for map area
        w, h = self.map_area.get_size()
        self.grid = StaticWidget((w, h))
        self.grid.fill((255, 0, 255))
        self.grid.set_colorkey((255, 0, 255))
        self.grid.set_alpha(100)
        for row in xrange(h / tsize):
            for col in xrange(w / tsize):
                pygame.draw.line(self.grid, (255, 255, 255), (col * 32, 0),
                                 (col * 32, h))
                pygame.draw.line(self.grid, (255, 255, 255), (0, row * 32),
                                 (w, row * 32))
        self.grid.set_pos(self.map_area.get_pos())

        #buttons
        buttons = [(" NEW ", self.new_map), (" LOAD ", self.open_file),
                   (" SAVE AS ", self.save_file), (" SAVE ", self.save_map)]

        x, y = 650, 1
        for b in buttons:
            name, callback = b
            btn = ImgButton(TextLine(name), callback)
            btn.set_pos((x, y))
            btn.draw_border((255, 255, 255))
            self.widgets.append(btn)
            btn.draw(self.background)
            x = x + btn.get_size()[0] + 4

        #add objects
        buttons = [
            (" delete obj", "delete"),
            (" add start ", "start"),
            (" add exit ", "exit"),
            (" add enemy ", "enemy"),
            (" add dialog-trigger ", "dtrigger"),
        ]

        x, y = 650, 50
        for b in buttons:
            name, cmd = b
            btn = ImgButton(TextLine(name, fontsize=15), \
                self.select_add_object, cmd=cmd)
            btn.set_pos((x, y))
            self.widgets.append(btn)
            btn.draw(self.background)
            y = y + btn.get_size()[1] + 5
            self.buttons[cmd] = btn

        #TEST button :)
        btn = ImgButton(TextLine(" TEST ", fontsize=25), self.test)
        btn.set_pos((900, 420))
        btn.draw_border((255, 255, 255))
        self.widgets.append(btn)
        btn.draw(self.background)

        #keyboard events
        pygame.key.set_repeat(10, 20)

        #scroll map
        self.add_kbevent(KEYDOWN, K_UP, self.scroll_map, vy=-1)
        self.add_kbevent(KEYDOWN, K_DOWN, self.scroll_map, vy=1)
        self.add_kbevent(KEYDOWN, K_LEFT, self.scroll_map, vx=-1)
        self.add_kbevent(KEYDOWN, K_RIGHT, self.scroll_map, vx=1)