import pygame
import random
from pygame.locals import *
from sys import exit
mouse_image_filename="ojizousan2.png"
pygame.init()
background_image_filename = 'j.jpg'
filename = 'ojizousan2.png'
filename2 = 'ohagi2.png'
screen = pygame.display.set_mode((640,480),0,32)
background = pygame.image.load(background_image_filename).convert()
ohagiconv = pygame.image.load(background_image_filename).convert()
mouse_cursor = pygame.image.load(mouse_image_filename).convert_alpha()
ohagi = pygame.image.load(filename2).convert_alpha()
xx = random.random()*480
yy = 0
x,y = 0, 0
move_x,move_y = 0, 0
mpos = pygame.mouse.get_pos()
dd = 1
ff = 1
score = 0

score = 1
while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            exit()
        if event.type == KEYDOWN:
            exit()

    
    screen.blit(background, (0,0))
    mpos = pygame.mouse.get_pos()
    x, y = pygame.mouse.get_pos()
    x -= mouse_cursor.get_width() /2
    y -= mouse_cursor.get_height() /2
    
    botamoti = 2
    #screen.fill((0,0,0))
    screen.blit(mouse_cursor,(x,y))
    yy = yy + 1.0
    if yy > 480:
        print("deta")
        yy = 0
        xx = random.random()*200
    print(yy,xx)
    print("ss")
        #if x > xx and y > yy and x +100 < xx + 100 and y + 100 < yy + 220: 
    if  mpos[0] < (xx + 55) and mpos[1] < (yy + 55) and mpos[0] > xx and mpos[1] > yy:
        xx = yy = 0
        score = score + 1 
        xx = random.random()*480
        print("ok")
        
        ff = 0
    else:
        screen.blit(ohagi,(xx,yy)) 
        print("else")
        #if mpos[0] > 220 and mpos[1] > 100 and mpos[0] < 325 and mpos[1] < 130 and pygame.mouse.get_pressed()[0] == 1 :
        if event.type == KEYDOWN:
            if event.key == K_LEFT:
                move_x = -1
            elif event.key == K_RIGHT:
                move_x = +1
            elif event.key == K_UP:
                move_y = -1
            elif event.key == K_DOWN:
                move_y = +1
            elif event.key == K_ESCAPE:
                main()
        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

        x=+move_x
        y=+move_y
    
    print(mpos)
    font  = pygame.font.Font(None,33)
    text = font.render("SCORE"+ str(score),False,(0,0,0))

    screen.blit(text,(1,1)) 
    pygame.display.update()



