Exemplo n.º 1
0
 def __init__(self, bgimg):
     BgState.__init__(self, bgimg)
     txt = TextLine("Press any key to start", fontsize=15)
     pos = (utils.center(txt.get_size(),
                         (800, 600))[0], 590 - txt.get_size()[1])
     self.background.blit(txt, pos)
     self.upd = 1
Exemplo n.º 2
0
    def __init__(self, bgimg=None):
        BgState.__init__(self, bgimg)

        pygame.mouse.set_visible(1)

        #background of message
        size = (250, 100)
        msg_bg = StaticWidget(size)
        draw_border(msg_bg)
        pos = utils.center(size, (800, 600))
        msg_bg.set_pos(pos)
        self.msg_bg = msg_bg
        msg_pos = pos

        txt_img = TextLine("Paused", fontsize=30)
        pos = (utils.center(txt_img.get_size(), size))
        msg_bg.blit(txt_img, pos)
        msg_bg.draw(self.background)

        #continue/cancel buttons
        btn = FixedTextButton((100, 24), "Abort Game", callback=self.to_menu)
        btn.set_pos((msg_pos[0], msg_pos[1] + size[1] + 4))
        btn.draw_border()
        self.add_button("cancel", btn)
        btn.draw(self.background)

        btn = FixedTextButton((100, 24), "Continue", callback=self.quit)
        btn.set_pos((msg_pos[0] + size[0] - 100, msg_pos[1] + size[1] + 4))
        btn.draw_border()
        self.add_button("start", btn)
        btn.draw(self.background)

        self.upd = 1
Exemplo n.º 3
0
    def __init__(self, img=None, lost=False):
        img = pygame.Surface((800, 600))
        BgState.__init__(self, img)
        self.game_bg = img.copy()
        pygame.mouse.set_visible(1)

        #background of message
        size = (300, 300)
        msg_bg = StaticWidget(size)
        #draw_border(msg_bg)
        pos = utils.center(size, (800, 600))
        msg_bg.set_pos(pos)
        self.msg_bg = msg_bg
        msg_pos = pos

        #message
        img = GFX["win"]
        if lost:
            img = GFX["lose"]
        pos = (utils.center(img.get_size(), size)[0], 1)
        msg_bg.blit(img, pos)

        score = SAVE["cur"]["score"] + 100 * SAVE["cur"]["lives"]
        txt = "Score: " + str(score)
        txt_img = TextLine(txt, fontsize=20)
        pos = (utils.center(txt_img.get_size(), size)[0], size[1] - 60)
        msg_bg.blit(txt_img, pos)

        scr_list = ScoreList()
        scr_list.max = 10
        scr_list.set_list(SAVE["overhigh"])

        #add highscore entry
        if scr_list.check(score):
            txt = "New Highscore!"
            txt_img = TextLine(txt, fontsize=20)
            pos = (utils.center(txt_img.get_size(), size)[0], size[1] - 30)
            msg_bg.blit(txt_img, pos)

            scr_list.max = 10
            scr_list.add(SAVE["cur"]["name"], score, SAVE["cur"]["lives"])
            SAVE["overhigh"] = scr_list.get_list()
            save_data()

        btn = FixedTextButton((120, 25), "Exit", callback=self.quit)
        btn.draw_border()
        btn.set_pos((msg_pos[0], msg_pos[1] + size[1] + 4))
        self.add_button("continue", btn)

        btn = FixedTextButton((120, 25),
                              "Highscore",
                              callback=self.to_highscore)
        btn.draw_border()
        btn.set_pos((msg_pos[0] + size[0] - 120, msg_pos[1] + size[1] + 4))
        self.add_button("highscore", btn)

        SAVE["cur"] = {}  #delete savegame
        save_data()

        self.redraw()
