示例#1
0
def intro():
    ikalogo = ika.Image('%s/ika.png' % config.IMAGE_PATH)
    gbabg = ika.Image('%s/sky_bg.png' % config.IMAGE_PATH)
    gba = ika.Image('%s/gba.png' % config.IMAGE_PATH)
    yourmom = ika.Image('%s/yourmother.png' % config.IMAGE_PATH)
    isabitch = ika.Image('%s/yourmother2.png' % config.IMAGE_PATH)
    controls.attack1()  # unpress
    controls.joy_attack1()  # unpress
    controls.ui_accept()  # unpress
    v = ika.Video
    d = 40

    def stub():
        clearScreen()

    def showGba():
        gbabg.Blit(0, 0)
        v.Blit(gba, (v.xres - gba.width) / 2, (v.yres - gba.height) / 2)
        clouds.update()
        clouds.draw()

    try:
        delay(stub, 10)
        delay(showGba, 440)
        delay(lambda: v.Blit(ikalogo, 0, 0, ika.Opaque), 440)
        delay(lambda: v.Blit(yourmom, 0, 0, ika.Opaque), 450)
        delay(lambda: v.Blit(isabitch, 0, 0, ika.Opaque), 1)
    except _DoneException:
        return
示例#2
0
def animate(ent, frames, delay, thing=None, loop=True, text=None):
    class AnimException(Exception):
        pass

    # frames should be a list of (frame, delay) pairs.
    if thing is not None:
        crap.append(thing)
    if text is not None:
        text = textBox(ent, text)
        crap.append(text)
    try:
        while True:
            for frame in frames:
                ent.specframe = frame
                d = delay
                while d > 0:
                    d -= 1
                    draw()
                    ika.Video.ShowPage()
                    ika.Delay(1)
                    ika.Input.Update()
                    if controls.attack() or controls.ui_accept(
                    ) or controls.joy_attack():
                        loop = False
                        raise AnimException
            if not loop:
                raise AnimException
    except:  #except what?
        if thing:
            crap.remove(thing)
        if text:
            crap.remove(text)
        ent.specframe = 0
示例#3
0
def text(where, *args):
    """Displays a text frame.

    Where can be either a point or an entity.
    TODO: update Things while the textbox is visible
    """
    portrait, text, side = None, '', ''

    if len(args) == 1:
        text = args[0]
    elif len(args) == 2:
        portrait, text = args
    elif len(args) == 3:
        portrait, side, text = args
    else:
        assert False, 'text recieves 1 or two arguments.'

    textBox = TextBox(where, portrait, side, text)

    engine.things.append(textBox)

    try:
        engine.beginCutScene()
        while not (controls.attack1() or controls.joy_attack1()
                   or controls.ui_accept()):
            engine.tick()
            engine.draw()

    finally:
        engine.endCutScene()
        engine.things.remove(textBox)
示例#4
0
    def gameOver(self):
        c = Caption('G A M E   O V E R',
                    duration=1000000,
                    y=(ika.Video.yres - self.font.height) / 2)
        t = 80
        i = 0
        self.fields = []
        while True:
            i = min(i + 1, t)
            c.update()
            self.tick()
            self.draw()

            # darken the screen, draw the game over message:
            o = i * 255 / t
            ika.Video.DrawRect(0, 0, ika.Video.xres, ika.Video.yres,
                               ika.RGB(0, 0, 0, o), True)
            c.draw()

            ika.Video.ShowPage()
            ika.Delay(4)

            if i == t and (controls.attack() or controls.joy_attack()
                           or controls.ui_accept() or controls.ui_cancel()
                           or controls.cancel() or controls.joy_cancel()):
                break
