view 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 source

'''Game main module.

Contains the entry point used by the run_game.py script.

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

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 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