Example #1
0
def init(gravity):
    reload(const)
    reload(param)

    pygame.init()
    pygame.font.init()
    pygame.display.set_caption(u"TETRIS")

    model.p = Piece()
    model.p_next = Piece()

    view.renderNext(model.p_next)
    param.score = 0
    
    clock = pygame.time.Clock()
    param.t['dropped'] = param.t['moved'] = param.t['rotated'] = \
    param.t['stopped_moving'] = param.t['stopped_rotating'] \
        = time.clock()
    param.interval['gravity'] = gravity
    pygame.key.set_repeat(150, 40)
Example #2
0
def loop():
    tick()
    if param.flag['erase']:
        model.erase()
        pass
    elif param.flag['update']:
        for i in range(len(model.p.shape[0])):
            for j in range (len(model.p.shape[0][i])):
                if model.p.shape[0][i][j]:
                    const.map[model.p.y+i][model.p.x+j] = model.p.shape[1]
        model.checkErase()
        model.p= copy.deepcopy(model.p_next)
        model.p.updateMap(const.map)
        model.p_next = Piece()
        view.renderNext(model.p_next)
        param.flag['update'] = False
        param.flag['ground'] = False
    elif param.flag['gameover']:
        print('oh no')
    else:
        model.getKey(model.p)
        if (param.t['now']-param.t['dropped'])> param.interval['gravity']:
#            param.t['dropped'] = param.t['now']
            if param.flag['ground']:
                if param.t['now']-param.t['moved'] < param.interval['gravity']\
                or param.t['now']-param.t['rotated'] < param.interval['gravity']:
                    pass
                else:
                    param.flag['update'] = True
            else:
                model.p.move('down')
        else:
            pass

    model.p.checkGround()
    model.checkGameover()
    draw()