Exemplo n.º 4
0
    def __init__(self, bgimg=None):
        BgState.__init__(self, bgimg)

        #background of message
        size = (300, 200)
        msg_bg = StaticWidget(size)
        #msg_bg.fill((0,0,128))
        draw_border(msg_bg)
        pos = utils.center(size, (800, 600))
        msg_bg.set_pos(pos)
        self.msg_bg = msg_bg
        msg_pos = pos

        txt = "New game"
        txt_img = TextLine(txt, fontsize=30)
        pos = (utils.center(txt_img.get_size(), size)[0], 10)
        msg_bg.blit(txt_img, pos)

        #message
        txt = "Enter name:"
        txt_img = TextLine(txt, fontsize=15)
        pos = (10, 80)
        msg_bg.blit(txt_img, pos)

        self.entry = TextEntry(size=(130, 22))
        self.entry.max = 10
        self.entry.set_pos(
            (msg_pos[0] + txt_img.get_size()[0] + 20, msg_pos[1] + 75))

        txt = "Note: Any previous savegame will be "
        txt_img = TextLine(txt, fontsize=12)
        pos = (10, 150)
        msg_bg.blit(txt_img, pos)

        txt = "overwritten!"
        txt_img = TextLine(txt, fontsize=12)
        pos = (10, pos[1] + 18)
        msg_bg.blit(txt_img, pos)

        #start/cancel buttons
        btn = FixedTextButton((100, 24), "Cancel", callback=self.quit)
        btn.set_pos((msg_pos[0], msg_pos[1] + size[1] + 2))
        btn.draw_border()
        self.add_button("cancel", btn)

        btn = FixedTextButton((100, 24), "Start!", callback=self.submit)
        btn.set_pos((msg_pos[0] + size[0] - 100, msg_pos[1] + size[1] + 2))
        btn.draw_border()
        self.add_button("start", btn)

        self.add_textentry_events(self.entry)
        self.add_kbevent(KEYDOWN, K_ESCAPE, self.quit)

        self.redraw()
Exemplo n.º 5
0
    def __init__(self):
        img = GFX["help"]
        BgState.__init__(self, img)

        img1 = GFX["btn_back1"]
        img2 = GFX["btn_back2"]
        img3 = GFX["btn_back3"]
        anim = [img1, img2, img1, img3]
        btn = SuperFlipButton(img1, anim, callback=self.quit)
        btn.set_pos((315, 519))
        self.add_button("back", btn)
Exemplo n.º 6
0
    def __init__(self):
        def add_btn(pos, name, callback, **kwargs):
            img1 = GFX[name + "1"]
            img2 = GFX[name + "2"]
            img3 = GFX[name + "3"]
            anim = [img1, img2, img1, img3]
            btn = SuperFlipButton(img1, anim, callback, **kwargs)
            btn.set_pos(pos)
            self.add_button(name, btn)

        img = GFX["main"]
        BgState.__init__(self, img)
        pygame.mouse.set_visible(1)

        #add buttons
        pos = (29, 132)
        add_btn(pos,
                "btn_start",
                self.start,
                state=StartCampaign,
                bgimg=self.background)
        pos = (29, 286)
        add_btn(pos, "btn_resume", self.resume)
        pos = (29, 437)
        add_btn(pos, "btn_freeplay", self.start, state=LoadMenu, edit=False)
        pos = (315, 78)
        add_btn(pos,
                "btn_highscore",
                self.start,
                state=Highscore,
                bgimg=self.background)
        pos = (315, 519)
        add_btn(pos, "btn_exit", self.quit)
        pos = (599, 286)
        add_btn(pos, "btn_editor", self.start, state=Editor)
        pos = (599, 437)
        add_btn(pos, "btn_help", self.start, state=Help)
        pos = (537, 113)
        add_btn(pos, "btn_credits", self.start, state=Credits)

        self.eyes = {
            "btn_highscore": GFX["eyes_u"],
            "btn_credits": GFX["eyes_ur"],
            "btn_editor": GFX["eyes_r"],
            "btn_help": GFX["eyes_dr"],
            "btn_exit": GFX["eyes_d"],
            "btn_freeplay": GFX["eyes_dl"],
            "btn_resume": GFX["eyes_l"],
            "btn_start": GFX["eyes_ul"],
        }
        self.redraw()

        self.add_kbevent(KEYDOWN, K_ESCAPE, self.quit)
