#NeoPeewee Pygame Engine (January 4, 2020)

import pygame

#Import Global Memory
from Scripts import Global

class Main:
    def __init__(this):
        #Main Variables
        this.state = 1
        this.doControls = 1
        this.doGraphics = 1
        this.alarm = [0, 0]
        #Class Variables

    #Main Control Method
    def Control(this, leftpress, rightpress, uppress, downpress, zpress, xpress):
        #Manage Alarms
        for i in range(len(this.alarm)):
            if this.alarm[i] > 0:
                this.alarm[i] -= 1
                if this.alarm[i] == 0:
                    #Go to Main Menu
                    if i == 0:
                        this.state = 2
                        this.doControls = 1
                        Global.audio.StartMusic('Sounds/Music/Town_Theme_Busy.mp3')
                    #Disable the state and activate the shop
                    if i == 1:
                        this.state = 0
                        Global.audio.ReplaceMusic('Sounds/Music/Town_Theme_Minimal.mp3')
                        this.doControls = 1
                        Global.shop.state = 3
                        Global.shop.text = ['...My very own shop!',
                                            'Now that I’ve graduated my apprenticeship, I can now open my own#storefront.',
                                            'It’s all mine - no one can tell me what to do!',
                                            'This village hasn’t had a resident alchemist in decades.',
                                            'Finally!',
                                            '.....',
                                            '*Floorboards that creak with every step.*',
                                            '*Ceiling-high shelves filled with broken bottles, burned books, and#jars of long-expired ingredients.*',
                                            '*A thick layer of dust covering every surface.*',
                                            '.....',
                                            'There’s not much else to do but get to work.',
                                            '(TRANSITION)',
                                            'I feel like every time I blink after sweeping these floors, a new layer#of dust appears.',
                                            'All these books look like they were the victims of a fireblast potion.',
                                            '*The door slowly opens*',
                                            '"My first customer?!"',
                                            'Welcome to ALCHEMY, is there anything I can help you wi -',
                                            '"A knight from the castle! I’ve only ever seen them in story books."',
                                            '*the knight unsheathes his sword...*',
                                            '*It becomes quickly apparent that the sword is dull, both in its blunt#edges and without its metallic gleam.*',
                                            'Ah… Is there anything you need from me, Knight?',
                                            'Yves the Kind: While I was fighting a magical beast, it devoured the#protection enchantment from my sword.',
                                            'Yves the Kind: The blade used to glimmer and shine... It’s never#been the same since.',
                                            'A protection enchantment... That requires a mermaid scale and#spine flower berries.',
                                            'Come back soon, and I’ll have your order prepared.',
                                            'Yves the Kind: Thank you, Alchemist.',
                                            '(ORDER)']

        #Do Controls
        if this.doControls == 1:
            if zpress == 1:
                this.doControls = 0
                Global.DoTransition(Global, 10)
                if this.state == 1:
                    this.alarm[0] = 10
                else:
                    this.alarm[1] = 10

        #Do Graphics
        if this.doGraphics == 1:
            if this.state == 1:
                Global.screen.fill((0, 0, 0))
                Global.TextDisplay(Global, 1, (255, 255, 255), 16, 16, 'Project Alchemy: Made by')
                Global.TextDisplay(Global, 1, (255, 255, 255), 20, 32, 'Douglas Wetmore (NeoPeewee) - Coding & Graphics')
                Global.TextDisplay(Global, 1, (255, 255, 255), 20, 48, 'Nikki McIntyre - Music')
                Global.TextDisplay(Global, 1, (255, 255, 255), 20, 64, '& Veronica Hatala - Writing & Concepts')
                Global.TextDisplay(Global, 1, (255, 255, 255), 20, 80, 'Use the arrow keys, Z key and X key to play.')
                Global.TextDisplay(Global, 1, (255, 255, 255), 3, 226, 'Press Z to continue')
            if this.state == 2:
                Global.screen.blit(Global.graphics.shop, (0, 0))
                Global.TextDisplay(Global, 2, (255, 255, 255), 220, 6, 'PROJECT ALCHEMY')
                Global.TextDisplay(Global, 2, (0, 0, 0), 221, 7, 'PROJECT ALCHEMY')
                Global.TextDisplay(Global, 1, (0, 0, 0), 3, 206, 'Press Z to start game.')
