Exemple #1
0
 def __init__(self, x, y, width, height):
     self.grid = []
     self.pos = Point(x, y)
     self.origin = Point(0, 0)
     self.size = Dimension(width, height)
     self.rotState = rotState()
     self.tranState = tranState()
Exemple #2
0
 def __init__(self, x, y, width, height):
     self.grid = []
     self.pos = Point(x, y)
     self.origin = Point(0, 0)
     self.size = Dimension(width, height)
Exemple #3
0
import random
from tetris.util import Point, Dimension
from movePlacer import rotState, tranState
GridSize = Dimension(10, 20)


def random_piece():
    pieces = [SquarePiece, IPiece, JPiece, LPiece, TPiece, SPiece, ZPiece]
    return random.choice(pieces)()


# A 4x4 matrix representing a grid piece
class Piece(object):
    def __init__(self, x, y, width, height):
        self.grid = []
        self.pos = Point(x, y)
        self.origin = Point(0, 0)
        self.size = Dimension(width, height)
        self.rotState = rotState()
        self.tranState = tranState()

    # Set the grid values.
    def set(self, grid):
        self.grid = grid
        self.origin = Point(self.left(), self.top())

    # Rotate piece grid counter clockwise
    def rotate_left(self):
        rotated = zip(*self.grid)[::-1]
        self.set(rotated)
        self.size = self.size.rotate()
Exemple #4
0
import os
import pygame
from tetris.util import Point, Dimension

# Image dimensions
BlockSize = Dimension(20, 20)
BackgroundSize = Dimension(480, 450)
    
# Load an image from the file system
def load(filename):
    return pygame.image.load(os.path.join("images", filename)).convert()

class Gallery(object):
    
    def __init__(self):
        
        self.splash = load("splash.png")
        self.background = load("tetris-background.png")
        self.blocks = {}
        self.fading = {}
        
        # Parse blocks from sprite sheet
        width, height = BlockSize.width, BlockSize.height
        blocksheet = SpriteSheet("_blocks.png")
        for level in xrange(11):
            blockset = []
            for index in xrange(3):
                sub = blocksheet.subimage(level * width, index * height, width, height)
                blockset.append(Block(sub))
            self.blocks[level] = blockset