Basic rendering work.
This commit is contained in:
parent
f55f112cfe
commit
7b4f18df60
33
tetris.py
33
tetris.py
@ -3,10 +3,35 @@
|
|||||||
import pygame
|
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:
|
class Engine:
|
||||||
|
def __init__(self):
|
||||||
|
self.board = Board((10, 10), (10, 20), (20, 20))
|
||||||
|
self.surface = None
|
||||||
|
|
||||||
|
|
||||||
def create(self, resolution):
|
def create(self, resolution):
|
||||||
pygame.init()
|
pygame.init()
|
||||||
pygame.display.set_mode(resolution, pygame.DOUBLEBUF)
|
self.surface = pygame.display.set_mode(resolution, pygame.DOUBLEBUF)
|
||||||
|
|
||||||
if pygame.joystick.get_count() > 0:
|
if pygame.joystick.get_count() > 0:
|
||||||
self.joystick = pygame.joystick.Joystick(0)
|
self.joystick = pygame.joystick.Joystick(0)
|
||||||
@ -16,13 +41,19 @@ class Engine:
|
|||||||
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
self.board.advance()
|
||||||
|
self.board.render(self.surface)
|
||||||
|
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
pygame.time.delay(1)
|
pygame.time.delay(1)
|
||||||
|
|
||||||
event = pygame.event.poll()
|
event = pygame.event.poll()
|
||||||
return self.handle_event(event)
|
return self.handle_event(event)
|
||||||
|
|
||||||
|
|
||||||
def destroy(self):
|
def destroy(self):
|
||||||
|
self.surface = None
|
||||||
|
|
||||||
if self.joystick is not None:
|
if self.joystick is not None:
|
||||||
self.joystick.quit()
|
self.joystick.quit()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user