Compare commits

..

29 Commits

Author SHA1 Message Date
6c0ef9b711 main.py aktualisiert 2025-07-03 11:03:20 +02:00
55cc9b8e3f main.py aktualisiert 2025-07-03 10:59:20 +02:00
3a4f579f05 main.py aktualisiert 2025-07-03 10:44:54 +02:00
e8366a9ab4 main.py aktualisiert 2025-07-03 10:41:02 +02:00
79e84b9fe4 Dateien nach "images" hochladen 2025-07-03 09:38:07 +02:00
186f0c2d3f Dateien nach "images" hochladen 2025-07-03 09:34:33 +02:00
52ec929c3f Dateien nach "images" hochladen 2025-07-03 09:19:30 +02:00
79d0e88f0d main.py aktualisiert 2025-07-02 14:58:15 +02:00
443f3ee05f revert e534678494
revert main.py aktualisiert
2025-07-02 14:23:04 +02:00
e534678494 main.py aktualisiert 2025-07-02 14:16:26 +02:00
4335aafdf8 Dateien nach "images" hochladen 2025-06-26 00:04:45 +02:00
bf94840bad images/tutorial.png/tutorial.png gelöscht 2025-06-26 00:04:13 +02:00
6d03cb6a38 Dateien nach "images/tutorial.png" hochladen 2025-06-26 00:03:39 +02:00
32924ae867 images/tutorial.png gelöscht 2025-06-26 00:02:44 +02:00
a22baf175a Dateien nach "images" hochladen 2025-06-26 00:02:20 +02:00
1370d7696e images/tutorial.png gelöscht 2025-06-26 00:01:32 +02:00
93308cbee1 test webhook 2025-05-04 22:26:09 +02:00
80ff81f57c final changes for better touch function 2025-05-04 14:09:22 +02:00
3e4c4442cf final changes for better touch function 2025-05-04 14:07:40 +02:00
41ce304a76 final changes for better touch function 2025-05-04 14:01:55 +02:00
349ee7a520 final changes for better touch function 2025-05-04 13:58:15 +02:00
b462f3e66a final changes for better touch function 2025-05-04 13:38:23 +02:00
bda701948b final changes for better touch function 2025-05-03 02:23:32 +02:00
f5580a6eda final changes for better touch function 2025-05-03 02:14:00 +02:00
f59b0895bb final changes for better touch function 2025-05-03 02:06:10 +02:00
96a8b4d8e5 final changes for better touch function 2025-05-03 02:01:15 +02:00
c353b5645e final changes for better touch function 2025-05-03 01:56:31 +02:00
019a674cac final changes for better touch function 2025-05-03 01:54:25 +02:00
6b02b8390c final changes for better touch function 2025-05-03 01:50:44 +02:00
2 changed files with 38 additions and 25 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 844 KiB

After

Width:  |  Height:  |  Size: 886 KiB

63
main.py
View File

