Esempio n. 1
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
Esempio n. 2
0
    def run(self):
        try:
            skipCount = 0
            controls.UnpressAllKeys()
            self.nextFrameTime = ika.GetTime() + self.ticksPerFrame
            while True:
                t = ika.GetTime()

                # if we're ahead, delay
                if t < self.nextFrameTime:
                    ika.Delay(int(self.nextFrameTime - t))

                automap.map.update()

                if controls.cancel() or controls.ui_cancel(
                ) or controls.joy_cancel():
                    self.pause()

                #if controls.savestate():
                #    self.SaveState()

                #if ika.Input.keyboard['F1'].Pressed():
                #    automap.map.debugrooms()

                #if controls.loadstate():
                #    self.LoadState()

                if controls.showmap() or controls.joy_showmap():
                    self.ShowMap()

                #if controls.speedhack():
                #    if self.framerate == 100:
                #        self.SetFrameRate(200)
                #    else:
                #        self.SetFrameRate(100)

                # Do some thinking
                self.tick()

                # if we're behind, and can, skip the frame.  else draw
                if t > self.nextFrameTime and skipCount < MAX_SKIP_COUNT:
                    skipCount += 1
                else:
                    skipCount = 0
                    self.draw()
                    ika.Video.ShowPage()
                    ika.Input.Update()

                self.nextFrameTime += self.ticksPerFrame

        except GameOverException:
            self.gameOver()
            self.killList = self.entities[:]
            self.clearKillQueue()

        except LoadStateException, l:
            self.killList = self.entities[:]
            self.clearKillQueue()
            saveload.quicksave = l.s  #assign quicksave to be loaded, to be interpreted back in system.py
Esempio n. 3
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
Esempio n. 4
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()
Esempio n. 5
0
def run():
    global killList
    try:
        while True:
            tick()
            if controls.cancel() or controls.ui_cancel():
                pause()
            draw()

    except GameOverException:
        gameOver()
        killList = entities[:]
        clearKillQueue()
    except EndGameException:
        killList = entities[:]
        clearKillQueue()
Esempio n. 6
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
Esempio n. 7
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
Esempio n. 8
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() 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() 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():
                return self.cursorPos
            elif controls.cancel():
                return Cancel
            else:
                self._cursorCount = self._pauseDelay

            # execution reaches this point if enter or cancel is not pressed
            return None
