"""
resources.py - Loads image resources from files
"""

import common
import pygame.image
from pygame.locals import *
import os

def loadResources():
    #print "Loading ship images..",
    common.images = {}
    common.images['Player'] = [pygame.image.load("images%sshipA1.gif"%os.sep).convert()]
    common.images['Player'].append(pygame.image.load("images%sshipA2.gif"%os.sep).convert())
    common.images['Player'].append(pygame.image.load("images%sshipA3.gif"%os.sep).convert())
    common.images['Player'].append(pygame.image.load("images%sshipA4.gif"%os.sep).convert())
    #print "[done]"
    
    #print "Loading shot images..",
    for x in os.listdir("images"):
        if x[:4] == 'shot' and x[-3:] == 'gif':
            if common.images.has_key('Shot%s'%x[4]):
                common.images['Shot%s'%x[4]].append(pygame.image.load("images%s%s"%(os.sep,x)).convert())
            else:
                common.images['Shot%s'%x[4]] = [pygame.image.load("images%s%s"%(os.sep,x)).convert()]
            #print x,
    #print "[done]"

    #print "Loading enemy images..",
    for x in os.listdir("images"):
        if x[:5] == 'enemy' and x[-3:] == 'gif':
            if common.images.has_key('Enemy%s'%x[5]):
                common.images['Enemy%s'%x[5]].append(pygame.image.load("images%s%s"%(os.sep, x)).convert())
            else:
                common.images['Enemy%s'%x[5]] = [pygame.image.load("images%s%s"%(os.sep,x)).convert()]
            #print x,
    #print "[done]"

    #print "Loading explosion images..",
    for x in os.listdir("images"):
        if x[:9] == 'explosion' and x[-3:] == 'gif':
            if common.images.has_key('Explosion%s'%x[9]):
                common.images['Explosion%s'%x[9]].append(pygame.image.load("images%s%s"%(os.sep,x)).convert())
            else:
                common.images['Explosion%s'%x[9]] = [pygame.image.load("images%s%s"%(os.sep,x)).convert()]
            #print x,
    #print "[done]"

    #print "Loading goodie images.. ",
    for x in os.listdir("images"):
        if x[:6] == 'goodie' and x[-3:] == 'gif':
            if common.images.has_key('Goodie%s'%x[6]):
                common.images['Goodie%s'%x[6]].append(pygame.image.load("images%s%s"%(os.sep,x)).convert())
            else:
                common.images['Goodie%s'%x[6]] = [pygame.image.load("images%s%s"%(os.sep,x)).convert()]
            #print x,
    #print "[done]"

    #print "Loading shield images.. ",
    for x in os.listdir("images"):
        if x[:6] == 'shield' and x[-3:] == 'gif':
            if common.images.has_key('Shield%s'%x[6]):
                common.images['Shield%s'%x[6]].append(pygame.image.load("images%s%s"%(os.sep,x)).convert())
            else:
                common.images['Shield%s'%x[6]] = [pygame.image.load("images%s%s"%(os.sep,x)).convert()]
            #print x,
    #print "[done]"

    #print "Loading meteor images.. ",
    for x in os.listdir("images"):
        if x[:6] == 'meteor' and x[-3:] == 'gif':
            if common.images.has_key('Meteor%s'%x[6]):
                common.images['Meteor%s'%x[6]].append(pygame.image.load("images%s%s"%(os.setp,x)).convert())
            else:
                common.images['Meteor%s'%x[6]] = [pygame.image.load("images%s%s"%(os.sep,x))]
            #print x,
    #print "[done]"
    
    #print "Activating colorkey..",
    for x in common.images.keys():
        for y in common.images[x]:
            y.set_colorkey((0,0,0),RLEACCEL)
    #print "[done]"
