Example #1
0
 def display(self):
     self.screen.fill((0, 0, 64))  # dark blue
     [draw_rect(self.screen, (0, 191, 255), b) for b in model.borders]  # deep sky blue 
     [draw_rect(self.screen, (255, 192, 203), p) for p in model.pellets]  # shrimp
     for name, p in model.players.items():
         if name != model.myname:
             draw_rect(self.screen, (255, 0, 0), p)  # red
     if model.myname:
         draw_rect(self.screen, (0, 191, 255), model.players[model.myname])  # deep sky blue
        
     update_pygame_display()
        
     self.clock.tick(50)  # frames per second, independent of server frame rate
Example #2
0
while 1:
    
    poll()  # push and pull network messages

    # send valid inputs to the server
    for event in get_pygame_events():  
        if event.type == QUIT:
            exit()
        if event.type == KEYDOWN:
            key = event.key
            if key == K_ESCAPE:
                exit()
            elif key in valid_inputs:
                msg = {'input': valid_inputs[key]}
                client.do_send(msg)
    
    # draw everything
    screen.fill((0, 0, 64))  # dark blue
    [draw_rect(screen, (0, 191, 255), b) for b in borders]  # deep sky blue 
    [draw_rect(screen, (255, 192, 203), p) for p in pellets]  # shrimp
    for name, p in players.items():
        if name != myname:
            draw_rect(screen, (255, 0, 0), p)  # red
    if myname:
        draw_rect(screen, (0, 191, 255), players[myname])  # deep sky blue
    
    update_pygame_display()
    
    clock.tick(50)  # frames per second, independent of server frame rate
Example #3
0
            if key == K_ESCAPE:
                exit()
            elif key in valid_inputs:
                if key == K_UP:
                    dx, dy = 0, -1
                elif key == K_DOWN:
                    dx, dy = 0, 1
                elif key == K_LEFT:
                    dx, dy = -1, 0
                elif key == K_RIGHT:
                    dx, dy = 1, 0
                msg = {'input': valid_inputs[key]}
                client.do_send(msg)

    # draw everything
    screen.fill((0, 0, 64))  # dark blue
    [draw_rect(screen, (0, 191, 255), b) for b in borders]  # deep sky blue
    [draw_rect(screen, (255, 192, 203), p) for p in pellets]  # shrimp
    for name, p in players.items():
        if name != myname:
            draw_rect(screen, (255, 0, 0), p)  # red
    if myname and myname in players.keys():
        if counter % 2 == 0:
            players[myname].move_ip(dx, dy)  # update position
        draw_rect(screen, (0, 191, 255), players[myname])  # deep sky blue

    update_pygame_display()

    counter += 1
    clock.tick(50)  # frames per second, independent of server frame rate