test for touch function
This commit is contained in:
28
main.py
28
main.py
@@ -70,6 +70,31 @@ def init_sounds():
|
|||||||
|
|
||||||
case_images = {}
|
case_images = {}
|
||||||
|
|
||||||
|
def is_snap_event(event):
|
||||||
|
global touch_start
|
||||||
|
|
||||||
|
# Tastatur oder Joystick A
|
||||||
|
if (event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE) or \
|
||||||
|
(event.type == pygame.JOYBUTTONDOWN and event.button == 0):
|
||||||
|
return True
|
||||||
|
|
||||||
|
# Touch (Tap)
|
||||||
|
if event.type == pygame.FINGERDOWN:
|
||||||
|
touch_start = (event.x * SCREEN_WIDTH, event.y * SCREEN_HEIGHT)
|
||||||
|
|
||||||
|
elif event.type == pygame.FINGERUP and touch_start:
|
||||||
|
end = (event.x * SCREEN_WIDTH, event.y * SCREEN_HEIGHT)
|
||||||
|
dx = end[0] - touch_start[0]
|
||||||
|
dy = end[1] - touch_start[1]
|
||||||
|
distance = (dx ** 2 + dy ** 2) ** 0.5
|
||||||
|
touch_start = None
|
||||||
|
|
||||||
|
if distance < 50: # Kurzer Tap = Snap
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
async def init_game():
|
async def init_game():
|
||||||
global screen, clock, font, controls
|
global screen, clock, font, controls
|
||||||
pygame.init()
|
pygame.init()
|
||||||
@@ -670,8 +695,7 @@ async def main():
|
|||||||
stacked_cases.append(current_case)
|
stacked_cases.append(current_case)
|
||||||
spawn_case_in_game()
|
spawn_case_in_game()
|
||||||
shake_timer = 10
|
shake_timer = 10
|
||||||
elif ((event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE) or
|
elif is_snap_event(event):
|
||||||
(event.type == pygame.JOYBUTTONDOWN and event.button == 0)):
|
|
||||||
if current_case and current_case.allow_snap:
|
if current_case and current_case.allow_snap:
|
||||||
await current_case.animate_snap()
|
await current_case.animate_snap()
|
||||||
can_use_tilt = True
|
can_use_tilt = True
|
||||||
|
|||||||
Reference in New Issue
Block a user