diff gamelib/main.py @ 37:9c4bf1f15431

gui stuff
author Rizmari Versfeld <rizziepit@gmail.com>
date Sun, 06 May 2012 22:05:40 +0200
parents c90a6586cd66
children 7e18a67995f6
line wrap: on
line diff
--- a/gamelib/main.py	Sun May 06 21:56:21 2012 +0200
+++ b/gamelib/main.py	Sun May 06 22:05:40 2012 +0200
@@ -5,10 +5,66 @@
 Feel free to put all your game code here, or in other modules in this "gamelib"
 package.
 '''
+import pygame
+from pygame.locals import *
+from pygame.event import *
+from pygame.time import Clock
+from pygame import Surface
 
-import data
+from gamelib import data
+
+from gamelib.gui_base import *
+from gamelib.gui import *
 
 
+pygame.init()
+
+FPS = 30
+
+GAME_IS_RUNNING = True
+
+WINDOW_STACK = []
+
+# input variables
+MOUSE_DOWN = False
+  
+  
 def main():
-    print "Hello from your game's main()"
-    print data.load('sample.txt').read()
+  #print data.load('sample.txt').read()
+  clock = Clock()
+  screen = pygame.display.set_mode((800, 600))
+  window = Window(screen)
+  window.background_colour = (0,0,0)
+  button1 = MainMenuButton(((800-128)/2, 200), 'Start')
+  window.add_child(button1)
+  WINDOW_STACK.append(window)
+  while GAME_IS_RUNNING:
+    process_input()
+    draw(screen)
+    clock.tick(FPS)    
+
+    
+def draw(screen):
+  for view in WINDOW_STACK:
+    view.draw(screen)
+  pygame.display.flip()
+   
+   
+def process_input():
+  global MOUSE_DOWN
+  global GAME_IS_RUNNING
+  for event in pygame.event.get():
+    if MOUSE_DOWN:
+      if event.type == MOUSEBUTTONUP:
+	MOUSE_DOWN = False
+	WINDOW_STACK[len(WINDOW_STACK)-1].on_mouse_up(event.pos)
+      elif event.type == MOUSEMOTION:
+	WINDOW_STACK[len(WINDOW_STACK)-1].on_mouse_move(event.pos)
+    elif not MOUSE_DOWN and event.type == MOUSEBUTTONDOWN:
+      MOUSE_DOWN = True
+      WINDOW_STACK[len(WINDOW_STACK)-1].on_mouse_down(event.pos)
+    elif event.type == QUIT:
+      GAME_IS_RUNNING = False
+      
+    
+    
\ No newline at end of file