mima-engine 0.2.3__tar.gz → 0.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of mima-engine might be problematic. Click here for more details.
- {mima_engine-0.2.3 → mima_engine-0.2.4}/PKG-INFO +2 -2
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/__init__.py +1 -1
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/backend/pygame_events.py +210 -194
- mima_engine-0.2.4/src/mima/backend/touch_control_scheme_a.py +126 -0
- mima_engine-0.2.4/src/mima/backend/touch_control_scheme_b.py +132 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/core/collision.py +46 -23
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/core/engine.py +25 -13
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/core/mode_engine.py +7 -2
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/objects/creature.py +6 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/objects/effects/debug_box.py +11 -2
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/objects/world/container.py +1 -1
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/objects/world/oneway.py +34 -8
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/objects/world/pickup.py +8 -2
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/objects/world/switch.py +20 -4
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/scripts/commands/oneway_move.py +4 -3
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/util/constants.py +3 -3
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/util/input_defaults.py +12 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/view/mima_mode.py +60 -19
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/view/mima_scene.py +6 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/view/mima_window.py +91 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima_engine.egg-info/PKG-INFO +2 -2
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima_engine.egg-info/SOURCES.txt +2 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/README.md +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/pyproject.toml +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/setup.cfg +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/backend/__init__.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/backend/pygame_assets.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/backend/pygame_audio.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/backend/pygame_backend.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/backend/pygame_camera.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/core/__init__.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/core/database.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/core/scene_engine.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/maps/__init__.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/maps/template.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/maps/tile.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/maps/tile_animation.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/maps/tile_info.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/maps/tile_layer.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/maps/tiled/__init__.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/maps/tiled/tiled_layer.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/maps/tiled/tiled_map.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/maps/tiled/tiled_object.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/maps/tiled/tiled_objectgroup.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/maps/tiled/tiled_template.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/maps/tiled/tiled_tile.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/maps/tiled/tiled_tileset.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/maps/tilemap.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/maps/tileset.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/maps/tileset_info.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/maps/transition_map.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/objects/__init__.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/objects/animated_sprite.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/objects/attribute_effect.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/objects/attributes.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/objects/dynamic.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/objects/effects/__init__.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/objects/effects/colorize_screen.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/objects/effects/light.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/objects/effects/show_sprite.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/objects/effects/walking_on_grass.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/objects/effects/walking_on_water.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/objects/loader.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/objects/projectile.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/objects/sprite.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/objects/world/__init__.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/objects/world/color_gate.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/objects/world/color_switch.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/objects/world/floor_switch.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/objects/world/gate.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/objects/world/light_source.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/objects/world/logic_gate.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/objects/world/movable.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/objects/world/teleport.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/scripts/__init__.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/scripts/command.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/scripts/commands/__init__.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/scripts/commands/add_quest.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/scripts/commands/change_map.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/scripts/commands/close_dialog.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/scripts/commands/equip_weapon.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/scripts/commands/give_item.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/scripts/commands/give_resource.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/scripts/commands/move_map.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/scripts/commands/move_to.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/scripts/commands/parallel.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/scripts/commands/play_sound.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/scripts/commands/present_item.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/scripts/commands/progress_quest.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/scripts/commands/quit_game.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/scripts/commands/save_game.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/scripts/commands/screen_fade.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/scripts/commands/serial.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/scripts/commands/set_facing_direction.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/scripts/commands/set_spawn_map.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/scripts/commands/show_choices.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/scripts/commands/show_dialog.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/scripts/commands/take_coins.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/scripts/script_processor.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/states/__init__.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/states/game_state.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/states/memory.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/states/quest.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/types/__init__.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/types/alignment.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/types/blend.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/types/damage.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/types/direction.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/types/gate_color.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/types/graphic_state.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/types/keys.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/types/mode.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/types/nature.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/types/object.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/types/player.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/types/position.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/types/start.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/types/terrain.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/types/tile_collision.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/types/weapon_slot.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/types/window.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/usables/__init__.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/usables/item.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/usables/weapon.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/util/__init__.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/util/colors.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/util/functions.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/util/logging.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/util/property.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/util/runtime_config.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/util/trading_item.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/view/__init__.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/view/camera.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima/view/mima_view.py +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima_engine.egg-info/dependency_links.txt +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima_engine.egg-info/requires.txt +0 -0
- {mima_engine-0.2.3 → mima_engine-0.2.4}/src/mima_engine.egg-info/top_level.txt +0 -0
|
@@ -13,6 +13,8 @@ from ..util.input_defaults import (
|
|
|
13
13
|
DEFAULT_KEYBOARD_MAP,
|
|
14
14
|
DEFAULT_TOUCHSCREEN_MAP,
|
|
15
15
|
)
|
|
16
|
+
from .touch_control_scheme_a import TouchControlSchemeA
|
|
17
|
+
from .touch_control_scheme_b import TouchControlSchemeB
|
|
16
18
|
|
|
17
19
|
LOG = logging.getLogger(__name__)
|
|
18
20
|
|
|
@@ -41,14 +43,15 @@ class PygameUserInput:
|
|
|
41
43
|
):
|
|
42
44
|
self._last_keys: Dict[K, bool] = {}
|
|
43
45
|
self._new_keys: Dict[K, bool] = {but: False for but in BUTTONS}
|
|
44
|
-
self.
|
|
45
|
-
self.
|
|
46
|
-
self.
|
|
47
|
-
self.
|
|
48
|
-
self.
|
|
49
|
-
self.
|
|
50
|
-
self.
|
|
51
|
-
self.
|
|
46
|
+
self._touch_control = TouchControlSchemeB()
|
|
47
|
+
# self._left_finger_tap_pos: pygame.Vector2 = pygame.Vector2(0, 0)
|
|
48
|
+
# self._right_finger_tap_pos: pygame.Vector2 = pygame.Vector2(0, 0)
|
|
49
|
+
# self._left_finger_pos: pygame.Vector2 = pygame.Vector2(0, 0)
|
|
50
|
+
# self._right_finger_pos: pygame.Vector2 = pygame.Vector2(0, 0)
|
|
51
|
+
# self._last_left_tap: float = 0.0
|
|
52
|
+
# self._last_right_tap: float = 0.0
|
|
53
|
+
# self._last_left_motion: float = 0.0
|
|
54
|
+
# self._last_right_motion: float = 0.0
|
|
52
55
|
self._key_map: Dict[K, List[int]] = {}
|
|
53
56
|
self.joystick_to_player: Dict[int, Player] = (
|
|
54
57
|
joy_to_player
|
|
@@ -104,6 +107,7 @@ class PygameUserInput:
|
|
|
104
107
|
self._past_events = {}
|
|
105
108
|
self._new_events = {}
|
|
106
109
|
self._collect_all_events = False
|
|
110
|
+
self.enable_touch_controls = False
|
|
107
111
|
|
|
108
112
|
def reset(self):
|
|
109
113
|
self._last_keys = self._new_keys.copy()
|
|
@@ -159,7 +163,8 @@ class PygameUserInput:
|
|
|
159
163
|
if event.type in JOYSTICK_EVENTS and self.joystick_input_enabled:
|
|
160
164
|
self._handle_joystick(event)
|
|
161
165
|
|
|
162
|
-
|
|
166
|
+
# self._touch_control.update(self.width, self.height)
|
|
167
|
+
if self.enable_touch_controls and event.type in TOUCH_EVENTS:
|
|
163
168
|
self._handle_touch(event)
|
|
164
169
|
|
|
165
170
|
# print(
|
|
@@ -270,194 +275,202 @@ class PygameUserInput:
|
|
|
270
275
|
self.unset_key(self._js_real(event.joy, K.DOWN))
|
|
271
276
|
|
|
272
277
|
def _handle_touch(self, event):
|
|
273
|
-
|
|
274
|
-
event
|
|
278
|
+
set_keys, unset_keys = self._touch_control.handle_touch(
|
|
279
|
+
event, self.width, self.height
|
|
275
280
|
)
|
|
281
|
+
for key in unset_keys:
|
|
282
|
+
self.unset_key(key)
|
|
283
|
+
for key in set_keys:
|
|
284
|
+
self.set_key(key)
|
|
276
285
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
286
|
+
# finger_pos = pygame.Vector2(
|
|
287
|
+
# event.x * self.width, event.y * self.height
|
|
288
|
+
# )
|
|
280
289
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
290
|
+
# if event.type == pygame.FINGERDOWN:
|
|
291
|
+
# tap = time.time()
|
|
292
|
+
# for key, area in DEFAULT_TOUCHSCREEN_MAP.items():
|
|
293
|
+
|
|
294
|
+
# if (
|
|
295
|
+
# area[0][0] <= event.x < area[1][0]
|
|
296
|
+
# and area[0][1] <= event.y < area[1][1]
|
|
297
|
+
# ):
|
|
298
|
+
# if key == K.P1_UP:
|
|
299
|
+
# self._left_finger_tap_pos = finger_pos
|
|
300
|
+
# if tap - self._last_left_tap < DOUBLE_TAP_SPEED:
|
|
301
|
+
# # print("Left Double Tap")
|
|
302
|
+
# self.set_key(K.P1_SELECT)
|
|
303
|
+
# self._last_left_tap = tap
|
|
304
|
+
# elif key == K.P1_L:
|
|
305
|
+
# self.set_key(K.P1_L)
|
|
306
|
+
# else:
|
|
307
|
+
# self.set_key(key)
|
|
308
|
+
# self._right_finger_tap_pos = finger_pos
|
|
309
|
+
# self._last_right_tap = tap
|
|
310
|
+
|
|
311
|
+
# # if event.x < 0.0625 and event.y < 0.1111:
|
|
312
|
+
# # self.set_key(K.L)
|
|
313
|
+
# # elif event.x > 1.0 - 0.0625 and event.y < 0.1111:
|
|
314
|
+
# # self.set_key(K.R)
|
|
315
|
+
# # elif event.x < 0.5:
|
|
316
|
+
# # # print(f"Left Finger Down: {finger_pos}")
|
|
317
|
+
# # self._left_finger_tap_pos = finger_pos
|
|
318
|
+
|
|
319
|
+
# # if tap - self._last_left_tap < DOUBLE_TAP_SPEED:
|
|
320
|
+
# # # print("Left Double Tap")
|
|
321
|
+
# # self.set_key(K.SELECT)
|
|
322
|
+
# # self._last_left_tap = tap
|
|
323
|
+
# # # self._left_finger_pos.x = event.x
|
|
324
|
+
# # # self._left_finger_pos.y = event.y
|
|
325
|
+
|
|
326
|
+
# # # if tap - self._last_left_tap < 0.2:
|
|
327
|
+
# # # print("Left Double Tap")
|
|
328
|
+
# # # # self._set_key(K.START)
|
|
329
|
+
# # # # self._unset_key(K.RIGHT)
|
|
330
|
+
# # # # self._unset_key(K.LEFT)
|
|
331
|
+
# # # # self._unset_key(K.UP)
|
|
332
|
+
# # # # self._unset_key(K.DOWN)
|
|
333
|
+
# # else:
|
|
334
|
+
# # self._right_finger_tap_pos = finger_pos
|
|
335
|
+
|
|
336
|
+
# # # if tap - self._last_right_tap < DOUBLE_TAP_SPEED:
|
|
337
|
+
# # # # print("Right Double Tap")
|
|
338
|
+
# # # self.set_key(K.SELECT)
|
|
339
|
+
# # self._last_right_tap = tap
|
|
340
|
+
# # if event.y < 0.3:
|
|
341
|
+
# # self.set_key(K.START)
|
|
342
|
+
# # elif event.x < 0.75:
|
|
343
|
+
# # self.set_key(K.B)
|
|
344
|
+
# # else:
|
|
345
|
+
# # self.set_key(K.A)
|
|
346
|
+
# # self._right_finger_pos.x = event.x
|
|
347
|
+
# # self._right_finger_pos.y = event.y
|
|
348
|
+
# # if tap - self._last_right_tap < 0.2:
|
|
349
|
+
# # print("Right Double Tap")
|
|
350
|
+
|
|
351
|
+
# if event.type == pygame.FINGERUP:
|
|
352
|
+
# # release = time.time()
|
|
353
|
+
# # finger_dist = (finger_pos - self._left_finger_tap_pos).length()
|
|
354
|
+
|
|
355
|
+
# if event.x < 0.5:
|
|
356
|
+
# # print(f"Left Finger Up: {finger_pos}")
|
|
357
|
+
# # if (
|
|
358
|
+
# # SINGLE_TAP_MIN
|
|
359
|
+
# # < release - self._last_left_tap
|
|
360
|
+
# # < SINGLE_TAP_MAX
|
|
361
|
+
# # ) and finger_dist < 2.5:
|
|
362
|
+
# # print("Left Single Tap")
|
|
363
|
+
# # # self.set_key(K.START)
|
|
364
|
+
|
|
365
|
+
# self.unset_key(K.P1_SELECT)
|
|
366
|
+
# self.unset_key(K.P1_RIGHT)
|
|
367
|
+
# self.unset_key(K.P1_LEFT)
|
|
368
|
+
# self.unset_key(K.P1_UP)
|
|
369
|
+
# self.unset_key(K.P1_DOWN)
|
|
370
|
+
# self.unset_key(K.P1_L)
|
|
371
|
+
# # print(
|
|
372
|
+
# # f"Left Finger moved {finger_dist} "
|
|
373
|
+
# # f"({release - self._last_left_tap} s)"
|
|
374
|
+
# # )
|
|
375
|
+
# else:
|
|
376
|
+
# self.unset_key(K.P1_START)
|
|
377
|
+
# self.unset_key(K.P1_A)
|
|
378
|
+
# self.unset_key(K.P1_B)
|
|
379
|
+
# self.unset_key(K.P1_Y)
|
|
380
|
+
# self.unset_key(K.P1_X)
|
|
381
|
+
# self.unset_key(K.P1_R)
|
|
382
|
+
# # print(f"Right Finger Up: {finger_pos}")
|
|
383
|
+
# # if (
|
|
384
|
+
# # SINGLE_TAP_MIN
|
|
385
|
+
# # < release - self._last_right_tap
|
|
386
|
+
# # < SINGLE_TAP_MAX
|
|
387
|
+
# # ) and finger_dist < 2.5:
|
|
388
|
+
# # print("Right Single Tap")
|
|
389
|
+
|
|
390
|
+
# # print(
|
|
391
|
+
# # f"Left Finger moved {finger_dist} "
|
|
392
|
+
# # f"({release - self._last_left_tap} s)"
|
|
393
|
+
# # )
|
|
394
|
+
# #
|
|
395
|
+
# # if event.x < 0.5:
|
|
396
|
+
# # if 0.1 < release - self._last_left_tap < 0.25:
|
|
397
|
+
# # print("Left Single Tap")
|
|
398
|
+
|
|
399
|
+
# # self._left_finger_pos.x = 0
|
|
400
|
+
# # self._left_finger_pos.y = 0
|
|
401
|
+
# # self._unset_key(K.DOWN)
|
|
402
|
+
# # self._unset_key(K.LEFT)
|
|
403
|
+
# # self._unset_key(K.UP)
|
|
404
|
+
# # self._unset_key(K.RIGHT)
|
|
405
|
+
# # self._unset_key(K.START)
|
|
406
|
+
# # else:
|
|
407
|
+
# # if 0.1 < release - self._last_right_tap < 0.25:
|
|
408
|
+
# # print("Right Single Tap")
|
|
409
|
+
|
|
410
|
+
# # self._unset_key(K.A)
|
|
411
|
+
# # self._unset_key(K.B)
|
|
412
|
+
# if event.type == pygame.FINGERMOTION:
|
|
413
|
+
# if event.x < 0.5:
|
|
414
|
+
# vd = finger_pos - self._left_finger_tap_pos
|
|
415
|
+
# self.unset_key(K.P1_RIGHT)
|
|
416
|
+
# self.unset_key(K.P1_LEFT)
|
|
417
|
+
# self.unset_key(K.P1_UP)
|
|
418
|
+
# self.unset_key(K.P1_DOWN)
|
|
419
|
+
# if abs(vd.x) > 2 * abs(vd.y):
|
|
420
|
+
# # Horizontal
|
|
421
|
+
# if vd.x > 5.0:
|
|
422
|
+
# self.set_key(K.P1_RIGHT)
|
|
423
|
+
# self.unset_key(K.P1_LEFT)
|
|
424
|
+
# self.unset_key(K.P1_UP)
|
|
425
|
+
# self.unset_key(K.P1_DOWN)
|
|
426
|
+
# elif vd.x < -5.0:
|
|
427
|
+
# self.set_key(K.P1_LEFT)
|
|
428
|
+
# self.unset_key(K.P1_RIGHT)
|
|
429
|
+
# self.unset_key(K.P1_UP)
|
|
430
|
+
# self.unset_key(K.P1_DOWN)
|
|
431
|
+
# elif abs(vd.x) * 2 < abs(vd.y):
|
|
432
|
+
# # Vertical
|
|
433
|
+
# if vd.y > 5.0:
|
|
434
|
+
# self.unset_key(K.P1_RIGHT)
|
|
435
|
+
# self.unset_key(K.P1_LEFT)
|
|
436
|
+
# self.unset_key(K.P1_UP)
|
|
437
|
+
# self.set_key(K.P1_DOWN)
|
|
438
|
+
# elif vd.y < -5.0:
|
|
439
|
+
# self.unset_key(K.P1_LEFT)
|
|
440
|
+
# self.unset_key(K.P1_RIGHT)
|
|
441
|
+
# self.set_key(K.P1_UP)
|
|
442
|
+
# self.unset_key(K.P1_DOWN)
|
|
443
|
+
# elif abs(vd.x) * 1.05 > abs(vd.y) or abs(vd.x) < 1.05 * abs(
|
|
444
|
+
# vd.y
|
|
445
|
+
# ):
|
|
446
|
+
# if vd.x < 0:
|
|
447
|
+
# self.set_key(K.P1_LEFT)
|
|
448
|
+
# elif vd.x > 0:
|
|
449
|
+
# self.set_key(K.P1_RIGHT)
|
|
450
|
+
# if vd.y < 0:
|
|
451
|
+
# self.set_key(K.P1_UP)
|
|
452
|
+
# elif vd.y > 0:
|
|
453
|
+
# self.set_key(K.P1_DOWN)
|
|
454
|
+
# # else:
|
|
455
|
+
# # vd = finger_pos - self._right_finger_tap_pos
|
|
456
|
+
# # self.unset_key(K.A)
|
|
457
|
+
# # self.unset_key(K.B)
|
|
458
|
+
# # self.unset_key(K.Y)
|
|
459
|
+
# # self.unset_key(K.X)
|
|
460
|
+
# # if abs(vd.x) > 2 * abs(vd.y):
|
|
461
|
+
# # # Horizontal
|
|
462
|
+
# # if vd.x > 5.0:
|
|
463
|
+
# # self.set_key(K.Y)
|
|
464
|
+
# # elif vd.x < -5.0:
|
|
465
|
+
# # self.set_key(K.B)
|
|
466
|
+
# # elif abs(vd.x) * 2 < abs(vd.y):
|
|
467
|
+
# # # Vertical
|
|
468
|
+
# # if vd.y > 5.0:
|
|
469
|
+
# # self.set_key(K.A)
|
|
470
|
+
# # elif vd.y < -5.0:
|
|
471
|
+
# # self.set_key(K.X)
|
|
472
|
+
|
|
473
|
+
# self.vd = vd
|
|
461
474
|
|
|
462
475
|
def _handle_mouse(self, event):
|
|
463
476
|
# if event.type == pygame.MOUSEBUTTONDOWN:
|
|
@@ -674,6 +687,9 @@ class PygameUserInput:
|
|
|
674
687
|
def trigger_all_events_collection(self, active: bool = True):
|
|
675
688
|
self._collect_all_events = active
|
|
676
689
|
|
|
690
|
+
def get_touch_state(self):
|
|
691
|
+
return self._touch_control.get_touch_state()
|
|
692
|
+
|
|
677
693
|
|
|
678
694
|
def _button_to_player(button: K, player: Player):
|
|
679
695
|
return K(button.value + 12 * player.value)
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import time
|
|
2
|
+
|
|
3
|
+
import pygame
|
|
4
|
+
|
|
5
|
+
from ..types.keys import Key as K
|
|
6
|
+
from ..util.constants import DOUBLE_TAP_SPEED
|
|
7
|
+
from ..util.input_defaults import BUTTONS, DEFAULT_TOUCHSCREEN_MAP
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class TouchControlSchemeA:
|
|
11
|
+
|
|
12
|
+
def __init__(self):
|
|
13
|
+
|
|
14
|
+
self._left_finger_tap_pos = 0.0
|
|
15
|
+
self._right_finger_tap_pos = 0.0
|
|
16
|
+
|
|
17
|
+
self._last_left_tap = 0.0
|
|
18
|
+
self._last_right_tap = 0.0
|
|
19
|
+
|
|
20
|
+
def handle_touch(self, event, width=1.0, height=1.0):
|
|
21
|
+
set_keys = []
|
|
22
|
+
unset_keys = []
|
|
23
|
+
|
|
24
|
+
tap_pos = pygame.Vector2(event.x * width, event.y * height)
|
|
25
|
+
|
|
26
|
+
if event.type == pygame.FINGERDOWN:
|
|
27
|
+
tap_time = time.time()
|
|
28
|
+
for key, area in DEFAULT_TOUCHSCREEN_MAP.items():
|
|
29
|
+
|
|
30
|
+
if (
|
|
31
|
+
area[0][0] <= event.x < area[1][0]
|
|
32
|
+
and area[0][1] <= event.y < area[1][1]
|
|
33
|
+
):
|
|
34
|
+
if key == K.P1_UP:
|
|
35
|
+
self._left_finger_tap_pos = tap_pos
|
|
36
|
+
if tap_time - self._last_left_tap < DOUBLE_TAP_SPEED:
|
|
37
|
+
# print("Left Double Tap")
|
|
38
|
+
set_keys.append(K.P1_SELECT)
|
|
39
|
+
self._last_left_tap = tap_time
|
|
40
|
+
elif key == K.P1_L:
|
|
41
|
+
set_keys.append(K.P1_L)
|
|
42
|
+
else:
|
|
43
|
+
set_keys.append(key)
|
|
44
|
+
self._right_finger_tap_pos = tap_pos
|
|
45
|
+
self._last_right_tap = tap_time
|
|
46
|
+
|
|
47
|
+
if event.type == pygame.FINGERUP:
|
|
48
|
+
# release = time.time()
|
|
49
|
+
# finger_dist = (finger_pos - self._left_finger_tap_pos).length()
|
|
50
|
+
|
|
51
|
+
if event.x < 0.5:
|
|
52
|
+
# print(f"Left Finger Up: {finger_pos}")
|
|
53
|
+
# if (
|
|
54
|
+
# SINGLE_TAP_MIN
|
|
55
|
+
# < release - self._last_left_tap
|
|
56
|
+
# < SINGLE_TAP_MAX
|
|
57
|
+
# ) and finger_dist < 2.5:
|
|
58
|
+
# print("Left Single Tap")
|
|
59
|
+
# # set_keys.append(K.START)
|
|
60
|
+
|
|
61
|
+
unset_keys.append(K.P1_SELECT)
|
|
62
|
+
unset_keys.append(K.P1_RIGHT)
|
|
63
|
+
unset_keys.append(K.P1_LEFT)
|
|
64
|
+
unset_keys.append(K.P1_UP)
|
|
65
|
+
unset_keys.append(K.P1_DOWN)
|
|
66
|
+
unset_keys.append(K.P1_L)
|
|
67
|
+
# print(
|
|
68
|
+
# f"Left Finger moved {finger_dist} "
|
|
69
|
+
# f"({release - self._last_left_tap} s)"
|
|
70
|
+
# )
|
|
71
|
+
else:
|
|
72
|
+
unset_keys.append(K.P1_START)
|
|
73
|
+
unset_keys.append(K.P1_A)
|
|
74
|
+
unset_keys.append(K.P1_B)
|
|
75
|
+
unset_keys.append(K.P1_Y)
|
|
76
|
+
unset_keys.append(K.P1_X)
|
|
77
|
+
unset_keys.append(K.P1_R)
|
|
78
|
+
|
|
79
|
+
if event.type == pygame.FINGERMOTION:
|
|
80
|
+
if event.x < 0.5:
|
|
81
|
+
vd = tap_pos - self._left_finger_tap_pos
|
|
82
|
+
unset_keys.append(K.P1_RIGHT)
|
|
83
|
+
unset_keys.append(K.P1_LEFT)
|
|
84
|
+
unset_keys.append(K.P1_UP)
|
|
85
|
+
unset_keys.append(K.P1_DOWN)
|
|
86
|
+
if abs(vd.x) > 2 * abs(vd.y):
|
|
87
|
+
# Horizontal
|
|
88
|
+
if vd.x > 5.0:
|
|
89
|
+
set_keys.append(K.P1_RIGHT)
|
|
90
|
+
unset_keys.append(K.P1_LEFT)
|
|
91
|
+
unset_keys.append(K.P1_UP)
|
|
92
|
+
unset_keys.append(K.P1_DOWN)
|
|
93
|
+
elif vd.x < -5.0:
|
|
94
|
+
set_keys.append(K.P1_LEFT)
|
|
95
|
+
unset_keys.append(K.P1_RIGHT)
|
|
96
|
+
unset_keys.append(K.P1_UP)
|
|
97
|
+
unset_keys.append(K.P1_DOWN)
|
|
98
|
+
elif abs(vd.x) * 2 < abs(vd.y):
|
|
99
|
+
# Vertical
|
|
100
|
+
if vd.y > 5.0:
|
|
101
|
+
unset_keys.append(K.P1_RIGHT)
|
|
102
|
+
unset_keys.append(K.P1_LEFT)
|
|
103
|
+
unset_keys.append(K.P1_UP)
|
|
104
|
+
set_keys.append(K.P1_DOWN)
|
|
105
|
+
elif vd.y < -5.0:
|
|
106
|
+
unset_keys.append(K.P1_LEFT)
|
|
107
|
+
unset_keys.append(K.P1_RIGHT)
|
|
108
|
+
set_keys.append(K.P1_UP)
|
|
109
|
+
unset_keys.append(K.P1_DOWN)
|
|
110
|
+
elif abs(vd.x) * 1.05 > abs(vd.y) or abs(vd.x) < 1.05 * abs(
|
|
111
|
+
vd.y
|
|
112
|
+
):
|
|
113
|
+
if vd.x < 0:
|
|
114
|
+
set_keys.append(K.P1_LEFT)
|
|
115
|
+
elif vd.x > 0:
|
|
116
|
+
set_keys.append(K.P1_RIGHT)
|
|
117
|
+
if vd.y < 0:
|
|
118
|
+
set_keys.append(K.P1_UP)
|
|
119
|
+
elif vd.y > 0:
|
|
120
|
+
set_keys.append(K.P1_DOWN)
|
|
121
|
+
self.vd = vd
|
|
122
|
+
|
|
123
|
+
return set_keys, unset_keys
|
|
124
|
+
|
|
125
|
+
def get_touch_state(self):
|
|
126
|
+
return {}
|