Skip to content

Commit

Permalink
added How To Page (#36)
Browse files Browse the repository at this point in the history
* fixed typo with new link

* added pre init calls for game

* Add executable permissions to setup.py

* added how to screen

* sped up the pizza to trashcan prozess

* added Experience
  • Loading branch information
wilfriedE committed May 13, 2016
1 parent 377aeaa commit ae96046
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 4 deletions.
1 change: 1 addition & 0 deletions game/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def __init__(self):
self.bold_font_path = "game/assets/font/Roboto-Regular.ttf"
self.shop_background = pygame.image.load("game/assets/img/Background.png")
self.counter_top = pygame.image.load("game/assets/img/Countertop.png")
self.help_img = pygame.image.load("game/assets/img/help.png")
self.plain_pizza = pygame.image.load("game/assets/img/blank_pizza.png")
self.button_bg = pygame.image.load("game/assets/img/red_button01.png")
self.button_bg_active = pygame.image.load("game/assets/img/red_button02.png")
Expand Down
Binary file added game/assets/img/help.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion game/objects/pizza.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, context):
update the button drawing surface.
"""
def draw(self):
S = 2 #speed towards trash can
S = 8 #speed towards trash can
A = 9.8 #acceleration towards trash can
if self.trashing:
if self.touches(self.trash_can):
Expand Down
1 change: 1 addition & 0 deletions game/scenes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .base_scene import SceneBase
from .help_scene import HelpScene
from .game_scene import GameScene
from .title_scene import TitleScene
2 changes: 1 addition & 1 deletion game/scenes/game_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def Update(self):

def Render(self):
# The game scene is just a blank blue screen
self.screen.fill((0, 0, 255))
self.screen.fill((244, 101, 36))
self.screen.blit(self.context.shop_background,(0,0))
self.screen.blit(self.characters[self.level% len(self.characters)],(850,255))
self.screen.blit(self.context.counter_top,(0,0))
Expand Down
72 changes: 72 additions & 0 deletions game/scenes/help_scene.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import pygame
from . import SceneBase
from game.objects import Text, Button, STATE

class HelpScene(SceneBase):
def __init__(self, context):
SceneBase.__init__(self, context)
self.buttons = []
self.createGameMenu()

def ProcessInput(self, events, pressed_keys):
for event in events:
if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
# Move to the next scene when the user pressed Enter
pass

if event.type == pygame.MOUSEBUTTONDOWN:
for button in self.buttons:
button.isClicked(event)

if event.type == pygame.MOUSEBUTTONUP:
for button in self.buttons:
button.isClicked(event)

if event.type == pygame.MOUSEMOTION:
for button in self.buttons:
button.isHovered(event)

def Update(self):
pass

def Render(self):
# For the sake of brevity, the title scene is a blank red screen
self.screen.fill((244, 101, 36))
self.screen.blit(self.context.help_img,
( (self.context.width - self.context.help_img.get_width()) // 2,
((self.context.height - self.context.help_img.get_height()) // 2)))
for button in self.buttons:
button.drawOn(self.screen)
#self.screen.blit(self.start_button.draw(),
# ( (self.context.width - self.start_button.width) // 2,
# ((self.context.height - self.start_button.height) + self.title.get_height()) // 2))
#pygame.draw.rect(self.screen, (0, 100, 100), pygame.Rect(100, 100, 200, 200))


def createGameMenu(self):
P, K, Y = 300, 5, 30
currX = P
self.quit_button = Button(self.context, "Quit")
self.quit_button.setPen(self.context.font)
self.quit_button.setColor((255, 255, 255))
self.quit_button.setBackgroundImg(self.context.button_bg, STATE.NORMAL)
self.quit_button.setBackgroundImg(self.context.button_bg_active, STATE.ACTIVE)
self.quit_button.setOnLeftClick(self.handleQuitButtonClick)
self.quit_button.setLocation(P, Y)
currX+= self.quit_button.width
self.home_button = Button(self.context, "Menu/Home")
self.home_button.setPen(self.context.font)
self.home_button.setColor((255, 255, 255))
self.home_button.setBackgroundImg(self.context.button_bg, STATE.NORMAL)
self.home_button.setBackgroundImg(self.context.button_bg_active, STATE.ACTIVE)
self.home_button.setOnLeftClick(self.handleHomeButtonClick)
self.home_button.setLocation(currX + K, Y)
self.buttons += [self.quit_button, self.home_button]
"""
helper methods below this point
"""
def handleQuitButtonClick(self):
self.context.quit()

def handleHomeButtonClick(self):
self.SwitchToScene(self.context.starting_scene, self.context)
33 changes: 31 additions & 2 deletions game/scenes/title_scene.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import pygame
from . import SceneBase, GameScene
from . import SceneBase, GameScene, HelpScene
from game.objects import Text, Button, STATE

class TitleScene(SceneBase):
def __init__(self, context):
SceneBase.__init__(self, context)
self.createTitle()
self.createStartButton()
self.createHowToButton()
self.createScoreText()

def ProcessInput(self, events, pressed_keys):
for event in events:
Expand All @@ -16,12 +18,15 @@ def ProcessInput(self, events, pressed_keys):

if event.type == pygame.MOUSEBUTTONDOWN:
self.start_button.isClicked(event)
self.help_button.isClicked(event)

if event.type == pygame.MOUSEBUTTONUP:
self.start_button.isClicked(event)
self.help_button.isClicked(event)

if event.type == pygame.MOUSEMOTION:
self.start_button.isHovered(event)
self.help_button.isHovered(event)

def Update(self):
pass
Expand All @@ -31,14 +36,17 @@ def Render(self):
self.screen.fill((255, 255, 255))
self.title.drawOn(self.screen)
self.start_button.drawOn(self.screen)
self.help_button.drawOn(self.screen)
self.score_msg.drawOn(self.screen)
#self.screen.blit(self.start_button.draw(),
# ( (self.context.width - self.start_button.width) // 2,
# ((self.context.height - self.start_button.height) + self.title.get_height()) // 2))
#pygame.draw.rect(self.screen, (0, 100, 100), pygame.Rect(100, 100, 200, 200))

def createTitle(self):
self.title = Text(self.context, self.context.title)
self.title.setPen(self.context.font_large)
self.title.setColor((244, 101, 36))
self.title.setPen(self.context.bold_font_large)
self.title.setLocation( (self.context.width - self.title.width) // 2,
(self.context.height - self.title.height) // 2)

Expand All @@ -52,6 +60,24 @@ def createStartButton(self):
self.start_button.setBackgroundImg(self.context.button_bg_active, STATE.ACTIVE)
self.start_button.setLocation((self.context.width - self.start_button.width) // 2,
((self.context.height - self.start_button.height) // 2) + self.title.height )

def createHowToButton(self):
self.help_button = Button(self.context, "How To Play")
self.help_button.setPen(self.context.font_small)
self.help_button.setPen(self.context.font, STATE.HOVER)
self.help_button.setOnLeftClick(self.handleHelpButtonClick)
self.help_button.setBackgroundImg(self.context.button_bg, STATE.NORMAL)
self.help_button.setBackgroundImg(self.context.button_bg_active, STATE.ACTIVE)
self.help_button.setLocation((self.context.width - self.help_button.width) // 2,
((self.context.height - self.help_button.height) // 2) + self.title.height + self.start_button.height + 5 )

def createScoreText(self):
self.score_msg = Text(self.context, "Experience: {} Pizzas".format(self.context.total_good_pizza))
self.score_msg.setPen(self.context.bold_font)
self.score_msg.setColor((244, 101, 36))
self.score_msg.setLocation((self.context.width - self.score_msg.width) // 2,
((self.context.height - self.score_msg.height) // 2) + self.title.height + self.start_button.height + self.help_button.height + 10)

"""
helper methods below this point
"""
Expand All @@ -60,3 +86,6 @@ def handleStartButtonHover(self):

def handleStartButtonClick(self):
self.SwitchToScene(GameScene)

def handleHelpButtonClick(self):
self.SwitchToScene(HelpScene)

0 comments on commit ae96046

Please sign in to comment.