Esempio n. 1
0
def newGameLoadExit():

    sv.hold = False
    sv.shifted = False
    sv.quick = False
    sv.left = False
    sv.right = False

    sv.leftDelay = sv.rightDelay = moveInitDelay

    setBlock(sv.nBlock, game.nextGrid, 1, 1)
    if sv.hBlock != None: setBlock(sv.hBlock, game.holdGrid, 1, 1)

    gridSurf = Surface((blockBase, blockBase))

    cL = range(1, blockBase / 2)
    cL.reverse()
    for c in cL:

        drawRect(gridSurf,
                 (min(255, int(255 / (c * overlayColorConstant))), ) * 3,
                 Rect((blockBase / 2) - c, (blockBase / 2) - c, c * 2,
                      c * 2), 1)

    game.grid.overlay = gridSurf
    game.nextGrid.overlay = gridSurf
    game.holdGrid.overlay = gridSurf

    game.sm.flags.discard('gameOver')
    game.msg('levelLabel::level' + str(sv.levelCounter) + ' - ' +
             str(sv.score))
Esempio n. 2
0
File: item.py Progetto: eyeCube/RPyG
def equip(unit, item, slot):
    canEquip = False
    toOffHand = False  #flag for equipping weapon in offhand
    equip = getEquipment(unit, slot)
    if equip:  #slot unavailable
        game.msg("{u} cannot equip {i} (equip slot unavailable)".format(
            u=unit.name, i=item.name))
    else:
        #weapons
        if item.type == HAND1:
            if slot == HAND1:  #equipping to mainhand
                if item.hands == "2":
                    if getEquipment(unit, HAND2) == None:
                        canEquip = True
                else:
                    canEquip = True
            elif slot == HAND2:  #equipping to offhand
                if item.hands != "2":
                    if getEquipment(unit, HAND1):
                        if getEquipment(unit, HAND1).hands != "2":
                            canEquip = True
                            toOffHand = True
                    else:
                        canEquip = True
                        toOffHand = True

        #others
        elif item.type == slot:  #right type?
            canEquip = True

    if canEquip:
        modDict = None
        if toOffHand:  #equipping a weapon in the offhand, need to change values
            dic = item.stats
            newDic = {}
            #make all stats for hand1 to hand2
            for k, v in dic.items():
                if k[:5] == "hand1":
                    string = "hand2" + k[5:]
                    newDic[string] = v
                else:
                    newDic[k] = v
            modDict = newDic
        else:
            modDict = item.stats
        mod = Mod(modDict)
        unit.equipment[slot] = EquipSlot(item, mod.id)
        unit.stats.addModifier(mod)  #modify stats of unit
        game.msg("{u} equipped {i}".format(u=unit.name, i=item.name))
        return True
    else:
        return False  #failure to equip
Esempio n. 3
0
  def run(self):

    import game

    self.running = True

    game.msg.handler('state')(self.switch)

    if self.next is not None and self.next != self.activeName:
      self._next(self.next)

    while self.running and not peek(QUIT):

      self.states[self.activeName].tick()

      if self.next is not None and self.next != self.activeName:
        self._next(self.next)

      game.msg('display::update')
      game.msg.process()
      self.clock.tick(game.fps)

    self.quit()
