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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
| // Initialisation
var
larg = 32,
a = [-larg, 1, larg, -1],
b = [1, larg, -1, -larg],
c = [larg, -1, -larg, 1],
d = [ -1, -larg, 1, larg],
t = 0,
pos = 976,
// pos = 572,
cle2 = 0
;
// Définition des MURS
var mur = [ null,
"1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1",
"1","0","0","0","0","0","1","1","0","0","0","0","0","0","0","1","1","1","1","1","0","1","1","1","1","0","0","0","0","1","1","1",
"1","0","1","1","0","1","1","1","0","1","0","1","0","1","0","0","1","1","1","0","0","0","0","1","1","0","1","1","0","0","1","1",
"1","1","1","1","0","0","0","1","0","1","0","1","0","1","1","0","1","1","1","0","1","1","0","1","1","0","1","1","0","1","1","1",
"1","1","0","0","0","1","0","1","0","0","0","1","0","0","1","0","0","0","0","1","1","1","0","0","0","0","1","0","0","1","1","1",
"1","1","1","1","1","1","0","1","1","1","0","1","1","1","1","1","1","0","1","1","1","1","0","1","1","1","1","1","0","0","0","1",
"1","1","1","1","1","1","0","1","1","1","0","0","1","1","1","1","1","0","1","1","1","1","0","1","1","1","1","1","1","1","0","1",
"1","1","1","0","0","0","0","1","1","1","1","0","1","0","0","0","0","0","1","1","0","0","0","1","1","1","0","1","1","1","0","1",
"1","1","1","0","1","0","1","1","1","1","1","0","1","0","1","1","1","1","1","1","0","1","1","0","0","0","0","1","1","1","0","1",
"1","0","0","0","1","0","0","0","1","1","0","0","1","0","1","1","1","0","0","0","0","1","1","0","1","1","1","0","0","0","0","1",
"1","1","0","1","1","1","1","0","1","1","0","1","1","0","0","0","1","0","1","1","0","1","1","0","0","0","1","0","1","0","1","1",
"1","1","0","1","1","1","1","0","1","0","0","1","1","1","1","0","1","0","0","1","0","0","0","1","1","0","1","0","1","0","0","1",
"1","1","0","0","0","0","0","0","1","0","1","1","1","1","1","0","1","1","0","1","1","1","0","1","1","0","1","0","1","1","1","1",
"1","0","0","1","0","1","1","1","1","0","1","0","0","1","1","0","1","1","0","1","1","1","0","1","0","0","1","0","0","1","1","1",
"1","1","1","1","0","1","1","1","1","0","1","0","1","0","0","0","0","0","0","1","1","1","0","1","0","1","1","1","0","1","0","1",
"1","1","1","1","0","1","1","1","1","0","0","0","1","0","1","1","0","1","0","1","1","0","0","1","0","1","1","0","0","0","0","1",
"1","1","1","1","0","0","0","0","1","1","1","0","1","0","1","1","0","1","0","1","1","0","1","1","0","1","1","0","1","1","1","1",
"1","0","0","0","0","1","1","0","1","1","1","0","1","0","1","1","0","1","0","0","0","0","1","0","0","0","0","0","0","1","1","1",
"1","0","1","1","1","1","0","0","0","1","1","0","1","0","0","0","0","1","1","0","1","0","1","0","1","0","1","1","0","1","1","1",
"1","0","1","1","1","1","0","1","0","1","0","0","1","1","0","1","1","1","1","1","1","1","1","1","1","0","1","1","0","0","0","1",
"1","0","1","0","1","1","0","0","0","1","0","1","1","0","0","0","0","0","1","1","1","1","1","1","1","0","0","0","1","1","0","1",
"1","0","0","0","1","1","1","1","1","1","0","1","1","0","1","1","1","0","1","0","0","0","0","1","1","0","1","0","1","0","0","1",
"1","1","1","0","1","1","1","1","1","1","0","1","1","0","1","1","1","0","1","0","1","1","0","1","1","0","1","0","1","1","0","1",
"1","1","1","0","0","0","0","1","0","0","0","0","1","0","1","0","1","0","1","0","1","1","0","1","1","0","0","0","0","0","0","1",
"1","1","1","1","1","1","0","1","0","1","1","0","1","0","0","0","0","0","1","0","1","1","0","0","0","0","1","1","1","1","0","1",
"1","0","0","0","1","1","0","1","0","1","1","1","1","1","1","1","1","1","1","0","1","1","1","1","0","1","1","1","1","0","0","1",
"1","0","1","0","1","1","0","1","0","1","1","1","1","0","1","1","1","0","1","0","1","1","1","1","1","1","1","1","1","1","0","1",
"1","0","1","0","0","0","0","1","0","0","0","1","1","0","1","1","1","0","0","0","1","0","0","0","1","0","0","0","1","1","1","1",
"1","0","0","1","1","0","1","1","1","1","0","1","0","0","1","0","0","0","1","0","1","0","1","0","0","0","1","0","1","1","0","1",
"1","1","0","0","0","0","1","1","1","1","0","0","0","1","1","0","1","1","1","0","0","0","1","0","1","0","1","0","0","0","0","1",
"1","1","1","0","1","0","0","0","0","0","0","1","0","1","0","0","0","1","1","0","1","0","0","0","1","0","0","0","1","1","0","1",
"1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1"
];
// Définition des IMAGES (GRID)
var
imgGrid_1 = document.getElementById('image01'),
imgGrid_2 = document.getElementById('image02'),
imgGrid_3 = document.getElementById('image03'),
imgGrid_4 = document.getElementById('image04'),
imgGrid_5 = document.getElementById('image05'),
imgGrid_6 = document.getElementById('image06'),
imgGrid_7 = document.getElementById('image07');
// -------------------
// Gestion des PORTES
function checkDoor()
{
// ----------
// PORTE
if ( (pos==976 && t==0)
|| (pos==912 && t==2)
|| (pos==572 && t==0)
|| (pos==508 && t==2)
){
document.getElementById('porte').src = "visuels/porte.jpg";
document.getElementById('porte').style.display = "block";
} else {
document.getElementById('porte').src = "visuels/vide.png";
document.getElementById('porte').style.display = "none";
}
}
// -------------------
// ANIMATION des PORTES
function checkDoorAnim()
{
if ( (pos==944 && t==0)
|| (pos==540 && t==0)
|| (pos==540 && t==2)
){
document.getElementById('porte').src = "visuels/porteanim.gif";
document.getElementById('porte').style.display = "block";
// ----------
// on execute la suite APRES un DELAI (duree de l'ANIMATION de la porte)
setTimeout(function(){
displayGrid();
flecheb();
document.getElementById('porte').src = "visuels/vide.png";
document.getElementById('porte').style.display = "none";
}, 1000); // 1 seconde
// ----------
} else {
document.getElementById('porte').src = "visuels/vide.png";
document.getElementById('porte').style.display = "none";
// ----------
displayGrid();
flecheb();
// ----------
}
}
// -------------------
// AVANCER
function moveAhead()
{
if (mur[pos+a[t]]=="0")
{
if (pos==572 && t==0 && cle2==0 )
{
rien=rien;
}
else
{
// ----------
// MAP : carré noir (cases parcourues)
j = parseInt(pos/larg);
var spot = document.createElement('img');
spot.setAttribute('src','visuels/carrenoir.jpg');
spot.classList.add('trace');
spot.style.left = 4+((pos-(j*larg))*8)+'px';
spot.style.top = 22+(j*8)+'px';
document.getElementById('game-map').appendChild( spot );
pos = pos+a[t];
// ----------
checkDoor();
checkDoorAnim();
}
}}
var r = 0; // global
// -------------------
// TOURNER A DROITE
function moveRight()
{
if (pos!=976)
{
// ----------
// Rotation de la Boussole
r = r - 90;
document.getElementById('boussole').style.transform = "rotate("+r+"deg)";
// ----------
t = (t+1)%4;
// ----------
checkDoor();
displayGrid();
flecheb();
}
}
// -------------------
// TOURNER A GAUCHE
function moveLeft()
{
if (pos!=976)
{
// ----------
// Rotation de la Boussole
r = r + 90;
document.getElementById('boussole').style.transform = "rotate("+r+"deg)";
// ----------
t = (t+3)%4;
// ----------
checkDoor();
displayGrid();
flecheb();
}
}
// -------------------
// MAP : flèche blanche (position du joueur)
function flecheb()
{
// ----------
j=parseInt(pos/larg);
var spot = document.createElement('img');
spot.setAttribute('src','visuels/carre'+(t+1)+'.jpg');
spot.classList.add('trace');
spot.style.left = 4+((pos-(j*larg))*8)+'px';
spot.style.top = 22+(j*8)+'px';
document.getElementById('game-map').appendChild( spot );
// ----------
}
// -------------------
// AFFICHAGE de la GRILLE
function displayGrid() {
if (pos==944){ pos=912; }
// console.log( pos+' - '+ t );
// ----------
// déco début
if ( (pos==976 && t==0) )
{
document.getElementById('game-debut').style.display = "block";
} else {
document.getElementById('game-debut').style.display = "none";
}
// ----------
// 3e plan
im03="33.jpg";
im05="35.jpg";
aa=a[t]; bb=b[t]; cc=c[t]; dd=d[t];
// ----------
// MURS
if (mur[pos+(aa*3)]=="1") im04="34p.jpg";
if (mur[pos+(aa*3)]=="0") im04="34v.jpg";
// 2e plan
if (mur[pos+(aa*2)+dd]=="1") im03="22p.jpg";
if (mur[pos+(aa*2)+bb]=="1") im05="26p.jpg";
if (mur[pos+(aa*2)]=="1") { im03="23p.jpg"; im04="24p.jpg"; im05="25p.jpg"; };
if (mur[pos+(aa*2)+dd]=="0") im02="21v.jpg";
if (mur[pos+(aa*2)+bb]=="0") im06="26v.jpg";
if (mur[pos+(aa*2)+dd]=="1") im02="21p.jpg";
if (mur[pos+(aa*2)+bb]=="1") im06="27p.jpg";
// 1er plan
if (mur[pos+aa+dd]=="1") im02="11p.jpg";
if (mur[pos+aa+bb]=="1") im06="16p.jpg";
if (mur[pos+aa]=="1") { im02="12p.jpg"; im03="13p.jpg"; im04="14p.jpg"; im05="15p.jpg"; im06="17p.jpg"; };
if (mur[pos+aa+dd]=="0") im01="01v.jpg";
if (mur[pos+aa+bb]=="0") im07="07v.jpg";
if (mur[pos+aa+dd]=="1") im01="01p.jpg";
if (mur[pos+aa+bb]=="1") im07="07p.jpg";
if (mur[pos+dd]=="1") im01="01.jpg";
if (mur[pos+bb]=="1") im07="07.jpg";
// ----------
// IMAGES
imgGrid_1.src = "visuels/"+im01;
imgGrid_2.src = "visuels/"+im02;
imgGrid_3.src = "visuels/"+im03;
imgGrid_4.src = "visuels/"+im04;
imgGrid_5.src = "visuels/"+im05;
imgGrid_6.src = "visuels/"+im06;
imgGrid_7.src = "visuels/"+im07;
// ----------
if ( (pos==34 && t==2) ){ imgGrid_4.src = "visuels/bravo.jpg"; }
if ( (pos==568 && t==2 && cle2==0 ) ){ imgGrid_4.src = "visuels/cle.jpg"; }
if (pos==600 ){ cle2=1; }
}
// -------------------
// au chargement de page
window.onload = function(){
checkDoor();
displayGrid();
}; |
Partager