# Copyright (C) 2008-2009 Charlie Dog Games

# This file is part of Atomic Worm.

# Atomic Worm is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# Atomic Worm is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with Atomic Worm.  If not, see <http://www.gnu.org/licenses/>.
import game

poem1Line1 = "O Rose though art sick" 
poem1Line2 = "The invisible worm"
poem1Line3 = "That flies in the night"
poem1Line4 = "In the howling storm"
poem1Line5 = "Has found out thy bed of crimson joy"
poem1Line6 = "And his dark secret love"
poem1Line7 = "Does thy life destroy."
blank = ""
poem1Lyrics = [poem1Line1,poem1Line2,poem1Line3,poem1Line4,poem1Line5,poem1Line6,poem1Line7,blank,blank]

poem2Line1 = "`Twas brillig, and the slithy toves"
poem2Line2 = "Did gyre and gimble in the wabe;"
poem2Line3 = "All mimsy were the borogoves,"
poem2Line4 = "And the mome raths outgrabe."
poem2Line5 = "Beware the Jabberwock, my son!"
poem2Line6 = "The jaws that bite, the claws that catch!"
poem2Line7 = "Beware the Jubjub bird, and shun"
poem2Line8 = "The frumious Bandersnatch!"
poem2Lyrics = [poem2Line1,poem2Line2,poem2Line3,poem2Line4,poem2Line5,poem2Line6,poem2Line7,poem2Line8,blank,blank]

poem3Line1 = "But see, amid the mimic rout"
poem3Line2 = "A crawling shape intrude!"
poem3Line3 = "A blood-red thing that writhes from out"
poem3Line4 = "The scenic solitude!"
poem3Line5 = "It writhes!- it writhes!- with mortal pangs"
poem3Line6 = "The mimes become its food,"
poem3Line7 = "And seraphs sob at vermin fangs"
poem3Line8 = "In human gore imbued."
poem3Line9 = "Out- out are the lights- out all!"
poem3Line10 = "And, over each quivering form,"
poem3Line11 = "The curtain, a funeral pall,"
poem3Line12 = "Comes down with the rush of a storm,"
poem3Line13 = "While the angels, all pallid and wan,"
poem3Line14 = "Uprising, unveiling, affirm"
poem3Line15 = "That the play is the tragedy, 'Man,'"
poem3Line16 = "And its hero the Conqueror Worm."

poem3Lyrics = [poem3Line1,poem3Line2,poem3Line3,poem3Line4,poem3Line5,poem3Line6,poem3Line7,poem3Line8,poem3Line9,poem3Line10,poem3Line11,poem3Line12,poem3Line13,poem3Line14,poem3Line15,poem3Line16,blank,blank]

poem4Line1 = "A damsel with a dulcimer"
poem4Line2 = "In a vision once I saw:"
poem4Line3 = "It was an Abyssinian maid,"
poem4Line4 = "And on her dulcimer she played,"
poem4Line5 = "Singing of Mount Abora."
poem4Line6 = "Could I revive within me"
poem4Line7 = "Her symphony and song,"
poem4Line8 = "To such a deep delight 'twould win me"
poem4Line9 = "That with music loud and long"
poem4Line10 = "I would build that dome in air,"
poem4Line11 = "That sunny dome! those caves of ice!"
poem4Line12 = "And all who heard should see them there,"
poem4Line13 = "And all should cry, Beware! Beware!"
poem4Line14 = "His flashing eyes, his floating hair!"
poem4Line15 = "Weave a circle round him thrice,"
poem4Line16 = "And close your eyes with holy dread,"
poem4Line17 = "For he on honey-dew hath fed"
poem4Line18 = "And drunk the milk of Paradise."

poem5Lyrics = [poem4Line1,poem4Line2,poem4Line3,poem4Line4,poem4Line5,poem4Line6,poem4Line7,poem4Line8,poem4Line9,poem4Line10,poem4Line11,poem4Line12,poem4Line13,poem4Line14,poem4Line15,poem4Line16,poem4Line17,poem4Line18,blank,blank]

