Example #1
0
def startProgramm(teamid):
    #Rennvorbereitung und Startsequenz
    activeCheckpoint = 1  #Checkpoint 1 ist der nächste Checkpoint nach dem Start
    x = time.time()  #Nur ein Platzhalter vom richtigen Datentyp
    rslt.showResults(0, teamid, x)
    sound.playSound(-3)
    sound.playSpeech(0, teamid)
    lit.playStartSequence()
    starttime = time.time()

    while teamid != 0:  #Schleife während des Rennens
        if cpl.checkpointReached(
                activeCheckpoint % 4
        ):  #Kontrolliert jeweils den nächsten Checkpoint nach dem zuletzt durchfahrenen, misst Zeiten, spielt Sounds und aktualisiert Zwischenergebnisse
            cpl.saveTime(starttime, activeCheckpoint % 4)
            _thread.start_new_thread(sound.playSound,
                                     (activeCheckpoint, teamid, starttime))
            rslt.showResults(activeCheckpoint, teamid, starttime)
            activeCheckpoint += 1
        if activeCheckpoint == 9:  #beendet das Rennen, speichert und zeigt Ergebnisse, spielt entsprechende Sounds & Sprache und resettet Checkpoints
            cpl.prepareDataForDB(teamid)
            rslt.showResults(9, teamid, starttime)
            lit.raceEnd()
            time.sleep(6)
            sound.playSpeech(9, teamid, starttime)
            activeCheckpoint = 1
            teamid = 0
            cpl.resetAll()
Example #2
0
 def update(self, dt):
     import sound
     self.world.loop(dt/500.0)
     for evt in self.world.get_events():
         print 'EVENTO:',evt
         if isinstance(evt, world.Collision):
             #print evt.ball.velocity.magnitude(), evt
             n = evt.ball.velocity.magnitude()/50
             if (n>1.0):
                 n = 1.0
             vol = 1.0
             sound.playSound(n, vol)
             
         if isinstance(evt, world.NewObject):
             if isinstance(evt.object, world.Ball):
                 self.addBall(evt.object)
             elif isinstance(evt.object, world.Segment):
                 self.addSegment(evt.object)    
             elif isinstance(evt.object, world.Generator):
                 self.addGenerator(evt.object)
             elif isinstance(evt.object, world.Goal):
                 self.addGoal(evt.object)
             else:
                 print repr(evt.object)        
                 print evt.object    
                 print evt.object.__class__
                 raise "Unknown Object"
     self._update_camera(pygame.mouse.get_pos())
Example #3
0
def onHit(self, damage):
	import random
	import sound
	self.health -= damage
	sound.playSound("Sounds/GettingHit"+str(random.randint(1,5))+".mp3")
	if self.health <= 0.:
		sound.playSound("Sounds/SterbenMitFX.mp3")
		self.remove()
Example #4
0
def startProgramm(teamid):
    #identified = False
    activeCheckpoint = 1
    #teamid = teamid
    print("running")
    while identified == False:  #Loop solange kein Auto identifiziert ist
        print("startWhile")
        #qr.readQRCode()
        #teamid = 1 #qr.readQRCode()                      #Wenn der Scan funktioniert hat, wird die teamid und ein True-Flag zurückgegeben
        if teamid != 0:
            identified = True  #Initialisiere Startsequenz sobald ein Auto erkannt wurde
            print("identified")
            x = time.time()
            rslt.showResults(0, teamid,
                             x)  #zeigt bisherige Ergebnisse des Teams an
            sound.playSound(-3)
            #sound.playSpeech(0, teamid)                          #erzählt infos zum Team
            print("sound played")
            fehlstart = lit.playStartSequence(
            )  #startet Ampel, Sounds und Fehlstartkontrolle
            print("light lit")
            if fehlstart:
                print("Fehlstart")
                break
            print("starttime")
            print(teamid)
            starttime = time.time(
            )  #startet die Zeitmessung unabhängig davon, ob das Auto zu spät los fährt
    print("waiting for checkpoints")
    while identified == True:  #Loop für Rennen, Messung etc.

        if cpl.checkpointReached(activeCheckpoint % 4):
            print("cpReached")
            cpl.saveTime(
                starttime, activeCheckpoint %
                4)  #speichert die LiveZeit vom aktuellen Checkpoint [0,1,2,3]
            #_thread.start_new_thread(lit.startLightExpress,())  #Ampel leuchtet, checkpointabhängig, läuft parallel
            #_thread.start_new_thread(sound.playSound,(activeCheckpoint))        #Spielt parallel den Sound, checkpointabhängig [1...8]
            #_thread.start_new_thread(sound.playSpeech,(activeCheckpoint, teamid)) #spricht (parallel),checkpointabhängig [1...8],teamid?
            rslt.showResults(activeCheckpoint, teamid,
                             starttime)  #Zeigt Ergebnisse
            activeCheckpoint += 1
            print("nextCheckpoint:")
            print(activeCheckpoint)
        if activeCheckpoint == 8:
            _thread.start_new_thread(lit.startLightExpress, ())
        if activeCheckpoint == 9:  #beendet das Rennen, speichert und zeigt Ergebnisse
            cpl.prepareDataForDB(
                teamid
            )  #rechnet einzelne Zeiten aus und schreibt diese in die DB
            rslt.showResults(9, teamid, starttime)
            rslt.showTime(starttime)
            lit.raceEnd()
            print("Rennen beendet")
            while 1:
                time.sleep(1)
