Exemple #1
0
class Pytar:
    
    def __init__(self, fretcount):
        '''Class constructor'''
        Screen.clear() # Clear the screen
        self.screen = Screen()
        self.fretcount = fretcount
        
    def run(self):
        '''Run the application'''
        self.screen.draw(self.fretcount)
Exemple #2
0
           linkLength4, linkLength5, linkLengthhip)

csvWriter = CsvWriter(screen, fileWriteName, leg1)
csvReader = CsvReader(screen, fileReadName)

mouse = Mouse(screen, 0, 0)

Point(screen, screen.inches_to_pixels(screen.origin_x), screen.inches_to_pixels(screen.origin_y + 3), 0, screen.points)

run = True
test = False
while run:
    screen.initialize()

    # Mouse Position
    keys = py.key.get_pressed()
    mouse_press = py.mouse.get_pressed()
    mouse_pos = py.mouse.get_pos()
    mouse.function(mouse_pos, mouse_press, leg1.lhipz)

    screen.check_key_commands(keys)

    # Calculate all position and force variables based on current point
    leg1.create()

    screen.draw([[leg1]])

py.quit()


def main():
    #initialize all imported pygame modules
    pygame.init()
    #create the main screen
    screen = Screen('Break it!', 'img/star.png', 'img/outerspace.png', 600,
                    600, Colors.WHITE)
    score = Score(450, 25, Colors.FIREBRICK, 1, "sounds/BonusChime.ogg",
                  screen.Surface)
    #create a lives object'
    lives = Lives(50, 25, 3, "img/heart3.png", screen.Surface)
    level = Level(230, 25, Colors.AQUAMARINE, 40, screen.Surface)
    #create a ball object
    paddle = Paddle(160, 30, Colors.DEEPSKYBLUE, "sounds/beep4.ogg",
                    screen.Surface)
    ball = Ball(40, 0, 0, 600, 600, "img/earth-icon.png",
                "sounds/BonusSymbol.ogg", screen.Surface)
    #list of colors for brick
    colors = [Colors.RED, Colors.BLUE, Colors.GREEN, Colors.YELLOW]
    values = [100, 75, 50, 25]
    #create bricks
    bricks = Brick.createBricks(17, 100, 4, 10, 2, colors, values, 55, 20,
                                screen.Surface)

    #rate to increase speed
    speedLevel = 15
    #initialize clock
    clock = pygame.time.Clock()

    #indicates if the game is paused
    paused = False
    #set the variable that controls the main game loop
    playing = True
    while playing:
        #maintain a frame rate of 100 fps
        clock.tick(100)
        #the events since last time
        for event in pygame.event.get():
            #if the user clicks exit stop playing
            if event.type == QUIT:
                playing = False
            if event.type == KEYDOWN:
                if event.key == K_q:
                    playing = False
                if event.key == K_p:
                    paused = not paused
                if event.key == K_LEFT:
                    #move left
                    paddle.setMoveLeft()
                    #move right
                if event.key == K_RIGHT:
                    paddle.setMoveRight()

            if event.type == KEYUP:
                if event.key == K_LEFT or event.key == K_RIGHT:
                    paddle.stop()

        #move and draw only if the pause feature is off
        if not paused:
            #update and move things
            ball.move()
            paddle.move()

            #check for paddle hit
            if ball.checkCollision(paddle.rect):
                paddle.playSound()
                score.addScore(100)

            #if ball leaves screen
            if ball.lost():
                ball.reset()
                lives.subtractLives(1)
                if lives.getLives() == 0:
                    if screen.restartPrompt("img/GameOver4.png"):
                        lives.reset()
                        score.resetScore()

            #loop through all the bricks
            for brick in bricks:
                #is there a collision?
                if (brick.checkBallCollision(ball)):
                    if score.addScore(brick.value):
                        lives.addLives(0)
                if brick.gone:
                    bricks.remove(brick)
                    if level.addPartialLevel(1):
                        bricks = Brick.createBricks(17, 100, 4, 10, 2, colors,
                                                    values, 55, 20,
                                                    screen.Surface)
                        ball.reset()

            #draw things
            #draw screen first so it does nor overwrite other objects
            #screen.draw

            screen.draw()
            score.draw()
            lives.draw()
            level.draw()
            paddle.draw()
            ball.draw()
            #loops through all the bricks
            for brick in bricks:
                brick.draw()

            #update the changes to show on the main screen
            pygame.display.update()

    #Uninialize all pygame modules that have previously beeen inialized
    pygame.quit()
