-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.js
94 lines (85 loc) · 2.64 KB
/
functions.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"use strict";
waw.deepCopy = function(o) {
var copy = o,k;
if (o && typeof o === 'object') {
copy = Object.prototype.toString.call(o) === '[object Array]' ? [] : {};
for (k in o) {
copy[k] = waw.deepCopy(o[k]);
}
}
return copy;
};
//pick random item from array
waw.pickRandomArray = function(a) {
if(a.length<1)
return null;
return a[Math.round(Math.random()*(a.length-1))];
};
//random X Y coords in the room
waw.pickSafeRandomX = function() {
return Math.round(50 + Math.random() * 220);
};
waw.pickSafeRandomY = function() {
return Math.round(40 + Math.random() * 130);
};
waw.pickRandomEdgeCoord = function() {
var x,y;
if(Math.random()<0.5){
x = Math.round(Math.random()*320);
y = Math.round()<0.5 ? 0 : 240;
} else {
y = Math.round(Math.random()*240);
y = Math.round()<0.5 ? 0 : 320;
}
return cc.p(x,y);
};
waw.pickPlayersBackCoord = function(obj, n) {
var x = obj.x, y = obj.y;
var px = waw.player.x, py = waw.player.y;
if(x < px)
x = px + n;
else
x = px - n;
if(y < py)
y = py + n;
else
y = py - n;
return cc.p(x,y);
};
waw.RandomPlusMinus = function(n) {
return n - Math.round(Math.random()*2*n);
};
//prowide width and height of the spritesheet frame
//and get a function that returns correct frame rect by its COLUMN, ROW
waw.SpriteRect = function(w, h) {
return function(x , y) {
return cc.rect(1+(w+2)*x, 1+(h+2)*y, w, h);
};
};
waw.makeSpriteJump = function(sprite) {
sprite.runAction(
new cc.RepeatForever(
new cc.Sequence(
new cc.JumpBy(0.3, 0, 0, 2, 1),
new cc.JumpBy(0.2, 0, 0, 1, 1),
new cc.DelayTime(1 + Math.random() * 3)
)
)
)
};
waw.wipeMobsItemsOffScreen = function() {
for (var i = 0; i < waw.mobs.length; i++) {
if (waw.mobs) {
waw.mobs[i].shadowSprite.visible = false;
waw.mobs[i].sprite.runAction(new cc.MoveTo(0.5 + Math.random(), waw.mobs[i].x < 160 ? -40 : 360, waw.mobs[i].y < 120 ? -40 : 280));
waw.mobs[i].runAction(new cc.RotateBy(0.5 + Math.random(), Math.random() < 0.5 ? -180 : 180));
}
}
for (var i = 0; i < waw.items.length; i++) {
if (waw.items) {
waw.items[i].shadowSprite.visible = false;
waw.items[i].sprite.runAction(new cc.MoveTo(0.5 + Math.random(), waw.items[i].x < 160 ? -40 : 360, waw.items[i].y < 120 ? -40 : 280));
waw.items[i].runAction(new cc.RotateBy(0.5 + Math.random(), Math.random() < 0.5 ? -180 : 180));
}
}
};