diff --git a/UWP/EmbeddedPygame/Assets/Pygame/aliens.py b/UWP/EmbeddedPygame/Assets/Pygame/aliens.py index 3ad7216..6defbc6 100644 --- a/UWP/EmbeddedPygame/Assets/Pygame/aliens.py +++ b/UWP/EmbeddedPygame/Assets/Pygame/aliens.py @@ -252,6 +252,17 @@ def main(winstyle=0): bestdepth = pg.display.mode_ok(SCREENRECT.size, winstyle, 32) screen = pg.display.set_mode(SCREENRECT.size, winstyle, bestdepth) + # joystick setup + pg.joystick.init() + + try: + j = pg.joystick.Joystick(0) # create a joystick instance + j.init() # init instance + print ("Enabled joystick: {0}".format(j.get_name())) + except pg.error: + print ("no joystick found.") + pass + # Load images, assign to sprite classes # (do this before the classes are used, after screen setup) img = load_image("player1.gif") @@ -314,6 +325,10 @@ def main(winstyle=0): # Run our main loop whilst the player is alive. while player.alive(): + joystick_input = False + joystick_direction = 0 + joystick_button = False + # get input for event in pg.event.get(): if event.type == pg.QUIT: @@ -338,6 +353,18 @@ def main(winstyle=0): screen.blit(screen_backup, (0, 0)) pg.display.flip() fullscreen = not fullscreen + elif event.type == pg.JOYAXISMOTION: # Joystick + if j.get_axis(0) >= 0.5: + joystick_input = True + joystick_direction = 1 + if j.get_axis(0) <= -1: + joystick_input = True + joystick_direction = -1 + + elif event.type == pg.JOYBUTTONDOWN: + joystick_input = True + joystick_button = True + keystate = pg.key.get_pressed() @@ -347,10 +374,18 @@ def main(winstyle=0): # update all the sprites all.update() - # handle player input direction = keystate[pg.K_RIGHT] - keystate[pg.K_LEFT] + # handle player input + if joystick_input: + direction = joystick_direction + player.move(direction) + firing = keystate[pg.K_SPACE] + + if joystick_input: + firing = joystick_button + if not player.reloading and firing and len(shots) < MAX_SHOTS: Shot(player.gunpos()) if pg.mixer: diff --git a/UWP/Libraries/Pygame/Extensions/sdl2/sdl2.vcxproj b/UWP/Libraries/Pygame/Extensions/sdl2/sdl2.vcxproj index 2c94241..a9ec4fc 100644 --- a/UWP/Libraries/Pygame/Extensions/sdl2/sdl2.vcxproj +++ b/UWP/Libraries/Pygame/Extensions/sdl2/sdl2.vcxproj @@ -45,7 +45,7 @@ 10.0.18362.0 10.0.17763.0 10.0 - _sdl2 + __sdl2 diff --git a/UWP/python34app/PyShell.xaml.cpp b/UWP/python34app/PyShell.xaml.cpp index f37a880..6fce5e9 100644 --- a/UWP/python34app/PyShell.xaml.cpp +++ b/UWP/python34app/PyShell.xaml.cpp @@ -224,7 +224,7 @@ void PyShell::StartInterpreter() last_was_stderr = false; Py_Initialize(); - PyEval_InitThreads(); + //PyEval_InitThreads(); /* boot interactive shell */ metrosetup = PyImport_ImportModule("metrosetup"); @@ -232,12 +232,12 @@ void PyShell::StartInterpreter() PyErr_Print(); } - PyEval_ReleaseThread(PyThreadState_Get()); + //PyEval_ReleaseThread(PyThreadState_Get()); } void PyShell::StopInterpreter() { - PyGILState_STATE s = PyGILState_Ensure(); + //PyGILState_STATE s = PyGILState_Ensure(); Py_Finalize(); this->textBlock1->Blocks->Clear(); } @@ -303,7 +303,7 @@ void PyShell::disable_input() PyObject* PyShell::try_compile() { - PyGILState_STATE s = PyGILState_Ensure(); + //PyGILState_STATE s = PyGILState_Ensure(); PyObject *code = PyObject_CallMethod(metrosetup, "compile", "u", command->Data()); if (code == NULL) { PyErr_Print(); @@ -317,13 +317,13 @@ PyObject* PyShell::try_compile() } else _prompt = 0; - PyGILState_Release(s); + //PyGILState_Release(s); return code; } void PyShell::run_code() { - PyGILState_STATE s = PyGILState_Ensure(); + //PyGILState_STATE s = PyGILState_Ensure(); PyObject *result = PyObject_CallMethod(metrosetup, "eval", "O", current_code); if (result == NULL) { PyErr_Print(); @@ -334,7 +334,7 @@ void PyShell::run_code() Py_CLEAR(current_code); _prompt = 1; command = ""; - PyGILState_Release(s); + //PyGILState_Release(s); if (exited) { //Window::Current->Close(); StopInterpreter(); @@ -448,9 +448,9 @@ void python34app::PyShell::do_restart(Platform::Object^ sender, Windows::UI::Xam void PyShell::run_simple_string() { - PyGILState_STATE s = PyGILState_Ensure(); + //PyGILState_STATE s = PyGILState_Ensure(); PyRun_SimpleString((char*)simple_string->Data); - PyGILState_Release(s); + //PyGILState_Release(s); } void python34app::PyShell::run_file(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) diff --git a/UWP/python34app/python34app.zip b/UWP/python34app/python34app.zip index dbb01bf..e65a1fe 100644 Binary files a/UWP/python34app/python34app.zip and b/UWP/python34app/python34app.zip differ diff --git a/UWP/python34app/python34app/pygame/_sdl2/__init__.py b/UWP/python34app/python34app/pygame/_sdl2/__init__.py index f3d71dd..b8ffe11 100644 --- a/UWP/python34app/python34app/pygame/_sdl2/__init__.py +++ b/UWP/python34app/python34app/pygame/_sdl2/__init__.py @@ -7,7 +7,7 @@ def unbulk_dyn_load_package_name(module_name, package_name, extension_name): sys.modules[module_name] = foo return foo -sdl2 = unbulk_dyn_load_package_name("_sdl2.sdl2", "_sdl2.sdl2", "_sdl2.pyd") +sdl2 = unbulk_dyn_load_package_name("_sdl2.sdl2", "_sdl2.sdl2", "__sdl2.pyd") video = unbulk_dyn_load_package_name("_sdl2.video", "_sdl2.video", "_video.pyd")