I'm making a simple game with pygame where I wanted to move a picture, but that picture seems to be made every time it clicks, and it's not what I want at all, I want to move it by pressing a key, but every time Moves one is made
Code:
# import modules
import pygame
from pygame.locals import *
import sys
import os
#################
pygame.init()
#################
#Colors
red = (255 , 0 , 0) # RED
green = (0, 255, 0) # GREEN
blue = (10, 60, 225) # BLUE
white = (255, 255, 255) # WHITE
black = (0, 0, 0) # BLACK
# window
window = pygame.display.set_mode((600, 400)) # window size
pygame.display.set_caption("Ball away") # title
window.fill(white) # backgrond color
img = pygame.image.load("bin/images/icon.png") # window icon
pygame.display.set_icon(img) # load icon
# screen
#lines
lineup = pygame.draw.line(window, black, (0,35), (100000,0),4)
linedown = pygame.draw.line(window, black, (0,350), (1000000,4),4)
#TEXTS
ping_text = "Ping : 50"
font = pygame.font.SysFont(None, 25)
t_p = font.render(ping_text, True, (0, 0, 0))
window.blit(t_p, (515, 10))
count_win = "0 - 0"
font = pygame.font.SysFont(None, 30)
c_w = font.render(count_win, True, (0, 0, 0))
window.blit(c_w, (284, 10))
exit_ico = pygame.image.load("bin/images/exit.png")
exit_i = pygame.transform.scale(exit_ico,(30, 30))
window.blit(exit_i , (3, 3))
# players
# RED
P1_x = 3
P1_y = 140
speed = 5
Player_RED = pygame.image.load("bin/images/Player1_RED.png")
player1_red = pygame.transform.scale(Player_RED,(80, 85))
# BLUE
P2_x = 520
P2_y = 145
speed = 5
Player_BLUE = pygame.image.load("bin/images/Player2_BLUE.png")
player2_blue = pygame.transform.scale(Player_BLUE,(80, 85))
# ball
Ball_lets = pygame.transform.scale(img,(35,35))
window.blit(Ball_lets, (300, 170))
# soundObj = pygame.mixer.Sound('bin/sounds/Music.mp3')
# soundObj.play()
# main loop
running = True
while running:
for event in pygame.event.get():
if event.type == QUIT:
os.system('cls')
running = False
if event.type == KEYUP:
if event.key == K_w:
P1_y -= speed
if event.key == K_s:
P1_y += speed
window.blit(player1_red, (P1_x, P1_y))
if event.type == KEYUP:
if event.key == K_UP:
P2_y -= speed
if event.key == K_DOWN:
P2_y += speed
window.blit(player2_blue, (P2_x, P2_y))
pygame.display.update()
pygame.quit()
sys.exit()
Indentations are not my problem, I am a newbie to stackoverflow
please help