Compare commits
29 Commits
63253b69eb
...
old
| Author | SHA1 | Date | |
|---|---|---|---|
| 6c0ef9b711 | |||
| 55cc9b8e3f | |||
| 3a4f579f05 | |||
| e8366a9ab4 | |||
| 79e84b9fe4 | |||
| 186f0c2d3f | |||
| 52ec929c3f | |||
| 79d0e88f0d | |||
| 443f3ee05f | |||
| e534678494 | |||
| 4335aafdf8 | |||
| bf94840bad | |||
| 6d03cb6a38 | |||
| 32924ae867 | |||
| a22baf175a | |||
| 1370d7696e | |||
| 93308cbee1 | |||
| 80ff81f57c | |||
| 3e4c4442cf | |||
| 41ce304a76 | |||
| 349ee7a520 | |||
| b462f3e66a | |||
| bda701948b | |||
| f5580a6eda | |||
| f59b0895bb | |||
| 96a8b4d8e5 | |||
| c353b5645e | |||
| 019a674cac | |||
| 6b02b8390c |
Binary file not shown.
|
Before Width: | Height: | Size: 844 KiB After Width: | Height: | Size: 886 KiB |
63
main.py
63
main.py
@@ -4,6 +4,8 @@ import random
|
||||
import sys
|
||||
import os
|
||||
import time
|
||||
import re
|
||||
random.seed(time.time())
|
||||
|
||||
|
||||
from pygame import FULLSCREEN
|
||||
@@ -73,14 +75,14 @@ def init_sounds():
|
||||
|
||||
case_images = {}
|
||||
|
||||
async def touch(event):
|
||||
def touch(event):
|
||||
global touch_start, touch_start_time
|
||||
|
||||
if event.type == pygame.FINGERDOWN and not touch_start:
|
||||
touch_start = (event.x * SCREEN_WIDTH, event.y * SCREEN_HEIGHT)
|
||||
touch_start_time = time.time()
|
||||
print("touch_start")
|
||||
return None
|
||||
return False
|
||||
|
||||
elif event.type == pygame.FINGERUP and touch_start:
|
||||
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:
|
||||
return "ontop"
|
||||
else:
|
||||
print("touch problem")
|
||||
return None
|
||||
return None
|
||||
print("touch probleeeeem")
|
||||
return False
|
||||
return False
|
||||
|
||||
async def is_SPACE_event(event):
|
||||
def is_SPACE_event(event):
|
||||
|
||||
# Tastatur oder Joystick A
|
||||
if (event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE) or \
|
||||
@@ -117,7 +119,7 @@ async def is_SPACE_event(event):
|
||||
|
||||
return False
|
||||
|
||||
async def is_LEFT_event(event):
|
||||
def is_LEFT_event(event):
|
||||
# Tastatur oder Joystick links
|
||||
if ((event.type == pygame.KEYDOWN and event.key == pygame.K_LEFT) or
|
||||
(event.type == pygame.JOYHATMOTION and event.value[0] == -1) or
|
||||
@@ -127,9 +129,8 @@ async def is_LEFT_event(event):
|
||||
return False
|
||||
|
||||
|
||||
async def is_UP_event(event):
|
||||
global touch_start, touch_start_time
|
||||
|
||||
def is_UP_event(event):
|
||||
# Tastatur oder Joystick oben
|
||||
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.JOYBUTTONDOWN and event.button == 3)):
|
||||
@@ -497,12 +498,12 @@ async def show_instruction_screen(image):
|
||||
pygame.display.flip()
|
||||
await asyncio.sleep(0)
|
||||
for event in pygame.event.get():
|
||||
result = await touch(event)
|
||||
await asyncio.sleep(0)
|
||||
result = touch(event)
|
||||
if event.type == pygame.QUIT:
|
||||
pygame.quit()
|
||||
sys.exit()
|
||||
elif await is_SPACE_event(event) or result == "snap":
|
||||
print (result)
|
||||
elif is_SPACE_event(event) or (result == "snap"):
|
||||
waiting = False
|
||||
|
||||
async def fail_current_case():
|
||||
@@ -524,8 +525,17 @@ def generate_fill_sequence():
|
||||
global case_sequence
|
||||
try:
|
||||
with open("case_sequences.txt", "r") as f:
|
||||
sets = f.read().strip().split("\n\n")
|
||||
chosen = random.choice(sets).strip().split("\n")
|
||||
sets = re.split(r"\r?\n\r?\n", f.read().strip())
|
||||
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 = []
|
||||
for line in chosen:
|
||||
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'
|
||||
sequence.append({'w': w, 'h': h, 'rotated': rot})
|
||||
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}]
|
||||
|
||||
|
||||
def spawn_case_in_game():
|
||||
global current_case, next_queue, case_index
|
||||
if not case_sequence:
|
||||
@@ -639,7 +652,7 @@ async def show_game_over(score):
|
||||
overlay.fill((0, 0, 0))
|
||||
screen.blit(overlay, (0, 0))
|
||||
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))
|
||||
screen.blit(text, (SCREEN_WIDTH // 2 - text.get_width() // 2, SCREEN_HEIGHT // 2 - text.get_height() // 2))
|
||||
pygame.display.flip()
|
||||
@@ -651,7 +664,7 @@ async def show_game_over(score):
|
||||
if event.type == pygame.QUIT:
|
||||
pygame.quit()
|
||||
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:
|
||||
print("Benutzer bestätigt, Punkte werden jetzt gesendet.")
|
||||
prepared_form.submit()
|
||||
@@ -712,17 +725,16 @@ async def main():
|
||||
if state == 1: # PLAYING
|
||||
result = "none"
|
||||
if event.type == pygame.FINGERUP and touch_start:
|
||||
result = await touch(event)
|
||||
print(result)
|
||||
result = touch(event)
|
||||
elif event.type == pygame.FINGERDOWN and not touch_start:
|
||||
await touch(event)
|
||||
|
||||
if await is_LEFT_event(event) or result == "ontop":
|
||||
touch(event)
|
||||
print(result)
|
||||
if is_LEFT_event(event) or (result == "ontop"):
|
||||
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:
|
||||
await current_case.animate_tip()
|
||||
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 await current_case.animate_place_on_top():
|
||||
transition_counter = transition_fps
|
||||
@@ -739,7 +751,8 @@ async def main():
|
||||
stacked_cases.append(current_case)
|
||||
spawn_case_in_game()
|
||||
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:
|
||||
await current_case.animate_snap()
|
||||
can_use_tilt = True
|
||||
|
||||
Reference in New Issue
Block a user