import pygame
from pygame.locals import *
from sys import exit
import random
import datetime
import time
import out
mouse_image_filename="ojizousan2.png"
background_image_filename = 'j.jpg'
def main():
    pygame.init()
    screen = pygame.display.set_mode((640,480),0,32)
    background = pygame.image.load(background_image_filename).convert()
    screen.fill((255,255,255))

    black = [  0,  0,  0]
    #screen.blit(background,(0,0)) 
    while True:
        for event in pygame.event.get():
            print(event)
            if event.type == QUIT:
                exit()
            if event.type == KEYDOWN:
                exit() 

        pygame.draw.circle(screen, (0,0,0), (32,24), 100)
        sprite_image_filename3= 'ojizousan3.png'
        pressed_mouse = pygame.mouse.get_pressed()
    #sprite = pygame.image.load(sprite_image_filename3)
    #sprite = pygame.image.load(sprite_image_filename3).convert_alpha()
        #text = font.render('kasajizou1', False, (55,255,255))
        #screen.blit(text,(220,50))
        #text = font.render('kasajizou2',  False, (55,255,255))
        font = pygame.font.Font(None, 32)
        text = font.render('kasajizou1', False, (55,255,255))
        screen.blit(text,(220,100))
        text = font.render('kasajizou2', False, (55,255,255))
        screen.blit(text,(220,150))
        text = font.render('jizoumove', False, (55,255,255))
        screen.blit(text,(220,200))
        text = font.render('jizoumove2', False, (55,255,255))
        screen.blit(text,(220,250))
        text = font.render('Game', False, (55,255,255))
        screen.blit(text,(220,300))
        text = font.render('Quit', False, (55,255,255))
        screen.blit(text,(220,350))
        #pygame.mouse.set_visible(False)
        #pygame.event.set_grab(True)
        rotation_direction = pygame.mouse.get_rel()[0] / 5.
        mpos = pygame.mouse.get_pos()
        #print(mpos)
        pygame.display.update()
#        print(pygame.mouse.get_pos())  
        #pygame.draw.rect(screen, (255,0,0), Rect(10,10,300,200))
        if mpos[0] > 220 and mpos[1] > 100 and mpos[0] < 325 and mpos[1] < 130 and pygame.mouse.get_pressed()[0] == 1 :
            jizouanime("ojizousan4.png")
        if mpos[0] > 220 and mpos[1] > 150 and mpos[0] < 325 and mpos[1] < 170 and pygame.mouse.get_pressed()[0] == 1 :
            jizouanime("ojizousanmarins.png")
        if mpos[0] > 220 and mpos[1] > 200 and mpos[0] < 325 and mpos[1] < 220 and pygame.mouse.get_pressed()[0] == 1 :
            jizoumove()
        if mpos[0] > 220 and mpos[1] > 250 and mpos[0] < 325 and mpos[1] < 270 and pygame.mouse.get_pressed()[0] == 1 :
            jizoumove2()
        if mpos[0] > 220 and mpos[1] > 300 and mpos[0] < 325 and mpos[1] < 320 and pygame.mouse.get_pressed()[0] == 1 :
           out.obgameout()
        if mpos[0] > 220 and mpos[1] > 350 and mpos[0] < 325 and mpos[1] < 370 and pygame.mouse.get_pressed()[0] == 1 :
            exit()
