Skip to content

Movimiento de personajes y balas de cada uno #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Juego1/CowBoyIdle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Juego1/CowBoyWalking.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 34 additions & 12 deletions Juego1/ObjetosJuego.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,48 @@

#miObjeto {
position: absolute;
left: 49%; /* Posición inicial */
top: 95%; /* Posición fija vertical */
width: 20px;
height: 20px;
background-color: blue;
left: 40%;
top: 76.3%; /* Posición fija vertical */
width: 90px;
height: 190px;
background-color: aqua;

}
#bala1{
left: 40%;
top: 76.3%; /* Posición fija vertical */
width: 10px;
height: 10px;
background-color: rgb(255, 0, 21);
}

#miObjetivo {
position: absolute;
left: 51%; /* Posición inicial */
top: 95%; /* Posición fija vertical */
width: 20px;
height: 20px;
background-color: blue;
left: 40%;
top: 76.3%; /* Posición fija vertical */
width: 90px;
height: 190px;
background-color: aqua;

}
#bala2 {

left: 40%;
top: 76.3%; /* Posición fija vertical */
width: 10px;
height: 10px;
background-color: rgb(255, 0, 0);

}


#contenedor{
position: absolute; /* Posición relativa al viewport */
width: 1800px; /* Ancho del contenedor */
height: 750px; /* Altura del contenedor */
height: 800px; /* Altura del contenedor */
border: solid 1px;
left: 50%; /* Posicionamiento horizontal */
top: 50%; /* Posicionamiento vertical */
top: 50%;

transform: translate(-50%, -50%); /* Ajuste para centrar */
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion Juego1/juego1.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
<body id="pantalla">

<div id="contenedor">
<div id="miObjeto"></div>
<div id="miObjeto">
<div id="bala1"></div>
</div>
<div id="miObjetivo"></div>
</div>

Expand Down
118 changes: 59 additions & 59 deletions Juego1/juego1.js
Original file line number Diff line number Diff line change
@@ -1,83 +1,83 @@
const objeto = document.getElementById("miObjeto");
const contenedor = document.getElementById("contenedor");
let posicionx1 = 883; // Posición inicial en el eje y
let velocidadx1 = 5; // Velocidad en el eje X
let posicionx1 = 850; // Posición inicial en el eje y
let velocidadx1 = 0.5; // Velocidad en el eje X

function moverObjeto() {
const altoContenedor = contenedor.offsetHeight; // Ancho de la ventana
const altoObjeto = objeto.offsetHeight;
function moverObjeto() {
const altoContenedor = contenedor.offsetHeight; // Ancho de la ventana
const altoObjeto = objeto.offsetHeight;

// Actualizamos la posición en el eje X

// Actualizamos la posición en el eje X

// Detectamos colisiones con los bordes horizontales
if (posicionx1 < distancia1) {
posicionx1 += velocidadx1;
velocidadx1 *= +1; // Invertimos la dirección en el eje X
// Aplicamos la nueva posición al estilo del objeto
objeto.style.left= posicionx1 + "px";
}else {
clearInterval(intervalo); // Detenemos el movimiento
console.log("El objeto alcanzó la distancia objetivo.");
}


}

// Llamamos a la función `moverObjeto` repetidamente
setInterval(moverObjeto, 20);
// Detectamos colisiones con los bordes horizontales
if (posicionx1 < distancia1) {
posicionx1 += velocidadx1;
velocidadx1 *= +1; // Invertimos la dirección en el eje X
// Aplicamos la nueva posición al estilo del objeto
objeto.style.left = posicionx1 + "px";
}
}

// Llamamos a la función `moverObjeto` repetidamente
setInterval(moverObjeto, 20);



const objetivo = document.getElementById("miObjetivo");
const contenedor2 = document.getElementById("contenedor");
const distancia1 =1400;
const distancia2 =395;
let posicionx2 = 920; // Posición inicial en el eje y
let velocidadx2 = 5; // Velocidad en el eje X

function moverObjetivo() {
const altoContenedor = contenedor2.offsetHeight; // Ancho de la ventana
const altoObjetivo = objetivo.offsetHeight;



// Detectamos colisiones con los bordes horizontales
if (posicionx2 > distancia2) {
// Actualizamos la posición en el eje X
posicionx2 -= velocidadx2;
velocidadx2 *= +1; // Invertimos la dirección en el eje X
// Aplicamos la nueva posición al estilo del objeto
objetivo.style.left= posicionx2 + "px";
} else {
clearInterval(intervalo); // Detenemos el movimiento
console.log("El objeto alcanzó la distancia objetivo.");
}


}

// Llamamos a la función `moverObjeto` repetidamente
setInterval(moverObjetivo, 20);









const distancia1 = 1200;
const distancia2 = 440;
let posicionx2 = 790; // Posición inicial en el eje y
let velocidadx2 = 0.5; // Velocidad en el eje X

function moverObjetivo() {
const altoContenedor = contenedor2.offsetHeight; // Ancho de la ventana
const altoObjetivo = objetivo.offsetHeight;

// Detectamos colisiones con los bordes horizontales
if (posicionx2 > distancia2) {
// Actualizamos la posición en el eje X
posicionx2 -= velocidadx2;
velocidadx2 *= +1; // Invertimos la dirección en el eje X
// Aplicamos la nueva posición al estilo del objeto
objetivo.style.left = posicionx2 + "px";
}

}
// Llamamos a la función `moverObjeto` repetidamente
setInterval(moverObjetivo, 20);


const bala1 =document.getElementById("bala1")



let posicionb1=440;
let velocidadb1=addEventListener("click",20);

function disparoBala1(){
const diana1=1200;

if (posicionb1<diana1){
posicionb1 +=velocidadb1;
velocidadb1*=-1;
bala1.style.left=posicionb1+"px";
}
}
setInterval(disparoBala1,10);

const bala2 =document.getElementById("bala2")

let posicionb2=440;
let velocidadb2=addEventListener("click",20);
function disparoBala2(){
const diana2=1200;

if (posicionb2<diana2){
posicionb2 +=velocidadb2;
velocidadb2*=-1;
bala1.style.left=posicionb2+"px";
}
}
setInterval(disparoBala2,10);