Esempio n. 9
0
    def run(self):
        self.show()
        selectmode = 0  #nothing selected
        done = False
        selected = -1

        ika.Input.Unpress()

        while not done:
            self.draw(selected)
            ika.Video.ShowPage()
            ika.Input.Update()

            if selectmode == 0:  #selecting which control to map
                if controls.cancel() or controls.ui_cancel():
                    done = True

                result = self.control_menu.update()

                if isinstance(result, int):
                    if result >= 0 and result <= self.control_menu.lastcontrol:
                        selectmode = 1  #now poll for input!
                        selected = result  #-3 because top options
                        controls.UnpressAllKeys()
                        self.text = 'Press Escape to Cancel, Backspace to clear.'
                    elif result == self.control_menu.default:
                        controls.setConfig(controls.defaultControls)
                        self.text = 'Default Controls Loaded'
                    elif result == self.control_menu.save:
                        c = controls.currentConfig
                        try:
                            controls.writeConfig('controls.cfg', c)
                            self.text = 'Controls Saved'
                        except:
                            self.text = 'Error saving controls.cfg'
                    elif result == self.control_menu.restore:
                        try:
                            c = controls.readConfig('controls.cfg')
                            controls.setConfig(c)
                            self.text = 'Controls Loaded'
                        except:
                            self.text = 'Error loading controls.cfg'
                    elif result == self.control_menu.exit:
                        done = True

            else:  #polling for input now
                polling = True
                controls.UnpressAllKeys()
                joyconfirm = controls.joy_attack()
                unpress = False
                while polling:
                    self.draw(selected)
                    ika.Video.ShowPage()
                    ika.Input.Update()

                    for k in keyNames:  #check keyboard
                        key = ika.Input.keyboard[k]
                        if key.Pressed():  #key pressed!
                            if k == 'ESCAPE':  #skip escape
                                polling = False
                                self.text = ''
                                break
                            elif k == 'BACKSPACE':
                                controls.currentConfig[
                                    controls.
                                    configcontrolsList[selected]] = 'None'
                                controls.currentConfig[
                                    'joy_' + controls.
                                    configcontrolsList[selected]] = 'None'
                                controls.setConfig(controls.currentConfig)
                                self.text = 'Control cleared'
                                polling = False
                                break
                            else:
                                badkey = False
                                for c in controls.configcontrolsDict.keys():
                                    d = controls.currentConfig[c]
                                    if k == d:
                                        sound.menuBuzz.Play()
                                        self.text = 'Key ' + k + ' already assigned.'
                                        badkey = True
                                        polling = False
                                        break
                                if not badkey:
                                    controls.currentConfig[
                                        controls.
                                        configcontrolsList[selected]] = k
                                    controls.setConfig(controls.currentConfig)
                                    polling = False
                                    self.text = ''
                                break

                    if joyconfirm and not controls.joy_attack():
                        joyconfirm = False

                    if unpress:  #hack hack hack
                        repress = False
                        for joyIndex in range(len(ika.Input.joysticks)):
                            for axisIndex in range(
                                    len(ika.Input.joysticks[joyIndex].axes)):
                                if ika.Input.joysticks[joyIndex].axes[
                                        axisIndex].Position() > 0.5:
                                    repress = True  #if any axis is pressed, continue to "ignore" it
                            for axisIndex in range(
                                    len(ika.Input.joysticks[joyIndex].
                                        reverseAxes)):
                                if ika.Input.joysticks[joyIndex].reverseAxes[
                                        axisIndex].Position() > 0.5:
                                    repress = True
                        unpress = repress

                    if len(
                            ika.Input.joysticks
                    ) > 0 and not joyconfirm:  #check gamepad only if gamepad confirm button was unpressed
                        badkey = False
                        for joyIndex in range(len(ika.Input.joysticks)):
                            for axisIndex in range(
                                    len(ika.Input.joysticks[joyIndex].axes)):
                                if ika.Input.joysticks[joyIndex].axes[
                                        axisIndex].Position(
                                        ) > 0.5 and not unpress:
                                    unpress = True
                                    ax = 'joy%iaxis%i+' % (joyIndex, axisIndex)
                                    for c in controls.configcontrolsDict.keys(
                                    ):
                                        d = controls.currentConfig[c]
                                        if ax == d:
                                            sound.menuBuzz.Play()
                                            self.text = controls.buttonmapping[
                                                str(axisIndex) +
                                                '+'] + ' already assigned.'
                                            badkey = True
                                            break
                                    if not badkey:
                                        controls.currentConfig[
                                            'joy_' + controls.
                                            configcontrolsList[selected]] = ax
                                        controls.setConfig(
                                            controls.currentConfig)
                                        polling = False
                                        self.text = ''
                                    break
                            for axisIndex in range(
                                    len(ika.Input.joysticks[joyIndex].
                                        reverseAxes)):
                                if ika.Input.joysticks[joyIndex].reverseAxes[
                                        axisIndex].Position(
                                        ) > 0.5 and not unpress:
                                    unpress = True
                                    ax = 'joy%iaxis%i-' % (joyIndex, axisIndex)
                                    for c in controls.configcontrolsDict.keys(
                                    ):
                                        d = controls.currentConfig[c]
                                        if ax == d:
                                            sound.menuBuzz.Play()
                                            self.text = controls.buttonmapping[
                                                str(axisIndex) +
                                                '-'] + ' already assigned.'
                                            badkey = True
                                            break
                                    if not badkey:
                                        controls.currentConfig[
                                            'joy_' + controls.
                                            configcontrolsList[selected]] = ax
                                        controls.setConfig(
                                            controls.currentConfig)
                                        polling = False
                                        self.text = ''
                                    break
                            for buttonIndex in range(
                                    len(ika.Input.joysticks[joyIndex].buttons)
                            ):
                                if ika.Input.joysticks[joyIndex].buttons[
                                        buttonIndex].Pressed():
                                    btn = 'joy%ibutton%i' % (joyIndex,
                                                             buttonIndex)
                                    for c in controls.configcontrolsDict.keys(
                                    ):
                                        d = controls.currentConfig[c]
                                        if btn == d:
                                            sound.menuBuzz.Play()
                                            self.text = controls.buttonmapping[
                                                str(buttonIndex
                                                    )] + ' already assigned.'
                                            badkey = True
                                            break
                                    if not badkey:
                                        controls.currentConfig[
                                            'joy_' + controls.
                                            configcontrolsList[selected]] = btn
                                        controls.setConfig(
                                            controls.currentConfig)
                                        polling = False
                                        self.text = ''
                                    break
                controls.UnpressAllKeys()
                selectmode = 0
                selected = -1
                self.control_menu.unpress = True

        self.hide()
Esempio n. 10
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() 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() 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():
                return self.cursorPos
            elif controls.cancel():
                return Cancel
            else:
                self._cursorCount = self._pauseDelay

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