import pygame import gamebox width = 800 height = 600 camera = gamebox.Camera(width, height) ship = gamebox.from_image(400, 560, "http://www.cs.virginia.edu/~up3f/cs1111/images/spaceship.jpg") bullets = [ gamebox.from_color(-300, 300, 'pink', 5, 20), ] def tick(keys): ''' This is where the game goes :param keys: recognizes what the user does with :return: doesn't return anything, it is actively running ''' camera.clear("black") # make sure all bullet in a list keep moving for bullet in bullets: bullet.move_speed() if pygame.K_RIGHT in keys: ship.x += 5 if pygame.K_LEFT in keys: ship.x -= 5 if pygame.K_UP in keys: ship.y -= 5 if pygame.K_DOWN in keys: ship.y += 5 # if a spacebar is pressed, add one more bullet to the list if pygame.K_SPACE in keys: bullets.append( gamebox.from_color(-300, 300, 'pink', 5, 20), ) # set the last button to move up (negative speedy) bullets[-1].speedy = -10 # set position of the bullet bullets[-1].center = ship.center # remove the spacebar press from keys # (each spacebar press results in one shooting) keys.remove(pygame.K_SPACE) # wrap if ship.x > width: ship.x = 0 if ship.x < 0: ship.x = width if ship.y > height: ship.y = 0 if ship.y < 0: ship.y = height for bullet in bullets: camera.draw(bullet) camera.draw(ship) camera.display() # make that screen appear ticks_per_second = 60 gamebox.timer_loop(ticks_per_second, tick)