Advertisement
diliupg

Space Gladiator II the Spiritual Warrior

Aug 25th, 2014
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 108.73 KB | None | 0 0
  1.                 #-------------- Space Gladiator ----------------#
  2.                 # Concept & Design      : Diliup Gabadamudalige #
  3.                 # Coding Commenced      : 2013-08-03            #
  4.                 # Coding Completed      : 2013-11-08            #
  5.                 #-----------------------------------------------#
  6.  
  7. import pygame
  8. import pygame._view
  9. from pygame.locals import *
  10. import sys
  11. import os
  12. import math
  13. import time
  14. import random
  15. import copy
  16. import cPickle
  17.  
  18. wincon=pygame.image.load("resources\grfx\dg.bmp")
  19. pygame.display.set_icon(wincon)
  20. pygame.display.set_caption('SPACE GLADIATOR-EMorphus Productions 2013')
  21. #initialize pygame, load the 1st. music track and start playing while the game\
  22. # loads in the background
  23. clock = pygame.time.Clock()
  24. pygame.mixer.pre_init(44100, 16, 2, 4096) # setup mixer to avoid sound lag
  25. pygame.init()
  26. if sys.platform == 'win32' or sys.platform == 'win64':
  27.     os.environ['SDL_VIDEO_CENTERED'] = '2'# center of screen
  28. Dlist=pygame.display.list_modes(0,FULLSCREEN)
  29. Swidth=Dlist[0][0]-24
  30. Sheight=Dlist[0][1]-50
  31. screenmode=0
  32. screen = pygame.display.set_mode((Swidth, Sheight),screenmode,0)
  33. pygame.mouse.set_visible(False)
  34. startmusic="resources\snd\SGOpeningtheme.ogg"
  35. pygame.mixer.set_num_channels(64)
  36. pygame.mixer.music.load(startmusic)
  37. pygame.mixer.music.set_volume(0.3)
  38. pygame.mixer.music.play(-1)
  39. font = pygame.font.Font("resources\data\prometheanb.ttf", 22)
  40. text = font.render("Game Loading. Please wait....", 2, (150,150,250))
  41. screen.blit(text,[Swidth/2-text.get_width()/2,Sheight/2-text.get_height()])
  42. pygame.display.update()
  43.  
  44. #------------------------------------------------------------------------------#
  45. #                        A L L  T H E  F U N C T I O N S                       #
  46. #------------------------------------------------------------------------------#
  47. def update_all(text1,text2,text3):
  48.     global life
  49.     for i in xrange (Hero.lives):
  50.         screen.blit(life,(controls.Swidth-(25*(i+1)),2))
  51.     if Hero.life>0 and Hero.lives>0 and Hero.status=="N":
  52.         Hero.update()
  53.  
  54.     for g in controls.globelist:
  55.         g.update()
  56.  
  57.     for e in controls.Alien1: # 1st WAVE of ALIENS
  58.         if e.status=="M":
  59.             e.follow(Hero,7)
  60.             e.update()
  61.  
  62.     if controls.enemystate=='boss on' and boss1.status<>"E":
  63.         boss1.follow(Hero,8)
  64.         boss1.update()
  65.  
  66.     if controls.enemystate=='MLA2' and Mothership1.status=="M":
  67.         Mothership1.mship_update(Mothership1.heading)
  68.  
  69.     for e in controls.Alien2: # 1st WAVE of ALIENS
  70.         if e.status=="M":
  71.             e.follow(Hero,8)
  72.             e.update()
  73.  
  74.     for e in controls.FinalAliens: # 1st WAVE of ALIENS
  75.         if e.status=="M":
  76.             e.follow(Hero,9)
  77.             e.update()
  78.  
  79.     for a in asteroids:
  80.         a.update()
  81.  
  82.  
  83.     update_score(score,scorestr,realscore)
  84.     update_game_text(text1,text2,text3)
  85.     update_screen()
  86.     star_field()
  87. def update_screen():
  88.     pygame.display.update()
  89.     screen.fill((0,0,0))
  90.  
  91. def update_score(score,scorestr,realscore):
  92.     if score[6]>=10: score[6]=0; score[5]+=1
  93.     if score[5]>=10: score[5]=0; score[4]+=1
  94.     if score[4]>=10: score[4]=0; score[3]+=1
  95.     if score[3]>=10: score[3]=0; score[2]+=1
  96.     if score[2]>=10: score[2]=0; score[1]+=1
  97.     if score[1]>=10: score[1]=0; score[0]+=1
  98.     for w in score: scorestr+=str(w)
  99.     realscore=int(scorestr)
  100.  
  101. def update_game_text(text1,text2,text3):
  102.     pygame.draw.rect(screen, (128,128,128), [2, controls.Sheight-(152)\
  103.                                          , 14,152],3)# SHIELD meter border
  104.     pygame.draw.rect(screen, (128,128,128), [18, controls.Sheight-(152)\
  105.                                          , 14,152],3)#GUN TEMP meter border
  106.     if colourvals[0]<0: colourvals[0]=1
  107.     pygame.draw.rect(screen, (255,colourvals[0],0),\
  108.                      [controls.Swidth-controls.Swidth+4,\
  109.                       controls.Sheight-Hero.life/3, 10,295],0)# SHIELD amount
  110.     pygame.draw.rect(screen, (255,colourvals[1],0),\
  111.                      [controls.Swidth-controls.Swidth+20,\
  112.                       controls.Sheight-Hero.guntemp*2+4, 10,295],0)# GUN TEMPERATURE
  113.     font = pygame.font.Font("resources\data\prometheanb.ttf", 22)
  114.     screen.blit(text1, [2,0])# print text->score, colourvals[1]
  115.     text = font.render(scorestr, 2, (150,150,250))
  116.     screen.blit(text, [84,1])# print score
  117.     screen.blit(text2, [1,controls.Sheight-108])# SHIELD
  118.     screen.blit(text3, [18,controls.Sheight-100])# GUN TEMP
  119.  
  120.     if Hero.bonus[2]=="M":
  121.         screen.blit(text4,(controls.Swidth/2-text4.get_width()/2,5))
  122.         Hero.bonus[3]+=1
  123.         if Hero.bonus[3]>=100:
  124.             Hero.bonus[3]=0
  125.             Hero.bonus[2]="S"
  126.             shipbonus.play()
  127.     if Hero.bombs[0]>0 and controls.CBomb==False:
  128.         font = pygame.font.Font("resources\data\prometheanb.ttf", 22)
  129.         bombamount=font.render('BOMBS '+str(Hero.bombs[0])+\
  130.                                ' : '+'READY TO FIRE! (B)', 2,[200,0,200])
  131.         screen.blit(bombamount,((controls.Swidth-bombamount.get_width())/2,\
  132.                            controls.Sheight-25))
  133.     if Hero.bombs[1]=="R" and controls.CBomb==False:
  134.         R=random.randrange(100,250,25)
  135.     if controls.CBomb=="C":
  136.         R=random.randrange(100,250,25)
  137.         font = pygame.font.Font("resources\data\prometheanb.ttf", 20)
  138.         text7=font.render("CLUSTER BOMB READY! 'C' TO LAUNCH",\
  139.                           2,[R,R,R])
  140.         screen.blit(text7,(controls.Swidth/2-text7.get_width()/2,\
  141.                            controls.Sheight-25))
  142.  
  143. def initialize_stars():
  144.     global stars
  145.     controls.stars=[]
  146.     for x in xrange (500):
  147.         controls.stars.append([(int(controls.Swidth*random.random())),\
  148.                       (int(controls.Sheight*random.random()))])
  149. def star_field():
  150.     for w in xrange(len(controls.stars)):
  151.         x=random.randrange(100,255,2)
  152.         color1=(x,x,255)
  153.         pygame.draw.line(screen, color1, [controls.stars[w][0],\
  154.                                           controls.stars[w][1]],\
  155.                          [controls.stars[w][0],controls.stars[w][1]], 1)
  156.         controls.stars[w][1]+=starvel[0]
  157.         if controls.stars[w][1]>=controls.Sheight:
  158.             controls.stars[w][1]=0
  159.             controls.stars[w][0]=int(controls.Swidth*random.random())
  160.  
  161. def show_instructions():
  162.     font = pygame.font.Font("resources\data\prometheanb.ttf", 18)
  163.     while controls.instructions ==True:
  164.         x=60;y=80
  165.         for t in xrange(len(instructions)):
  166.             a=str(instructions[t]).strip('[]')
  167.             a=a[1:-1]
  168.             text = font.render(a, 0, [200,200,200])
  169.             screen.blit(text,(x,y))
  170.             y+=36
  171.         for event in pygame.event.get():
  172.             if event.type==KEYDOWN:
  173.                 controls.instructions=False
  174.         star_field()
  175.         update_screen()
  176.  
  177. def player_instructions(akuru,time):
  178.     color=[0,0,0]; x=0
  179.     c=0
  180.     length=(len(akuru))
  181.     t=0
  182.     font = pygame.font.Font("resources\data\prometheanb.ttf", 30)
  183.     while controls.instructions==True:
  184.         pygame.event.pump()
  185.         keys = pygame.key.get_pressed()
  186.         if keys[K_ESCAPE] or keys[K_BACKSPACE] or keys[K_RETURN]:
  187.                 controls.instructions=False
  188.         a=str(akuru[t])
  189.         for c in xrange(254):
  190.             text = font.render(a, 0, color)
  191.             textlength=text.get_width()
  192.             screen.blit(text,(controls.Swidth/2-textlength/2,controls.Sheight/2))
  193.             pygame.time.wait(time)
  194.             y=1 if c<127 else -1
  195.             x+=y
  196.             x=0 if x<0 else x
  197.             color[0]=color[1]=color[2]=x
  198.             update_screen()
  199.             pygame.event.pump()
  200.             keys = pygame.key.get_pressed()
  201.             if keys[K_ESCAPE] or keys[K_BACKSPACE] or keys[K_RETURN]:
  202.                 controls.instructions=False
  203.         t+=1
  204.         if t==length:
  205.             controls.instructions=False
  206. def save_game():
  207.     yref=yy=(Sheight/4)+100
  208.     slotno=1
  209.     while controls.savegame==True:
  210.         timestamp=time.asctime(time.localtime())[4:]
  211.         x=controls.Swidth/3
  212.         y=controls.Sheight/4
  213.         font = pygame.font.Font("resources\data\prometheanb.ttf", 20)
  214.         empty='<      - e m p t y -     >'
  215.         warning='save slot not empty.  S to overwrite'
  216.         warntext=font.render(warning,0,[200,0,0])
  217.         text=['Save Game','select slot and hit ENTER to SAVE game.',\
  218.               'BACKSPACE to exit without saving.']
  219.         for i in xrange(len(text)):
  220.             itext=font.render(text[i],0,[100,100,255])
  221.             screen.blit(itext,(controls.Swidth/2-itext.get_width()/2,\
  222.                               y-itext.get_height()))
  223.             y+=(itext.get_height()*2)
  224.         if len(savelist[slotno-1])>0:
  225.             screen.blit(warntext,(controls.Swidth/2-\
  226.                                   warntext.get_width()/2,y-itext.get_height()))
  227.  
  228.         screen.fill([30,30,30],[0,y,controls.Swidth,y],0)
  229.         font = pygame.font.Font("resources\data\prometheanb.ttf", 16)
  230.         cursor=font.render("<<<",0,[100,100,255])
  231.         for i in xrange(len(savelist)): # print the save list from disk file
  232.             if savelist[i]==[]:
  233.                 text=font.render(str(i+1)+". "+empty,0,[200,200,200])
  234.             else:
  235.                 text=font.render(str(i+1)+'. '+str(savelist[i][0]),0,[200,200,200])
  236.             screen.blit(text,(controls.Swidth/2-text.get_width()/2,y))
  237.             y+=text.get_height()*2
  238.         screen.blit(cursor,(controls.Swidth-controls.Swidth/2.55,yy))
  239.  
  240.         for event in pygame.event.get():
  241.             if event.type==KEYDOWN:
  242.                 if event.key==K_DOWN:
  243.                     yy+=25
  244.                     slotno+=1
  245.                 elif event.key==K_UP:
  246.                     yy-=25
  247.                     slotno-=1
  248.  
  249.                 if yy>=yref+250:
  250.                     yy=yref
  251.                     slotno=1
  252.                 if yy<yref:
  253.                     yy=yref+225
  254.                     slotno=10
  255.  
  256.                 if event.key==K_RETURN:
  257.                     savegamedata=vars(save_game_data()) # dict
  258.                     print savegamedata
  259.                     newsave=[timestamp,savegamedata] # make the save file
  260.                     savelist[slotno-1]=newsave # put into slot selected
  261.                     f=open('resources\data\saves.sg','wb')
  262.                     cPickle.dump(savelist,f) # write the file to disk
  263.                     f.close()
  264.                     controls.savegame=False
  265.  
  266.                 if event.key==K_BACKSPACE:
  267.                     controls.savegame=False
  268.  
  269.         star_field()
  270.         update_screen()
  271.  
  272. def load_game():
  273.     yref=yy=(Sheight/4)+100
  274.     slotno=1
  275.     while controls.loadgame==True:
  276.         timestamp=time.asctime(time.localtime())[4:]
  277.         x=controls.Swidth/3
  278.         y=controls.Sheight/4
  279.         font = pygame.font.Font("resources\data\prometheanb.ttf", 20)
  280.         empty='<      - e m p t y -     >'
  281.         warning='slot empty. nothing to load'
  282.         warntext=font.render(warning,0,[200,0,0])
  283.         text=['Load Game','select slot and hit HNTER to LOAD game.',\
  284.               'BACKSPACE to exit without loading.']
  285.         for i in xrange(len(text)):
  286.             itext=font.render(text[i],0,[100,100,255])
  287.             screen.blit(itext,(controls.Swidth/2-itext.get_width()/2,\
  288.                               y-itext.get_height()))
  289.             y+=(itext.get_height()*2)
  290.         if len(savelist[slotno-1])==0:
  291.             screen.blit(warntext,(controls.Swidth/2-\
  292.                                   warntext.get_width()/2,y-itext.get_height()))
  293.  
  294.         screen.fill([30,30,30],[0,y,controls.Swidth,250],0)
  295.         font = pygame.font.Font("resources\data\prometheanb.ttf", 16)
  296.         cursor=font.render("<<<",0,[100,100,255])
  297.         for i in xrange(len(savelist)): # print the save list from disk file
  298.             if savelist[i]==[]:
  299.                 text=font.render(str(i+1)+". "+empty,0,[200,200,200])
  300.             else:
  301.                 text=font.render(str(i+1)+'. '+str(savelist[i][0]),0,[200,200,200])
  302.             screen.blit(text,(controls.Swidth/2-text.get_width()/2,y))
  303.             y+=25
  304.         screen.blit(cursor,(controls.Swidth-controls.Swidth/2.55,yy))
  305.  
  306.         for event in pygame.event.get():
  307.             if event.type==KEYDOWN:
  308.                 if event.key==K_DOWN:
  309.                     yy+=25
  310.                     slotno+=1
  311.                 elif event.key==K_UP:
  312.                     yy-=25
  313.                     slotno-=1
  314.  
  315.                 if yy>=yref+250:
  316.                     yy=yref
  317.                     slotno=1
  318.                 if yy<yref:
  319.                     yy=yref+225
  320.                     slotno=10
  321.  
  322.                 if event.key==K_RETURN and savelist[slotno-1]!=[]:
  323.                     # Get highscores from disk n close file
  324.                     f=open('resources\data\saves.sg','rb')
  325.                     loadlist=cPickle.load(f)
  326.                     controls.loadgamedata=loadlist[slotno-1][1]
  327.                     # call the routine to load the game data to the vazriables
  328.                     set_game_data(controls.loadgamedata)
  329.                     f.close()
  330.                     controls.loadgame=False
  331.  
  332.                 if event.key==K_BACKSPACE:
  333.                     controls.loadgame=False
  334.  
  335.         star_field()
  336.         update_screen()
  337.  
  338. def set_game_data(info):
  339.     global score
  340.     controls.globes=info['globes']
  341.     controls.PUcount=info['PUcount']
  342.     controls.invincibility=info['invincibility']
  343.     controls.TRIPLEgun=info['TRIPLEgun']
  344.     controls.TRIPLEguntime=info['TRIPLEguntime']
  345.     controls.CBombflag=info['CBombflag']
  346.     controls.CBomb=info['CBomb']
  347.     controls.enemystate=info['enemystate']
  348.     controls.gamestate=info['gamestate']
  349.     controls.asteroidcount=info['asteroidcount']
  350.     controls.collected=info['collected']
  351.     controls.gamecounter=info['gamecounter']
  352.     controls.no_of_enemies=info['no_of_enemies']
  353.     controls.enemycount=info['enemycount']
  354.     controls.music=info['music']
  355.     controls.rank=info['rank']
  356.     score=info['score']
  357.     Hero.lives=info['Herolives']
  358.     Hero.life=info['Herolife']
  359.     Hero.nodamage=info['Heronodamage']
  360.    
  361.     # if player had collected any globes before saving the game, reduce it from
  362.     # the amount to be spawned
  363.     if controls.globes=='Galive':
  364.         globeamount=controls.globequantity[0]-controls.collected
  365.         controls.globelist=[]
  366.         spawn_globes(Gglobe, 0.3,10,globeamount)
  367.  
  368.     if controls.globes=='Ralive':
  369.         globeamount=controls.globequantity[1]-controls.collected
  370.         controls.globelist=[]
  371.         spawn_globes(Rglobe, 0.4,15,globeamount)
  372.    
  373.     if controls.globes=='Oalive':
  374.         if controls.asteroidswitch=="OFF":
  375.             controls.asteroidswitch="ON"
  376.         globeamount=controls.globequantity[2]-controls.collected
  377.         controls.globelist=[]
  378.         spawn_globes(Oglobe, 0.5,20,globeamount)
  379.        
  380.     if controls.globes=='Palive':
  381.         globeamount=controls.globequantity[3]-controls.collected
  382.         controls.globelist=[]
  383.         spawn_globes(Pglobe, 0.6,25,globeamount)
  384.  
  385.     if controls.gamestate=="Level 2":
  386.         boss1.radar=controls.Swidth/2-100
  387.         boss1.mag=40 # shooting delay
  388.         controls.enemystate="boss on"
  389.         boss1.status='M'
  390.  
  391.     if controls.gamestate=="Level 3":
  392.         controls.asteroidswitch="OFF"
  393.         controls.globes='OFF'
  394.         Mothership1.status="M"
  395.         controls.globelist=[]
  396.         Hero.BMag=[]
  397.         Hero.bombs=[0,"D"]
  398.         controls.counter=0
  399.         controls.no_of_enemies=12
  400.         controls.spendtime=0
  401.         boss1.status='boss1 dest'
  402.  
  403.     if controls.gamestate=="Level 4":
  404.         controls.enemystate="REST 2"
  405.         controls.asteroidswitch="ON"
  406.         controls.asteroidcount=0
  407.         controls.asteroidlimit=6
  408.         controls.asteroidamount=100
  409.         controls.spendtime=0
  410.    
  411. def hall_of_fame_message():
  412.     x=controls.Swidth/4
  413.     y=300
  414.     font = pygame.font.Font("resources\data\prometheanb.ttf", 22)
  415.     akuru=['CONGRATULATIONS! You qualify to enter ',\
  416.            'the Space Gladiator Hall of Fame.','Please enter your name.']
  417.  
  418.     for t in xrange(len(akuru)):
  419.         a=str(akuru[t])
  420.         text = font.render(a, 0, [175,175,175])
  421.         screen.blit(text,(controls.Swidth/2-text.get_width()/2,y))
  422.         y+=text.get_height()
  423.     return y # y position to print name as it is typed
  424.  
  425. def random_xyheading(): #generates a random number outside 0 and Swidth
  426.     x=int(random.randrange(-100,100,1))
  427.     y=int(random.randrange(50,(controls.Sheight-50),1))
  428.     h=int(random.randrange(-45,45,1)) # heading
  429.     if x>=-50:
  430.         x+=controls.Swidth+50
  431.         h=h+180
  432.     return x,y,h
  433.  
  434. def Asteroid_spawn():
  435.     radius=controls.Sheight-100
  436.     x=int(radius*math.cos(controls.asterseed)+controls.Swidth/2)
  437.     y=int(radius*math.sin(controls.asterseed)+controls.Sheight/2)
  438.     h=random.randrange(-180,180,1) # heading
  439.     controls.asterseed=(controls.asterseed+40)%180
  440.     return x,y,h
  441.  
  442. def spawn_globes(globeimage,gspeed,size,quantity):
  443.     for w in xrange (quantity):
  444.         '''image,x,y,scale,no of items spawned'''
  445.         globe=Collectibles(globeimage,controls.Swidth*random.random(),\
  446.                            controls.Sheight*random.random(),\
  447.                           size,quantity)
  448.         globe.speed=gspeed
  449.         controls.globelist.append(globe)
  450.     return controls.globelist
  451.  
  452. def add_and_close_file():
  453.     cPickle.dump(highscores,f)
  454.     f.close()
  455.  
  456. def game_over():
  457.     pygame.mixer.music.stop()
  458.     pygame.quit()
  459.     sys.exit()
  460.  
  461. def really_quit():
  462.     controls.quitgame=True
  463.     while controls.quitgame==True:
  464.         font = pygame.font.Font("resources\data\prometheanb.ttf", 25)
  465.         y=controls.Sheight/2
  466.         for i in xrange(len(confirm)):
  467.             text=font.render(str(confirm[i]),2,[10,10,250])
  468.             screen.blit(text,(controls.Swidth/2-text.get_width()/2,y))
  469.             y+=text.get_height()
  470.         for event in pygame.event.get():
  471.             if event.type==KEYDOWN:
  472.                 if event.key==K_y:
  473.                     game_over()
  474.  
  475.                 elif event.key!=K_y:
  476.                     controls.quitgame=False
  477.         star_field()
  478.         update_screen()
  479.  
  480. #------------------------------------------------------------------------------#
  481. #                          A L L  T H E  C L A S S E S                         #
  482. #------------------------------------------------------------------------------#
  483.  
  484. #The Master class with common attributes and methods for all classes
  485. class Master_elements(object):
  486.     def __init__(self,x,y,scale,status,frrate,frsize):
  487.         self.x=x
  488.         self.y=y
  489.         self.scale=scale
  490.         self.status=status
  491.         self.frsize=frsize
  492.         self.frrate=frrate
  493.         self.heading=0 #in degrees
  494.         self.frame=0 # when exploding
  495.         self.rectarea=pygame.Rect(self.x-self.scale/2,\
  496.                                   (controls.Sheight-self.y)-self.scale/2,\
  497.                                   self.scale,self.scale)
  498.         self.centerx=self.rectarea.centerx
  499.         self.centery=self.rectarea.centery
  500.     def posxy(self,x,y):
  501.         if self.x>controls.Swidth:
  502.             self.x=0
  503.         elif self.x<0 :
  504.             self.x=controls.Swidth
  505.         else:
  506.             self.x=x
  507.         if self.y<0:
  508.             self.y=controls.Sheight
  509.         elif self.y>controls.Sheight:
  510.             self.y=0
  511.         else:
  512.             self.y=y
  513.     def setHeading(self,angle):
  514.         self.heading=angle%360
  515.  
  516.     def getrectarea(self):
  517.         self.rectarea=pygame.Rect(self.x-self.scale/2,\
  518.                                   (controls.Sheight-self.y)-self.scale/2,\
  519.                                   self.scale,self.scale)
  520.         self.centerx=self.rectarea.centerx
  521.         self.centery=self.rectarea.centery
  522.  
  523. class HeroObject(Master_elements):
  524.     def __init__(self,scale,x,y,status,lives,\
  525.                  bonus,bombs,frrate,frsize):
  526.         Master_elements.__init__(self,x,y,scale,status,frrate,frsize)
  527.         self.image1=pygame.transform.scale(images.Heroa,(self.scale,self.scale))# normal
  528.         self.image2=pygame.transform.scale(images.Herob,(self.scale,self.scale))# thrust
  529.         self.image3=images.Heroc # explode
  530.         self.image4=images.Herod # teleport
  531.         self.speedx=0
  532.         self.speedy=0
  533.         self.thrust=0.02
  534.         self.speedlimit=6
  535.         self.engines=False
  536.         self.firerate=0
  537.         self.maxfirerate=4
  538.         self.life=450 # initial value 450
  539.         self.lives=lives
  540.         self.reinit=100# if Hero dies respawn after reinit becomes 0
  541.         self.ssx=0 # sprite sheet pox
  542.         self.ssy=0 # sprite sheet posy
  543.         self.guntemp=0 # when max value can't fire gun!
  544.         self.nodamage=500# time invincible after being spawned 250*2=500
  545.         self.bonus=bonus # ["one",20,"S",0]
  546.         self.shieldradius=22
  547.         self.shieldcolour=[250,250,250]
  548.         self.shieldcolour2=255
  549.         self.CMag=[] # Center Magazine
  550.         self.LMag=[] # Left Magazine
  551.         self.RMag=[] # Right magazine
  552.         self.BMag=[] # Bomb Magazine
  553.         self.CBMag=[]# Cluster Bomb Mag
  554.         self.bombs=bombs
  555.  
  556.     def move(self,speedx,speedy):
  557.         self.x+=speedx
  558.         self.y+=speedy
  559.         self.posxy(self.x,self.y)
  560.     def teleport(self):
  561.         if (self.frame<16):
  562.             self.ssx=(self.frame%4)*100
  563.             self.ssy=math.floor(self.frame/4)*100
  564.         else:
  565.             self.status="N"
  566.             self.x=controls.Swidth*random.random()
  567.             self.y=controls.Sheight*random.random()
  568.             self.speedx*=-Hero.thrust
  569.             self.speedy*=-Hero.thrust
  570.             self.frame=0
  571.         screen.blit(self.image4,(self.x-self.scale,(controls.Sheight-self.y)-\
  572.                                  self.scale),Rect((self.ssx,self.ssy),\
  573.                                                     (100,100)))
  574.         self.frame+=1
  575.     def explode(self):
  576.         if self.frame < self.frrate:
  577.             self.ssx=(self.frame%self.frrate)*self.frsize
  578.             self.ssy=math.floor(self.frame/self.frrate)*self.frsize
  579.         else:
  580.             self.status="S"
  581.         screen.blit(self.image3,(self.x-self.scale/2,\
  582.                                  (controls.Sheight-self.y)-\
  583.                                  self.scale/2),Rect((self.ssx,self.ssy),\
  584.                                                     (self.frsize,self.frsize)))
  585.         self.frame+=1
  586.     def update(self):
  587.         if self.engines==True:
  588.             rot_image = pygame.transform.rotate(self.image2,self.heading)
  589.             rot_rect=self.image2.get_rect().copy()
  590.         else:
  591.             rot_image = pygame.transform.rotate(self.image1,self.heading)
  592.             rot_rect=self.image1.get_rect().copy()
  593.         rot_rect.center = rot_image.get_rect().center
  594.         rot_image = rot_image.subsurface(rot_rect).copy()
  595.         screen.blit(rot_image,(self.x-self.scale/2,controls.Sheight\
  596.                                -self.y-self.scale/2))
  597.  
  598. class Gun():
  599.     def __init__(self,image1,image2,speed,status,scale,life,kind,frrate,frsize):
  600.         self.x=0
  601.         self.y=0
  602.         self.scale=scale
  603.         self.life=life
  604.         self.heading=0
  605.         self.rectarea=pygame.Rect(self.x-self.scale/2,\
  606.                                   (controls.Sheight-self.y)-self.scale/2,\
  607.                                   self.scale,self.scale)
  608.         self.image1=pygame.transform.scale(image1, (self.scale,self.scale))
  609.         self.image2=image2
  610.         self.speed=speed
  611.         self.status =status #S=Standby, F=Fired, E=exploding, D=Destroyed
  612.         self.ssx=0
  613.         self.ssy=0
  614.         self.frame=0
  615.         self.frrate=frrate
  616.         self.frsize=frsize
  617. # AB-alien bullet HB-Hero bullet HM=Hero missile BM=boss missile
  618.         self.kind=kind
  619.     def fire(self,parent):
  620.         self.x=parent.x+(parent.scale/2)*math.cos(math.radians(parent.heading))
  621.         self.y=parent.y+(parent.scale/2)*math.sin(math.radians(parent.heading))
  622.         self.heading=parent.heading
  623.         self.status="F"
  624.     def fireR(self,parent):
  625.         self.x=parent.x+(parent.scale/2)*math.cos(math.radians\
  626.                                                   (parent.heading-30))
  627.         self.y=parent.y+(parent.scale/2)*math.sin(math.radians\
  628.                                                   (parent.heading-30))
  629.         self.heading=parent.heading
  630.         self.status="F"
  631.     def fireL(self,parent):
  632.         self.x=parent.x+(parent.scale/2)*math.cos(math.radians\
  633.                                                   (parent.heading+30))
  634.         self.y=parent.y+(parent.scale/2)*math.sin(math.radians\
  635.                                                   (parent.heading+30))
  636.         self.heading=parent.heading
  637.         self.status="F"
  638.  
  639.     def fireBombCluster(self,parent,angle,h):
  640.         self.x=parent.x-(parent.scale/2)*math.cos(math.radians\
  641.                                                   (parent.heading-angle))
  642.         self.y=parent.y-(parent.scale/2)*math.sin(math.radians\
  643.                                                   (parent.heading-angle))
  644.         self.heading=h
  645.         self.status="CF"
  646.  
  647.     def explode(self):
  648.         self.status="E"
  649.     def next_image_frame(self):
  650.         self.frame+=1
  651.         if self.frame < self.frrate*self.frrate:
  652.             self.ssx=(self.frame%self.frrate)*self.frsize
  653.             self.ssy=math.floor(self.frame/self.frrate)*self.frsize
  654.         else:
  655.             self.status="D"
  656.             self.frame=0
  657.             self.ssx=0
  658.             self.ssy=0
  659.     def update(self):
  660.         if self.kind!="HM":
  661.             self.life-=1
  662.         if self.kind=="HM" and self.status=="CF":
  663.             self.life-=1
  664.             if self.x>controls.Swidth or self.x<0 or \
  665.                self.y>controls.Sheight or self.y<0:
  666.                 self.life=0
  667.         if self.life<=0:
  668.             self.status="D"
  669.         if self.status=="F" or self.status=="CF":
  670.             if self.status=='CF': # bomb fired so start reducing speed
  671.                 self.speed-=0.1
  672.                 if self.speed<=0:
  673.                     self.speed=0
  674.             self.x+=self.speed*math.cos(math.radians(self.heading))
  675.             self.y+=self.speed*math.sin(math.radians(self.heading))
  676.             if((self.x<0 or self.x > controls.Swidth) \
  677.                and (self.y < 0 or self.y > controls.Sheight)):
  678.                 self.status="D"
  679.         if self.status=="E":
  680.             self.next_image_frame()
  681.         if self.status=="F" or self.status=="CF":
  682.             self.rotate()
  683.             screen.blit(self.new_image,(self.x,\
  684.                                      controls.Sheight-self.y),\
  685.                         Rect((self.ssx,self.ssy),(100,100)))
  686.         if self.status=="E":
  687.             screen.blit(self.image2,(self.x-self.frsize/2,\
  688.                                      controls.Sheight-self.y-self.frsize/2),\
  689.                         Rect((self.ssx,self.ssy),(self.frsize,self.frsize)))
  690.     def getrectarea(self):
  691.         if self.kind=="BM":
  692.             self.rectarea=pygame.Rect(self.x+10-self.scale/2,\
  693.                           (controls.Sheight+10-self.y)-self.scale/2,\
  694.                           self.scale-8,self.scale-8)
  695.         elif self.kind=="HM" and controls.CBomb=="F":
  696.             self.rectarea=pygame.Rect(self.x,\
  697.                                       (controls.Sheight-self.y),\
  698.                                       self.scale,self.scale)
  699.         elif self.kind=="HM" and controls.CBomb=="E":
  700.             self.rectarea=pygame.Rect(self.x-self.frsize/2,\
  701.                                       (controls.Sheight-self.y)-self.frsize/2,\
  702.                                       self.frsize,self.frsize)
  703.         else:
  704.             self.rectarea=pygame.Rect(self.x-self.scale/2,\
  705.                                       (controls.Sheight-self.y)-self.scale/2,\
  706.                                       self.scale,self.scale)
  707.  
  708.     def rotate(self):
  709.         rot_image = pygame.transform.rotate(self.image1,self.heading)
  710.         rot_rect=self.image1.get_rect().copy()
  711.         rot_rect.center = rot_image.get_rect().center
  712.         self.new_image = rot_image.subsurface(rot_rect).copy()
  713.  
  714. class Collectibles():
  715.     def __init__(self,image,x,y,scale,noofitems):
  716.         self.x=x
  717.         self.y=y
  718.         self.scale=scale
  719.         self.status="N"# normal when collected becomes "C"
  720.         self.heading=controls.Swidth*random.random()
  721.         self.image=image
  722.         self.image=pygame.transform.scale(image,(self.scale,self.scale))
  723.         self.speed=0.3
  724.         self.noofitems=noofitems
  725.         self.rectarea=pygame.Rect(self.x-self.scale/2,\
  726.                                   (controls.Sheight-self.y)-self.scale/2,\
  727.                                   self.scale,self.scale)
  728.     def update(self):
  729.         self.x+=self.speed*math.cos(math.radians(self.heading))
  730.         self.y+=self.speed*math.sin(math.radians(self.heading))
  731.         """accelerate the collectibles when the Hero gets close"""
  732.         if abs(Hero.x-self.x)<75 and abs(Hero.y-self.y)<100:
  733.             self.x+=self.speed*math.cos(math.radians(self.heading))*\
  734.                      (4*random.random())
  735.             self.y+=self.speed*math.sin(math.radians(self.heading))*\
  736.                      (4*random.random())
  737.         if self.x<0: self.x=controls.Swidth
  738.         if self.x>controls.Swidth: self.x=0
  739.         if self.y<0: self.y=controls.Sheight
  740.         if self.y>controls.Sheight: self.y=0
  741.         screen.blit(self.image,(self.x-self.scale/2,controls.Sheight\
  742.                                -self.y-self.scale/2))
  743.     def getrectarea(self):
  744.         self.rectarea=pygame.Rect(self.x-self.scale/2,\
  745.                                   (controls.Sheight-self.y)-self.scale/2,\
  746.                                   self.scale,self.scale)
  747.  
  748. class Asteroids():
  749.     """image,x,y,life,scale,width,xfr,frsize,noframes,status"""
  750.     def __init__(self,image,image2,x,y,life,width,frrate,\
  751.                  frsize,noframes,kind,status):
  752.         self.x=x
  753.         self.y=y
  754.         self.scale=frsize
  755.         self.kind=kind # L-Large, M-Medium, S-Small
  756.         self.status=status #  M-moving in space,  E-explode,  D- destroyed
  757.         self.heading=360*random.random()
  758.         self.frame=0
  759.         self.frrate=frrate
  760.         self.frsize=frsize
  761.         """rect smaller than actual size cause of asteroid shape"""
  762.         self.life=life
  763.         self.image=image
  764.         self.expimage=image2
  765.         self.width=width
  766.         self.noframes=noframes
  767.         self.speed=0.6
  768.         self.speedlimit=self.speed
  769.         self.ssx=0
  770.         self.ssy=0
  771.         self.framecount=0
  772.         self.rectarea=pygame.Rect(self.x-self.scale/3,\
  773.                                   (controls.Sheight-self.y)-self.scale/3,\
  774.                                   self.scale-self.scale/2.5,\
  775.                                   self.scale-self.scale/2.5)
  776.         self.centerx=self.rectarea.centerx
  777.         self.centery=self.rectarea.centery
  778.  
  779.     def update(self):
  780.         """only the number of frames on the x axis is needed"""
  781.         if self.frame<self.noframes:
  782.             self.ssx=(self.frame%self.frrate)*self.frsize
  783.             self.ssy=math.floor(self.frame/self.frrate)*self.frsize
  784.         self.frame+=1
  785.  
  786.         if self.status=="M" and self.frame==self.noframes:
  787.             self.frame=0
  788.             self.ssx=0
  789.             self.xxy=0
  790.  
  791.         if self.status=="M":
  792.             self.x+=self.speed*math.cos(math.radians(self.heading))
  793.             self.y+=self.speed*math.sin(math.radians(self.heading))
  794.  
  795.         if self.y<-self.frsize: self.y=controls.Sheight
  796.         if self.y>controls.Sheight: self.y=0
  797.         if self.x<-self.frsize: self.x=controls.Swidth
  798.         if self.x>controls.Swidth: self.x=0
  799.         if self.status=="M":
  800.             screen.blit(self.image,(self.x-self.scale/2,\
  801.                                     controls.Sheight-self.y-self.scale/2),Rect\
  802.                         ((self.ssx,self.ssy),(self.scale,self.scale)))
  803.         if self.status=="E":
  804.             screen.blit(self.expimage,(self.x-self.scale/2,\
  805.                                        controls.Sheight-self.y-self.scale/2),\
  806.                         Rect((self.ssx,self.ssy),(self.scale,self.scale)))
  807.             if self.frame>=self.noframes:
  808.                 self.status="D"
  809.  
  810.     def getrectarea(self):
  811.         """get the rect a little smaller than the actual size"""
  812.         self.rectarea=pygame.Rect(self.x-self.scale/3,\
  813.                                   (controls.Sheight-self.y)-self.scale/3,\
  814.                                   self.scale-self.scale/2.5,\
  815.                                   self.scale-self.scale/2.5)
  816.  
  817. class EnemyObject(Master_elements):
  818.     def __init__(self,image,image2,scale,x,y,life,firerate,frrate,\
  819.                  frsize,status):
  820.         """status-"M" move "E"-explode "D"-destroy"""
  821.         Master_elements.__init__(self,x,y,scale,status,frrate,frsize)
  822.         self.life=life
  823.         self.image=pygame.transform.scale(image,(self.scale,self.scale))
  824.         self.image2=image2
  825.         """enemy starts with status 'M' becomes 'E'-life=0 'D'=destroyed"""
  826.         self.a=0.04 # accelleration
  827.         self.fixeda=0.04
  828.         self.firerate=firerate
  829.         self.radar=0 # how close the enemy must be to detect opponent
  830.         self.Mag=[] # The gun bullet magazine
  831.         self.BMag=[] # The bomb mag if any
  832.         """state= flag to show style of movement,counter,accel save loc"""
  833.         self.state='normal'
  834.         self.counter=0
  835.         # safe area for same type collisions
  836.         self.safearea=self.scale/2
  837.  
  838.     def follow(self,target,speed):
  839.         self_rect=pygame.Rect(self.x-self.scale/2,\
  840.                               controls.Sheight-self.y-self.scale/2,\
  841.                               self.scale,self.scale)
  842.         target_rect=pygame.Rect(target.x-target.scale/2,\
  843.                                 controls.Sheight-target.y-target.scale/2,\
  844.                                 target.scale,target.scale)
  845.         # follow Hero only if close than radar
  846.         if abs(self.centerx-Hero.centerx)<self.radar and \
  847.            abs(self.centery-Hero.centery)<self.radar and self.state=='normal':
  848.             delta_x=target.x-self.x
  849.             delta_y=target.y-self.y
  850.             self.setHeading(math.degrees(math.atan2(delta_y,delta_x)))
  851.             self.move(speed)
  852.         else:
  853.             self.heading=self.heading
  854.             self.move(speed)
  855.  
  856.     def move(self,speed):
  857.         new_x=self.x+speed*math.cos(math.radians(self.heading))*\
  858.                constant*self.a
  859.         new_y=self.y+speed*math.sin(math.radians(self.heading))*\
  860.                constant*self.a
  861.         self.ai_behaviour()
  862.         self.posxy(new_x,new_y)
  863.  
  864.     def ai_behaviour(self):
  865.         if self.state=='turn':
  866.             self.counter=0
  867.             self.state='away' # move away from hero
  868.  
  869.         # dont get too close to the Hero
  870.         if abs(self.centerx-Hero.centerx)<=((self.scale)+(Hero.scale)) and\
  871.            abs(self.centery-Hero.centery)<=((self.scale)+(Hero.scale)):
  872.             self.state='away'
  873.             self.counter=0
  874.  
  875.         if self.state=='away' and self.counter<80:
  876.             if self.counter<20: #turn till this value
  877.                 self.heading+=2
  878.                 self.a=0.06 # move away faster than approaching
  879.             self.counter+=1
  880.  
  881.         if self.counter>=80: # reach limit of  moving away
  882.             self.state='normal'
  883.             self.a=self.fixeda
  884.             self.counter=0
  885.             self.heading=self.heading+30
  886.  
  887.     def explode(self):
  888.         if (self.frame <=(self.frrate*self.frrate)):
  889.             self.ssx=(self.frame%self.frrate)*self.frsize
  890.             self.ssy=math.floor(self.frame/self.frrate)*self.frsize
  891.             screen.blit(self.image2,(self.x-self.frsize/2,controls.Sheight-\
  892.                                      self.y-self.frsize/2),Rect\
  893.                         ((self.ssx,self.ssy),(self.frsize,self.frsize)))
  894.         else:
  895.             self.status="D"
  896.         self.frame+=1
  897.  
  898.     def update(self):
  899.         rot_image = pygame.transform.rotate(self.image,self.heading)
  900.         rot_rect=self.image.get_rect().copy()
  901.         rot_rect.center = rot_image.get_rect().center
  902.         rot_image = rot_image.subsurface(rot_rect).copy()
  903.         screen.blit(rot_image,(self.x-self.scale/2,controls.Sheight-\
  904.                                self.y-self.scale/2))
  905.         self.draw_healthbar()
  906.  
  907.     def mship_update(self,heading): # use for rotating mothership while moving
  908.         self.x+=self.speed*math.cos(math.radians(self.heading))
  909.         self.y+=self.speed*math.sin(math.radians(self.heading))
  910.         rot_image = pygame.transform.rotate(self.image,self.heading)
  911.         rot_rect=self.image.get_rect().copy()
  912.         rot_rect.center = rot_image.get_rect().center
  913.         rot_image = rot_image.subsurface(rot_rect).copy()
  914.         screen.blit(rot_image,(self.x-self.scale/2,controls.Sheight\
  915.                                -self.y-self.scale/2))
  916.         self.draw_healthbar()
  917.  
  918. # Draw the Alien Health Bar
  919.     def draw_healthbar(self):
  920.         pygame.draw.rect(screen,(255,0,0),[self.x-self.scale/2\
  921.                                    ,controls.Sheight-self.y-self.scale/2,\
  922.                                            self.life ,3],0)
  923. class Load_images():
  924.     def __init__(self):
  925.         self.Heroa=pygame.image.load\
  926.                     ("resources\grfx\HeroTF.png").convert_alpha()
  927.         self.Herob=pygame.image.load\
  928.                     ("resources\grfx\HeroTT.png").convert_alpha()
  929.         self.Heroc=pygame.image.load\
  930.                     ("resources\grfx\Hexplosion.png").convert_alpha()
  931.         self.Herod=pygame.image.load\
  932.                     ("resources\grfx\Teleport.png").convert_alpha()
  933.        
  934. class Game_controls():
  935.     def __init__(self):
  936.         self.Swidth=Swidth
  937.         self.Sheight=Sheight
  938.         self.globelist=[] # list for globes
  939.         self.globes='Green'
  940.         """globes come on when the flag shows the color"""
  941.         self.globequantity=[100,75,50,15] # 100 Green,75 Red,50 Orange,15 Purple
  942.         self.PUcount=[1,1,1]    # counter-invincibility, guntytpe,CBomb
  943.         self.invincibility=False
  944.         self.TRIPLEgun=False
  945.         self.TRIPLEguntime=0
  946.         self.CBombflag=False
  947.         self.CBomb=False # Cluster bomb False,True,fired-F,exploding-E,over-D
  948.         self.CBangle=0 # the cluster bomb dispersion angle increase by 36
  949.         self.enemystate='boss off'
  950.         self.gamestate='initial'#(initial,Level 1,Level 2 etc.)
  951.         self.pause=True
  952.         self.instructions=False
  953.         self.titlewidth=0
  954.         self.titleheight=0
  955.         self.halloffame=False
  956.         self.asteroidcount=0    # if equal to asteroid amount no more spawned
  957.         self.asteroidlimit=4# minimum no of asteroids in list. 5 at start
  958.         self.asteroidamount=75# total amount of large asteroids spawned
  959.         self.asteroidswitch="OFF" # first time on is with Orange globes
  960.         self.asterseed=int(random.randrange(0,360,36))
  961.         self.collected=0        # amount of globes collected
  962.         self.gamespeed=250
  963.         self.gamecounter=0
  964.         self.no_of_enemies=0
  965.         self.enemycount=0 # count each alienwave
  966.         self.enemy_limit=25  # enemy limit on screen
  967.         self.LreduceA1=6     # life reduce Alien1 life-24
  968.         self.LreduceA2=8     # life reduce Alien2 life-24
  969.         self.LreduceB=0.4   # life reduce Boss  life-100
  970.         self.LreduceM=0.2  # life reduce Mothership life-100
  971.         self.LreduceFA=0.2 # life reduce FinalAliens life-50
  972.         self.FAamount=6
  973.         self.spendtime=0 # a counter to do nothing
  974.         self.glt_sec=clock.tick()/1000 # game looptime in seconds
  975.         self.name=''            # hall of fame name
  976.         self.music='theme'
  977.         self.stars=[] # the star field co ordinates list
  978.         self.Alien1=[]    # amount of enemies
  979.         self.Alien2=[]
  980.         self.FinalAliens=[] # the final Alien attack ships-2
  981.         self.AlienMag=[]
  982.         self.Alien2Mag=[]
  983.         self.Alien3Mag=[]
  984.         self.BossBombMag=[]
  985.         self.musicfader=.5
  986.         self.counter=0 # a counter to do waiting
  987.         self.savegame=False
  988.         self.loadgame=False
  989.         self.loadgamedata=[] # load game data here and distribute to variables
  990.         self.rank="CADET"
  991.         self.quitgame=False
  992.        
  993. class save_game_data():
  994.     def __init__(self):
  995.         self.globes=controls.globes
  996.         self.PUcount=controls.PUcount
  997.         self.invincibility=controls.invincibility
  998.         self.TRIPLEgun=controls.TRIPLEgun
  999.         self.TRIPLEguntime=controls.TRIPLEguntime
  1000.         self.CBombflag=controls.CBombflag
  1001.         self.CBomb=controls.CBomb
  1002.         self.enemystate=controls.enemystate
  1003.         self.gamestate=controls.gamestate
  1004.         self.asteroidcount=controls.asteroidcount
  1005.         self.collected=controls.collected
  1006.         self.gamecounter=controls.gamecounter
  1007.         self.no_of_enemies=controls.no_of_enemies
  1008.         self.enemycount=controls.enemycount
  1009.         self.music=controls.music
  1010.         self.rank=controls.rank
  1011.         self.score=score
  1012.         self.Herolives=Hero.lives
  1013.         self.Herolife=Hero.life
  1014.         self.Heronodamage=Hero.nodamage
  1015.  
  1016. controls=Game_controls() # initialize all game controls
  1017. screen = pygame.display.set_mode\
  1018.          ((controls.Swidth, controls.Sheight),screenmode,0) #display screen
  1019. colourvals=[225,250] # colour grad,temp. color
  1020. color1=(255,255,255)
  1021. color2=(170,170,170)
  1022. color3=(100,100,100)
  1023. red=[255,0,0]
  1024.  
  1025. # no font specified-NONE
  1026. font = pygame.font.Font("resources\data\prometheanb.ttf", 22)
  1027. text1 = font.render("Score:", 2, (150,150,250))
  1028. font = pygame.font.Font("resources\data\prometheanb.ttf", 18)
  1029. text = font.render("S H I E L D", 2, [190,0,0])
  1030. text2=pygame.transform.rotozoom(text,90,1)
  1031. text = font.render("GUN TEMP.", 2,[200,200,200])
  1032. text3=pygame.transform.rotozoom(text,90,1)
  1033. font = pygame.font.Font("resources\data\prometheanb.ttf", 22)
  1034. text4= font.render("ALIEN SHIP BONUS-1000!", 2,[255,55,35])
  1035. text5= font.render("BOMBS: ", 2,[200,0,200])
  1036.  
  1037. scorestr=""
  1038. score=[0,0,0,0,0,0,0] #mil,hunthous, tenthous,thous,huns,tens,ones
  1039. scorestr= "".join(str(i) for i in score)
  1040. ##for w in score: scorestr+=str(w)
  1041. realscore=int(scorestr)
  1042. asteroids=[]
  1043. starvel=[0.1,0.1,0.05] # velocity of the different star layers
  1044. initialize_stars()
  1045.  
  1046. f=open('resources\data\scores.sg','rb')# Get highscores from disk n close file
  1047. highscores=cPickle.load(f)
  1048. f.close()
  1049.  
  1050. f=open('resources\data\saves.sg','rb')# Get save list from disk n close file
  1051. savelist=cPickle.load(f)
  1052. f.close()
  1053.  
  1054.  
  1055. intro=['special thanks to','Shanika Amarasoma and Jonathan Stockwell',\
  1056.        'Hero Space Ship graphics','Kim Lathrope','other Space Ship graphics',\
  1057.        'millionthvector.blogspot.com','Game concept, design, coding,',\
  1058.        'music composed and performed by','Diliup Gabadamudalige',\
  1059.        ' ','somewhere in the Galaxy','this could be happening.....']
  1060.  
  1061. instructions=['You are searching for rare elements in the far corners of the ',\
  1062. 'Galaxy. You have found a system abundant with rare energy globes.',\
  1063. 'Collect as much as you can while fighting the guardian Krogg ships.',\
  1064. 'The purple energy globes can be converted into Plasma bombs which',\
  1065. 'can be used to defend your ship from the Main Fighter Ship.',\
  1066. 'Spacebar-Lazer Fire      "B"-Fire Bombs      "T"-Teleport',\
  1067. 'Teleporting causes shield depletion. Continous firing will heat your',\
  1068. 'gun and overheating will prevent you from further firing.',\
  1069. '"UP"-thrust     "DOWN"-brake     "LEFT"/"RIGHT"-to rotate',\
  1070. '"P" for High Scores and pause game.',\
  1071. '"Esc" to quit game','Good Luck!',' ',\
  1072. 'Hit a key to get back to the game']
  1073.  
  1074. confirm=['Do you really want to quit?','Y to Quit',\
  1075.              'any other key to get back to the game']
  1076.  
  1077. level3=['Just as you thought it was over','and start breathing again,',\
  1078.         'your Radar picks up something','heading your way....']
  1079.  
  1080. level4=["The Kroggs who consider themselves","Masters of the Universe,",\
  1081.         "are not pleased by your daring actions.",\
  1082.         "So now it's time to meet them.","personally.."]
  1083.  
  1084. playerwins=["Congratulations!","You completed the game.",\
  1085.             'you are hereby','A  S P A C E  G L A D I A T O R !']
  1086. #------------------------------------------------------------------------------#
  1087. #                                load the sound                                #
  1088. #------------------------------------------------------------------------------#
  1089.  
  1090. Heromove=pygame.mixer.Sound('resources\snd\Thrust.ogg')
  1091. Herofire=pygame.mixer.Sound('resources\snd\LASER1.WAV')
  1092. Herofire2=pygame.mixer.Sound('resources\snd\atarifire.WAV')
  1093. enemyexp=pygame.mixer.Sound('resources\snd\enemyexplode.WAV')
  1094. alienshoot=pygame.mixer.Sound('resources\snd\photon.wav')
  1095. warn=pygame.mixer.Sound('resources\snd\warn1.ogg')
  1096. Heroexp=pygame.mixer.Sound('resources\snd\Heroexplode.wav')
  1097. collect=pygame.mixer.Sound('resources\snd\hiblip.wav')
  1098. teleportsound=pygame.mixer.Sound('resources\snd\synthfall.wav')
  1099. extralife=pygame.mixer.Sound('resources\snd\extra_life.wav')
  1100. shipbonus=pygame.mixer.Sound('resources\snd\asbp.wav')
  1101. bosscanfire=pygame.mixer.Sound('resources\snd\podipipireema.wav')
  1102. Herofirebomb=pygame.mixer.Sound('resources\snd\HBlaunch.wav')
  1103. hkollidea=pygame.mixer.Sound('resources\snd\Kollide.wav')
  1104. astexplode=pygame.mixer.Sound('resources\snd\globexplod.wav')
  1105. bossexplode=pygame.mixer.Sound('resources\snd\B1exp.wav')
  1106. bossmove=pygame.mixer.Sound('resources\snd\badboss1.wav')
  1107. invince=pygame.mixer.Sound('resources\snd\invincecollect.ogg')
  1108. alien1music="resources\snd\SGAlien1theme.ogg"
  1109. alien2music="resources\snd\SGAlien2theme.ogg"
  1110. boss1music="resources\snd\SGBoss1theme.ogg"
  1111.  
  1112. Herofirech= pygame.mixer.Channel(0)
  1113. Herothrustch=pygame.mixer.Channel(1)
  1114. bosschannel=pygame.mixer.Channel(2)
  1115. collectch=pygame.mixer.Channel(3)
  1116. aliench=pygame.mixer.Channel(4)
  1117. pygame.mixer.set_reserved(0)
  1118. pygame.mixer.set_reserved(1)
  1119. pygame.mixer.set_reserved(2)
  1120. pygame.mixer.set_reserved(3)
  1121. pygame.mixer.set_reserved(4)
  1122. Heromove.set_volume(.2); Herofire.set_volume(.2)
  1123. enemyexp.set_volume(.5); alienshoot.set_volume(0.06)
  1124. teleportsound.set_volume(.3); shipbonus.set_volume(0.9)
  1125. bosscanfire.set_volume(0.5); warn.set_volume(0.02)
  1126. hkollidea.set_volume(0.4) ;Heroexp.set_volume(0.5)
  1127. astexplode.set_volume(0.3);bossexplode.set_volume(.5)
  1128. extralife.set_volume(0.2); invince.set_volume(0.02)
  1129.  
  1130. #------------------------------------------------------------------------------#
  1131. #                              load the Graphics                               #
  1132. #------------------------------------------------------------------------------#
  1133.  
  1134. # Enemy types
  1135. alien1=pygame.image.load("resources\grfx\AlienANew.png").convert_alpha()
  1136. alien2=pygame.image.load("resources\grfx\AlienBNew.png").convert_alpha()
  1137. bossA=pygame.image.load("resources\grfx\BossA.png").convert_alpha()
  1138. bossB=pygame.image.load("resources\grfx\FAlien.png").convert_alpha()
  1139. AMSHIP1=pygame.image.load("resources\grfx\mothership1.png").convert_alpha()
  1140. # Bullets and Bombs
  1141. Herobullet=pygame.image.load("resources\grfx\lazerH.png").convert_alpha()
  1142. alienbullet=pygame.image.load("resources\grfx\lazerA.png").convert_alpha()
  1143. Herobomb=pygame.image.load("resources\grfx\item4.png").convert_alpha()
  1144. bossbomb1=pygame.image.load("resources\grfx\BOSBOM.png").convert_alpha()
  1145. # Bomb & Bullet xplosions
  1146. alxplode=pygame.image.load("resources\grfx\explosiondg002.png").convert_alpha()#alien
  1147. al2xplode=pygame.image.load("resources\grfx\AL2EX.png").convert_alpha()#alien
  1148. bsxplode=pygame.image.load("resources\grfx\Boss1explode.png").convert_alpha()#boss
  1149. BAexpld=pygame.image.load("resources\grfx\BaddestAlienexp.png").convert_alpha()#last Alien
  1150. Abltxpld=pygame.image.load("resources\grfx\Abx.png").convert_alpha()#Ablt
  1151. Hbltxpld=pygame.image.load("resources\grfx\Hbx.png").convert_alpha()#Hblt
  1152. HBxpld=pygame.image.load("resources\grfx\explosiondg003.png").convert_alpha()#HBOMB
  1153. BBxpld=pygame.image.load("resources\grfx\explosiondg004.png").convert_alpha()#BOSBOMB
  1154. AMS1EXP=pygame.image.load("resources\grfx\mothershipexp.png").convert_alpha()
  1155. # Different collectibles
  1156. Gglobe=pygame.image.load("resources\grfx\item1.png").convert_alpha()
  1157. Rglobe=pygame.image.load("resources\grfx\item2.png").convert_alpha()
  1158. Oglobe=pygame.image.load("resources\grfx\item3.png").convert_alpha()
  1159. Pglobe=pygame.image.load("resources\grfx\item4.png").convert_alpha()
  1160. clusterbomb=pygame.image.load("resources\grfx\item5.png").convert_alpha()
  1161. Bglobe=pygame.image.load("resources\grfx\item6.png").convert_alpha()
  1162. Mglobe=pygame.image.load("resources\grfx\item7.png").convert_alpha()
  1163. CBombexp=pygame.image.load("resources\grfx\clusterbombex.png").convert_alpha()
  1164. CBombe=pygame.image.load("resources\grfx\item8.png").convert_alpha()
  1165. # Asteroids
  1166. meteor=pygame.image.load("resources\grfx\BIGasters.png").convert_alpha()
  1167. meteor2=pygame.image.load("resources\grfx\SMALLasters.png").convert_alpha()
  1168. meteor3=pygame.image.load("resources\grfx\TINYasters.png").convert_alpha()
  1169. metex1=pygame.image.load("resources\grfx\AEXL.png").convert_alpha()
  1170. metex2=pygame.image.load("resources\grfx\AEXM.png").convert_alpha()
  1171. metex3=pygame.image.load("resources\grfx\AEXS.png").convert_alpha()
  1172.  
  1173. title=pygame.image.load("resources\grfx\SGtitle2.png").convert_alpha()
  1174. prana=pygame.image.load("resources\grfx\HeroTF.png").convert_alpha()
  1175. podiprana=pygame.transform.scale(prana,(25,25))
  1176. life=pygame.transform.rotate(podiprana, 90)
  1177.  
  1178. images=Load_images()
  1179. #------------------------------------------------------------------------------#
  1180. #                          Prepare Game Characters                             #
  1181. #------------------------------------------------------------------------------#
  1182.  
  1183. # image1 image2 speed status size,life,kind,firerate, framesize
  1184. Hbullet=Gun(Herobullet,Hbltxpld,9,"S",9,45,"HB",4,25)# Hero BULLET
  1185. Abullet=Gun(alienbullet,Abltxpld,8.3,"S",9,40,"AB",4,25)# ALIEN BULLET
  1186. HBOMB=Gun(Herobomb,HBxpld,8,"S",25,100,"HM",6,100)# Hero BOMB
  1187. BBOMB=Gun(bossbomb1,BBxpld,7,"S",20,100,"BM",6,50)# BOSS BOMB
  1188. CBOMB=Gun(CBombe,CBombexp,6,"S",20,250,"HM",10,250)# CBOMB
  1189.  
  1190. #1-scale, 2-posx,3-posy,4-status,5-lives,6-bonus\
  1191. #(7-extra life,enemycount,bonus,bombs),8-frrate,-frsize,9-bonus message
  1192. Hero =HeroObject(46,controls.Swidth/2,controls.Sheight/2,"N",6,\
  1193.                  ["one",20,"S",0],[0,"D"],5,64)
  1194. #new attribute created for the clusterbomb in the class Gun
  1195. CBOMB.explode=100 # cluster bomb will explode when this turn 0
  1196.  
  1197. # BOSS1 initialized
  1198. #image,image2(expld),scale,x,y,life,firerate,frame rate,frame size,status
  1199. bosx=-100
  1200. bosy=random.randrange(50,controls.Sheight-100)
  1201. # create boss1 off screen but passive-P
  1202. boss1=EnemyObject(bossA,bsxplode,80,bosx,bosy,100,30,8,400,"P")
  1203. mx=random.randrange(50,100,5)
  1204. Mothership1=EnemyObject(AMSHIP1,AMS1EXP,110,mx,0,100.0,0,10,250,"P")
  1205. Mothership1.heading=90
  1206. Mothership1.speed=2
  1207. controls.musicfader=pygame.mixer.music.get_volume()
  1208. Hero.setHeading(90)
  1209. controls.instructions=True
  1210. player_instructions(intro,10)
  1211.  
  1212. #------------------------------------------------------------------------------#
  1213. #                             MAIN GAME LOOP                                   #
  1214. #------------------------------------------------------------------------------#
  1215.  
  1216.  
  1217. #------------------------------------------------------------------------------#
  1218. #                           LEVEL 1  THE ENERGY GLOBES                         #                                     #
  1219. #------------------------------------------------------------------------------#
  1220. while True:
  1221.     timestamp=time.asctime(time.localtime())[4:]
  1222.  
  1223.     Hero.getrectarea()
  1224.     # reduce the size of the Hero rect by 10 pixels
  1225.     Hero.rectarea=Hero.rectarea.inflate(-10,-10)
  1226.     controls.gamecounter+=1
  1227.     controls.glt_sec=clock.tick(50)/1000.0# time taken to run game loop in seconds
  1228. ##    controls.timegone+=controls.glt_sec
  1229.     constant=controls.gamespeed*controls.glt_sec
  1230.     scorestr= "".join(str(i) for i in score)
  1231.     realscore=int(scorestr)
  1232. #bonus 1000 for every 20 alien ships
  1233.     if controls.enemycount>=Hero.bonus[1]:
  1234.         score[3]+=1
  1235.         Hero.bonus[1]+=20
  1236.         Hero.bonus[2]="M"
  1237. # extra life for every 20000 points up to max 60000 and 3 lives
  1238.     if Hero.bonus[0]=="one" and realscore>=20000:
  1239.         Hero.lives+=1
  1240.         extralife.play()
  1241.         Hero.bonus[0]="two"
  1242.     elif Hero.bonus[0]=="two" and realscore>=40000:
  1243.         Hero.lives+=1
  1244.         extralife.play()
  1245.         Hero.bonus[0]="three"
  1246.     elif Hero.bonus[0]=="three" and realscore>=60000:
  1247.         Hero.lives+=1
  1248.         extralife.play()
  1249.         Hero.bonus[0]="four"
  1250. # short period where Hero has no damage from enemy fire
  1251.     Hero.nodamage-=1
  1252.     if Hero.nodamage<=0:
  1253.         Hero.nodamage=0
  1254.         Hero.shieldcolour=[250,250,250]
  1255. # increase number of Alien1s by one every 750 increase of score
  1256.     if controls.globes<>'Palive' and realscore>750 and\
  1257.        controls.gamestate=="Level 1":
  1258.         controls.no_of_enemies=realscore//750
  1259.     if controls.no_of_enemies>controls.enemy_limit:
  1260.         controls.no_of_enemies=controls.enemy_limit
  1261.  
  1262.     pygame.event.pump()
  1263.     keys = pygame.key.get_pressed()
  1264.     if keys[K_ESCAPE]:
  1265.         really_quit()
  1266.        
  1267.     for event in pygame.event.get():
  1268.         if event.type==KEYDOWN:
  1269.             # PAUSE GAME,high scores and instructions
  1270.             if event.key==K_p:
  1271.                 controls.pause=not controls.pause
  1272.  
  1273.             if event.key==K_t:              # TELEPORT
  1274.                 teleportsound.play()
  1275.                 Hero.status="T"
  1276.  
  1277.             if event.key==K_f and screenmode==0: # toggle fullscreen on/off
  1278.                 screenmode=FULLSCREEN
  1279.                 screen = pygame.display.set_mode((Swidth, Sheight),screenmode,0)
  1280.             elif event.key==K_f and screenmode==FULLSCREEN:
  1281.                 screenmode=0
  1282.                 screen = pygame.display.set_mode((Swidth, Sheight),screenmode,0)
  1283.  
  1284. # bomb count and launch status D-dormant R-ready to launch L-launched
  1285.             if controls.globes=='Palive' and Hero.bombs[0]>0 \
  1286.                and Hero.status!="E"\
  1287.                and Hero.bombs[1]=="D" and event.key==K_b :
  1288.                 Hero.bombs[1]="R" # get bomb ready
  1289.                 Hero.bombs[0]-=1
  1290.                 Hero.BMag.append(copy.copy(HBOMB))
  1291.                 Herofirebomb.play()
  1292.                 Hero.bombs[1]="L"
  1293.                 Hero.BMag[-1].fire(Hero)     # BOMB FIRED
  1294.  
  1295.             if controls.CBomb=='C' and event.key==K_b:
  1296.                 Herofirebomb.play()
  1297.                 for CB in Hero.CBMag:
  1298.                     # Cluster Bombs FIRED
  1299.                     controls.CBangle+=1
  1300.                     CB.fireBombCluster(Hero,\
  1301.                                        ( controls.CBangle*36),\
  1302.                                        ( controls.CBangle*36))
  1303.                     CB.status='CF'
  1304.                     controls.CBomb="F"
  1305.  
  1306.     if Hero.status=="T":
  1307.         Hero.teleport()
  1308.         Hero.life-=1
  1309.     # MOVE THE Hero
  1310.     if keys[K_LEFT]:
  1311.         Hero.setHeading(Hero.heading+4)
  1312.     if keys[K_RIGHT]:
  1313.         Hero.setHeading(Hero.heading-4)
  1314.     if keys[K_UP]: # accellerate!
  1315.         Herothrustch.play(Heromove)
  1316.         Hero.engines=True
  1317.         Hero.speedx+=Hero.thrust*math.cos(math.radians(Hero.heading))*constant
  1318.         Hero.speedy+=Hero.thrust*math.sin(math.radians(Hero.heading))*constant
  1319.         if Hero.speedx>=Hero.speedlimit: Hero.speedx=Hero.speedlimit
  1320.         if Hero.speedx<=-Hero.speedlimit: Hero.speedx=-Hero.speedlimit
  1321.         if Hero.speedy>=Hero.speedlimit: Hero.speedy=Hero.speedlimit
  1322.         if Hero.speedy<=-Hero.speedlimit: Hero.speedy=-Hero.speedlimit
  1323.     else:
  1324.         Heromove.stop()
  1325.         Hero.engines=False
  1326.         Hero.speedx-=0
  1327.         Hero.speedy-=0
  1328.     if keys[K_DOWN]: #brakes! :-)
  1329.         Hero.speedx*=0.97
  1330.         Hero.speedy*=0.97
  1331.  
  1332.     if Hero.life>0:
  1333.         Hero.move(Hero.speedx, Hero.speedy)
  1334.         Hero.life+=.04 # slow buildup of shield
  1335.     if Hero.life>=450:
  1336.         Hero.life=450
  1337.     if Hero.life<=0 and Hero.status=="N":
  1338.         Hero.life=0
  1339.         Heroexp.play()
  1340.         Hero.status="E"
  1341.     if Hero.status=="E":
  1342.         Hero.explode()
  1343.         for e in controls.Alien1: # when Hero explode enemy moves away
  1344.             e.follow(e,4)
  1345.             e.firerate=30
  1346.             e.update()
  1347.     if Hero.status=="S":
  1348.         Hero.reinit-=1
  1349.     if Hero.life<40 and Hero.life>0: # warn that shield is low
  1350.         warn.play()
  1351.     if Hero.reinit<=0:
  1352.         Hero.lives-=1
  1353.     # Hero IS RE-SPAWNED
  1354.         tempHerobombs=Hero.bombs
  1355.         tempHeroCBMag=Hero.CBMag
  1356.         Hero =HeroObject(45,controls.Swidth/2,\
  1357.                          controls.Sheight/2,"N",Hero.lives,\
  1358.                          Hero.bonus,Hero.bombs, Hero.frrate, Hero.frsize)
  1359.         Hero.setHeading(90)
  1360.         Hero.CBMag=tempHeroCBMag
  1361.         Hero.bombs=tempHerobombs
  1362.         for e in controls.Alien1:
  1363.             e.firerate=30
  1364.         if controls.globes=='Palive':
  1365.             boss1.firerate=30
  1366. # draw the Hero ship shield
  1367.     if Hero.nodamage>0:
  1368.         pygame.draw.circle(screen, (Hero.shieldcolour[2]*random.random(),\
  1369.                                     Hero.shieldcolour[1]*random.random(),\
  1370.                                     Hero.shieldcolour[0]*random.random()), \
  1371.                            (int(Hero.x),int(controls.Sheight-Hero.y)),Hero.\
  1372.                            shieldradius, 0)
  1373.         Hero.shieldcolour[0]-=1
  1374.         for x in xrange(2):
  1375.             if Hero.shieldcolour[x]<=0:
  1376.                 Hero.shieldcolour[x]=0
  1377.                 Hero.shieldcolour[x+1]-=1
  1378.         if Hero.shieldcolour[2]<=0:
  1379.             Hero.shieldcolour[2]=0
  1380.         Hero.shieldradius+=1
  1381.         if Hero.shieldradius>28:
  1382.             Hero.shieldradius=18
  1383.  
  1384. # HERO SHOOT
  1385.     if keys[K_SPACE] and Hero.guntemp<=74 and Hero.status=="N":
  1386.         Hero.firerate-=1 # fire the gun
  1387.         if Hero.firerate<=0 and controls.TRIPLEguntime<=0:
  1388.             Hero.CMag.append(copy.copy(Hbullet))
  1389.             Herofirech.play(Herofire)
  1390.             Hero.guntemp+=0.4 # GUN TEMPERATURE increases
  1391.             colourvals[1]-=10 # GUN TEMP. COLOUR changes
  1392.             if colourvals[1]<1:
  1393.                 colourvals[1]=1
  1394.             Hero.CMag[-1].fire(Hero)
  1395.             Hero.firerate=Hero.maxfirerate
  1396. # IF HERO CATCHES TRIPLE GUN BOOSTER PORT AND STARBOARD GUNS ACTIVATE
  1397.         elif Hero.firerate<=0 and controls.TRIPLEguntime>0:
  1398.             Hero.firerate=Hero.maxfirerate
  1399.             Hero.CMag.append(copy.copy(Hbullet))
  1400.             Hero.LMag.append(copy.copy(Hbullet))
  1401.             Hero.RMag.append(copy.copy(Hbullet))
  1402.             Herofirech.play(Herofire)
  1403.             Herofirech.play(Herofire2)
  1404.             Herofirech.play(Herofire)
  1405.             Hero.guntemp+=0.3 # GUN TEMPERATURE increases
  1406.             colourvals[1]-=20 # GUN TEMP. COLOUR changes
  1407.             if colourvals[1]<1:
  1408.                 colourvals[1]=1
  1409.             Hero.CMag[-1].fire(Hero)
  1410.             Hero.LMag[-1].fireL(Hero)
  1411.             Hero.RMag[-1].fireR(Hero)
  1412.             controls.TRIPLEguntime-=1
  1413.             if controls.TRIPLEguntime==0:
  1414.                 controls.TRIPLEguntime=0
  1415. # HERO GUN COOLS WHEN NOT FIRING
  1416.     if not keys[K_SPACE]:
  1417.         Hero.guntemp-=.2
  1418.         if Hero.guntemp<0:
  1419.             Hero.guntemp=0
  1420.         colourvals[1]+=5
  1421.         if colourvals[1]>100:
  1422.             colourvals[1]=100
  1423. #------------------------------------------------------------------------------#
  1424. #                               THE ASTEROIDS                                  #
  1425. #------------------------------------------------------------------------------#
  1426.     #image,image2,x,y,life,width,xfr,frsize,noframes.
  1427.     #...status(L-Large, M-Medium, S=Small),
  1428.     #status-M-moving, E-explode, D-destroyed
  1429.     if controls.asteroidswitch=="ON":
  1430.         if len(asteroids)<controls.asteroidlimit and \
  1431.            controls.asteroidcount<=controls.asteroidamount:
  1432.             x,y,h=Asteroid_spawn()
  1433.             asteroid=Asteroids(meteor,metex1,x,y,5,1024,8,128,60,"L","M")
  1434.             asteroid.heading=h
  1435.             asteroids.append(asteroid)
  1436. #------------------------------------------------------------------------------#
  1437. #                                   THE POWERUPS                               #
  1438. #------------------------------------------------------------------------------#
  1439.  
  1440. #THE INVINCIBILITY POWERUP
  1441.     if realscore>15000 and Hero.nodamage<=0 and controls.invincibility==False:
  1442.         controls.PUcount[0]+=1
  1443.     if controls.PUcount[0]%500==0 and controls.invincibility==False:
  1444.         controls.PUcount[0]+=1
  1445.         controls.invincibility=True
  1446.         # image,x,y,scale,no of items spawned
  1447.         invincibility=Collectibles(Bglobe,controls.Swidth*random.random(),\
  1448.                            controls.Sheight*random.random(),35,1)
  1449.         invincibility.speed=0.7
  1450.         invincibility.life=500
  1451.     if controls.invincibility==True and invincibility.life<=0:
  1452.         controls.invincibility=False
  1453.         controls.PUcount[0]=1 # reset the invincibilty counter
  1454.  
  1455. # THE TRIPLE GUN POWERUP
  1456.     if controls.TRIPLEgun==False and controls.gamestate<>"Level 1" \
  1457.        and controls.gamestate<>"Level 2":
  1458.         controls.PUcount[1]+=1
  1459.     if controls.PUcount[1]%750==0 and controls.TRIPLEgun==False:
  1460.         controls.PUcount[1]+=1
  1461.         controls.TRIPLEgun=True
  1462.         # image,x,y,scale,no of items spawned
  1463.         TRIPLEgun=Collectibles(Mglobe,controls.Swidth*random.random(),\
  1464.                            controls.Sheight*random.random(),45,1)
  1465.         TRIPLEgun.speed=0.7
  1466.         TRIPLEgun.life=500
  1467.     if controls.TRIPLEgun==True and TRIPLEgun.life<=0:
  1468.         controls.TRIPLEgun=False
  1469.         controls.PUcount[1]=1 # reset the TRIPLEgun counter
  1470.  
  1471. # THE CBOMB (Cluster Bomb) GENERATOR
  1472.     if controls.gamestate!='Level 2' and realscore>=25000\
  1473.        and controls.CBomb==False:
  1474.         controls.PUcount[2]+=1
  1475.     if controls.PUcount[2]%1000==0 and controls.CBomb==False:
  1476.         controls.PUcount[2]+=1
  1477.         controls.CBomb=True
  1478.         # image,x,y,scale,no of items spawned
  1479.         CBombpup=Collectibles(clusterbomb,controls.Swidth*random.random(),\
  1480.                            controls.Sheight*random.random(),50,1)
  1481.         CBombpup.speed=0.7
  1482.         CBombpup.life=300
  1483.     '''if CBomb NOT caught while alive reset flags to launch again'''
  1484. #------------------------------------------------------------------------------#
  1485. #                             THE COLLECTIBLES                                 #
  1486. #------------------------------------------------------------------------------#
  1487.     if controls.globes=='Green':
  1488.         # call function with globe image and speed
  1489.         spawn_globes(Gglobe, 0.3,10,controls.globequantity[0])
  1490.         controls.globes='Galive'
  1491.  
  1492.     if controls.globes=='Galive' and \
  1493.        controls.collected==controls.globequantity[0]:
  1494.         controls.collected=0
  1495.         controls.globes='Red'
  1496.  
  1497.     if controls.globes=='Red':
  1498.         controls.globelist=[]
  1499.         spawn_globes(Rglobe, 0.4,15,controls.globequantity[1])
  1500.         controls.collected=0
  1501.         controls.globes='Ralive'
  1502.  
  1503.     if controls.globes=='Ralive' and \
  1504.        controls.collected==controls.globequantity[1]:
  1505.         controls.collected=0
  1506.         controls.globes='Orange'
  1507.  
  1508.     if controls.globes=='Orange':
  1509.         if controls.asteroidswitch=="OFF":
  1510.             controls.asteroidswitch="ON" # bring on asteroids 1st time level 1
  1511.         controls.globelist=[]
  1512.         spawn_globes(Oglobe, 0.5,20,controls.globequantity[2])
  1513.         controls.collected=0
  1514.         controls.globes='Oalive'
  1515.  
  1516.     if controls.globes=='Oalive' and \
  1517.        controls.collected==controls.globequantity[2]:
  1518.         controls.collected=0
  1519.         controls.globes='Purple'
  1520.  
  1521.     if controls.globes=='Purple':
  1522.         controls.globelist=[]
  1523.         spawn_globes(Pglobe, 0.6,25,controls.globequantity[3])
  1524.         controls.collected=0
  1525.         controls.globes='Palive'
  1526. #------------------------------------------------------------------------------#
  1527. #                            THE 1ST. ALIEN WAVE                               #
  1528. #------------------------------------------------------------------------------#
  1529.  
  1530.     #image,image2(expld),scale,x,y,life,firerate,frame rate,frame size,status
  1531.     if len(controls.Alien1)<controls.no_of_enemies \
  1532.        and controls.gamecounter%300==0 and controls.globes!='Palive' \
  1533.        and controls.gamestate=='Level 1':
  1534.         x,y,h=random_xyheading()
  1535.         badET=EnemyObject(alien1,alxplode,35,30+x,y,30,30,6,100,"M")
  1536.         badET.heading=h
  1537.         badET.radar=220
  1538.         controls.Alien1.append(badET)
  1539.     if len(controls.Alien1)>0 and controls.music=='theme':
  1540.         pygame.mixer.music.load(alien1music)
  1541.         pygame.mixer.music.set_volume(0.3)
  1542.         pygame.mixer.music.play(-1)
  1543.         controls.music='level1alien1'
  1544.  
  1545.  
  1546. #------------------------------------------------------------------------------#
  1547. #                      L E V E L  2 THE ALIEN OVERLORD                         #
  1548. #------------------------------------------------------------------------------#
  1549.  
  1550.     if controls.globes=='Palive' and controls.enemystate=="boss off"\
  1551.        and controls.gamestate=='Level 1':
  1552.         boss1.radar=controls.Swidth/2-100
  1553.         boss1.mag=40 # shooting delay
  1554.         controls.enemystate="boss on"
  1555.         boss1.status='M'
  1556.         controls.gamestate="Level 2"
  1557.     if controls.enemystate=='boss on' and controls.music<>'boss music':
  1558.         pygame.mixer.music.load(boss1music)
  1559.         pygame.mixer.music.set_volume(0.3)
  1560.         pygame.mixer.music.play(-1)
  1561.         controls.music='boss music'
  1562.  
  1563.     if controls.enemystate=='boss on' and boss1.status<>"E":
  1564.         boss1.getrectarea()
  1565.         # make the boss rect 20 pixels smaller
  1566.         boss1.rectarea=boss1.rectarea.inflate(-20,-20)
  1567. ##        pygame.draw.rect(screen, (0,255,0), boss1.rectarea,2)
  1568.         boss1.firerate-=1
  1569.         if boss1.firerate==0 and Hero.life>0:
  1570.             controls.BossBombMag.append(copy.copy(BBOMB))
  1571.             # fire only if Hero  gets closer tham this
  1572.             if abs(Hero.x-boss1.x)<boss1.radar and\
  1573.                abs(Hero.y-boss1.y)<boss1.radar:
  1574.                 controls.BossBombMag[-1].fire(boss1)
  1575.                 bosschannel.play(bosscanfire)
  1576.             boss1.firerate=30# slow down the alien fire rate
  1577.         boss1.mag-=1
  1578.         if boss1.life>0:
  1579.             boss1.life+=0.01 # self healing ability of boss
  1580.         if boss1.life>=100:
  1581.             boss1.life=100
  1582.         if boss1.mag<=-50:
  1583.             boss1.mag=10
  1584.         if boss1.life<=0:
  1585.             boss1.life=0
  1586.             boss1.status="E"
  1587.             bosschannel.play(bossexplode)
  1588.             score[3]+=5
  1589.     if boss1.status=="E":
  1590.         boss1.explode()
  1591.  
  1592.     if boss1.status=='D' and controls.spendtime<=100:
  1593.         controls.spendtime+=1
  1594.         controls.enemystate='REST'
  1595.  
  1596.     if boss1.status=='D' and controls.spendtime>=100:
  1597.         controls.gamestate="Level 3"
  1598.         controls.asteroidswitch="OFF" # no asteroids in level 3
  1599.         controls.globes='OFF'
  1600.         Mothership1.status="M"
  1601.         controls.globelist=[]
  1602.         Hero.BMag=[]
  1603.         Hero.bombs=[0,"D"]
  1604.         controls.counter=0
  1605.         controls.no_of_enemies=12 # second round of aliens
  1606.         controls.spendtime=0
  1607.         boss1.status='boss1 dest'
  1608.         player_instructions(level3,8) # describe level 3 to player
  1609.  
  1610. #------------------------------------------------------------------------------#
  1611. #                         L E V E L  3 THE MOTHERSHIP                          #                              #
  1612. #------------------------------------------------------------------------------#
  1613. # MSA-Mother Ship Active   MLA2- Mothership Launch Alien2
  1614.  
  1615. #                                ALIEN WAVE 2                                  #
  1616.     if controls.enemystate=='REST' and controls.counter <25:
  1617.         controls.counter+=1 # rest a while
  1618.  
  1619.     if controls.enemystate=='REST' and controls.counter >=25:
  1620.         controls.counter=0
  1621.         controls.enemystate='MLA2'
  1622.  
  1623.     if controls.enemystate=='MLA2' and Mothership1.status=="M":
  1624.         Mothership1.getrectarea()
  1625.         Mothership1.heading-=5
  1626.         Mothership1.y+=1
  1627.         controls.counter+=1
  1628. #------------------------------------------------------------------------------#
  1629. #                      L E V E L  3 THE 2nd.ALIEN WAVE                         #                              #
  1630. #------------------------------------------------------------------------------#
  1631.  
  1632.         if controls.counter>=25:
  1633.             if len(controls.Alien2)<controls.no_of_enemies: # 10 alien2's
  1634. ##image,image2(expld),scale,x,y,life,firerate,frame rate,frame size,status
  1635.                 anotherbadET=EnemyObject(alien2,al2xplode,44,Mothership1.x,\
  1636.                                   Mothership1.y,32,25,6,100,"M")
  1637.                 anotherbadET.heading=random.randrange(0,360,10)
  1638.                 anotherbadET.radar=280
  1639.                 controls.Alien2.append(anotherbadET)
  1640.             controls.counter=0
  1641.  
  1642.     if Mothership1.y>=controls.Sheight+Mothership1.scale and\
  1643.        Mothership1.status<>"D" and len(controls.Alien2)<=controls.no_of_enemies:
  1644.         mx=random.randrange(75,controls.Swidth-75,10)
  1645.         Mothership1=EnemyObject(AMSHIP1,AMS1EXP,110,mx,0,Mothership1.life,\
  1646.                                 0,10,250,"M")
  1647.         Mothership1.speed=2
  1648.         controls.enemystate=='MSA'
  1649.     if len(controls.Alien2)<=5 and controls.enemystate=='MSA' \
  1650.        and Mothership1.status=="M":
  1651.         controls.enemystate='MLA2'
  1652.  
  1653.     if len(controls.Alien2)>0 and controls.music=='boss music':
  1654.         pygame.mixer.music.load(alien2music)
  1655.         pygame.mixer.music.set_volume(0.3)
  1656.         pygame.mixer.music.play(-1)
  1657.         controls.music='level2alien2'
  1658.  
  1659.     if Mothership1.life<=0 and Mothership1.status=="M":
  1660.         Mothership1.life=0
  1661.         Mothership1.status="E"
  1662.         score[3]+=5
  1663.     if Mothership1.status=="E":
  1664.         Mothership1.explode()
  1665.  
  1666.     if Mothership1.status=="D":
  1667.         Mothership1.status="DESTROYED"
  1668.         Mothership1.x=-4000
  1669.         Mothership1.y=-4000
  1670.  
  1671.     if Mothership1.status=="DESTROYED" and \
  1672.        len(controls.Alien2)==0 and controls.gamestate=="Level 3":
  1673.         controls.spendtime+=1
  1674.  
  1675.     if Mothership1.status=="DESTROYED" and controls.spendtime>=200:
  1676.         controls.enemystate="REST 2"
  1677.         controls.asteroidswitch="ON" # bring on more asteroids for level 3
  1678.         controls.asteroidcount=0 # respawn asteroids for this level with more
  1679.         controls.asteroidlimit=6 # should be 6
  1680.         controls.asteroidamount=100 # level 3 - double the amount of asteroids
  1681.         controls.gamestate="Level 4"
  1682.         controls.spendtime=0
  1683.         player_instructions(level4,7) # describe level 4 to player
  1684.  
  1685. #------------------------------------------------------------------------------#
  1686. #                           L E V E L  4 THE FINAL BATTLE                      #
  1687. #------------------------------------------------------------------------------#
  1688. # the asteroids are activated again and the FinalAien crafts are deployed
  1689.  
  1690.     if controls.gamestate=="Level 4" and controls.enemystate=="REST 2":
  1691.         for a in xrange(controls.FAamount): # 6 Final Aliens
  1692.             x,y,h=random_xyheading()
  1693.     #image,image2(expld),scale,x,y,life,firerate,frame rate,frame size,status
  1694.             BaddestET=EnemyObject(bossB,BAexpld,50,30+x,y,50,30,8,400,"M")
  1695.             BaddestET.heading=h
  1696.             BaddestET.radar=controls.Sheight/2
  1697.             controls.FinalAliens.append(BaddestET)
  1698.         controls.enemystate="FINAL BATTLE"
  1699.         controls.enemycount=0
  1700.  
  1701. #------------------------------------------------------------------------------#
  1702. #                           Fire the Alien Guns                                #
  1703. #------------------------------------------------------------------------------#
  1704.  
  1705.     for e in controls.Alien1:
  1706.         e.firerate-=1
  1707.         if e.firerate<=0 and Hero.life>0 and e.state=="normal":
  1708.             controls.AlienMag.append(copy.copy(Abullet))
  1709.             # fire only if Hero gets closer than this
  1710.             if abs(Hero.x-e.x)<e.radar and abs(Hero.y-e.y)<e.radar:
  1711.                 controls.AlienMag[-1].fire(e)
  1712.                 alienshoot.play()
  1713.             e.firerate=8# slow down the alien fire rate
  1714.  
  1715.     for e in controls.Alien2:
  1716.         e.firerate-=1
  1717.         if e.firerate<=0 and Hero.life>0 and e.state=="normal":
  1718.             controls.Alien2Mag.append(copy.copy(Abullet))
  1719.             if abs(Hero.x-e.x)<e.radar and abs(Hero.y-e.y)<e.radar:
  1720.                 controls.Alien2Mag[-1].fire(e)
  1721.                 alienshoot.play()
  1722.             e.firerate=7
  1723.  
  1724.     for e in controls.FinalAliens:
  1725.         e.firerate-=1
  1726.         if e.firerate<=0 and Hero.life>0 and e.state=="normal":
  1727.             controls.Alien2Mag.append(copy.copy(Abullet))
  1728.             if abs(Hero.x-e.x)<e.radar and abs(Hero.y-e.y)<e.radar:
  1729.                 controls.Alien2Mag[-1].fire(e)
  1730.                 alienshoot.play()
  1731.             e.firerate=7
  1732.  
  1733. #-----------------------------------------------------------------------------#
  1734. #                                 COLLISIONS                                  #
  1735. #-----------------------------------------------------------------------------#
  1736.     alien1INF_rects=[]
  1737.     alien1DEF_rects=[]
  1738.     alien2INF_rects=[]
  1739.     alien2DEF_rects=[]
  1740.     FalienINF_rects=[]
  1741.     FalienDEF_rects=[]
  1742.     globe_rects=[]
  1743.     asteroids_rects=[]
  1744.     asterINF_rects=[]
  1745.     font = pygame.font.Font("resources\data\prometheanb.ttf", 10)
  1746. #------------------------------------------------------------------------------#
  1747. #                       HERO COLLIDE WITH ALIEN SHIPS                          #
  1748. #------------------------------------------------------------------------------#
  1749.  
  1750. #------------------------------------------------------------------------------#
  1751. #                             THE 1ST. ALIEN WAVE                              #
  1752. #------------------------------------------------------------------------------#
  1753.  
  1754.     for e in controls.Alien1: # 1st WAVE of ALIENS
  1755.         e.getrectarea()
  1756.         """get DEFLATED rects as enemy surface is not a perfect square and the
  1757.        sprite rect will be large"""
  1758.         DEFrect=e.rectarea.inflate(-e.safearea, -e.safearea)
  1759.         alien1DEF_rects.append(DEFrect)
  1760.         """ get INFLATED rect list for same type collisions (STC)"""
  1761.         INFrect=e.rectarea.inflate(e.safearea,e.safearea)
  1762.         alien1INF_rects.append(INFrect)
  1763. ##        pygame.draw.rect(screen, (255,0,255), INFrect,2) # draw INFLATED rect
  1764.         Alcollide=Hero.rectarea.collidelist(alien1DEF_rects)
  1765.         if not Alcollide==-1 and Hero.nodamage<=0 and\
  1766.            Hero.life>0:
  1767.             Hero.life-=.4
  1768.             hkollidea.play()
  1769.         else:
  1770.             hkollidea.stop()
  1771.         if not Alcollide==-1 and Hero.nodamage>0:
  1772.             controls.Alien1[Alcollide].life-=1
  1773.  
  1774. #------------------------------------------------------------------------------#
  1775. #                       ALIEN1 colliding with each other                       #
  1776. #------------------------------------------------------------------------------#
  1777.     for i, e in enumerate(alien1INF_rects):
  1778.         A1INFlist=e.collidelistall(alien1INF_rects)
  1779.         for j in A1INFlist:
  1780.             if j==i:
  1781.                 continue # this prevents self collision
  1782.             dx=controls.Alien1[i].centerx-controls.Alien1[j].centerx
  1783.             dy=controls.Alien1[i].centery-controls.Alien1[j].centery
  1784.             distance=math.hypot(dx,dy)
  1785.             heading=.5*math.pi+(math.atan2(dy,dx))
  1786.             if distance<=controls.Alien1[j].safearea+\
  1787.                controls.Alien1[i].safearea:
  1788.                 controls.Alien1[i].heading+=2
  1789.                 controls.Alien1[i].x-=math.sin(heading)
  1790.                 controls.Alien1[i].y+=math.cos(heading)
  1791.                 controls.Alien1[j].heading-=2
  1792.                 controls.Alien1[j].x+=math.sin(heading)
  1793.                 controls.Alien1[j].y-=math.cos(heading)
  1794.             if distance<=controls.Alien1[j].scale/2+controls.Alien1[i].scale/2:
  1795.                 controls.Alien1[i].x-=1
  1796.                 controls.Alien1[j].x-=1
  1797.  
  1798. #------------------------------------------------------------------------------#
  1799. #                             THE 2ND. ALIEN WAVE                              #
  1800. #------------------------------------------------------------------------------#
  1801.  
  1802.     for e in controls.Alien2: # 2nd WAVE of ALIENS
  1803.         e.getrectarea()
  1804.         DEFrect=e.rectarea.inflate(-e.safearea, -e.safearea)
  1805.         alien2DEF_rects.append(DEFrect)
  1806.         INFrect=e.rectarea.inflate(e.safearea,e.safearea)
  1807.         alien2INF_rects.append(INFrect)
  1808.         Al2collide=Hero.rectarea.collidelist(alien2DEF_rects)
  1809.         if not Al2collide==-1 and Hero.nodamage<=0 and\
  1810.            Hero.life>0:
  1811.             Hero.life-=.2
  1812.             hkollidea.play()
  1813.         else:
  1814.             hkollidea.stop()
  1815.         if not Al2collide==-1 and Hero.nodamage>0:
  1816.             controls.Alien2[Al2collide].life-=1
  1817.  
  1818. #------------------------------------------------------------------------------#
  1819. #                       ALIEN2 colliding with each other                       #
  1820. #------------------------------------------------------------------------------#
  1821.  
  1822.     for i, e in enumerate(alien2INF_rects):
  1823.         A2INFlist=e.collidelistall(alien2INF_rects)
  1824.         for j in A2INFlist:
  1825.             if j==i:
  1826.                 continue
  1827.             dx=controls.Alien2[i].centerx-controls.Alien2[j].centerx
  1828.             dy=controls.Alien2[i].centery-controls.Alien2[j].centery
  1829.             distance=math.hypot(dx,dy)
  1830.             heading=.5*math.pi+(math.atan2(dy,dx))
  1831.             if distance<=controls.Alien2[j].safearea+controls.Alien2[i].safearea:
  1832.                 controls.Alien2[i].heading+=2
  1833.                 controls.Alien2[i].x-=math.sin(heading)
  1834.                 controls.Alien2[i].y+=math.cos(heading)
  1835.                 controls.Alien2[j].heading-=2
  1836.                 controls.Alien2[j].x+=math.sin(heading)
  1837.                 controls.Alien2[j].y-=math.cos(heading)
  1838.             if distance<=controls.Alien2[j].scale/2+controls.Alien2[i].scale/2:
  1839.                 controls.Alien2[i].x-=1
  1840.                 controls.Alien2[j].x-=1
  1841.  
  1842. #------------------------------------------------------------------------------#
  1843. #                              THE FINAL ALIENS                                #
  1844. #------------------------------------------------------------------------------#
  1845.  
  1846.     for e in controls.FinalAliens: # final WAVE of ALIENS
  1847.         e.getrectarea()
  1848.         DEFrect=e.rectarea.inflate(-e.safearea,-e.safearea)
  1849.         FalienDEF_rects.append(e.rectarea)
  1850.         INFrect=e.rectarea.inflate(e.safearea,e.safearea)
  1851.         FalienINF_rects.append(INFrect)
  1852.         Al2collide=Hero.rectarea.collidelist(FalienDEF_rects)
  1853.  
  1854.         if not Al2collide==-1 and Hero.nodamage<=0 and\
  1855.            Hero.life>0:
  1856.             Hero.life-=.5
  1857.             hkollidea.play()
  1858.         else:
  1859.             hkollidea.stop()
  1860.  
  1861. # Final Aliens not effected by Hero shield
  1862.  
  1863. #------------------------------------------------------------------------------#
  1864. #                      FinalAliens colliding with each other                       #
  1865. #------------------------------------------------------------------------------#
  1866.  
  1867.     for i, e in enumerate(FalienINF_rects):
  1868.         FAINFlist=e.collidelistall(FalienINF_rects)
  1869.         for j in FAINFlist:
  1870.             if j==i:
  1871.                 continue
  1872.             dx=controls.FinalAliens[i].centerx-controls.FinalAliens[j].centerx
  1873.             dy=controls.FinalAliens[i].centery-controls.FinalAliens[j].centery
  1874.             distance=math.hypot(dx,dy)
  1875.             heading=.5*math.pi+(math.atan2(dy,dx))
  1876.             if distance<=controls.FinalAliens[j].safearea+\
  1877.                controls.FinalAliens[i].safearea:
  1878.                 controls.FinalAliens[i].heading+=2
  1879.                 controls.FinalAliens[i].x-=math.sin(heading)
  1880.                 controls.FinalAliens[i].y+=math.cos(heading)
  1881.                 controls.FinalAliens[j].heading-=2
  1882.                 controls.FinalAliens[j].x+=math.sin(heading)
  1883.                 controls.FinalAliens[j].y-=math.cos(heading)
  1884.             if distance<=controls.FinalAliens[j].scale/2+\
  1885.                controls.FinalAliens[i].scale/2:
  1886. # if two Final Aliens collide with eachother, teleport one elsewhere
  1887.                 controls.FinalAliens[i].x=random.randrange\
  1888.                                            (10,controls.Swidth-100)
  1889.                 controls.FinalAliens[i].y=random.randrange\
  1890.                                            (10,controls.Sheight-100)
  1891.  
  1892.     if Hero.rectarea.colliderect(boss1.rectarea):
  1893.         Hero.life-=6
  1894.  
  1895. #------------------------------------------------------------------------------#
  1896. #                    ASTEROIDS COLLIDE WITH ALIENS AND HERO                    #
  1897. #------------------------------------------------------------------------------#
  1898.     for a in asteroids:
  1899.         if a.status=="M":
  1900.             a.getrectarea()
  1901.             asteroids_rects.append(a.rectarea)
  1902.             INFrect=a.rectarea.inflate(5,5)
  1903.             asterINF_rects.append(INFrect)
  1904.             Ascollide=Hero.rectarea.collidelist(asteroids_rects)
  1905.  
  1906.             if not Ascollide==-1 and Hero.nodamage<=0 \
  1907.                and Hero.life>0 and a.life>0:
  1908. # find which type of asteroid hit the Hero and reduce life accordingly
  1909.                 if asteroids[Ascollide].kind=="L":
  1910.                     Hero.life-=20
  1911.                 elif asteroids[Ascollide].kind=="M":
  1912.                     Hero.life-=10
  1913.                 else:
  1914.                     Hero.life-=5
  1915.  
  1916.             if not Ascollide==-1 and Hero.nodamage>0 and a.life>0:
  1917.                 asteroids[Ascollide].life=0
  1918.             Alcollisions=a.rectarea.collidelist(alien1DEF_rects)
  1919.             Al2collisions=a.rectarea.collidelist(alien2DEF_rects)
  1920.  
  1921.             if not Alcollisions==-1:
  1922.                 controls.Alien1[Alcollisions].life-=.2
  1923.                 if controls.Alien1[Alcollisions].life<=0:
  1924.                     controls.Alien1[Alcollisions].life=0
  1925.  
  1926.             if not Al2collisions==-1:
  1927.                 controls.Alien2[Al2collisions].life-=.2
  1928.                 if controls.Alien2[Al2collisions].life<=0:
  1929.                     controls.Alien2[Al2collisions].life=0
  1930.  
  1931. #------------------------------------------------------------------------------#
  1932. #                      Asteroids collide with each other                       #
  1933. #------------------------------------------------------------------------------#
  1934.  
  1935.     for i, a in enumerate(asterINF_rects):
  1936.         if asteroids[i].status=="M":
  1937.             asterbumplist=a.collidelistall(asterINF_rects)
  1938.             for j in asterbumplist:
  1939.                 if j==i:
  1940.                     continue
  1941. ##               if asteroids[j].rectarea.colliderect(asteroids[i].rectarea):
  1942.                 dx=asteroids[i].centerx-asteroids[j].centerx
  1943.                 dy=asteroids[i].centery-asteroids[j].centery
  1944.                 distance=math.hypot(dx,dy)
  1945. ##                if distance<=asteroids[j].scale+asteroids[i].scale:
  1946.                 angle=0.5*math.pi+(math.atan2(dy,dx))
  1947.                 asteroids[i].heading=(angle-asteroids[i].heading)%360
  1948.                 asteroids[j].heading-=(angle-asteroids[j].heading)%360
  1949.                 asteroids[i].life-=0.01
  1950.  
  1951. #------------------------------------------------------------------------------#
  1952. #                           A L L  E N E M Y  G U N S                          #
  1953. #------------------------------------------------------------------------------#
  1954.  
  1955. # AB-alien bullet HB-Hero bullet HM=Hero missile BM=boss missile
  1956.     for b in controls.AlienMag:
  1957.         b.update()
  1958.         b.getrectarea()
  1959.  
  1960.         if b.rectarea.colliderect(Hero.rectarea)and Hero.nodamage<=0 \
  1961.            and b.kind=="AB" and b.status=="F":
  1962.             Hero.life-=4
  1963.             b.status="E"
  1964.  
  1965.         if b.status=="D":
  1966.             try:
  1967.                 controls.AlienMag.remove(b) #REMOVE SPENT HBULLET
  1968.             except:
  1969.                 pass
  1970.  
  1971.     for b in controls.Alien2Mag:
  1972.         b.update()
  1973.         b.getrectarea()
  1974.  
  1975.         if b.rectarea.colliderect(Hero.rectarea)and Hero.nodamage<=0 \
  1976.            and b.kind=="AB" and b.status=="F":
  1977.             Hero.life-=2
  1978.             b.status="E"
  1979.  
  1980.         if b.status=="D":
  1981.             try:
  1982.                 controls.Alien2Mag.remove(b) #REMOVE SPENT HBULLET
  1983.             except:
  1984.                 pass
  1985.  
  1986.     for b in controls.Alien3Mag:
  1987.         b.update()
  1988.         b.getrectarea()
  1989.  
  1990.         if b.rectarea.colliderect(Hero.rectarea)and Hero.nodamage<=0 \
  1991.            and b.kind=="AB" and b.status=="F":
  1992.             Hero.life-=5
  1993.             b.status="E"
  1994.  
  1995.         if b.status=="D":
  1996.             try:
  1997.                 controls.Alien3Mag.remove(b) #REMOVE SPENT HBULLET
  1998.             except:
  1999.                 pass
  2000.  
  2001.     for b in controls.BossBombMag:
  2002.         b.update()
  2003.         b.getrectarea()
  2004.  
  2005.         if b.rectarea.colliderect(Hero.rectarea)and Hero.nodamage<=0 \
  2006.              and Hero.life>0 and b.kind=="BM" and b.status=='F':
  2007.             b.status="E"
  2008.             Hero.life-=20
  2009.  
  2010.         if b.status=="D":
  2011.             try:
  2012.                 controls.AlienMag.remove(b) #REMOVE SPENT HBULLET
  2013.             except:
  2014.                 pass
  2015.  
  2016. #------------------------------------------------------------------------------#
  2017. #                             COLLECT ALL POWERUPS                             #
  2018. #------------------------------------------------------------------------------#
  2019.  
  2020. #INVINCIBILITY POWERUP
  2021.     if controls.invincibility==True and invincibility.life>0:
  2022.         invincibility.life-=1
  2023.         invincibility.update()
  2024.         invincibility.getrectarea()
  2025. ##        pygame.draw.rect(screen, (0,255,0), invincibility.rectarea,2)
  2026.  
  2027.         if invincibility.rectarea.colliderect(Hero.rectarea):
  2028.             collectch.play(invince)
  2029.             invincibility.life=0 # type and life
  2030.             controls.PUcount[0]=0
  2031.             score[4]+=5
  2032.             Hero.nodamage=500
  2033.  
  2034. #TRIPLEGUN POWERUP
  2035.     if controls.TRIPLEgun==True and TRIPLEgun.life>0:
  2036.         TRIPLEgun.life-=1
  2037.         TRIPLEgun.update()
  2038.         TRIPLEgun.getrectarea()
  2039.  
  2040.         if TRIPLEgun.rectarea.colliderect(Hero.rectarea):
  2041.             collectch.play(invince)
  2042.             TRIPLEgun.life=0 # type and life
  2043.             controls.PUcount[1]=0
  2044.             score[4]+=5
  2045.             controls.TRIPLEguntime=150
  2046.  
  2047. #CBOMB POWERUP
  2048.     if controls.CBomb==True and CBombpup.life>0:
  2049.         CBombpup.life-=1
  2050.         CBombpup.update()
  2051.         CBombpup.getrectarea()
  2052.  
  2053.         if CBombpup.rectarea.colliderect(Hero.rectarea):
  2054.             collectch.play(invince)
  2055.             CBombpup.life=0 # type and life
  2056.             score[3]+=1
  2057.             controls.CBomb='C'  # CBomb caught by Hero
  2058.             for a in xrange(10): # now add 10 cluster bombs
  2059.                 Hero.CBMag.append(copy.copy(CBOMB))
  2060.  
  2061.     if controls.CBomb==True and CBombpup.life<=0:
  2062.         controls.CBomb=False
  2063.         controls.PUcount[2]=1 # reset the Cluster bomb counter
  2064.  
  2065. #THE ENERGY GLOBES
  2066.  
  2067.     for g in controls.globelist:
  2068.         g.getrectarea()
  2069.  
  2070.         if g.rectarea.colliderect(Hero.rectarea):
  2071.             g.status="C"
  2072.             collectch.play(collect)
  2073.             if controls.globes=='Galive':
  2074.                 score[5]+=5
  2075.             elif controls.globes=='Ralive':
  2076.                 score[5]+=7
  2077.                 score[6]+=5
  2078.             elif controls.globes=='Oalive':
  2079.                 score[4]+=1
  2080.             elif controls.globes=='Palive':
  2081.                 score[4]+=1
  2082.                 score[5]+=5
  2083.                 Hero.bombs[0]+=1 # bomb material added to list
  2084.             controls.collected+=1
  2085.         if g.status=="C":
  2086.             try:
  2087.                 controls.globelist.remove(g)
  2088.             except:
  2089.                 pass
  2090. #------------------------------------------------------------------------------#
  2091. #                              HERO GUN CONTROLS                               #
  2092. #------------------------------------------------------------------------------#
  2093.  
  2094.     for b in Hero.CMag: # MAIN GUN
  2095.         b.update()
  2096.         b.getrectarea()
  2097.         Alcollisions= b.rectarea.collidelist(alien1DEF_rects)
  2098.         Al2collisions=b.rectarea.collidelist(alien2DEF_rects)
  2099.         Al3collisions=b.rectarea.collidelist(FalienDEF_rects)
  2100.         Ascollisions=b.rectarea.collidelist(asteroids_rects)
  2101.  
  2102.         # MOTHERSHIP1 COLLISION CHECK
  2103.         if b.rectarea.colliderect(Mothership1.rectarea) and\
  2104.            Mothership1.status=="M" and b.status=="F":
  2105.             b.status="E"
  2106.             score[5]+=5
  2107.             Mothership1.life-=controls.LreduceM
  2108.  
  2109.         # BOSS1 COLLISION CHECK
  2110.         if boss1.status=='M' and b.rectarea.colliderect(boss1.rectarea)\
  2111.            and b.status=="F":
  2112.             b.status="E"
  2113.             score[4]+=4
  2114.             boss1.life-=controls.LreduceB
  2115.  
  2116.         # ALIEN1 COLLISION CHECK
  2117.         if not Alcollisions==-1 and b.status=="F" and \
  2118.            controls.Alien1[Alcollisions].status=="M":
  2119.             controls.Alien1[Alcollisions].life-=controls.LreduceA1
  2120.  
  2121.             if controls.Alien1[Alcollisions].state<>'turn':
  2122.                 controls.Alien1[Alcollisions].state='turn'
  2123.  
  2124.             if controls.Alien1[Alcollisions].life<=0:
  2125.                 controls.enemycount+=1
  2126.                 score[4]+=2
  2127.             b.status="E"
  2128.  
  2129.         # ALIEN2 COLLISION CHECK
  2130.         if not Al2collisions==-1 and b.status=="F" and \
  2131.            controls.Alien2[Al2collisions].status=="M":
  2132.             controls.Alien2[Al2collisions].life-=controls.LreduceA2
  2133.  
  2134.             if controls.Alien2[Al2collisions].state<>'turn':
  2135.                 controls.Alien2[Al2collisions].state='turn'
  2136.  
  2137.             if controls.Alien2[Al2collisions].life<=0:
  2138.                 controls.enemycount+=1
  2139.                 score[4]+=2
  2140.             b.status="E"
  2141.  
  2142.         # FINALALIEN COLLISION CHECK
  2143.         if not Al3collisions==-1 and b.status=="F" and \
  2144.            controls.FinalAliens[Al3collisions].status=="M":
  2145.             controls.FinalAliens[Al3collisions].life-=controls.LreduceFA
  2146.             score[5]+=5
  2147.  
  2148.             if controls.FinalAliens[Al3collisions].state<>'turn':
  2149.                 controls.FinalAliens[Al3collisions].state='turn'
  2150.             b.status="E"
  2151.  
  2152.         # ASTEROID COLLISION CHECK
  2153.         if not Ascollisions==-1 and b.status=="F" and \
  2154.            asteroids[Ascollisions].life>0:
  2155.             asteroids[Ascollisions].life-=1
  2156.             if asteroids[Ascollisions].life<=0:
  2157.                 controls.asteroidcount+=1
  2158.             if asteroids[Ascollisions].kind=="L":
  2159.                 score[4]+=1
  2160.             if asteroids[Ascollisions].kind=="M":
  2161.                 score[4]+=2
  2162.                 score[5]+=1
  2163.             if asteroids[Ascollisions].kind=="S":
  2164.                 score[4]+=4
  2165.             b.status="E"
  2166.  
  2167.         if b.status=="D":
  2168.             try:
  2169.                 Hero.CMag.remove(b) #REMOVE SPENT HBULLET
  2170.             except:
  2171.                 pass
  2172.  
  2173.     for b in Hero.LMag: # STARBOARD (LEFT) GUN
  2174.         b.update()
  2175.         b.getrectarea()
  2176.         Alcollisions= b.rectarea.collidelist(alien1DEF_rects)
  2177.         Al2collisions= b.rectarea.collidelist(alien2DEF_rects)
  2178.         Al3collisions=b.rectarea.collidelist(FalienDEF_rects)
  2179.         Ascollisions=b.rectarea.collidelist(asteroids_rects)
  2180.  
  2181.         # MOTHERSHIP1 COLLISION CHECK
  2182.         if b.rectarea.colliderect(Mothership1.rectarea) and\
  2183.            Mothership1.status=="M":
  2184.             b.status="E"
  2185.             score[5]+=1
  2186.             Mothership1.life-=controls.LreduceM/4
  2187.  
  2188.         # ALIEN2 COLLISION CHECK
  2189.         if not Al2collisions==-1 and b.status=="F" and \
  2190.            controls.Alien2[Al2collisions].status=="M":
  2191.             controls.Alien2[Al2collisions].life-=controls.LreduceA2
  2192.             if controls.Alien2[Al2collisions].state<>'turn':
  2193.                 controls.Alien2[Al2collisions].state='turn'
  2194.             if controls.Alien2[Al2collisions].life<=0:
  2195.                 controls.enemycount+=1
  2196.             b.status="E"
  2197.  
  2198. ##        # FINALALIEN COLLISION CHECK
  2199.         if not Al3collisions==-1 and b.status=="F" and \
  2200.            controls.FinalAliens[Al3collisions].status=="M":
  2201.             controls.FinalAliens[Al3collisions].life-=controls.LreduceFA
  2202.             score[5]+=1
  2203.  
  2204.             if controls.FinalAliens[Al3collisions].state<>'turn':
  2205.                 controls.FinalAliens[Al3collisions].state='turn'
  2206.             b.status="E"
  2207.  
  2208.         # ASTEROID COLLISION CHECK
  2209.         if not Ascollisions==-1 and b.status=="F" and \
  2210.            asteroids[Ascollisions].life>0:
  2211.             asteroids[Ascollisions].life-=1 #
  2212.             b.status="E"
  2213.  
  2214.         if b.status=="D":
  2215.             try:
  2216.                 Hero.LMag.remove(b) #REMOVE SPENT HBULLET
  2217.             except:
  2218.                 pass
  2219.  
  2220.     for b in Hero.RMag: # PORT (RIGHT) GUN
  2221.         b.update()
  2222.         b.getrectarea()
  2223.         Alcollisions= b.rectarea.collidelist(alien1DEF_rects)
  2224.         Al2collisions= b.rectarea.collidelist(alien2DEF_rects)
  2225.         Al3collisions=b.rectarea.collidelist(FalienDEF_rects)
  2226.         Ascollisions=b.rectarea.collidelist(asteroids_rects)
  2227.  
  2228.         # MOTHERSHIP1 COLLISION CHECK
  2229.         if b.rectarea.colliderect(Mothership1.rectarea) and\
  2230.            Mothership1.status=="M":
  2231.             b.status="E"
  2232.             score[5]+=1
  2233.             Mothership1.life-=controls.LreduceM/4
  2234.  
  2235.         # ALIEN2 COLLISION CHECK
  2236.         if not Al2collisions==-1 and b.status=="F" and \
  2237.            controls.Alien2[Al2collisions].status=="M":
  2238.             controls.Alien2[Al2collisions].life-=controls.LreduceA2
  2239.             if controls.Alien2[Alcollisions].state<>'turn':
  2240.                 controls.Alien2[Alcollisions].state='turn'
  2241.             b.status="E"
  2242.  
  2243.         # FINALALIEN COLLISION CHECK
  2244.         if not Al3collisions==-1 and b.status=="F" and \
  2245.            controls.FinalAliens[Al3collisions].status=="M":
  2246.             controls.FinalAliens[Al3collisions].life-=controls.LreduceFA
  2247.             score[5]+=1
  2248.             if controls.FinalAliens[Al3collisions].state<>'turn':
  2249.                 controls.FinalAliens[Al3collisions].state='turn'
  2250.             b.status="E"
  2251.  
  2252.         # ASTEROID COLLISION CHECK
  2253.         if not Ascollisions==-1 and b.status=="F" and \
  2254.            asteroids[Ascollisions].life>0:
  2255.             asteroids[Ascollisions].life-=1 #
  2256.             b.status="E"
  2257.  
  2258.         if b.status=="D":
  2259.             try:
  2260.                 Hero.RMag.remove(b) #REMOVE SPENT HBULLET
  2261.             except:
  2262.                 pass
  2263.  
  2264.     for b in Hero.BMag: # bomb collisions
  2265.         b.update()
  2266.         b.getrectarea()
  2267.         #pygame.draw.rect(screen, (0,255,0), b.rectarea,1)
  2268.         if b.rectarea.colliderect(boss1.rectarea) and b.status=="F":
  2269.             score[4]+=5
  2270.             boss1.life-=10
  2271.             b.status="E"
  2272.             Hero.bombs[1]="D"
  2273.         if b.status=="D":
  2274.             try:
  2275.                 Hero.BMag.remove(b) #REMOVE HBOMB
  2276.                 Hero.bombs[1]="D"
  2277.             except:
  2278.                 pass
  2279.  
  2280.     for b in Hero.CBMag: # CLUSTER BOMB COLLISIONS
  2281.         b.update()
  2282.         b.getrectarea()
  2283.         Alcollisions= b.rectarea.collidelist(alien1INF_rects)
  2284.         Al2collisions= b.rectarea.collidelist(alien2INF_rects)
  2285.         Al3collisions=b.rectarea.collidelist(FalienDEF_rects)
  2286.         Ascollisions=b.rectarea.collidelist(asteroids_rects)
  2287.  
  2288.         if b.speed==0:
  2289.             b.explode-=1
  2290.         if b.explode==0:
  2291.             b.status="E"
  2292.             controls.CBomb="E"
  2293.         # ALIEN COLLISION CHECK
  2294.         if not Alcollisions==-1 and b.status=="E" and \
  2295.            controls.Alien1[Alcollisions].status=="M":
  2296.             controls.Alien1[Alcollisions].life=0
  2297.             controls.enemycount+=1
  2298.             score[4]+=2
  2299.             score[5]+=5
  2300.         # ALIEN2 COLLISION CHECK
  2301.         if not Al2collisions==-1 and b.status=="E" and \
  2302.            controls.Alien2[Al2collisions].status=="M":
  2303.             controls.Alien2[Al2collisions].life=0
  2304.             controls.enemycount+=1
  2305.             score[4]+=2
  2306.             score[5]+=5
  2307.  
  2308.         # FINAL ALIENS COLLISION CHECK
  2309.         if not Al3collisions==-1 and b.status=="E" and \
  2310.            controls.FinalAliens[Al3collisions].status=="M":
  2311.             controls.FinalAliens[Al3collisions].life-=controls.LreduceFA
  2312.             score[4]+=2
  2313.             score[5]+=5
  2314.  
  2315.         # ASTEROID COLLISION CHECK
  2316.         if not Ascollisions==-1 and b.status=="E" and \
  2317.            asteroids[Ascollisions].life>0:
  2318.             asteroids[Ascollisions].life=0
  2319.             score[4]+=1
  2320.         if b.status=="D":
  2321.             try:
  2322.                 Hero.CBMag.remove(b) #REMOVE HBOMB
  2323.             except:
  2324.                 pass
  2325.         if len(Hero.CBMag)<=0 and controls.CBomb=="E":
  2326.             controls.PUcount[2]=1
  2327.             controls.CBomb=False
  2328.  
  2329. #------------------------------------------------------------------------------#
  2330. #                    REMOVE DESTORYED ALIENS AND ASTEROIDS                     #
  2331. #------------------------------------------------------------------------------#
  2332.  
  2333.     for e in controls.Alien1:
  2334.         if e.life<=0 and e.status=="M": # ALIEN LIFE 0 SO EXPLODE
  2335.             enemyexp.play()
  2336.             e.status="E"
  2337.         if e.status=="E":
  2338.             e.explode()
  2339.         if e.status=="D":
  2340.             try:
  2341.                 controls.Alien1.remove(e) #REMOVE DESTROYED ALIEN
  2342.             except:
  2343.                 pass
  2344.  
  2345.     for e in controls.Alien2:
  2346.         if e.life<=0 and e.status=="M": # ALIEN LIFE 0 SO EXPLODE
  2347.             enemyexp.play()
  2348.             e.status="E"
  2349.         if e.status=="E":
  2350.             e.explode()
  2351.         if e.status=="D":
  2352.             try:
  2353.                 controls.Alien2.remove(e) #REMOVE DESTROYED ALIEN
  2354.             except:
  2355.                 pass
  2356.  
  2357.     for e in controls.FinalAliens:
  2358.         if e.life<=0 and e.status=="M": # ALIEN LIFE 0 SO EXPLODE
  2359.             enemyexp.play()
  2360.             e.status="E"
  2361.         if e.status=="E":
  2362.             e.explode()
  2363.         if e.status=="D":
  2364.             score[3]+=2
  2365.             controls.enemycount+=1
  2366.             try:
  2367.                 controls.FinalAliens.remove(e) #REMOVE DESTROYED ALIEN
  2368.             except:
  2369.                 pass
  2370.  
  2371.     for a in asteroids:
  2372.         if a.life<=0 and a.kind=="L" and a.status=="M":
  2373.             astexplode.play()
  2374.             x=a.x+40; y=a.y+40
  2375.             asteroidA=Asteroids(meteor2,metex2,x,y,5,512,8,64,60,"M","M")
  2376.             asteroidA.speed=1.8
  2377.             asteroidA.speedlimit=asteroidA.speed
  2378.             asteroidA.heading+=90
  2379.             asteroidA.life=4
  2380.             x=a.x-40; y=a.y-40
  2381.             asteroidB=Asteroids(meteor2,metex2,x,y,5,512,8,64,60,"M","M")
  2382.             asteroidB.speed=1.5
  2383.             asteroidB.speedlimit=asteroidB.speed
  2384.             asteroidB.heading-=90
  2385.             a.status="E"
  2386.             asteroids.append(asteroidA)
  2387.             asteroids.append(asteroidB)
  2388.         if a.life<=0 and a.kind=="M" and a.status=="M":
  2389.             astexplode.play()
  2390.             x=a.x+20; y=a.y+20
  2391.             asteroidA=Asteroids(meteor3,metex3,x,y,2,128,8,32,60,"S","M")
  2392.             asteroidA.speed=2.5
  2393.             asteroidA.speedlimit=asteroidA.speed
  2394.             asteroidA.heading+=90
  2395.             asteroidA.life=2
  2396.             x=a.x-20; y=a.y-20
  2397.             asteroidB=Asteroids(meteor3,metex3,x,y,2,128,8,32,60,"S","M")
  2398.             asteroidB.speed=3.5
  2399.             asteroidB.speedlimit=asteroidB.speed
  2400.             asteroidB.heading-=90
  2401.             a.status="E"
  2402.             asteroids.append(asteroidA)
  2403.             asteroids.append(asteroidB)
  2404.         if a.life<=0 and a.kind=="S" and a.status=="M":
  2405.             astexplode.play()
  2406.             a.status="E"
  2407.         if a.status=="D":
  2408.             try:
  2409.                 asteroids.remove(a) #REMOVE EXPLODED ASTEROID FROM GAME
  2410.             except:
  2411.                 pass
  2412.  
  2413.     if Hero.life<=0:
  2414.         Hero.life=0
  2415.  
  2416.     if controls.enemystate=="FINAL BATTLE" \
  2417.        and controls.enemycount==controls.FAamount:
  2418.         controls.gamestate="player wins"
  2419.         player_instructions(playerwins,10)
  2420.         Hero.lives=0
  2421.  
  2422. #------------------------------------------------------------------------------#
  2423. #                    START, INSTRUCTIONS AND PAUSE SCREENS                     #
  2424. #------------------------------------------------------------------------------#
  2425.  
  2426.     while controls.pause==True :
  2427.         scorepos=55
  2428.         font = pygame.font.Font("resources\data\prometheanb.ttf", 30)
  2429.         text = font.render("Hall Of Fame", 1, (70,70,255))
  2430.         textpos1 = text.get_rect()
  2431.         x=controls.Swidth/2-(textpos1[2]/2)
  2432.         screen.blit(text,(x,textpos1[3]/2))
  2433.         font = pygame.font.Font("resources\data\prometheanb.ttf", 15)
  2434.         text = font.render("----------------------------", 1,(80,80,255) )
  2435.         textpos2 = text.get_rect()
  2436.         screen.blit(text,(x,25+textpos2[3]/2))
  2437.         font = pygame.font.Font("resources\data\prometheanb.ttf", 14)
  2438.         for t in highscores:
  2439.             text = font.render(t[1], 1, (90,90,255)) # player name
  2440.             textpos3= text.get_rect()
  2441.             y=x-60
  2442.             screen.blit(text,(y,scorepos-textpos3[3]/2))
  2443.             text = font.render(str(t[0]), 1, (90,90,255)) # player high score
  2444.             textpos4 = text.get_rect()
  2445.             screen.blit(text,(y+100,scorepos-textpos4[3]/2))
  2446.             text = font.render(str(t[2]), 1, (90,90,255)) # player rank
  2447.             textpos5 = text.get_rect()
  2448.             screen.blit(text,(y+200,scorepos-textpos5[3]/2))
  2449.             scorepos+=18
  2450.         # Instructions
  2451.         font = pygame.font.Font("resources\data\prometheanb.ttf", 20)
  2452.         text = font.render("I-Instructions", 0, (128,128,128))
  2453.         textpos = text.get_rect()
  2454.         x=textpos[3]
  2455.         screen.blit(text,(controls.Swidth/2-textpos[2]/2,\
  2456.                                              controls.Sheight-x))
  2457.         a=random.randrange(0,100)
  2458.         b=random.randrange(0,175)
  2459.         c=random.randrange(0,255)
  2460.         if controls.gamestate=="initial":
  2461.             text = font.render("P - to start game", 1,\
  2462.                                [40,40,b])
  2463.         else:
  2464.             text = font.render("Game Paused... P - to continue!",\
  2465.                                1, [60,60,a])
  2466.         textpos = text.get_rect()
  2467.         y=x+textpos[3]+10
  2468.         screen.blit(text,(controls.Swidth/2-textpos[2]/2,controls.Sheight-y))
  2469.  
  2470.         text = font.render("Music Volume : "+str(int(controls.musicfader*100))\
  2471.                             +" -> inc <- dec",1, [50,50,c])
  2472.         textpos = text.get_rect()
  2473.         z=y+textpos[3]+10
  2474.         screen.blit(text,(controls.Swidth/2-textpos[2]/2,\
  2475.                           controls.Sheight-z))
  2476.  
  2477.         text = font.render("F - FULLSCREEN or WINDOWED mode",0, (128,128,128))
  2478.         textpos = text.get_rect()
  2479.         zz=z+textpos[3]+10
  2480.         screen.blit(text,(controls.Swidth/2-textpos[2]/2,controls.Sheight-zz))
  2481.  
  2482.         text = font.render("S - Save Game    L - Load Game",0, (128,128,128))
  2483.         textpos = text.get_rect()
  2484.         za=zz+textpos[3]+10
  2485.         screen.blit(text,(controls.Swidth/2-textpos[2]/2,controls.Sheight-za))
  2486.  
  2487.         # animate the game title
  2488.         controls.titlewidth+=8
  2489.         controls.titleheight+=1
  2490.         if controls.titlewidth>=800:
  2491.             controls.titlewidth=800; controls.titleheight=100
  2492.         p=pygame.transform.scale(title, (controls.titlewidth,\
  2493.                                          controls.titleheight))
  2494.         w=p.get_rect(); x=(controls.Sheight-w[3])-150; y=x-3
  2495.         screen.blit(p,((controls.Swidth-w[2])/2,random.randrange(y,x)))
  2496.         star_field()
  2497.         update_screen()
  2498.  
  2499.         #get key input
  2500.         for event in pygame.event.get():
  2501.             if event.type==KEYDOWN:
  2502.                 if event.key==K_p :
  2503.                     if controls.gamestate=="initial":
  2504.                         controls.gamestate="Level 1"
  2505.                         pygame.event.clear()
  2506.                     controls.pause=not controls.pause
  2507.                 Hero.setHeading(90)
  2508.                 if event.key==K_i:
  2509.                     controls.instructions=True
  2510.                     show_instructions()
  2511.                 if event.key==K_RIGHT:              # Music vol+
  2512.                         controls.musicfader+=0.01
  2513.                 if event.key==K_LEFT:              # Music vol-
  2514.                         controls.musicfader-=0.01
  2515.                 if controls.musicfader<=0:
  2516.                     controls.musicfader=0
  2517.                 if controls.musicfader>=1:
  2518.                     controls.musicfader=1
  2519.                 pygame.mixer.music.set_volume(controls.musicfader)
  2520.                 if event.key==K_f and screenmode==0: # toggle fullscreen on/off
  2521.                     screenmode=FULLSCREEN
  2522.                     screen = pygame.display.set_mode((Swidth, Sheight),\
  2523.                                                      screenmode,0)
  2524.                 elif event.key==K_f and screenmode==FULLSCREEN:
  2525.                     screenmode=0
  2526.                     screen = pygame.display.set_mode((Swidth, Sheight),\
  2527.                                                      screenmode,0)
  2528.                 if event.key==K_s:
  2529.                     controls.savegame=True
  2530.  
  2531.                 if event.key==K_l:
  2532.                     controls.loadgame=True
  2533.  
  2534.         if controls.savegame==True:
  2535.             save_game()
  2536.  
  2537.         if controls.loadgame==True:
  2538.             load_game()
  2539.  
  2540.     update_all(text1,text2,text3)
  2541.  
  2542. #------------------------------------------------------------------------------#
  2543. #                        G A  M  E    O  V  E  R                               #
  2544. #                            replay or quit                                    #
  2545. #------------------------------------------------------------------------------#
  2546.     controls.name=''
  2547.     f=open('resources\data\scores.sg','wb')
  2548.     while Hero.lives<=0 and controls.halloffame==False:
  2549.         font = pygame.font.Font("resources\data\prometheanb.ttf", 70)
  2550.         akuru="GAME OVER!"
  2551.         text = font.render(akuru, 1, red)
  2552.         textpos = text.get_rect()
  2553.         screen.blit(text,(controls.Swidth/2-(textpos[2]/2),50))
  2554.         if realscore>20000 and controls.halloffame==False:
  2555.             ypos=hall_of_fame_message()
  2556.             # get the rank
  2557.             if controls.gamestate=="Level 2":
  2558.                 controls.rank="CADET"
  2559.             elif controls.gamestate=="Level 3":
  2560.                 controls.rank="SOLDIER"
  2561.             elif controls.gamestate=="Level 4":
  2562.                 controls.rank="WARRIOR"
  2563.             elif controls.gamestate=="player wins":
  2564.                 controls.rank="SPACE GLADIATOR"
  2565.  
  2566.             for event in pygame.event.get(): # get player name
  2567.                 if event.type==KEYDOWN:
  2568.                     if event.key==K_BACKSPACE and len(controls.name)>0:
  2569.                         controls.name=controls.name[:-1]
  2570.                     if event.key>=97 and event.key<=122 and \
  2571.                        len(controls.name)<10 or event.key>=48 and \
  2572.                        event.key<=57 and len(controls.name)<10:
  2573.                         text=str(pygame.key.name(event.key))
  2574.                         controls.name=controls.name+text
  2575.  
  2576.                     if event.key==K_RETURN:
  2577.                         newname=controls.name.upper()# convert to uppercase
  2578.                         controls.name=newname
  2579.                         controls.halloffame=True
  2580.                         if len(controls.name)>0:
  2581.                             addnew=[realscore,controls.name,controls.rank]
  2582.                             if len(highscores)<19:#max 20 items in list
  2583.                                 highscores.append(addnew)#add new data to file
  2584.                             #list is already full so add to last item if bigger
  2585.                             # than the number there
  2586.                             elif highscores[-1]<addnew:
  2587.                                 highscores[-1]=addnew
  2588.                             highscores.sort(reverse=True)
  2589.  
  2590.         font = pygame.font.Font("resources\data\prometheanb.ttf", 20)
  2591.         text=font.render((controls.name+'_'),1,[175,175,175])
  2592.         textpos = text.get_rect()
  2593.         screen.blit(text,(controls.Swidth/2-textpos[2]/2,ypos+10))
  2594.  
  2595.         font = pygame.font.Font("resources\data\prometheanb.ttf", 30)
  2596.         text = font.render("Hit ESC to Quit!", 1, red)
  2597.         textpos1 = text.get_rect()
  2598.         screen.blit(text,(controls.Swidth/2-(textpos1[2]/2),120))
  2599.         text = font.render("Enter to replay", 1, red)
  2600.         textpos2 = text.get_rect()
  2601.         screen.blit(text,(controls.Swidth/2-(textpos2[2]/2),150))
  2602.         pygame.event.pump()
  2603.         key=pygame.key.get_pressed()
  2604.         if key[pygame.K_RETURN]:
  2605.             Hero.life=450
  2606.             Hero.lives=6
  2607.             score=[0,0,0,0,0,0,0]#mil,hunthous, tenthous,thous,huns,tens,ones
  2608.             scorestr= "".join(str(i) for i in score)
  2609.             realscore=int(scorestr)
  2610.             controls=Game_controls()
  2611.             initialize_stars()
  2612.             asteroids=[]
  2613.             Hero =HeroObject(45,controls.Swidth/2, controls.Sheight/2,\
  2614.                              "N",6,["one",20,"S",0],[0,"D"],5,64)
  2615.             Hero.setHeading(90)
  2616.             bosx=-100
  2617.             bosy=random.randrange(50,controls.Sheight-100)
  2618.             # create boss1  and Mothership1 off screen but passive-"P"
  2619.             boss1=EnemyObject(bossA,bsxplode,80,bosx,bosy,100,30,8,400,"P")
  2620.             mx=random.randrange(50,100,5)
  2621.             Mothership1=EnemyObject(AMSHIP1,AMS1EXP,110,mx,0,75.0,0,10,250,"P")
  2622.             Mothership1.heading=90
  2623.             Mothership1.speed=2
  2624.             pygame.mixer.music.load(startmusic)
  2625.             pygame.mixer.music.set_volume(0.4)
  2626.             pygame.mixer.music.play(-1)
  2627.             controls.musicfader=pygame.mixer.music.get_volume()
  2628.         if key[pygame.K_ESCAPE]:
  2629.             add_and_close_file()
  2630.             game_over()
  2631.         update_all(text1,text2,text3)
  2632.     add_and_close_file()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement