rendered paste body#imports libraries
import pygame, os, sys
from pygame.locals import *
#variables
a = 0
background = os.path.join(os.path.dirname(__file__), 'starfield1.bmp')
#player ship graphic
ship = os.path.join(os.path.dirname(__file__), 'pship.bmp')
#enemy ship graphic
eship = os.path.join(os.path.dirname(__file__), 'eship.bmp')
lives = 3
live3 = os.path.join(os.path.dirname(__file__), 'live3.bmp')
live2 = os.path.join(os.path.dirname(__file__), 'live2.bmp')
live1 = os.path.join(os.path.dirname(__file__), 'live1.bmp')
pygame.init()
#the window
window = pygame.display.set_mode ((800, 600))
pygame.display.set_caption('Galaga!')
surface = pygame.display.get_surface()
#the lives gui
lives3 = pygame.image.load(live3).convert()
lives2 = pygame.image.load(live2).convert()
lives1 = pygame.image.load(live1).convert()
#creating the surface
screen = pygame.image.load (background).convert()
/
#create player ship
playership = pygame.image.load (ship).convert()
#create enemy ship
enemyship = pygame.image.load (eship).convert()
#to print "lives:" in botom left hand corner and update the number of lives the player has
def lives(lives):
lives = 3
if lives == 3:
surface.blit (lives3, (50,550))
if lives == 2:
surface.blit (lives2, (50,550))
if lives == 1:
surface.blit (lives1, (50,550))
#play position variables
sposx = 374
sposy = 512
#enemy position variable
eposx = 760
eposy = 55
xmax = 750
xmin = 25
#initializes the clock
clock = pygame.time.Clock()
#Draws the players ship on the surface and controls movement of the ship and fireing
def pship(sposx, sposy):
surface.blit (playership, (sposx, sposy))
return sposx, sposy
#draws the enemy ship on the surface and controls movement
def eship(eposx, eposy):
surface.blit (enemyship, (eposx, eposy))
vel = 1
dir = 0
def move():
global eposx
global vel
global dir
if eposx >= xmin:
dir = 1
else:
dir = 0
if dir == 1:
eposx = eposx - vel
elif dir == 0:
vel = -1
if eposx <= xmax:
eposx = eposx - vel
def emove():
global xmax
global xmin
clock.tick(70)
move()
def input(events):
global sposx
for event in events:
if event.type == QUIT:
sys.exit(0)
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
sposx = sposx - 10
if event.key == pygame.K_RIGHT:
sposx = sposx + 10
else:
print event
while True:
surface.blit (screen, (10,0))
lives(lives)
pship(sposx, sposy)
eship(eposx, eposy)
emove()
input (pygame.event.get())
pygame.display.flip()