Exemple #4
0
# Handling time
clock = pygame.time.Clock()

# Set up the screen
BLOCKSCALEFACTOR = 2
HORIZTILES = 25
VERTTILES = 15
BLOCKRESO = 16
screenWidth = HORIZTILES * BLOCKRESO * BLOCKSCALEFACTOR
screenHeight = VERTTILES * BLOCKRESO * BLOCKSCALEFACTOR
myScreen = Screen(screenWidth, screenHeight)
# Also set up out default background for the game
myBackground = pygame.Surface((screenWidth, screenHeight))
myBackground.fill((99, 155, 255))
myBackground = myBackground.convert()
myScreen.set_background(myBackground)

running = True
while running:
    # Capping the game at 30 FPS
    timeDelta = clock.tick(30)

    # Look at the queue for the exit event
    for event in pygame.event.get():
        if event.type == QUIT:
            running = False

    myScreen.draw()

pygame.quit()
Exemple #5
0
def main():
    #initialize all imported pygame modules
    pygame.init()    
    #create the main screen
    screen = Screen('Break IT', 'img/star.png', 
                    'img/outerspace.png',600, 600,Colors.WHITE)

    #Create a score object
    score = Score(450, 25,Colors.GOLD , 2500, 
                  "sounds/BonusChime.ogg", screen.surface)	

    #Create a lives object
    lives = Lives(50, 25, 3,"img/heart3.png", screen.surface)	

    #Create a level object
    level = Level(230, 25,Colors.GOLD, 40, screen.surface)

    #Create a paddle object
    paddle = Paddle(80, 20, Colors.AQUAMARINE,
                    "sounds/beep1.ogg", screen.surface)	
    #Create Ball here
    ball = Ball(40, 0, 0, 600, 600,"img/star.png",
                "sounds/beep4.ogg", screen.surface)	



    #Initialize clock
    clock = pygame.time.Clock() 	
    #indicates if the game is paused
    paused = False	
    #set the variable that controls the main game loop
    playing = True
    #start the game loop
    while playing:    
        #maintain a frame rate of 100 fps
        clock.tick(100)	
        #get all the events since last time 
        #the events were checked
        for event in pygame.event.get():
            #if the user click exit stop playing	    
            if event.type == QUIT:
                playing = False			
            #if this is a keydown (pressing down of a key) 
            if event.type == KEYDOWN:
                if event.key == K_q:
                    playing = False	
                #switch the pause feature on or off	
                if event.key == K_ESCAPE:
                    paused = not paused	
                #set the paddle to move to the left	
                if event.key == K_LEFT:
                    paddle.setMoveLeft()					
                #set the paddle to move to the right		
                if event.key == K_RIGHT:
                    paddle.setMoveRight()
            #if this is a keyup (the player release 
            #the key so it is no longer down) 
            if event.type == KEYUP:
                #since the player released the key 
                #the paddle should be stationary
                if event.key == K_LEFT or event.key == K_RIGHT:
                    paddle.stop()  
        #move and draw only
        #if pause feature off	
        if not paused:

            #update and move things
            ball.move()
            paddle.move()   
            #Check for paddle hit
            if ball.checkCollision(paddle.rect):
                paddle.playSound()
                score.addScore(10)
            #if the ball leaves the screen
            if ball.lost():
                ball.reset()			
                lives.subtractLives(1)	
                if lives.getLives() == 0:				
                    #we are out of lives check for restart
                    if screen.restartPrompt("img/GameOver4.png"):
                        lives.reset()
                        score.reset()
                    else:
                        playing = False	
               


            #draw things
            #draw screen first so it does not
            #overwrite other objects
            screen.draw()
            score.draw()
            lives.draw()
            level.draw()
            ball.draw()
            paddle.draw()


            #update the changes to 
            #show on the main screen
            pygame.display.update()



    #Uninitialized all pygame modules that
    #have previously been initialized
    pygame.quit()	    
