<commit_before>import pygame
import time
import constants
from gui import Gui
from player import Player
from game_data import GameData
from client import Client

class Game:
  def __init__(self, _players):
    self.players = _players #list of players in the game

  #takes input, returns velocity and a flag that tells whether velocity should be
  #changed
  def get_input(self, x, y):
    for event in pygame.event.get():
      if event.type == pygame.QUIT:
        quit()
      elif event.type == pygame.KEYDOWN:
        #respond to arrow keys and wasd
        if event.key == pygame.K_LEFT or event.key == pygame.K_a:
          new_speed = x - constants.SPEED
          if new_speed < -constants.SPEED:
            x = -constants.SPEED
          else:
            x = new_speed
        elif event.key == pygame.K_UP or event.key == pygame.K_w:
          new_speed = y - constants.SPEED
          if new_speed < -constants.SPEED:
            y = -constants.SPEED
          else:
            y = new_speed
        elif event.key == pygame.K_RIGHT or event.key == pygame.K_d:
          new_speed = x + constants.SPEED
          if new_speed > constants.SPEED:
            x = constants.SPEED
          else:
            x = new_speed
        elif event.key == pygame.K_DOWN or event.key == pygame.K_s:
          new_speed = y + constants.SPEED
          if new_speed > constants.SPEED:
            y = constants.SPEED
          else:
            y = new_speed
      elif event.type == pygame.KEYUP:
        if event.key == pygame.K_LEFT or event.key == pygame.K_a:
          x += constants.SPEED
        elif event.key == pygame.K_UP or event.key == pygame.K_w:
          y += constants.SPEED
        elif event.key == pygame.K_RIGHT or event.key == pygame.K_d:
          x -= constants.SPEED
        elif event.key == pygame.K_DOWN or event.key == pygame.K_s:
          y -= constants.SPEED
    return (x, y)

def main():
  client = Client(constants.HOST, constants.PORT)

  gd = client.get_game_data()
  field = Gui(gd.width, gd.height, 1.0)
  print("About to call client.get_playerS()")
  players = client.get_players()
  print("Done calling client.get_playerS()")
  game = Game(players)

  velocity = (0, 0)
  while True:
    start_time = time.time()

    #get input
    inp = game.get_input(velocity[0], velocity[1])
    velocity = (inp[0], inp[1])

    #talk to server
    client.update_velocity(velocity)    #send my velocity to the server
    game.players = client.get_players() #update the player list

    #draw
    field.fill_black()
    for p in game.players:
      field.draw_player(p.position, p.color, gd.radius, p.it)
    pygame.display.flip()

    sleep_time = constants.LOOP_TIME - (time.time() - start_time)
    if sleep_time > 0:
      time.sleep(sleep_time)

if __name__ == "__main__":
    main()<commit_msg>fixed wasd+arrows input for real this time<commit_after>import pygame
import time
import constants
from gui import Gui
from player import Player
from game_data import GameData
from client import Client

class Game:
  def __init__(self, _players):
    self.players = _players #list of players in the game

  # returns a boolean tuple of 4 directions
  def get_input(self, dirs):
    up, down, left, right = dirs
    for event in pygame.event.get():
      if event.type == pygame.QUIT:
        quit()
      elif event.type == pygame.KEYDOWN:
        #respond to arrow keys and wasd
        if event.key == pygame.K_LEFT or event.key == pygame.K_a:
          left += 1
        elif event.key == pygame.K_UP or event.key == pygame.K_w:
          up += 1
        elif event.key == pygame.K_RIGHT or event.key == pygame.K_d:
          right += 1
        elif event.key == pygame.K_DOWN or event.key == pygame.K_s:
          down += 1
      elif event.type == pygame.KEYUP:
        if event.key == pygame.K_LEFT or event.key == pygame.K_a:
          left -= 1
        elif event.key == pygame.K_UP or event.key == pygame.K_w:
          up -= 1
        elif event.key == pygame.K_RIGHT or event.key == pygame.K_d:
          right -= 1
        elif event.key == pygame.K_DOWN or event.key == pygame.K_s:
          down -= 1
    return (up, down, left, right)
  
  def dirs_to_vel(self, dirs):
    x = 0
    y = 0
    if dirs[0] > 0 and dirs[1] > 0:
      y = 0
    elif dirs[0] > 0:
      y = -constants.SPEED
    elif dirs[1] > 0:
      y = constants.SPEED

    if dirs[2] > 0 and dirs[3] > 0:
      x = 0
    elif dirs[2] > 0:
      x = -constants.SPEED
    elif dirs[3] > 0:
      x = constants.SPEED
    return (x, y)

def main():
  client = Client(constants.HOST, constants.PORT)

  gd = client.get_game_data()
  field = Gui(gd.width, gd.height, 1.0)
  players = client.get_players()
  game = Game(players)

  # up, down, left, right
  dirs = (0, 0, 0, 0)
  while True:
    start_time = time.time()

    #get input
    dirs = game.get_input(dirs)
    velocity = game.dirs_to_vel(dirs)

    #talk to server
    client.update_velocity(velocity)    #send my velocity to the server
    game.players = client.get_players() #update the player list

    #draw
    field.fill_black()
    for p in game.players:
      field.draw_player(p.position, p.color, gd.radius, p.it)
    pygame.display.flip()

    sleep_time = constants.LOOP_TIME - (time.time() - start_time)
    if sleep_time > 0:
      time.sleep(sleep_time)

if __name__ == "__main__":
    main()
{'fraction_non_alphanumeric': 0.10906383770705379, 'fraction_numerical': 0.008375209380234505, 'mean_word_length': 2.247129909365559, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6084069', 'n_tokens_mistral': 1864, 'n_tokens_neox': 1821, 'n_words': 515}