-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
65 lines (54 loc) · 2.33 KB
/
server.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
/**
* Created by TONY on 02.05.2015.
*/
var express = require('express');
var app = express();
var Gopnik = require('./gopnik');
var Boxer = require('./boxer');
var Vec2d = require('./vector');
var world = require('./world');
var coords = require('./rout');
var gopnik = new Gopnik('Vasya', 'Saltovka');
var boxer = new Boxer('Fomin', 'XT3');
app.get('/moveto', function(req, res){
var step = 0;
if(check() == false){
//перемещение гопника
gopnik.speed.add(world.wind);
gopnik.position.add(gopnik.speed);
gopnik.position.x += coords.firstCord[step][0];
gopnik.position.y += coords.firstCord[step][1];
var gopnikX = Math.round(gopnik.position.x);
var gopnikY = Math.round(gopnik.position.y);
//перемещение боксера
boxer.speed.add(world.wind);
boxer.position.add(boxer.speed);
boxer.position.x -= coords.secondCord[step][0];
boxer.position.y -= coords.secondCord[step++][1];
var boxerX = Math.round(boxer.position.x);
var boxerY = Math.round(boxer.position.y);
res.send('Гопник в пути' + ' ' + 'x ='+ gopnikX +' '+ 'y= '+ gopnikY +
'Боксер в пути' + ' ' + 'x ='+ boxerX +' '+ 'y= '+ boxerY);
} else {
gopnik.figth(boxer, gopnik);
}
});
var check = function() {
var GOPNIK_VISIBLE = 7.07;
var BOXER_VISIBLE = 14.14;
var MAX_VISIBLE = GOPNIK_VISIBLE + BOXER_VISIBLE; // максимальное расстояние при котором игроки увидят друг друга и начнется бой
//находим расстояние между позициями Гопника и Боксера
var distanceBetweenOpponents = function(){
var posX = boxer.position.x - gopnik.position.y;
var posY = boxer.position.y - gopnik.position.y;
return Math.sqrt(Math.pow(posX, 2) - Math.pow(posY, 2));
};
// если максимальное расстояние меньше растояние между персонажами то бой начинается
if(MAX_VISIBLE <= distanceBetweenOpponents()){
console.log(MAX_VISIBLE - distanceBetweenOpponents());
return true
} else return false
};
app.listen(3000, function () {
console.log('Server start on port = 3000');
});