Example #5
0
    def update(self, dt):
        import sound
        self.world.loop(self.step)
        for evt in self.world.get_events():
            #print 'EVENTO:',evt
            if isinstance(evt, world.Collision):
                n = evt.ball.velocity.magnitude()/50
                if (n>1.0):
                    n = 1.0
                vol = 1.0
                sound.playSound(n, vol)
                
            elif isinstance(evt, world.BallAtGoal):
                self.ballsAtGoal += 1
                self.lost-=1
                if self.ballsAtGoal>=self.target:
                    #you won
                    self.levelFinished()

            elif isinstance(evt, world.ObjectGone):
                self.group.remove(evt.object.group)
                if isinstance(evt.object, world.Ball):
                    self.lost+=1
                    if self.lost>=self.lives:
                        self.levelLost()
                
            elif isinstance(evt, world.NewObject):
                # check hierarchy upside-down
                if isinstance(evt.object, world.Ball):
                    self.addBall(evt.object)
                elif isinstance(evt.object, world.Floor):
                    self.addFloor(evt.object)
                elif isinstance(evt.object, world.LimitedLifeSegment):
                    self.addLimitedLifeSegment(evt.object)
                elif isinstance(evt.object, world.Segment):
                    self.addSegment(evt.object)    
                elif isinstance(evt.object, world.Generator):
                    self.addGenerator(evt.object)
                elif isinstance(evt.object, world.Goal):
                    self.addGoal(evt.object)
                elif isinstance(evt.object, world.Ceiling):
                    self.addCeiling(evt.object)
                elif isinstance(evt.object, world.Attractor):
                    self.addAttractor(evt.object)
                else:
                    print evt.object    
                    print evt.object.__class__
                    raise "Unknown Object"
        self._update_camera2(pygame.mouse.get_pos())
Example #6
0
    def update(self, dt):
        import sound
        self.world.loop(self.step)
        for evt in self.world.get_events():
            #print 'EVENTO:',evt
            if isinstance(evt, world.Collision):
                n = evt.ball.velocity.magnitude() / 50
                if (n > 1.0):
                    n = 1.0
                vol = 1.0
                sound.playSound(n, vol)

            elif isinstance(evt, world.BallAtGoal):
                self.ballsAtGoal += 1
                self.lost -= 1
                if self.ballsAtGoal >= self.target:
                    #you won
                    self.levelFinished()

            elif isinstance(evt, world.ObjectGone):
                self.group.remove(evt.object.group)
                if isinstance(evt.object, world.Ball):
                    self.lost += 1
                    if self.lost >= self.lives:
                        self.levelLost()

            elif isinstance(evt, world.NewObject):
                # check hierarchy upside-down
                if isinstance(evt.object, world.Ball):
                    self.addBall(evt.object)
                elif isinstance(evt.object, world.Floor):
                    self.addFloor(evt.object)
                elif isinstance(evt.object, world.LimitedLifeSegment):
                    self.addLimitedLifeSegment(evt.object)
                elif isinstance(evt.object, world.Segment):
                    self.addSegment(evt.object)
                elif isinstance(evt.object, world.Generator):
                    self.addGenerator(evt.object)
                elif isinstance(evt.object, world.Goal):
                    self.addGoal(evt.object)
                elif isinstance(evt.object, world.Ceiling):
                    self.addCeiling(evt.object)
                elif isinstance(evt.object, world.Attractor):
                    self.addAttractor(evt.object)
                else:
                    print evt.object
                    print evt.object.__class__
                    raise "Unknown Object"
        self._update_camera2(pygame.mouse.get_pos())
