-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.py
More file actions
64 lines (55 loc) · 1.98 KB
/
Main.py
File metadata and controls
64 lines (55 loc) · 1.98 KB
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
63
64
import pygame as pyg
from PongFramework import *
pyg.init()
#Initialise game manager, screen, and allowed events
screenSize = Vector2(1400, 800)
screenCaption = "Pong"
allowedEvents = [pyg.QUIT, pyg.MOUSEBUTTONUP, pyg.MOUSEBUTTONDOWN, pyg.MOUSEMOTION, pyg.KEYDOWN, pyg.KEYUP]
fps = 30
GM = PongGM(screenSize, screenCaption, allowedEvents)
GM.winBGColour = Colour.black
#main game loop
while True:
GM.clock.tick(fps)
#check for pygame events
for event in pyg.event.get():
if event.type == pyg.QUIT:
sys.exit()
elif event.type == pyg.MOUSEMOTION:
mouseX, mouseY = event.pos
GM.mousePos = Vector2(mouseX, mouseY)
elif event.type == pyg.MOUSEBUTTONDOWN:
if event.button == 1:
mouseX, mouseY = event.pos
GM.mousePos = Vector2(mouseX, mouseY)
GM.mouseDown = True
elif event.type == pyg.MOUSEBUTTONUP:
if event.button == 1:
mouseX, mouseY = event.pos
GM.mousePos = Vector2(mouseX, mouseY)
GM.mouseDown = False
elif event.type == pyg.KEYDOWN:
if event.key == pyg.K_ESCAPE:
sys.exit()
elif event.key == pyg.K_w:
GM.wDown = True
elif event.key == pyg.K_s:
GM.sDown = True
elif event.key == pyg.K_UP:
GM.upDown = True
elif event.key == pyg.K_DOWN:
GM.downDown = True
elif event.type == pyg.KEYUP:
if event.key == pyg.K_w:
GM.wDown = False
elif event.key == pyg.K_s:
GM.sDown = False
elif event.key == pyg.K_UP:
GM.upDown = False
elif event.key == pyg.K_DOWN:
GM.downDown = False
GM.UpdateScripts()
GM.CastRigidBodies()
GM.UpdateCollisions()
GM.MoveRigidBodies()
GM.UpdateWindow()