Exemplo n.º 7
0
    def __init__(self, img, map, mapname="", folder="custom"):
        BgState.__init__(self, img)
        self.map = map
        self.folder = folder
        pygame.mouse.set_visible(1)

        #background image + "save as"
        self.menu = StaticWidget((250, 100))
        self.menu.fill((0, 0, 0))
        txt = TextLine("Save as:", fontsize=15)
        self.menu.blit(txt, (10, 10))
        w, h = self.menu.get_size()
        pygame.draw.lines(self.menu, (0, 0, 255), True,
                          ((0, 0), (w - 4, 0), (w - 4, h - 4), (0, h - 4)), 4)
        x, y = utils.center((w, h), (800, 600))
        self.menu.set_pos((x, y))

        #text entry + ".map"
        self.entry = TextEntry(text=mapname[:-4])
        self.entry.set_pos((x + 10, y + 30))
        txt = TextLine(".map", fontsize=20)
        self.menu.blit(txt, (self.entry.get_size()[0] + 15, 30))

        #save/cancel buttons
        msg_pos = self.menu.get_pos()
        size = self.menu.get_size()
        btn = FixedTextButton((100, 24), "Cancel", callback=self.quit)
        btn.set_pos((msg_pos[0], msg_pos[1] + size[1] + 4))
        btn.draw_border()
        self.add_button("cancel", btn)
        btn.draw(self.background)

        btn = FixedTextButton((100, 24), "Save", callback=self.submit)
        btn.set_pos((msg_pos[0] + size[0] - 100, msg_pos[1] + size[1] + 4))
        btn.draw_border()
        self.add_button("save", btn)
        btn.draw(self.background)

        self.redraw()

        self.quit_timer = utils.Timer(20)
        self.quit_timer.deactivate()

        self.add_kbevent(KEYDOWN, K_ESCAPE, callback=self.quit)
        self.add_textentry_events(self.entry)
Exemplo n.º 8
0
    def __init__(self, bgimg=None):
        BgState.__init__(self, bgimg)

        bgsize = (300, 400)
        bgimg = pygame.Surface(bgsize)
        draw_border(bgimg, width=4)
        self.background.blit(bgimg, (250, 100))

        txt = TextLine("Highscore", fontsize=30)
        pos = (utils.center(txt.get_size(), (800, 600))[0], 120)
        self.background.blit(txt, pos)

        x, y = 275, pos[1] + txt.get_size()[1] + 40
        tmp = SAVE["overhigh"][:]
        tmp.reverse()
        for i in tmp:
            name, score, lives = i
            self.background.blit(TextLine(name), (x, y))
            self.background.blit(TextLine(str(score)), (x + 150, y))
            self.background.blit(TextLine(str(lives)), (x + 240, y))
            y += 25

        img = pygame.transform.scale(GFX["ghost"], (19, 19))
        icon_pos = (x + 235, pos[1] + 55)
        self.background.blit(img, icon_pos)
        img = pygame.transform.scale(GFX["catnip"], (19, 19))
        icon_pos = (x + 168, pos[1] + 55)
        self.background.blit(img, icon_pos)

        btn = FixedTextButton((200, 25), "Back to Menu", callback=self.quit)
        btn.draw_border()
        x = utils.center(btn.get_size(), (800, 600))[0]
        btn.set_pos((x, 510))
        btn.draw(self.background)
        self.add_button("back", btn)

        self.add_kbevent(KEYDOWN, K_ESCAPE, self.quit)
        self.upd = 1
