#!/usr/bin/python3

import random

import pygame
from pygame.sprite import Sprite
from load import Load

class Sailor_Jupitor(Sprite):
    def __init__(self, game):
        """initializes the memory sailor mercury"""
        super().__init__()
        
        #screen set up:
        self.screen = game.screen
        self.screen_rect = self.screen.get_rect()

        #loads
        self.write = game.load.write_difference

        #flags
        self.delay = 0

        #images
        self.stage = 1

        self.jupitor_idle2 = []
        self.jupitor_idle2.append(pygame.image.load('sailor_jupitor/sailor_jupitor_idle2-1.png'))
        self.jupitor_idle2.append(pygame.image.load('sailor_jupitor/sailor_jupitor_idle2-2.png'))
        self.jupitor_idle2.append(pygame.image.load('sailor_jupitor/sailor_jupitor_idle2-3.png'))
        self.jupitor_idle2.append(pygame.image.load('sailor_jupitor/sailor_jupitor_idle2-4.png'))
        
        self.current_idle2 = 0

        self.jupitor_idle3 = []
        self.jupitor_idle3.append(pygame.image.load('sailor_jupitor/sailor_jupitor_idle3.png'))
        
        self.current_idle3 = 0

        self.jupitor_idle4 = []
        self.jupitor_idle4.append(pygame.image.load('sailor_jupitor/sailor_jupitor_idle4-1.png'))
        self.jupitor_idle4.append(pygame.image.load('sailor_jupitor/sailor_jupitor_idle4-2.png'))
        self.jupitor_idle4.append(pygame.image.load('sailor_jupitor/sailor_jupitor_idle4-3.png'))
        self.jupitor_idle4.append(pygame.image.load('sailor_jupitor/sailor_jupitor_idle4-4.png'))
        self.jupitor_idle4.append(pygame.image.load('sailor_jupitor/sailor_jupitor_idle4-5.png'))
        self.jupitor_idle4.append(pygame.image.load('sailor_jupitor/sailor_jupitor_idle4-6.png'))
        
        self.current_idle4 = 0

        self.jupitor_shock1 =[]
        self.jupitor_shock1.append(pygame.image.load('sailor_jupitor/sailor_jupitor_shock1-1.png'))
        self.jupitor_shock1.append(pygame.image.load('sailor_jupitor/sailor_jupitor_shock1-2.png'))
        self.jupitor_shock1.append(pygame.image.load('sailor_jupitor/sailor_jupitor_shock1-3.png'))
        self.jupitor_shock1.append(pygame.image.load('sailor_jupitor/sailor_jupitor_shock1-4.png'))
        self.jupitor_shock1.append(pygame.image.load('sailor_jupitor/sailor_jupitor_shock1-5.png'))
        self.jupitor_shock1.append(pygame.image.load('sailor_jupitor/sailor_jupitor_shock1-6.png'))
        self.jupitor_shock1.append(pygame.image.load('sailor_jupitor/sailor_jupitor_shock1-7.png'))

        self.current_shock1 = 0

        self.jupitor_shock2 = []
        self.jupitor_shock2.append(pygame.image.load('sailor_jupitor/sailor_jupitor_shock2-1.png'))
        self.jupitor_shock2.append(pygame.image.load('sailor_jupitor/sailor_jupitor_shock2-2.png'))
        self.jupitor_shock2.append(pygame.image.load('sailor_jupitor/sailor_jupitor_shock2-3.png'))
        self.jupitor_shock2.append(pygame.image.load('sailor_jupitor/sailor_jupitor_shock2-4.png'))
        self.jupitor_shock2.append(pygame.image.load('sailor_jupitor/sailor_jupitor_shock2-5.png'))
        self.jupitor_shock2.append(pygame.image.load('sailor_jupitor/sailor_jupitor_shock2-6.png'))
        self.jupitor_shock2.append(pygame.image.load('sailor_jupitor/sailor_jupitor_shock2-7.png'))
        self.jupitor_shock2.append(pygame.image.load('sailor_jupitor/sailor_jupitor_shock2-8.png'))

        self.current_shock2 = 0

        #sets image and rect
        self.image = self.jupitor_idle2[self.current_idle2]
        self.rect = self.image.get_rect()


        #places image and rect in correct location
        self.rect.midright = game.sailor_mercury.rect.midleft
        self.rect.x += 45
        self.rect.y = game.sailor_moon.rect.y
        self.rect.y -= 5
    
   
    def update(self, game):
        if self.write >= 0 and self.write < 10:
            if self.stage == 3:
                self.stage = 1

            elif self.stage == 2:
                self.stage = 1
            
            elif self.stage == 1:
                if self.current_idle2 >= len(self.jupitor_idle2):
                    self.current_idle2 = 0
                    #self.write = game.write_difference
            
                self.image = self.jupitor_idle2[self.current_idle2]
                self.current_idle2 += 1
                self.write = game.write_difference

        if self.write >=10 and self.write < 20:
            if self.stage == 1:
                if self.current_shock1 >= len(self.jupitor_shock1):
                    self.current_shock1 = 0
                    self.stage = 2

                if self.stage == 1:
                    self.image = self.jupitor_shock1[self.current_shock1]
                    self.current_shock1 += 1

            elif self.stage == 2:
                self.image = self.jupitor_idle3[self.current_idle3]
                self.delay += 1
                if self.delay == 5:
                    self.delay = 0
                    self.write = game.write_difference

            elif self.stage == 3:
                self.stage = 2

        if self.write >= 20:
            if self.stage == 1:
                if self.current_shock1 >= len(self.jupitor_shock1):
                    self.current_shock1 = 0
                    self.stage = 2

                if self.stage == 1:
                    self.image = self.jupitor_shock1[self.current_shock1]
                    self.current_shock1 += 1

            elif self.stage == 2:
                if self.current_shock2 >= len(self.jupitor_shock2):
                    self.current_shock2 = 0
                    self.stage = 3

                if self.stage == 2:
                    self.image = self.jupitor_shock2[self.current_shock2]
                    self.current_shock2 += 1

            elif self.stage == 3:
                if self.current_idle4 >= len(self.jupitor_idle4):
                    self.current_idle4 = 0
                    self.write = game.write_difference

                self.image = self.jupitor_idle4[self.current_idle4]
                self.current_idle4 += 1
