Revision: 0408f0eedf
Author: Hugo Ruscitti <
hugoru...@gmail.com>
Date: Sun May 23 17:41:16 2010
Log: creando una animacion cuando el usuario hace una linea.
http://code.google.com/p/asadetris/source/detail?r=0408f0eedf
Modified:
/doc/etapas.otl
/doc/source/diseno_etapa_5.rst
/lib/board.py
/lib/game_scene.py
=======================================
--- /doc/etapas.otl Sun May 23 13:05:52 2010
+++ /doc/etapas.otl Sun May 23 17:41:16 2010
@@ -22,6 +22,7 @@
☑ mejorar la escena de juego
☑ crear un mensaje al inicio que diga "listo, ya!!"
☑ mostrar un mensaje de game over con una imagen
+ ☑ Crear un efecto cuando se elimina una linea.
=======================================
--- /doc/source/diseno_etapa_5.rst Sun May 23 13:05:52 2010
+++ /doc/source/diseno_etapa_5.rst Sun May 23 17:41:16 2010
@@ -51,3 +51,38 @@
def on_game_over(self):
self.show_graphic_message(game_scene_messages.GameOverMessage(self))
+
+
+Animación al eliminar lineas
+----------------------------
+
+En esta estapa también se ha incorporado una animación sencilla
+cuando se elimina una o mas lineas.
+
+Para crear el efecto se optó lo mas sencillo, mostrar un
+rectángulo intermitente sobre la linea que desaparece.
+
+El encargado del efecto es el objeto ``LineAnimation`` dentro
+del archivo ``gamescene.py``. Este objeto se genera cada vez
+que se realizan lineas. Por ejemplo, el siguiente
+fragmento de código se ejecuta cuando el usuario realiza
+una o mas lineas (el que invoca a este método es el
+objeto ``Board``):
+
+.. code-block:: python
+
+ def on_line_complete(self, lines):
+ self.line_animation = LineAnimation(lines)
+
+ # aumenta la velocidad del juego
+ self.game_speed = (self.display.level * 2) * len(lines)
+ self.delay_showing_line_animation = DELAY_LINE_COMPLE_EFFECT
+
+Aquí hay dos sentencias importantes, la primera genera el objeto
+``LineAnimation`` indicando las lineas que se van a eliminar. Y la
+segunda sentencia es la que le da valor al atributo
``delay_showing_line_animation``,
+este atributo indica que el juego debe detenerse unos pocos milisegundos
+para que el usuario pueda ver la animación.
+
+Cuando este contador llega a cero, el juego continúa y el tablero se limpia
+de efectos para que pueda seguir jugando.
=======================================
--- /lib/board.py Sun May 23 13:05:52 2010
+++ /lib/board.py Sun May 23 17:41:16 2010
@@ -133,12 +133,14 @@
self.matrix = self.matrix[:row] + self.matrix[row + 1:]
self.matrix.insert(0, empty_line)
- print "Asi queda la matriz luego de remover la linea."
- import pprint
- pprint.pprint(self.matrix)
-
+ #print "Asi queda la matriz luego de remover la linea."
+ #import pprint
+ #pprint.pprint(self.matrix)
def check_lines(self):
+ "Informa al objeto game si hay al menos una linea de bloques
completa."
+ lines = []
+
for row in range(len(self.matrix)):
width = len(self.matrix[row])
cwidth = 0
@@ -148,7 +150,24 @@
cwidth += 1
if cwidth == width:
- print "LINE at ROW %d" % (row)
- # self.draw_line_block(row)
+ lines.append(row)
+
+ if lines:
+ self.gamescene.on_line_complete(lines)
+
+ def remove_complete_lines(self):
+ """Elimina las lineas completas del tablero.
+
+ Este metodo lo invoca la clase Game luego de mostrar
+ un efecto sobre las lineas que van a desaparecer."""
+
+ for row in range(len(self.matrix)):
+ width = len(self.matrix[row])
+ cwidth = 0
+
+ for col in range(width):
+ if self.matrix[row][col] == 1:
+ cwidth += 1
+
+ if cwidth == width:
self.chop_line(row)
- self.gamescene.on_line_complete()
=======================================
--- /lib/game_scene.py Sun May 23 13:05:52 2010
+++ /lib/game_scene.py Sun May 23 17:41:16 2010
@@ -7,6 +7,31 @@
import piece
import display
import game_scene_messages
+from config import LEFT_CORNER, TOP_CORNER
+DELAY_LINE_COMPLE_EFFECT = 30
+
+
+class LineAnimation:
+
+ def __init__(self, lines):
+ self.lines = lines
+ self.count = 0
+
+ def draw(self, screen):
+ self.count += 1
+
+ for line in self.lines:
+ self.blit_rect(screen, line)
+
+ def blit_rect(self, screen, line):
+ rect = pygame.Rect((LEFT_CORNER, TOP_CORNER + line * 20, 20 * 10,
20))
+
+ if self.count % 10 <= 5:
+ color = (255, 255, 255)
+ else:
+ color = (100, 100, 100)
+
+ screen.fill(color, rect)
class GameScene(scene.Scene):
@@ -18,6 +43,7 @@
scene.Scene.__init__(self, director)
self.graphic_message = None
self.running = True
+ self.delay_showing_line_animation = 0
self.current_message = None
self.current_message_rect = None
self.board = board.Board(self)
@@ -27,20 +53,26 @@
self.game_speed = 0
self.create_return_message()
self.show_graphic_message(game_scene_messages.AreYouReadyMessage(self))
+ self.line_animation = None
+ self.delay_showing_line_animation = 0
def unpause_and_start_to_play(self):
self.running = True
self.go_to_next_piece()
-
def create_return_message(self):
font = utils.load_font("FreeSans.ttf", 14)
text = "Pulse ESC para regresar al menu"
self.return_message, rect = utils.render_text(text, font)
def on_update(self):
- self.board.update()
- self.pieces.update()
+
+ if self.delay_showing_line_animation:
+ self.delay_showing_line_animation -= 1
+ else:
+ self.board.update()
+ self.pieces.update()
+
if self.graphic_message:
self.graphic_message.on_update()
@@ -51,6 +83,14 @@
self.board.draw(screen)
screen.blit(self.return_message, (8, 460))
+ # muestra la animacion de las lineas que se han
+ # eliminando.
+ if self.delay_showing_line_animation:
+ self.line_animation.draw(screen)
+
+ if self.delay_showing_line_animation == 1:
+ self.board.remove_complete_lines()
+
if self.graphic_message:
self.graphic_message.on_draw(screen)
@@ -99,9 +139,14 @@
self.pieces.add(nextp)
self.display.set_next_piece()
- def on_line_complete(self):
- self.display.on_line_complete()
- self.game_speed = self.display.level * 2
+ def on_line_complete(self, lines):
+ self.line_animation = LineAnimation(lines)
+ for line in lines:
+ self.display.on_line_complete()
+
+ # aumenta la velocidad del juego
+ self.game_speed = (self.display.level * 2) * len(lines)
+ self.delay_showing_line_animation = DELAY_LINE_COMPLE_EFFECT
def pause(self):
self.running = False
--
Has recibido este mensaje porque estás suscrito al grupo "losersjuegos-alerts" de Grupos de Google.
Para publicar una entrada en este grupo, envía un correo electrónico a
losersjue...@googlegroups.com.
Para anular tu suscripción a este grupo, envía un correo electrónico a
losersjuegos-al...@googlegroups.com
Para tener acceso a más opciones, visita el grupo en
http://groups.google.com/group/losersjuegos-alerts?hl=es.