mirror of
https://github.com/ApfelTeeSaft/WarioWare-Black-and-WAH.git
synced 2026-08-26 19:33:45 +00:00
85 lines
3.0 KiB
Python
85 lines
3.0 KiB
Python
# microgames/ninevolt/pixel_paint.py
|
|
import pygame
|
|
from engine.scene import Scene
|
|
from settings import *
|
|
|
|
class PixelPaint(Scene):
|
|
def __init__(self, manager):
|
|
super().__init__(manager)
|
|
self.prompt = "Paint the pixels!"
|
|
self.grid_size = 8
|
|
self.pixels = []
|
|
self.pixels_to_paint = 0
|
|
self.timer = 5.0 / self.manager.speed
|
|
self.state = "playing"
|
|
self.end_timer = 2.0
|
|
|
|
def start(self):
|
|
self.timer = 5.0 / self.manager.speed
|
|
self.state = "playing"
|
|
self.end_timer = 2.0
|
|
self.pixels = []
|
|
self.pixels_to_paint = 0
|
|
|
|
pixel_size = 30
|
|
grid_width = self.grid_size * pixel_size
|
|
grid_height = self.grid_size * pixel_size
|
|
start_x = (SCREEN_WIDTH - grid_width) // 2
|
|
start_y = (SCREEN_HEIGHT - grid_height) // 2
|
|
|
|
for i in range(self.grid_size * self.grid_size):
|
|
row = i // self.grid_size
|
|
col = i % self.grid_size
|
|
x = start_x + col * pixel_size
|
|
y = start_y + row * pixel_size
|
|
rect = pygame.Rect(x, y, pixel_size, pixel_size)
|
|
# Simple heart shape
|
|
if (row == 1 and col in [2, 5]) or \
|
|
(row == 2 and col in [1, 3, 4, 6]) or \
|
|
(row == 3 and col in [1, 2, 3, 4, 5, 6]) or \
|
|
(row == 4 and col in [2, 3, 4, 5]) or \
|
|
(row == 5 and col in [3, 4]):
|
|
self.pixels.append({"rect": rect, "painted": False})
|
|
self.pixels_to_paint += 1
|
|
else:
|
|
self.pixels.append({"rect": rect, "painted": True}) # Already painted
|
|
|
|
def update(self, dt, time_left=None):
|
|
if self.state == "playing":
|
|
if time_left is not None and time_left <= 0:
|
|
self.end(False) # Failure due to timeout
|
|
|
|
mouse_pos = pygame.mouse.get_pos()
|
|
mouse_pressed = pygame.mouse.get_pressed()
|
|
|
|
if mouse_pressed[0]:
|
|
for pixel in self.pixels:
|
|
if not pixel["painted"] and pixel["rect"].collidepoint(mouse_pos):
|
|
pixel["painted"] = True
|
|
self.pixels_to_paint -= 1
|
|
if self.pixels_to_paint == 0:
|
|
self.end(True)
|
|
elif self.state == "success" or self.state == "failure":
|
|
self.end_timer -= dt
|
|
if self.end_timer <= 0:
|
|
self.manager.microgame_finished(self.state == "success", 'ninevolt')
|
|
|
|
def draw(self, screen):
|
|
screen.fill(NINEVOLT_BG_COLOR)
|
|
|
|
if self.state == "playing":
|
|
# Draw pixels
|
|
for pixel in self.pixels:
|
|
color = RED if pixel["painted"] else (50, 50, 50)
|
|
pygame.draw.rect(screen, color, pixel["rect"])
|
|
pygame.draw.rect(screen, BLACK, pixel["rect"], 1)
|
|
|
|
# Timer is now drawn by GameManager
|
|
pass
|
|
|
|
def end(self, success):
|
|
if success:
|
|
self.state = "success"
|
|
else:
|
|
self.state = "failure"
|