from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
# Configuración del display SSD1306
i2c = I2C(0, scl=Pin(5), sda=Pin(4), freq=400000)
oled = SSD1306_I2C(128, 64, i2c)
# Nivel Sokoban de 12x9 con bloques de 7x7 píxeles
nivel = [
[2,2,2,2,2, 2,2,2,0,0,0,0],
[2,0,0,0,2, 0,0,0,2,2,2,0],
[2,0,0,3,0, 0,3,0,0,0,2,0],
[0,2,2,2,2, 3,0,0,0,0,2,0],
[0,2,0,0,0, 1,0,0,3,0,2,0],
[0,2,4,4,3, 0,3,0,0,0,2,0],
[0,2,4,4,0, 2,0,0,0,0,2,0],
[0,2,4,4,2, 2,2,2,2,2,2,0],
[0,2,2,2,2, 0,0,0,0,0,0,0]
]
CELDA = 7
def dibujar_rombo(oled, x, y):
oled.pixel(x+3, y, 1)
oled.pixel(x+2, y+1, 1)
oled.pixel(x+4, y+1, 1)
oled.pixel(x+1, y+2, 1)
oled.pixel(x+5, y+2, 1)
oled.pixel(x+2, y+3, 1)
oled.pixel(x+4, y+3, 1)
oled.pixel(x+3, y+4, 1)
def dibujar_caja(oled, x, y):
for i in range(CELDA):
oled.pixel(x+i, y, 1)
oled.pixel(x+i, y+CELDA-1, 1)
oled.pixel(x, y+i, 1)
oled.pixel(x+CELDA-1, y+i, 1)
oled.pixel(x+3, y+3, 1)
def dibujar_jugador(oled, x, y):
oled.pixel(x+2, y+3, 1)
oled.pixel(x+3, y+2, 1)
oled.pixel(x+3, y+3, 1)
oled.pixel(x+3, y+4, 1)
oled.pixel(x+4, y+3, 1)
# Dibujar el nivel en pantalla
oled.fill(0)
for j in range(9):
for i in range(12):
val = nivel[j][i]
x = i * CELDA
y = j * CELDA
if val == 1:
dibujar_jugador(oled, x, y)
elif val == 2:
oled.fill_rect(x, y, CELDA, CELDA, 1)
elif val == 3:
dibujar_caja(oled, x, y)
elif val == 4:
dibujar_rombo(oled, x, y)
oled.show()