Changeset 11:5d58a5b13731


Ignore:
Timestamp:
Aug 30, 2009, 3:11:44 PM (11 years ago)
Author:
Simon Cross <hodgestar@…>
Branch:
default
Convert:
svn:b4e93282-eac8-4b8b-b765-0f5d36de2b68@12
Message:

Extremely rudimentary game engine.

Location:
gamelib
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • gamelib/gameboard.py

    r9 r11  
    11import random
    22
    3 import pygame
    43from pgu import tilevid
    54
    6 import constants
    75import data
    86
  • gamelib/main.py

    r7 r11  
    99import pygame
    1010from pgu import gui
    11 from pygame.locals import SWSURFACE, QUIT, KEYDOWN, K_ESCAPE, USEREVENT
     11from pygame.locals import SWSURFACE
    1212
    1313from mainmenu import MainMenu
     14from engine import Engine, MainMenuState
    1415import constants
    1516
    16 def gameloop(screen, app):
    17     """Main game loop."""
    18     clock = pygame.time.Clock()
    19     done = False
    20     while not done:
    21         for e in pygame.event.get():
    22             if e.type is QUIT:
    23                 done = True
    24             elif e.type is KEYDOWN and e.key == K_ESCAPE:
    25                 done = True
    26             elif e.type is USEREVENT:
    27                 print e.event
    28             else:
    29                 app.event(e)
    30 
    31         # Clear the screen and render the stars
    32         dt = clock.tick()/1000.0
    33         screen.fill((0,0,0))
    34         app.paint(screen)
    35         pygame.display.flip()
    36         pygame.time.wait(10)
    37 
    38 
    39 def main():
    40     """Main script."""
    41     screen = pygame.display.set_mode(constants.SCREEN, SWSURFACE)
    42 
    43     form = gui.Form()
     17def create_menu_app():
     18    """Create the menu app."""
    4419    app = gui.App()
    4520    main_menu = MainMenu()
     
    4924
    5025    app.init(c)
     26    return app
    5127
    52     gameloop(screen, app)
     28def main():
     29    """Main script."""
     30    screen = pygame.display.set_mode(constants.SCREEN, SWSURFACE)
     31    main_menu_app = create_menu_app()
     32    engine = Engine(main_menu_app)
     33    engine.run(MainMenuState(engine), screen)
  • gamelib/mainmenu.py

    r7 r11  
    44import pygame
    55import constants
     6import engine
    67
    78class MainMenu(gui.Table):
     
    1314
    1415        def quit_pressed():
    15             pygame.event.post(pygame.event.Event(pygame.QUIT))
     16            pygame.event.post(engine.QUIT)
    1617
    1718        def start_pressed():
    18             pygame.event.post(pygame.event.Event(pygame.USEREVENT, event="<Our Start Event Class>"))
     19            pygame.event.post(engine.START_DAY)
    1920
    2021        start_button = gui.Button("Start")
Note: See TracChangeset for help on using the changeset viewer.