Python
import pygame as g from color import* RED = (255, 0, 0) BLACK = (0, 0, 0) WHITE = (255, 255, 255) GREEN = (0, 255, 0) BLUE = (0, 0, 255) YELLOW = (255, 255, 0) SILVER = (192, 192, 192) GRAY = (128, 128, 128) ORANGE = (255, 128, 0) CYAN = (0, 255, 255) PURPLE = (255, 0, 255) g.init() BLOCKWIDTH = 75 FPS = 30 pos_=[] di = g.image.load("diamond_block.png") diamond_block = g.transform.scale(di, (BLOCKWIDTH, BLOCKWIDTH)) screen = g.display.set_mode((BLOCKWIDTH * 12, BLOCKWIDTH * 10)) g.display.set_caption("block's break and put") clock = g.time.Clock() def draw(ray,H): for i in range(len(ray)): screen.blit(diamond_block, (ray[i][0], ray[i][1])) #g.draw.rect(screen, BLACK,(ray[i][0], ray[i][1], H, H)) def pos(a, H): return a // H * H def clicked(H): global pos_ click = g.mouse.get_pressed() draw(pos_, H) if click[2] == 1: x1, y1 = g.mouse.get_pos() x1 = pos(x1, H) y1 = pos(y1, H) where = list((x1, y1)) if where not in pos_: pos_.append(where) if click[0] == 1: x1, y1 = g.mouse.get_pos() x1 = pos(x1, H) y1 = pos(y1, H) where = list((x1, y1)) if where in pos_: pos_.remove(where) def chose(H): x, y = g.mouse.get_pos() x = pos(x, H) y = pos(y, H) g.draw.rect(screen, RED,(x, y, H, H), 2) run=True while run: for event in g.event.get(): if event.type == g.QUIT: run = False elif event.type == g.KEYDOWN: if event.key == g.K_ESCAPE: pos_ = [] screen.fill g.mouse.set_visible(False) screen.fill(WHITE) clicked(BLOCKWIDTH) chose(BLOCKWIDTH) clock.tick(FPS) g.display.flip() g.quit()