from machine import Pin, SPI from tft import TFT_GREEN _init() machine.freq(160000000) dc = Pin(4, Pin.OUT) #a0 cs = Pin(2, Pin.OUT) rst = Pin(5, Pin.OUT) spi = SPI(1, baudrate=40000000, polarity=0, phase=0) # TFT object, this is ST7735R green tab version tft = TFT_GREEN(128, 160, spi, dc, cs, rst, rotate=0) Map = [ [1,1,0,1,1,1,0,1], [0,1,1,1,1,1,1,0], [1,1,0,0,0,1,1,1], [0,1,0,1,0,1,0,1], [0,1,0,0,0,1,0,1], [1,1,1,1,0,0,0,1], [1,0,0,0,0,0,0,1], [1,0,0,0,1,0,0,1], [1,0,0,0,1,1,1,1], [1,1,1,1,1,0,0,0] ] Gates = [] Boxes = [] class Box: def __init__(self, tft, x, y): self.tft = tft self.x = x self.y = y self.picture = 'box.bmp' self.picture_onGate = 'boxngate.bmp' self.onGate = False self.draw() def draw(self): if (self.onGate): self.tft.draw_bmp(self.x * 16,self.y * 16, self.picture_onGate) else: self.tft.draw_bmp(self.x * 16,self.y * 16, self.picture) def setOnGate(self, state): self.onGate = state def getOnGate(self): return self.onGate def getPos(self): return (self.x, self.y) def setPos(self, x, y): self.x = x self.y = y self.draw() class Gate: def __init__(self, tft, x, y): self.tft = tft self.x = x self.y = y self.picture = 'gate.bmp' self.draw() def draw(self): self.tft.draw_bmp(self.x * 16,self.y * 16, self.picture) def getPos(self): return (self.x, self.y) class Man: def __init__(self, tft, x, y): self.tft = tft self.x = x self.y = y self.picture = 'man.bmp' self.draw() def draw(self): self.tft.draw_bmp(self.x * 16,self.y * 16, self.picture) def getPos(self): return (self.x, self.y) def setPos(self, x, y): self.tft.rect(self.x * 16, self.y * 16, 16, 16, tft.COLOR_BLACK) self.x = x self.y = y self.draw() # init TFT tft.initr(tft.BGR) # tft.initr(tft.RGB) #Если вместо синего цвета отображается красный, а вместо красного синий tft.clear(tft.COLOR_BLACK) #b, g, r x = 0 y = 0 for row in Map: for col in row: if col: tft.draw_bmp(x * 16, y * 16,'brick.bmp') x+=1 x=0 y+=1 Boxes.append(Box(tft, 3,4)) Boxes.append(Box(tft, 4,6)) Boxes.append(Box(tft, 2,7)) Gates.append(Gate(tft, 6,3)) Gates.append(Gate(tft, 6,4)) Gates.append(Gate(tft, 6,5)) man = Man(tft, 5, 6)