Пример #1
0
    def run(self):
        player = Player()
        Shared.groups['player'].add(player)
        while True:
            self.clock.tick(60)

            keys = key.get_pressed()
            if keys[K_DOWN]:
                self.camera['y'] -= 1
            
            event_handler(Shared.groups)
            
            render(self.screen, Shared.groups, self.camera)
Пример #2
0
def get_user_input(grid):
    while True:
        render(grid)
        print("   ENTER ROW AND COLUMN")
        choice = input("   > ").split()
        try:
            row, col = map(int, choice)
            if row < 0 or row > size:
                continue
            if col < 0 or col > size:
                continue
            if grid[row][col] != 0:
                continue
            return row, col
        except:
            continue
Пример #3
0
async def display(processor, dashboard_queues):
    while True:
        dashboard = render(processor.nodes, processor.gateway)

        for queue in dashboard_queues:
            queue.put_nowait(dashboard)

        await asyncio.sleep(1.0)
Пример #4
0
def game_loop(grid):
    while True:
        # player turn
        row, col = get_user_input(grid)
        move(grid, row, col, -1)
        render(grid)
        # check if the player wins
        if win_player(grid, -1):
            print("   YOU WIN!")
            break
        # check if it's a tie
        if terminal(grid):
            print("   TIE!")
            break
        # computer turn
        row, col = best_move(grid)
        move(grid, row, col, 1)
        render(grid)
        # check if machine wins
        if win_player(grid, 1):
            print("   YOU LOSE!")
            break
Пример #5
0
def game_loop(fps):
    '''
    Game loops here indefinitely
    '''
    global CLOCK
    global GAME_OVER
    global LEVEL
    global WON

    logger.debug("Start game loop")

    while True:
        # Handle any and all events
        event_handler.handle_events()

        # Is there a reason to quit the game?
        if not GAME_OVER:
            # Update the game state
            update()

            # Render the game state to the screen
            objects_to_remove, exist_enemies = display.render(LEVEL)

            # Remove the items from the game that are dead
            for layer in objects_to_remove:
                for id in objects_to_remove[layer]:
                    index = 0
                    for game_object in LEVEL["OBJECTS"][layer]:
                        if id == game_object.id:
                            LEVEL["OBJECTS"][layer].pop(index)
                            break
                        index += 1

            # If there are no more enemies, the level has been beaten
            if not exist_enemies:
                event_handler.remove_all()
                LEVEL["OBJECTS"] = []
                LEVEL["LOADED"]  = False
        else:
            display.game_over(WON)

        # We only want the game to go as fast as fps
        CLOCK.tick(fps)
Пример #6
0
def splash_screen(cfg):
    bg = display.open(cfg["splash_screen"])
    display.render(bg)
    sleep(5)
    display.render(f)
Пример #7
0
    timers = [0] * 5

    # ---- WELCOME SCREEN ---- #
    print("Welcome")
    if cfg["splash_screen"]:
        splash_screen(cfg)

    welcome_image = welcome(cfg)
    t0 = time()
    while time() < t0 + 5:
        t = time()
        if t - timers[4] >= 1.0 / cfg["scroll_speed"]:
            timers[4] = t
            welcome_image = display.cycle(welcome_image)
            image = display.add(display.blank(), welcome_image, dy=3)
            display.render(image)
    display.clear()

    # ---- CAVA PROCESS AND FRAMES ---- #
    cava_frame = display.blank()
    c = display.blank()
    blank = display.blank()
    cava_ps = cava.start()
    print(cava_ps)

    while True:
        t = time()
        f_last = f
        c_last = c

        # ---- CAVA ---- #
Пример #8
0
import map

WIDTH = 384
HEIGHT = 384

# Event handlers
def quit(e):
    """Event hander for quit events"""
    # Any shutdown code should go here
    sys.exit()


pygame.display.init()

display.init(WIDTH, HEIGHT)
display.register(map.sample_map())
display.register(objects.sample_statue())

minotaur = objects.sample_minotaur()
display.register(minotaur)

ehandler.register("quit", quit)

while True:
    minotaur.update()
    display.render()
    ehandler.run()


pygame.quit()
Пример #9
0
def game_loop():
    while not world.done:
        display.check_input()
        display.render()
Пример #10
0
states = {
  'quit': s_Quit,
  'menu': s_Menu,
  'generate': s_WorldGen,
  'play': s_Play,
  'death': s_Death
}


for (name, s) in states.items():
  s.registerStates(states)

'''
Main

'''
currentState = s_WorldGen
while not libtcod.console_is_window_closed() :
  
  disp.render(currentState)
  currentState.inputHandler.handleInput()
  currentState.tick()
  newState = currentState.nextState
  
  if newState != currentState:
    currentState.reset()
    currentState = newState
    currentState.beforeTransition()
    disp.clear()
  
Пример #11
0
   #sample the input
   result = ui.update();
   if result:
      command = result[0];
      # if this is a rotation...
      if (command < 18):
         rot = command / 2;
         reverse = command % 2;
         print "queuing rotation";
         #grooviksCube.QueueRotation( rot, reverse );
         iPixel += 1;
         if (iPixel == 54):
            iPixel = 0;
         
   #handle any display management 
   display.loop();
      
   #throttle the frame-rate
   if (time.time() - lasttime > .2):
      cFrames = cFrames + 1;
      # run the simmulation
      grooviksCube.Update( time.clock() )  
      colors = grooviksCube.GetColors();
      for i in range(54):
         display.setPixel(i, lightboard.Pixel(int(colors[i][0] * 255), int(colors[i][1] * 255), int(colors[i][2] * 255)));
      
      display.setPixel(iPixel, lightboard.Pixel( 255, 0, 255 ));
      
      lasttime = time.time();
      display.render();