-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.py
103 lines (76 loc) · 2.52 KB
/
Main.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import pygame
import random
pygame.init()
screen = pygame.display.set_mode((720,720))
pygame.display.set_caption("PyGolf")
running = True
gameObjects = []
class Transform():
pos = [0, 0]
class Time():
getTicksLastFrame = 0
deltaTime = 1
t = 0
def __init__(self):
gameObjects.append(self)
def update(self):
self.t = pygame.time.get_ticks()
self.deltaTime = (self.t - self.getTicksLastFrame) / 1000.0
self.getTicksLastFrame = self.t
Time = Time()
class Circle():
radius = 0
color = [0, 0, 0]
def __init__(self, radius, color):
self.radius = radius
self.color = color
def draw(self, pos):
pygame.draw.circle(screen, self.color, (pos[0] + self.radius, pos[1] + self.radius), self.radius, 5)
class obj():
transform = Transform()
class PlayerController():
gameObject = obj()
vel = [200,150]
def move(self, x, y):
gameObject.transform.pos = [self.transform.pos[0] + (x * Time.deltaTime), self.transform.pos[1] + (y * Time.deltaTime)]
def collisions(self):
if self.transform.pos[0] <= 0 :
if(self.transform.pos[0] < 0):
self.vel[0] = -self.vel[0]
if self.transform.pos[0] + self.gameObject.body.radius * 2 >= 720:
if(self.vel[0] > 0):
self.vel[0] = -self.vel[1]
if self.transform.pos[1] <= 0:
if(self.vel[1] < 0):
self.vel[1] = -self.vel[1]
if self.transform.pos[1] + self.gameObject.body.radius * 2 >= 720:
if(self.vel[1] > 0):
self.vel[1] = -self.vel[1]
def update(self):
self.move(self.vel[0], self.vel[1])
self.collisions()
class nullController():
transform = Transform()
class GameObject():
body = Circle(5, [255, 0, 0])
transform = Transform()
controller = nullController()
def __init__(self, body, controller):
gameObjects.append(self)
self.body = body
self.controller = controller
self.controller.transform = self.transform
self.controller.gameObject = self
def update(self):
self.body.draw(self.transform.pos)
self.controller.update()
player = GameObject(Circle(20, [255, 0, 0]), PlayerController())
while running:
pygame.display.flip()
screen.fill((255,255,255))
for gameObject in gameObjects:
gameObject.update()
keys = pygame.key.get_pressed()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False