changed collision logic for bombs
This commit is contained in:
parent
1e88921226
commit
7c419d8e33
|
|
@ -38,9 +38,11 @@ function spawnBomb() {
|
||||||
function fall() {
|
function fall() {
|
||||||
for (let element of bombs) {
|
for (let element of bombs) {
|
||||||
element.style.top = (element.offsetTop + 10) + "px";
|
element.style.top = (element.offsetTop + 10) + "px";
|
||||||
var closestElement = document.elementFromPoint(element.offsetLeft, element.offsetTop+10);
|
var elemRect = element.getBoundingClientRect();
|
||||||
if (!closestElement.classList.contains("sky") && !closestElement.classList.contains("alien") && !closestElement.classList.contains("bomb") && !closestElement.classList.contains("explosion")) {
|
var bodyRect = document.body.getBoundingClientRect();
|
||||||
if(Math.floor(Math.random() * 100) < 10 || element.bottom >= document.body.bottom || closestElement.classList.contains("character")) {
|
var skyRect = document.getElementsByClassName("sky")[0].getBoundingClientRect();
|
||||||
|
if (elemRect.bottom >= skyRect.bottom || elemRect.bottom <= bodyRect.offsetHeight) {
|
||||||
|
if(Math.floor(Math.random() * 100) < 10) {
|
||||||
element.className = "explosion";
|
element.className = "explosion";
|
||||||
console.log("Explosion")
|
console.log("Explosion")
|
||||||
setTimeout(() => {element.remove()}, 3000);
|
setTimeout(() => {element.remove()}, 3000);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue