Commit 157578f6 authored by Luc Damas's avatar Luc Damas

TP 3, 4 et 6

parent 4e8d2d7d
This diff is collapsed.
* { margin: 0px; padding: 0px; }
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link rel="stylesheet" type="text/css" href="css/animate.css" />
</head>
<body>
<header>
</header>
<section>
</section>
<footer>
</footer>
<script type='text/javascript' src='js/jquery.js'></script>
<script type='text/javascript' src='js/main.js'></script>
</body>
</html>
This diff is collapsed.
$(document).ready(function() {
});
function property(object, name, value) {
var props = { };
props[name] = {
get: function () {
return this["_"+name];
},
set: function (x) {
this["_"+name] = x;
update();
}
};
Object.defineProperties(object, props);
object[name] = value;
}
function update() {
console.log("ui updated");
}
\ No newline at end of file
This diff is collapsed.
#mazeDiv {
position: relative;
}
#mazeDiv div {
width: 10px;
height: 10px;
float: left;
}
.wall {
background-color: black;
}
.floor {
}
.lineEnd {
clear: left;
}
#mazeDiv .player {
background-color: green;
position: absolute;
}
#mazeDiv .me {
background-color: orangeRed;
}
.playerPseudo {
position: absolute;
font-family: arial;
font-size: 0.7em;
top: -10px;
left: 15px;
}
#coin {
background-color: yellow;
position: absolute;
}
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link rel="stylesheet" type="text/css" href="css/animate.css" />
</head>
<body>
<script type='text/javascript' src='js/jquery.js'></script>
<script type='text/javascript' src='js/main.js'></script>
</body>
</html>
This diff is collapsed.
This diff is collapsed.
var url = "http://srv-tpinfo.iut-acy.local:1337/";
$(document).ready(function() {
// Récup du labyrinthe
$.post(
url+"lab",
{ pseudo: "ldama", password: "7369" },
function(maze) {
var mazeDiv = $("<div/>");
mazeDiv.attr("id","mazeDiv");
$("body").append(mazeDiv);
for(var y=0; y<maze.length; y++) {
for(var x=0; x<maze[y].length; x++) {
var element = $("<div/>");
if (maze[y][x] == 1) { // Wall = 1
element.addClass("wall");
} else { // Floor = 0
element.addClass("floor");
}
if (x==0)
element.addClass("lineEnd");
mazeDiv.append(element);
}
}
setInterval(play, 10);
},
"json"
);
// Gestion des événements claviers
$("body").keyup(function(event) {
switch(event.keyCode) {
case 38: move( 0, -1); break;
case 40: move( 0, 1); break;
case 37: move(-1, 0); break;
case 39: move( 1, 0); break;
};
});
});
//------------------------------------------
var speed = { x: 0, y: 0 };
function move(vx, vy) {
speed.x = vx;
speed.y = vy;
}
//------------------------------------------
var count = 0;
function play() {
if (count == 0)
players();
else if (count == 1)
moveMe();
else
coin();
count = (count+1)%3;
}
//------------------------------------------
function moveMe() {
// if (speed.x ==0 && speed.y == 0) {
speed.x = coinPos.x - me.x;
if (speed.x != 0)
speed.x = speed.x/Math.abs(speed.x);
speed.y = coinPos.y - me.y;
if (speed.y != 0)
speed.y = speed.y/Math.abs(speed.y);
console.log(speed);
// }
$.post(
url+"move",
{
pseudo: "ldama",
password: "7369",
v: speed
},
function(response) {
speed = { x: 0, y: 0 };
},
"json"
);
}
//------------------------------------------
var me = { x: 0, y: 0 };
function players() {
$.post(
url+"players",
{ pseudo: "ldama", password: "7369" },
function(players) {
for(var pseudo in players) {
var player = players[pseudo];
var playerDiv;
if ($("#"+pseudo).length > 0) {
playerDiv = $("#"+pseudo);
} else {
playerDiv = $("<div/>");
playerDiv
.attr("id",pseudo)
.addClass("player")
.addClass(pseudo=="ldama"?"me":"opponent")
.append("<div class='playerPseudo'>"
+pseudo+" "+player.score+"</div>");
$("#mazeDiv").append(playerDiv);
}
playerDiv.children(".playerPseudo")
.text(pseudo+" "+player.score);
if (pseudo == "ldama")
me = player.position;
playerDiv.css({
top: player.position.y*10,
left: player.position.x*10,
});
}
},
"json"
);
}
//------------------------------------------
var coinPos = { x: 0, y: 0 };
function coin() {
$.post(
url+"coin",
{ pseudo: "ldama", password: "7369" },
function(coinP) {
coinPos = coinP;
var coinDiv;
if ($("#coin").length > 0) {
coinDiv = $("#coin");
} else {
coinDiv = $("<div/>");
coinDiv
.attr("id","coin")
$("#mazeDiv").append(coinDiv);
}
coinDiv.css({
top: coinPos.y*10,
left: coinPos.x*10,
});
},
"json"
);
}
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<canvas width='800' height='450'></canvas>
<audio controls src='sounds/NancySinatra-BangBangMyBabyShotMeDown.mp3'></audio>
<script src='main.js'></script>
</body>
</html>
\ No newline at end of file
var canvas = document.querySelector("canvas");
var c = canvas.getContext("2d");
var w = canvas.width;
var h = canvas.height;
var ball = { x: w/2, y: h/2, vx: 0, vy: 0, r: w/20 };
var audio = document.querySelector("audio");
var audioCtx = new AudioContext();
var analyser = audioCtx.createAnalyser();
var source = audioCtx.createMediaElementSource(audio);
source.connect(analyser);
analyser.connect(audioCtx.destination);
audio.play();
var frequencyData = new Uint8Array(analyser.frequencyBinCount);
function analyseSound(timestamp) {
analyser.getByteFrequencyData(frequencyData);
c.clearRect(0,0,w,h);
c.beginPath();
c.fillStyle = "orange";
var imin = 0;
var imax = 256;
var sum = 0;
for(var i in frequencyData) {
var freq = frequencyData[i];
if (i>=imin && i<imax)
sum += freq;
c.beginPath();
c.fillRect(
w*i/frequencyData.length,
h/2 - freq/2,
w/frequencyData.length,
freq);
}
var avg = sum/(imax-imin);
ball.r = 50+avg*0.5;
c.beginPath();
c.fillStyle = "rgba(0,0,0,0.5)";
c.arc(ball.x, ball.y, ball.r, 0, Math.PI*2, true);
c.fill();
ball.vy += 0.1;
if (ball.y+ball.vy+ball.r > h)
ball.vy = -ball.vy*0.9;
ball.y += ball.vy;
window.requestAnimationFrame(analyseSound);
}
window.requestAnimationFrame(analyseSound);
\ No newline at end of file
canvas {
background-color: #FFDDAA;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment