-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlearning.py
More file actions
60 lines (39 loc) · 1.44 KB
/
learning.py
File metadata and controls
60 lines (39 loc) · 1.44 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
import pygame
from sys import exit
pygame.init()
screen = pygame.display.set_mode((800,400), pygame.SCALED, vsync = 1)
pygame.display.set_caption('Traffic Light Sim')
# you could also change the icon
# print info about the the game instance (drivers / hw)
obj = pygame.display.Info()
print(obj)
clock = pygame.time.Clock()
test_surface = pygame.Surface((100,200))
# list of colors https://github.com/pygame/pygame/blob/main/src_py/colordict.py
test_surface.fill('Red')
test_font = pygame.font.Font('font/Pixeltype.ttf', 50)
text_surface = test_font.render('test text', False, 'Yellow')
car = pygame.image.load('graphics/orange_car_2.png')
# time = 0
# delta_t = 1/60
prev_time = 0
while True:
# check for player input
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
# erase the previous time
text_surface = test_font.render(str(round(prev_time,2)), False, 'Black')
screen.blit(text_surface, (400,200))
# update the time
prev_time = pygame.time.get_ticks()/1000
text_surface = test_font.render(str(round(prev_time,2)), False, 'Yellow')
#blit = block image transfer
screen.blit(test_surface,(0,0))
screen.blit(car,(200,200))
screen.blit(text_surface, (400,200))
# update everything
pygame.display.update()
# rate limiter
clock.tick(60) # equiv to rate in vpython, loop should not run faster than 60 times per sec