示例#5
0
    def update(self):
        '''Performs one tick of menu input.
           This includes scrolling things around, and updating the
           position of the cursor, based on user interaction.

           If the user has selected an option, then the return value is
           the index of that option.  If the user hit the cancel (ESC)
           key, the Cancel object is returned.  Else, None is returned,
           to signify that nothing has happened yet.
        '''
        ika.Input.Update()
        cy = self.cursorY
        unpress = False  # lame unpress faking
        # TODO: handle it the manly way, by making the cursor repeat after a moment
        # update the cursor
        ymax = max(0, len(self.Text) * self.Font.height - self.textCtrl.Height)
        assert (0 <= self.cursorPos <= len(self.Text),
                'cursorPos out of range 0 <= %i <= %i' %
                (self.cursorPos, len(self.Text)))
        delta = self.cursorPos * self.Font.height - self.textCtrl.YWin - cy
        if delta > 0:
            if cy < self.textCtrl.Height - self.Font.height:
                self.cursorY += self.cursorSpeed
            else:
                self.textCtrl.YWin += self.cursorSpeed
        elif delta < 0:
            if cy > 0:
                self.cursorY -= self.cursorSpeed
            elif self.textCtrl.YWin > 0:
                self.textCtrl.YWin -= self.cursorSpeed
        else:
            # Maybe this isn't a good idea.  Maybe it is.
            # only move the cursor if delta is zero
            # that way movement doesn't get bogged
            # down by a cursor that moves too slowly
            if (controls.up.pressed or controls.ui_up.pressed
                    or controls.joy_up.pressed) and self.cursorPos > 0:
                if not unpress:
                    self.cursorPos -= 1
                    sound.menuMove.Play()
                    unpress = True
            elif (controls.down.pressed or controls.ui_down.pressed
                  or controls.joy_down.pressed
                  ) and self.cursorPos < len(self.Text) - 1:
                if not unpress:
                    self.cursorPos += 1
                    sound.menuMove.Play()
                    unpress = True
            elif (controls.attack1() or controls.joy_attack1()
                  or controls.ui_accept()):
                sound.menuSelect.Play()
                return self.cursorPos
            elif (controls.cancel() or controls.joy_cancel()
                  or controls.ui_cancel()):
                return Cancel
            else:
                unpress = False
示例#6
0
def text(where, txt):
    """Displays a text frame.

    Where can be either a point or an ika entity.
    """
    frame = textBox(where, txt)

    while not (controls.attack() or controls.joy_attack()
               or controls.ui_accept()):
        draw()
        frame.draw()
        ika.Video.ShowPage()
        ika.Input.Update()
示例#7
0
def delay(draw, count, snow):
    while count > 0:
        draw()
        snow.update()
        snow.draw()
        ika.Delay(1)
        count -= 1
        ika.Video.ShowPage()

        ika.Input.Update()
        if controls.attack() or controls.ui_accept(
        ) or controls.cancel() or controls.ui_cancel() or controls.joy_cancel(
        ) or controls.joy_attack():
            raise _DoneException()
示例#8
0
def delay(draw, count):
    scr = effects.grabScreen()
    draw()
    effects.crossFade(30, scr)

    while count > 0:
        draw()
        ika.Delay(1)
        count -= 1
        ika.Video.ShowPage()
        ika.Input.Update()
        if controls.attack1() or controls.joy_attack1() or controls.ui_accept(
        ):
            raise _DoneException()

    draw()
示例#9
0
 def update(self):
     assert (len(self.layout.children),
             'There should be at least one frame in here. (Either '
             'indicating no saves, or to create a new save.)')
     ika.Input.Update()
     if self.curY < self.oldY:
         self.oldY -= 2
     elif self.curY > self.oldY:
         self.oldY += 2
     elif (controls.up.pressed or controls.ui_up.pressed or controls.joy_up.pressed) and self.cursorPos > 0:
        sound.menuMove.Play()
        self.cursorPos -= 1
        self.curY = self.cursorPos * self.wndHeight
     elif (controls.down.pressed or controls.ui_down.pressed or controls.joy_down.pressed) and \
          self.cursorPos < len(self.layout.children) - 1:
        sound.menuMove.Play()
        self.cursorPos += 1
        self.curY = self.cursorPos * self.wndHeight
     elif (controls.attack1() or controls.joy_attack1() or controls.ui_accept()):
         sound.menuSelect.Play()
         return self.cursorPos
     elif (controls.cancel() or controls.joy_cancel() or controls.ui_cancel()):
         return Cancel
示例#10
0
    def update(self):
        assert len(self.layout.children), 'There should be at least one frame in here. (either indicating no saves, or to create a new save.'
        ika.Input.Update()

        if self.curY < self.oldY:
            self.oldY -= 2
        elif self.curY > self.oldY:
            self.oldY += 2
        else:
            if (controls.up() or controls.ui_up() or controls.joy_up()) and self.cursorPos > 0:
                self.cursorPos -= 1
                self.curY = self.cursorPos * self.wndHeight
            elif (controls.down() or controls.ui_down() or controls.joy_down()) and self.cursorPos < len(self.layout.children) - 1:
                self.cursorPos += 1
                self.curY = self.cursorPos * self.wndHeight
            elif controls.attack() or controls.ui_accept() or controls.joy_attack():
                if self.saving and self.cursorPos == len(self.layout.children) -1: #create new
                    return New
                else: 
                    return self.cursorPos
            elif controls.cancel() or controls.ui_cancel() or controls.joy_cancel():
                return Cancel

            return None
