# Game Python Postgres with Sound

Have a Database Problem? Speak with an Expert for Free
Get Started >>

## Introduction

In this part, we continue building a game with Python and Postgres with Sound as part 7 of a multi-part series of lessons where the final result will be a simple 2D graphical top-down-view videogame somewhat like PacMan in that the goal is to acquire powerups while avoiding monsters. We are using Python’s “Arcade” library for its gaming-related functions and methods. We used Postgres to read and write screen and object (player, enemies, obstacles, and power-ups) data. In this lesson we will add sound to give the game more life. In future lessons in this series, we will add various graphics, a “save game” feature, multi-player, and even a screen editor/builder.

## Prerequisites

See part 1 through 6, where we learned how to draw a screen, create tables in Postgres for storing and reading screen data and screen objects as Sprites, reading keys to control player movement, added random movements to the monsters, collision detection, and a bit of intelligent player tracking to the monsters. Please study the previous parts of this lesson, starting at Build game with Python and draw a screen.

We will assume you followed the previous parts of this series, we’ll leave out creating the Postgres tables and re-doing the details of setting up a window with Arcade, except in the source code at the bottom of this part seven. So, before the final code at the bottom, we’ll briefly go over some of what we covered in previous parts of the overall lesson.

## Random Sprite movement

 1234567891011121314151617181920 random_compass = random.randint(1, 8) if random_compass == 1:     y += 2 if random_compass == 2:     x += 2     y += 2 if random_compass == 3:     x += 2 if random_compass == 4:     x += 2     y -= 2 if random_compass == 5:     y -= 2 if random_compass == 6:     y -= 2     x -= 2 if random_compass == 7:     x -= 2 if random_compass == 8:     x -= 2

## Intelligent Sprite movement

 12345678 if player_y > monster_y:     monster_y += 2 if player_x > monster_x:     monster_x += 2 if player_y < monster_y:     monster_y -= 2 if player_x < monster_x:     monster_x -= 2

The code above code compares the location cooredinates of the player with the position of a monster. If the monster is above the player, the monster’s “monster_y” value is incremented.