-
Notifications
You must be signed in to change notification settings - Fork 0
/
onload.js
111 lines (102 loc) · 3.57 KB
/
onload.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
var audioItem, audioFight, audioGameOver, audioWon;
var audioBackground;
window.onload = function() {
canvas = document.getElementById('game');
ctx = canvas.getContext('2d');
//initiating screen measures for culling
culling.screen = [
document.getElementById("game").width,
document.getElementById("game").height
];
startLevel();
ctx.font = "bold 10pt sans-serif";
//Audio
audioItem = new Audio("audio/ItemAdded.mp3");
audioFight = new Audio("audio/Fight.wav");
audioGameOver = new Audio("audio/gameOver_funky.mp3");
audioWon = new Audio("audio/YouWon.mp3");
audioBackground = new Audio("audio/mary.mp3");
//Eventlisteners
window.addEventListener("keydown", function(e){
if(e.keyCode >= 37 && e.keyCode <= 40 ){
keysDown[e.keyCode] = true;
}
});
window.addEventListener("keyup", function(e){
if(e.keyCode >= 37 && e.keyCode <= 40 ){
keysDown[e.keyCode] = false;
}
});
window.addEventListener("keydown",function(e){
if(fight && !actionIsRunning && firstAction){
switch(e.keyCode){
case 65:
if(monster_index >= 0) {
attackMonster();
}
else {
noMonster();
}
document.getElementById('YourAction').style.display='none';
break;
case 67:
if(!charFight){
catchMonster();
document.getElementById('YourAction').style.display='none';
}
break;
case 70:
if(charFight){
feedOwnMonster();
}
else {
feedOtherMonster();
}
document.getElementById('YourAction').style.display='none';
break;
case 82:
runAway();
document.getElementById('YourAction').style.display='none';
break;
}
}
if ((isGameOver || isLevelScreen) && e.keyCode == 13){
document.getElementById('startExplanation').style.display='none';
isLevelScreen = false;
isGameOver = false;
audioGameOver.pause();
audioBackground.play();
if(explanation){
explanation = false;
lvlExplanation();
}
else{
startNewLevel();
}
}
if(noMonsterNoFight && e.keyCode == 13){
noMonsterNoFight = false;
gameOver();
}
if(e.keyCode == 13 && text && currText != "YourAction"){
document.getElementById(currText).style.display='none';
document.getElementById(currBG).style.display='none';
text = false;
if(charMeet){
visited[gameMap[player.tileTo[1] * map.width + player.tileTo[0]]] = 10;
charMeet = false;
}
if(fightMsg){
startFight();
}
}
if(e.keyCode == 13 && lost && currText == 'Lost'){
lost = false;
document.getElementById('Lost').style.display='none';
document.getElementById(currBG).style.display='none';
text = false;
gameOver();
afterFight();
}
});
};