def jizouanime(jizou6):
    #!/usr/bin/env python
    # -*-coding:utf8-*-
    background_image_filename = 'j.jpg'
    sprite_image_filename= 'ojizousan3.png'
    sprite_image_filename4 = 'ojizousan4.png'
    sprite_image_filename5 = 'empty.png'
    sprite_image_filename6 = jizou6
    sprite_image_filename3= 'ojizousan3.png'
    
    a = 0
    b = 0
    c = 0
    
    
    
    background = pygame.image.load(background_image_filename).convert()
    sprite = pygame.image.load(sprite_image_filename3).convert_alpha()
    sprite2 = pygame.image.load(sprite_image_filename4).convert_alpha()
    sprite3 = pygame.image.load(sprite_image_filename5).convert_alpha()
    sprite4 = pygame.image.load(sprite_image_filename6).convert_alpha()
    sprite5 = pygame.image.load(sprite_image_filename6).convert_alpha()
    #sprite5 = pygame.image.load(sprite_image_filename).convert_alpha()
    #sprite6 = pygame.image.load(sprite_image_filename).convert_alpha()
    clock = pygame.time.Clock()
    
    x = 0.
    i = 0.
    l = 0
    s = 0
    speed = 51.
    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                    main()
            if event.type == KEYDOWN:
                    main()

        screen = pygame.display.set_mode((640,480))
        screen.blit(background,(0,0))
        screen.blit(sprite,(s,150))
        screen.blit(sprite,(s-120,150))
        screen.blit(sprite,(s-220,150))
        screen.blit(sprite,(s-320,150))
        screen.blit(sprite,(s-420,150))
        screen.blit(sprite4,(s-520,150))
        time_passed = clock.tick()
        time_passed_seconds = time_passed / 1000.0

        distance_moved = time_passed_seconds * speed
        s += distance_moved
        #screen.blit(sprite3,(s,150))
        #print str(x) + "x"
        #print "time_passed" + str(time_passed )
        #print distance_moved
        #print str(s) + "s"
        #print x
        #if s > 120:
        #   screen.blit(sprite2,(x-s,150))
            
        #x+= 1 
      
        if s > 1240.:
          s = 0.
        pygame.display.update()
    
            
    
    
def jizoumove():
            
    background_image_filename = 'j.jpg'
    filename = 'ojizousan2.png'
    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()
    mouse_cursor = pygame.image.load(mouse_image_filename).convert_alpha()

    x,y = 0, 0
    move_x,move_y = 0, 0
   
    while True:
        for event in pygame.event.get():
            #pygame.event.set_blocked([KEYDOWN,KEYUP])
            if event.type == QUIT:
                main()
        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 = 0
   
        x+=move_x
        y+=move_y
   
       #screen.fill((0,0,0))
        screen.blit(background,(0,0))
        screen.blit(jizou,(x,y))
   
        pygame.display.update()
def jizoumove2():
            
    pygame.init()
    background_image_filename = 'j.jpg'
    filename = 'ojizousan2.png'
    screen = pygame.display.set_mode((640,480),0,32)
    background = pygame.image.load(background_image_filename).convert()
    mouse_cursor = pygame.image.load(mouse_image_filename).convert_alpha()

    x,y = 0, 0
    move_x,move_y = 0, 0
   
    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                exit()

        screen.blit(background, (0,0))
        x, y = pygame.mouse.get_pos()
        x -= mouse_cursor.get_width() /2
        y -= mouse_cursor.get_height() /2

   
       #screen.fill((0,0,0))
        screen.blit(mouse_cursor,(x,y))
     
        pygame.display.update()



def jizoumove2():
            
    pygame.init()
    background_image_filename = 'j.jpg'
    filename = 'ojizousan2.png'
    screen = pygame.display.set_mode((640,480),0,32)
    background = pygame.image.load(background_image_filename).convert()
    mouse_cursor = pygame.image.load(mouse_image_filename).convert_alpha()

    x,y = 0, 0
    move_x,move_y = 0, 0
   
    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                exit()

        screen.blit(background, (0,0))
        x, y = pygame.mouse.get_pos()
        x -= mouse_cursor.get_width() /2
        y -= mouse_cursor.get_height() /2

   
       #screen.fill((0,0,0))
        screen.blit(mouse_cursor,(x,y))
     
        pygame.display.update()
