Permalink
Browse files

Separated out the utility functions and made all paths OS independent

  • Loading branch information...
1 parent c5441e6 commit 31bfd185d66bda4ec9f921134f9a0ae9f4b5e980 Mateusz Kowalczyk committed Oct 5, 2012
Showing with 42 additions and 20 deletions.
  1. +1 −1 char.py
  2. +8 −2 credit.py
  3. +2 −2 game.py
  4. +1 −7 main.py
  5. +9 −6 menu.py
  6. +9 −2 screen.py
  7. +12 −0 utility.py
View
@@ -4,7 +4,7 @@
import button
import config
import text
-from main import load_join_i
+from utility import load_join_i
# Non-divided sprite_sheet
SPRITE_SHEET_MERGED = load_join_i(["resources", "art", "sprite_sheet.png"])
View
@@ -4,10 +4,11 @@
import messenger
import config
import text
+from utility import load_join_i
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"])
class CreditScreen(screen.AbstractScreen):
def __init__(self):
@@ -17,11 +18,13 @@ def __init__(self):
self.background = IMAGES["background"]
self.make_buttons()
self.make_labels()
+
def on_draw(self):
self.background.blit(0, 0)
self.menu_button.draw()
self.score_label.draw()
self.score_comment.draw()
+
def make_score_comment(self):
score = messenger.Messenger.gameScreen.score
if score == 0:
@@ -71,8 +74,10 @@ def make_score_comment(self):
color = self.color,
x = 25,
y = config.SCREEN_HEIGHT - 50)
+
def on_mouse_press(self, x, y, button, modifiers):
self.menu_button.click(x, y)
+
def make_labels(self):
self.score_label = pyglet.text.Label(text = "Final Score: %d" % 0,
font_name = config.FONT_TYPE,
@@ -87,6 +92,7 @@ def make_labels(self):
color = self.color,
x = config.SCREEN_WIDTH / 4,
y = config.SCREEN_HEIGHT / 4 * 2)
+
def make_buttons(self):
self.menu_button = button.Button(image = IMAGES["menu_button"],
x = config.SCREEN_WIDTH / 4,
View
@@ -3,7 +3,7 @@
import messenger
import random
import screen
-from main import list_pj, load_join_m, load_join_i
+from utility import list_pj, load_join_m, load_join_i
from pyglet.gl import * #Neccesary to prevent linear scaling
#Non-divided sprite_sheet
@@ -190,7 +190,7 @@ def collide(self, other):
class Interpolate(object):
"""Adds methods for tweening."""
def interpolate(self, number, steps, form):
- "Allows for various forms of interpolation."
+ """Allows for various forms of interpolation."""
if form == "step":
return [number / steps for i in range(steps)]
elif form == "accelerate":
View
@@ -9,13 +9,7 @@
import char
import random
import os.path
-
-# Joins a list of paths into a single path (OS independent)
-list_pj = lambda l: reduce(os.path.join, l)
-
-# Composition of join and load
-load_join_i = lambda l: pyglet.image.load(reduce(os.path.join(l)))
-load_join_m = lambda l: pyglet.media.load(reduce(os.path.join(l)))
+from utility import *
def resourceInit():
try: #This will install avbin if needed, and it works on windows and linux!
View
15 menu.py
@@ -3,14 +3,17 @@
import button
import config
import messenger
-from main import load_join_i, list_pj
+from utility import load_join_i
+
+import os.path
+load_join_i = lambda l: pyglet.image.load(reduce(os.path.join, l))
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"]])))
+ 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):
@@ -25,7 +28,7 @@ def on_draw(self):
self.quit_button.draw()
def make_buttons(self):
- messenger.Messenger = msngr
+ msngr = messenger.Messenger
self.start_button = button.Button(image = IMAGES["start_button"],
x = config.SCREEN_WIDTH / 2,
y = config.SCREEN_HEIGHT / 2)
View
@@ -1,16 +1,23 @@
class AbstractScreen(object):
- "An abstract class for values in the 'Game' 'mode_hash' member."
+ """An abstract class for values in the 'Game' 'mode_hash' member."""
def on_draw(self):
- pass
+ pass
+
def on_key_press(self, symbol, modifiers):
pass
+
def on_key_release(self, symbol, modifiers):
pass
+
def on_mouse_motion(self, x, y, dx, dy):
pass
+
def on_mouse_press(self, x, y, button, modifiers):
pass
+
def on_mouse_release(self, x, y, button, modifiers):
pass
+
def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
pass
+
View
@@ -0,0 +1,12 @@
+"""Utility function in separate file to prevent cicular imports."""
+import pyglet
+import os.path
+
+# Joins a list of paths into a single path (OS independent)
+list_pj = lambda l: reduce(os.path.join, l)
+
+# Composition of join and load
+load_join_i = lambda l: pyglet.image.load(reduce(os.path.join, l))
+load_join_m = lambda l: pyglet.media.load(reduce(os.path.join, l))
+
+

0 comments on commit 31bfd18

Please sign in to comment.