Skip to content
Browse files

Syntax improvement

  • Loading branch information...
1 parent 0ce4697 commit b167be143d232bbcd17ee36b223ae3ea4b58966e Mateusz Kowalczyk committed Oct 5, 2012
Showing with 33 additions and 20 deletions.
  1. +1 −4 button.py
  2. +8 −4 char.py
  3. +2 −1 config.py
  4. +14 −8 menu.py
  5. +8 −3 messenger.py
View
5 button.py
@@ -1,10 +1,7 @@
import pyglet
-import config
-
-IMAGES = {}
class Button(pyglet.sprite.Sprite):
- "A sprite that reacts when clicked."
+ """A sprite that reacts when clicked."""
def __init__(self, image, x, y, text = None):
super(Button, self).__init__(image)
#The following text part needs work.
View
12 char.py
@@ -4,13 +4,17 @@
import button
import config
import text
+from main import load_join_i
-SPRITE_SHEET_MERGED = pyglet.image.load(r"resources/art/sprite_sheet.png") #Non-divided sprite_sheet
-SPRITE_SHEET_DIVIDED = pyglet.image.ImageGrid(SPRITE_SHEET_MERGED, 8, 8) #Divided sprite_sheet
+# Non-divided sprite_sheet
+SPRITE_SHEET_MERGED = load_join_i(["resources", "art", "sprite_sheet.png"])
+
+# Divided sprite_sheet
+SPRITE_SHEET_DIVIDED = pyglet.image.ImageGrid(SPRITE_SHEET_MERGED, 8, 8)
IMAGES = {}
-IMAGES["background"] = pyglet.image.load(r"resources/art/background1.png")
-IMAGES["menu_button"] = pyglet.image.load(r"resources/art/menu_button.png")
+IMAGES["background"] = load_join_i(["resources", "art", "background1.png"])
+IMAGES["menu_button"] = load_join_i(["resources", "art", "menu_button.png"])
IMAGES["tiber"] = SPRITE_SHEET_DIVIDED[63]
IMAGES["gwen"] = SPRITE_SHEET_DIVIDED[62]
View
3 config.py
@@ -1,4 +1,5 @@
-"A file for storing configuration text. It's easier than parsing a text file."
+"""A file for storing configuration text.
+It's easier than parsing a text file."""
FONT_TYPE = "Arial"
SCREEN_WIDTH = 800
View
22 menu.py
@@ -3,43 +3,49 @@
import button
import config
import messenger
+from main import load_join_i, list_pj
-IMAGES = {}
-IMAGES["title_screen"] = pyglet.image.load(r"resources/art/title_screen.png")
-IMAGES["start_button"] = pyglet.image.load(r"resources/art/start_button.png")
-IMAGES["quit_button"] = pyglet.image.load(r"resources/art/quit_button.png")
-IMAGES["char_button"] = pyglet.image.load(r"resources/art/char_button.png")
+IMAGES = dict(zip(["title_screen", "start_button",
+ "quit_button", "char_button"],
+ map(load_join_i, [["resources", "art", "title_screen.png",
+ "resources", "art", "start_button.png",
+ "resources", "art", "quit_button.png",
+ "resources", "art", "char_button.png"]])))
class MenuScreen(screen.AbstractScreen):
def __init__(self):
self.color = (0, 0, 0, 255)
self.make_buttons()
self.background = IMAGES["title_screen"]
+
def on_draw(self):
self.background.blit(0,0)
self.start_button.draw()
self.char_button.draw()
self.quit_button.draw()
+
def make_buttons(self):
+ messenger.Messenger = msngr
self.start_button = button.Button(image = IMAGES["start_button"],
x = config.SCREEN_WIDTH / 2,
y = config.SCREEN_HEIGHT / 2)
self.start_button.x -= self.start_button.width / 2
self.start_button.y -= self.start_button.height / 2
- self.start_button.command = lambda : messenger.Messenger.change_mode("GameScreen")
+ self.start_button.command = lambda : msngr.change_mode("GameScreen")
self.char_button = button.Button(image = IMAGES["char_button"],
x = config.SCREEN_WIDTH / 2,
y = config.SCREEN_HEIGHT / 2)
self.char_button.x -= self.char_button.width / 2
self.char_button.y -= self.char_button.height * 2
- self.char_button.command = lambda : messenger.Messenger.change_mode("CharScreen")
+ self.char_button.command = lambda : msngr.change_mode("CharScreen")
self.quit_button = button.Button(image = IMAGES["quit_button"],
x = config.SCREEN_WIDTH / 2,
y = config.SCREEN_HEIGHT / 2)
self.quit_button.x -= self.quit_button.width / 2
self.quit_button.y -= self.quit_button.height * 3.5
- self.quit_button.command = lambda : messenger.Messenger.quit()
+ self.quit_button.command = lambda : msngr.quit()
+
def on_mouse_press(self, x, y, button, modifiers):
self.start_button.click(x, y)
self.char_button.click(x, y)
View
11 messenger.py
@@ -1,24 +1,29 @@
import game
class Messenger(object):
- "Used to allow objects to communicate with each other."
+ """Used to allow objects to communicate with each other."""
game = None
gameScreen = None
menuScreen = None
creditScreen = None
score = None
+
@staticmethod
def change_mode(new_mode):
- "Changes game mode, makes me wish we had symbols in Python."
+ """Changes game mode, makes me wish we had symbols in Python."""
if new_mode == "CreditScreen":
- Messenger.creditScreen.score_label.text = "Final Score: %d" % Messenger.gameScreen.score
+ score = "Final Score: %d" % Messenger.gameScreen.score
+ Messenger.creditScreen.score_label.text = score
Messenger.creditScreen.make_score_comment()
+
if Messenger.game.mode == Messenger.game.mode_hash["GameScreen"]:
Messenger.game.mode.end_updates()
Messenger.game.mode_hash["GameScreen"] = game.GameScreen()
+
Messenger.game.mode = Messenger.game.mode_hash[new_mode]
if new_mode == "GameScreen":
Messenger.game.mode.start_updates()
+
@staticmethod
def quit():
Messenger.game.on_close()

0 comments on commit b167be1

Please sign in to comment.
Something went wrong with that request. Please try again.