Skip to content

Commit

Permalink
Left rotate (issue #12)
Browse files Browse the repository at this point in the history
  • Loading branch information
haykkh committed Aug 23, 2019
1 parent 2aa65a4 commit 74d304f
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions pytris/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,26 @@ def keyLeft(self):
mapAdd(self, posMap)

def keyRight(self):
if pyxel.btnp(pyxel.KEY_RIGHT, 10, 1) and not mapCheck(self, posMap, 1, 0):
if pyxel.btnp(pyxel.KEY_RIGHT, 10, 1) and not mapCheck(self, posMap, 1, 0):
mapDel(self, posMap)
self.x = min(self.x + 1, -self.left + (pyxel.width - self.width) // 4)
mapAdd(self, posMap)

def rotater(self, direction):
if not self.center:
None
else:
mapDel(self, posMap)
rotate(self, direction)
mapAdd(self, posMap)

def keyUp(self):
if pyxel.btnp(pyxel.KEY_UP):
if not self.center:
None
else:
mapDel(self, posMap)
rotate(self)
mapAdd(self, posMap)
self.rotater(-1)

def keyZ(self):
if pyxel.btnp(pyxel.KEY_Z):
self.rotater(1)

def update(self):
"""Updates block
Expand All @@ -100,6 +107,7 @@ def update(self):
self.keyLeft()
self.keyRight()
self.keyUp()
self.keyZ()

if pyxel.btnp(pyxel.KEY_DOWN):
self.vy = 1
Expand Down Expand Up @@ -253,12 +261,12 @@ def mapDel(block, posMap):
posMap[y + block.y][x + block.x] = 0


def rotate(block):
def rotate(block, direction):
# SRS
block.coords = [
(
int(block.center[0] - y + block.center[1]),
int(block.center[1] + x - block.center[0])
int(block.center[0] + direction * (y - block.center[1])),
int(block.center[1] + direction * (block.center[0] - x))
)
for (x, y) in block.coords]
widthAndHeight(block)
Expand Down

0 comments on commit 74d304f

Please sign in to comment.