Exemple #6
0
class Game:

    gamepad = None
    player = None
    screen = None
    entityManager = None
    world = None

    FRAMES_PER_SECOND = 25

    game_is_running = False

    def __init__(self):
        print("Press Ctrl-C to quit")

        self.gamepad = GamePad()
        self.screen = Screen()
        self.entityManager = EntityManager()
        self.player = Player(self)
        self.world = World(self)
        self.entityManager.add(self.player)

    def update(self, dt):

        self.gamepad.update()

        if (self.gamepad.pressed[GAMEPAD_BUTTON.START]):
            self.game_is_running = False
            return

        self.world.update()
        self.entityManager.update(dt)

    def draw(self):
        self.screen.clear()
        self.world.draw()
        self.entityManager.draw()
        self.screen.draw()

    def start(self):
        print("GO!")
        self.loop()

    def loop(self):

        self.game_is_running = True

        lastFrameTime = time.time()

        try:
            while self.game_is_running:
                currentTime = time.time()
                dt = currentTime - lastFrameTime

                sleepTime = 1. / self.FRAMES_PER_SECOND - (currentTime -
                                                           lastFrameTime)

                if sleepTime > 0:
                    time.sleep(sleepTime)

                self.update(dt)
                self.draw()

                lastFrameTime = currentTime
            self.screen.off()
        except KeyboardInterrupt:
            self.screen.off()
            sys.exit()
def main():
    pygame.init()
    #create screen
    screen = Screen('Space Invaders!', 'img/lightning.png',
                    'img/outerspace.png', 700, 700, Colors.WHITE)
    score = Score(450, 25, Colors.BLUE, 2500, "sounds/BonusChime.ogg",
                  screen.Surface)
    #create lives
    lives = Lives(50, 25, 3, "img/shield.png", screen.Surface)
    #level
    level = Level(230, 25, Colors.YELLOW, 70, screen.Surface)
    #gun
    gun = BattleGun(80, 20, Colors.AQUAMARINE, 50, "sounds/Laser_Shoot.ogg",
                    screen.Surface)
    #list of bullets
    bullets = list()
    #the explosion colors =
    colors = [Colors.YELLOW, Colors.RED, Colors.GREEN, Colors.BLUE]
    #the In leg images
    imageIns = [
        "img/CyanIn.png", "img/PurpleIn.png", "img/RedIn.png",
        "img/smallInLeg1.png"
    ]
    #the out images
    imageOuts = [
        "img/CyanOut.png", "img/PurpleOut.png", "img/RedOut.png",
        "img/smallOutLeg1.png"
    ]
    #the score values
    values = [200, 150, 100, 50]
    #create list of attacking invaders
    invaders = Invader.createInvaders(17, 100, 4, 15, 5, 20, 20,
                                      "img//lightning.png",
                                      "sounds//shortbreak.ogg", colors,
                                      imageIns, imageOuts, values,
                                      screen.Surface)
    alienBullets = list()
    clock = pygame.time.Clock()
    #indicates if the game is paused
    paused = False
    #set var to control game loop
    playing = True
    #start game
    while playing:
        #maintain 100 fps
        clock.tick(100)
        for event in pygame.event.get():
            #if user click exit
            if event.type == QUIT:
                playing = False
            if event.type == KEYDOWN:
                if event.key == K_q:
                    playing = False
                if event.key == K_p:
                    paused = not paused
                #set gun to move left
                if event.key == K_LEFT:
                    gun.setMoveLeft()
                #move right
                if event.key == K_RIGHT:
                    gun.setMoveRight()
                if event.key == K_SPACE:
                    #if gun can fire
                    if gun.reloadCount == 0:
                        #add new bullet
                        bullets.append(gun.fire())
                if event.key == K_n:
                    event.type == QUIT
            if event.type == KEYUP:
                if event.key == K_LEFT or event.key == K_RIGHT:
                    gun.stop()

        #move and draw if not paused
        if not paused:

            #update + move things
            gun.move()
            for bullet in bullets:
                bullet.move()
                if bullet.shotMissed():
                    bullets.remove(bullet)
            for bullet in alienBullets:
                bullet.move()
                if bullet.shotMissed():
                    alienBullets.remove(bullet)
                if bullet.checkCollision(gun.rect):
                    alienBullets.remove(bullet)
                    lives.subtractLives(1)
            Invader.moveGroup(invaders)
            for invader in invaders:
                if random.randrange(5000) < 2:
                    alienBullets.append(invader.fire())
                for bullet in bullets:
                    if bullet.checkCollision(invader.rect):
                        bullets.remove(bullet)
                        if score.addScore(invader.value):
                            lives.addLives(1)
                        invader.hit()
            if len(invaders) == 0:
                level.increaseLevel()
                invaders = Invader.createInvaders(17, 100, 4, 15, 5, 20, 20,
                                                  "img//lightning.png",
                                                  "sounds//shortbreak.ogg",
                                                  colors, imageIns, imageOuts,
                                                  values, screen.Surface)
                Invader.speed = level.getLevel() * 2
                Invader.numberDestroyed = 0

            if Invader.landed or lives.lives == 0:
                if screen.restartPrompt("img//GameOver4.png"):
                    lives.reset()
                    invaders = Invader.createInvaders(
                        17, 100, 4, 15, 5, 20, 20, "img//lightning.png",
                        "sounds//shortbreak.ogg", colors, imageIns, imageOuts,
                        values, screen.Surface)

            #draw things screen first so not overide other objects
            screen.draw()
            score.draw()
            lives.draw()
            level.draw()
            gun.draw()
            for bullet in bullets:
                bullet.draw()
            for bullet in alienBullets:
                bullet.draw()

            Invader.moveGroup(invaders)

            for invader in invaders:
                if invader.gone:
                    invaders.remove(invader)
                else:
                    invader.draw()
            #update changes on screen
            pygame.display.update()
    #uninitialize pygame mods have have benn inited
    pygame.quit()
    screen.initialize()

    # Mouse Position
    keys = py.key.get_pressed()
    mouse_press = py.mouse.get_pressed()
    mouse_pos = py.mouse.get_pos()
    mouse.function(mouse_pos, mouse_press, 0)

    screen.check_key_commands(keys)

    if iterate:
        iterator.iterate_ground_positions()

        sd.work_space_origin = [26, -18]
        sd.ground_positions_origin = [-28, sd.work_space_origin[1] - sd.work_space[1]]
        iterator.iterate_ground_positions()

        sd.work_space_origin = [24, -18]
        sd.ground_positions_origin = [-30, sd.work_space_origin[1] - sd.work_space[1]]
        iterator.iterate_ground_positions()
        break

    # Calculate all position and force variables based on current point
    arm1.create()
    arm1.kinetics(sd.patient_weight, sd.patient_angle)
    screen.draw([[arm1]])

py.quit()


