diff --git a/JANKFILE.md b/JANKFILE.md index eaa6944..f11a1d7 100644 --- a/JANKFILE.md +++ b/JANKFILE.md @@ -90,3 +90,12 @@ Main problem that came up today: all Python code is executed at the moment the G Workaround: There's a clickable button that performs the input registration. This is good for working out the behavior, but doesn't really allow Python scripts to properly control and set up their own environment. The module name is passed to the PythonScene constructor, and the `start()` method is called to set up class objects. Can I add more methods that are called on this module to swap scenes? + +## Notes 17 July + +The player entity is moving around via Python now! + +Unfortunately, the "actiononce" macro I use in C++ is not the behavior passed on to the Python key events. Key release events are being passed to Python just the way that keypresses are. + +I'll need to expose more of the input event properties down to Python. I also don't like how keycodes are being passed from python to C++, which currently limits user input to key strokes. Mouse buttons and mouse wheel should be possible too (just as they are under the SFML event binding). + diff --git a/src/Grid.cpp b/src/Grid.cpp index 2548ca6..4ecd7f5 100644 --- a/src/Grid.cpp +++ b/src/Grid.cpp @@ -297,7 +297,7 @@ void Grid::render(sf::RenderWindow & window) // visible & discovered layers for testing purposes if (!gridpoint.discovered) { - r.setFillColor(sf::Color(16, 16, 20, 255)); + r.setFillColor(sf::Color(16, 16, 20, 192)); // 255 opacity for actual blackout renderTexture.draw(r); } else if (!gridpoint.visible) { r.setFillColor(sf::Color(32, 32, 40, 128)); diff --git a/src/PythonScene.cpp b/src/PythonScene.cpp index 1122606..10ce409 100644 --- a/src/PythonScene.cpp +++ b/src/PythonScene.cpp @@ -12,6 +12,7 @@ PythonScene::PythonScene(GameEngine* g, std::string pymodule) registerAction(ActionCode::MOUSEWHEEL + ActionCode::WHEEL_NEG + ActionCode::WHEEL_DEL, "wheel_down"); // keyboard events + /* registerAction(ActionCode::KEY + sf::Keyboard::Q, "upleft"); registerAction(ActionCode::KEY + sf::Keyboard::W, "up"); registerAction(ActionCode::KEY + sf::Keyboard::E, "upright"); @@ -31,7 +32,7 @@ PythonScene::PythonScene(GameEngine* g, std::string pymodule) registerAction(ActionCode::KEY + sf::Keyboard::Numpad1, "downleft"); registerAction(ActionCode::KEY + sf::Keyboard::Numpad2, "down"); registerAction(ActionCode::KEY + sf::Keyboard::Numpad3, "downright"); - + */ // window resize registerAction(0, "event"); diff --git a/src/scripts/TestScene.py b/src/scripts/TestScene.py index 05296d6..fa31e59 100644 --- a/src/scripts/TestScene.py +++ b/src/scripts/TestScene.py @@ -259,14 +259,15 @@ class TestScene: mcrfpy.createSprite("o", 4, 4, 10, 10, 1.0) mcrfpy.createMenu("p", 20, 20, 40, 40) #11 - mcrfpy.createButton("p", 0, 0, 130, 40, DARKGREEN, (0, 0, 0), "Register", "keyregistration") + #mcrfpy.createButton("p", 0, 0, 130, 40, DARKGREEN, (0, 0, 0), "Register", "keyregistration") + mcrfpy.createButton("p", 0, 0, 130, 40, DARKGREEN, (0, 0, 0), "Register", "startrepl") mcrfpy.registerPyAction("keyregistration", keyregistration) #print("Make UIs visible") self.menus = mcrfpy.listMenus() self.menus[0].visible = True self.menus[1].w = 170 self.menus[1].visible = True - #self.menus[2].visible = True + self.menus[2].visible = True for mn in range(2, 6): self.menus[mn].bgcolor = BLACK @@ -551,7 +552,18 @@ def keyregistration(): print("Registering 'keytest'") mcrfpy.registerPyAction("keytest", keytest) print("Registering input") - print(mcrfpy.registerInputAction(15, "keytest")) + print(mcrfpy.registerInputAction(15, "keytest")) # 15 = P + + mcrfpy.registerPyAction("player_move_up", lambda: scene.player.move(0, -1)) + mcrfpy.registerPyAction("player_move_left", lambda: scene.player.move(-1, 0)) + mcrfpy.registerPyAction("player_move_down", lambda: scene.player.move(0, 1)) + mcrfpy.registerPyAction("player_move_right", lambda: scene.player.move(1, 0)) + + mcrfpy.registerInputAction(ord('w') - ord('a'), "player_move_up") + mcrfpy.registerInputAction(ord('a') - ord('a'), "player_move_left") + mcrfpy.registerInputAction(ord('s') - ord('a'), "player_move_down") + mcrfpy.registerInputAction(ord('d') - ord('a'), "player_move_right") + def start(): global scene