-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
40 lines (31 loc) · 944 Bytes
/
main.py
File metadata and controls
40 lines (31 loc) · 944 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
32
33
34
35
36
37
38
39
40
"""
Section 4: Scoring & Full Game Loop.
This section introduces:
- Player paddle movement (W/S or Up/Down keys).
- Opponent paddle (simple CPU that follows the ball).
- Ball collisions with paddles.
- Ball reset when leaving the screen.
Press 1 to switch to the Menu state.
Press 2 to switch to the Game state.
Press SPACE to start the ball once in the Game state.
As is, the CPU cannot lose. In Section 5, we will address this in a few ways
"""
import pygame
from game import Game
def main():
pygame.init()
screen = pygame.display.set_mode((1280, 720))
clock = pygame.time.Clock()
running = True
game = Game()
while running:
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT:
running = False
game.run(events, screen)
pygame.display.flip()
clock.tick(60)
pygame.quit()
if __name__ == "__main__":
main()