示例#1
0
def getTag():
    try:
        data = rfid.readTag()
        if data == False:
            noTag()
        else:
            status["last_read"] = time.time()
            if data == status["current_tag"]:
                if status["current_state"] == "playing":
                    if audio.finishedTrack():
                        toggleTrack()
            else:
                data = str(data)
                status["current_tag"] = data
                status["current_track"] = 0
                status["current_playlist"] = []
                audio.stopMusic()
                if data == "":
                    audio.playSoundEffect(status["current_volume"],
                                          "error.wav")
                    displayText("Empty tag!")
                else:
                    getPlaylist(data)
        time.sleep(0.5)
    except:
        pass
示例#2
0
def enterWriteState(data):
    audio.playSoundEffect(0.5, "select.wav")
    allowWrite = False
    if data is None or data == "":
        allowWrite = True
    else:
        displayText("Write state:^Confirm action!")
        populatedTagInput = raw_input(
            "The inserted tag is already populated with '" + data +
            "'.\nEnter Y/N to proceed: ")
        if populatedTagInput.lower() == "y":
            allowWrite = True
    if allowWrite:
        displayText("Write state:^Name the tag!")
        nameTagInput = raw_input(
            "Populate the inserted tag with the name of your choice. Max 16 characters!\nEnter name: "
        )
        dataWritten = False
        endTime = time.time() + 2.5
        while time.time() < endTime:
            if dataWritten == False:
                if rfid.writeTag(nameTagInput):
                    dataWritten = True
                    audio.playSoundEffect(0.5, "write.wav")
                    displayText("Write state:^Success!")
                    status["current_tag"] = data
示例#3
0
def exit():
    audio.stopMusic(True)
    audio.playSoundEffect(status["current_volume"], "power-off.wav")
    displayText("Good bye!", 1)
    time.sleep(1.5)
    GPIO.output(cfg.pins["led"], GPIO.LOW)
    lcd.exit()
    GPIO.cleanup()
    subprocess.call(['shutdown', '-h', 'now'], shell=False)
示例#4
0
def exit():
    audio.playSoundEffect(0.5, "power-off.wav")
    displayText("Good bye!", 1)
    GPIO.output(cfg.pins["led"], GPIO.LOW)
    lcd.exit()
    GPIO.cleanup()
    try:
        sys.exit(0)
    except SystemExit:
        os._exit(0)
示例#5
0
def init(sceneMan, score):
    global __sceneMan, __gameOverImg, __state, __currentScore

    __currentScore = score
    __state = NORMAL_STATE
    __sceneMan = sceneMan
    audio.playSoundEffect('gameover.wav')
    __gameOverImg = ImgObj(gConf.SCREEN_W // 2, gConf.SCREEN_H * 0.25,
                           'res/img/gameover.png', ImgObj.CENTER_STYLE)
    __sceneMan.add(__gameOverImg, SceneManager.MENU_L)
    __initialsImg.clear()
示例#6
0
 def setExplosion(self):
     self.state = Enemy04.EXPLODE
     w = self.getRect().width // 4
     h = self.getRect().height // 4
     self.__explosion[0].setPos(self.x - w - random.randint(0, 10),
                                self.y - h - random.randint(0, 10))
     self.__explosion[1].setPos(self.x + w + random.randint(0, 10),
                                self.y - h - random.randint(0, 10))
     self.__explosion[2].setPos(self.x - w - random.randint(0, 10),
                                self.y + h + random.randint(0, 10))
     self.__explosion[3].setPos(self.x + w + random.randint(0, 10),
                                self.y + h + random.randint(0, 10))
     audio.playSoundEffect('bexp.wav')
