#<F11><F11:wq
import pygame 
from pygame.locals import *
from sys import exit
import random
import datetime
import time
filename="ojizousan2.png"
filename2="tesita2.png"
filename3="kougeki.png"
filename4="bougyo.png"
filename5="nigeru.png"
filename6="kougeki2.png"
filename7="bougyo2.png"
filename8="nigeru2.png"
background_image_filename = 'j.png'
def main():
            

    pygame.init()
    screen = pygame.display.set_mode((640,480),0,32)
    background = pygame.image.load(background_image_filename).convert()
    jizou = pygame.image.load(filename).convert_alpha()

    s = 0
    x2 = 0
    y2 = 0
    x,y = 0, 100
    move_x,move_y = 0, 0
    r  =  random.random()*10
   
    while True:
        for event in pygame.event.get():
            #pygame.event.set_blocked([KEYDOWN,KEYUP])
            if event.type == QUIT:
                exit()
        if event.type == KEYDOWN:
            if event.key == K_LEFT:
                move_x = -0.1
            elif event.key == K_RIGHT:
                move_x = +0.1
            elif event.key == K_UP:
                move_y = -0.1
            elif event.key == K_DOWN:
                move_y = +0.1
            elif event.key == K_ESCAPE:
                exit()
        elif event.type == KEYUP:
            if event.key == K_LEFT:
                move_x = 0
            elif event.key == K_RIGHT:
                move_x = 0
            elif event.key == K_UP:
                move_y = 0
            elif event.key == K_DOWN:
                move_y = 0
   
        x+=move_x
        y+=move_y
        print(move_x)
        if move_x == 0.1 or  move_y == 0.1 or move_x == -0.1 or move_y == -0.1:
        #if move_x >= 1 or  y >= 1 or y <= 1 or x <= 1 :
            s = s + 1
            print(s)
        else:
        
            print("h")
        if s == (10 + int(r*100)):
            sentou()
            
       #screen.fill((0,0,0))
        screen.blit(background,(0,0))
        screen.blit(jizou,(x,y))
   
        pygame.display.update()
"""
class Player():
    def __init__(self,name):
        self.name = name
        self.hp = hp
        self.
        """
    
    
def sentou():
    pygame.init()
    background_image_filename = "sentou.png"
    screen = pygame.display.set_mode((640,480),0,32)
    background = pygame.image.load(background_image_filename).convert()
    jizou = pygame.image.load(filename).convert_alpha()
    tesita = pygame.image.load(filename2).convert_alpha()
    k = pygame.image.load(filename3).convert_alpha()

    b = pygame.image.load(filename4).convert_alpha()
    n = pygame.image.load(filename5).convert_alpha()
    k2 = pygame.image.load(filename6).convert_alpha()

    b2 = pygame.image.load(filename7).convert_alpha()
    n2 = pygame.image.load(filename8).convert_alpha()
    x,y = 100, 200 
    x2,y2 = 600, 200 
    tesita_x,tesita_y = 400, 200
    move_x,move_y = 0, 0
    c = 1
   
    while True:
        for event in pygame.event.get():
            #pygame.event.set_blocked([KEYDOWN,KEYUP])
            if event.type == QUIT:
                exit()
        if event.type == KEYDOWN:
            if event.key == K_ESCAPE:
                exit()
            elif event.key == K_UP:
                y2 = y2 - 10
                x2 = x2 - 10
            elif event.key == K_DOWN:
                y2 = 10
                x2 = 10

                """
            elif event.key == K_UP:
                pygame.draw.rect(screen,(255,255,255),(60,300,100,20),5)
            elif event.key == K_DOWN:
                pygame.draw.rect(screen,(255,255,255),(60,320,80,20),2)
                """

        hp =16
        mp =10
        tuyosa = 5
        gp = 0
        tesita_hp=10
        screen.blit(background,(0,0))
   
        screen.blit(jizou,(x,y))
        screen.blit(tesita,(tesita_x,tesita_y))
        font = pygame.font.Font(None,32)
        pygame.draw.rect(screen,(0,0,0),(20,20,150,150))
        font = pygame.font.Font(None,32)
        text = font.render(str(hp),False,(255,255,255))
        screen.blit(text,(30,120))
        text = font.render(str(mp),False,(255,255,255))
        screen.blit(text,(60,120))
        font = pygame.font.Font(None,32)
        text = font.render("HP",False,(255,255,255))
        screen.blit(text,(20,100))
        text = font.render("MP",False,(255,255,255))
        screen.blit(text,(60,100))
        pygame.draw.rect(screen,(0,0,0),(20,300,150,150))
        screen.blit(k,(300,60))
        screen.blit(b,(320,60))
        screen.blit(n,(340,60))
        pygame.draw.rect(screen,(255,255,255),(x2,y2,100,20),5)
        print(x2)
        """
        pygame.draw.rect(screen,(255,255,255),(60,320,80,20),2)
        pygame.draw.rect(screen,(255,255,255),(60,340,80,20),2)
        """
        text = font.render("kougeki",False,(255,255,255))
        screen.blit(text,(60,300))
        text = font.render("bougyo",False,(255,255,255))
        screen.blit(text,(60,320))

        def kougeki():
            r2 = int(r)
            if r2 >= 7:
                damege = tuyosa + 1
            elif r2 >= 3:
                damege = tuyosa + 3
            elif r2 >= 0:
                damege = tuyosa + 5

        pygame.display.update()
        
        

def up():
    pygame.draw.rect(screen,(255,255,255),(60,300,100,20),5)
def down():
    pygame.draw.rect(screen,(255,255,255),(60,300,100,20),5)

main()
