예제 #1
0
파일: cutscene.py 프로젝트: bitcraft/mh
    def update(self, time):
        if self.queue_dialog:
            if self.cleared:
                sd.start(self.queue_dialog)
                self.queue_dialog = None
                self.cleared = False

        else:

            try:
                text = self.dialogs.pop()
            except IndexError:
                sd.done()
                return

            if text[:6] == "#image":
                fill = False
                tag, path = text.split(":")

                if path[0] == "+":
                    fill = True
                    path = path[1:]

                if tag[-8:] == "colorkey":
                    image = res.loadImage(path, colorkey=1)
                elif tag[-5:] == "alpha":
                    image = res.loadImage(path, alpha=1)
                else:
                    image = res.loadImage(path)
     
                rect = image.get_rect()
                if fill:
                    size = [ int(i) for i in sd.get_size() ]
                    x = size[0] - rect.w
                    y = size[1] - rect.h
                    r = float(rect.w) / rect.h
                    if x > y:
                        rect = pygame.Rect((0,0,size[0],size[1]*r))
                    else:
                        rect = pygame.Rect((0,0,size[0]*r,size[1]))

                    rect.center = size[0] / 2, size[1] / 2
                    image = pygame.transform.smoothscale(image, rect.size)
                else:
                    rect.topleft = ((sd.get_size()[0]/2)-(rect.width/2), 10)
                
                self.queue_image = (image, rect)
                self.cleared = False

            elif text[:6] == "#music":
                tag, path = text.split(":")
                self.queue_music = path

            else:
                self.queue_dialog = TextDialog(text)
예제 #2
0
파일: titlescreen.py 프로젝트: bitcraft/mh
    def update(self, time):

        for i in self.maps:
            i[0] += i[2]
            i[1] += i[3]
            if i[4] > 0:
                i[4] += 1

        self.last_update += time
        if self.last_update >= self.change_delay:
            self.change_map()
            self.last_update -= self.change_delay

        try:
            image = self.subpixelQueue.get(0)
        except Empty:
            pass

        else:
            if not len(self.maps) == 0:
                self.maps[0][4] = 1  # mark it for fadeout

            w0, h0 = sd.get_size()
            w1, h1 = image.get_size()

            self.maps.insert(0, [-(w1-w0)/2, -(h1-h0)/2,
                             round(uniform(-0.08, 0.08), 3),
                             round(uniform(-0.08, 0.08), 3), 0, image])

            self.subpixelQueue.task_done()

        self.maps = [ i for i in self.maps if i[4] < self.map_fadeout ][:2]
예제 #3
0
파일: titlescreen.py 프로젝트: bitcraft/mh
    def activate(self):
        self.activated = True

        res.fadeoutMusic()

        self.maps = []
        self.change_delay = 8000        # seconds until map moves to next point
        self.map_fadeout = 60.0         # must be a float
        self.last_update = 0
        self.surfaceQueue = queue()
        self.subpixelQueue = queue()

        self.hotspots = cycle(([300,500], [750, 800], [350, 260], [700, 340], [120, 1000], [800, 830], [480, 900]))
        
        self.overworld = res.loadImage("overworld.png")

        self.menu = cMenu(Rect((42,20), sd.get_size()),
            20, 5, 'vertical', 100,
            [('New Game', self.new_game),
            ('Battle Test', self.continue_game),
            ('Introduction', self.show_intro),
            ('Quit Game', self.quit_game)],
            font="northwoodhigh.ttf", font_size=24)

        self.menu.ready()
        self.change_map()
예제 #4
0
파일: battlestate.py 프로젝트: MacLeek/mh
    def __init__(self, party, enemies):
        GameState.__init__(self)

        self.bkg = gfx.load("misc/overpass.png")
        self.bkg = pygame.transform.scale(self.bkg, (sd.get_size()))

        self.actors = []
        self.glitter = []

        hero = lib2d.sheetloader.load_actor("hero", Hero)
        hero.avatar.play("walk")
        hero.face("north")
        self.actors.append(hero)

        m0 = Monster()
        m0.render()

        m0.rect.topleft = (170, 10)   # hack

        party = [hero]
        enemies = [m0]

        self.timer = VisualTimer(0, (10,30,100,16))
        self.player_area = Rect(160, 140, 160, 78)
        self.party = [party, enemies]
        self.member_focus = 0

        self.stale_spells = []

        # kinda a hack until [if] i properly implement a scheduler for
        # concurrent states
        self.states = []
        self.substate = None
예제 #5
0
파일: battlestate.py 프로젝트: MacLeek/mh
    def activate(self):
        import spells

        def name(spell):
            if spell.uses >= 1:
                i = loaded_spells.index(spell)
                return "{0} ({1})".format(
                    spell.name,
                    spell.uses - self.history[(caller, i)])

            else:
                return spell.name

        caller = self.parent.party[0][self.parent.member_focus]

        loaded_spells = spells.load("all")

        self.items = [ (name(s), self.select_spell, s) for s in loaded_spells ]
        self.menu = cMenu(Rect((10,60),sd.get_size()),
            20, 0, 'vertical', 100,
            self.items,
            font="fonts/dpcomic.ttf", font_size=16,
            banner_style="normal")

        self.menu.callback = self.update_spell_card

        for i, spell in enumerate(loaded_spells):
            if spell.uses >= 1:
                if self.history[(caller, i)] >= spell.uses:
                    self.menu.disable(i)

        self.menu.ready(self.last_selection[caller])
        self.update_spell_card(self.menu.selection)
        self.parent.timer.set_alarm(self.select_delay)
예제 #6
0
    def __init__(self, party, enemies):
        GameState.__init__(self)

        self.bkg = gfx.load("misc/overpass.png")
        self.bkg = pygame.transform.scale(self.bkg, (sd.get_size()))

        self.actors = []
        self.glitter = []

        hero = lib2d.sheetloader.load_actor("hero", Hero)
        hero.avatar.play("walk")
        hero.face("north")
        self.actors.append(hero)

        m0 = Monster()
        m0.render()

        m0.rect.topleft = (170, 10)  # hack

        party = [hero]
        enemies = [m0]

        self.timer = VisualTimer(0, (10, 30, 100, 16))
        self.player_area = Rect(160, 140, 160, 78)
        self.party = [party, enemies]
        self.member_focus = 0

        self.stale_spells = []

        # kinda a hack until [if] i properly implement a scheduler for
        # concurrent states
        self.states = []
        self.substate = None
예제 #7
0
파일: overworld.py 프로젝트: MacLeek/mh
    def activate(self):
        GameState.activate(self)

        w, h = sd.get_size()

        self.cr_open = scale(res.loadImage("open.png", 0, 1), (20,30))
        self.cr_grasp = scale(res.loadImage("grasp.png", 0, 1), (20, 25))
        self.cr_arrow = res.loadImage("next_arrow.png", 0, 1)

        self.cr = KeyCursor(self.cr_open)
        self.cr_state = HAND_OPEN

        self.cr_bounds = Rect(0,0,w,h).inflate(-w*.2, -h*.2)
        self.cr_bounds.height -= 30
        self.cr_bounds.width -= 20
        self.cr_pos = list(self.cr_bounds.center)
        self.cr_speed = 0
        self.cr.enable()

        self.map_pos = self.cr_pos[:]

        path = res.mapPath("overworld3.tmx")

        self.tilemap = BufferedTilemapRenderer(path,
                       (w,h), force_colorkey=(128,0,63))

        self.camera = OverworldCamera([], self.tilemap, ((0,0), (w,h)))
        self.camera.center(self.cr_pos)
        self.tilemap.redraw()


        self.cleared = 0
예제 #8
0
    def activate(self):
        GameState.activate(self)

        w, h = sd.get_size()

        self.cr_open = scale(res.loadImage("open.png", 0, 1), (20, 30))
        self.cr_grasp = scale(res.loadImage("grasp.png", 0, 1), (20, 25))
        self.cr_arrow = res.loadImage("next_arrow.png", 0, 1)

        self.cr = KeyCursor(self.cr_open)
        self.cr_state = HAND_OPEN

        self.cr_bounds = Rect(0, 0, w, h).inflate(-w * .2, -h * .2)
        self.cr_bounds.height -= 30
        self.cr_bounds.width -= 20
        self.cr_pos = list(self.cr_bounds.center)
        self.cr_speed = 0
        self.cr.enable()

        self.map_pos = self.cr_pos[:]

        path = res.mapPath("overworld3.tmx")

        self.tilemap = BufferedTilemapRenderer(path, (w, h),
                                               force_colorkey=(128, 0, 63))

        self.camera = OverworldCamera([], self.tilemap, ((0, 0), (w, h)))
        self.camera.center(self.cr_pos)
        self.tilemap.redraw()

        self.cleared = 0
