Moved background color to BaseState.
This commit is contained in:
45
ingame.py
45
ingame.py
@@ -11,32 +11,35 @@ from state import BaseState, VALID_STATES
|
|||||||
|
|
||||||
class InGameState(BaseState):
|
class InGameState(BaseState):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.count = 0
|
BaseState.__init__(self)
|
||||||
screen_center = self.get_screen_center()
|
|
||||||
self.rectangle = pygame.Rect(screen_center[0] - 50, screen_center[1] - 50, 100, 100)
|
self.count = 0
|
||||||
self.next_transition = VALID_STATES['STAY']
|
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']
|
||||||
|
|
||||||
def input(self):
|
def input(self):
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if android:
|
if android:
|
||||||
if android.check_pause():
|
if android.check_pause():
|
||||||
android.wait_for_resume()
|
android.wait_for_resume()
|
||||||
|
|
||||||
if event.type == pygame.KEYDOWN:
|
if event.type == pygame.KEYDOWN:
|
||||||
if event.key == pygame.K_ESCAPE:
|
if event.key == pygame.K_ESCAPE:
|
||||||
self.next_transition = VALID_STATES['QUIT']
|
|
||||||
if event.type == pygame.QUIT:
|
|
||||||
self.next_transition = VALID_STATES['QUIT']
|
self.next_transition = VALID_STATES['QUIT']
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
self.next_transition = VALID_STATES['QUIT']
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
if self.next_transition != VALID_STATES['QUIT']:
|
if self.next_transition != VALID_STATES['QUIT']:
|
||||||
if self.count < 120:
|
if self.count < 120:
|
||||||
self.count += 1
|
self.count += 1
|
||||||
self.next_transition = VALID_STATES['STAY']
|
self.next_transition = VALID_STATES['STAY']
|
||||||
else:
|
else:
|
||||||
self.count = 0
|
self.count = 0
|
||||||
self.next_transition = VALID_STATES['SCORE']
|
self.next_transition = VALID_STATES['SCORE']
|
||||||
return self.next_transition
|
return self.next_transition
|
||||||
|
|
||||||
def render(self, canvas):
|
def render(self, canvas):
|
||||||
pygame.draw.rect(canvas, (255, 0, 255), self.rectangle)
|
canvas.fill(self.background_color)
|
||||||
|
pygame.draw.rect(canvas, (255, 0, 255), self.rectangle)
|
||||||
|
45
menu.py
45
menu.py
@@ -11,32 +11,35 @@ from state import BaseState, VALID_STATES
|
|||||||
|
|
||||||
class MenuState(BaseState):
|
class MenuState(BaseState):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.count = 0
|
BaseState.__init__(self)
|
||||||
screen_center = self.get_screen_center()
|
|
||||||
self.rectangle = pygame.Rect(screen_center[0] - 50, screen_center[1] - 50, 100, 100)
|
self.count = 0
|
||||||
self.next_transition = VALID_STATES['STAY']
|
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']
|
||||||
|
|
||||||
def input(self):
|
def input(self):
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if android:
|
if android:
|
||||||
if android.check_pause():
|
if android.check_pause():
|
||||||
android.wait_for_resume()
|
android.wait_for_resume()
|
||||||
|
|
||||||
if event.type == pygame.KEYDOWN:
|
if event.type == pygame.KEYDOWN:
|
||||||
if event.key == pygame.K_ESCAPE:
|
if event.key == pygame.K_ESCAPE:
|
||||||
self.next_transition = VALID_STATES['QUIT']
|
|
||||||
if event.type == pygame.QUIT:
|
|
||||||
self.next_transition = VALID_STATES['QUIT']
|
self.next_transition = VALID_STATES['QUIT']
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
self.next_transition = VALID_STATES['QUIT']
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
if self.next_transition != VALID_STATES['QUIT']:
|
if self.next_transition != VALID_STATES['QUIT']:
|
||||||
if self.count < 120:
|
if self.count < 120:
|
||||||
self.count += 1
|
self.count += 1
|
||||||
self.next_transition = VALID_STATES['STAY']
|
self.next_transition = VALID_STATES['STAY']
|
||||||
else:
|
else:
|
||||||
self.count = 0
|
self.count = 0
|
||||||
self.next_transition = VALID_STATES['IN_GAME']
|
self.next_transition = VALID_STATES['IN_GAME']
|
||||||
return self.next_transition
|
return self.next_transition
|
||||||
|
|
||||||
def render(self, canvas):
|
def render(self, canvas):
|
||||||
pygame.draw.rect(canvas, (0, 255, 255), self.rectangle)
|
canvas.fill(self.background_color)
|
||||||
|
pygame.draw.rect(canvas, (0, 255, 255), self.rectangle)
|
||||||
|
@@ -11,25 +11,27 @@ from state import BaseState, VALID_STATES
|
|||||||
|
|
||||||
class NotValidState(BaseState):
|
class NotValidState(BaseState):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.count = 0
|
BaseState.__init__(self)
|
||||||
screen_center = self.get_screen_center()
|
|
||||||
self.rectangle = pygame.Rect(screen_center[0] - 50, screen_center[1] - 50, 100, 100)
|
self.count = 0
|
||||||
self.next_transition = VALID_STATES['STAY']
|
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']
|
||||||
|
|
||||||
def input(self):
|
def input(self):
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if android:
|
if android:
|
||||||
if android.check_pause():
|
if android.check_pause():
|
||||||
android.wait_for_resume()
|
android.wait_for_resume()
|
||||||
|
|
||||||
if event.type == pygame.KEYDOWN:
|
if event.type == pygame.KEYDOWN:
|
||||||
if event.key == pygame.K_ESCAPE:
|
self.next_transition = VALID_STATES['QUIT']
|
||||||
self.next_transition = VALID_STATES['QUIT']
|
if event.type == pygame.QUIT:
|
||||||
if event.type == pygame.QUIT:
|
self.next_transition = VALID_STATES['QUIT']
|
||||||
self.next_transition = VALID_STATES['QUIT']
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
return self.next_transition
|
return self.next_transition
|
||||||
|
|
||||||
def render(self, canvas):
|
def render(self, canvas):
|
||||||
pygame.draw.rect(canvas, (0, 0, 0), self.rectangle)
|
canvas.fill(self.background_color)
|
||||||
|
pygame.draw.rect(canvas, (0, 0, 0), self.rectangle)
|
||||||
|
45
score.py
45
score.py
@@ -11,32 +11,35 @@ from state import BaseState, VALID_STATES
|
|||||||
|
|
||||||
class ScoreState(BaseState):
|
class ScoreState(BaseState):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.count = 0
|
BaseState.__init__(self)
|
||||||
screen_center = self.get_screen_center()
|
|
||||||
self.rectangle = pygame.Rect(screen_center[0] - 50, screen_center[1] - 50, 100, 100)
|
self.count = 0
|
||||||
self.next_transition = VALID_STATES['STAY']
|
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']
|
||||||
|
|
||||||
def input(self):
|
def input(self):
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if android:
|
if android:
|
||||||
if android.check_pause():
|
if android.check_pause():
|
||||||
android.wait_for_resume()
|
android.wait_for_resume()
|
||||||
|
|
||||||
if event.type == pygame.KEYDOWN:
|
if event.type == pygame.KEYDOWN:
|
||||||
if event.key == pygame.K_ESCAPE:
|
if event.key == pygame.K_ESCAPE:
|
||||||
self.next_transition = VALID_STATES['QUIT']
|
|
||||||
if event.type == pygame.QUIT:
|
|
||||||
self.next_transition = VALID_STATES['QUIT']
|
self.next_transition = VALID_STATES['QUIT']
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
self.next_transition = VALID_STATES['QUIT']
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
if self.next_transition != VALID_STATES['QUIT']:
|
if self.next_transition != VALID_STATES['QUIT']:
|
||||||
if self.count < 120:
|
if self.count < 120:
|
||||||
self.count += 1
|
self.count += 1
|
||||||
self.next_transition = VALID_STATES['STAY']
|
self.next_transition = VALID_STATES['STAY']
|
||||||
else:
|
else:
|
||||||
self.count = 0
|
self.count = 0
|
||||||
self.next_transition = VALID_STATES['MENU']
|
self.next_transition = VALID_STATES['MENU']
|
||||||
return self.next_transition
|
return self.next_transition
|
||||||
|
|
||||||
def render(self, canvas):
|
def render(self, canvas):
|
||||||
pygame.draw.rect(canvas, (255, 255, 0), self.rectangle)
|
canvas.fill(self.background_color)
|
||||||
|
pygame.draw.rect(canvas, (255, 255, 0), self.rectangle)
|
||||||
|
5
state.py
5
state.py
@@ -7,6 +7,9 @@ VALID_STATES = { 'INTRO':0, 'MENU':1, 'IN_GAME':2, 'SCORE':3, 'STAY':4, 'QUIT':8
|
|||||||
|
|
||||||
# Parent class for game states.
|
# Parent class for game states.
|
||||||
class BaseState:
|
class BaseState:
|
||||||
|
def __init__(self):
|
||||||
|
self.background_color = (139, 210, 228)
|
||||||
|
|
||||||
def input(self):
|
def input(self):
|
||||||
""" Empty. Should handle PyGame input. """
|
""" Empty. Should handle PyGame input. """
|
||||||
pass
|
pass
|
||||||
@@ -17,7 +20,7 @@ class BaseState:
|
|||||||
|
|
||||||
def render(self, canvas):
|
def render(self, canvas):
|
||||||
""" Empty. Should render this state on the canvas. """
|
""" Empty. Should render this state on the canvas. """
|
||||||
pass
|
canvas.fill(self.background_color)
|
||||||
|
|
||||||
def get_screen_center(self):
|
def get_screen_center(self):
|
||||||
return (pygame.display.Info().current_w / 2,
|
return (pygame.display.Info().current_w / 2,
|
||||||
|
Reference in New Issue
Block a user