-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLuna copy.py
96 lines (94 loc) · 3.61 KB
/
Luna copy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import pyautogui
import random
import tkinter as tk
from PIL import Image,ImageTk
x = 1000
cycle = 0
check = 1
idle_num =[1,2,3,4]
sleep_num = [10,11,12,13,15]
walk_left = [6,7]
walk_right = [8,9]
event_number = random.randrange(1,3,1)
impath = 'Assets\\'
#transfer random no. to event
def event(cycle,check,event_number,x):
if event_number in idle_num:
check = 0
#print('idle')
window.after(100,update,cycle,check,event_number,x) #no. 1,2,3,4 = idle
elif event_number == 5:
check = 1
#print('from idle to sleep')
window.after(100,update,cycle,check,event_number,x) #no. 5 = idle to sleep
elif event_number in walk_left:
check = 4
#print('walking towards left')
window.after(100,update,cycle,check,event_number,x)#no. 6,7 = walk towards left
elif event_number in walk_right:
check = 5
#print('walking towards right')
window.after(100,update,cycle,check,event_number,x)#no 8,9 = walk towards right
elif event_number in sleep_num:
check = 2
#print('sleep')
window.after(100,update,cycle,check,event_number,x)#no. 10,11,12,13,15 = sleep
elif event_number == 14:
check = 3
#print('from sleep to idle')
window.after(100,update,cycle,check,event_number,x)#no. 15 = sleep to idle
#making gif work
def gif_work(cycle,frames,event_number,first_num,last_num):
if cycle < len(frames) -1:
cycle+=1
else:
cycle = 0
event_number = random.randrange(first_num,last_num+1,1)
return cycle,event_number
def update(cycle,check,event_number,x):
#idle
if check ==0:
frame = idle[cycle]
cycle ,event_number = gif_work(cycle,idle,event_number,1,9)
#idle to sleep
elif check ==1:
frame = idle_to_sleep[cycle]
cycle ,event_number = gif_work(cycle,idle_to_sleep,event_number,10,10)
#sleep
elif check == 2:
frame = sleep[cycle]
cycle ,event_number = gif_work(cycle,sleep,event_number,10,15)
#sleep to idle
elif check ==3:
frame = sleep_to_idle[cycle]
cycle ,event_number = gif_work(cycle,sleep_to_idle,event_number,1,1)
#walk toward left
elif check == 4:
frame = walk_positive[cycle]
cycle , event_number = gif_work(cycle,walk_positive,event_number,1,9)
x -= 10
#walk towards right
elif check == 5:
frame = walk_negative[cycle]
cycle , event_number = gif_work(cycle,walk_negative,event_number,1,9)
x -= -10
window.geometry('100x100+'+str(x)+'-57')
label.configure(image=frame)
window.after(1,event,cycle,check,event_number,x)
window = tk.Tk()
#call buddy's action gif
idle = [tk.PhotoImage(file=impath+'idle.gif',format = 'gif -index %i' %(i)) for i in range(8)]#idle gif
idle_to_sleep = [tk.PhotoImage(file=impath+'play.gif',format = 'gif -index %i' %(i)) for i in range(6)]#idle to sleep gif
sleep = [tk.PhotoImage(file=impath+'lick.gif',format = 'gif -index %i' %(i)) for i in range(8)]#sleep gif
sleep_to_idle = [tk.PhotoImage(file=impath+'idle.gif',format = 'gif -index %i' %(i)) for i in range(8)]#sleep to idle gif
walk_positive = [tk.PhotoImage(file=impath+'run_negative.gif',format = 'gif -index %i' %(i)) for i in range(8)]#walk to left gif
walk_negative = [tk.PhotoImage(file=impath+'run.gif',format = 'gif -index %i' %(i)) for i in range(8)]#walk to right gif
#window configuration
window.config(highlightbackground='black')
label = tk.Label(window,bd=0,bg='black')
window.overrideredirect(True)
window.wm_attributes('-transparentcolor','black')
label.pack()
#loop the program
window.after(3,update,cycle,check,event_number,x)
window.mainloop()