Exemplo n.º 9
0
    def __init__(self, bgimg=None, mapname="", folder="", pacmode=False):
        BgState.__init__(self, bgimg)
        pygame.mouse.set_visible(1)

        self.pacmode = pacmode
        self.mapname = mapname
        self.folder = folder

        #background of message
        size = (250, 100)
        msg_bg = StaticWidget(size)
        draw_border(msg_bg)
        pos = utils.center(size, (800, 600))
        msg_bg.set_pos(pos)
        self.msg_bg = msg_bg
        msg_pos = pos

        txt_img = TextLine("You lose.", fontsize=30)
        pos = (utils.center(txt_img.get_size(), size))
        msg_bg.blit(txt_img, pos)
        msg_bg.draw(self.background)

        #continue/cancel buttons
        btn = FixedTextButton((100, 24), "Abort Game", callback=self.quit)
        btn.set_pos((msg_pos[0], msg_pos[1] + size[1] + 4))
        btn.draw_border()
        self.add_button("cancel", btn)
        btn.draw(self.background)

        btn = FixedTextButton((100, 24), "Try Again", callback=self.tryagain)
        btn.set_pos((msg_pos[0] + size[0] - 100, msg_pos[1] + size[1] + 4))
        btn.draw_border()
        self.add_button("start", btn)
        btn.draw(self.background)

        self.add_kbevent(KEYDOWN, K_ESCAPE, self.quit)
        self.upd = 1
Exemplo n.º 10
0
 def main_start(self):
     BgState.main_start(self)
     pygame.mouse.set_visible(1)
Exemplo n.º 11
0
    def __init__(self,
                 img,
                 mapname,
                 score,
                 custom=False,
                 name="",
                 pacmode=False,
                 win=True):
        BgState.__init__(self, img)
        score_str = str(score)

        #background of message
        size = (300, 200)
        msg_bg = StaticWidget(size)
        #msg_bg.fill((0,0,128))
        draw_border(msg_bg)
        pos = utils.center(size, (800, 600))
        msg_bg.set_pos(pos)
        self.msg_bg = msg_bg
        msg_pos = pos

        #message
        if win:
            txt = "Map completed!"
        else:
            txt = "You were caught!"
        txt_img = TextLine(txt, fontsize=30)
        pos = (utils.center(txt_img.get_size(), size)[0], 10)
        msg_bg.blit(txt_img, pos)

        txt = "Score: " + score_str
        txt_img = TextLine(txt, fontsize=20)
        pos = (utils.center(txt_img.get_size(), size)[0], 60)
        msg_bg.blit(txt_img, pos)

        #check if highscore
        type = "camphigh"
        if custom:
            type = "custhigh"

        if pacmode:
            type = "pachighca"
            if custom:
                type = "pachighcu"

        scr_list = []
        if SAVE[type].has_key(mapname):
            scr_list = SAVE[type][mapname]
        else:
            SAVE[type][mapname] = []

        self.type = type
        self.mapname = mapname
        self.score = score
        self.scr_list = ScoreList()
        self.scr_list.set_list(scr_list)

        self.entry = None
        #add highscore entry
        if self.scr_list.check(score):
            txt = "New Highscore!"
            txt_img = TextLine(txt, fontsize=20)
            pos = (utils.center(txt_img.get_size(), size)[0], 120)
            msg_bg.blit(txt_img, pos)

            txt = "Enter name:"
            txt_img = TextLine(txt, fontsize=20)
            pos = (10, 150)
            msg_bg.blit(txt_img, pos)

            self.entry = TextEntry(text=name, size=(130, 22))
            self.entry.max = 10
            self.entry.set_pos(
                (msg_pos[0] + txt_img.get_size()[0] + 20, msg_pos[1] + 150))

            self.add_textentry_events(self.entry)
        btn = FixedTextButton((120, 25), "Continue", callback=self.submit)
        btn.draw_border()
        btn.set_pos((msg_pos[0] + size[0] - 120, msg_pos[1] + size[1] + 4))
        self.add_button("continue", btn)
        self.add_kbevent(KEYDOWN, K_RETURN, self.quit)
        self.redraw()

        #keys
        self.add_kbevent(KEYDOWN, K_ESCAPE, self.quit)
