def addRemoveTick(): toClear = None for event in pygameEventGet(): if event.type == KEYDOWN: if event.key == K_ESCAPE: game.sm.switch('menu') elif event.key == K_SPACE: game.sm.switch('grow-shrink') sv.lastPlayState = 'grow-shrink' game.fbLabel.string = game.fbLabel.string.replace( 'add/remove', 'grow/shrink') elif event.key == K_c: display.clear() sv.circles.empty() elif event.type == MOUSEBUTTONDOWN: tx, ty = event.pos game.fbLabel.text(str(tx) + ', ' + str(ty) + ' add/remove') if event.button == 1: sv.mb1Down = True thisCircle = circle(tx, ty, sv.circles) thisCircle.radius = randint(radiusMin, radiusMax / 2) thisCircle.redraw() elif event.button == 3: for c in reversed(list(sv.circles.sprites())): if c.rect.collidepoint(tx, ty): toClear = c break elif event.type == MOUSEBUTTONUP: if event.button == 1: sv.mb1Down = False game.currCircle = None elif event.button == 3: sv.mb3Down = False game.currCircle = None game.ui.clear(display.screen, clear_callback) sv.circles.clear(display.screen, clear_callback) sv.circles.remove(toClear) postPlayTick()
def menuTick(): s = game.menu.tick(pygameEventGet()) if s != None: game.sm.switch(s)
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)
def growShrinkTick(): for event in pygameEventGet(): if event.type == KEYDOWN: if event.key == K_ESCAPE: game.sm.switch('menu') elif event.key == K_SPACE: game.sm.switch('add-remove') sv.lastPlayState = 'add-remove' game.fbLabel.string = game.fbLabel.string.replace( 'grow/shrink', 'add/remove') elif event.key == K_c: display.clear() sv.circles.empty() elif event.type == MOUSEBUTTONDOWN: tx, ty = event.pos game.fbLabel.text(str(tx) + ', ' + str(ty) + ' grow/shrink') if event.button == 1: sv.mb1Down = True for c in reversed(list(sv.circles.sprites())): if c.rect.collidepoint(tx, ty): game.currCircle = c break elif event.button == 3: sv.mb3Down = True for c in reversed(list(sv.circles.sprites())): if c.rect.collidepoint(tx, ty): game.currCircle = c break elif event.type == MOUSEBUTTONUP: if event.button == 1: sv.mb1Down = False game.currCircle = None elif event.button == 3: sv.mb3Down = False game.currCircle = None if sv.mb1Down and game.currCircle != None: game.currCircle.radius = min(game.currCircle.radius + 1, radiusMax) if sv.mb3Down and game.currCircle != None: game.currCircle.radius = max(game.currCircle.radius - 1, radiusMin) game.ui.clear(display.screen, clear_callback) sv.circles.clear(display.screen, clear_callback) if game.currCircle != None: game.currCircle.redraw() postPlayTick()