Beispiel #1
0
def wavSing(loopedsheet, instruments, key, ticktime, filename, hidefinal=False):
    from Waves import initArray, FREQS
    cues = []
    offset = NOTES.index(key) + 48 # Middle C is MIDI note #48    
    for track in loopedsheet:
        cuedtrack = track[1:]
        cuedtrack.append((track[0], 0)) # append tracklength to the end so i+1 still works for last note
        cues.append([(cuedtrack[i + 1][0] - cuedtrack[i][0], cuedtrack[i][1] + offset) for i in range(0, len(cuedtrack) - 1)])
    # cues now contains the sheet in a usable format
    startprogress('Generating waves: ')
    waves = []
    vol = 1.0 / len(cues)
    notecount = rlen(cues) // 2
    progress = 0.0
    instscpy=instruments[:]
    for track in cues:
        trackwave = initArray()
        instrument = instscpy.pop(0)
        for (duration, note) in track:
            trackwave.extend(Waves.cachedWaveGen(FREQS[note], duration * ticktime, instrument, vol))
            progress += 1.0
            updateprogress(progress / notecount)
        waves.append(trackwave)
    replaceprint('Creating mixdown...' + ' ' * 30)
    wave = Waves.mergeWaves(waves)
    replaceprint('Writing file...')
    Waves.makeWavFile(wave, filename+".wav")
    replaceprint('Synth complete!')
    if not hidefinal:print("\nWAV output to: \"" + filename + ".wav\"")
Beispiel #2
0
def wavSing(loopedsheet,
            instruments,
            key,
            ticktime,
            filename,
            hidefinal=False):
    from Waves import initArray, FREQS
    cues = []
    offset = NOTES.index(key) + 48  # Middle C is MIDI note #48
    for track in loopedsheet:
        cuedtrack = track[1:]
        cuedtrack.append(
            (track[0], 0)
        )  # append tracklength to the end so i+1 still works for last note
        cues.append([(cuedtrack[i + 1][0] - cuedtrack[i][0],
                      cuedtrack[i][1] + offset)
                     for i in range(0,
                                    len(cuedtrack) - 1)])
    # cues now contains the sheet in a usable format
    startprogress('Generating waves: ')
    waves = []
    vol = 1.0 / len(cues)
    notecount = rlen(cues) // 2
    progress = 0.0
    instscpy = instruments[:]
    for track in cues:
        trackwave = initArray()
        instrument = instscpy.pop(0)
        for (duration, note) in track:
            trackwave.extend(
                Waves.cachedWaveGen(FREQS[note], duration * ticktime,
                                    instrument, vol))
            progress += 1.0
            updateprogress(progress / notecount)
        waves.append(trackwave)
    replaceprint('Creating mixdown...' + ' ' * 30)
    wave = Waves.mergeWaves(waves)
    replaceprint('Writing file...')
    Waves.makeWavFile(wave, filename + ".wav")
    replaceprint('Synth complete!')
    if not hidefinal: print("\nWAV output to: \"" + filename + ".wav\"")
Beispiel #3
0
    def __init__(self):
        pygame.init()
        pygame.display.set_caption("Fever Fighter")
        self.clock = pygame.time.Clock()

        self.game_canvas = Canvas.Canvas(self, 800, 600)
        self.input_handler = InputHandler.InputHandler(self)
        self.player = Player.Player(100, 100, 30, 30, 100, 100)
        #self.enemy = Enemy.Enemy()

        self.entities = []
        self.entities.append(self.player)
        #self.entities.append(enemy)

        self.running = True

        self.wave = Waves.Waves()
Beispiel #4
0
    def __init__(self, frame):
        self.width = 0
        self.height = 0
        self.frame = frame
        self.width, self.height = pygame.display.get_surface().get_size()

        pygame.display.set_caption("Fishin' Mission")
        self.frame.fill((135, 206, 235))
        self.cloud = Clouds.Clouds(self.frame)
        self.fisher = Fisher.Fisher(self.frame)
        self.boat = Boat.Boat(self.frame)
        self.rod = Rod.Rod(self.frame)
        self.wave = Waves.Waves(self.frame)
        self.score = Score.Score(self.frame)
        self.upgrades = Upgrades.Upgrades(self.frame)
        self.trash_list = []
        self.trash_interval = 6
        self.start_time = time.time()
        self.fish1_list = []
        self.fish2_list = []
        self.fish3_list = []
        self.fish1_interval = 10
        self.fish2_interval = 5
        self.fish3_interval = 20
        self.trashCount = 0
        self.fish1Count = 0
        self.fish2Count = 0
        self.fish3Count = 0

        # Load Fish Images
        self.image1 = pygame.image.load('images/small fish.png')
        self.image2 = pygame.image.load('images/medium sized fish.png')
        self.image3 = pygame.image.load('images/big fish.png')
        self.fish1width = 117
        self.fish1height = 117
        self.fish2width = 146
        self.fish2height = 146
        self.fish3width = 176
        self.fish3height = 176
        self.image1 = pygame.transform.scale(
            self.image1, (self.fish1width, self.fish1height))
        self.image2 = pygame.transform.scale(
            self.image2, (self.fish2width, self.fish2height))
        self.image3 = pygame.transform.scale(
            self.image3, (self.fish3width, self.fish3height))
