execfile('music.py')
execfile('OceanPalace.py')
execfile('SchalaTheme.py')
execfile('MemoriesofGreen.py')

mainBG = makePicture("test.jpg")
w = getWidth(mainBG)
h = getHeight(mainBG)

mainWin = GraphWin("Chrono Trigger", w, h)
displayBG = Image(Point(w / 2.0, h / 2.0), mainBG)

displayBG.draw(mainWin)

sp = range(5)
a = range(5)
b = range(6)
t = range(6)
switch = range(5)

# annoying workaround to make everything in switch be 0
for groan in range(5): 
    switch[groan] = 0

# draw the sprites? could have done this with a loop, but didn't think of that until after the fact
# perhaps it is just an example of crufty coding
sp[0] = Image(Point(586, 140), makePicture("s1.jpg"))
sp[0].draw(mainWin)
sp[1] = Image(Point(586, 140 + 80), makePicture("s2.jpg"))
sp[1].draw(mainWin)
sp[2] = Image(Point(586, 140 + 160), makePicture("s3.jpg"))
sp[2].draw(mainWin)
sp[3] = Image(Point(586, 140 + 240), makePicture("s4.jpg"))
sp[3].draw(mainWin)
sp[4] = Image(Point(586, 140 + 320), makePicture("s5.jpg"))
sp[4].draw(mainWin)

# alternate sprites
a[0] = Image(Point(586, 140), makePicture("a1.jpg"))
a[1] = Image(Point(586, 140 + 80), makePicture("a2.jpg"))
a[2] = Image(Point(586, 140 + 160), makePicture("a3.jpg"))
a[3] = Image(Point(586, 140 + 240), makePicture("s4.jpg"))
a[4] = Image(Point(586, 140 + 320), makePicture("a5.jpg"))

# backgrounds for songs
b[0] = Image(Point(32 + (512/2), 98 + 224), makePicture("b1.jpg"))
b[1] = Image(Point(32 + (512/2), 98 + 224), makePicture("b2.jpg"))
b[2] = Image(Point(32 + (512/2), 98 + 224), makePicture("b3.jpg"))
b[3] = Image(Point(32 + (512/2), 98 + 224), makePicture("b4.jpg"))
b[4] = Image(Point(32 + (512/2), 98 + 224), makePicture("b5.jpg"))
b[5] = Image(Point(32 + (512/2), 98 + 224), makePicture("b0.jpg"))
b[5].draw(mainWin)

t[0] = Text(Point(680, 140), "Chrono")
t[1] = Text(Point(680, 140 + 80), "Marle")
t[2] = Text(Point(680, 140 + 160), "Lucca")
t[3] = Text(Point(680, 140 + 240), "Frog")
t[4] = Text(Point(680, 140 + 320), "Magus")
t[5] = Text(Point(0,0), "")

# arrow for point/select
arrow = Image(Point(630, 140), makePicture("arrow.jpg"))
arrow.draw(mainWin)

pos = 0 # where the arrow points
prevpos = 5 # where it was pointing
lock = 0 # are we allowed to move the arrow?

while True:
    action = getGamepad()
    x, y = action['axis']
    go = action['button']
    if (y != -3.0517578125e-005) and lock == 0: 
        if y > 0 and pos < 4:
            arrow.move(0,80)
            pos = pos + 1
        elif y < 0 and pos > 0:
            arrow.move(0,-80)
            pos = pos - 1
        t[prevpos].undraw()
        t[pos].setStyle("bold")
        t[pos].draw(mainWin)
        b[prevpos].undraw()
        b[pos].draw(mainWin)
        prevpos = pos
    if go != [0, 0, 0, 0, 0, 0, 0, 0]:
        if switch[pos] == 0: # if music is off here
            sp[pos].undraw() # get rid of the old sprite
            a[pos].draw(mainWin) # draw a new one
            prevpos = pos # this is the old position
            switch[pos] = 1
            lock = 1
            if pos == 0:
                OceanPalace()
            elif pos == 1:
                MemoriesofGreen()
            elif pos == 2:
                WindScene()
            elif pos == 3:
                FrogTheme()
            elif pos == 4:
                SchalaTheme()
        elif switch[pos] == 1:
            a[pos].undraw()
            b[pos].undraw()
            b[5].draw(mainWin)
            sp[pos].draw(mainWin)
            switch[pos] = 0
            lock = 0


            
