MCPcopy Index your code
hub / github.com/geekcomputers/Python / Slab

Class Slab

PingPong/Slab.py:6–41  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4
5
6class Slab:
7 def __init__(self, win, size, pos, player, minPos, maxPos):
8 self.win = win
9 self.size = size
10 self.pos = pos
11 self.player = player # player = 1 or 2
12 self.minPos = minPos
13 self.maxPos = maxPos
14
15 def draw(self):
16 pygame.draw.rect(
17 self.win,
18 (255, 255, 255),
19 (self.pos[0], self.pos[1], self.size[0], self.size[1]),
20 )
21
22 def getCoords(self):
23 return [
24 self.pos[0],
25 self.pos[1],
26 self.pos[0] + self.size[0],
27 self.pos[1] + self.size[1],
28 ]
29
30 def updatePos(self):
31 keys = pygame.key.get_pressed()
32 if self.player == 1:
33 if keys[pygame.K_UP] and self.getCoords()[1] > self.minPos[1]:
34 self.pos[1] -= 0.3
35 if keys[pygame.K_DOWN] and self.getCoords()[3] < self.maxPos[1]:
36 self.pos[1] += 0.3
37 else:
38 if keys[pygame.K_w] and self.getCoords()[1] > self.minPos[1]:
39 self.pos[1] -= 0.3
40 if keys[pygame.K_s] and self.getCoords()[3] < self.maxPos[1]:
41 self.pos[1] += 0.3

Callers 1

main.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected