add neue Spiel code
This commit is contained in:
parent
07be19be7c
commit
32351334d9
@ -10,22 +10,31 @@ import threading
|
|||||||
touch_x, touch_y = None, None
|
touch_x, touch_y = None, None
|
||||||
clap_trigger = False
|
clap_trigger = False
|
||||||
|
|
||||||
|
|
||||||
def osc_touch(address, x, y):
|
def osc_touch(address, x, y):
|
||||||
|
"""Wird aufgerufen, wenn /touch x y über OSC empfangen wird."""
|
||||||
global touch_x, touch_y
|
global touch_x, touch_y
|
||||||
touch_x, touch_y = x, y
|
touch_x, touch_y = x, y
|
||||||
|
|
||||||
def osc_clap(address):
|
|
||||||
|
def osc_clap(address, *args):
|
||||||
|
"""Wird aufgerufen, wenn /clap empfangen wird."""
|
||||||
global clap_trigger
|
global clap_trigger
|
||||||
clap_trigger = True
|
clap_trigger = True
|
||||||
|
|
||||||
|
|
||||||
def start_osc_server():
|
def start_osc_server():
|
||||||
disp = dispatcher.Dispatcher()
|
disp = dispatcher.Dispatcher()
|
||||||
disp.map("/touch", osc_touch)
|
disp.map("/touch", osc_touch)
|
||||||
disp.map("/clap", osc_clap)
|
disp.map("/clap", osc_clap)
|
||||||
server = osc_server.ThreadingOSCUDPServer(("127.0.0.1", 8000), disp)
|
|
||||||
print("🔊 OSC server läuft auf Port 8000")
|
# ⚠ Port an deine Gesture-App anpassen:
|
||||||
|
# Dein gesture_input_osc sendet an 127.0.0.1:5005 → hier auch 5005
|
||||||
|
server = osc_server.ThreadingOSCUDPServer(("127.0.0.1", 5005), disp)
|
||||||
|
print("🔊 OSC server läuft auf Port 5005")
|
||||||
server.serve_forever()
|
server.serve_forever()
|
||||||
|
|
||||||
|
|
||||||
# Starte den OSC Listener im Hintergrund
|
# Starte den OSC Listener im Hintergrund
|
||||||
threading.Thread(target=start_osc_server, daemon=True).start()
|
threading.Thread(target=start_osc_server, daemon=True).start()
|
||||||
|
|
||||||
@ -50,9 +59,6 @@ BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
|||||||
BACKGROUND_FILE = os.path.join(BASE_DIR, "GlobalHintergrund.png")
|
BACKGROUND_FILE = os.path.join(BASE_DIR, "GlobalHintergrund.png")
|
||||||
|
|
||||||
|
|
||||||
# -------------------------------
|
|
||||||
# Helper: Card Back (Logo)
|
|
||||||
# -------------------------------
|
|
||||||
def build_card_back(image_path, size):
|
def build_card_back(image_path, size):
|
||||||
"""Load and scale a logo image to fill card backs."""
|
"""Load and scale a logo image to fill card backs."""
|
||||||
w, h = size
|
w, h = size
|
||||||
@ -71,9 +77,6 @@ def build_card_back(image_path, size):
|
|||||||
return surf
|
return surf
|
||||||
|
|
||||||
|
|
||||||
# -------------------------------
|
|
||||||
# Memory Game Class
|
|
||||||
# -------------------------------
|
|
||||||
class MemoryGame:
|
class MemoryGame:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# Game Data
|
# Game Data
|
||||||
@ -184,7 +187,7 @@ class MemoryGame:
|
|||||||
self.card_rects.append(pygame.Rect(x, y, card_width, card_height))
|
self.card_rects.append(pygame.Rect(x, y, card_width, card_height))
|
||||||
|
|
||||||
# -------------------------------
|
# -------------------------------
|
||||||
# Drawing Functions
|
# Drawing
|
||||||
# -------------------------------
|
# -------------------------------
|
||||||
def draw_menu(self, screen, title, options):
|
def draw_menu(self, screen, title, options):
|
||||||
screen.fill(BG_COLOR)
|
screen.fill(BG_COLOR)
|
||||||
@ -268,7 +271,8 @@ class MemoryGame:
|
|||||||
if option == "Americas":
|
if option == "Americas":
|
||||||
self.state = "americas"
|
self.state = "americas"
|
||||||
elif option == "All Continents":
|
elif option == "All Continents":
|
||||||
self.selected_continents = ["Europe", "Asia", "Africa", "Oceania", "North-America", "South-America"]
|
self.selected_continents = ["Europe", "Asia", "Africa",
|
||||||
|
"Oceania", "North-America", "South-America"]
|
||||||
self.state = "difficulty"
|
self.state = "difficulty"
|
||||||
else:
|
else:
|
||||||
self.selected_continents = [option]
|
self.selected_continents = [option]
|
||||||
@ -307,6 +311,26 @@ class MemoryGame:
|
|||||||
self.selected.append(i)
|
self.selected.append(i)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# -------------------------------
|
||||||
|
# OSC Input Processing
|
||||||
|
# -------------------------------
|
||||||
|
def process_osc_input(self):
|
||||||
|
"""Verarbeite die aktuellen OSC-Eingaben (Touch & Clap)."""
|
||||||
|
global touch_x, touch_y, clap_trigger
|
||||||
|
|
||||||
|
# TOUCH: als Klick ins Spiel
|
||||||
|
if touch_x is not None and touch_y is not None:
|
||||||
|
pos = (int(touch_x), int(touch_y))
|
||||||
|
self.handle_click(pos)
|
||||||
|
# Reset, damit es nicht mehrfach feuert
|
||||||
|
touch_x, touch_y = None, None
|
||||||
|
|
||||||
|
# CLAP: bestätige "Yes", wenn wir gerade fragen
|
||||||
|
if clap_trigger:
|
||||||
|
if self.awaiting_confirmation and self.confirmation_result is None:
|
||||||
|
self.confirmation_result = "yes"
|
||||||
|
clap_trigger = False
|
||||||
|
|
||||||
# -------------------------------
|
# -------------------------------
|
||||||
# Game Logic
|
# Game Logic
|
||||||
# -------------------------------
|
# -------------------------------
|
||||||
@ -370,7 +394,8 @@ class MemoryGame:
|
|||||||
else:
|
else:
|
||||||
text = "🤝 Draw!"
|
text = "🤝 Draw!"
|
||||||
win_text = self.font.render(text, True, (255, 255, 0))
|
win_text = self.font.render(text, True, (255, 255, 0))
|
||||||
screen.blit(win_text, win_text.get_rect(center=(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2)))
|
rect = win_text.get_rect(center=(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2))
|
||||||
|
screen.blit(win_text, rect)
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
|
||||||
# -------------------------------
|
# -------------------------------
|
||||||
@ -384,31 +409,23 @@ class MemoryGame:
|
|||||||
self.font = pygame.font.SysFont(None, 32)
|
self.font = pygame.font.SysFont(None, 32)
|
||||||
self.small_font = pygame.font.SysFont(None, 22)
|
self.small_font = pygame.font.SysFont(None, 22)
|
||||||
|
|
||||||
global touch_x, touch_y, clap_trigger
|
|
||||||
|
|
||||||
while self.running:
|
while self.running:
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
self.running = False
|
self.running = False
|
||||||
elif event.type == pygame.MOUSEBUTTONDOWN:
|
elif event.type == pygame.MOUSEBUTTONDOWN:
|
||||||
|
# Maus bleibt optional als Eingabe
|
||||||
self.handle_click(event.pos)
|
self.handle_click(event.pos)
|
||||||
|
|
||||||
# 👇 OSC-Eingaben integrieren
|
# 💡 HIER werden jetzt *jeden Frame* die OSC-Eingaben verarbeitet
|
||||||
if touch_x is not None:
|
self.process_osc_input()
|
||||||
self.handle_click((touch_x, touch_y))
|
|
||||||
touch_x, touch_y = None, None
|
|
||||||
|
|
||||||
if clap_trigger:
|
|
||||||
if self.awaiting_confirmation:
|
|
||||||
self.confirmation_result = "yes"
|
|
||||||
clap_trigger = False
|
|
||||||
|
|
||||||
# Menü- und Spiel-Rendering
|
|
||||||
|
|
||||||
|
# Menü + Spiel zeichnen
|
||||||
if self.state == "mode":
|
if self.state == "mode":
|
||||||
self.draw_menu(screen, "Select Player Mode", ["1 Player", "2 Players"])
|
self.draw_menu(screen, "Select Player Mode", ["1 Player", "2 Players"])
|
||||||
elif self.state == "continent":
|
elif self.state == "continent":
|
||||||
self.draw_menu(screen, "Select Continent", ["Europe", "Americas", "Asia", "Africa", "Oceania", "All Continents"])
|
self.draw_menu(screen, "Select Continent",
|
||||||
|
["Europe", "Americas", "Asia", "Africa", "Oceania", "All Continents"])
|
||||||
elif self.state == "americas":
|
elif self.state == "americas":
|
||||||
self.draw_menu(screen, "Select Region", ["North-America", "South-America", "Americas"])
|
self.draw_menu(screen, "Select Region", ["North-America", "South-America", "Americas"])
|
||||||
elif self.state == "difficulty":
|
elif self.state == "difficulty":
|
||||||
@ -430,20 +447,6 @@ class MemoryGame:
|
|||||||
pygame.quit()
|
pygame.quit()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
def display_winner(self, screen):
|
|
||||||
if self.player_mode == 1:
|
|
||||||
text = f"🏆 Final Score: {self.scores[0]}"
|
|
||||||
else:
|
|
||||||
if self.scores[0] > self.scores[1]:
|
|
||||||
text = "🏆 Player 1 Wins!"
|
|
||||||
elif self.scores[1] > self.scores[0]:
|
|
||||||
text = "🏆 Player 2 Wins!"
|
|
||||||
else:
|
|
||||||
text = "🤝 Draw!"
|
|
||||||
win_text = self.font.render(text, True, (255, 255, 0))
|
|
||||||
rect = win_text.get_rect(center=(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2))
|
|
||||||
screen.blit(win_text, rect)
|
|
||||||
|
|
||||||
|
|
||||||
# -------------------------------
|
# -------------------------------
|
||||||
# Run
|
# Run
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user