import pygame 
from pygame.locals import *
from sys import exit
import random
import datetime
import time
import mini
filename="ojizousan2.png"
filename2="tesita2.png"
background_image_filename = 'j.png'
basho = []
basho = [0,100]
def field(basho):
            

    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

    
    move_x,move_y = 0, 0
    r  =  random.random()*10
    xxx = basho[0]
    yyy = basho[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_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
   
        xxx+=move_x
        yyy+=move_y

        print(yyy)
        print(move_y)
        print("hhh")
        print(xxx)
        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
        else:
            print("")
        if s == (10 + int(r*100)):
            t = 1
            basho[0] = xxx + move_x
            basho[1] = yyy + move_y
            mini.sentou()
            #mini.sentou(basho[0],basho[1])
             
            
       #screen.fill((0,0,0))
        screen.blit(background,(0,0))
        screen.blit(jizou,(xxx,yyy))
        print(xxx,yyy,"jfjkdlksjf")
   
        pygame.display.update()
"""
class Player():
    def __init__(self,name):
        self.name = name
        self.hp = hp
        self.
        """
    
    
    #<F11><F11:wq

field(basho)