Esempio n. 4
0
def attack(attkr, dfndr, atkHand):
    crit=False
    blocked=False
    reachPenalty=False
    
    #get weapon values
    atkWeap, atkWeapName = item.getWeapData(attkr, atkHand)
    if atkHand == HAND1:
        reach = Unit.getStat(attkr,'hand1reachMax')
        reachMin = Unit.getStat(attkr,'hand1reachMin')
    elif atkHand == HAND2:
        reach = Unit.getStat(attkr,'hand2reachMax')
        reachMin = Unit.getStat(attkr,'hand2reachMin')
        
    #unit stats
    acc = Unit.getStat(attkr,"accm")
    spd = Unit.getStat(attkr,'spd')

    if acc <= 0:
        return False #unit cannot attack, no accuracy.
        
    #check if in range
    dist = hex_distance(attkr.pos, dfndr.pos)
    if reach < dist:
        game.msg("{a} cannot hit {d} with {w}! (out of reach)".format(
            d=dfndr.name, a=attkr.name, w=atkWeapName))
        return False #cannot go through with attack.
    if dist < reachMin:
        reachPenalty = True
        acc -= MINREACH_ACCPENALTY
        spd -= MINREACH_SPDPENALTY
    
    game.msg("> {a} targets {d} ...".format(
        d=dfndr.name,a=attkr.name))
    
    #attacking uses up your unit's turn
    Unit.exhaustTurn(attkr)
    
    #hit adjacent foe
    if (random.random()*100 < Unit.getStat(attkr, 'hitAdjFoe')):
        unitList=[]
        for unit in Unit.getAdjacentUnits(dfndr): #create list of possible targets
            if foes(unit, attkr): #don't friendly fire!
                unitList.append(unit)
        #pick a random unit from the list of possible targets
        randIndex = int(random.random() * len(unitList))
        unit = unitList[randIndex]
        d = hex_distance(unit.pos, attkr.pos)
        if (d <= reach and d >= reachMin): #check if within ideal range.
            strike(attkr, unit, HAND1, atkWeap, atkWeapName) #deal one hit
    
    #speed, multi-hits
    remainder = spd % SPEED_FACTOR
    hits = spd//SPEED_FACTOR
    if (random.random()*100 < remainder*(100//SPEED_FACTOR)):
        hits += 1
    
    #attempt to hit as many times as we can
    for hitNum in range(hits):
        _continue=False
        #check aim
        if (random.random()*100 >= acc):
            game.msg("{d} is missed by {a}'s {w}".format(
                d=dfndr.name,a=attkr.name, w=atkWeapName))
            continue #attack failed
        
        #parry
        if (random.random()*100 < Unit.getStat(dfndr,"parry")):
            result = parryAttack(dfndr, attkr, atkWeap, atkWeapName)
            if result == "counter":
                return False #counter breaks chains of attacks
            else:
                continue #attack failed
        #parry from ally
        for unit in Unit.getAdjacentUnits(dfndr):
            if unit:
                if not allies(unit, dfndr):
                    continue
                if (random.random()*100 < Unit.getStat(unit,'parryAlly')):
                    result = parryAttack(unit, attkr, atkWeap, atkWeapName)
                    if result == "counter":
                        return False #counter breaks chains of attacks
                    else:
                        _continue=True
                        break #attack failed
        if _continue:
            continue #attack failed
            
        #evade
        realEva = Unit.getStat(dfndr,'eva')
        eva = realEva - max(0, acc - 100)
        eva -= dfndr.evadeCounter*EVA_LOSS_PER_EVADE
        if eva < realEva//2:
            eva = realEva//2 #Acc cut of Eva at maximum cuts Eva in half.
        eva = min(MAX_EVASION, eva) #evasion cap
        if (random.random()*100 < eva):
            game.msg("{d} evades {a}'s {w}".format(
                d=dfndr.name,a=attkr.name, w=atkWeapName))
            dfndr.evadeCounter += 1
            continue #attack failed
        
        #Attack!
        strike(attkr, dfndr, HAND1, atkWeap, atkWeapName, reachPenalty)
Esempio n. 5
0
def playTick():

    import zoot.config as config

    if sv.c >= config.speed - (
        (sv.levelCounter - 1) * config.levelSpeedIncrease):

        sv.c = 0
        sv.cx, sv.cy = check(0, 1)

    sv.c += 1

    for event in pygameEventGet():

        if event.type == ACTIVEEVENT:
            if event.gain == 0 and event.state in (2, 4, 6):
                game.sm.switch('menu')

        if event.type == KEYDOWN and event.key == K_ESCAPE:
            #~ game.sm.switch('menu')
            game.msg('state::menu')

        if not sv.cBlock.settle:

            if event.type == KEYDOWN:

                if event.key == K_s:
                    checkRotated(1)

                elif (event.key == K_a or event.key == K_UP):
                    checkRotated(-1)

                elif event.key == K_LEFT:
                    if event.mod & KMOD_SHIFT and not sv.shifted:
                        sv.cx, sv.cy = checkSide(-1)
                        sv.shifted = True
                    else:
                        sv.cx, sv.cy = check(-1, 0)
                        sv.left = True

                elif event.key == K_RIGHT:
                    if event.mod & KMOD_SHIFT and not sv.shifted:
                        sv.cx, sv.cy = checkSide(1)
                        sv.shifted = True
                    else:
                        sv.cx, sv.cy = check(1, 0)
                        sv.right = True

                elif event.key == K_DOWN:
                    sv.quick = True

        if event.type == KEYDOWN:

            if event.key == K_SPACE:
                sv.cx, sv.cy = checkDrop()
                sv.c = 1

            elif event.key == K_c:
                sv.ghost = not sv.ghost

            elif event.key == K_TAB:
                sv.hold = True

        if event.type == KEYUP:

            if event.key == K_LEFT:
                sv.left = False
                if sv.levelCounter < 19:
                    sv.leftDelay = config.moveInitDelay
                else:
                    sv.rightDelay = config.moveDelay

            elif event.key == K_RIGHT:
                sv.right = False
                if sv.levelCounter < 19:
                    sv.rightDelay = config.moveInitDelay
                else:
                    sv.rightDelay = config.moveDelay

            elif event.key == K_DOWN:
                sv.quick = False

            elif event.key == K_SPACE:
                sv.cx, sv.cy = check(0, 1)

            elif (event.key == K_LSHIFT or event.key == K_RSHIFT):
                sv.shifted = False

    if not sv.cBlock.settle:

        if sv.quick:
            sv.cx, sv.cy = check(0, 1)

        if sv.left:
            sv.leftDelay -= 1
            if sv.leftDelay == 0:
                sv.cx, cy = check(-1, 0)
                sv.leftDelay = config.moveDelay

        if sv.right:
            sv.rightDelay -= 1
            if sv.rightDelay == 0:
                sv.cx, sv.cy = check(1, 0)
                sv.rightDelay = config.moveDelay

        if sv.ghost:
            gx, gy = checkDrop()

    if sv.hold:

        if sv.hBlock is None:
            sv.hBlock = sv.nBlock
            sv.nBlock = sv.newBlock()
        else:
            sv.hBlock, sv.nBlock = sv.nBlock, sv.hBlock

        game.holdGrid.clear(display.screen)

        setBlock(sv.hBlock, game.holdGrid, 1, 1)

        game.nextGrid.clear(display.screen)

        setBlock(sv.nBlock, game.nextGrid, 1, 1)

        sv.redrawGrids = True
        sv.hold = False

    game.grid.clear(display.screen)

    game.ui.clear(display.screen, display.background)

    setBlock(sv.cBlock, game.grid, sv.cx, sv.cy)

    if sv.cBlock.settle:

        for bx, by in sv.cBlock.pos[sv.cBlock.p]:
            thisRect = game.grid.get(sv.cx + bx, sv.cy + by)
            thisRect.settled = True
            thisRect.active = False

        sv.quick = False

        sv.cBlock.settle = False

        fullLines = game.grid.checkLines()

        #~ bgc = 0
        #~ for bottomGrid in range(config.gridWidth):
        #~ if game.grid.get(bottomGrid, config.gridHeight - 1).settled:
        #~ bgc += 1

        #~ print bgc

        if fullLines > 0:

            if fullLines == 1:
                sv.score += 10
            elif fullLines == 2:
                sv.score += 30
            elif fullLines == 3:
                sv.score += 60
            elif fullLines == 4:
                sv.score += 100

            sv.lineCounter += fullLines

            sv.levelCounter = (sv.lineCounter / config.nextLevelLines) + 1

            game.msg.post('levelLabel::level' + str(sv.levelCounter) + ' - ' +
                          str(sv.score))

        sv.cBlock = sv.nBlock
        sv.cx, sv.cy = config.startPos

        setBlock(sv.cBlock, game.grid, sv.cx, sv.cy)

        sv.nBlock = sv.newBlock()

        game.nextGrid.clear(display.screen)

        setBlock(sv.nBlock, game.nextGrid, 1, 1)

        game.nextGrid.draw(display.screen)

        if game.grid.get(config.startPos).settled:  # fixme!
            #from os import remove as osRemove
            print 'level ' + str(sv.levelCounter) + ' - ' + str(sv.score)
            # osRemove('zoot.save')
            game.sm.flags.add('gameOver')
            game.sm.switch('menu')

    elif sv.ghost:

        for bx, by in sv.cBlock.pos[sv.cBlock.p]:

            thisRect = game.grid.get(gx + bx, gy + by)
            thisRect.ghost = True
            game.grid.clearRects.append(thisRect)

    game.ui.update()

    game.grid.draw(display.screen)

    if sv.redrawGrids:

        drawGrids()

    game.ui.draw(display.screen)