Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import enum
- from pygame import Vector2
- from math import fmod
- import random
- class tetromino(enum.Enum):
- O = 0
- I = 1
- S = 2
- Z = 3
- L = 4
- J = 5
- T = 6
- shapes = [
- """
- XX
- XO
- """,
- """
- X
- X
- O
- X
- """,
- """
- XX
- XO
- """,
- """
- XX
- OX
- """,
- """
- X
- X
- OX
- """,
- """
- X
- X
- XO
- """,
- """
- XOX
- X
- """
- ]
- # no error handling lol
- def get_shape(tet):
- shape = shapes[tet.value]
- compiled = []
- x_o, y_o, x, y = 0, 0, 0, 0
- for i in shape:
- if i == "\n":
- y-=1
- x=0
- else:
- x+=1
- if i == "X":
- compiled.append(Vector2(x, y))
- elif i == "O":
- x_o = x
- y_o = y
- compiled.append(Vector2(x, y))
- for i in compiled:
- i.x-=x_o
- i.y-=y_o
- return compiled
- def rotate(shape, degrees):
- normalized = fmod(round(degrees / 90), 4)
- compiled = []
- if normalized == 0:
- compiled = shape
- elif normalized == 1:
- for i in shape:
- compiled.append(Vector2(i.y, i.x))
- elif normalized == 2:
- for i in shape:
- compiled.append(Vector2(-i.x, -i.y))
- elif normalized == 3:
- for i in shape:
- compiled.append(Vector2(-i.y, -i.x))
- return compiled
- def random_tetromino():
- return random.choice([
- tetromino.I,
- tetromino.J,
- tetromino.L,
- tetromino.O,
- tetromino.S,
- tetromino.T,
- tetromino.Z
- ])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement