-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode1.py
More file actions
85 lines (74 loc) · 1.98 KB
/
node1.py
File metadata and controls
85 lines (74 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#this is Controller file or Main Class
import random as ran
import pygame as pg
from world import*
@timer
class Main:
def __init__(self):
self.car = Car()
self.button = Button()
self.tcar1 = Red_Car()
self.tcar2 = Green_Car()
self.tcar3 = Blue_Car()
self.score = Score()
#self.sound = sound
#___________________________
self.click= False
self.left =False
self.right = False
self.move =True
self.game = False
def event(self):
self.score.num +=1
self.pos = pg.mouse.get_pos()
for i in pg.event.get():
if i.type == pg.QUIT:
run = False
if i.type == pg.MOUSEBUTTONDOWN:
not self.click
if self.button.rect1.collidepoint(self.pos):
print("left")
self.left = True
self.right = False
if self.button.rect2.collidepoint(self.pos):
print("right")
self.right = True
self.left = False
def draw(self):
pg.draw.rect(win,black,(10, 10, width-30, 1400))
self.car.draw()
self.tcar1.draw()
self.tcar2.draw()
self.tcar3.draw()
self.button.draw()
self.score.draw()
def update(self):
if self.left:
self.car.rect.x -= 5
if self.car.rect.x <= 10:
self.car.rect.x = 10
if self.right:
self.car.rect.x +=5
if self.car.rect.x >= 650:
self.car.rect.x = 650
if self.move:
#self.sound.play()
self.tcar1.rect.y +=10
self.tcar2.rect.y += 10
self.tcar3.rect.y += 10
if self.tcar1.rect.y ==1400:
self.tcar1.rect.y = ran.choice([0,-500])
self.tcar1.rect.x = ran.choice([400,50,100,630])
if self.tcar2.rect.y ==1400:
self.tcar2.rect.y = ran.choice([-100,-300])
self.tcar2.rect.x = ran.choice([250,50,350])
if self.tcar3.rect.y ==1400:
self.tcar3.rect.y = 0
self.tcar3.rect.x = ran.choice([50,100,350, 630])
if self.car.rect.colliderect(self.tcar1.rect) or self.car.rect.colliderect(self.tcar2.rect) or self.car.rect.colliderect(self.tcar3.rect):
self.move = False
self.game = True
if self.game:
win.blit(r_GO, (200,500))
pg.display.flip()
pg.display.update()