Implemented and tested the TiledBackground class.

This commit is contained in:
2013-01-16 22:03:30 -04:30
parent a6aebd9126
commit a928348e07
2 changed files with 69 additions and 7 deletions

View File

@@ -9,16 +9,22 @@ except ImportError:
android = None
import player
import background
from state import BaseState, VALID_STATES
class InGameState(BaseState):
def __init__(self):
BaseState.__init__(self)
self.count = 0
self.next_transition = VALID_STATES['STAY']
self.cursor_x = 0
self.cursor_y = 0
self.user_click = False
screen_center = self.get_screen_center()
self.rectangle = pygame.Rect(screen_center[0] - 50, screen_center[1] - 50, 100, 100)
self.next_transition = VALID_STATES['STAY']
self.background = background.TiledBackground(1280, 1024, 'gfx/piso.png')
def input(self):
for event in pygame.event.get():
@@ -29,19 +35,26 @@ class InGameState(BaseState):
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
self.next_transition = VALID_STATES['QUIT']
self.user_click = True
if event.type == pygame.QUIT:
self.next_transition = VALID_STATES['QUIT']
# Catch the position of a mouse click (or tap).
if event.type == pygame.MOUSEBUTTONDOWN:
(self.cursor_x, self.cursor_y) = event.pos
self.user_click = True
def update(self):
if self.next_transition != VALID_STATES['QUIT']:
if self.count < 120:
self.count += 1
if self.next_transition != VALID_STATES['STAY']:
self.next_transition = VALID_STATES['STAY']
else:
self.count = 0
if self.user_click:
self.next_transition = VALID_STATES['SCORE']
self.user_click = False
return self.next_transition
def render(self, canvas):
canvas.fill(self.background_color)
self.background.draw(canvas)
pygame.draw.rect(canvas, (255, 0, 255), self.rectangle)