Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- from pygame.locals import *
- import random
- import math
- import threading
- import sys
- import time
- from time import localtime, strftime
- #options
- number_of_blocks=15
- window_open=True
- speed=250
- if len(sys.argv)!=3:
- print "Enter valid arguments, like 'python file.py 12:56 30', where 12:56 - time, when you want run alarm, 30 - seconds of play"
- sys.exit()
- time_alarm=sys.argv[1]
- time_alarm=time_alarm.split(':')
- hours=time_alarm[0]
- minutes=time_alarm[1]
- time_of_play=int(sys.argv[2])*1000
- #init
- pygame.init()
- screen = pygame.display.set_mode((640,480))
- pygame.display.set_caption('Wake up, mazafaka')
- def wait():
- """wait for time"""
- while window_open:
- if strftime("%H", localtime())>=hours and strftime("%M", localtime()) >= minutes:
- thrd()
- break
- else: time.sleep(30)
- def music():
- try:
- pygame.mixer.music.load('music.mp3')
- except:
- print "no music file"
- sys.exit()
- pygame.mixer.music.set_volume(1)
- pygame.mixer.music.play()
- def main():
- clock=pygame.time.Clock()
- clock2=pygame.time.Clock()
- alltime=0
- data=[ random.randint(0,360) for i in range(number_of_blocks)]
- colors=[(random.randint(0,255),random.randint(0,255),random.randint(0,255)) for i in range(number_of_blocks)]
- rects=[Rect(320,240,random.randint(20,70),random.randint(20,70)) for i in range(number_of_blocks)]
- #main cicle
- while window_open:
- #x,y coordinats of our rectangle
- for event in pygame.event.get():
- pygame.mouse.set_visible(0)
- x,y=pygame.mouse.get_pos()
- try:
- me=Rect(x,y,30,30) #our rectangle and his position
- except:
- x,y=-100,-100 #the crutch
- me=Rect(x,y,30,30)
- #make main window and fill him
- screen.fill(pygame.Color(0, 0, 0, 0))
- milli = clock.tick(40)
- seconds = milli / 1000.0
- dr= int(speed*seconds)
- for i in range(number_of_blocks):
- rects[i].x+=math.cos(data[i])*dr
- rects[i].y+=math.sin(data[i])*dr
- if rects[i].x>640:
- data[i]=random.randint(140,230)
- if rects[i].y>480:
- data[i]=random.randint(50,150)
- if rects[i].x<0:
- data[i]=random.randint(-30,60)
- if rects[i].y<0:
- data[i]=random.randint(-100,-30)
- #draw other blocks
- pygame.draw.rect(screen,colors[i],rects[i])
- #draw our block
- pygame.draw.rect(screen,(255,0,0),me)
- pygame.display.update()
- if me.collidelistall(rects):
- pygame.time.wait(100)
- main()
- if pygame.mixer.music.get_busy() == False:
- pygame.mixer.music.rewind()
- pygame.mixer.music.play()
- alltime+=clock2.tick()
- if alltime>time_of_play:sys.exit()
- def thrd():
- thread1=threading.Thread(target=music)
- thread2=threading.Thread(target=main)
- thread1.start()
- thread2.start()
- def wait():
- while window_open:
- if strftime("%H", localtime())>=hours and strftime("%M", localtime()) >= minutes:
- thrd()
- break
- else: time.sleep(30)
- if __name__=='__main__':
- wait()
Advertisement
Add Comment
Please, Sign In to add comment