Problème jeu
Utilisateur anonyme
-
Utilisateur anonyme -
Utilisateur anonyme -
Bonjour,
Alors voila, vous verrez que pour mon décor, je fais défiler des étoiles: dès que il y en a une qui atteint le bas, on la remet en haut: seleument, pourquoi que certaines remontent?
<html>
<head>
<title></title>
<script type="text/JavaScript">
//Variables
var fusee=new Image;
fusee.src="fusee.jpg";
var boardW=400;
var boardH=500;
var rocketX=180;
var rocketY=420;
var rocketDX=5;
var rocketW=18;
var decorD=4;
var starW=2;
var starH=20;
//Variables de décor (étoiles qui défilent)
var star1Y=20;
var star2Y=130;
var star3Y=210;
var star4Y=250;
var star5Y=290;
var star6Y=330;
var star7Y=390;
var star8Y=430;
var star9Y=40;
var star10Y=70;
var star11Y=233;
var star12Y=222;
var star13Y=290;
var star14Y=260;
//On récupère le canvas, context, ect...
function getCanvas() {
canvas=document.getElementById("monCanvas");
if (canvas.getContext) {
ctx=canvas.getContext("2d");
gameLoop=setInterval(drawGame, 1000/60);
window.addEventListener("keydown", keyboard, true);
}
else {
alert("Votre navigateur ne supporte pas canvas. Téléchargez FireFox ou IE9!");
}
}
function drawGame() {
//Dessiner le terrain et la fusée
ctx.beginPath();
ctx.fillStyle="black";
ctx.fillRect(0, 0, boardW, boardH);
ctx.drawImage(fusee, rocketX, rocketY);
//Dessiner le décor (étoiles qui défilent)
if (star5Y==boardH) {
star5Y=0;
}
if (star1Y==boardH) {
star1Y=boardH-boardH;
}
if (star2Y==boardH) {
star2Y=0;
}
if (star3Y==boardH) {
star3Y=boardH-boardH;
}
if (star4Y==boardH) {
star4Y=boardH-boardH;
}
if (star6Y==boardH) {
star6Y=boardH-boardH;
}
if (star7Y==boardH) {
star7Y=0;
}
if (star8Y==boardH) {
star8Y=0;
}
if (star9Y==boardH) {
star9Y=0;
}
if (star10Y==boardH) {
star10Y=0;
}
if (star11Y==boardH) {
star11Y=0;
}
if (star12Y==boardH) {
star12Y=0;
}
if (star13Y==boardH) {
star13Y=0;
}
if (star14Y==boardH) {
star14Y=0;
}
star1Y=star1Y+decorD;
star2Y=star2Y+decorD;
star3Y=star3Y+decorD;
star4Y=star4Y+decorD;
star5Y=star5Y+decorD;
star6Y=star6Y+decorD;
star7Y=star7Y+decorD;
star8Y=star8Y+decorD;
star9Y=star9Y+decorD;
star10Y=star10Y+decorD;
star11Y=star11Y+decorD;
star12Y=star12Y+decorD;
star13Y=star13Y+decorD;
star14Y=star14Y+decorD;
ctx.fillStyle="white";
ctx.fillRect(100, star1Y, starW, starH);
ctx.fillRect(120, star2Y, starW, starH);
ctx.fillRect(190, star3Y, starW, starH);
ctx.fillRect(80, star4Y, starW, starH);
ctx.fillRect(30, star5Y, starW, starH);
ctx.fillRect(240, star6Y, starW, starH);
ctx.fillRect(265, star7Y, starW, starH);
ctx.fillRect(280, star8Y, starW, starH);
ctx.fillRect(20, star9Y, starW, starH);
ctx.fillRect(250, star10Y, starW, starH);
ctx.fillRect(300, star11Y, starW, starH);
ctx.fillRect(210, star12Y, starW, starH);
ctx.fillRect(255, star13Y, starW, starH);
ctx.fillRect(10, star14Y, starW, starH);
}
//programme clavier
function keyboard(evt) {
switch (evt.keyCode) {
// Left arrow.
case 37:
rocketX-=rocketDX;
if (rocketX < 0) rocketX = 0;
break;
// Right arrow.
case 39:
rocketX+=rocketDX;
if (rocketX > boardW - rocketW) rocketX = boardW - rocketW;
break;
}
}
</script>
<style type="text/CSS">
</style>
<body onLoad="getCanvas();">
<div align="center">
<canvas id="monCanvas" width="400" height="500"></canvas>
</div>
</body>
</html>
Merci.
Alors voila, vous verrez que pour mon décor, je fais défiler des étoiles: dès que il y en a une qui atteint le bas, on la remet en haut: seleument, pourquoi que certaines remontent?
<html>
<head>
<title></title>
<script type="text/JavaScript">
//Variables
var fusee=new Image;
fusee.src="fusee.jpg";
var boardW=400;
var boardH=500;
var rocketX=180;
var rocketY=420;
var rocketDX=5;
var rocketW=18;
var decorD=4;
var starW=2;
var starH=20;
//Variables de décor (étoiles qui défilent)
var star1Y=20;
var star2Y=130;
var star3Y=210;
var star4Y=250;
var star5Y=290;
var star6Y=330;
var star7Y=390;
var star8Y=430;
var star9Y=40;
var star10Y=70;
var star11Y=233;
var star12Y=222;
var star13Y=290;
var star14Y=260;
//On récupère le canvas, context, ect...
function getCanvas() {
canvas=document.getElementById("monCanvas");
if (canvas.getContext) {
ctx=canvas.getContext("2d");
gameLoop=setInterval(drawGame, 1000/60);
window.addEventListener("keydown", keyboard, true);
}
else {
alert("Votre navigateur ne supporte pas canvas. Téléchargez FireFox ou IE9!");
}
}
function drawGame() {
//Dessiner le terrain et la fusée
ctx.beginPath();
ctx.fillStyle="black";
ctx.fillRect(0, 0, boardW, boardH);
ctx.drawImage(fusee, rocketX, rocketY);
//Dessiner le décor (étoiles qui défilent)
if (star5Y==boardH) {
star5Y=0;
}
if (star1Y==boardH) {
star1Y=boardH-boardH;
}
if (star2Y==boardH) {
star2Y=0;
}
if (star3Y==boardH) {
star3Y=boardH-boardH;
}
if (star4Y==boardH) {
star4Y=boardH-boardH;
}
if (star6Y==boardH) {
star6Y=boardH-boardH;
}
if (star7Y==boardH) {
star7Y=0;
}
if (star8Y==boardH) {
star8Y=0;
}
if (star9Y==boardH) {
star9Y=0;
}
if (star10Y==boardH) {
star10Y=0;
}
if (star11Y==boardH) {
star11Y=0;
}
if (star12Y==boardH) {
star12Y=0;
}
if (star13Y==boardH) {
star13Y=0;
}
if (star14Y==boardH) {
star14Y=0;
}
star1Y=star1Y+decorD;
star2Y=star2Y+decorD;
star3Y=star3Y+decorD;
star4Y=star4Y+decorD;
star5Y=star5Y+decorD;
star6Y=star6Y+decorD;
star7Y=star7Y+decorD;
star8Y=star8Y+decorD;
star9Y=star9Y+decorD;
star10Y=star10Y+decorD;
star11Y=star11Y+decorD;
star12Y=star12Y+decorD;
star13Y=star13Y+decorD;
star14Y=star14Y+decorD;
ctx.fillStyle="white";
ctx.fillRect(100, star1Y, starW, starH);
ctx.fillRect(120, star2Y, starW, starH);
ctx.fillRect(190, star3Y, starW, starH);
ctx.fillRect(80, star4Y, starW, starH);
ctx.fillRect(30, star5Y, starW, starH);
ctx.fillRect(240, star6Y, starW, starH);
ctx.fillRect(265, star7Y, starW, starH);
ctx.fillRect(280, star8Y, starW, starH);
ctx.fillRect(20, star9Y, starW, starH);
ctx.fillRect(250, star10Y, starW, starH);
ctx.fillRect(300, star11Y, starW, starH);
ctx.fillRect(210, star12Y, starW, starH);
ctx.fillRect(255, star13Y, starW, starH);
ctx.fillRect(10, star14Y, starW, starH);
}
//programme clavier
function keyboard(evt) {
switch (evt.keyCode) {
// Left arrow.
case 37:
rocketX-=rocketDX;
if (rocketX < 0) rocketX = 0;
break;
// Right arrow.
case 39:
rocketX+=rocketDX;
if (rocketX > boardW - rocketW) rocketX = boardW - rocketW;
break;
}
}
</script>
<style type="text/CSS">
</style>
<body onLoad="getCanvas();">
<div align="center">
<canvas id="monCanvas" width="400" height="500"></canvas>
</div>
</body>
</html>
Merci.
A voir également:
- Problème jeu
- 94 jeu - Télécharger - Puzzle & Réflexion
- 94 degrés jeu - Télécharger - Divers Jeux
- Jeu zuma - Télécharger - Jeux vidéo
- Jeu logo - Télécharger - Jeux vidéo
- Jeu google - Guide