If event.key = pygame.K_LEFT or event.key = pygame.K_RIGHT: Thing_startx = random.randrange(0, display_width) TextSurf, TextRect = text_objects("A bit Racey", largeText)īutton("GO!",150,450,100,50,green,bright_green,game_loop) TextSurf, TextRect = text_objects("Paused", largeText)īutton("Continue",150,450,100,50,green,bright_green,unpause) TextSurf, textRect = text_objects(msg, smallText) Return textSurface, textSurface.get_rect() TextSurface = font.render(text, True, black) Text = font.render("Dodged: "+str(count), True, black)ĭef things(thingx, thingy, thingw, thingh, color): GameIcon = ('carIcon.png')įont = ("comicsansms", 25) _caption('A bit Racey')ĬarImg = ('racecar.png') GameDisplay = _mode((display_width,display_height)) Now, the only other thing we may want to do is learn how to pause/unpause music when the player pauses the game. This means the music will start over again if the game is re-played. TextSurf, TextRect = text_objects("You Crashed", largeText)Ībove, we're calling PyGame to play the crash_sound, as well as to stop the music. Also, we'd like to stop the music if this is the case. Now, we want the music to play, and it is, then we need the crash sound to play when crashed. The -1 signals PyGame to just play forever, but, if you put, say, a 5 in there, then the music would play once and 5 more times. The above code will play the music file indefinitely (though you can call it to stop). Now that we know how to call sounds, how can we do music? mp3 as well, but it is somewhat glitchy, and will work sometimes and other times it wont. The above will assign the crash.wav sound file to play when we call crash_sound within PyGame's sound playing functionality. First, we will use a simple tune from YouTube as our game's music and then we'll add a "crash" sound that we will play if we hit any of the blocks.Ĭrash_sound = ("crash.wav") We're going to cover both here by adding them both to our current game. Music will just play in the background when you call it to, and sounds will play at any time you call them to play. With PyGame, you get two choices: Music or Sounds. Sounds generally come in two major forms: Either "ambient" noise or as results of player actions. We do this mainly visually, but it can make a massive difference and be a massive improvement to your game if you add sounds as well. Video games are meant to immerse the player into a sort of virtual reality.
0 Comments
Leave a Reply. |