From 7b4f18df605a5aab4e0b8a125ca6c1f8ca4445fa Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Fri, 16 May 2014 13:58:16 +0900 Subject: [PATCH] Basic rendering work. --- tetris.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/tetris.py b/tetris.py index 2038958..caab3c3 100755 --- a/tetris.py +++ b/tetris.py @@ -3,10 +3,35 @@ import pygame +class Board: + def __init__(self, grid_position, grid_block_dims, block_dims): + self.block_dims = block_dims + self.grid_dims = grid_block_dims[0]*block_dims[0], grid_block_dims[1]*grid_block_dims[1] + self.grid_color = pygame.Color(0xff, 0xff, 0xff, 0xff) + self.grid_rect = pygame.Rect(grid_position, self.grid_dims) + + + def render(self, surface): + self.render_frame(surface) + + + def render_frame(self, surface): + pygame.draw.rect(surface, self.grid_color, self.grid_rect, 1) + + + def advance(self): + pass + + class Engine: + def __init__(self): + self.board = Board((10, 10), (10, 20), (20, 20)) + self.surface = None + + def create(self, resolution): pygame.init() - pygame.display.set_mode(resolution, pygame.DOUBLEBUF) + self.surface = pygame.display.set_mode(resolution, pygame.DOUBLEBUF) if pygame.joystick.get_count() > 0: self.joystick = pygame.joystick.Joystick(0) @@ -16,13 +41,19 @@ class Engine: def update(self): + self.board.advance() + self.board.render(self.surface) + pygame.display.flip() pygame.time.delay(1) + event = pygame.event.poll() return self.handle_event(event) def destroy(self): + self.surface = None + if self.joystick is not None: self.joystick.quit()