-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClockAvatarNumber.pde
194 lines (171 loc) · 5.92 KB
/
ClockAvatarNumber.pde
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
PVector[] ArrPos_ClockNum={new PVector(0,0),new PVector(1,0),new PVector(2,0),new PVector(3,0),new PVector(4,0),
new PVector(0,1),new PVector(4,1),
new PVector(0,2),new PVector(1,2),new PVector(2,2),new PVector(3,2),new PVector(4,2),
new PVector(0,3),new PVector(4,3),
new PVector(0,4),new PVector(1,4),new PVector(2,4),new PVector(3,4),new PVector(4,4)};
class ClockAvatarNumber{
int cur_num=-1;
int dest_num=-1;
ArrayList<PVector> arr_num_pos;
ArrayList<ClockAvatar> arr_avatar;
ImageSeq img_seq;
FrameAnimation anima_pos,anima_change;
ClockAvatarNumber(int set_num){
arr_num_pos=new ArrayList<PVector>();
arr_avatar=new ArrayList<ClockAvatar>();
img_seq=new ImageSeq(6);
img_seq.play();
/* Go out every 10 sec */
anima_pos=new FrameAnimation(180);
// anima_pos.is_loop=true;
anima_change=new FrameAnimation(90);
updateNum(set_num);
}
void addAvatar(int aindex,int findex,PImage fimage){
arr_avatar.add(new ClockAvatar(findex,fimage,arr_num_pos.get(aindex),
new PVector(arr_num_pos.get(aindex).x+random(5,10)*(random(2)<1?1:-1),arr_num_pos.get(aindex).y+random(5,10)*(random(2)<1?1:-1))));
}
void updateAvatar(int aindex){
printlnA("Update Clock Avatar: "+aindex);
ClockAvatar _avatar=arr_avatar.get(aindex);
try{
_avatar.updatePos(arr_num_pos.get(aindex),
new PVector(arr_num_pos.get(aindex).x+random(5,10)*(random(2)<1?1:-1),arr_num_pos.get(aindex).y+random(5,10)*(random(2)<1?1:-1)));
}catch(Exception e){
printlnA("Update Pos Exception: "+e.getMessage());
}
}
void removeAvatar(int aindex){
printlnA("Rmv Clock Avatar: "+aindex);
arr_avatar.get(aindex).gotoDie(anima_pos.GetPortion());
}
void startChange(){
// anima_change.setDue(min(90,180-180*anima_change.GetPortion()));
anima_change.Restart();
}
void start(){
anima_pos.Restart();
img_seq.play();
}
void pause(){
anima_pos.Pause();
img_seq.pause();
}
void update(){
anima_pos.Update();
img_seq.update();
anima_change.Update();
if(anima_change.GetPortion()==1) cur_num=dest_num;
// for(ClockAvatar c:arr_avatar) c.update();
Iterator<ClockAvatar> it=arr_avatar.iterator();
while(it.hasNext()){
ClockAvatar c=it.next();
if(c.isDead()) it.remove();
}
}
int getAvatarSize(){
return arr_avatar.size();
}
int getPosSize(){
return arr_num_pos.size();
}
ClockAvatar getAvatar(int i){
return arr_avatar.get(i);
}
int getCurFrame(){
return (int)(img_seq.icur_frame);
}
float getAniPortion(){
return anima_pos.GetPortion();
}
float getChangePortion(){
return anima_change.GetPortion();
}
boolean updateNum(int set_num){
if(dest_num==set_num) return false;
if(arr_avatar.size()>0 && (getAniPortion()==1 || getAniPortion()==0)) return false;
dest_num=set_num;
arr_num_pos.clear();
// arr_avatar.clear();
switch(dest_num){
case 0:
for(int i=0;i<5;++i) arr_num_pos.add(ArrPos_ClockNum[i]);
arr_num_pos.add(ArrPos_ClockNum[5]);arr_num_pos.add(ArrPos_ClockNum[6]);
arr_num_pos.add(ArrPos_ClockNum[7]);arr_num_pos.add(ArrPos_ClockNum[11]);
arr_num_pos.add(ArrPos_ClockNum[12]);arr_num_pos.add(ArrPos_ClockNum[13]);
for(int i=14;i<19;++i) arr_num_pos.add(ArrPos_ClockNum[i]);
break;
case 1:
arr_num_pos.add(new PVector(2,0));
arr_num_pos.add(new PVector(2,1));
arr_num_pos.add(new PVector(2,2));
arr_num_pos.add(new PVector(2,3));
arr_num_pos.add(new PVector(2,4));
break;
case 2:
for(int i=0;i<5;++i) arr_num_pos.add(ArrPos_ClockNum[i]);
arr_num_pos.add(ArrPos_ClockNum[6]);
for(int i=7;i<12;++i) arr_num_pos.add(ArrPos_ClockNum[i]);
arr_num_pos.add(ArrPos_ClockNum[12]);
for(int i=14;i<19;++i) arr_num_pos.add(ArrPos_ClockNum[i]);
break;
case 3:
for(int i=0;i<5;++i) arr_num_pos.add(ArrPos_ClockNum[i]);
arr_num_pos.add(ArrPos_ClockNum[6]);
for(int i=7;i<12;++i) arr_num_pos.add(ArrPos_ClockNum[i]);
arr_num_pos.add(ArrPos_ClockNum[13]);
for(int i=14;i<19;++i) arr_num_pos.add(ArrPos_ClockNum[i]);
break;
case 4:
arr_num_pos.add(ArrPos_ClockNum[0]);arr_num_pos.add(ArrPos_ClockNum[4]);
arr_num_pos.add(ArrPos_ClockNum[5]);arr_num_pos.add(ArrPos_ClockNum[6]);
for(int i=7;i<12;++i) arr_num_pos.add(ArrPos_ClockNum[i]);
arr_num_pos.add(ArrPos_ClockNum[13]);
arr_num_pos.add(ArrPos_ClockNum[18]);
break;
case 5:
for(int i=0;i<5;++i) arr_num_pos.add(ArrPos_ClockNum[i]);
arr_num_pos.add(ArrPos_ClockNum[5]);
for(int i=7;i<12;++i) arr_num_pos.add(ArrPos_ClockNum[i]);
arr_num_pos.add(ArrPos_ClockNum[13]);
for(int i=14;i<19;++i) arr_num_pos.add(ArrPos_ClockNum[i]);
break;
case 6:
for(int i=0;i<5;++i) arr_num_pos.add(ArrPos_ClockNum[i]);
arr_num_pos.add(ArrPos_ClockNum[5]);
for(int i=7;i<12;++i) arr_num_pos.add(ArrPos_ClockNum[i]);
arr_num_pos.add(ArrPos_ClockNum[12]);arr_num_pos.add(ArrPos_ClockNum[13]);
for(int i=14;i<19;++i) arr_num_pos.add(ArrPos_ClockNum[i]);
break;
case 7:
for(int i=0;i<5;++i) arr_num_pos.add(ArrPos_ClockNum[i]);
arr_num_pos.add(ArrPos_ClockNum[6]);
arr_num_pos.add(ArrPos_ClockNum[11]);
arr_num_pos.add(ArrPos_ClockNum[13]);
arr_num_pos.add(ArrPos_ClockNum[18]);
break;
case 8:
for(int i=0;i<19;++i) arr_num_pos.add(ArrPos_ClockNum[i]);
break;
case 9:
for(int i=0;i<5;++i) arr_num_pos.add(ArrPos_ClockNum[i]);
arr_num_pos.add(ArrPos_ClockNum[5]);arr_num_pos.add(ArrPos_ClockNum[6]);
for(int i=7;i<12;++i) arr_num_pos.add(ArrPos_ClockNum[i]);
arr_num_pos.add(ArrPos_ClockNum[13]);
for(int i=14;i<19;++i) arr_num_pos.add(ArrPos_ClockNum[i]);
break;
case 11: //colon
arr_num_pos.add(new PVector(2,1));
arr_num_pos.add(new PVector(2,3));
break;
case 10:
arr_num_pos.add(new PVector(3,0));
arr_num_pos.add(new PVector(2.5,1));
arr_num_pos.add(new PVector(2,2));
arr_num_pos.add(new PVector(1.5,3));
arr_num_pos.add(new PVector(1,4));
break;
}
return true;
}
}