示例#11
0
def menu():
    bg = ika.Image('gfx/title.png')
    cursor = ika.Image('gfx/ui/pointer.png')
    snow = Snow(velocity=(0, 0.5))
    snow.update()
    result = None
    cursorPos = 0
    FADE_TIME = 60

    font = ika.Font('system.fnt')

    def draw():
        ika.Video.Blit(bg, 0, 0, ika.Opaque)
        ika.Video.Blit(cursor, 68, 128 + cursorPos * 26)
        txt = '(c) 2003, 2021'
        length = font.StringWidth(txt)
        font.Print(ika.Video.xres - length - 10, ika.Video.yres - 10, txt)
        txt = 'Version 1.02'
        length = font.StringWidth(txt)
        font.Print(ika.Video.xres - length - 10, ika.Video.yres - 20, txt)
        if controls.useGamePad:
            font.Print(10, ika.Video.yres - 10, 'Gamepad controls enabled.')

    for i in range(FADE_TIME - 1, -1, -1):
        draw()
        ika.Video.DrawRect(0, 0, ika.Video.xres, ika.Video.yres,
                           ika.RGB(0, 0, 0, i * 255 / FADE_TIME), True)
        snow.update()
        snow.draw()
        ika.Video.ShowPage()
        ika.Input.Update()
        ika.Delay(1)

    u = 0  # gay unpress hack

    while result == None:
        draw()
        snow.update()
        snow.draw()
        ika.Video.ShowPage()
        ika.Input.Update()
        ika.Delay(1)

        if (controls.up() or controls.ui_up()
                or controls.joy_up()) and cursorPos > 0:
            if not u:
                cursorPos -= 1
                u = 1
        elif (controls.down() or controls.ui_down()
              or controls.joy_down()) and cursorPos < 2:
            if not u:
                cursorPos += 1
                u = 1
        elif controls.attack() or controls.ui_accept() or controls.joy_attack(
        ):
            result = cursorPos
        else:
            u = 0

    # one last draw.  Later on, there's a blurfade that can take advantage of this:
    draw()
    snow.draw()
    return result

    for i in range(FADE_TIME):
        draw()
        ika.Video.DrawRect(0, 0, ika.Video.xres, ika.Video.yres,
                           ika.RGB(0, 0, 0, i * 255 / FADE_TIME), True)
        snow.update()
        snow.draw()
        ika.Video.ShowPage()
        ika.Input.Update()
        ika.Delay(1)
