forked from GabrielPinango/Pong_Pygame
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbat2.py
More file actions
31 lines (27 loc) · 686 Bytes
/
bat2.py
File metadata and controls
31 lines (27 loc) · 686 Bytes
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
import pygame
from pygame.locals import *
from ball import pelota
def cargar_img(nombre):
try:
img = pygame.image.load(nombre)
except:
print 'no se puede cargar la imagen' +str(nombre)
return img
class raqueta_dos(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = cargar_img('raqueta2.png')
self.rect = self.image.get_rect()
self.rect.center = (620, 240)
def update(self):
keys = pygame.key.get_pressed()
if keys[K_DOWN]:
self.rect.y += 6
if keys[K_UP] :
self.rect.y -= 6
self.control()
def control(self):
if self.rect.top <=0:
self.rect.top = 0
if self.rect.bottom >=480:
self.rect.bottom = 480