war aber auch ne echt super hilfe ^^
klappt

klappt

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Ferngesteuertes Auto</title> <script type="text/javascript"> var x = 50; //variable für die x-achse var y = 50; //variable für die y-achse var t = 8; //variable für die Zeit var b = "url(images/rechts.png)"; //variable für den Background des Bereichs var move = null; function go(anweisung) { if(anweisung == "rechts" || anweisung == "links" || anweisung == "runter" || anweisung == "rauf" || anweisung == "right"){ if(move != null) { clear(move); } move = window.setInterval("moveto('"+anweisung+"')", 40); } if(anweisung=="turbo") { t = t + 10; } if(anweisung == "slow") { t = t - 5; } else if(anweisung == "stop") { window.clearInterval (move);} } function clear(interval) { window.clearInterval (interval); } function moveto(richtung) { switch(richtung) { case "links": if (x > 20) { x = x - t; b = "url(images/links.png)"; document.getElementById("auto").style.left = (x + "px"); document.getElementById("auto").style.backgroundImage = b; } break; case "rechts": if (x < 1400) { x = x + t; b = "url(images/vor.png)"; document.getElementById("auto").style.left = (x + "px"); document.getElementById("auto").style.backgroundImage = b; } break; case "rauf": if (y > 50) { y = y - t; b = "url(images/rauf.png)"; document.getElementById("auto").style.top = (y + "px"); document.getElementById("auto").style.backgroundImage= b; } break; case "runter": if (y < 450 ) { y = y + t; b = "url(images/runter.png)"; document.getElementById("auto").style.top = (y + "px"); document.getElementById("auto").style.backgroundImage= b; } break; } } function buttonrechts() { if(b=='url(images/rechts.png)'){go('rechts');} if(b=='url(images/vor.png)'){go('runter');} if(b=='url(images/runter.png)'){go('links');} if(b=='url(images/links.png)'){go('rauf');} if(b=='url(images/rauf.png)'){go('rechts');} } function buttonlinks() { if(b=='url(images/vor.png)'){go('links');} if(b=='url(images/links.png)'){go('runter');} if(b=='url(images/runter.png)'){go('right');} if(b=='url(images/rechts.png)'){go('rauf');} if(b=='url(images/rauf.png)'){go('links');} } </script> <style type="text/css"> body { width:700px;height:700px; background-image:url(images/camouflage.png); } #auto { top: 50px; left: 20px; position: absolute; background-image:url('images/rechts.png'); width:200px; height:200px; background-repeat:no-repeat; } #steuer { margin-left:500px; padding-left:50px; padding-top:3px; padding-right:50px; background:white; height:30px; width:570px; border:5px ridge green; opacity:0.6; filter:alpha(opacity=60); } #fahren { height:600px; width:1600px; border:5px ridge green; opacity:0.2; filter:alpha(opacity=60); background:white; } </style> <link rel="stylesheet" href="cardesign.css" type="text/css" > <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> </head> <body> <div id="steuer"> <input type="button" name="Right" value="Right" onclick= "buttonrechts()"> <input type="button" name="Left" value="Left" onclick= "go('links')" > <input type="button" name="Stop" value="Stop" onclick= "go('stop')"> <input type="button" name="Down" value="Down" onclick= "go('runter')"> <input type="button" name="Up" value="Up" onclick= "go('rauf')"> <input type="button" name="Turbo" value="Turbo" onclick= "go('turbo')"> <input type="button" name="Slow" value="Slow" onclick= "go('slow')"> </div> <div id="fahren"><!-- Bereich in dem das Auto sich bewegt--> </div> <div id="auto"><!--Bereich des Autos--> </div> </body> </html>
und danke für deine bemühungen :>var x = 50; //variable für die x-achse
var y = 50; //variable für die y-achse
var t = 8; //variable für die Zeit
var b = "url(images/rechts.png)"; //variable für den Background des Bereichs
function go(anweisung) {
if(anweisung == "rechts" ||
anweisung == "links" ||
anweisung == "runter" ||
anweisung == "rauf" ||
anweisung == "right"){
move = window.setInterval("moveto("+anweisung+")", 40);
} }
function moveto(richtung)
{
switch(richtung)
{
case "links":
if (x > 20) {
x = x - t;
b = "url(images/links.png)";
document.getElementById("auto").style.left = (x + "px");
document.getElementById("auto").style.backgroundImage = b;
}
break;
case "rechts":
if (x < 1400)
{
x = x + t;
b = "url(images/vor.png)";
document.getElementById("auto").style.left = (x + "px");
document.getElementById("auto").style.backgroundImage = b; }
break;
case "rauf":
if (y > 50) {
y = y - t;
b = "url(images/rauf.png)";
document.getElementById("auto").style.top = (y + "px");
document.getElementById("auto").style.backgroundImage= b; }
break;
case "runter":
if (y < 450 ) {
y = y + t;
b = "url(images/runter.png)";
document.getElementById("auto").style.top = (y + "px");
document.getElementById("auto").style.backgroundImage= b; }
break;
}
}
function buttonrechts() // die funktion fragt ab wie das auto gerade steht und je nachdem wie es steht wird die richtung verändert beim drücken des buttons
{
if(b=='url(images/rechts.png)'){go('rechts');}
if(b=='url(images/vor.png)'){go('runter');}
if(b=='url(images/runter.png)'){go('links');}
if(b=='url(images/links.png)'){go('rauf');}
if(b=='url(images/rauf.png)'){go('rechts');}
}
function buttonlinks()
{
if(b=='url(images/vor.png)'){go('links');}
if(b=='url(images/links.png)'){go('runter');}
if(b=='url(images/runter.png)'){go('right');}
if(b=='url(images/rechts.png)'){go('rauf');}
if(b=='url(images/rauf.png)'){go('links');}
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Ferngesteuertes Auto</title>
<script src="starts.js" type="text/javascript"></script>
<link rel="stylesheet" href="cardesign.css" type="text/css" >
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<div id="steuer">
<input type="button" name="Right" value="Right" onclick= "buttonrechts()"> <!--bei click auf den Button rechts wird die funktion buttonrechts() ausgeführt.das auto fährt nach rechts-->
<input type="button" name="Left" value="Left" onclick= "go('links')" > <!--bei click auf den Button links wird die funktion buttonlinks() ausgeführt. das auto fährt nach links-->
<input type="button" name="Stop" value="Stop" onclick= "go('stop')"> <!--bei click auf den Button Stop wird die funktion Stop() ausgeführt die alle intervalle stopt-->
<input type="button" name="Down" value="Down" onclick= "go('runter')">
<input type="button" name="Up" value="Up" onclick= "go('rauf')">
<input type="button" name="Turbo" value="Turbo" onclick= "go('turbo')"> <!--bei click auf den Button Turbo wird die funktion turbo() ausgeführt und das auto fährt schneller-->
<input type="button" name="Slow" value="Slow" onclick= "go('slow')"> <!-- bei click auf den button slow wird die funktion slow() ausgeführt und das auto fährt langsamer-->
</div>
<div id="fahren"><!-- Bereich in dem das Auto sich bewegt-->
</div>
<div id="auto"><!--Bereich des Autos-->
</div>
</body>
</html>
go(anweisung) {
if(anweisung == "rechts" ||
anweisung == "links" || anweisung == "runter" || anweisung == "rauf" || anweisung == "right")
{
move = window.setInterval("moveto('"+anweisung+")", 40);
}
}
moveto(richtung)
{
switch(richtung)
{
case "links":
if (x > 20)
{
x = x - t;
b = "url(images/links.png)";
document.getElementById("auto").style.left = (x + "px");
document.getElementById("auto").style.backgroundImage = b;
}
break;
case "rechts":
if (x < 1400)
{
x = x + t;
b = "url(images/vor.png)"; // setzt den hintergrund des bereichs für das auto fest
document.getElementById("auto").style.left = (x + "px");
document.getElementById("auto").style.backgroundImage = b;
}
break;
case "rauf":
if (y > 50)
{
y = y - t;
b = "url(images/rauf.png)";
document.getElementById("auto").style.top = (y + "px");
document.getElementById("auto").style.backgroundImage= b;
}
break;
case "runter":
if (y < 450 )
{
y = y + t;
b = "url(images/runter.png)";
document.getElementById("auto").style.top = (y + "px");
document.getElementById("auto").style.backgroundImage= b;
}
break;
case "right":
x = x + t;
b = "url(images/rechts.png)";
document.getElementById("auto").style.left = (x + "px");
document.getElementById("auto").style.backgroundImage = b;
break;
}
}
function rauf(){
if (y > 50)
{
y = y - t;
b = "url(images/rauf.png)";
document.getElementById("auto").style.top = (y + "px");
document.getElementById("auto").style.backgroundImage= b;
} }
function runter(){
if (y < 450 )
{
y = y + t;
b = "url(images/runter.png)";
document.getElementById("auto").style.top = (y + "px");
document.getElementById("auto").style.backgroundImage= b;
}}
function links(){
if (x > 20)
{
x = x - t;
b = "url(images/links.png)";
document.getElementById("auto").style.left = (x + "px");
document.getElementById("auto").style.backgroundImage = b;
}}
function rechts(){
if (x < 1400)
{
x = x + t;
b = "url(images/vor.png)"; // setzt den hintergrund des bereichs für das auto fest
document.getElementById("auto").style.left = (x + "px");
document.getElementById("auto").style.backgroundImage = b;
}}
function right(){
x = x + t;
b = "url(images/rechts.png)";
document.getElementById("auto").style.left = (x + "px");
document.getElementById("auto").style.backgroundImage = b;
}
function buttonrechts() // die funktion fragt ab wie das auto gerade steht und je nachdem wie es steht wird die richtung verändert beim drücken des buttons
{
if(b=='url(images/rechts.png)'){go('rechts');}
if(b=='url(images/vor.png)'){window.clearInterval(move); go('runter');}
if(b=='url(images/runter.png)'){window.clearInterval(move);go('links');}
if(b=='url(images/links.png)'){window.clearInterval(move);go('rauf');}
if(b=='url(images/rauf.png)'){window.clearInterval(move);go('rechts');}
}
function buttonlinks()
{
if(b=='url(images/vor.png)'){window.clearInterval(move);go('links');}
if(b=='url(images/links.png)'){window.clearInterval(move);go('runter');}
if(b=='url(images/runter.png)'){window.clearInterval(move);go('right');}
if(b=='url(images/rechts.png)'){window.clearInterval(move);go('rauf');}
if(b=='url(images/rauf.png)'){window.clearInterval(move);go('links');}
}
Einen Kommentar schreiben: