class Game(object):
    def __init__(self):
        self.clock = pygame.time.Clock()
        self.world = World()
        self.world.setup(4, 3, 64)
        self.player = Player()
        self.world.addPlayer(self.player)
        area = AreaTest(64, 64)
        area2 = AreaTest2(64, 64)
        area3 = AreaTest3(64, 64)
        self.world.addArea(area)
        self.world.addArea(area2)
        self.world.addArea(area3)
        self.world.loadStartArea(area)
        self.keyPressed = None
        
    def controls(self):
        self.keyPressed = pygame.key.get_pressed()
        for event in pygame.event.get():
            if event.type == QUIT:
                self.quitGame()
            elif event.type == KEYDOWN:
                if event.key == K_SPACE: #Action key
                    d = self.player.facingDirection
                    if not self.player.direction:
                        #return node that the player is facing towards
                        print self.player.mover.getNeighborNode(d)

    def readObjectText(self):
        pass
    
    def pause(self):
        pass
    
    def quitGame(self):
        '''Quit the game'''
        exit()
        
    def gameLoop(self):
        while True:
            dt = self.clock.tick(30) / 1000.0
            self.controls()
            self.world.update(dt, self.keyPressed)
            self.world.render()
            pygame.display.update()
Exemple #2
0
from areas import *

clock = pygame.time.Clock()

world = World()
world.setup(4, 3, 64)
player = Entity()
#player.setMoverMinDistance(world.tileSize)
world.addPlayer(player)

area = AreaTest(64, 64)
#area.divideIntoSubAreas(*world.screenSize)
area2 = AreaTest2(64, 64)
#area2.divideIntoSubAreas(*world.screenSize)
area3 = AreaTest3(64, 64)
world.addArea(area)
world.addArea(area2)
world.addArea(area3)
#for val in area.subAreas.keys():
#    print area.subAreas[val].entityOffset
#world.loadNewArea(area)

world.loadStartArea(area, 1)

while True:
    world.handleEvents()
    dt = clock.tick(30) / 1000.0
    world.update(dt)
    world.render()
    pygame.display.update()