def generate_course(): holes = [] alphabet = string.ascii_letters for i in range(18): holes.append(Hole.generate_hole()) return Course(''.join((random.choices(alphabet, k=10))), holes)
def merge(in1, in2): """ :param in1: Hole -> First hole :param in2: Hole -> Second hole """ """ Merges a hole with another hole. Note that the number of holes will constantly decrease first, we make sure that the two holes aren't assigned to any processes """ first = Holes_Objects[in1] second = Holes_Objects[in2] if first.allocated_to == -1 and second.allocated_to == -1: # The hole will have the least starting address of the two if first.address + first.size == second.address: merge_address = first.address if first.address < second.address else second.address # The hole size will be the sum of the previous two merge_size = first.size + second.size # Delete original holes to avoid accidentally using them Holes_Objects.remove(first) Holes_Objects.remove(second) # Create the new hole Holes_Objects.append(Hole.Hole(merge_address, merge_size))
def apply_inputs(holes_given, processes_given): """ :param holes_given: List of tuples -> Holes parameters :param processes_given: List of tuples -> Processes parameters """ # Create Holes classes for each in holes_given: Holes_Objects.append(Hole.Hole(each[1], each[2])) # Create Processes classes for each in processes_given: Processes_Objects.append(Process.Process(each[0], each[1]))
def allocator(holes, process, option): """ :param holes: List -> list of Hole Objects :param process: Process -> Process object to allocate :param option: char -> Memory Management Algorithm 'b' -> Best Fit 'w' -> Worse Fit ELSE -> First Fit """ if option is 'b': # Best Fit # Sort in ascending order according to Holes size holes.sort(key=lambda tup: tup.size) elif option is 'w': # Worst Fit # Sort in descending order according to Holes size holes.sort(key=lambda tup: tup.size) holes.reverse() remaining_hole = -1 for hole in holes: if hole.size >= process.size: # Allocate and create remaining hole hole_size = process.size # new hole new_hole_address = hole.address + process.size new_hole_size = hole.size - process.size remaining_hole = Hole.Hole(new_hole_address, new_hole_size) # allocate current hole -> modify size hole.size = hole_size process.allocate(hole) # Show Progress break # Allocation is done -> remaining hole must be appended to Holes Objects list if remaining_hole is not -1: # append remaining hole to list holes.append(remaining_hole) return # Indicates that this process couldn't be allocated print "Couldn't allocate hole"
def populate_course(self): hole_list = [] if self.course_name == "Spring Meadows": for i in range(0, 17): hole_list.append(Hole.Hole(i, self.course_name)) return hole_list
def new(self, mapPath): self.mapPath = mapPath self.map = tiledMap(mapPath) self.mapImg = self.map.makeMap(self) self.mapRect = self.mapImg.get_rect() self.camera = Camera(self.mapRect.x, self.mapRect.y) self.frontSprites = pygame.sprite.Group() self.backSprites = pygame.sprite.Group() self.allSprites = pygame.sprite.Group() self.triggers = pygame.sprite.Group() self.holes = pygame.sprite.Group() self.players = pygame.sprite.Group() self.walls = pygame.sprite.Group() self.spikes = pygame.sprite.Group() self.bullets = pygame.sprite.Group() self.enemies = pygame.sprite.Group() self.enemyBullet = pygame.sprite.Group() self.chests = pygame.sprite.Group() self.allUpgrades = pygame.sprite.Group() self.allDrops = pygame.sprite.Group() self.savers = pygame.sprite.Group() self.texts = {} self.hasBoss = False if name == 'nt': if mapPath == '../Maps\\mapBoss1.tmx': self.hasBoss = True else: if mapPath == '../Maps/mapBoss1.tmx': self.hasBoss = True if self.hasBoss: self.boss = BossController(self) for i in self.map.tmdata.objects: if i.name == 'spawn': self.player = Player(self, 1, i.x, i.y) if self.hasBoss: self.boss.setSpawn(i.x, i.y) elif i.name == 'wall': Wall(self, i.x, i.y, i.width, i.height) elif i.name == 'end': End(self, i.x, i.y, i.width, i.height) elif i.name == 'hole': Hole(self, i.x, i.y, i.width, i.height) elif i.name == 'spike': Spike(self, i.x, i.y, i.width, i.height, i.type) elif i.name == 'enemy': if not self.hasBoss: Enemy(self, i.x, i.y, i.width, i.height) else: self.boss.addEnemiesArena(i.x, i.y, i.width, i.height) elif i.name == 'chest': Chest(self, i.x, i.y, i.width, i.height) elif i.name == 'save': Save(self, self.menu, i.x, i.y, i.width, i.height) elif i.name == 'boss': self.boss.setPos(i.x, i.y) elif i.name == 'bossCopy': self.boss.addCopy(i.x, i.y) elif i.name == 'spawn1': self.boss.setSpawn1(i.x, i.y) elif i.name == 'spawn2': self.boss.setSpawn2(i.x, i.y) elif i.name == 'bossSpawn': self.boss.setBossSpawn(i.x, i.y) elif i.name == 'enemyAfter': self.boss.addEnemiesAfter(i.x, i.y) self.hud = Hud(self) self.camera = Camera(self.mapRect.width, self.mapRect.height) print(self.walls) print(self.triggers) print(self.mapsAlreadyPlayed)
class FlipperGame(Widget): GPIO.setmode(GPIO.BCM) # set up BCM GPIO numbering #MCP I2C adresses CHIPONE = 0x20 CHIPTWO = 0x21 CHIPTHREE = 0x22 #relais are turned off at a high signal HIGH = 0 LOW = 1 #Switch creation print ("Creating Switches") lowerRightScoreSwitch = Switch("Lower Right Score Switch", CHIPONE, 0) upperRightScoreSwitch = Switch("Upper Right Score Switch", CHIPONE, 1) upperLeftScoreSwitch = Switch("Upper Left Score Switch", CHIPONE, 2) upperLeftBallGate = Switch("Upper Left Ball Gate", CHIPONE, 3) tiltSwitch = Switch("Tilt Switch", CHIPONE, 4) hPointsSwitch = Switch("100 Points Switch", CHIPONE, 11) upperRightBallGate = Switch("Upper Right Ball Gate", CHIPONE, 12) middleLeftScoreSwitch = Switch("Middle Left Score Switch", CHIPONE, 13) middleRightScoreSwitch = Switch("Middle Right Score Switch", CHIPONE, 14) lowerLeftScoreSwitch = Switch("Lower Left Score Switch", CHIPONE, 15) print ("Chip One Done") lowerRightBallGate = Switch("Lower Right Ball Gate", CHIPTWO, 0) ballLaunchBallGate = Switch("Ball Launch Ball Gate", CHIPTWO, 1) upperHoleSwitch = Switch("Upper Hole Ball Detection Switch", CHIPTWO, 2) rightHoleSwitch = Switch("Right Hole Ball Detection Switch", CHIPTWO, 3) lowerLeftBumperCoilEnabledSwitch = Switch("Lower Left Bumper Coil Enabled Switch", CHIPTWO, 4) upperRightBumperCoilEnabledSwitch = Switch("Upper Right Bumper Coil Enabled Switch", CHIPTWO, 5) lowerRightBumperCoilEnabledSwitch = Switch("Lower Right Bumper Coil Enabled Switch", CHIPTWO, 6) upperLeftBumperCoilEnabledSwitch = Switch("Upper Left Bumper Coil Enabled Switch", CHIPTWO, 7) upperLeftBumperBallDetectionSwitch = Switch("Upper Left Bumper Ball Detection Switch", CHIPTWO, 8) lowerRightBumperBallDetectionSwitch = Switch("Lower Right Bumper Ball Detection Switch", CHIPTWO, 9) upperRightBumperBallDetectionSwitch = Switch("Upper Right Bumper Ball Detection Switch", CHIPTWO, 10) lowerLeftBumperBallDetectionSwitch = Switch("Lower Left Bumper Ball Detection Switch", CHIPTWO, 11) leftHoleSwitch = Switch("Left Hole Ball Detection Switch", CHIPTWO, 12) scrubModePositionDetectionSwitch = Switch("Scrub Mode Position Detection Switch", CHIPTWO, 13) gameOverBallGate = Switch("Game Over Ball Gate", CHIPTWO, 14) lowerLeftBallGate = Switch("Lower Left Ball Gate", CHIPTWO, 15) print ("Chip Two Done") upperRightKickerBallDetectionSwitch = Switch("Upper Right Kicker Ball Detection Switch", CHIPTHREE, 2) lowerRightKickerBallDetectionSwitch = Switch("Lower Right Kicker Ball Detection Switch", CHIPTHREE, 3) rightKickerCoilEnabledSwitch = Switch("Right Kicker Coil Enabled Switch", CHIPTHREE, 4) upperLeftTarget = Switch("Upper Left Target", CHIPTHREE, 5) middleLeftTarget = Switch("Middle Left Target", CHIPTHREE, 6) lowerLeftTarget = Switch("Lower Left Target", CHIPTHREE, 7) lowerRightTarget = Switch("Lower Right Target", CHIPTHREE, 8) middleRightTarget = Switch("Middle Right Target", CHIPTHREE, 9) upperRightTarget = Switch("Upper Right Target", CHIPTHREE, 10) leftKickerCoilEnabledSwitch = Switch("Left Kicker Coil Enabled Switch", CHIPTHREE, 11) lowerLeftKickerBallDetectionSwitch = Switch("Lower Left Kicker Ball Detection Switch", CHIPTHREE, 12) upperLeftKickerBallDetectionSwitch = Switch("Upper Left Kicker Ball Detection Switch", CHIPTHREE, 13) startResetSwitch = Switch("Start Switch", CHIPTHREE, 15) leftFlipperSwitch = Switch("Left Flipper Switch", CHIPTHREE, 14) print ("Chip Three Done") #Coils Creation print ("Creating Coils" ) #flippers GPIO.setup(6, GPIO.OUT,initial=LOW) #ball pusher GPIO.setup(24, GPIO.OUT,initial=LOW) middleHole = Hole("middleHole",19,upperHoleSwitch) GPIO.setup(middleHole.coilPin, GPIO.OUT,initial=LOW) rightHole = Hole("rightHole",18,rightHoleSwitch) GPIO.setup(rightHole.coilPin, GPIO.OUT,initial=LOW) leftHole = Hole("leftHole",17,leftHoleSwitch) GPIO.setup(leftHole.coilPin, GPIO.OUT,initial=LOW) rightKicker = Kicker("rightKicker",11,upperRightKickerBallDetectionSwitch,lowerRightKickerBallDetectionSwitch,rightKickerCoilEnabledSwitch) GPIO.setup(rightKicker.coilPin, GPIO.OUT,initial=LOW) leftKicker = Kicker("leftKicker",5,upperLeftKickerBallDetectionSwitch,lowerLeftKickerBallDetectionSwitch,leftKickerCoilEnabledSwitch) GPIO.setup(leftKicker.coilPin, GPIO.OUT,initial=LOW) lowerLeftBumper = Bumper("lowerLeftBumper",26,lowerLeftBumperBallDetectionSwitch,lowerLeftBumperCoilEnabledSwitch) GPIO.setup(lowerLeftBumper.coilPin, GPIO.OUT,initial=LOW) topLeftBumper = Bumper("topLeftBumper",13,upperLeftBumperBallDetectionSwitch,upperLeftBumperCoilEnabledSwitch) GPIO.setup(topLeftBumper.coilPin, GPIO.OUT,initial=LOW) lowerRightBumper = Bumper("lowerRightBumper",19,lowerRightBumperBallDetectionSwitch,lowerRightBumperCoilEnabledSwitch) GPIO.setup(lowerRightBumper.coilPin, GPIO.OUT,initial=LOW) topRightBumper = Bumper("topRightBumper",21,upperRightBumperBallDetectionSwitch,upperRightBumperCoilEnabledSwitch) GPIO.setup(topRightBumper.coilPin, GPIO.OUT,initial=LOW) scrubMode = Scrubmode("Scrubmode",10,9,lowerRightTarget,middleRightTarget,lowerLeftTarget,middleLeftTarget,scrubModePositionDetectionSwitch) GPIO.setup(scrubMode.coilPinOne, GPIO.OUT,initial=LOW) GPIO.setup(scrubMode.coilPinTwo, GPIO.OUT,initial=LOW) noobGate = Noobgate("Noobgate",12,lowerRightBallGate,ballLaunchBallGate) GPIO.setup(noobGate.coilPin, GPIO.OUT,initial=LOW) coilList = [rightKicker, leftKicker, lowerLeftBumper, topLeftBumper, lowerRightBumper, topRightBumper, middleHole, rightHole, leftHole] state = 0 resetSwitchDuration = 0.0 resetMaxDuration = 2.0 firstBall = True score = 0 lives = 0 screenScore = NumericProperty(score) screenLives = NumericProperty(lives) #scoreChanger = ScoreChanger() filename="highscore.txt" file=open(filename,'r') plaats1=file.readline() plaats2=file.readline() plaats3 = file.readline() isRunning = True high_score1 = plaats1.split() highscore1 = high_score1[1] high_score2 = plaats2.split() highscore2 = high_score2[1] high_score3 = plaats3.split() highscore3 = high_score3[1] elapsedTime = 0.0 scoreActive = False #STATES: #0 - Not Active #1 - Initializing #2 - New Ball #3 - Game Logic #4 - Tilt #5 - Game Over #-1 - Reset #State 0 def notActive(self, deltaTime): #print ("STATE 000000000000000000000000") if self.startResetSwitch.getState() == 1: #print ("STATE 000000000000000000000000 iiiiiiiiiiiiffffffffffff statement") self.state = 1 #state 1 def Initialize(self, deltaTime): #print ("STATE 11111111111111111111") self.lives = 3 self.score = 0 self.state = 2 self.firstBall = True def disableCoils(self, disableFlippers): for x in self.coilList: #print ("disablecoils functie, for x in self.coilList:") x.disable() if disableFlippers == True: #print ("disablecoils functie, if disableFlippers == TRUE") #self.scrubMode.disable() #self.noobGate.disable() GPIO.output(6, self.LOW) #state 2 def NewBall(self, deltaTime): #print ("STATE 2222222222222222222222222") self.disableCoils(True) if self.gameOverBallGate.getState() == 1: print ("eerste if is geactiveerd") if self.firstBall == False: self.lives-=1 print ("tweede if is geactiveerd") if self.lives <= 0: self.state = -1 print ("derde if is geactiveerd") return print ("BALL PUSHER IS AAN") GPIO.output(24, self.HIGH) sleep(0.2) GPIO.output(24, self.LOW) sleep(0.5) if self.ballLaunchBallGate.getState() == 0: print ("ballLaunchBallGate is gelijk aan 0") self.state=3 self.firstBall = False self.noobGate.reset() #GPIO.output(12, self.HIGH) #Turn on Flippers GPIO.output(6, self.HIGH) def CheckOtherInputs(self): if(self.hPointsSwitch.getState() == 1 or self.upperLeftBallGate.getState() == 1 or self.upperRightBallGate.getState() == 1): if self.scoreActive == False: self.score += 100 self.scoreActive == True; else: self.scoreActive = False if(self.lowerLeftScoreSwitch.getState() == 1 or self.lowerRightScoreSwitch.getState() == 1 or self.middleLeftScoreSwitch.getState() == 1 or self.middleRightScoreSwitch.getState() == 1 or self.upperLeftScoreSwitch.getState() == 1 or self.upperRightScoreSwitch.getState() == 1): if self.scoreActive == False: self.score += 2 self.scoreActive == True; else: self.scoreActive = False if(self.lowerLeftBallGate.getState() == 1 or self.lowerRightBallGate.getState() == 1): if self.scoreActive == False: self.score += 15 self.scoreActive == True; else: self.scoreActive = False #state 3 def GameLogic(self, deltaTime): #print ("STATE 3333333333333333333333333333") for x in self.coilList: self.score += x.update(deltaTime) self.scrubMode.update(deltaTime) self.noobGate.update(deltaTime) self.CheckOtherInputs() if self.gameOverBallGate.getState() == 1: self.state = 2 #elif self.tiltSwitch.getState() == 1: #self.state = 4 #state 4 def Tilt(self, deltaTime): #print ("STATE 4444444444444444444444") #Zet alle Coils even aan self.disableCoils(True) if self.gameOverBallGate.getState() == 1 or self.ballLaunchBallGate.getState() == 0: self.state = 2 #state 5 def GameOver(self, deltaTime): #print ("STATE 555555555555555555555555") self.disableCoils(True) #handle topscoreshizzle print("haat piraat") if self.score >= FlipperGame.highscore3: high = Highscore() #Clock.schedule_interval(high.update, 1.0/60) if self.score >= FlipperGame.highscore2: if self.score >= FlipperGame.highscore1: print("plek 3 gekomen") high.deplaats =1 high.setScores() else: high.deplaats =2 print("plek 2 gekomen") high.setScores() else: high.deplaats =3 print("plek 3 gekomen") high.setScores() self.state = -1 #state -1 def Reset(self, deltaTime): #print ("STATE -------------11111111111111111111") self.disableCoils(True) #self.scoreChanger.resetScoreReels self.scrubMode.disable() self.state = 0 #creation of state dictionary stateFunctionsDict = {0: notActive, 1: Initialize, 2:NewBall, 3:GameLogic, 4:Tilt, 5:GameOver, -1:Reset} oldDebugMessage = "" ######################################### #main function. called every 1/60 second# ######################################### def update(self, dt): #calculate the time since the last call and update the elapsed time deltaTime = dt - self.elapsedTime self.elapsedTime = dt deltaTime = 1.0 / 60 #print "State: -1 " + " Score: 0" + " Lives: " + str(self.lives) #print ("State: ")+ str(self.state) + (" Score: ") + str(self.score) + (" Lives: ") + str(self.lives) debugMessage = "State: "+ str(self.state) + (" Score: ") + str(self.score) + (" Lives: ") + str(self.lives) if(debugMessage != self.oldDebugMessage): print(debugMessage) self.oldDebugMessage = debugMessage #reset the game if the resetswitch is pressed for 5 seconds if self.startResetSwitch.getState() == 1 and self.state > 1: self.resetSwitchDuration+=deltaTime if self.resetSwitchDuration>self.resetMaxDuration: self.state = -1 self.resetSwitchDuration = 0.0 else: self.resetSwitchDuration = 0.0 #call the state function func = self.stateFunctionsDict[self.state] func(self, deltaTime) self.screenScore=self.score self.screenLives=self.lives
def construct_game(): # Creates zones Z1A1 = Zone() Z1A1.coordinate = ((5, 0), (10, 20), (-10, 20)) Z1A1.picture = 'Map\A.jpg' Z1A1.is_goal = False Z1A2 = Zone() Z1A2.coordinate = ((-10, 20), (-5, 0), (5, 0)) Z1A2.picture = 'Map\A.jpg' Z1A2.is_goal = False Z1B1 = Zone() Z1B1.coordinate = ((-20, 30), (-10, 20), (-5, 30)) Z1B1.picture = 'Map\B.jpg' Z1B1.is_goal = False Z1B2 = Zone() Z1B2.coordinate = ((-20, 30), (-10, 35), (-5, 30)) Z1B2.picture = 'Map\B.jpg' Z1B2.is_goal = False Z1C1 = Zone() Z1C1.coordinate = ((-10, 20), (-5, 30), (5, 30)) Z1C1.picture = 'Map\C.jpg' Z1C1.is_goal = False Z1C2 = Zone() Z1C2.coordinate = ((-5, 30), (5, 30), (10, 20)) Z1C2.picture = 'Map\C.jpg' Z1C2.is_goal = False Z1D1 = Zone() Z1D1.coordinate = ((10, 20), (5, 30), (20, 30)) Z1D1.picture = 'Map\D.jpg' Z1D1.is_goal = False Z1D2 = Zone() Z1D2.coordinate = ((5, 30), (20, 30), (10, 35)) Z1D2.picture = 'Map\D.jpg' Z1D2.is_goal = False Z1E = Zone() Z1E.coordinate = ((-5, 55), (-10, 45), (0, 40)) Z1E.picture = 'Map\E.jpg' Z1E.is_goal = False Z1F = Zone() Z1F.coordinate = ((-10, 45), (-10, 35), (0, 40)) Z1F.picture = 'Map\F.jpg' Z1F.is_goal = False Z1G = Zone() Z1G.coordinate = ((-10, 35), (-5, 30), (0, 40)) Z1G.picture = 'Map\G.jpg' Z1G.is_goal = False Z1H = Zone() Z1H.coordinate = ((-5, 30), (5, 30), (0, 40)) Z1H.picture = 'Map\H.jpg' Z1H.is_goal = False Z1I = Zone() Z1I.coordinate = ((5, 30), (10, 35), (0, 40)) Z1I.picture = 'Map\I.jpg' Z1I.is_goal = False Z1J = Zone() Z1J.coordinate = ((10, 35), (10, 45), (0, 40)) Z1J.picture = 'Map\J.jpg' Z1J.is_goal = False Z1K = Zone() Z1K.coordinate = ((10, 45), (5, 55), (0, 40)) Z1K.picture = 'Map\K.jpg' Z1K.is_goal = False Z1G1 = Zone() Z1G1.coordinate = ((-1, 39), (-1, 41), (1, 39)) Z1G1.picture = 'Map\Goal.png' Z1G1.is_goal = True Z1G2 = Zone() Z1G2.coordinate = ((-1, 41), (1, 41), (1, 39)) Z1G2.picture = 'Map\Goal.png' Z1G2.is_goal = True Z2A1 = Zone() Z2A1.coordinate = ((5, 0), (10, 20), (-10, 20)) Z2A1.picture = 'Map\A.jpg' Z2A1.is_goal = False Z2A2 = Zone() Z2A2.coordinate = ((-10, 20), (-5, 0), (5, 0)) Z2A2.picture = 'Map\A.jpg' Z2A2.is_goal = False Z2B1 = Zone() Z2B1.coordinate = ((-20, 30), (-10, 20), (-5, 30)) Z2B1.picture = 'Map\B.jpg' Z2B1.is_goal = False Z2B2 = Zone() Z2B2.coordinate = ((-20, 30), (-10, 35), (-5, 30)) Z2B2.picture = 'Map\B.jpg' Z2B2.is_goal = False Z2C1 = Zone() Z2C1.coordinate = ((-10, 20), (-5, 30), (5, 30)) Z2C1.picture = 'Map\C.jpg' Z2C1.is_goal = False Z2C2 = Zone() Z2C2.coordinate = ((-5, 30), (5, 30), (10, 20)) Z2C2.picture = 'Map\C.jpg' Z2C2.is_goal = False Z2D1 = Zone() Z2D1.coordinate = ((10, 20), (5, 30), (20, 30)) Z2D1.picture = 'Map\D.jpg' Z2D1.is_goal = False Z2D2 = Zone() Z2D2.coordinate = ((5, 30), (20, 30), (10, 35)) Z2D2.picture = 'Map\D.jpg' Z2D2.is_goal = False Z2E = Zone() Z2E.coordinate = ((-5, 55), (-10, 45), (0, 40)) Z2E.picture = 'Map\E.jpg' Z2E.is_goal = False Z2F = Zone() Z2F.coordinate = ((-10, 45), (-10, 35), (0, 40)) Z2F.picture = 'Map\F.jpg' Z2F.is_goal = False Z2G = Zone() Z2G.coordinate = ((-10, 35), (-5, 30), (0, 40)) Z2G.picture = 'Map\G.jpg' Z2G.is_goal = False Z2H = Zone() Z2H.coordinate = ((-5, 30), (5, 30), (0, 40)) Z2H.picture = 'Map\H.jpg' Z2H.is_goal = False Z2I = Zone() Z2I.coordinate = ((5, 30), (10, 35), (0, 40)) Z2I.picture = 'Map\I.jpg' Z2I.is_goal = False Z2J = Zone() Z2J.coordinate = ((10, 35), (10, 45), (0, 40)) Z2J.picture = 'Map\J.jpg' Z2J.is_goal = False Z2K = Zone() Z2K.coordinate = ((10, 45), (5, 55), (0, 40)) Z2K.picture = 'Map\K.jpg' Z2K.is_goal = False Z2G1 = Zone() Z2G1.coordinate = ((-1, 39), (-1, 41), (1, 39)) Z2G1.picture = 'Map\Goal.png' Z2G1.is_goal = True Z2G2 = Zone() Z2G2.coordinate = ((-1, 41), (1, 41), (1, 39)) Z2G2.picture = 'Map\Goal.png' Z2G2.is_goal = True Z3A1 = Zone() Z3A1.coordinate = ((5, 0), (10, 20), (-10, 20)) Z3A1.picture = 'Map\A.jpg' Z3A1.is_goal = False Z3A2 = Zone() Z3A2.coordinate = ((-10, 20), (-5, 0), (5, 0)) Z3A2.picture = 'Map\A.jpg' Z3A2.is_goal = False Z3B1 = Zone() Z3B1.coordinate = ((-20, 30), (-10, 20), (-5, 30)) Z3B1.picture = 'Map\B.jpg' Z3B1.is_goal = False Z3B2 = Zone() Z3B2.coordinate = ((-20, 30), (-10, 35), (-5, 30)) Z3B2.picture = 'Map\B.jpg' Z3B2.is_goal = False Z3C1 = Zone() Z3C1.coordinate = ((-10, 20), (-5, 30), (5, 30)) Z3C1.picture = 'Map\C.jpg' Z3C1.is_goal = False Z3C2 = Zone() Z3C2.coordinate = ((-5, 30), (5, 30), (10, 20)) Z3C2.picture = 'Map\C.jpg' Z3C2.is_goal = False Z3D1 = Zone() Z3D1.coordinate = ((10, 20), (5, 30), (20, 30)) Z3D1.picture = 'Map\D.jpg' Z3D1.is_goal = False Z3D2 = Zone() Z3D2.coordinate = ((5, 30), (20, 30), (10, 35)) Z3D2.picture = 'Map\D.jpg' Z3D2.is_goal = False Z3E = Zone() Z3E.coordinate = ((-5, 55), (-10, 45), (0, 40)) Z3E.picture = 'Map\E.jpg' Z3E.is_goal = False Z3F = Zone() Z3F.coordinate = ((-10, 45), (-10, 35), (0, 40)) Z3F.picture = 'Map\F.jpg' Z3F.is_goal = False Z3G = Zone() Z3G.coordinate = ((-10, 35), (-5, 30), (0, 40)) Z3G.picture = 'Map\G.jpg' Z3G.is_goal = False Z3H = Zone() Z3H.coordinate = ((-5, 30), (5, 30), (0, 40)) Z3H.picture = 'Map\H.jpg' Z3H.is_goal = False Z3I = Zone() Z3I.coordinate = ((5, 30), (10, 35), (0, 40)) Z3I.picture = 'Map\I.jpg' Z3I.is_goal = False Z3J = Zone() Z3J.coordinate = ((10, 35), (10, 45), (0, 40)) Z3J.picture = 'Map\J.jpg' Z3J.is_goal = False Z3K = Zone() Z3K.coordinate = ((10, 45), (5, 55), (0, 40)) Z3K.picture = 'Map\K.jpg' Z3K.is_goal = False Z3G1 = Zone() Z3G1.coordinate = ((-1, 39), (-1, 41), (1, 39)) Z3G1.picture = 'Map\Goal.png' Z3G1.is_goal = True Z3G2 = Zone() Z3G2.coordinate = ((-1, 41), (1, 41), (1, 39)) Z3G2.picture = 'Map\Goal.png' Z3G2.is_goal = True """ Constructs object hierarchy """ # create users StKH1 = Hole() StKH1.name = "Cage to Cage hole (temp 1)" StKH1.zones = [ Z1A1, Z1A2, Z1B1, Z1B2, Z1C1, Z1C2, Z1D1, Z1D2, Z1E, Z1F, Z1G, Z1H, Z1I, Z1J, Z1K ] StKH1.goal_position = (0, 40) StKH1.goal_zone = [Z1G1, Z1G2] StKH1.starting_position = (0, 0) StKH1.par = 3 StKH1.number = 1 StKH2 = Hole() StKH2.name = "Cage to Cage hole" StKH2.zones = [ Z2A1, Z2A2, Z2B1, Z2B2, Z2C1, Z2C2, Z2D1, Z2D2, Z2E, Z2F, Z2G, Z2H, Z2I, Z2J, Z2K ] StKH2.goal_position = (0, 40) StKH2.goal_zone = [Z2G1, Z2G2] StKH2.starting_position = (0, 0) StKH2.par = 3 StKH2.number = 2 StKH3 = Hole() StKH3.name = "Cage to Cage hole (temp 3)" StKH3.zones = [ Z3A1, Z3A2, Z3B1, Z3B2, Z3C1, Z3C2, Z3D1, Z3D2, Z3E, Z3F, Z3G, Z3H, Z3I, Z3J, Z3K ] StKH3.goal_position = (0, 40) StKH3.goal_zone = [Z3G1, Z3G2] StKH3.starting_position = (0, 0) StKH3.par = 3 StKH3.number = 3 StK = Course() StK.name = "St Kilda Botanical Gardens" StK.holes = [StKH1, StKH2, StKH3] TheGame = Game() TheGame.course = StK TheGame.hole = StK.holes[0] return TheGame
def __init__(self, course, number, par): self.hole = Hole.Hole(course) self.hole.set_number(number) self.hole.set_par(par) self.hole.set_distance(self.create_distance(par)) self.hole.reset_distance_left()
def Initialize(self, deltaTime): self.lives = 3 self.score = 0 self.state = 2 self.firstBall = True #flippers, disabled on startup GPIO.setup(21, GPIO.OUT, initial=self.LOW) GPIO.setup(16, GPIO.OUT, initial=self.LOW) self.middleHole = Hole("middleHole", 7, self.upperHoleSwitch) GPIO.setup(self.middleHole.coilPin, GPIO.OUT, initial=self.LOW) self.rightHole = Hole("rightHole", 1, self.rightHoleSwitch) GPIO.setup(self.rightHole.coilPin, GPIO.OUT, initial=self.LOW) self.leftHole = Hole("leftHole", 8, self.leftHoleSwitch) GPIO.setup(self.leftHole.coilPin, GPIO.OUT, initial=self.LOW) self.rightKicker = Kicker("rightKicker", 13, self.upperRightKickerBallDetectionSwitch, self.lowerRightKickerBallDetectionSwitch, self.rightKickerCoilEnabledSwitch) GPIO.setup(self.rightKicker.coilPin, GPIO.OUT, initial=self.LOW) self.leftKicker = Kicker("leftKicker", 6, self.upperLeftKickerBallDetectionSwitch, self.lowerLeftKickerBallDetectionSwitch, self.leftKickerCoilEnabledSwitch) GPIO.setup(self.leftKicker.coilPin, GPIO.OUT, initial=self.LOW) self.lowerLeftBumper = Bumper("lowerLeftBumper", 9, self.lowerLeftBumperBallDetectionSwitch, self.lowerLeftBumperCoilEnabledSwitch) GPIO.setup(self.lowerLeftBumper.coilPin, GPIO.OUT, initial=self.LOW) self.topLeftBumper = Bumper("topLeftBumper", 0, self.upperLeftBumperBallDetectionSwitch, self.upperLeftBumperCoilEnabledSwitch) GPIO.setup(self.topLeftBumper.coilPin, GPIO.OUT, initial=self.LOW) self.lowerRightBumper = Bumper( "lowerRightBumper", 11, self.lowerRightBumperBallDetectionSwitch, self.lowerRightBumperCoilEnabledSwitch) GPIO.setup(self.lowerRightBumper.coilPin, GPIO.OUT, initial=self.LOW) self.topRightBumper = Bumper("topRightBumper", 5, self.upperRightBumperBallDetectionSwitch, self.upperRightBumperCoilEnabledSwitch) GPIO.setup(self.topRightBumper.coilPin, GPIO.OUT, initial=self.LOW) self.scrubMode = Scrubmode("Scrubmode", 19, 26, self.lowerRightTarget, self.middleRightTarget, self.lowerLeftTarget, self.middleLeftTarget, self.scrubModePositionDetectionSwitch) GPIO.setup(self.scrubMode.coilPinOne, GPIO.OUT, initial=self.LOW) GPIO.setup(self.scrubMode.coilPinTwo, GPIO.OUT, initial=self.LOW) self.noobGate = Noobgate("Noobgate", 20, self.lowerRightBallGate, self.ballLaunchBallGate) GPIO.setup(self.noobGate.coilPin, GPIO.OUT, initial=self.LOW) self.coilList = [ self.rightKicker, self.leftKicker, self.lowerLeftBumper, self.topLeftBumper, self.lowerRightBumper, self.topRightBumper, self.middleHole, self.rightHole, self.leftHole ]
class FlipperGame(Widget): GPIO.setmode(GPIO.BCM) # set up BCM GPIO numbering #MCP I2C adresses CHIPONE = 0x20 CHIPTWO = 0x21 CHIPTHREE = 0x22 #relais are turned off at a high signal HIGH = 0 LOW = 1 #Switch creation print "Creating Switches" # MCP23017 1 GPA0_R_OND5_S4_RUBBERBAND_KICKER_RECHTS_MIDDEN = Switch( "GPA0_R_OND5_S4_RUBBERBAND_KICKER_RECHTS_MIDDEN", CHIPONE, 0) GPA1_R_OND6_S9_2_RUBBERBAND_KICKER_RECHTS_BOVEN_BOVENSTE = Switch( "GPA1_R_OND6_S9_2_RUBBERBAND_KICKER_RECHTS_BOVEN_BOVENSTE", CHIPONE, 1) GPA2_R_OND7_S12_2_RUBBERBAND_KICKER_LINKS_BOVEN_ONDERSTE = Switch( "GPA2_R_OND7_S12_2_RUBBERBAND_KICKER_LINKS_BOVEN_ONDERSTE", CHIPONE, 2) GPA3_R_OND8_S13_PADDRAAD_LINKS_BOVEN = Switch( "GPA3_R_OND8_S13_PADDRAAD_LINKS_BOVEN", CHIPONE, 3) GPA4_R_OND5_S27_TILT_SENSOR = Switch("GPA4_R_OND5_S27_TILT_SENSOR", CHIPONE, 4) GPA5_LEEG = 5 GPA6_LEEG = 6 GPA7_LEEG = 7 GPB0_LEEG = 8 GPB1_LEEG = 9 GPB2_LEEG = 10 GPB3_R_BVN9_S100_SWITCH_WIT_BOVENAAN = Switch( "GPB3_R_BVN9_S100_SWITCH_WIT_BOVENAAN", CHIPONE, 11) GPB4_R_BVN8_S8_PADDRAAD_RECHTS_BOVEN = Switch( "GPB4_R_BVN8_S8_PADDRAAD_RECHTS_BOVEN", CHIPONE, 12) GPB5_R_BVN7_S21_RUBBERBAND_KICKER_LINKS_BOVEN_BOVENSTE = Switch( "GPB5_R_BVN7_S21_RUBBERBAND_KICKER_LINKS_BOVEN_BOVENSTE", CHIPONE, 13) GPB6_R_BVN6_S9_1_RUBBERBAND_KICKER_RECHTS_BOVEN_ONDERSTE = Switch( "GPB6_R_BVN6_S9_1_RUBBERBAND_KICKER_RECHTS_BOVEN_ONDERSTE", CHIPONE, 14) GPB7_R_BVN5_S16_RUBBERBAND_KICKER_LINKS_MIDDEN = Switch( "GPB7_R_BVN5_S16_RUBBERBAND_KICKER_LINKS_MIDDEN", CHIPONE, 15) print("Chip One Done") # MCP23017 2 GPA0_R_OND1_S26_PADDRAAD_RECHTS_BENEDEN = Switch( "GPA0_R_OND1_S26_PADDRAAD_RECHTS_BENEDEN", CHIPTWO, 0) GPA1_R_OND2_S24_PADDRAAD_START_BALSCHIETEN = Switch( "GPA1_R_OND2_S24_PADDRAAD_START_BALSCHIETEN", CHIPTWO, 1) GPA2_R_OND3_S10_WHEEL_MIDDLE = Switch("GPA2_R_OND3_S10_WHEEL_MIDDLE", CHIPTWO, 2) GPA3_R_OND4_S2_WHEEL_RIGHT = Switch("GPA3_R_OND4_S2_WHEEL_RIGHT", CHIPTWO, 3) GPA4_L_OND1_S17_BUMPER_METAAL_LINKS_BENEDEN = Switch( "GPA4_L_OND1_S17_BUMPER_METAAL_LINKS_BENEDEN", CHIPTWO, 4) GPA5_L_OND2_S5_BUMPER_METAAL_RECHTS_BOVEN = Switch( "GPA5_L_OND2_S5_BUMPER_METAAL_RECHTS_BOVEN", CHIPTWO, 5) GPA6_L_OND3_S6_BUMPER_METAAL_RECHTS_BENEDEN = Switch( "GPA6_L_OND3_S6_BUMPER_METAAL_RECHTS_BENEDEN", CHIPTWO, 6) GPA7_L_OND4_S15_BUMPER_METAAL_LINKS_BOVEN = Switch( "GPA7_L_OND4_S15_RUBBERBAND_KICKER_RECHTS_MIDDEN", CHIPTWO, 7) GPB0_L_BVN4_S15_BUMPER_PLASTIC_LINKS_BOVEN = Switch( "GPB0_L_BVN4_S15_BUMPER_METAAL_LINKS_BOVEN", CHIPTWO, 8) GPB1_L_BVN3_S6_BUMPER_PLASTIC_RECHTS_BENEDEN = Switch( "GPB1_L_BVN3_S6_BUMPER_PLASTIC_RECHTS_BENEDEN", CHIPTWO, 9) GPB2_L_BVN2_S5_BUMPER_PLASTIC_RECHTS_BOVEN = Switch( "GPB2_L_BVN2_S5_BUMPER_PLASTIC_RECHTS_BOVEN", CHIPTWO, 10) GPB3_L_BVN1_S17_BUMPER_PLASTIC_LINKS_BENEDEN = Switch( "GPB3_L_BVN1_S17_BUMPER_PLASTIC_LINKS_BENEDEN", CHIPTWO, 11) GPB4_R_BVN4_S17_WHEEL_LEFT = Switch("GPB4_R_BVN4_S17_WHEEL_LEFT", CHIPTWO, 12) GPB5_R_BVN3_S101_RODE_KNOP_SCROBMODE = Switch( "GPB5_R_BVN3_S101_RODE_KNOP_SCROBMODE", CHIPTWO, 13) GPB6_R_BVN2_S23_PADDRAAD_BALLPUSHER = Switch( "GPB6_R_BVN2_S23_PADDRAAD_BALLPUSHER", CHIPTWO, 14) GPB7_R_BVN1_S21_PADDRAAD_LINKS_BENEDEN = Switch( "GPB7_R_BVN1_S21_PADDRAAD_LINKS_BENEDEN", CHIPTWO, 15) print("Chip Two Done") # MCP23017 3 GPA0_LEEG = 0 GPA1_LEEG = 1 GPA2_L_OND5_S25_RUBBERBAND_KICKER_RECHTS_BENEDEN_BOVENSTE = Switch( "GPA2_L_OND5_S25_RUBBERBAND_KICKER_RECHTS_BENEDEN_BOVENSTE", CHIPTHREE, 2) GPA3_L_OND6_S25_RUBBERBAND_KICKER_RECHTS_BENEDEN_ONDERSTE = Switch( "GPA3_L_OND6_S25_RUBBERBAND_KICKER_RECHTS_BENEDEN_ONDERSTE", CHIPTHREE, 3) GPA4_L_OND7_S103_RUBBERBAND_KICKER_RECHTS_BENEDEN_SOLENOID = Switch( "GPA4_L_OND7_S103_RUBBERBAND_KICKER_RECHTS_BENEDEN_SOLENOID", CHIPTHREE, 4) GPA5_L_OND8_S14_GELE_TARGET_LINKS_BOVEN = Switch( "GPA5_L_OND8_S14_GELE_TARGET_LINKS_BOVEN", CHIPTHREE, 5) GPA6_L_OND9_S18_GELE_TARGET_LINKS_MIDDEN = Switch( "GPA6_L_OND9_S18_GELE_TARGET_LINKS_MIDDEN", CHIPTHREE, 6) GPA7_L_OND10_S20_GELE_TARGET_LINKS_BENEDEN = Switch( "GPA7_L_OND10_S20_GELE_TARGET_LINKS_BENEDEN", CHIPTHREE, 7) GPB0_L_BVN10_S1_GELE_TARGET_RECHTS_BENEDEN = Switch( "GPB0_L_BVN10_S1_GELE_TARGET_RECHTS_BENEDEN", CHIPTHREE, 8) GPB1_L_BVN9_S3_GELE_TARGET_RECHTS_MIDDEN = Switch( "GPB1_L_BVN9_S3_GELE_TARGET_RECHTS_MIDDEN", CHIPTHREE, 9) GPB2_L_BVN8_S7_GELE_TARGET_RECHTS_BOVEN = Switch( "GPB2_L_BVN8_S7_GELE_TARGET_RECHTS_BOVEN", CHIPTHREE, 10) GPB3_L_BVN7_S105_RUBBERBAND_KICKER_LINKS_BENEDEN_BOVENSTE_SOLENOID = Switch( "GPB3_L_BVN7_S105_RUBBERBAND_KICKER_LINKS_BENEDEN_BOVENSTE_SOLENOID", CHIPTHREE, 11) GPB4_L_BVN6_S104_RUBBERBAND_KICKER_LINKS_BENEDEN_ONDERSTE = Switch( "GPB4_L_BVN6_S104_RUBBERBAND_KICKER_LINKS_BENEDEN_ONDERSTE", CHIPTHREE, 12) GPB5_L_BVN5_S22_RUBBERBAND_KICKER_LINKS_BENEDEN_BOVENSTE = Switch( "GPB5_L_BVN5_S22_RUBBERBAND_KICKER_LINKS_BENEDEN_BOVENSTE", CHIPTHREE, 13) leftFlipperSwitch = Switch("Left Flipper Switch", CHIPTHREE, 14) startResetSwitch = Switch("Start Switch", CHIPTHREE, 15) print("Chip Three Done") #Coils Creation print("Creating Coils") #flippers GPIO.setup(6, GPIO.OUT, initial=LOW) #ball pusher #GPIO.setup(24, GPIO.OUT,initial=LOW) SOLENOID_GPB6_R_BVN2_S23_PADDRAAD_BALLPUSHER = Hole( "GPB6_R_BVN2_S23_PADDRAAD_BALLPUSHER", 24, GPB6_R_BVN2_S23_PADDRAAD_BALLPUSHER) GPIO.setup(SOLENOID_GPB6_R_BVN2_S23_PADDRAAD_BALLPUSHER.coilPin, GPIO.OUT, initial=LOW) SOLENOID_GPA2_R_OND3_S10_WHEEL_MIDDLE = Hole( "GPA2_R_OND3_S10_WHEEL_MIDDLE", 19, GPA2_R_OND3_S10_WHEEL_MIDDLE) GPIO.setup(SOLENOID_GPA2_R_OND3_S10_WHEEL_MIDDLE.coilPin, GPIO.OUT, initial=LOW) SOLENOID_GPA3_R_OND4_S2_WHEEL_RIGHT = Hole("GPA3_R_OND4_S2_WHEEL_RIGHT", 18, GPA3_R_OND4_S2_WHEEL_RIGHT) GPIO.setup(SOLENOID_GPA3_R_OND4_S2_WHEEL_RIGHT.coilPin, GPIO.OUT, initial=LOW) SOLENOID_GPB4_R_BVN4_S17_WHEEL_LEFT = Hole("GPB4_R_BVN4_S17_WHEEL_LEFT", 17, GPB4_R_BVN4_S17_WHEEL_LEFT) GPIO.setup(SOLENOID_GPB4_R_BVN4_S17_WHEEL_LEFT.coilPin, GPIO.OUT, initial=LOW) rightKicker = Kicker( "rightKicker", 16, GPA2_L_OND5_S25_RUBBERBAND_KICKER_RECHTS_BENEDEN_BOVENSTE, GPA3_L_OND6_S25_RUBBERBAND_KICKER_RECHTS_BENEDEN_ONDERSTE, GPA4_L_OND7_S103_RUBBERBAND_KICKER_RECHTS_BENEDEN_SOLENOID) GPIO.setup(rightKicker.coilPin, GPIO.OUT, initial=LOW) leftKicker = Kicker( "leftKicker", 13, GPB3_L_BVN7_S105_RUBBERBAND_KICKER_LINKS_BENEDEN_BOVENSTE_SOLENOID, GPB4_L_BVN6_S104_RUBBERBAND_KICKER_LINKS_BENEDEN_ONDERSTE, GPA4_L_OND7_S103_RUBBERBAND_KICKER_RECHTS_BENEDEN_SOLENOID) GPIO.setup(leftKicker.coilPin, GPIO.OUT, initial=LOW) lowerLeftBumper = Bumper("lowerLeftBumper", 23, GPB3_L_BVN1_S17_BUMPER_PLASTIC_LINKS_BENEDEN, GPA4_L_OND1_S17_BUMPER_METAAL_LINKS_BENEDEN) GPIO.setup(lowerLeftBumper.coilPin, GPIO.OUT, initial=LOW) topLeftBumper = Bumper("topLeftBumper", 20, GPB0_L_BVN4_S15_BUMPER_PLASTIC_LINKS_BOVEN, GPA7_L_OND4_S15_BUMPER_METAAL_LINKS_BOVEN) GPIO.setup(topLeftBumper.coilPin, GPIO.OUT, initial=LOW) lowerRightBumper = Bumper("lowerRightBumper", 22, GPB1_L_BVN3_S6_BUMPER_PLASTIC_RECHTS_BENEDEN, GPA6_L_OND3_S6_BUMPER_METAAL_RECHTS_BENEDEN) GPIO.setup(lowerRightBumper.coilPin, GPIO.OUT, initial=LOW) topRightBumper = Bumper("topRightBumper", 21, GPB2_L_BVN2_S5_BUMPER_PLASTIC_RECHTS_BOVEN, GPA5_L_OND2_S5_BUMPER_METAAL_RECHTS_BOVEN) GPIO.setup(topRightBumper.coilPin, GPIO.OUT, initial=LOW) scrubMode = Scrubmode("Scrubmode", 4, 5, GPA5_L_OND8_S14_GELE_TARGET_LINKS_BOVEN, GPA6_L_OND9_S18_GELE_TARGET_LINKS_MIDDEN, GPA7_L_OND10_S20_GELE_TARGET_LINKS_BENEDEN, GPB0_L_BVN10_S1_GELE_TARGET_RECHTS_BENEDEN, GPB1_L_BVN9_S3_GELE_TARGET_RECHTS_MIDDEN, GPB2_L_BVN8_S7_GELE_TARGET_RECHTS_BOVEN, GPB5_R_BVN3_S101_RODE_KNOP_SCROBMODE) GPIO.setup(scrubMode.coilPinOne, GPIO.OUT, initial=LOW) GPIO.setup(scrubMode.coilPinTwo, GPIO.OUT, initial=LOW) noobGate = Noobgate("Noobgate", 12, GPA0_R_OND1_S26_PADDRAAD_RECHTS_BENEDEN, GPA1_R_OND2_S24_PADDRAAD_START_BALSCHIETEN) GPIO.setup(noobGate.coilPin, GPIO.OUT, initial=LOW) coilList = [ rightKicker, leftKicker, lowerLeftBumper, topLeftBumper, lowerRightBumper, topRightBumper, SOLENOID_GPA2_R_OND3_S10_WHEEL_MIDDLE, GPA3_R_OND4_S2_WHEEL_RIGHT, GPB4_R_BVN4_S17_WHEEL_LEFT ] state = 0 resetSwitchDuration = 0.0 resetMaxDuration = 2.0 firstBall = True score = 0 lives = 0 screenScore = NumericProperty(score) screenLives = NumericProperty(lives) #scoreChanger = ScoreChanger() filename = "highscore.txt" file = open(filename, 'r') plaats1 = file.readline() plaats2 = file.readline() plaats3 = file.readline() isRunning = True high_score1 = plaats1.split() highscore1 = high_score1[1] high_score2 = plaats2.split() highscore2 = high_score2[1] high_score3 = plaats3.split() highscore3 = high_score3[1] elapsedTime = 0.0 scoreActive = False #STATES: #0 - Not Active #1 - Initializing #2 - New Ball #3 - Game Logic #4 - Tilt #5 - Game Over #-1 - Reset #State 0 def notActive(self, deltaTime): #print ("STATE 000000000000000000000000") if self.startResetSwitch.getState() == 1: print( "STATE 000000000000000000000000 iiiiiiiiiiiiffffffffffff statement" ) self.state = 1 #state 1 def Initialize(self, deltaTime): print("STATE 11111111111111111111") self.lives = 3 self.score = 0 self.state = 2 self.firstBall = True def disableCoils(self, disableFlippers): #for x in self.coilList: #print ("disablecoils functie, for x in self.coilList:") # x.disable() if disableFlippers == True: print("disablecoils functie, if disableFlippers == TRUE") self.scrubMode.disable() self.noobGate.disable() GPIO.output(6, self.LOW) #flippers #state 2 def NewBall(self, deltaTime): print("STATE 2222222222222222222222222") self.disableCoils(True) if self.GPB6_R_BVN2_S23_PADDRAAD_BALLPUSHER.getState() == 1: print("eerste if is geactiveerd") if self.firstBall == False: self.lives -= 1 print("tweede if is geactiveerd") if self.lives <= 0: self.state = -1 print("derde if is geactiveerd") return print("BALL PUSHER ..........................") GPIO.output(24, self.HIGH) #ball pusher print("BALL PUSHER IS AAN") sleep(0.2) GPIO.output(24, self.LOW) #ball pusher print("BALL PUSHER IS UIT") sleep(0.5) if self.GPA1_R_OND2_S24_PADDRAAD_START_BALSCHIETEN.getState() == 0: print("GPA1_R_OND2_S24_PADDRAAD_START_BALSCHIETEN is gelijk aan 0") self.state = 3 print("state wordt 3") self.firstBall = False print("firstbal is FALSE") self.noobGate.reset() print("noobGate resetten") GPIO.output(12, self.HIGH) #hekje print("hekje aan") #Turn on Flippers GPIO.output(6, self.HIGH) ##flippers print("flippers aan") def CheckOtherInputs(self): if (self.GPB3_R_BVN9_S100_SWITCH_WIT_BOVENAAN.getState() == 1 or self.GPA3_R_OND8_S13_PADDRAAD_LINKS_BOVEN.getState() == 1 or self.upperRightBallGate.getState() == 1): if self.scoreActive == False: self.score += 100 self.scoreActive == True else: self.scoreActive = False if (self.GPA2_L_OND5_S25_RUBBERBAND_KICKER_RECHTS_BENEDEN_BOVENSTE. getState() == 1 or self.GPA3_L_OND6_S25_RUBBERBAND_KICKER_RECHTS_BENEDEN_ONDERSTE. getState() == 1 or self.GPA2_R_OND7_S12_2_RUBBERBAND_KICKER_LINKS_BOVEN_ONDERSTE. getState() == 1 or self.GPB5_R_BVN7_S21_RUBBERBAND_KICKER_LINKS_BOVEN_BOVENSTE. getState() == 1 or self.GPB6_R_BVN6_S9_1_RUBBERBAND_KICKER_RECHTS_BOVEN_ONDERSTE. getState() == 1 or self.GPB7_R_BVN5_S16_RUBBERBAND_KICKER_LINKS_MIDDEN.getState() == 1): if self.scoreActive == False: self.score += 2 self.scoreActive == True else: self.scoreActive = False if (self.GPB7_R_BVN1_S21_PADDRAAD_LINKS_BENEDEN.getState() == 1 or self.GPA0_R_OND1_S26_PADDRAAD_RECHTS_BENEDEN.getState() == 1): if self.scoreActive == False: self.score += 15 self.scoreActive == True else: self.scoreActive = False #state 3 def GameLogic(self, deltaTime): print("STATE 3333333333333333333333333333") for x in self.coilList: self.score += x.update(deltaTime) self.scrubMode.update(deltaTime) self.noobGate.update(deltaTime) #self.CheckOtherInputs() if self.GPB6_R_BVN2_S23_PADDRAAD_BALLPUSHER.getState() == 1: self.state = 2 #elif self.tiltSwitch.getState() == 1: #self.state = 4 #state 4 def Tilt(self, deltaTime): print("STATE 4444444444444444444444") #Zet alle Coils even aan self.disableCoils(True) if self.GPB6_R_BVN2_S23_PADDRAAD_BALLPUSHER.getState( ) == 1 or self.GPA1_R_OND2_S24_PADDRAAD_START_BALSCHIETEN.getState( ) == 0: self.state = 2 #state 5 def GameOver(self, deltaTime): print("STATE 555555555555555555555555") self.disableCoils(True) #handle topscoreshizzle print("haat piraat") if self.score >= FlipperGame.highscore3: high = Highscore() #Clock.schedule_interval(high.update, 1.0/60) if self.score >= FlipperGame.highscore2: if self.score >= FlipperGame.highscore1: print("plek 3 gekomen") high.deplaats = 1 high.setScores() else: high.deplaats = 2 print("plek 2 gekomen") high.setScores() else: high.deplaats = 3 print("plek 3 gekomen") high.setScores() self.state = -1 #state -1 def Reset(self, deltaTime): print("STATE -------------11111111111111111111") self.disableCoils(True) #self.scoreChanger.resetScoreReels self.scrubMode.disable() self.state = 0 #creation of state dictionary stateFunctionsDict = { 0: notActive, 1: Initialize, 2: NewBall, 3: GameLogic, 4: Tilt, 5: GameOver, -1: Reset } oldDebugMessage = "" ######################################### #main function. called every 1/60 second# ######################################### def update(self, dt): #calculate the time since the last call and update the elapsed time deltaTime = dt - self.elapsedTime self.elapsedTime = dt deltaTime = 1.0 / 60 #print "State: -1 " + " Score: 0" + " Lives: " + str(self.lives) #print ("State: ")+ str(self.state) + (" Score: ") + str(self.score) + (" Lives: ") + str(self.lives) debugMessage = "State: " + str(self.state) + (" Score: ") + str( self.score) + (" Lives: ") + str(self.lives) if (debugMessage != self.oldDebugMessage): print(debugMessage) self.oldDebugMessage = debugMessage #reset the game if the resetswitch is pressed for 5 seconds if self.startResetSwitch.getState() == 1 and self.state > 1: self.resetSwitchDuration += deltaTime if self.resetSwitchDuration > self.resetMaxDuration: self.state = -1 self.resetSwitchDuration = 0.0 else: self.resetSwitchDuration = 0.0 #call the state function func = self.stateFunctionsDict[self.state] func(self, deltaTime) self.screenScore = self.score self.screenLives = self.lives