Exemple #9
0
class Interpreter(object):

    digits = {
        0x0: [0xf0, 0x90, 0x90, 0x90, 0xf0],
        0x1: [0x20, 0x60, 0x20, 0x20, 0x70],
        0x2: [0xf0, 0x10, 0xf0, 0x80, 0xf0],
        0x3: [0xf0, 0x10, 0xf0, 0x10, 0xf0],
        0x4: [0x90, 0x90, 0xf0, 0x10, 0x10],
        0x5: [0xf0, 0x80, 0xf0, 0x10, 0xf0],
        0x6: [0xf0, 0x80, 0xf0, 0x90, 0xf0],
        0x7: [0xf0, 0x10, 0x20, 0x40, 0x40],
        0x8: [0xf0, 0x90, 0xf0, 0x90, 0xf0],
        0x9: [0xf0, 0x90, 0xf0, 0x10, 0xf0],
        0xa: [0xf0, 0x90, 0xf0, 0x90, 0x90],
        0xb: [0xe0, 0x90, 0xf0, 0x10, 0xf0],
        0xc: [0xf0, 0x80, 0x80, 0x80, 0xf0],
        0xd: [0xe0, 0x90, 0x90, 0x90, 0xe0],
        0xe: [0xf0, 0x80, 0xf0, 0x80, 0xf0],
        0xf: [0xf0, 0x80, 0xf0, 0x80, 0x80]
    }

    def __init__(self, rom_name, scale=5):
        self.screen = Screen(scale=scale)

        self.rom_name = None
        self.registers = np.zeros(16, dtype=np.uint8)
        self.I = np.zeros(1, dtype=np.uint16)
        self.mem = np.zeros(4096, dtype=np.uint8)
        self.digit_locs = {d: 5 * d for d in range(16)}

        self.keyboard = np.zeros(16, dtype=np.uint8)

        self.stack = []

        self.dt = np.zeros(1, dtype=np.uint8)
        self.st = np.zeros(1, dtype=np.uint8)

        self.pc = 0x200

        self.clock = pygame.time.Clock()
        self.clock_speed = 600  # Hz
        self.cycle = 0

        self.open(rom_name)

    def reset_mem(self):
        self.pc = 0x200

        self.mem[:] = 0

        for d in range(16):
            self.mem[5 * d:5 * d + 5] = self.digits[d]

    def open(self, rom_name):
        self.rom_name = rom_name
        self.screen.set_caption(rom_name)

        self.reset_mem()

        with open(f".//rom//{rom_name}.ch8", "rb") as f:
            i = 0x200
            byte = f.read(1)
            while byte:
                self.mem[i] = int.from_bytes(byte, byteorder="big")
                byte = f.read(1)

                i += 1

    def handle_events(self):

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

            if event.type == pygame.KEYDOWN:

                for i in range(16):
                    if event.key == getattr(pygame,
                                            "K_" + "x123qweasdzc4rfv"[i]):
                        self.keyboard[i] = 1
                        break

            elif event.type == pygame.KEYUP:
                for i in range(16):
                    if event.key == getattr(pygame,
                                            "K_" + "x123qweasdzc4rfv"[i]):
                        self.keyboard[i] = 0
                        break

    def get_key(self):
        print("GET KEY")
        while True:
            self.handle_events()

            for i in range(16):
                if self.keyboard[i]:
                    return i

            self.clock.tick(self.clock_speed)

    def run(self):

        while True:

            self.execute()
            self.cycle = (self.cycle + 1) % self.clock_speed

            if self.cycle % 60 == 0:
                self.handle_events()

                if np.any(self.dt):
                    self.dt -= 1

                if np.any(self.st):
                    self.st -= 1
                    winsound.Beep(2500, 100)

            self.clock.tick(self.clock_speed)

    def execute(self):
        instruction = int(0x100 * self.mem[self.pc] + self.mem[self.pc + 1])
        self.pc += 2

        x = (instruction & 0x0f00) // 0x0100
        y = (instruction & 0x00f0) // 0x0010

        # CLS
        if instruction == 0x00e0:
            self.screen.clear()

        # RET
        elif instruction == 0x00ee:
            self.pc = self.stack.pop(-1)

        # JP
        elif instruction & 0xf000 == 0x1000:
            self.pc = instruction & 0x0fff

        # CALL
        elif instruction & 0xf000 == 0x2000:
            self.stack.append(self.pc)  # todo: +2 or no?
            assert len(self.stack) <= 16
            self.pc = instruction & 0x0fff

        # SE
        elif instruction & 0xf000 == 0x3000:
            if self.registers[x] == (instruction & 0x00ff):
                self.pc += 2

        # SNE
        elif instruction & 0xf000 == 0x4000:
            if self.registers[x] != (instruction & 0x00ff):
                self.pc += 2

        # SE
        elif instruction & 0xf000 == 0x5000:
            if self.registers[x] == self.registers[y]:
                self.pc += 2

        # LD
        elif instruction & 0xf000 == 0x6000:
            self.registers[x] = instruction & 0x00ff

        # ADD
        elif instruction & 0xf000 == 0x7000:
            self.registers[x] += instruction & 0x00ff

        elif instruction & 0xf000 == 0x8000:

            # LD
            if instruction & 0x000f == 0x0000:
                self.registers[x] = self.registers[y]

            # OR
            elif instruction & 0x000f == 0x0001:
                self.registers[x] |= self.registers[y]

            # AND
            elif instruction & 0x000f == 0x0002:
                self.registers[x] &= self.registers[y]

            # XOR
            elif instruction & 0x000f == 0x0003:
                self.registers[x] ^= self.registers[y]

            # ADD
            elif instruction & 0x000f == 0x0004:
                self.registers[0xf] = int(self.registers[x]) + int(
                    self.registers[y]) > 255
                self.registers[x] += self.registers[y]

            # SUB
            elif instruction & 0x000f == 0x0005:
                self.registers[0xf] = self.registers[x] > self.registers[y]
                self.registers[x] -= self.registers[y]

            # SHR
            elif instruction & 0x000f == 0x0006:
                self.registers[0xf] = self.registers[x] & 0b00000001
                self.registers[x] //= 2

            # SUBN
            elif instruction & 0x000f == 0x0007:
                self.registers[0xf] = self.registers[x] < self.registers[y]
                self.registers[x] = self.registers[y] - self.registers[x]

            # SHL
            elif instruction & 0x000f == 0x000e:
                self.registers[0xf] = self.registers[x] & 0b10000000
                self.registers[x] *= 2

            else:
                raise Exception(f"Unknown instruction: {hex(instruction)}")

        # SNE
        elif instruction & 0xf000 == 0x9000:
            if self.registers[x] != self.registers[y]:
                self.pc += 2

        # LD I
        elif instruction & 0xf000 == 0xa000:
            self.I[0] = instruction & 0x0fff

        # JP V0
        elif instruction & 0xf000 == 0xb000:
            self.pc = (instruction & 0x0fff) + self.registers[0x0]

        # RND
        elif instruction & 0xf000 == 0xc000:
            self.registers[x] = random.randint(0, 255) & (instruction & 0x00ff)

        # DRW
        elif instruction & 0xf000 == 0xd000:
            self.registers[0xf] = self.screen.draw(
                self.mem[int(self.I[0]):int(self.I[0]) +
                         (instruction & 0x000f)],
                (self.registers[x], self.registers[y]))

        elif instruction & 0xf000 == 0xe000:

            # SKP
            if instruction & 0x00ff == 0x009e:
                if self.keyboard[self.registers[x]]:
                    self.pc += 2

            # SKNP
            elif instruction & 0x00ff == 0x00a1:
                if not self.keyboard[self.registers[x]]:
                    self.pc += 2

            else:
                raise Exception(f"Unknown instruction: {hex(instruction)}")

        elif instruction & 0xf000 == 0xf000:

            # LD
            if instruction & 0x00ff == 0x0007:
                self.registers[x] = self.dt[0]

            # LD
            elif instruction & 0x00ff == 0x000a:
                self.registers[x] = self.get_key()

            # LD DT
            elif instruction & 0x00ff == 0x0015:
                self.dt[0] = self.registers[x]

            # LD ST
            elif instruction & 0x00ff == 0x0018:
                self.st[0] = self.registers[x]

            # ADD I
            elif instruction & 0x00ff == 0x001e:
                self.I[0] += self.registers[x]

            # LD F
            elif instruction & 0x00ff == 0x0029:
                self.I[0] = self.digit_locs[int(self.registers[x])]

            # LD B
            elif instruction & 0x00ff == 0x0033:
                decimal = str(int(self.registers[x])).zfill(3)
                for i in range(3):
                    self.mem[int(self.I[0]) + i] = int(decimal[i])

            # LD [I]
            elif instruction & 0x00ff == 0x0055:
                for i in range((instruction & 0x0f00) // 0x0100 + 1):
                    self.mem[int(self.I[0]) + i] = self.registers[i]

            # LD
            elif instruction & 0x00ff == 0x0065:
                for i in range((instruction & 0x0f00) // 0x0100 + 1):
                    self.registers[i] = self.mem[int(self.I[0]) + i]

            else:
                raise Exception(f"Unknown instruction: {hex(instruction)}")

        else:
            raise Exception(f"Unknown instruction: {hex(instruction)}")
def main():

    #initialize all imported pygame modules
    pygame.init()
    #create the main screen
    screen = Screen('Invaders of an Alien Nature', 'img/Icon.png',
                    'img/outerspace.png', 600, 600, Colors.WHITE)
    #Create a score object
    score = Score(450, 25, Colors.WHITE, 2500, "sounds/BonusChime.ogg",
                  screen.surface)
    #Create a lives object
    lives = Lives(50, 25, 5, "img/shield.png", screen.surface)

    #Create a level object
    level = Level(230, 25, Colors.WHITE, 40, screen.surface)

    #Create a BattleGun object
    gun = BattleGun(80, 20, Colors.AQUAMARINE, 50, "sounds/Laser_Shoot.ogg",
                    screen.surface)
    bullets = list()

    #Initialize clock
    clock = pygame.time.Clock()
    #indicates if the game is paused
    paused = False
    #set the variable that controls the main game loop
    playing = True
    #start the game loop
    while playing:
        #maintain a frame rate of 100 fps
        clock.tick(100)
        #get all the events since last time
        #the events were checked
        for event in pygame.event.get():
            #if the user click exit stop playing
            if event.type == QUIT:
                playing = False
            #if this is a keydown (pressing down of a key)
            if event.type == KEYDOWN:
                if event.key == K_q:
                    playing = False
                #switch the pause feature on or off
                if event.key == K_ESCAPE:
                    paused = not paused
                #set the gun to move to the left
                if event.key == K_LEFT:
                    gun.setMoveLeft()
                #set the gun to move to the right
                if event.key == K_RIGHT:
                    gun.setMoveRight()
                if event.key == K_SPACE:
                    #if the gun is able to fire
                    if gun.reloadCount == 0:
                        #add new bullet to our list
                        bullets.append(gun.fire())

            #if this is a keyup (the player release
            #the key so it is no longer down)
            if event.type == KEYUP:
                #since the player released the key
                #the paddle should be stationary
                if event.key == K_LEFT or event.key == K_RIGHT:
                    gun.stop()

        #move and draw only
        #if pause feature off
        if not paused:

            #update and move things
            gun.move()
            for bullet in bullets:
                bullet.move()
                if bullet.shotMissed():
                    bullets.remove(bullet)

            #draw things
            #draw screen first so it does not
            #overwrite other objects
            screen.draw()
            score.draw()
            lives.draw()
            level.draw()
            gun.draw()
            for bullet in bullets:
                bullet.draw()

            #update the changes to
            #show on the main screen
            pygame.display.update()

    #Uninitialized all pygame modules that
    #have previously been initialized
    pygame.quit()