Deutsch   English   Français   Italiano  
<QK2dnfQMAacl8Rv8nZ2dnUU7983NnZ2d@giganews.com>

View for Bookmarking (what is this?)
Look up another Usenet article

X-Received: by 2002:a1c:4d0b:: with SMTP id o11mr37040592wmh.68.1636199608925;
        Sat, 06 Nov 2021 04:53:28 -0700 (PDT)
MIME-Version: 1.0
Path: ...!buffer2.nntp.ams1.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Sat, 06 Nov 2021 06:53:28 -0500
Newsgroups: fr.comp.lang.python
Subject: Déplacement joueur problème
X-poster: PEAR::Net_NNTP v1.5.0 (stable)
From: ThomasPython <nospam_thomaspython8@gmail.com.invalid>
Organization: !No_Organization!
Message-ID: <QK2dnfQMAacl8Rv8nZ2dnUU7983NnZ2d@giganews.com>
Date: Sat, 06 Nov 2021 06:53:28 -0500
Lines: 62
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-mR9ALDY2NXKbKrYT/u9wu1DkfJX+ri8soa+UHcYLNyrJIc2NEXrm5JnSz74CKwTctSys8wDaSs+Owzk!ToDxs4kcJr4YVh8TeQGSkF3wI/LuSBraYz4dhKFBG6QBxtGxYRxD8Fa6oBvAem1tZBe9IVKFHNkU
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
Bytes: 2757
X-Original-Bytes: 2384
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 8bit

Bonjour,

Je n'arrive pas à déplacer mon jouer dans le jeux suivant : 
le problème est-il dans la définition de keys ? 
Merci par avance pour vos réponses

import pygame

pygame.init()
win = pygame.display.set_mode((1280,720))
pygame.display.set_caption("e;Jeux"e;)

x = 600
y = 600
baddyX = 400
baddyY = 400
vel = 6
baddyVel = 4
run = True
keys = pygame.key.get_pressed()

def drawGame():
    win.fill((0,0,0))
    pygame.draw.rect(win, (0,0,255), (x,y,20,20))
    pygame.draw.rect(win,(255,0,0),(baddyX,baddyY,40,40))
    pygame.display.update()

while run :
    pygame.time.delay(100)
    if baddyX < x - 10 :
        baddyX = baddyX + baddyVel
        drawGame()
    elif baddyX > x + 10 :
        baddyX = baddyX - baddyVel
        drawGame()
    elif baddyY < y - 10 :
        baddyY = baddyY + baddyVel
        drawGame()
    elif baddyY > y + 10 :
        baddyY = baddyY - baddyVel
        drawGame()
    else:
        run = False

for event in pygame.event.get():
    if event.type == pygame.QUIT:
        run = False

keys = pygame.key.get_pressed()

if keys[pygame.K_a]:
    x = x-vel
    drawGame()

if keys[pygame.K_b]:
    x = x + vel
    drawGame()
if keys[pygame.K_UP]:
    y -= vel

if keys[pygame.K_DOWN]:
    y += vel