Skip to content

Commit 8fdfff2

Browse files
committed
Fix for latest SP2 API change. And add some minor android related changes.
1 parent eee3973 commit 8fdfff2

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/controls.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ Controls::Controls(int index)
1717
{
1818
if (index == 0)
1919
{
20-
up.setKeys("up", "keypad 8");
21-
down.setKeys("down", "keypad 2");
22-
left.setKeys("left", "keypad 4");
23-
right.setKeys("right", "keypad 6");
20+
up.setKeys({"up", "keypad 8"});
21+
down.setKeys({"down", "keypad 2"});
22+
left.setKeys({"left", "keypad 4"});
23+
right.setKeys({"right", "keypad 6"});
2424

2525
primary_action.setKey("space");
26-
secondary_action.setKey("z");
26+
secondary_action.setKeys({"z", "Menu"});
2727

2828
unknown2.setKey("x");
29-
self_destruct.setKey("c");
29+
self_destruct.setKeys({"c", "AC Back"}); //"AC Back" is the back key in android
3030
replay_time.setKey("v");
3131
replay_fuel.setKey("b");
3232

@@ -86,6 +86,10 @@ PlayerControlsState Controls::playerControlStateFromKeybindings()
8686
result.left = KeyState(left);
8787
result.right = KeyState(right);
8888
result.primary_action = KeyState(primary_action);
89+
#ifdef ANDROID
90+
if (result.left.pressed && result.right.pressed)
91+
result.primary_action.pressed = true;
92+
#endif
8993
result.secondary_action = KeyState(secondary_action);
9094
result.unknown2 = KeyState(unknown2);
9195
result.self_destruct = KeyState(self_destruct);

src/main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <sp2/assert.h>
55
#include <sp2/random.h>
66
#include <sp2/io/directoryResourceProvider.h>
7+
#include <sp2/io/virtualTouchKeys.h>
78
#include <sp2/graphics/gui/widget/button.h>
89
#include <sp2/graphics/gui/scene.h>
910
#include <sp2/graphics/gui/theme.h>
@@ -56,6 +57,13 @@ int main(int argc, char** argv)
5657
#endif
5758
window->addLayer(scene_layer);
5859

60+
#ifdef ANDROID
61+
sp::io::VirtualTouchKeyLayer* touch_layer = new sp::io::VirtualTouchKeyLayer(50);
62+
touch_layer->addButton(sp::Rect2f(sp::Vector2f(0, 0), sp::Vector2f(0.5, 1.0)), controls[0].left);
63+
touch_layer->addButton(sp::Rect2f(sp::Vector2f(0.5, 0), sp::Vector2f(0.5, 1)), controls[0].right);
64+
window->addLayer(touch_layer);
65+
#endif
66+
5967
new LevelScene();
6068
new LevelSelect();
6169
engine->run();

0 commit comments

Comments
 (0)