"""
def obgame():
    pygame.init()
    mouse_image_filename="ojizousan2.png"
    background_image_filename = 'j.jpg'
    filename = 'ojizousan2.png'
    filename2 = 'ob.png'
    filename3 = 'ob.png'
    screen = pygame.display.set_mode((640,480),HWSURFACE,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()
    botamoti = pygame.image.load(filename3).convert_alpha()

    xx = random.random()*640
    xx2 = random.random()*640
    xx3 = random.random()*640
    yy = 0
    yy2 = 0
    yy3 = 300
    x,y = 0, 0
    move_x,move_y = 0, 0
    mpos = pygame.mouse.get_pos()
    dd = 1
    ff = 1
    score = 0
    
    score = 1
    yy2 = 200
    t1=0
    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
        
        #screen.fill((0,0,0))
        screen.blit(mouse_cursor,(x,y))
        ohagibotamoti = random.random()*10
        ob = random.random()*10 
        yy = yy + 1.0
        pygame.draw.circle(screen,(105,105,105),(int(xx),int(yy)),20)
        #screen.blit(ohagi,(xx,yy)) 
        yy2 = yy2 + 1.0
        screen.blit(botamoti,(xx2,yy2)) 
        yy3 = yy3 + 1.0
        screen.blit(botamoti,(xx3,yy3)) 
        if yy > 480:
            print("data")
            yy = 0
            xx = random.random()*640
        if yy2 > 480:
            print("data")
            yy2 = 0
            xx2 = random.random()*640
        if yy3 > 480:
            print("data")
            yy3 = 0
            xx3 = random.random()*640
        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()*640
            print("ok")
            
            ff = 0
        if  mpos[0] < (xx2 + 55) and mpos[1] < (yy2 + 55) and mpos[0] > xx2 and mpos[1] > yy2:
            xx2 = yy2 = 0
            score = score + 1 
            xx2 = random.random()*640
        if  mpos[0] < (xx3 + 55) and mpos[1] < (yy3 + 55) and mpos[0] > xx3 and mpos[1] > yy3:
            xx3 = yy3 = 0
            score = score + 1 
            xx3 = random.random()*640
            print("ok")
            #if mpos[0] > 220 and mpos[1] > 100 and mpos[0] < 325 and mpos[1] < 130 and pygame.mouse.get_pressed()[0] == 1 :
    
            x=+move_x
            y=+move_y
        
        print(mpos)
        pygame.init()
        font  = pygame.font.Font(None,33)
        scoretext = font.render("SCORE"+ str(score),False,(0,0,0))
        t1 = pygame.time.get_ticks()
        #t2 = pygame.time.Clock()
        t2 = t1 / 1000
        t3 = font.render(str(t2),False,(0,0,0))
        t4 = t2
        #t4 = 1 
        print(t3)
        if t4 ==  30:
           cong(score) 
           print("555")
        screen.blit(scoretext,(1,1)) 
        screen.blit(t3,(200,1)) 

        pygame.display.update()
    
def cong(score):
    pygame.init()
    screen = pygame.display.set_mode((640,480),0,32)
    while True:
        for event in pygame.event.get():
            print(event)
            if event.type == QUIT:
                exit()
            if event.type == KEYDOWN:
                exit() 

        font  = pygame.font.Font(None,53)
        scoretext = font.render(("Omedetou"),False,(2,200,0))
        scoretext2 = font.render((str(score) + "point"),False,(2,200,0))
        background_image_filename = 'b.png'
        background = pygame.image.load(background_image_filename).convert()
        mpos = pygame.mouse.get_pos()
        screen.blit(background,(0,0)) 
        screen.blit(scoretext,(200,200)) 
        screen.blit(scoretext2,(200,300)) 
        text = font.render('Quit', False, (55,255,255))
        screen.blit(text,(220,350))
        if mpos[0] > 220 and mpos[1] > 350 and mpos[0] < 325 and mpos[1] < 370 and pygame.mouse.get_pressed()[0] == 1 :
            exit()
        pygame.display.update()

"""  
main()