@@ -4,6 +4,8 @@ import random
import sys import sys
import os import os
import time import time
import re
random.seed(time.time())
from pygame import FULLSCREEN from pygame import FULLSCREEN
@@ -73,14 +75,14 @@ def init_sounds():
case_images = {} case_images = {}
async def touch(event): def touch(event):
global touch_start, touch_start_time global touch_start, touch_start_time
if event.type == pygame.FINGERDOWN and not touch_start: if event.type == pygame.FINGERDOWN and not touch_start:
touch_start = (event.x * SCREEN_WIDTH, event.y * SCREEN_HEIGHT) touch_start = (event.x * SCREEN_WIDTH, event.y * SCREEN_HEIGHT)
touch_start_time = time.time() touch_start_time = time.time()
print("touch_start") print("touch_start")
return None return False
elif event.type == pygame.FINGERUP and touch_start: elif event.type == pygame.FINGERUP and touch_start:
end = (event.x * SCREEN_WIDTH, event.y * SCREEN_HEIGHT) end = (event.x * SCREEN_WIDTH, event.y * SCREEN_HEIGHT)
@@ -100,11 +102,11 @@ async def touch(event):
elif dy < -50 and abs(dx) < 80 and duration > 0.08: elif dy < -50 and abs(dx) < 80 and duration > 0.08:
return "ontop" return "ontop"
else: else:
print("touch problem") print("touch probleeeeem")
return None return False
return None return False
async def is_SPACE_event(event): def is_SPACE_event(event):
# Tastatur oder Joystick A # Tastatur oder Joystick A
if (event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE) or \ if (event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE) or \
@@ -117,7 +119,7 @@ async def is_SPACE_event(event):
return False return False
async def is_LEFT_event(event): def is_LEFT_event(event):
# Tastatur oder Joystick links # Tastatur oder Joystick links
if ((event.type == pygame.KEYDOWN and event.key == pygame.K_LEFT) or if ((event.type == pygame.KEYDOWN and event.key == pygame.K_LEFT) or
(event.type == pygame.JOYHATMOTION and event.value[0] == -1) or (event.type == pygame.JOYHATMOTION and event.value[0] == -1) or
@@ -127,9 +129,8 @@ async def is_LEFT_event(event):
return False return False
async def is_UP_event(event): def is_UP_event(event):
global touch_start, touch_start_time # Tastatur oder Joystick oben
if ((event.type == pygame.KEYDOWN and event.key == pygame.K_UP) or if ((event.type == pygame.KEYDOWN and event.key == pygame.K_UP) or
(event.type == pygame.JOYHATMOTION and event.value[1] == 1) or (event.type == pygame.JOYHATMOTION and event.value[1] == 1) or
(event.type == pygame.JOYBUTTONDOWN and event.button == 3)): (event.type == pygame.JOYBUTTONDOWN and event.button == 3)):
@@ -497,12 +498,12 @@ async def show_instruction_screen(image):
pygame.display.flip() pygame.display.flip()
await asyncio.sleep(0) await asyncio.sleep(0)
for event in pygame.event.get(): for event in pygame.event.get():
result = await touch(event) await asyncio.sleep(0)
result = touch(event)
if event.type == pygame.QUIT: if event.type == pygame.QUIT:
pygame.quit() pygame.quit()
sys.exit() sys.exit()
elif await is_SPACE_event(event) or result == "snap": elif is_SPACE_event(event) or (result == "snap"):
print (result)
waiting = False waiting = False
async def fail_current_case(): async def fail_current_case():
@@ -524,8 +525,17 @@ def generate_fill_sequence():
global case_sequence global case_sequence
try: try:
with open("case_sequences.txt", "r") as f: with open("case_sequences.txt", "r") as f:
sets = f.read().strip().split("\n\n") sets = re.split(r"\r?\n\r?\n", f.read().strip())
chosen = random.choice(sets).strip().split("\n") print(f"Anzahl erkannter Sets: {len(sets)}")
index = random.randint(0, len(sets) - 1)
print(f"Zufällig gewählter Index: {index}")
chosen_raw = sets[index].strip()
print("Erste Zeilen des gewählten Sets:")
print("\n".join(chosen_raw.splitlines()[:3])) # Zeigt max. 3 Zeilen an
chosen = chosen_raw.split("\n")
sequence = [] sequence = []
for line in chosen: for line in chosen:
parts = line.strip().split(",") parts = line.strip().split(",")
@@ -533,9 +543,12 @@ def generate_fill_sequence():
w, h, rot = int(parts[0]), int(parts[1]), parts[2].strip().lower() == 'true' w, h, rot = int(parts[0]), int(parts[1]), parts[2].strip().lower() == 'true'
sequence.append({'w': w, 'h': h, 'rotated': rot}) sequence.append({'w': w, 'h': h, 'rotated': rot})
case_sequence = sequence case_sequence = sequence
except:
except Exception as e:
print("Fehler beim Laden der Sequenz:", e)
case_sequence = [{'w': 2, 'h': 1, 'rotated': False}, {'w': 1, 'h': 2, 'rotated': False}] case_sequence = [{'w': 2, 'h': 1, 'rotated': False}, {'w': 1, 'h': 2, 'rotated': False}]
def spawn_case_in_game(): def spawn_case_in_game():
global current_case, next_queue, case_index global current_case, next_queue, case_index
if not case_sequence: if not case_sequence:
@@ -639,7 +652,7 @@ async def show_game_over(score):
overlay.fill((0, 0, 0)) overlay.fill((0, 0, 0))
screen.blit(overlay, (0, 0)) screen.blit(overlay, (0, 0))
font_big = pygame.font.SysFont(None, 72) font_big = pygame.font.SysFont(None, 72)
message = f"Spiel beendet! Punkte: {int(score)}%" message = f"Spiel beendet! Punkte: {int(score)}%. Drücke die Leertaste um deine Punkte zu übermitteln."
text = font_big.render(message, True, (255, 255, 255)) text = font_big.render(message, True, (255, 255, 255))
screen.blit(text, (SCREEN_WIDTH // 2 - text.get_width() // 2, SCREEN_HEIGHT // 2 - text.get_height() // 2)) screen.blit(text, (SCREEN_WIDTH // 2 - text.get_width() // 2, SCREEN_HEIGHT // 2 - text.get_height() // 2))
pygame.display.flip() pygame.display.flip()
@@ -651,7 +664,7 @@ async def show_game_over(score):
if event.type == pygame.QUIT: if event.type == pygame.QUIT:
pygame.quit() pygame.quit()
sys.exit() sys.exit()
elif await is_SPACE_event(event) or await touch(event) == "snap": elif is_SPACE_event(event) or (touch(event) == "snap"):
if ready_to_submit and prepared_form: if ready_to_submit and prepared_form:
print("Benutzer bestätigt, Punkte werden jetzt gesendet.") print("Benutzer bestätigt, Punkte werden jetzt gesendet.")
prepared_form.submit() prepared_form.submit()
@@ -712,17 +725,16 @@ async def main():
if state == 1: # PLAYING if state == 1: # PLAYING
result = "none" result = "none"
if event.type == pygame.FINGERUP and touch_start: if event.type == pygame.FINGERUP and touch_start:
result = await touch(event) result = touch(event)
print(result)
elif event.type == pygame.FINGERDOWN and not touch_start: elif event.type == pygame.FINGERDOWN and not touch_start:
await touch(event) touch(event)
print(result)
if await is_LEFT_event(event) or result == "ontop": if is_LEFT_event(event) or (result == "ontop"):
can_tip = current_case.length_units * UNIT_HEIGHT <= TRAILER_HEIGHT can_tip = current_case.length_units * UNIT_HEIGHT <= TRAILER_HEIGHT
if current_case and current_case.allow_snap and can_use_tilt and can_tip: if current_case and current_case.allow_snap and can_use_tilt and can_tip:
await current_case.animate_tip() await current_case.animate_tip()
can_use_tilt = False can_use_tilt = False
elif await is_UP_event(event) or result == "tilt": elif is_UP_event(event) or (result == "tilt"):
if current_case and current_case.allow_snap and can_use_on_top and current_case.can_place_on_top(): if current_case and current_case.allow_snap and can_use_on_top and current_case.can_place_on_top():
if await current_case.animate_place_on_top(): if await current_case.animate_place_on_top():
transition_counter = transition_fps transition_counter = transition_fps
@@ -739,7 +751,8 @@ 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 await is_SPACE_event(event) or result == "snap": elif is_SPACE_event(event) or (result == "snap"):
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