#!/usr/bin/python3

import sys

import pygame
from settings import Settings
from sailor_moon import Moon_Walk
from sailor_moon import Wand
from display_load import Walking
from load import Load

#we imported load here so take it out of sailormoon and flow the load info into sailormoon
class Sailor_Moon_Gauge:
    def __init__(self):
        pygame.init()

        self.clock = pygame.time.Clock()
        
        #flags
        self.walking = True
        self.delay = 0

        #settings
        self.settings = Settings()

        #screens
        self.screen = pygame.display.set_mode((self.settings.screen_width, self.settings.screen_height))
        self.screen_rect = self.screen.get_rect()
        self.image = pygame.image.load('backgrounds/gibson.png')
        self.rect = self.image.get_rect()

        #sprites
        self.sailor_moon_gauge_sprite = pygame.sprite.Group()
        self.sailor_moon_walking_sprite = pygame.sprite.Group()
        self.moon_walk = Moon_Walk(self)
        self.moon_wand = Wand(self)
        self.sailor_moon_walking_sprite.add(self.moon_walk)
        self.sailor_moon_gauge_sprite.add(self.moon_wand)

        #modules
        self.load = Load()
        self.walking_text = Walking(self)
        self.walking_text.prep_text(self.load)

    def check_events(self):
        """checks for events"""
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_q:
                    sys.exit()
                elif event.key == pygame.K_e:
                    self.walking = False

    def update_text(self):
        self.delay += 1
        if self.delay == 7:
            self.walking_text.update_text(self.load)
            self.delay = 0
        self.walking_text.show_text()


    def update_screen(self):
        """updates the screen"""
        self.screen.fill(self.settings.screen_color)
        self.screen.blit(self.image, self.rect)
        self.sailor_moon_walking_sprite.draw(self.screen)
        self.sailor_moon_gauge_sprite.draw(self.screen)
        self.update_text()
        pygame.display.flip()

    def run_walk(self):
        """main loop"""
        while self.walking == True:
            self.check_events()
            self.load.load_update()
            self.sailor_moon_walking_sprite.update()
            self.sailor_moon_gauge_sprite.update(self)
            self.update_screen()
            self.clock.tick(4)

#if __name__ == "__main__":
#    sailor_moon_gauge = Sailor_Moon_Gauge()
#    sailor_moon_gauge.run_game()