Beispiel #5
0
##days = Dates.DayLocator((5,10,15,20,25,30))
##daysFmt= Dates.DateFormatter("%b-%d")   
##MaxVal = None

##Figure 2
##infilename = "WaveSpectrum-Fig2.txt"
##outfilename = infilename[:-4]
##bins, Es, dates = W.ReadNDBCSpectrum(infilename)
##days = Dates.MonthLocator()
##daysFmt= Dates.DateFormatter("%b-%y")   
##MaxVal = None

##Figure 3
infilename = "WaveSpectrum-Fig2.txt"
outfilename = infilename[:-5] + "3"
bins, Es, dates = W.ReadNDBCSpectrum(infilename)
days = Dates.MonthLocator()
daysFmt= Dates.DateFormatter("%b-%y")   
MaxVal = 20


dates = [ ([int(x) for x in i]) for i in dates ]
datetimes = [datetime.datetime(*i) for i in dates]

# convert bins (Hz) to k:
omega = 2 * N.pi * bins
k = W.WaveNumber(g, omega, h)

# convert to energy at the bottom:
Eb = Es / (N.sinh(k*h)**2)
Beispiel #6
0
def game():

    if Globals.clearSprites == True:
        Globals.environment.empty()
        Globals.powerups.empty()
        Globals.fireballs.empty()
        Globals.enemySprites.empty()
        Globals.gameGUI.empty()

    pygame.display.set_caption(
        "Knight Hunter - Defend against the vicious knights")

    Globals.screen.blit(Globals.background, (0, 0))

    field = Field.Field()
    dragon = Dragon.Dragon()
    growthBarOutline = ScoreboardGUI.GrowthBarGUI()
    scoreboard = ScoreboardGUI.ScoreboardGUI()
    fieldSprite = pygame.sprite.Group(field)
    friendlySprites = pygame.sprite.Group(dragon)
    scoreSprites = pygame.sprite.Group(scoreboard, growthBarOutline)

    if Globals.resume == False:
        Globals.score = 0
        Waves.spawnWave(Globals.currentWave)
        # SpawnSprites.spawnGrowthBarFill(Globals.meat)
        Globals.clearSprites = False

    clock = pygame.time.Clock()
    keepGoing = True
    while keepGoing:
        clock.tick(30)
        pygame.mouse.set_visible(False)
        for event in pygame.event.get():

            #clearing sprites without leaving the game() function
            #if Globals.clearSprites == True:
            #Globals.environment.empty()
            #Globals.powerups.empty()
            #Globals.fireballs.empty()
            #Globals.enemySprites.empty()
            #Globals.gameGUI.empty()

            print Globals.growthBar
            print len(Globals.growthBar)
            print Globals.growthBarFill

            if scoreboard.lives <= -1:
                Globals.gameOver = True
                Globals.resume = False
                Globals.clearSprites = True
                Globals.mainGame = False
                keepGoing = False

            if event.type == pygame.QUIT:
                Globals.donePlaying = True
                keepGoing = False

            elif event.type == pygame.KEYDOWN:
                keyName = pygame.key.name(event.key)
                if event.key == pygame.K_ESCAPE:
                    Globals.donePlaying = True
                    keepGoing = False

                if event.key == pygame.K_p:
                    keepGoing = False
                    Globals.pauseMenu = True
                    Globals.mainGame = False
                    Globals.resume = True
                    Globals.clearSprites = False

        hitEnvironment = pygame.sprite.spritecollide(dragon,
                                                     Globals.environment,
                                                     False)
        for theEnvironment in hitEnvironment:
            if theEnvironment.type == Globals.environmentTree:
                dragon.state = dragon.STANDING
                dragon.dx = 0
                dragon.dy = 0
            elif theEnvironment.type == Globals.environmentBoulder:
                dragon.dx = 0
                dragon.dy = 0

        hitPowerUp = pygame.sprite.spritecollide(dragon, Globals.powerups,
                                                 True)
        for powerUps in hitPowerUp:
            print powerUps.type
            if powerUps.type == Globals.powerUpSmallMeat:
                print Globals.growth
                #dragon.sndEat.play()
                Globals.score += 500
                Globals.meat += 1
                #SpawnSprites.spawnGrowthBarFill(Globals.meat)
                if Globals.meat >= 30:
                    Globals.meat = 30
                scoreboard.score = Globals.score

            elif powerUps.type == Globals.powerUpLargeMeat:
                print Globals.growth
                #dragon.sndEat.play()
                Globals.score += 1250
                Globals.meat += 2
                if Globals.meat >= 30:
                    Globals.meat = 30
                scoreboard.score = Globals.score

            elif powerUps.type == Globals.powerUpExtraLife:
                #dragon.sndExtraLife.play()
                Globals.score += 75
                Globals.lives += 1
                scoreboard.lives = Globals.lives
                scoreboard.score = Globals.score

            elif powerUps.type == Globals.powerUpFlameCone3:
                # this will give score, destroy the sprite, and start counting
                # down the timer for the flame cone
                Globals.score += 150
                dragon.powerupactive = dragon.FLAMECONE3

            elif powerUps.type == Globals.powerUpFlameCone5:
                # this will give score, destroy the sprite, and start counting
                # down the timer for the flame cone
                Globals.score += 350
                dragon.powerupactive = dragon.FLAMECONE5

            else:
                print "got a power up type I don't understand"

        bounceEnemies = pygame.sprite.groupcollide(Globals.environment,
                                                   Globals.enemySprites, False,
                                                   False)
        if bounceEnemies:
            for theEnemyBounce in bounceEnemies:
                if theEnemyBounce.type == Globals.enemySpearKnight:
                    theEnemyBounce.dx *= -1
                    theEnemyBounce.dy *= -1

        hitEnemies = pygame.sprite.spritecollide(dragon, Globals.enemySprites,
                                                 True)
        if hitEnemies:
            for theEnemyHit in hitEnemies:
                if theEnemyHit.type == Globals.enemySpearKnight:
                    SpawnSprites.spawnEnemy(SpearKnight.SpearKnight, 1, 2)
                #elif theEnemyHit == SpearKnightMedium:
                #SpawnSprites.spawnEnemy(SpearKnight.SpearKnight, 1, 4, SpawnSprites)
                #elif theEnemyHit == SpearKnightFast:
                #SpawnSprites.spawnEnemy(SpearKnight.SpearKnight, 1, 8, SpawnSprites)
                else:
                    print theEnemyHit
                    print theEnemyHit.type
                    print "enemy spawn error"

                Globals.lives -= 1
                Globals.meat /= 2
                scoreboard.lives = Globals.lives
                dragon.reset()

        for fireball in Globals.fireballs:
            burnEnemies = pygame.sprite.spritecollide(fireball,
                                                      Globals.enemySprites,
                                                      True)
            if burnEnemies:
                for enemyBurned in burnEnemies:
                    Globals.score += 3000
                    scoreboard.score = Globals.score
                    #fireball.sndKill.play()
                    fireball.kill()
                    SpawnSprites.spawnIten(SmallMeat.SmallMeat, 1,
                                           enemyBurned.x, enemyBurned.y)
                    #SpawnSprites.spawnItem(SmallMeat.SmallMeat, 1, enemyBurned.x, enemyBurned.y)

        for fireball in Globals.fireballs:
            burnEnvironment = pygame.sprite.spritecollide(
                fireball, Globals.environment, False)
            for theEnvironment in burnEnvironment:
                if theEnvironment.type == Globals.environmentTree:
                    theEnvironment.kill()
                    Globals.score += 50
                    scoreboard.score = Globals.score
                    #fireball.sndKill.play()
                    fireball.kill()
                elif theEnvironment.type == Globals.environmentBoulder:
                    fireball.kill()

        if len(Globals.enemySprites) == 0:
            if Globals.currentWave > 10:
                Globals.winScreen = True
                Globals.resume = False
                Globals.clearSprites = True
                Globals.mainGame = False
                keepGoing = False
            else:
                Globals.currentWave += 1
                dragon.reset()
                Globals.clearSprites = True
                Globals.resume = True
                Waves.spawnWave(Globals.currentWave)

        SpawnSprites.spawnGrowthBarFill(ScoreboardGUI.GrowthBarFillGUI,
                                        Globals.meat)
        fieldSprite.update()
        Globals.fireballs.update()
        Globals.environment.update()
        Globals.enemySprites.update()
        Globals.gameGUI.update()
        friendlySprites.update()
        scoreSprites.update()

        fieldSprite.draw(Globals.screen)
        Globals.fireballs.draw(Globals.screen)
        Globals.powerups.draw(Globals.screen)
        Globals.environment.draw(Globals.screen)
        Globals.enemySprites.draw(Globals.screen)
        friendlySprites.draw(Globals.screen)
        Globals.gameGUI.draw(Globals.screen)
        scoreSprites.draw(Globals.screen)
        Globals.powerups.update()

        pygame.display.flip()

    pygame.mouse.set_visible(True)