poem5Line1 = "And on the pedestal"
poem5Line2 = "these words appear:"
poem5Line3 = "'My name is Ozymandias, "
poem5Line4 = "king of kings:"
poem5Line5 = "Look on my works, "
poem5Line6 = "ye Mighty, and despair!'"
poem5Line7 = "Nothing beside remains."
poem5Line8 = "Round the decay"
poem5Line9 = "Of that colossal wreck,"
poem5Line10 = "boundless and bare" 
poem5Line11 = "The lone and level sands"
poem5Line12 = "stretch far away.'"

poem4Lyrics = [poem5Line1,poem5Line2,poem5Line3,poem5Line4,poem5Line5,poem5Line6,poem5Line7,poem5Line8,poem5Line9,poem5Line10,poem5Line11,poem5Line12,blank,blank]

class poemClass:
    currentColour = 0
    currentLine = 0
    moreLines = 1
    poem = None
    x = 0
    y = 0
    startTime = 600
    lineTime= startTime
    timeToColourChange = 5
    timeToPositionChange = 5
    font = None
    timeToFontChange = 10   
    go = 0
    
    def __init__(self,poem):
        self.poem = poem
    
    def setUp(self,controlFlag = 0):
        self.currentColour = 0
        self.currentLine = 0
        self.moreLines = 1
        #self.x = game.random.randint(380,420)
        #self.y = 110
        
        if controlFlag:
            self.x = game.random.randint(200,600)
            self.y = game.random.randint(100,600)
            font = game.random.randint(1,3)
        else:  
            self.x = game.random.randint(380,420)
            self.y = 110
            font = game.random.randint(0,2)

#        font = game.random.randint(1,3)
        self.startTime = 600
        self.lineTime= self.startTime
        self.timeToColourChange = 5
        self.timeToPositionChange = 5 
        self.font = game.font36
        self.go = 0
        
    def render(self,controlFlag = 0):
        if self.moreLines:
            if self.lineTime <256:
                alpha = self.lineTime*0.5
            elif self.lineTime > self.startTime-256:
                alpha =  game.clamp255(self.startTime - self.lineTime-128)
            else:    
                alpha = 128
            line = self.poem[self.currentLine]
            if self.font == None:
                self.font = game.font36
            #if controlFlag:
            #    alpha *= .9
            game.game.pallet.setColourByIndex(self.currentColour,alpha)
            game.drawStringCentred(line,self.x,self.y,self.font)
            
    def tick(self,delta,controlFlag = 0): 
        if self.go:
            self.lineTime -= delta
            if self.lineTime<=0:
                self.go -= 1
                if self.go<0:
                    self.go = 0
                self.lineTime = self.startTime
                if self.currentLine < len(self.poem)-1:
                    self.currentLine += 1
                else:
                    self.currentLine = 0
                if controlFlag:
                    self.x = game.random.randint(200,600)
                    self.y = game.random.randint(100,600)
                    font = game.random.randint(1,3)
                else:  
                    self.x = game.random.randint(380,420)
                    self.y = 110
                    font = game.random.randint(0,2)
                if font == 0:
                    self.font = game.font26
                elif font == 1:
                    self.font = game.font30 
                elif font == 2:
                    self.font = game.font36 
                else:
                    self.font = game.font44
          
            self.timeToColourChange -= delta
            if self.timeToColourChange <= 0:
                self.currentColour = game.random.randint(2,4)
                self.timeToColourChange = game.random.randint(3,30)
            self.timeToPositionChange -= delta
            if self.timeToPositionChange <= 0:
                self.x += game.random.randint(-2,2)
                self.y += game.random.randint(-3,2)
                self.timeToPositionChange = game.random.randint(1,4)    

    def startLine(self):
        self.go += 1

poem1 =  poemClass(poem1Lyrics)     
poem2 =  poemClass(poem2Lyrics) 
poem3 =  poemClass(poem3Lyrics)
poem4 =  poemClass(poem4Lyrics)
poem5 =  poemClass(poem5Lyrics)

levelPoems = [poem1,poem2,poem3,poem4,poem5]
