[go: up one dir, main page]

0% found this document useful (0 votes)
14 views3 pages

4 Objects

This document is a Python script using Pygame to create a simple graphical application. It initializes a window and allows for the movement of four circles using keyboard inputs. Each circle is controlled by different keys, and the program continuously updates the screen based on user input until the window is closed.

Uploaded by

aleixboves10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

4 Objects

This document is a Python script using Pygame to create a simple graphical application. It initializes a window and allows for the movement of four circles using keyboard inputs. Each circle is controlled by different keys, and the program continuously updates the screen based on user input until the window is closed.

Uploaded by

aleixboves10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

import pygame, sys

pygame. init()

black = (0,0,0)
white = (255,255, 255)
red = (255,0,0)
blue = (0,0,255)
green = (0,255,0)
size = (800, 500)
screen = pygame.display.set_mode (size)
clock = pygame.time.Clock()

pygame.mouse.set_visible(0)

coord_x = 10
coord_y = 10
coord_x1 = 790
coord_y1 = 10
coord_x2 = 10
coord_y2 = 490
coord_x3 = 790
coord_y3 = 490
x_speed = 0
y_speed = 0

x_speed1 = 0
y_speed1 = 0
x_speed2 = 0
y_speed2 = 0
x_speed3 = 0
y_speed3 = 0
while True:
for event in pygame.event.get():
if event.type == pygame. QUIT:
sys. exit()

if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
x_speed = -3
if event.key == pygame.K_RIGHT:
x_speed = 3
if event.key == pygame.K_UP:
y_speed = -3
if event.key == pygame.K_DOWN:
y_speed = 3

if event.key == pygame.K_a:
x_speed1 = -3
if event.key == pygame.K_d:
x_speed1 = 3
if event.key == pygame.K_w:
y_speed1 = -3
if event.key == pygame.K_s:
y_speed1 = 3

if event.key == pygame.K_f:
x_speed2 = -3
if event.key == pygame.K_h:
x_speed2 = 3
if event.key == pygame.K_t:
y_speed2 = -3
if event.key == pygame.K_g:
y_speed2 = 3

if event.key == pygame.K_j:
x_speed3 = -3
if event.key == pygame.K_l:
x_speed3 = 3
if event.key == pygame.K_i:
y_speed3 = -3
if event.key == pygame.K_k:
y_speed3 = 3
if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT:
x_speed = 0
if event.key == pygame.K_RIGHT:
x_speed = 0
if event.key == pygame.K_UP:
y_speed = 0
if event.key == pygame.K_DOWN:
y_speed = 0

if event.key == pygame.K_a:
x_speed1 = 0
if event.key == pygame.K_d:
x_speed1 = 0
if event.key == pygame.K_w:
y_speed1 = 0
if event.key == pygame.K_s:
y_speed1 = 0

if event.key == pygame.K_f:
x_speed2 = 0
if event.key == pygame.K_h:
x_speed2 = 0
if event.key == pygame.K_t:
y_speed2 = 0
if event.key == pygame.K_g:
y_speed2 = 0

if event.key == pygame.K_j:
x_speed3 = 0
if event.key == pygame.K_l:
x_speed3 = 0
if event.key == pygame.K_i:
y_speed3 = 0
if event.key == pygame.K_k:
y_speed3 = 0

screen. fill(white)
coord_x += x_speed
coord_y += y_speed
pygame.draw.circle(screen, red, (coord_x, coord_y),50)
coord_x1 += x_speed1
coord_y1 += y_speed1
pygame.draw.circle(screen, black, (coord_x1, coord_y1),50)
coord_x2 += x_speed2
coord_y2 += y_speed2
pygame.draw.circle(screen, green, (coord_x2, coord_y2),50)
coord_x3 += x_speed3
coord_y3 += y_speed3
pygame.draw.circle(screen, blue, (coord_x3, coord_y3),50)
pygame. display.flip()
clock.tick(60)

You might also like