Beispiel #7
0
def game():
    
    if Globals.clearSprites == True:
        Globals.environment.empty()
        Globals.powerups.empty()
        Globals.fireballs.empty()
        Globals.enemySprites.empty()
        Globals.gameGUI.empty()
        

    pygame.display.set_caption("Knight Hunter - Defend against the vicious knights")

    Globals.screen.blit(Globals.background, (0, 0))
    
    field = Field.Field()
    dragon = Dragon.Dragon()
    growthBarOutline = ScoreboardGUI.GrowthBarGUI()
    scoreboard = ScoreboardGUI.ScoreboardGUI()
    fieldSprite = pygame.sprite.Group(field)
    friendlySprites = pygame.sprite.Group(dragon)
    scoreSprites = pygame.sprite.Group(scoreboard, growthBarOutline)

    
    if Globals.resume == False:
        Globals.score = 0
        Waves.spawnWave(Globals.currentWave)
       # SpawnSprites.spawnGrowthBarFill(Globals.meat)
        Globals.clearSprites = False
        
    
    clock = pygame.time.Clock()
    keepGoing = True
    while keepGoing:
        clock.tick(30)
        pygame.mouse.set_visible(False)
        for event in pygame.event.get():
            
            #clearing sprites without leaving the game() function
            #if Globals.clearSprites == True:
                #Globals.environment.empty()
                #Globals.powerups.empty()
                #Globals.fireballs.empty()
                #Globals.enemySprites.empty()
                #Globals.gameGUI.empty()
            
            print Globals.growthBar
            print len(Globals.growthBar)
            print Globals.growthBarFill
            
                      
            if scoreboard.lives <= -1:
                Globals.gameOver = True
                Globals.resume = False
                Globals.clearSprites = True
                Globals.mainGame = False
                keepGoing = False
            
            if event.type == pygame.QUIT:
                Globals.donePlaying = True
                keepGoing = False
                
                
            elif event.type == pygame.KEYDOWN:
                keyName = pygame.key.name(event.key)
                if event.key == pygame.K_ESCAPE:
                    Globals.donePlaying = True
                    keepGoing = False
                    
                if event.key == pygame.K_p:
                    keepGoing = False
                    Globals.pauseMenu = True
                    Globals.mainGame = False
                    Globals.resume = True
                    Globals.clearSprites = False
                         
         
         
        hitEnvironment = pygame.sprite.spritecollide(dragon, Globals.environment, False)
        for theEnvironment in hitEnvironment:
            if theEnvironment.type == Globals.environmentTree:  
                dragon.state = dragon.STANDING
                dragon.dx = 0
                dragon.dy = 0
            elif theEnvironment.type == Globals.environmentBoulder:
                dragon.dx = 0
                dragon.dy = 0
                
        hitPowerUp = pygame.sprite.spritecollide(dragon, Globals.powerups, True)
        for powerUps in hitPowerUp: 
            print powerUps.type
            if powerUps.type == Globals.powerUpSmallMeat:
                print Globals.growth
                #dragon.sndEat.play()
                Globals.score += 500
                Globals.meat += 1
                #SpawnSprites.spawnGrowthBarFill(Globals.meat)
                if Globals.meat >= 30:
                    Globals.meat = 30
                scoreboard.score = Globals.score
                        
            elif powerUps.type == Globals.powerUpLargeMeat:
                print Globals.growth
                #dragon.sndEat.play()   
                Globals.score += 1250
                Globals.meat += 2
                if Globals.meat >= 30:
                    Globals.meat = 30
                scoreboard.score = Globals.score
                    
            elif powerUps.type == Globals.powerUpExtraLife:
                #dragon.sndExtraLife.play()
                Globals.score += 75
                Globals.lives += 1
                scoreboard.lives = Globals.lives
                scoreboard.score = Globals.score
                
            elif powerUps.type == Globals.powerUpFlameCone3:
                # this will give score, destroy the sprite, and start counting
                # down the timer for the flame cone
                Globals.score += 150
                dragon.powerupactive = dragon.FLAMECONE3
                
            elif powerUps.type == Globals.powerUpFlameCone5:
                # this will give score, destroy the sprite, and start counting
                # down the timer for the flame cone
                Globals.score += 350
                dragon.powerupactive = dragon.FLAMECONE5
                
            else:
                print "got a power up type I don't understand"
                        
        
        bounceEnemies = pygame.sprite.groupcollide(Globals.environment, Globals.enemySprites, False, False)
        if bounceEnemies:
            for theEnemyBounce in bounceEnemies:
                if theEnemyBounce.type == Globals.enemySpearKnight:
                    theEnemyBounce.dx *= -1
                    theEnemyBounce.dy *= -1
                    
       
 
        hitEnemies = pygame.sprite.spritecollide(dragon, Globals.enemySprites, True)
        if hitEnemies:
            for theEnemyHit in hitEnemies:
                if theEnemyHit.type == Globals.enemySpearKnight:
                    SpawnSprites.spawnEnemy(SpearKnight.SpearKnight, 1, 2)
                #elif theEnemyHit == SpearKnightMedium:
                    #SpawnSprites.spawnEnemy(SpearKnight.SpearKnight, 1, 4, SpawnSprites)
                #elif theEnemyHit == SpearKnightFast:
                    #SpawnSprites.spawnEnemy(SpearKnight.SpearKnight, 1, 8, SpawnSprites)
                else:
                    print theEnemyHit
                    print theEnemyHit.type
                    print "enemy spawn error"
                    
                Globals.lives -= 1
                Globals.meat /= 2
                scoreboard.lives = Globals.lives
                dragon.reset()
        
        for fireball in Globals.fireballs:        
            burnEnemies = pygame.sprite.spritecollide(fireball, Globals.enemySprites, True)
            if burnEnemies:
                for enemyBurned in burnEnemies:
                    Globals.score += 3000
                    scoreboard.score = Globals.score
                    #fireball.sndKill.play()
                    fireball.kill()
                    SpawnSprites.spawnIten(SmallMeat.SmallMeat, 1, enemyBurned.x, enemyBurned.y)
                    #SpawnSprites.spawnItem(SmallMeat.SmallMeat, 1, enemyBurned.x, enemyBurned.y)
                    
        for fireball in Globals.fireballs:        
            burnEnvironment = pygame.sprite.spritecollide(fireball, Globals.environment, False)
            for theEnvironment in burnEnvironment: 
                if theEnvironment.type == Globals.environmentTree:
                    theEnvironment.kill()
                    Globals.score += 50
                    scoreboard.score = Globals.score
                    #fireball.sndKill.play()
                    fireball.kill()
                elif theEnvironment.type == Globals.environmentBoulder:
                    fireball.kill()
                
        
        if len(Globals.enemySprites) == 0:
            if Globals.currentWave > 10:
                Globals.winScreen = True
                Globals.resume = False
                Globals.clearSprites = True
                Globals.mainGame = False
                keepGoing = False
            else: 
                Globals.currentWave += 1
                dragon.reset()
                Globals.clearSprites = True
                Globals.resume = True
                Waves.spawnWave(Globals.currentWave)
            
        
        SpawnSprites.spawnGrowthBarFill(ScoreboardGUI.GrowthBarFillGUI, Globals.meat)
        fieldSprite.update()
        Globals.fireballs.update()
        Globals.environment.update()
        Globals.enemySprites.update()
        Globals.gameGUI.update()
        friendlySprites.update()
        scoreSprites.update()
        
        fieldSprite.draw(Globals.screen)
        Globals.fireballs.draw(Globals.screen)
        Globals.powerups.draw(Globals.screen)
        Globals.environment.draw(Globals.screen)
        Globals.enemySprites.draw(Globals.screen)
        friendlySprites.draw(Globals.screen)
        Globals.gameGUI.draw(Globals.screen)
        scoreSprites.draw(Globals.screen)
        Globals.powerups.update()
        
        pygame.display.flip()
        
    pygame.mouse.set_visible(True)