view gamelib/main.py @ 38:7e18a67995f6

fixed pep8 issues
author Rizmari Versfeld <rizziepit@gmail.com>
date Mon, 07 May 2012 00:13:11 +0200
parents 9c4bf1f15431
children d82d3e54a4ef
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():
    clock = Clock()
    screen = pygame.display.set_mode((800, 600))
    window = Window(screen)
    window.background_colour = (0, 0, 0)
    button1 = BigButton(((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