示例#7
0
def initialize():
    #kill tinystereo.py
    GPIO.setwarnings(cfg.pins["warnings"])
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(cfg.pins["buttons"]["power"], GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(cfg.pins["led"], GPIO.OUT)
    GPIO.output(cfg.pins["led"], GPIO.HIGH)
    GPIO.add_event_detect(cfg.pins["buttons"]["power"],
                          GPIO.BOTH,
                          callback=toggleButton,
                          bouncetime=200)
    lcd.initialize()
    audio.initialize(0.5)
    audio.playSoundEffect(0.5, "power-on.wav")
    displayText("Write state:^Insert tag!")
    time.sleep(1)
示例#8
0
def initialize():
    if lockFile():
        GPIO.setwarnings(cfg.pins["warnings"])
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(cfg.pins["buttons"]["power"],
                   GPIO.IN,
                   pull_up_down=GPIO.PUD_UP)
        GPIO.setup(cfg.pins["buttons"]["next"],
                   GPIO.IN,
                   pull_up_down=GPIO.PUD_UP)
        GPIO.setup(cfg.pins["buttons"]["volume_up"],
                   GPIO.IN,
                   pull_up_down=GPIO.PUD_UP)
        GPIO.setup(cfg.pins["buttons"]["volume_down"],
                   GPIO.IN,
                   pull_up_down=GPIO.PUD_UP)
        GPIO.setup(cfg.pins["led"], GPIO.OUT)
        GPIO.output(cfg.pins["led"], GPIO.HIGH)
        GPIO.add_event_detect(cfg.pins["buttons"]["power"],
                              GPIO.BOTH,
                              callback=toggleButton,
                              bouncetime=200)
        GPIO.add_event_detect(cfg.pins["buttons"]["next"],
                              GPIO.BOTH,
                              callback=toggleButton,
                              bouncetime=200)
        GPIO.add_event_detect(cfg.pins["buttons"]["volume_up"],
                              GPIO.BOTH,
                              callback=toggleButton,
                              bouncetime=200)
        GPIO.add_event_detect(cfg.pins["buttons"]["volume_down"],
                              GPIO.BOTH,
                              callback=toggleButton,
                              bouncetime=200)
        lcd.initialize()
        displayText("Tiny Stereo -^Insert tag!")
        audio.initialize(status["current_volume"])
        audio.playSoundEffect(status["current_volume"], "power-on.wav")
        time.sleep(1)
    else:
        try:
            sys.exit(0)
        except:
            os._exit(0)
示例#9
0
def getPlaylist(data):
    playlist = audio.getPlaylist(data)
    if len(playlist):
        random.shuffle(playlist)
        status["current_playlist"] = playlist
        if audio.playMusic(playlist, 0):
            audio.playSoundEffect(status["current_volume"], "select.wav")
            status["current_state"] = "playing"
            status["current_track"] = 0
            displayTrackInfo()
        else:
            audio.playSoundEffect(status["current_volume"], "error.wav")
            displayText("Empty playlist!")
    else:
        status["current_playlist"] = []
        audio.playSoundEffect(status["current_volume"], "error.wav")
        displayText("Unknown tag!")
示例#10
0
 def doPowerUp(self, obj):
     if self.__objType == self.POWERUP01_TYPE:
         audio.playSoundEffect('hppowerup.wav')
         obj.updateHP(20)
示例#11
0
 def setExplosion(self):
     self.state = Enemy01.EXPLODE
     self.__explosion.setPos(self.x, self.y)
     audio.playSoundEffect('eexp.wav')
示例#12
0
def main():
    global __gameOverImg, __state, __currentScore, __currentInitialIndex, \
           __noKeyPressed, __inputDelayTimer

    if __state == NORMAL_STATE:
        # Done rendering "Game Over"
        if not __gameOverImg.isAnimating():
            bmpText = None
            rank = persistence.checkRankings(__currentScore)
            if rank < 0:
                bmpText = BmpText(gConf.SCREEN_W // 2, gConf.SCREEN_H * 0.6,
                                  "PRESS A BUTTON TO RETURN TO MENU",
                                  BmpText.SMALL_FNT, BmpText.CENTER_ALIGN,
                                  True, True)
                __sceneMan.add(bmpText, SceneManager.MENU_L)
                __state = DONE_STATE
            else:
                # Player's score made it into the ten best scores
                bmpText = BmpText(gConf.SCREEN_W // 2, gConf.SCREEN_H * 0.5,
                                  "YOUR HIGH SCORE RANKING: " + str(rank + 1) +
                                  rankingscr.appendRankSuffix(rank),
                                  BmpText.SMALL_FNT, BmpText.CENTER_ALIGN)
                __sceneMan.add(bmpText, SceneManager.MENU_L)
                bmpText = BmpText(gConf.SCREEN_W // 2, gConf.SCREEN_H * 0.6,
                                  "ENTER YOUR INITIALS:", BmpText.SMALL_FNT,
                                  BmpText.CENTER_ALIGN)
                __sceneMan.add(bmpText, SceneManager.MENU_L)
                __state = INPUTNAME_STATE
                __currentInitialIndex = 0
                startX = (gConf.SCREEN_W // 2) - 32
                for i in range(4):
                    initialChars = 'A'
                    if i == 3:
                        initialChars = '_'  # Display 'END'
                    bmpText = BmpText(startX,
                                      gConf.SCREEN_H * 0.725,
                                      initialChars,
                                      BmpText.BIG_FNT, BmpText.CENTER_ALIGN)
                    __sceneMan.add(bmpText, SceneManager.MENU_L)
                    startX += 32
                    __initialsImg.append(bmpText)
                __initialsImg[0].setBlink(True)
                __noKeyPressed = True
                __inputDelayTimer = pygame.time.get_ticks()
    elif __state == INPUTNAME_STATE:
        if not(gInps.isButtonDown() or gInps.isButtonUp() or
               gInps.isButtonLeft() or gInps.isButtonRight()):
            __noKeyPressed = True

        if pygame.time.get_ticks() - __inputDelayTimer > 225 or \
           __noKeyPressed:
            if gInps.isButtonDown() or gInps.isButtonUp() or \
               gInps.isButtonLeft() or gInps.isButtonRight():
                __noKeyPressed = False
                if __currentInitialIndex == 3:
                    curChar = __initialsImg[__currentInitialIndex].getText()
                    if curChar == '_':
                        curChar = '^'
                    else:
                        curChar = '_'
                    __initialsImg[__currentInitialIndex].setText(curChar)

            if __currentInitialIndex < 3:
                if gInps.isButtonDown() or gInps.isButtonRight():
                    curChar = __initialsImg[__currentInitialIndex].getText()
                    if curChar == 'Z':
                        curChar = 'A'
                    else:
                        curChar = chr(ord(curChar) + 1)
                    __initialsImg[__currentInitialIndex].setText(curChar)
                elif gInps.isButtonUp() or gInps.isButtonLeft():
                    curChar = __initialsImg[__currentInitialIndex].getText()
                    if curChar == 'A':
                        curChar = 'Z'
                    else:
                        curChar = chr(ord(curChar) - 1)
                    __initialsImg[__currentInitialIndex].setText(curChar)
            __inputDelayTimer = pygame.time.get_ticks()

        if gInps.isButtonHit():
            __initialsImg[__currentInitialIndex].setBlink(False)
            # Confirm single initial
            if __currentInitialIndex < 3:
                __currentInitialIndex += 1
                __initialsImg[__currentInitialIndex].setBlink(True)
                audio.playSoundEffect('beep.wav')
            else:
                # Confirm initials
                curChar = __initialsImg[__currentInitialIndex].getText()
                if curChar == '_':  # END
                    name = ''
                    for i in range(3):
                        name += __initialsImg[i].getText()
                    bmpText = BmpText(gConf.SCREEN_W // 2,
                                      gConf.SCREEN_H * 0.875,
                                      "CONGRATULATIONS!", BmpText.SMALL_FNT,
                                      BmpText.CENTER_ALIGN, True, True)
                    __sceneMan.add(bmpText, SceneManager.MENU_L)
                    persistence.insertRankings(__currentScore, name)
                    __state = DONE_STATE
                    audio.playSoundEffect('done.wav')
                else:  # DEL
                    # Re-input initials
                    __initialsImg[__currentInitialIndex].setText('_')
                    __currentInitialIndex = 0
                    __initialsImg[__currentInitialIndex].setBlink(True)
                    audio.playSoundEffect('beep.wav')
    elif __state == DONE_STATE:
        if gInps.isButtonHit():
            return -1
    return 0