-
Notifications
You must be signed in to change notification settings - Fork 1
/
bots.js
95 lines (85 loc) · 2.88 KB
/
bots.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
95
/*
Copyright (c) 2012, Tomi Leppänen
Copyright (c) 2012, Anssi "Miffyli" Kanervisto
Achtung, die Kurve! clone written in javascript and svg
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
*/
/* Begins the game with bots */
function startGameWithBots() {
for (var i in players) { // Setting up players ->
players[i] = new line(players[i].name,players[i].colour,players[i].keyL,
players[i].keyR,true);
}
points_to_end = 10*(PLAYERS-1);
newPointsDisplay();
startNewRoundWithBots();
}
/* Begins new round with bots */
function startNewRoundWithBots() {
clearArea(gamearea);
bonuses = new Array();
timeout = clearTimeout(timeout);
for (var i in players) { // Setting up players ->
players[i].init();
}
wallMode = "deadly";
timeout = setTimeout("main(true)",LOOPSPEED); // Start "loop"
}
/* inputLoop replacement for bot players */
function botControl(bot) { // Needs an intelligent AI
/*
* Idiot bot that uses random values to decide where to go
* This one is used because it's the least annoying
*/
var keypress=m.random();
if (keypress < 0.3) {
botInputLeft(bot);
} else if (keypress > 0.7) {
botInputRight(bot);
}
}
function botInputLeft(bot) {
if (bot.sharpTurns) var new_direction = bot.direction+m.PI/2;
else var new_direction = bot.direction+TURNINGSPEED;
if (new_direction > FULLCIRCLE) bot.direction = new_direction-FULLCIRCLE;
else bot.direction = new_direction;
}
function botInputRight(bot) {
if (bot.sharpTurns) var new_direction = bot.direction-m.PI/2;
else var new_direction = bot.direction-TURNINGSPEED;
if (new_direction < 0) bot.direction = new_direction+FULLCIRCLE;
else bot.direction = new_direction;
}
/* Ends a bot round */
/*
* Called when all bots are dead
*/
function botRoundOver() {
timeout = setTimeout("startNewRoundWithBots()",1000);
}
/* Ends a bot game */
/*
* Called when bots finish playing
*/
function botGameOver() {
timeout = setTimeout("startGameWithBots()",1000);
}
/* Forces ending a bot game */
/*
* Called when starting real game from main menu
*/
function endBotGame() {
timeout = clearTimeout(timeout);
clearArea(gamearea);
}