Moved background color to BaseState.

This commit is contained in:
2013-01-09 22:34:15 -04:30
parent 270872efe7
commit e742f9c19d
5 changed files with 93 additions and 79 deletions

View File

@@ -11,6 +11,8 @@ from state import BaseState, VALID_STATES
class InGameState(BaseState):
def __init__(self):
BaseState.__init__(self)
self.count = 0
screen_center = self.get_screen_center()
self.rectangle = pygame.Rect(screen_center[0] - 50, screen_center[1] - 50, 100, 100)
@@ -39,4 +41,5 @@ class InGameState(BaseState):
return self.next_transition
def render(self, canvas):
canvas.fill(self.background_color)
pygame.draw.rect(canvas, (255, 0, 255), self.rectangle)

View File

@@ -11,6 +11,8 @@ from state import BaseState, VALID_STATES
class MenuState(BaseState):
def __init__(self):
BaseState.__init__(self)
self.count = 0
screen_center = self.get_screen_center()
self.rectangle = pygame.Rect(screen_center[0] - 50, screen_center[1] - 50, 100, 100)
@@ -39,4 +41,5 @@ class MenuState(BaseState):
return self.next_transition
def render(self, canvas):
canvas.fill(self.background_color)
pygame.draw.rect(canvas, (0, 255, 255), self.rectangle)

View File

@@ -11,6 +11,8 @@ from state import BaseState, VALID_STATES
class NotValidState(BaseState):
def __init__(self):
BaseState.__init__(self)
self.count = 0
screen_center = self.get_screen_center()
self.rectangle = pygame.Rect(screen_center[0] - 50, screen_center[1] - 50, 100, 100)
@@ -23,7 +25,6 @@ class NotValidState(BaseState):
android.wait_for_resume()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
self.next_transition = VALID_STATES['QUIT']
if event.type == pygame.QUIT:
self.next_transition = VALID_STATES['QUIT']
@@ -32,4 +33,5 @@ class NotValidState(BaseState):
return self.next_transition
def render(self, canvas):
canvas.fill(self.background_color)
pygame.draw.rect(canvas, (0, 0, 0), self.rectangle)

View File

@@ -11,6 +11,8 @@ from state import BaseState, VALID_STATES
class ScoreState(BaseState):
def __init__(self):
BaseState.__init__(self)
self.count = 0
screen_center = self.get_screen_center()
self.rectangle = pygame.Rect(screen_center[0] - 50, screen_center[1] - 50, 100, 100)
@@ -39,4 +41,5 @@ class ScoreState(BaseState):
return self.next_transition
def render(self, canvas):
canvas.fill(self.background_color)
pygame.draw.rect(canvas, (255, 255, 0), self.rectangle)

View File

@@ -7,6 +7,9 @@ VALID_STATES = { 'INTRO':0, 'MENU':1, 'IN_GAME':2, 'SCORE':3, 'STAY':4, 'QUIT':8
# Parent class for game states.
class BaseState:
def __init__(self):
self.background_color = (139, 210, 228)
def input(self):
""" Empty. Should handle PyGame input. """
pass
@@ -17,7 +20,7 @@ class BaseState:
def render(self, canvas):
""" Empty. Should render this state on the canvas. """
pass
canvas.fill(self.background_color)
def get_screen_center(self):
return (pygame.display.Info().current_w / 2,