当前位置: 首页>>代码示例>>Python>>正文


Python Piece.getShape方法代码示例

本文整理汇总了Python中piece.Piece.getShape方法的典型用法代码示例。如果您正苦于以下问题:Python Piece.getShape方法的具体用法?Python Piece.getShape怎么用?Python Piece.getShape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在piece.Piece的用法示例。


在下文中一共展示了Piece.getShape方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from piece import Piece [as 别名]
# 或者: from piece.Piece import getShape [as 别名]
class PtModel:
    #class variables
    FPS = 60
    SCORE = [0, 40, 100, 300, 1200]
    TIME = {
        "fell": -100,
        "moved": -100,
        "rotated": -20,
        "stopped_moving": -30,
        "stopped_rotating":-30
        }
    INTERVAL = {
        "move": 0.3,
        "rotate": 0.3,
        "gravity": 0.3
        }
    
    def __init__(self, gravity = 0.3):
        self.view =  PtView()
        self.board = Board()
        self.p =  Piece(self.board)
        self.p_next = Piece(self.board)
        self.score = 0
        self.line_erasable = []
        self.interval = copy.deepcopy(PtModel.INTERVAL)
        self.interval['gravity'] = gravity
        self.time = copy.deepcopy(PtModel.TIME)

        self.flag = {
            'moving': True,
            'rotating': True
            }
        
        self.view.renderNext(self.p_next.getShape(), self.p_next.getType())
        
    def getKey(self):
        pygame.event.pump()
        keys = pygame.key.get_pressed()
        # 移動のキーn
        if self.isMovable():
            if keys[K_LEFT]:
                self.movePiece('left')
            elif keys[K_RIGHT]:
                self.movePiece('right')
            elif keys[K_UP]:
                self.movePiece('up')
            elif keys[K_DOWN]:
                self.movePiece('down')
                if self.p.isGround() == False:
                    self.time['moved'] = time.clock()
            else:
                # 動くのをやめた時だけインターバル回復
#                if self.flag['moving']:
                self.flag['moving'] = False
                self.time['stopped_moving'] = time.clock()
                self.interval['move'] = PtModel.INTERVAL['move']

        # 回転のキー
        if self.isRotatable():
            if keys[K_z]:
                self.rotatePiece('ccw')
            elif keys[K_x]:
                self.rotatePiece('cw')
            else:
 #               if self.flag['rotating']:
                self.flag['rotating'] = False
                self.time['stopped_rotating'] = time.clock()
                self.interval['rotate'] = PtModel.INTERVAL['rotate']

    def isMovable(self):
        if (time.clock() - self.time['moved']) > self.interval['move']:
            return True
        if (time.clock() - self.time['stopped_moving'])< PtModel.INTERVAL['move']:
            return True
        return False
    
    def isRotatable(self):
        if (time.clock() - self.time['rotated']) > self.interval['rotate']:
            return True
        if (time.clock() - self.time['stopped_rotating'])< PtModel.INTERVAL['rotate']:
            return True
        return False
    
    def movePiece(self, direction):
        if direction == 'up':
            self.p.drop()
        else:
            self.p.move(direction)
        self.time['moved'] = time.clock()
        if self.interval['move'] > 0.1:
            self.interval['move'] *= 0.9
#        self.flag['moving'] = True

    def rotatePiece(self, radius):
        self.p.rotate(radius)
        self.time['rotated'] = time.clock()
        if(self.interval['rotate']>0.1):
            self.interval['rotate'] *= 0.9
#        self.flag['rotating'] = True

#.........这里部分代码省略.........
开发者ID:fand,项目名称:pytetris,代码行数:103,代码来源:model.py


注:本文中的piece.Piece.getShape方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。