-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwalk_cycle2.pde
More file actions
79 lines (61 loc) · 1.55 KB
/
walk_cycle2.pde
File metadata and controls
79 lines (61 loc) · 1.55 KB
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
ArrayList<Animation> animations;
PImage rue;
PImage ruedevant;
void setup(){
animations = new ArrayList<Animation>(); // Create an empty ArrayList
size(displayWidth, displayHeight);
frameRate(12);
rue = loadImage("rue.gif");
ruedevant = loadImage("rue2.gif");
}
void draw(){
image(rue, 0,0, displayWidth, displayHeight );
for (int i = animations.size()-1; i >= 0; i--) {
Animation animation = animations.get(i);
animation.display();
animation.move();
// if (animation.finished()) {
// Items can be deleted with remove().
// animation.remove(i);
// }
}
image(ruedevant, 0,0, displayWidth, displayHeight );
}
void mousePressed(){
animations.add(new Animation("walk_cycle", 15, mouseX-50, mouseY-75, 100, 150, 6, 3));
}
class Animation {
PImage[] images;
int imageCount;
int frame;
float xpos;
float ypos;
float xwidth;
float ywidth;
int wspeed;
int yspeed;
Animation(String imagePrefix, int count, float _xpos, float _ypos, float _xwidth, float _ywidth, int _wspeed, int _yspeed) {
xpos = _xpos;
ypos = _ypos;
xwidth = _xwidth;
ywidth = _ywidth;
wspeed =_wspeed;
yspeed = _yspeed;
imageCount = count;
images = new PImage[imageCount];
for (int i = 0; i < imageCount; i++) {
// Use nf() to number format 'i' into four digits
String filename = imagePrefix + i + ".gif";
images[i] = loadImage(filename);
}
}
void display() {
frame = (frame+1) % imageCount;
image(images[frame], xpos, ypos, xwidth, ywidth);
}
void move() {
// Add speed to y location
xpos = xpos -= wspeed;
ypos = ypos -= yspeed;
}
}