예제 #9
0
파일: titlescreen.py 프로젝트: bitcraft/mh
    def change_map(self):
        pos = list(next(self.hotspots)[:])
        r = Rect((0,0), sd.get_size()).inflate((48, 48))
        r.center = pos
        clip = Surface(r.size)
        clip.blit(self.overworld, (0,0), r)

        self.surfaceQueue.put(clip)
        self.thread = SubPixelThread(self.surfaceQueue, self.subpixelQueue)
        self.thread.start()
예제 #10
0
    def reactivate(self):
        if self.game:
            self.menu = cMenu(((32,20), sd.get_size()),
                20, -5, 'vertical', 100,
                [('New Game', self.new_game),
                ('Continue', self.continue_game),
                #('Save', self.save_game),
                #('Reload', self.load_game),
                #('Save and Quit', self.savequit_game),
                ('Quit', self.quit_game)],
                font="visitor1.ttf", font_size=20)
        else:
            self.menu = cMenu(((32,20), sd.get_size()),
                20, -5, 'vertical', 100,
                [('New Game', self.new_game),
                #('Continue', self.load_game),
                ('Introduction', self.show_intro),
                ('Quit', self.quit_game)],
                font="visitor1.ttf", font_size=20)

        self.menu.ready()
        self.redraw = True
        res.playMusic("oneslymove.ogg")
예제 #11
0
    def activate(self):
        import spells

        def name(spell):
            if spell.uses >= 1:
                i = loaded_spells.index(spell)
                return "{0} ({1})".format(
                    spell.name, spell.uses - self.history[(caller, i)])

            else:
                return spell.name

        caller = self.parent.party[0][self.parent.member_focus]

        loaded_spells = spells.load("all")

        self.items = [(name(s), self.select_spell, s) for s in loaded_spells]
        self.menu = cMenu(Rect((10, 60), sd.get_size()),
                          20,
                          0,
                          'vertical',
                          100,
                          self.items,
                          font="fonts/dpcomic.ttf",
                          font_size=16,
                          banner_style="normal")

        self.menu.callback = self.update_spell_card

        for i, spell in enumerate(loaded_spells):
            if spell.uses >= 1:
                if self.history[(caller, i)] >= spell.uses:
                    self.menu.disable(i)

        self.menu.ready(self.last_selection[caller])
        self.update_spell_card(self.menu.selection)
        self.parent.timer.set_alarm(self.select_delay)
예제 #12
0
파일: worldstate.py 프로젝트: bitcraft/mh
    def activate(self):
        self.walkSound = None
        self.walkSoundDelay = 400
        self.walkSoundPlaying = 0
        self.sounds = {}

        self.msgFont = pygame.font.Font((res.fontPath("volter.ttf")), 9)
        self.border = gui.GraphicBox("dialog2-h.png", hollow=True)
        self.borderFilled = gui.GraphicBox("dialog2.png")
        self.player_vector = Vec2d(0,0)

        # get the root and the hero from it
        root = self.area.getRoot()
        self.hero = root.getChildByGUID(1)
        self.hero.move_speed = 1

        # add the hero to this map if it isn't ready there
        if not self.area.hasChild(self.hero):
            self.area.add(self.hero)

        # load the tmx data here.  it will be shared with the camera.
        self.tmxdata = tmxloader.load_pygame(
                       self.area.mappath, force_colorkey=(128,128,0))

        # attach a camera
        sw, sh = sd.get_size()
        mw = sw * .75
        mh = sh * .75
        self.camera = AreaCamera(self.area,((0,0), (mw, mh)),
                                 tmxdata=self.tmxdata)

        self.mapBorder = pygame.Rect((0,0,mw+6,mh+6))
        self.msgBorder = pygame.Rect((0,mh,sw,sh-mh))
        self.hudBorder = pygame.Rect((mw,0,sw-mw,mh+6))


        # play music if any has been set in tiled
        try:
            res.playMusic(self.tmxdata.music)
        except AttributeError:
            res.fadeoutMusic()
            
        # quadtree for handling collisions with exit tiles
        rects = []
        for guid, param in self.area.exits.items():
            try:
                x, y, l = param[0]
            except:
                continue
            rects.append(ExitTile((x,y,
                self.tmxdata.tilewidth, self.tmxdata.tileheight),
                guid))

        self.exitQT = QuadTree(rects)

        # load tile sounds
        for i, layer in enumerate(self.tmxdata.tilelayers):
            props = self.tmxdata.getTilePropertiesByLayer(i)
            for gid, tileProp in props:
                for key, value in tileProp.items():
                    if key[4:].lower() == "sound":
                        self.sounds[value] = res.loadSound(value)