В моем коде ниже я бы хотел, чтобы при нажатии на квадрат в «меню» ниже, он воспроизводился в «рабочей области» (верхняя часть) в том месте, где мы будем щелкать. Но на данный момент он только перемещает квадрат одновременно с мышью.
Я не могу решить эту проблему, не могли бы вы мне помочь, пожалуйста?
приветливо
import pygame
from pygame.locals import *
pygame.init()
#window
window = pygame.display.set_mode([1000,800])
pygame.display.set_caption("ArchiConnect World")
#constantes
clickable_area = pygame.Rect((100,720), (70, 70))
clickable_area2 = pygame.Rect((100,500), (70, 70))
clickable_area3 = pygame.Rect((220,730), (50, 50))
clickable_area4 = pygame.Rect((300, 450), (50, 50))
hold = 0;
#colors
GREEN = (84,173,65)
RED = (255,0,0)
BLUE = (0,0,255)
YELLOW = (255,255,0)
rect_draw = 0
x = 100
y = 500
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
event.pos = pygame.mouse.get_pos();
#menu rectangle
pygame.draw.rect(window, (BLUE), Rect((0,700), (1000,10)))
#server rectangle
pygame.draw.rect(window, (GREEN), Rect((100,720), (70,70)))
#server rectangle in board
if event.type == MOUSEBUTTONUP:
if event.button == 1:
if clickable_area.collidepoint(event.pos):
hold =1
if event.type == MOUSEMOTION: # Si mouvement de souris
# On change les coordonnées du
if hold == 1:
carre_x = event.pos[0]
carre_y = event.pos[1]
pygame.draw.rect(window, (GREEN), Rect((carre_x, carre_y), (70,70)))
pygame.display.update()