-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweather.js
More file actions
70 lines (65 loc) · 2.01 KB
/
Copy pathweather.js
File metadata and controls
70 lines (65 loc) · 2.01 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
class weather
{
constructor(typeOfWeather)
{
if (typeOfWeather == 1)
{
var drops = [];
for (var e = 0; e < 500; e++)
{
drops.push
({
x: Math.random() * world.width,
y: Math.random() * world.height,
width: 1,
height: 7
});
}
}
if(typeOfWeather == 2)
{
var drops = [];
for (var e = 0; e < 300; e++)
{
drops.push
({
x: Math.random() * world.width,
y: Math.random() * world.height,
size: Math.random() * 3,
vx: -4 + Math.random() * 5 + 2,
vy: Math.random() * 10
});
}
}
this.weatherType = function()
{
return typeOfWeather;
}
this.draw = function ()
{
if(typeOfWeather == 1)
{
ctx.fillStyle = "#F4FFFF";
for (var e = 0; e < drops.length; e++)
{
var p = drops[e];
ctx.fillRect(p.x, p.y, p.width, p.height);
p.y += 10;
if (p.y > game.height) p.y = Math.random() * game.width, p.y = -10;
}
}
if(typeOfWeather == 2)
{
ctx.fillStyle = "#FFFFFF";
for (var e = 0; e < drops.length; e++)
{
var p = drops[e];
ctx.fillRect(p.size * p.vx + p.x, p.size * p.vy + p.y, p.size, p.size);
p.x += p.vx;
p.y += p.vy;
if (p.x > world.width || p.y > world.height) p.x = Math.random() * world.width, p.y = p.size;
}
}
}
}
}