import pygame
import sys
pygame.init()
weight=550
height=400
screen = pygame.display.set_mode((weight,height))
image=pygame.image.load("Capture.jpg").convert()
ix= 70
iy = 80
speed =10
imageplace = screen.blit(image,(ix,iy))
pygame.display.update()
running=True
while running:
for event in pygame.event.get():
pygame.time.delay(10)
if event.type == pygame.QUIT:
running=False
keys=pygame.key.get_pressed()
if event.type == pygame.MOUSEBUTTONDOWN:
pos = pygame.mouse.get_pos()
pos_x = pos[0]
pos_y = pos[1]
if (keys[pygame.K_LEFT] or keys[pygame.K_a]) and ix > 0:
ix-=speed
if (keys[pygame.K_RIGHT] or keys[pygame.K_d]) and ix > 0:
ix+=speed
if (keys[pygame.K_UP] or keys[pygame.K_w]) and ix > 0:
iy-=speed
if (keys[pygame.K_DOWN] or keys[pygame.K_s]) and ix > 0:
iy+=speed
if imageplace.collidepoint(pos_x,pos_y):
print("You have clicked on button")
else:
print("Wrong Direction")
I tried to move an image with pygame but it didn't work. I am new at this. I couldn't find anything on internet and I didn't understand it.