-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
92 lines (85 loc) · 2.04 KB
/
main.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
const { generateMap } = require('./map');
const { playerInput } = require('./player');
const printColorMap = require('./colormap').printColorMap;
const mainMusic = require('./sound').mainMusic;
const tankSound = require('./sound').tankSound;
const mplayer3 = require('./sound').mplayer3;
const startSound = require('./sound').startSound;
const {
spawnAllEnemies,
enemySpawn,
enemyMotion,
getHighScore,
getNumOfEnemies
} = require('./enemy');
const map = generateMap(15, 15);
const player = {
tankIcon: '^',
life: 3,
spawnPointX: map.length - 2,
spawnPointY: (map.length - 1) / 2 - 2,
posX: 0,
posY: 0,
score: 0,
missileIcon: '*',
missilePosX: 0,
missilePosY: 0,
isPlayer: true
};
const enemy1 = {
tankIcon: 'v',
spawnPointX: map.length - (map.length - 1),
spawnPointY: (map.length - 1) / 2,
posX: 0,
posY: 0,
direction: 'obstructed',
status: 'unspawned',
missileIcon: '*',
missilePosX: 0,
missilePosY: 0
};
const enemy2 = {
tankIcon: 'v',
spawnPointX: map.length - (map.length - 1),
spawnPointY: map.length - 2,
posX: 0,
posY: 0,
direction: 'obstructed',
status: 'unspawned',
missileIcon: '*',
missilePosX: 0,
missilePosY: 0
};
const enemy3 = {
tankIcon: 'v',
spawnPointX: map.length - (map.length - 1),
spawnPointY: map.length - (map.length - 1),
posX: 0,
posY: 0,
direction: 'obstructed',
status: 'unspawned',
missileIcon: '*',
missilePosX: 0,
missilePosY: 0
};
const enemies = [enemy1, enemy2, enemy3];
// játék futtatásához szükséges függvény
const main = () => {
playerInput(map, enemies, player, getNumOfEnemies);
spawnAllEnemies(map, enemies);
setInterval(() => {
for (const enemy of enemies) {
if (enemy.status === 'spawned') {
enemyMotion(map, enemy, enemies, player);
} else if (enemy.status === 'dead') {
enemySpawn(map, enemy);
}
printColorMap(map, enemies, player, getNumOfEnemies(), getHighScore());
}
}, 500);
};
tankSound();
startSound();
setTimeout(() => mainMusic(), 4000);
main();
module.exports = { enemies };