-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
147 lines (119 loc) · 3.2 KB
/
run.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Real Time Count TEST
import RPi.GPIO as GPIO
import random as r
from time import sleep as s
import backend as B
# GPIO PINS FOR THE LEDs IN ORDER
lP = [19, 26, 12, 16, 21, 24, 23, 18, 22, 27, 17, 4]
# GPIO PINS FOR THE PLAYER 1 & 2 BUTTONS
button = [25, 20]
gameOver = 1
gP = 5 # Game Point
bIsDown = [False, False] # Button is Down
SSMM = [1000, 200000] # Step Speed Min Max
stepSpd = SSMM[gameOver]
waitFor = 1
buffer = 0
bSet = 3 # Buffer Set
lockInp = False #Lock Inputs
timer = stepSpd
stepCheck = None
cap = len(lP)-1
quit = [0,0]
points = [0,0]
step, polarity = B.RandomPos(cap)
GPIO.setmode(GPIO.BCM)
for a in lP:
GPIO.setup(a, GPIO.OUT)
GPIO.output(a, False)
GPIO.setup(button, GPIO.IN, pull_up_down = GPIO.PUD_UP)
try:
while True:
# THE STEP SPEED IS DETERMINED ON THE GAME MODE
stepSpd = SSMM[gameOver]
# WE COMPARE OUR CURRENT STEP TO OUR STEP CHECK TO TELL IF WE HAVE MOVED IN TIME OR NOT
if step is not stepCheck:
# THIS JUST CHECKS FOR IF PLAYERS ARE HOLDING THEIR BUTTONS & WANT TO QUIT
if quit[0] > 100 and quit[1] > 100:
B.TurnOnAll(lP)
s(2)
lockInp = False
points = [0,0]
gameOver = 1
step, polarity = B.RandomPos(goal)
B.SwitchLED(lP,lP[step])
# IF EITHER PLAYER IS HOLDING THEIR BUTTON WHILE IN GAME, THEN LETS ADD TO THEIR HOLD TIME ELSE RESET IT
# ENDED UP NOT REALLY USED
for a in range(2):
if gameOver is 0 and GPIO.input(button[a]) is 0:
quit[a]+=1
else:
quit[a] = 0
#IF GAME IS ACTIVE
if gameOver is 0:
# THIS IS ACTUAL GAMEPLAY FUNCTIONALITY
if lockInp is False and buffer is 0:
# PLAYER BUTTON PRESSES
for a in range(2):
if a is 0:
goal = cap
else:
goal = 0
# IF EITHER PLAYER PRESSES THE BUTTONS & WE KNOW ITS THEIR FIRST PRESS
if GPIO.input(button[a]) is 0 and bIsDown[a] is False:
bIsDown[a] = True
if step is not goal:
lockInp = True
buffer = bSet
s(waitFor)
lockInp = False
step, polarity = B.RandomPos(goal)
else:
points[a]+=1
lockInp = True
if points[a] >= gP:
B.TurnOnAll(lP)
for a in range(10):
B.Flash(lP[step],.1)
lockInp = False
points = [0,0]
gameOver = 1
step, polarity = B.RandomPos(goal)
else:
for a in range(points[a]):
B.Flash(lP[step],.3)
step, polarity = B.RandomPos(goal)
lockInp = False
elif GPIO.input(button[a]) is 1:
bIsDown[a] = False
# IF GAME IS NOT ACTIVE
else:
if GPIO.input(button[0]) is 0 and GPIO.input(button[1]) is 0:
B.TurnOnAll(lP)
s(2)
buffer = 4
gameOver = 0
# FIRST WE NEED TO GET A REFERENCE TO THE PREVIOUS STEP BEFORE WE CHANGE OUR STEP
stepCheck = step
# IF INPUTS ARE NOT LOCKED THEN PLAY TIMER
if not lockInp:
timer -=1
# IF TIMER RUNS OUT THEN CHANGE STEP
if timer is 0:
if polarity is 1:
if step < cap:
step +=1
else:
polarity = -1
step -=1
elif polarity is -1:
if step > 0:
step -=1
else:
polarity = 1
step +=1
if buffer > 0:
buffer -= 1
timer = stepSpd
finally:
GPIO.cleanup()