示例#12
0
def menu():
    clouds.speed = (1.0, .75)
    bg = ika.Image('%s/title_bg.png' % config.IMAGE_PATH)
    logo = ika.Image('%s/title_logo.png' % config.IMAGE_PATH)
    cursor = ika.Image('%s/ui/pointer.png' % config.IMAGE_PATH)
    result = None
    cursorPos = 0
    menuTop = 175
    menuLeft = 120
    secrat = 0
    menuItems = ("New Game", "Load Game", "Quit Game")
    wnd = subscreen.Window('gfx/ui/win_%s.png')
    FADE_TIME = 60
    opacity = 0
    opacity2 = 0
    opacity3 = 0

    def draw():
        ika.Video.Blit(bg, 0, 0, ika.Opaque)
        clouds.update()
        clouds.draw()
        font.Print(2, 2, "v.1/05")

        ika.Video.TintBlit(logo, 0, 0, ika.RGB(255, 255, 255, opacity))

        wnd.draw(menuLeft - 5, menuTop - 5, ika.Video.xres - (menuLeft * 2),
                 (len(menuItems) * font.height) + 10,
                 ika.RGB(255, 255, 255, opacity3))
        y = 0
        for i in menuItems:
            font.Print(menuLeft, menuTop + y,
                       '#[%02XFFFFFF]%s' % (opacity2, i))
            y += font.height
        ika.Video.TintBlit(cursor, menuLeft - cursor.width - 2,
                           menuTop + cursorPos * font.height + 2,
                           ika.RGB(255, 255, 255, opacity2))

    for i in range(FADE_TIME - 1, -1, -1):
        draw()
        ika.Video.DrawRect(0, 0, ika.Video.xres, ika.Video.yres,
                           ika.RGB(255, 255, 255, i * 255 / FADE_TIME), True)
        ika.Video.ShowPage()
        ika.Input.Update()
        ika.Delay(1)

    u = 0  # unpress hack
    while result == None:
        opacity = min(255, opacity + 2)
        opacity2 = min(255, opacity2 + (opacity >= 128) * 2)
        opacity3 = min(255, opacity2 * 3)
        draw()
        ika.Video.ShowPage()
        ika.Input.Update()
        ika.Delay(1)
        if opacity2 == 255:
            if controls.up.pressed or controls.ui_up.pressed or controls.joy_up.pressed:
                sound.menuMove.Play()
                if cursorPos > 0:
                    cursorPos -= 1
                else:
                    secrat += 1
                    if (secrat == 6):
                        menuItems = ("New Game", "Load Game", "Quit Game",
                                     "New Game +")
                        cursorPos = 3

            elif (controls.down.pressed or controls.ui_down.pressed
                  or controls.joy_down.pressed
                  ) and cursorPos < (len(menuItems) - 1):
                sound.menuMove.Play()
                cursorPos += 1
            elif controls.attack1() or controls.joy_attack1(
            ) or controls.ui_accept():
                result = cursorPos

    if result in (0, 3):
        sound.newGame.Play()
    else:
        sound.menuSelect.Play()
    return result
示例#13
0
    def update(self):
        '''
        Performs one tick of menu input.  This includes scrolling things around,
        and updating the position of the cursor based on user interaction.

        If the user has selected an option, then the return value is the index
        of that option.  If the user hit the cancel (ESC) key, Cancel is
        returned.  Else, None is returned, to signify that nothing has happened
        yet.
        '''
        ika.Input.Update()
        cy = self.cursorY

        # update the cursor
        ymax = max(0, len(self.text) * self.font.height - self._textCtrl.height)


        # Goofy, but kinda cool.
        # We figure out where the cursor should be given its logical position.
        # (ie the item it's supposed to point at)  If it's different from its
        # actual position, we move it.  This way, we get nice smooth cursor
        # movement.

        delta = self.cursorPos * self.font.height - self._textCtrl.ywin - cy
        if delta > 0:
            if cy < self._textCtrl.height - self.font.height:
                self._cursorY += self._cursorSpeed
            else:
                self._textCtrl.ywin += min(delta, self._cursorSpeed)
        elif delta < 0:
            if cy > 0:
                self._cursorY -= self._cursorSpeed
            elif self._textCtrl.ywin > 0:
                self._textCtrl.ywin -= min(-delta, self._cursorSpeed)
        else:

            # Only move the cursor if delta is zero.  That way movement doesn't
            # get bogged down by a cursor that moves too slowly.
            #
            # The cursor delaying stuff mucks this up considerably.  Basically, there's
            # a counter variable (_cursorCount) that is reset when no key is pressed.
            # When a key is pressed, the cursor is moved iff the count is maxed, or at 0.
            # when the counter goes below 0, it is set to the repeat count.
            if (controls.up() or controls.joy_up() or controls.ui_up()) and self.cursorPos > 0:
                if self._cursorCount == 0 or self._cursorCount == self._pauseDelay:
                    self.cursorPos -= 1
                    sound.cursormove.Play()

                self._cursorCount -= 1

                if self._cursorCount < 0:
                    self._cursorCount = self._repeatDelay

            elif (controls.down() or controls.joy_down() or controls.ui_down()) and self.cursorPos < len(self.text) - 1:
                if self._cursorCount == 0 or self._cursorCount == self._pauseDelay:
                    self.cursorPos += 1
                    sound.cursormove.Play()

                self._cursorCount -= 1

                if self._cursorCount < 0:
                    self._cursorCount = self._repeatDelay

            elif controls.enter() or controls.joy_enter() or controls.ui_accept():
                return self.cursorPos
            elif controls.cancel() or controls.joy_cancel() or controls.ui_cancel():
                return Cancel
            else:
                self._cursorCount = self._pauseDelay

            # execution reaches this point if enter or cancel is not pressed
            return None