-
-
Save nst/29c68f8f2f68a0a65109e2995ea8dbf9 to your computer and use it in GitHub Desktop.
Titou
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame | |
pygame.init() | |
# 1 = en haut à droite | |
# 2 = en bas à droite | |
# 3 = en bas à gauche | |
# 4 = en haut à gauche | |
l_écran = 400 | |
h_écran = 300 | |
direction = 2 | |
x1 = 0 | |
y1 = 0 | |
x2 = 30 | |
y2 = 60 | |
screen = pygame.display.set_mode((l_écran,h_écran)) | |
while True: | |
screen.fill((0,0,0)) | |
pygame.draw.line(screen, (255,0,0), (x1,y1), (x2,y2), (7)) | |
pygame.display.update() | |
for event in pygame.event.get(): | |
if event.type == pygame.QUIT: | |
pygame.quit() | |
if direction == 1 and y1 <= 0: | |
direction = 2 | |
elif direction == 1 and x2 >= l_écran: | |
direction = 4 | |
elif direction == 2 and y2 >= h_écran: | |
direction = 1 | |
elif direction == 2 and x2 >= l_écran: | |
direction = 3 | |
elif direction == 3 and y2 >= h_écran: | |
direction = 4 | |
elif direction == 3 and x1 <= 0: | |
direction = 2 | |
elif direction == 4 and x1 <= 0: | |
direction = 1 | |
elif direction == 4 and y1 <= 0: | |
direction = 3 | |
if direction == 1: | |
x1 += 3 | |
y1 -= 3 | |
x2 += 3 | |
y2 -= 3 | |
elif direction == 2: | |
x1 += 3 | |
y1 += 3 | |
x2 += 3 | |
y2 += 3 | |
elif direction == 3: | |
x1 -= 3 | |
y1 += 3 | |
x2 -= 3 | |
y2 += 3 | |
elif direction == 4: | |
x1 -= 3 | |
y1 -= 3 | |
x2 -= 3 | |
y2 -= 3 | |
pygame.time.delay(100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment