-
Notifications
You must be signed in to change notification settings - Fork 0
/
testing.py
62 lines (48 loc) · 1.31 KB
/
testing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import pygame
import random
import pygame as pg
from pygame.locals import *
from pygame import Surface
pygame.init()
running = True
screen = pygame.display.set_mode((800, 600))
ballIMG = pygame.image.load('ball.png')
pygame.display.set_caption('PONG')
pygame.display.set_icon(ballIMG)
iY = 300
fY = random.randint(0, 600)
iX = 400
fX = 0
px = 10
py = 300
ex = 770
ey = 300
pYspeed = 2
counter = 0
balldir = 'left'
# ball
def ball(x, y):
ball = pygame.Rect(x, y, 32, 32)
screen.blit(ballIMG, ball)
while running:
screen.fill((0, 0, 0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
startV = pygame.Vector2(iX, iY)
finalV = pygame.Vector2(fX, fY)
if counter < 500:
progress = counter / 500
currentV = startV.lerp(finalV, progress)
counter += 1
player_rect = Rect(px, py, 20, 100)
enem_rect = Rect(ex, ey, 20, 100)
keys = pygame.key.get_pressed()
if keys[pygame.K_UP] and py > 0:
py -= pYspeed
if keys[pygame.K_DOWN] and py < 600 - 100:
py += pYspeed
pygame.draw.rect(screen, (255, 255, 255), player_rect)
pygame.draw.rect(screen, (255, 255, 255), enem_rect)
screen.blit(ballIMG, currentV)
pygame.display.update()