-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmob.js
More file actions
113 lines (97 loc) · 3.54 KB
/
mob.js
File metadata and controls
113 lines (97 loc) · 3.54 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
class mob {
/**
* Constructs the player and inits their position
* @param {Nunber} x X position for the player to start at
* @param {Number} y Y position for the player to start at
*/
constructor(x, y) {
this.x = x*20;
this.y = y*20;
this.vx = 0.0;
this.vy = 0.0;
this.size = PLAYER_SIZE;
this.target = null;
this.task = null; // Following possibilites are: queue, drink, food, idle
this.queue_positions = ["18,31","20,31","22,31","24,31","26,31","28,31","30,31","18,33","20,33","22,33","24,33"];
this.route = null;
this.move_every = Math.floor(Math.random() * (20 - 10 + 1)) + 10;
this.idle_amount = Math.floor(Math.random() * (200 - 10 + 1)) + 10;
this.idle_counter = 0;
this.counter = 0;
this.is_signed_up = false;
this.idle_area_x = [8,15];
this.idle_area_y = [15,21];
this.timer = 0;
}
/**
* Update player based on current velocity
*/
update() {
if(this.task == null) {
if(this.is_signed_up) {
this.task = "idle";
this.pos = [Math.floor(Math.random() * (35 - 10 + 1)) + 10, + Math.floor(Math.random() * (21 - 15 + 1)) + 15].toString();
this.route = this.work_out_path(this.pos);
} else {
this.task = "queue";
this.route = this.work_out_path(this.queue_positions[queue_count])
queue_count +=1;
}
} else if (this.task == "queue") {
// Get next avalible position in the queue and navigate to there
this.timer+=1;
if(this.timer == 1000) {
player.satisfaction -=2;
this.timer = 0;
}
// console.log(this.timer)
} else if (this.task == "drink") {
//Navigate to drinks and remove 1 from global avalible_drinks
} else if (this.task == "food") {
// navigate to food table and take one from the table
} else if(this.task == "idle") {
// Program
if(this.idle_counter == this.idle_amount) {
this.pos = [Math.floor(Math.random() * (35 - 10 + 1)) + 10, + Math.floor(Math.random() * (21 - 15 + 1)) + 15].toString();
this.route = this.work_out_path(this.pos);
this.idle_counter = 0;
}
this.idle_counter +=1;
}
if(this.route.length != 0 && this.counter == this.move_every) {
//walk to target
let move_to = this.route[0];
this.x = move_to.y*20;
this.y = move_to.x*20;
this.route.shift()
this.counter = 0;
} else {
this.task == null;
}
if(this.counter == this.move_every) {
this.counter = 0
}
this.counter +=1;
}
/**
* Render the mob
*/
draw() {
// drawCircle(this.x, this.y, PLAYER_SIZE / 2);
// drawRect(this.x, this.y, PLAYER_SIZE, PLAYER_SIZE);
drawPlayerImage("mob",this.x,this.y)
}
work_out_path(end_x_y) {
let end_y = end_x_y.split(",")[0]
let end_x = end_x_y.split(",")[1]
console.log(this.x,this.y)
let start = ai_map.grid[this.y/20][this.x/20];
let end = ai_map.grid[end_x][end_y];
let result = astar.search(ai_map,start,end);
return result;
}
register_mob() {
this.is_signed_up = true;
this.task = null;
}
}