final code

This commit is contained in:
Killian Marty 2024-01-01 12:55:28 +01:00
parent 9dedf15df8
commit 5759f39bb8
7 changed files with 39 additions and 55 deletions

View file

@ -1,4 +1,4 @@
function getCookie(name) {//Code from OpenClassroom
function getCookie(name) {
nom = name + "=";
var liste = document.cookie.split (';');
for (var i = 0; i < liste.length; i++) {

View file

@ -175,15 +175,15 @@ let lastbulletdonjon=[0,0]
function Donjon() {
if(player.z==10) {
if(lastbulletdonjon[1]>=7) {
lastbulletdonjon[1]=0
lastbulletdonjon[1]=0;
bullets.push(new Bullet(107,95+(Date.now()*0.1)%365,10,1,0,-2, true));
bullets.push(new Bullet(107,460-(Date.now()*0.1)%365,10,1,0,-2, true));
} else {
lastbulletdonjon[1]++
lastbulletdonjon[1]++;
}
if(lastbulletdonjon[0]==59 && Math.floor(Date.now()/1000)%60 !=59) { lastbulletdonjon[0]=0 }
if(Math.floor(Date.now()/1000)%60 > lastbulletdonjon[0]) {
lastbulletdonjon[0]=Math.floor(Date.now()/1000)%60
lastbulletdonjon[0]=Math.floor(Date.now()/1000)%60;
for(let i=0;i<5;i++){
bullets.push(new Bullet(235,65,10,0,2,-2, true));
bullets.push(new Bullet(235,491,10,0,-2,-2, true));
@ -199,32 +199,32 @@ function Donjon() {
function Lester(type, data) {
switch(type) {
case 1:
player.x=data[0]
player.y=data[1]
player.z=data[2]
player.x=data[0];
player.y=data[1];
player.z=data[2];
net.update(player);
break;
case 2:
player.health=defaulthealth
player.health=defaulthealth;
break;
case 3:
addKill(data, player.id)
net.died(data, player.id)
addKill(data, player.id);
net.died(data, player.id);
break;
case 4:
players.forEach((p) => {
if(p.id>0) {
net.died(p.id, player.id)
addKill(data, player.id)
p.death++
net.died(p.id, player.id);
addKill(data, player.id);
p.death++;
}
});
break;
case 5:
if(drawCollisions) {
drawCollisions=false
drawCollisions=false;
} else {
drawCollisions=true
drawCollisions=true;
}
break;
}

View file

@ -1,6 +1,6 @@
class Input {
constructor(idCanvas) {
this.keysDown = new Set()
this.keysDown = new Set();
this.dir = 0;
this.canvas = document.getElementById(idCanvas);
@ -33,20 +33,19 @@ class Input {
});
window.addEventListener("keydown", (e)=>{
//blocks the action of the key (cf. Killian)
if(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(e.code)) {
e.preventDefault();
}
this.keysDown.add(e.key.toLowerCase())
this.keysDown.add(e.key.toLowerCase());
this.updateDir();
})
document.getElementById("retour_menu").addEventListener("click", (e) => {
phone.changeWindow(1)
phone.changeWindow(1);
});
window.addEventListener("keyup", (e)=>{
this.keysDown.delete(e.key.toLowerCase())
this.keysDown.delete(e.key.toLowerCase());
this.updateDir();
})
@ -97,10 +96,4 @@ class Input {
net.update(player);
}
}
/*
calculateAngle(playerX, playerY) {
return Math.atan2(this.mouseY - playerY, this.mouseX - playerX);
}
*/
}

View file

@ -58,14 +58,5 @@ class LeaderBoard {
this.nbjoueur++;
}
});
/*this.ctx.fillText('1', this.px+20, this.py+120);
this.ctx.fillText('Player1', this.px+50, this.py+120);
this.ctx.fillText('10/20', this.px+180, this.py+120);
this.ctx.fillText('2', this.px+20, this.py+120+20);
this.ctx.fillText('Player2', this.px+50, this.py+120+20);
this.ctx.fillText('10/2', this.px+180, this.py+120+20);
*/
}
}

View file

@ -47,7 +47,7 @@ class Network{
if(data.data.player_id == player.id){
alert("Vous avez essayé de tricher, vous jouez maintenant en solo.");
}else{
console.log("Player " + data.data.player_id.toString() + " caught cheating.")
console.log("Player " + data.data.player_id.toString() + " caught cheating.");
}
break;

View file

@ -9,39 +9,39 @@ class Phone{
this.inputDiv = document.getElementById("chatInputDiv");
this.webview = document.getElementById("webview");
this.webviewName = "Erreur"
this.webviewName = "Erreur";
this.chargeMainPage();
this.changeWindow(1)
this.changeWindow(1);
}
chargeMainPage() {
document.getElementById("appli-concord").addEventListener("click", (e) => {
this.changeWindow(2)
this.changeWindow(2);
});
document.getElementById("appli-gta6").addEventListener("click", (e) => {
this.webviewName = "GTA 6"
this.changeWindow("game.html")
this.webviewName = "GTA 6";
this.changeWindow("game.html");
});
document.getElementById("appli-vbuks").addEventListener("click", (e) => {
this.webviewName = "Free Vbucks"
this.changeWindow("assets/phone/webview/vbucks.html")
this.webviewName = "Free Vbucks";
this.changeWindow("assets/phone/webview/vbucks.html");
});
document.getElementById("appli-fb").addEventListener("click", (e) => {
this.webviewName = "FakeBook"
this.changeWindow("assets/phone/webview/fb.html")
this.webviewName = "FakeBook";
this.changeWindow("assets/phone/webview/fb.html");
});
document.getElementById("appli-utube").addEventListener("click", (e) => {
this.webviewName = "uTube"
this.changeWindow("assets/phone/webview/utube.html")
this.webviewName = "uTube";
this.changeWindow("assets/phone/webview/utube.html");
});
document.getElementById("appli-goo").addEventListener("click", (e) => {
this.webviewName = "Gogole"
this.changeWindow("https://mrdoob.com/projects/chromeexperiments/google-space/")
this.webviewName = "Gogole";
this.changeWindow("https://mrdoob.com/projects/chromeexperiments/google-space/");
});
document.getElementById("appli-lest").addEventListener("click", (e) => {
this.webviewName = "Lester"
this.changeWindow("assets/phone/webview/lester.html")
this.webviewName = "Lester";
this.changeWindow("assets/phone/webview/lester.html");
});
}
@ -57,11 +57,11 @@ class Phone{
switch (window) {
case 1:
this.name.innerText = "Pear phone"
this.name.innerText = "Pear phone";
this.content.style.display="block";
break;
case 2:
this.name.innerText = "Concord"
this.name.innerText = "Concord";
this.contentmsg.style.display="block";
this.inputDiv.style.display="block";
break;
@ -129,7 +129,7 @@ class Phone{
if(input.value!=''){
this.sendMessage(player.name, input.value);
input.value = '';
input.blur()
input.blur();
}
}
}

View file

@ -8,6 +8,6 @@ class Sound{
play(){
//this.sound.pause()
this.sound.currentTime=0;
this.sound.play()
this.sound.play();
}
}