dodanie mozliwosci przesuwania zawodnikow, istenieje blad przy najezdzie kursorem na innego zawodnika

This commit is contained in:
unknown 2024-01-05 03:39:25 +01:00
parent 070794daf2
commit f7b0307112

View File

@ -147,7 +147,7 @@ const Hero = () => {
ball.style.background = pColor; ball.style.background = pColor;
}) })
ball.addEventListener("mouseover",function(){ ball.addEventListener("mouseover",function podswietl(){
player.style.background = "#bf8e8e" player.style.background = "#bf8e8e"
tekst.style.color = "black" tekst.style.color = "black"
posytion.style.color = "black" posytion.style.color = "black"
@ -158,30 +158,52 @@ const Hero = () => {
posytion.style.color = "white" posytion.style.color = "white"
}) })
var bojo = document.getElementById('footballField')
// listenery pozwalające na przesuwanie punktu // listenery pozwalające na przesuwanie punktu
ball.addEventListener("mousedown", function(){
ball.addEventListener("mousedown", function przesuwanie(){
ball.style.background = "orange" ball.style.background = "orange"
ball.addEventListener("mousemove", whileMove(ball)) player.style.background = 'rgb(16, 46, 29)';
}) tekst.style.color = "white"
posytion.style.color = "white"
ball.addEventListener('mousemove', function(){ bojo.addEventListener("mousemove", function whileMove(ev){
var bojo = document.getElementById('footballField')
var bnd = ev.target.getBoundingClientRect()
// zapis od 0 - 1 w jakim procentowym miejscu boiska użytkownik kliknął
var x = ((ev.clientX - bnd.left)/bojo.offsetWidth)*100;
var y = ((ev.clientY - bnd.top)/bojo.offsetHeight)*100;
}) player.style.background = 'rgb(16, 46, 29)';
tekst.style.color = "white"
posytion.style.color = "white"
ball.addEventListener("mouseup", function(){ x = parseFloat(x) + 1
y = parseFloat(y) + 1
if(bojo.parentNode.querySelector(":hover")){
ball.style.left = x + "%"
ball.style.top = y + "%"
}
posytion.innerHTML = "x:" + konwerturX(ball.style.left) + "m " + "y:" + konwetujY(ball.style.top) + "m";
bojo.addEventListener("mouseup", function(){
ball.style.background = pColor ball.style.background = pColor
bojo.removeEventListener("mousemove", whileMove)
}) })
ball.addEventListener("mouseout", function(){
ball.style.background = pColor })
}) })
} }
function whileMove(ball){
}
// Wysłanie zapytania do serwera
// Wyłanie zapytania do serwera
function sentQuestion() { function sentQuestion() {
var ball = document.querySelector('.football'); var ball = document.querySelector('.football');
if (ball) { if (ball) {
@ -221,7 +243,7 @@ const Hero = () => {
addPlayer(0,ball) addPlayer(0,ball)
bojo.appendChild(ball) bojo.appendChild(ball)
ball.style.background = "#fc0303" ball.style.background = "#fc0303"
umer_od_shooters = numer_od_shooters + 1 numer_od_shooters = numer_od_shooters + 1
}else{alert("mozesz dodac tylko jednego strzelca")} }else{alert("mozesz dodac tylko jednego strzelca")}
}else if(active_bbt == "bbt2"){ }else if(active_bbt == "bbt2"){