-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol.js
More file actions
119 lines (87 loc) · 3.38 KB
/
control.js
File metadata and controls
119 lines (87 loc) · 3.38 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
114
115
116
117
118
119
import {sleep} from './Packages/utilities.js';
import {getLenY} from './Packages/matrix.js';
import {initializeMap,getMap,getMapLengthY} from './Map/main.js';
import {initializePlayer, getPlayerLevel, getPlayerX, setPlayerXY, isPlayerAtEnd, levelUpPlayer,
resetPlayerPath,isPlayerInDarkness, isPlayerInRiver,isPlayerOtherConflict,getPlayerPath} from './player.js';
import {initializeOthers, moveOthers} from "./others.js";
import {initializeDarkness, getNewDarknessColumn} from './darkness.js';
import {resetVirgil, moveVirgil} from './virgil.js';
import {playerMoved, spacePressed} from './input.js';
import {initializePalette} from './Map/colorList.js'
import {getCantoLength,getStanza,getStanzaLength,getStanzaWordCount, getStanzaTotal} from './Canto/main.js'
import {initializeDisplay, displayPlayer,displayOthers, displayVirgil,
setDisplayMessage, setGameOverMessage, setDisplayInstruction, addDarknessColumn, darken, sepiafy, brightenPath} from './display.js';
const {floor} = Math;
$(document).ready(() => init());
async function init(level = 1){
initializePlayer(level);
initializePalette(getStanzaTotal());
start()
}
async function start(){
resetPlayerPath();
const level = getPlayerLevel();
const map = initializeMap(level ,getStanzaLength(level-1) + 4,getStanzaWordCount(level-1));
const others = initializeOthers(level);
resetVirgil();
initializeDarkness(level, getStanzaTotal());
setPlayerXY([1,floor(getMapLengthY() / 2)]);
initializeDisplay(map, 'Stanza '+level,'');
displayPlayer();
displayOthers(others);
runLoop(R.slice(0,R.__,getStanza(level-1)));
}
async function runLoop(getStanzaSlice){
await playerMoved();
const others = moveOthers();
const virgil = moveVirgil();
setDisplayMessage(getStanzaSlice(getPlayerX()))
displayPlayer();
displayOthers(others);
displayVirgil(virgil);
const darkX = getNewDarknessColumn();
if(darkX !== null) addDarknessColumn(darkX);
const finish = checkForFinished();
if(finish) finish()
else runLoop(getStanzaSlice);
}
function checkForFinished(){
if(isPlayerAtEnd()) return levelUp;
if(isPlayerInDarkness()) return gameOver.bind(this, 'Darkness has overcome you. The end.');
//TODO
// - add ends below:
if(isPlayerInRiver()) return gameOver.bind(this, 'You have fallen into a deep dark river. The end.');
const {icon:otherIcon} = isPlayerOtherConflict() || {};
if(otherIcon === 'P') return gameOver.bind(this, 'A panther, a spotted panther, a leopard even, hath overtaken thee. The end.');
if(otherIcon === 'L') return gameOver.bind(this, 'A lion hath slain thee. The end.');
if(otherIcon === 'W') return gameOver.bind(this, 'A wolf, a she-wolf, hath made a spoil of thee. The end.');
return false;
}
async function levelUp(){
await brightenPath(getPlayerPath());
if(getPlayerLevel() === 46) return gameEnd();
await instructToPressSpaceBar()
levelUpPlayer()
start()
}
async function gameOver(msg){
setGameOverMessage(msg)
await darken(4000, 8);
await instructToPressSpaceBar()
//await sleep(3 * 1000)
start()
}
async function gameEnd(){
setDisplayMessage('End of Canto I')
sepiafy()
}
async function instructToPressSpaceBar(){
setDisplayInstruction('Press Spacebar')
await spacePressed();
setDisplayInstruction('');
}
/* TODO
- add press space bar meesage at end
- in map nake path object which uses x as keys of sets of ys
- give to virgil to follow path back
*/