История изменений
Исправление x0r, (текущая версия) :
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
sys.exit(0)
if event.key == K_LEFT:
key_states[0] = True
if event.key == K_RIGHT:
key_states[1] = True
if event.key == K_UP:
key_states[2] = True
if event.key == K_DOWN:
key_states[3] = True
if event.type == KEYUP:
if event.key == K_LEFT:
key_states[0] = False
if event.key == K_RIGHT:
key_states[1] = False
if event.key == K_UP:
key_states[2] = False
if event.key == K_DOWN:
key_states[3] = False
ну семен семенович...
keys = [K_LEFT, K_RIGHT, K_UP, K_DOWN]
to_index = {keys[i]: i for i in range(len(keys))}
if event.type in [KEYDOWN, KEYUP]:
key_states[to_index[event.key]] = (event.type == KEYDOWN)
хотя не понятно, зачем мапить на 0..3, можно использовать прямо константы K_LEFT т.д.
if event.type in [KEYDOWN, KEYUP]:
key_states[event.key] = (event.type == KEYDOWN)
if key_states[K_LEFT]:
print('yes')
Исправление x0r, :
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
sys.exit(0)
if event.key == K_LEFT:
key_states[0] = True
if event.key == K_RIGHT:
key_states[1] = True
if event.key == K_UP:
key_states[2] = True
if event.key == K_DOWN:
key_states[3] = True
if event.type == KEYUP:
if event.key == K_LEFT:
key_states[0] = False
if event.key == K_RIGHT:
key_states[1] = False
if event.key == K_UP:
key_states[2] = False
if event.key == K_DOWN:
key_states[3] = False
ну семен семенович...
keys = [K_LEFT, K_RIGHT, K_UP, K_DOWN]
to_index = {keys[i]: i for i in range(len(keys))}
if event.type in [KEYDOWN, KEYUP]:
key_states[to_index[event.key]] = (event.type == KEYDOWN)
хотя не понятно, зачем мапить на 0..3б можно использовать прямо константы K_LEFT т.д.
if event.type in [KEYDOWN, KEYUP]:
key_states[event.key] = (event.type == KEYDOWN)
if key_states[K_LEFT]:
print('yes')
Исправление x0r, :
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
sys.exit(0)
if event.key == K_LEFT:
key_states[0] = True
if event.key == K_RIGHT:
key_states[1] = True
if event.key == K_UP:
key_states[2] = True
if event.key == K_DOWN:
key_states[3] = True
if event.type == KEYUP:
if event.key == K_LEFT:
key_states[0] = False
if event.key == K_RIGHT:
key_states[1] = False
if event.key == K_UP:
key_states[2] = False
if event.key == K_DOWN:
key_states[3] = False
ну семен семенович...
keys = [K_LEFT, K_RIGHT, K_UP, K_DOWN]
to_index = {keys[i]: i for i in range(len(keys))}
if event.type in [KEYDOWN, KEYUP]:
key_states[to_index[event.key]] = (event.type == KEYDOWN)
Исправление x0r, :
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
sys.exit(0)
if event.key == K_LEFT:
key_states[0] = True
if event.key == K_RIGHT:
key_states[1] = True
if event.key == K_UP:
key_states[2] = True
if event.key == K_DOWN:
key_states[3] = True
if event.type == KEYUP:
if event.key == K_LEFT:
key_states[0] = False
if event.key == K_RIGHT:
key_states[1] = False
if event.key == K_UP:
key_states[2] = False
if event.key == K_DOWN:
key_states[3] = False
ну семен семенович...
keys = [K_LEFT, K_RIGHT, K_UP, K_DOWN]
to_index = {keys[i]: i for i in range(len(keys))}
if event.type in [KEYDOWN, KEYUP]:
key_states[to_index[event.key]] = (event.type == KEYDOWN)]
Исходная версия x0r, :
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
sys.exit(0)
if event.key == K_LEFT:
key_states[0] = True
if event.key == K_RIGHT:
key_states[1] = True
if event.key == K_UP:
key_states[2] = True
if event.key == K_DOWN:
key_states[3] = True
if event.type == KEYUP:
if event.key == K_LEFT:
key_states[0] = False
if event.key == K_RIGHT:
key_states[1] = False
if event.key == K_UP:
key_states[2] = False
if event.key == K_DOWN:
key_states[3] = False
ну семен семенович...
keys = [K_LEFT, K_RIGHT, K_UP, K_DOWN]
to_index = {keys[i]: i for i in range(len(keys))}
to_status = {KEYDOWN: True, KEYUP: False}
if event.type in [KEYDOWN, KEYUP]:
key_states[to_index[event.key]] = to_status[event.type]