Exemplo n.º 12
0
 def unpause(self):
     BgState.unpause(self)
     self.select(self.selected)
Exemplo n.º 13
0
    def __init__(self, edit=True, folder="custom"):
        img = GFX["levelsel"]
        BgState.__init__(self, img)
        pygame.mouse.set_visible(1)
        self.preview = pygame.Surface((416, 320))
        self.preview_pos = (312, 105)
        self.edit = edit
        self.folder = folder
        self.stats = {
            "cats": 0,
            "dogs": 0,
            "catnip": 0,
            "cataway": 0,
            "highscore": []
        }
        self.scores = []

        #list of map filenames
        self.msg = TextLine("")
        self.maps = get_maps(self.folder)

        #buttons
        btn = ClickFlipButton(GFX["btn_up1"],
                              GFX["btn_up2"],
                              callback=self.set_page,
                              add=-1)
        btn.set_pos((56, 233))
        self.add_button("up", btn)

        btn = ClickFlipButton(GFX["btn_down1"],
                              GFX["btn_down2"],
                              callback=self.set_page,
                              add=1)
        btn.set_pos((56, 265))
        self.add_button("down", btn)

        btn = FixedTextButton((64, 32), "Cancel", callback=self.quit)
        btn.set_pos((120, 457))
        btn.draw_border()
        self.add_button("cancel", btn)

        btn = FixedTextButton((64, 32), "Load", callback=self.load)
        btn.set_pos((216, 457))
        btn.draw_border()
        self.add_button("load", btn)

        if not edit:  #hide campaign maps in editor
            btn = ImgButton(GFX["sel_camp1"].copy(),
                            callback=self.set_folder,
                            val="lvl")
            btn.set_pos((117, 41))
            self.add_button("lvl", btn)

        btn = ImgButton(GFX["sel_cus1"].copy(),
                        callback=self.set_folder,
                        val="custom")
        btn.set_pos((212, 41))
        self.add_button("custom", btn)

        #pacmode unlocked when campaign done
        if SAVE["unlock"] >= 14:
            btn = ImgButton(GFX["mode_cat"], callback=self.set_pacmode)
            btn.set_pos((674, 55))
            self.add_button("pacmode", btn)
        self.pacmode = False

        #stats/score area
        stats = StaticWidget((160, 96))
        stats.blit(GFX["ghost"], (3, 0))
        stats.blit(GFX["pacdog-img"], (3, 32))
        stats.blit(GFX["catnip"], (3, 64))
        stats.blit(GFX["cataway"], (96, 0))
        self.stat_bg = stats

        score_bg = StaticWidget((160, 96))
        self.score_bg = score_bg

        self.stat_flip = FlipImg([stats.copy(), score_bg.copy()])
        self.stat_flip.set_pos((472, 457))

        #filename buttons
        size = (160, 30)
        file_pos = (120, 106)
        x = file_pos[0]
        y = file_pos[1]
        for i in xrange(10):
            name = ""
            if i < len(self.maps):
                name = self.maps[i]
            btn = FixedTextButton(size, name, callback=self.select, nr=i)
            btn.set_pos((x, y))
            self.add_button(i, btn)
            y = y + size[1] + 2

        self.page = 0
        self.selected = 0
        self.max_page = 0
        self.set_folder(self.folder)
        self.select(0)

        self.add_kbevent(KEYDOWN, K_ESCAPE, self.quit)
Exemplo n.º 14
0
 def unpause(self):
     BgState.unpause(self)
     x, y = pygame.mouse.get_pos()
     pygame.mouse.set_pos((x + 1, y))