Foros del Web » Programando para Internet » Javascript »

Barra desplazamiento

Estas en el tema de Barra desplazamiento en el foro de Javascript en Foros del Web. Hola a todos, tengo que realizar el mitko juego de la pelota que rebota en una barra que se desplaza mediante las teclas z y ...
  #1 (permalink)  
Antiguo 11/05/2011, 04:05
 
Fecha de Ingreso: marzo-2011
Mensajes: 37
Antigüedad: 13 años, 1 mes
Puntos: 0
Barra desplazamiento

Hola a todos, tengo que realizar el mitko juego de la pelota que rebota en una barra que se desplaza mediante las teclas z y x, pero no consigo hacer que la pelota me rebote en ella en cambio si que lo hace en el fondo del marco, en este cuando no consigas poner la barra debajo de la pelota deberia de dar un mensaje de fin de partida. Os pongo el codigo para ver si me podeis ayudar, ya que es bastante urgente:

<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style tpe="text/css">

#fondo {width:550; height:385; background-image: url(foto1.gif); margin-left:-8px; margin-top:-15px;}
#imagen {position:absolute;}

</style>

<script language="JavaScript">

// Movimiento Balon

balon = new Image();
balon.src="balon.gif";

barram = new Image();
barram.src="barra1.gif";

var x=0; //Coordenadas del balon
var y=0; //Coordenadas del balon

var direccionv=0;
var direccionh=0;

function moverbalon()
{

if(x>=parseInt(document.getElementById("muevebarra ").style.height)-balon.height)
{
direccionv=1;
}

if(y>parseInt(document.getElementById("fondo").sty le.width)-balon.width)
{
direccionh=1;
}

if(x<=0)
{
direccionv=0;
}

if(direccionv==0)
{
x+=5;
}

if(direccionv==1)
{
x-=5;
}

if(y<=0)
{
direccionh=0;
}

if(direccionh==0)
{
y+=5;
}

if(direccionh==1)
{
y-=5;
}

document.getElementById("imagen").style.top=x+"px" ;
document.getElementById("imagen").style.left=y+"px ";

setTimeout("moverbalon()",30);

}

// Movimiento Barra

var ie = (document.all)? true:false;

function iniciarbarra()
{
if (ie)
{
barra=muevebarra.style
}

barra.xpos=parseInt(barra.left);
barra.ypos=parseInt(barra.top);
barra.activeleft=false;
barra.activeright=false;
barra.activeup=false;
barra.activedown=false;
document.onkeydown=pulsartecla;
document.onkeyup=soltartecla;
}



function pulsartecla() {

if (ie)
{
var tecla=event.keyCode;
}

if ((tecla==90) && !barra.activeleft)
{
barra.activeleft=true;
barra.activeright=false;
moverizquierda()
}

if ((tecla==88) && !barra.activeright)
{
barra.activeright=true;
barra.activeleft=false;
moverderecha()
}

}

function soltartecla()
{

if (ie)
{
var tecla=event.keyCode;
}

if (tecla==90)
{
barra.activeleft=false
}

if (tecla==88)
{
barra.activeright=false
}
}


function moverizquierda()
{
if (barra.xpos==5)
{
barra.activeleft=false;
}
else
{
if (barra.activeleft)
{
barra.xpos-=5
barra.left=barra.xpos
setTimeout("moverizquierda()",10)
}
}

}


function moverderecha()
{
if (barra.xpos==730)
{
barra.activeright=false;
}
else
if (barra.activeright)
{
barra.xpos+=5
barra.left=barra.xpos
setTimeout("moverderecha()",10)
}
}

</script>

</head>

<body onload="moverbalon(); iniciarbarra()">

<div id="fondo" style="width: 800px; height: 850px;">
<img id="imagen" src="balon.gif">
<div id="muevebarra" style="position:absolute; left:350; top:810; width:70;">
<img src="barra1.gif" width=70 height=20>
</div>

</body>
</html>


Un saludo y gracias.

Última edición por ricardo_eslokehay; 11/05/2011 a las 11:41 Razón: error escritura

Etiquetas: barra, desplazamiento
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:38.