fix resize
This commit is contained in:
parent
4df3c6c9ba
commit
d85c63701c
@ -23,7 +23,14 @@ import os
|
|||||||
import itertools
|
import itertools
|
||||||
import configparser
|
import configparser
|
||||||
|
|
||||||
from tetrislogic import TetrisLogic, Color, Coord, I_Tetrimino, Movement, AbstractScheduler
|
from tetrislogic import (
|
||||||
|
TetrisLogic,
|
||||||
|
Color,
|
||||||
|
Coord,
|
||||||
|
I_Tetrimino,
|
||||||
|
Movement,
|
||||||
|
AbstractScheduler,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# Constants
|
# Constants
|
||||||
@ -175,20 +182,24 @@ class MinoSprite(arcade.Sprite):
|
|||||||
self.append_texture(TEXTURES[mino.color])
|
self.append_texture(TEXTURES[mino.color])
|
||||||
self.append_texture(TEXTURES[Color.LOCKED])
|
self.append_texture(TEXTURES[Color.LOCKED])
|
||||||
self.set_texture(0)
|
self.set_texture(0)
|
||||||
|
self.resize()
|
||||||
|
|
||||||
|
def resize(self):
|
||||||
|
self.scale = self.window.scale
|
||||||
|
self.size = MINO_SIZE * self.window.scale
|
||||||
|
|
||||||
def update(self, x, y):
|
def update(self, x, y):
|
||||||
size = MINO_SIZE * self.window.scale
|
self.left = self.window.matrix.bg.left + x * self.size
|
||||||
self.left = self.window.matrix.bg.left + x * size
|
self.bottom = self.window.matrix.bg.bottom + y * self.size
|
||||||
self.bottom = self.window.matrix.bg.bottom + y * size
|
|
||||||
|
|
||||||
def fall(self, lines_cleared):
|
def fall(self, lines_cleared):
|
||||||
self.bottom -= MINO_SIZE * self.window.scale * lines_cleared
|
self.bottom -= MINO_SIZE * self.window.scale * lines_cleared
|
||||||
|
|
||||||
|
|
||||||
class MinoesSprites(arcade.SpriteList):
|
class MinoesSprites(arcade.SpriteList):
|
||||||
def resize(self, scale):
|
def resize(self):
|
||||||
for sprite in self:
|
for sprite in self:
|
||||||
sprite.scale = scale
|
sprite.resize()
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
|
|
||||||
@ -197,6 +208,7 @@ class TetrominoSprites(MinoesSprites):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
self.tetromino = tetromino
|
self.tetromino = tetromino
|
||||||
self.alpha = alpha
|
self.alpha = alpha
|
||||||
|
self.window = window
|
||||||
for mino in tetromino:
|
for mino in tetromino:
|
||||||
mino.sprite = MinoSprite(mino, window, alpha)
|
mino.sprite = MinoSprite(mino, window, alpha)
|
||||||
self.append(mino.sprite)
|
self.append(mino.sprite)
|
||||||
@ -209,6 +221,7 @@ class TetrominoSprites(MinoesSprites):
|
|||||||
def set_texture(self, texture):
|
def set_texture(self, texture):
|
||||||
for mino in self.tetromino:
|
for mino in self.tetromino:
|
||||||
mino.sprite.set_texture(texture)
|
mino.sprite.set_texture(texture)
|
||||||
|
mino.sprite.scale = self.window.scale
|
||||||
|
|
||||||
|
|
||||||
class MatrixSprites(MinoesSprites):
|
class MatrixSprites(MinoesSprites):
|
||||||
@ -228,6 +241,7 @@ class MatrixSprites(MinoesSprites):
|
|||||||
if mino:
|
if mino:
|
||||||
self.remove(mino.sprite)
|
self.remove(mino.sprite)
|
||||||
|
|
||||||
|
|
||||||
class TetrArcade(TetrisLogic, arcade.Window):
|
class TetrArcade(TetrisLogic, arcade.Window):
|
||||||
"""Tetris clone with arcade GUI library"""
|
"""Tetris clone with arcade GUI library"""
|
||||||
|
|
||||||
@ -614,7 +628,7 @@ AGAIN""".format(
|
|||||||
self.matrix.bg.left = int(self.matrix.bg.left)
|
self.matrix.bg.left = int(self.matrix.bg.left)
|
||||||
self.matrix.bg.top = int(self.matrix.bg.top)
|
self.matrix.bg.top = int(self.matrix.bg.top)
|
||||||
|
|
||||||
self.matrix.sprites.resize(self.scale)
|
self.matrix.sprites.resize()
|
||||||
|
|
||||||
for tetromino in [
|
for tetromino in [
|
||||||
self.held.piece,
|
self.held.piece,
|
||||||
@ -622,7 +636,7 @@ AGAIN""".format(
|
|||||||
self.matrix.ghost,
|
self.matrix.ghost,
|
||||||
] + self.next.pieces:
|
] + self.next.pieces:
|
||||||
if tetromino:
|
if tetromino:
|
||||||
tetromino.sprites.resize(self.scale)
|
tetromino.sprites.resize()
|
||||||
|
|
||||||
def load_high_score(self):
|
def load_high_score(self):
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user