Fix menu crash: - Add back MenuItem.draw method - Remove duplicate MenuItem class - Fix menu item imports
This commit is contained in:
parent
d1fb3a58b4
commit
251822ec35
31
src/game.py
31
src/game.py
@ -3,7 +3,7 @@ import sys
|
||||
from enum import Enum, auto
|
||||
from src.snake import Snake, Direction
|
||||
from src.food import Food
|
||||
from src.menu import Menu, GameMode
|
||||
from src.menu import Menu, GameMode, MenuItem
|
||||
|
||||
class GameState(Enum):
|
||||
MENU = auto()
|
||||
@ -19,35 +19,6 @@ class GameRules:
|
||||
self.min_move_cooldown = 50 # Minimum movement delay in milliseconds
|
||||
self.initial_move_cooldown = 100 # Initial movement delay
|
||||
|
||||
class MenuItem:
|
||||
def __init__(self, text, position, action, size=36, color=(255, 255, 255)):
|
||||
self.text = text
|
||||
self.position = position
|
||||
self.action = action
|
||||
self.size = size
|
||||
self.default_color = color
|
||||
self.color = color
|
||||
self.hover = False
|
||||
self._setup_font()
|
||||
|
||||
def _setup_font(self):
|
||||
self.font = pygame.font.Font(None, self.size)
|
||||
self.surface = self.font.render(self.text, True, self.color)
|
||||
self.rect = self.surface.get_rect(center=self.position)
|
||||
|
||||
def update_hover(self, mouse_pos):
|
||||
old_hover = self.hover
|
||||
self.hover = self.rect.collidepoint(mouse_pos)
|
||||
if self.hover:
|
||||
self.color = (255, 255, 0) # Yellow on hover
|
||||
else:
|
||||
self.color = self.default_color
|
||||
if old_hover != self.hover:
|
||||
self._setup_font()
|
||||
|
||||
def draw(self, screen):
|
||||
screen.blit(self.surface, self.rect)
|
||||
|
||||
class SettingsMenu:
|
||||
def __init__(self, width, height, rules):
|
||||
self.width = width
|
||||
|
@ -34,6 +34,10 @@ class MenuItem:
|
||||
self.hover = self.rect.collidepoint(mouse_pos)
|
||||
if old_hover != self.hover:
|
||||
self._setup_font()
|
||||
|
||||
def draw(self, screen):
|
||||
"""Draw the menu item on the screen"""
|
||||
screen.blit(self.surface, self.rect)
|
||||
|
||||
class Menu:
|
||||
def __init__(self, width, height):
|
||||
|
Loading…
Reference in New Issue
Block a user