#pygame logic

2 messages · Page 1 of 1 (latest)

celest crag
#

I started learning pygame now and i have one question about my code, i dont know what is wrong whith my logic i think migth someone can help me and give the feedback, my main goal is to make the drawing moving in a loop and if i press A the loop will stop

import pygame
import random
from pygame.locals import *

pygame.init()
largura = 680
altura = 480
x = random.randint(0,680)
y = random.randint(0,480)

tela = pygame.display.set_mode((largura, altura))
clock = pygame.time.Clock()
rodando = True

while rodando:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
rodando = False

movimento = True
while movimento:
 movimento = x = x + 3
if event.type == KEYDOWN:
        if event.key == K_a:  
            movimento = False

if y >= altura:
    y = 0
if x >= largura:
    x = 0

tela.fill([0, 0, 0])
pygame.draw.rect(tela, (255,250,255),(x,y,20,50))
   
# jogo vai até aqui
pygame.display.update()

pygame.quit()

cunning depot
#

You never break out of the rodando loop?