-
Notifications
You must be signed in to change notification settings - Fork 2
/
dust.js
72 lines (64 loc) · 2.36 KB
/
dust.js
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
var DustParticle = function() {
this.segment = new Segment(0,0);
this.state = false;
this.type = 0; // 0,1,2 or 3 to alternate sprites
this.counter = 0; // life counter
this.animationCounter = new Animate(0,0,0);
}
/* Dust particle processor */
var DUST_MAX = 30;
var dustparticle = new Array();
var dust_idx = 0;
$(document).ready(function() {
for (var i = 0; i < DUST_MAX; i++)
dustparticle[i] = new DustParticle(0, 0, 16);
});
function add_dustparticle(xx,yy) {
dust_idx++;
if (dust_idx >= DUST_MAX)
dust_idx = 0;
dustparticle[dust_idx].segment = new Segment(xx,yy+Math.random()*4,10,10);
dustparticle[dust_idx].state = true;
if (Math.floor(Math.random()*2)==0)
dustparticle[dust_idx].animationCounter = 1;
}
function proc_dustparticle() {
for (var i = 0; i < DUST_MAX; i++) {
if (dustparticle[i].state == true) {
//dustparticle[i].segment.x += dustparticle[i].segment.vecx * 0.25;
dustparticle[i].segment.y -= 0.1;
// apply gravity
//dustparticle[i].segment.vecy += 0.3;
dustparticle[i].counter++;
//if (dustparticle[i].counter % 100 == 0) {
// var s = dustparticle[i].segment.normal();
// var n = s.unit();
// add_dustet( s );
// }
//
if (dustparticle[i].counter >= 140) {
dustparticle[i].counter = 0;
dustparticle[i].state = false;
// Reset animation counter
dustparticle[i].animationCounter.animationCurrentFrame = 0;
dustparticle[i].animationCounter.animationDelay = 0;
dustparticle[i].animationCounter.animationIndexCounter = 0;
}
}
}
}
function draw_dustparticle() {
for (var i = 0; i < DUST_MAX; i++) {
if (dustparticle[i].state == true) {
dust.rotAnim2(
dustparticle[i].segment.x,
grid.y + dustparticle[i].segment.y,
[0, 1, 2, 3, 4, 5, 6, 7],
0, // angle
16, // each dust particle is 16x16
8, // # of sprites per width of the spritesheet
15, // animation delay, for how long to display this frame before going to next?
dustparticle[i].animationCounter); // its own custom animation counter object
}
}
}