-
Notifications
You must be signed in to change notification settings - Fork 0
/
grass.js
58 lines (58 loc) · 1.96 KB
/
grass.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
var Main = require("./class.main.js");
module.exports = class Grass extends Main{
constructor(x, y, index){
super(x, y, index);
this.multiply = 0;
if(global.weather == "summer"){
this.multiply_interval = 12;
}else if(global.weather == "spring" || global.weather == "autumn"){
this.multiply_interval = 8;
}else if(global.weather == "winter"){
this.multiply_interval = 16;
}
}
findSlots(identifier) {
this.directions = [
[this.x - 1, this.y - 1],
[this.x, this.y - 1],
[this.x + 1, this.y - 1],
[this.x - 1, this.y],
[this.x + 1, this.y],
[this.x - 1, this.y + 1],
[this.x, this.y + 1],
[this.x + 1, this.y + 1]
];
var found = [];
for (var i in this.directions) {
var x = this.directions[i][0];
var y = this.directions[i][1];
if (x >= 0 && x < global.matrix[0].length && y >= 0 && y < global.matrix.length) {
if (global.matrix[y][x] == identifier) {
found.push(this.directions[i]);
}
}
}
return found;
}
multiplyF() {
if(global.weather == "summer"){
this.multiply_interval = 13;
}else if(global.weather == "spring"){
this.multiply_interval = 8;
}else if(global.weather == "winter"){
this.multiply_interval = 30;
}else if(global.weather == "autumn"){
this.multiply_interval = 8;
}
this.multiply++;
var norVandak = random(this.findSlots(0));
if (this.multiply >= this.multiply_interval && norVandak) {
var norXot = new Grass(norVandak[0], norVandak[1]);
global.totalGrassCounter++;
global.grassArray.push(norXot);
global.matrix[norVandak[1]][norVandak[0]] = 1;
this.multiply = 0;
}
}
}
var random = require("./random.js");