Exemplo n.º 1
0
    def slashState(self):
        self.stop()
        self.anim = 'slash'
        r = slashRange[self.direction]
        backslash = False
        backthrust = False

        # when we hit an entity, we append it here so that
        # we know not to hurt it again.
        hitList = []

        sound.slash1.Play()

        while not self._animator.kill:
            rect = list(r[self._animator.index]) + [self.layer]
            rect[0] += self.x
            rect[1] += self.y
            ents = ika.EntitiesAt(*rect)
            for e in ents:
                x = system.engine.entFromEnt[e]
                if isinstance(x, Enemy) and not x.invincible and x not in hitList:
                    hitList.append(x)
                    x.hurt( int(self.stats.att + ika.Random(0, 3)), 120, self.direction)
                    self.giveMPforHit()
            if self.stats.level >= BACK_LEVEL: 
                if (controls.up() or controls.joy_up()) and self.direction == dir.DOWN:  backthrust = True
                elif (controls.down()  or controls.joy_down()) and self.direction == dir.UP:  backthrust = True
                elif (controls.left() or controls.joy_left()) and self.direction in [dir.RIGHT, dir.UPRIGHT, dir.DOWNRIGHT]:  backthrust = True
                elif (controls.right() or controls.joy_right()) and self.direction in [dir.LEFT, dir.UPLEFT, dir.DOWNLEFT]:  backthrust = True

            if (controls.attack() or controls.joy_attack()) and self.stats.level >= SLASH_LEVEL: 
                backslash = True

            yield None

        if backthrust:
            self.state = self.backThrustState()
            yield None
        elif backslash:
            self.state = self.backSlashState()
            yield None
        else:
            # Stall:
            count = 10
            while count > 0:
                count -= 1
                if self.stats.level >= THRUST_LEVEL and (controls.attack() or controls.joy_attack()):
                    self.state = self.thrustState()
                yield None
Exemplo n.º 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
Exemplo n.º 3
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
Exemplo n.º 4
0
    def backSlashState(self):
        self.stop()
        self.anim = 'backslash'
        r = backSlashRange[self.direction]

        # when we hit an entity, we append it here so that
        # we know not to hurt it again.
        hitList = []

        sound.slash2.Play()

        while not self._animator.kill:
            rect = list(r[self._animator.index]) + [self.layer]
            rect[0] += self.x
            rect[1] += self.y
            ents = ika.EntitiesAt(*rect)
            for e in ents:
                x = system.engine.entFromEnt[e]
                if isinstance(x, Enemy) and not x.invincible and x not in hitList:
                    hitList.append(x)
                    x.hurt(int(self.stats.att + ika.Random(0, 3) * 1.25 ), 130, self.direction)
                    self.giveMPforHit()

            yield None

        # Stall:
        count = 10
        while count > 0:
            count -= 1
            if controls.rend() or controls.joy_rend():
                self.state = self.hearthRendState()
            elif self.stats.level >= THRUST_LEVEL and (controls.attack() or controls.joy_attack()):
                self.state = self.thrustState()
            yield None
Exemplo n.º 5
0
def text(where, txt):
    """Displays a text frame.
       Where txt can be either a point or an ika entity.
    """
    frame = textBox(where, txt)
    while not controls.attack():
        draw()
        frame.draw()
        ika.Video.ShowPage()
        ika.Input.Update()
Exemplo n.º 6
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()
Exemplo n.º 7
0
    def walkState(self):
        oldDir = self.direction
        self.anim = 'walk'
        while True:
            self.regenMP()                
            if controls.attack() or controls.joy_attack():
                self.state = self.slashState()
            elif controls.rend() or controls.joy_rend():
                self.state = self.hearthRendState()
                yield None
            elif controls.gale() or controls.joy_gale():
                self.state = self.crushingGaleState()
                yield None
            elif controls.heal() or controls.joy_heal():
                self.state = self.healingRainState()
                yield None
            elif controls.bolt() or controls.joy_bolt():
                self.state = self.boltState()
                yield None                
            elif controls.left() or controls.joy_left():
                if controls.up()  or controls.joy_up():
                    d = dir.UPLEFT
                elif controls.down()  or controls.joy_down():
                    d = dir.DOWNLEFT
                else:
                    d = dir.LEFT
            elif controls.right() or controls.joy_right():
                if controls.up() or controls.joy_up():
                    d = dir.UPRIGHT
                elif controls.down() or controls.joy_down():
                    d = dir.DOWNRIGHT
                else:
                    d = dir.RIGHT
            elif controls.up() or controls.joy_up():
                d = dir.UP
            elif controls.down() or controls.joy_down():
                d = dir.DOWN
            else:
                self.state = self.standState()
                yield None

            self.move(d)

            # handle animation and junk
            if d != oldDir:
                self.anim = 'walk'
                self.direction = d
                oldDir = d
            yield None           
Exemplo n.º 8
0
    def backThrustState(self):
        if self.direction == dir.UPLEFT or self.direction == dir.DOWNLEFT:
            self.direction = dir.LEFT
        elif self.direction == dir.UPRIGHT or self.direction == dir.DOWNRIGHT:
            self.direction = dir.RIGHT

        class SpeedSaver(object):
            def __init__(_self):        _self.s = self.speed
            def __del__(_self):         self.speed = _self.s

        ss = SpeedSaver()

        self.anim = 'backthrust'
        self.speed += 400
        self.move(dir.invert[self.direction], 1000)
        sound.dodge.Play()

        i = 8
        while i > 0:
            i -= 1
            self.speed -= 40
            yield None

        i = 30
        thrust = False
        gale = False

        while i > 0:
            i -= 1
            self.speed = max(0, self.speed - 10)
            if controls.attack() or controls.joy_attack():
                thrust = True
            elif controls.gale() or controls.joy_gale():
                gale = True
            yield None

        self.direction = dir.invert[self.direction]

        if thrust:
            self.state = self.thrustState()
            yield None

        elif gale:
            self.state = self.crushingGaleState()
            yield None

        self.stop()
Exemplo n.º 9
0
 def standState(self):
     self.stop()
     self.anim = 'stand'
         
     while True:
         self.regenMP()        
         if controls.attack() or controls.joy_attack():
             self.state = self.slashState()
         elif controls.rend() or controls.joy_rend():
             self.state = self.hearthRendState()
             yield None
         elif controls.gale() or controls.joy_gale():
             self.state = self.crushingGaleState()
             yield None
         elif controls.heal() or controls.joy_heal():
             self.state = self.healingRainState()
             yield None
         elif controls.bolt() or controls.joy_bolt():
             self.state = self.boltState()
             yield None
         elif controls.left() or controls.right() or controls.up() or controls.down() or controls.joy_left() or controls.joy_right() or controls.joy_up() or controls.joy_down():
             self.state = self.walkState()
             self._state() # get the walk state started right now.
         yield None
Exemplo n.º 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
Exemplo n.º 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)