Example #7
0
def playSoundMethod(uri):
    global loop
    loop = glib.MainLoop()
    playSoundClass = playSound(uri, loop=loop)
    thread.start_new_thread(playSoundClass.start, ())
    gobject.threads_init()
    loop.run()
Example #8
0
            rslt.showResults(activeCheckpoint, teamid, starttime)
            activeCheckpoint += 1
        if activeCheckpoint == 9:  #beendet das Rennen, speichert und zeigt Ergebnisse, spielt entsprechende Sounds & Sprache und resettet Checkpoints
            cpl.prepareDataForDB(teamid)
            rslt.showResults(9, teamid, starttime)
            lit.raceEnd()
            time.sleep(6)
            sound.playSpeech(9, teamid, starttime)
            activeCheckpoint = 1
            teamid = 0
            cpl.resetAll()


try:
    teamid = 0
    while 1:
        teamid = qr.readQRCode(
        )  #Führt solange die QR-Code Funktion aus, bis diese ein Auto erkennt. Erfasst die TeamID
        if teamid != 0:
            startProgramm(
                teamid)  #Wurde ein Auto erkannt, wird die Rennlogik ausgeführt
            time.sleep(
                8
            )  #verhindert Probleme,wenn in zwei Threads SOunds abgespielt werden. Der Pi hat keine Mischfunktion und kann immer nur in einem Thread Sound ausgeben.
            sound.playSound(
                -4)  #signalisiert Bereitschaft zum erneuten Rennstart
except KeyboardInterrupt:  #Manueller Abbruch über die Konsole
    print("Programm aborted")
    lit.raceEnd()  #schaltet die LEDs aus und deinitialisiert diese
    cpl.GPIO.cleanup()  #resettet die GPIOs und gibt diese wieder frei
    pass
Example #9
0
 def play(soundfile, soundhandle='PRIMARY'):
     sound.playSound(soundfile, soundhandle)
Example #10
0
        print("Invalid arguments")
        sys.exit(1)
    else:
        ser = serial.Serial("/dev/ttyACM0", 9600, timeout=1)
        ser.flush()
        while True:
            ser.write(b"PING\n")
            line = ser.readline().decode('utf-8').rstrip()
            if line == "REDE" or line == "LIVE":
                break

        def waitFor(target: str) -> None:
            while True:
                ser.write(b"STATUS\n")
                s = ser.readline().decode('utf-8').rstrip()
                print(s)
                if s == target:
                    return

        for _ in range(int(sys.argv[1])):
            print("lighting up!")
            ser.write(b"start\n")
            waitFor("Starting lights.")
            sound.playSound()
            time.sleep(.05)
            print("stopping")
            ser.write(b"cut\n")
            waitFor("Stopping lights")
            time.sleep(0.5)
        print("done.")
Example #11
0
def playStartSequence():
    sound.playSound(-2)
    print("firstLight")
    firstLight()
    strip.show()
    #time.sleep(2)
    sound.playSound(-1)
    check = False #cpl.checkpointReached(0)
    if check == True:                  
        print("Fehlstart")
        allOff()
        strip.show()
        time.sleep(0.5)
        flashRed()
        sound.playSound('')               #Hier fehlt noch Variable für Loser Sound
        allOff()
        strip.show()
        return True               
                                    
    else:
        print("SecondLight")
        secondLight()
        strip.show()
        #time.sleep(2)
        sound.playSound(-1)
        check = False #cpl.checkpointReached(0)
        if check == True:
            print("Fehlstart")
            allOff()
            strip.show()
            time.sleep(0.5)
            flashRed()
            #sound.playSound('')
            allOff()
            strip.show()
            return True
            
        else:
            print("allRed")
            allRed()
            strip.show()
            #time.sleep(2)
            sound.playSound(-1)
            check = False #cpl.checkpointReached(0)
            if check == True:
                print("Fehlstart")
                allOff()
                strip.show()
                time.sleep(0.5)
                flashRed()
                sound.playSound('')
                allOff()
                strip.show()
                return True
            
            else:
                print("allGreen")
                allGreen()
                startSignal = 1
                strip.show()
                #time.sleep(2)
                sound.playSound(0)
                allOff()
                strip.show()
Example #12
0
 def play(soundfile, soundhandle='PRIMARY'):
     sound.playSound(soundfile,soundhandle)