def freeze(self): shape = Blocks.getshape(self.now) for tph in range(Blocks.BLOCKH): for tpw in range(Blocks.BLOCKW): if shape[tph][tpw] == 0: continue ph = self.nowpos[0] + tph pw = self.nowpos[1] + tpw self.map[ph][pw] = self.now[0]
def __errmove__(self): shape = Blocks.getshape(self.now) for tph in range(Blocks.BLOCKH): for tpw in range(Blocks.BLOCKW): if shape[tph][tpw] == 0: continue if self.nowpos[0]+tph < 0: return True if self.nowpos[1]+tpw < 0: return True if self.nowpos[0]+tph >= self.size[0]: return True if self.nowpos[1]+tpw >= self.size[1]: return True if self.map[self.nowpos[0]+tph][self.nowpos[1]+tpw] != -1: return True return False
def draw_tips(scr,block): scr.fill(Colors.WHITE) brect = Blocks.getminirect(block) lh = brect[2] - brect[0] + 1 lw = brect[3] - brect[1] + 1 sh = (Blocks.BLOCKH - lh) * RECTH / 2 + 10 sw = (Blocks.BLOCKW - lw) * RECTW / 2 + 10 shape = Blocks.getshape(block) for th in range(lh): for tw in range(lw): if shape[brect[0] + th][brect[1] + tw] == 0: continue rect = [sw + tw * RECTW, sh + th * RECTH, RECTW, RECTH] draw_rect(scr, Colors.color[block[0]], rect)
def draw_blocks(scr, size, gamemap, block = None, blockpos = None): scr.fill(Colors.WHITE) for ph in xrange(size[0]): for pw in xrange(size[1]): if gamemap[ph][pw] == -1: continue draw_rect(scr, Colors.color[gamemap[ph][pw]], block_rect(ph,pw)) if block != None and blockpos != None: shape = Blocks.getshape(block) for tph in range(Blocks.BLOCKH): for tpw in range(Blocks.BLOCKW): if shape[tph][tpw] == 0: continue ph = blockpos[0] + tph pw = blockpos[1] + tpw if ph < 0 or ph > size[0]: continue if pw < 0 or pw > size[1]: continue draw_rect(scr, Colors.color[block[0]], block_rect(ph,pw))