Skip to main content

deactivate Deactivate keyboard input on collision

I amI'm creating an online-canvas-game with a tank as player object,
Now.

Now I have several structures in my canvas, that shouldn't be able to be overdriven by the tank...
My solution is to detect the collision like that:

        if(hero.x > reactor[i]['x'] - 32 && hero.x <= reactor[i]['x'] + 32
   && hero.y > reactor[i]['y'] - 32 && hero.y <= reactor[i]['y']){
        collidetop = true;
    }

    if(hero.x > reactor[i]['x'] - 32 && hero.x <= reactor[i]['x'] + 32
   && hero.y >= reactor[i]['y'] && hero.y < reactor[i]['y'] + 32){
        collidebottom = true;
    }

    if(hero.x > reactor[i]['x'] - 32 && hero.x <= reactor[i]['x']
   && hero.y > reactor[i]['y'] - 32 && hero.y <= reactor[i]['y'] + 32){
        collideleft = true;
    }

    if(hero.x > reactor[i]['x'] && hero.x <= reactor[i]['x'] + 32
   && hero.y > reactor[i]['y'] - 32 && hero.y <= reactor[i]['y'] + 32){
        collideright = true;
    }  

the heroThe hero object is the tank, hero.xhero.x the x-coordinate, and so on...
Now I'd like to deactivate the keyboard input for the direction key, if the objects collide...
For this reason I have the variables wokwok, aokaok, soksok and dok dok - they all contain booleans.
If wok = falsewok = false, then the key "w" is deactivated...
I've connected the collidevariablescollide variables to the keyboardinputskeyboard inputs:

if(collidetop == true){
    sok = false;
}
if(collidetop == false){
    sok = true;
}
if(collidebottom == true){
    wok = false;
}
if(collidebottom == false){
    wok = true;
}
if(collideright == true){
    aok = false;
}
if(collideright == false){
    aok = true;
}
if(collideleft == true){
    dok = false;
}
if(collideleft == false){
    dok = true;
}  

My Problemproblem is: if the tank doesn't collide the other object any more, the keys stay blocked... Could Could you help me with that?

Tried many things, but nothing really worked...

Already now, thank you for your answers ;)

Btw.: Sorry for my particular badly English...

deactivate keyboard input on collision

I am creating an online-canvas-game with a tank as player object,
Now I have several structures in my canvas, that shouldn't be able to be overdriven by the tank...
My solution is to detect the collision like that:

        if(hero.x > reactor[i]['x'] - 32 && hero.x <= reactor[i]['x'] + 32 && hero.y > reactor[i]['y'] - 32 && hero.y <= reactor[i]['y']){
        collidetop = true;
    }

    if(hero.x > reactor[i]['x'] - 32 && hero.x <= reactor[i]['x'] + 32 && hero.y >= reactor[i]['y'] && hero.y < reactor[i]['y'] + 32){
        collidebottom = true;
    }

    if(hero.x > reactor[i]['x'] - 32 && hero.x <= reactor[i]['x'] && hero.y > reactor[i]['y'] - 32 && hero.y <= reactor[i]['y'] + 32){
        collideleft = true;
    }

    if(hero.x > reactor[i]['x'] && hero.x <= reactor[i]['x'] + 32 && hero.y > reactor[i]['y'] - 32 && hero.y <= reactor[i]['y'] + 32){
        collideright = true;
    }  

the hero object is the tank, hero.x the x-coordinate, and so on...
Now I'd like to deactivate the keyboard input for the direction key, if the objects collide...
For this reason I have the variables wok, aok, sok and dok - they all contain booleans.
If wok = false, then the key "w" is deactivated...
I've connected the collidevariables to the keyboardinputs:

if(collidetop == true){
    sok = false;
}
if(collidetop == false){
    sok = true;
}
if(collidebottom == true){
    wok = false;
}
if(collidebottom == false){
    wok = true;
}
if(collideright == true){
    aok = false;
}
if(collideright == false){
    aok = true;
}
if(collideleft == true){
    dok = false;
}
if(collideleft == false){
    dok = true;
}  

My Problem is: if the tank doesn't collide the other object any more, the keys stay blocked... Could you help me with that?

Tried many things, but nothing really worked...

Already now, thank you for your answers ;)

Btw.: Sorry for my particular badly English...

Deactivate keyboard input on collision

I'm creating an online-canvas-game with a tank as player object.

Now I have several structures in my canvas, that shouldn't be able to be overdriven by the tank...
My solution is to detect the collision like that:

if(hero.x > reactor[i]['x'] - 32 && hero.x <= reactor[i]['x'] + 32
   && hero.y > reactor[i]['y'] - 32 && hero.y <= reactor[i]['y']){
    collidetop = true;
}

if(hero.x > reactor[i]['x'] - 32 && hero.x <= reactor[i]['x'] + 32
   && hero.y >= reactor[i]['y'] && hero.y < reactor[i]['y'] + 32){
    collidebottom = true;
}

if(hero.x > reactor[i]['x'] - 32 && hero.x <= reactor[i]['x']
   && hero.y > reactor[i]['y'] - 32 && hero.y <= reactor[i]['y'] + 32){
    collideleft = true;
}

if(hero.x > reactor[i]['x'] && hero.x <= reactor[i]['x'] + 32
   && hero.y > reactor[i]['y'] - 32 && hero.y <= reactor[i]['y'] + 32){
    collideright = true;
}

The hero object is the tank, hero.x the x-coordinate, and so on...
Now I'd like to deactivate the keyboard input for the direction key, if the objects collide...
For this reason I have the variables wok, aok, sok and dok - they all contain booleans.
If wok = false, then the key "w" is deactivated...
I've connected the collide variables to the keyboard inputs:

if(collidetop == true){
    sok = false;
}
if(collidetop == false){
    sok = true;
}
if(collidebottom == true){
    wok = false;
}
if(collidebottom == false){
    wok = true;
}
if(collideright == true){
    aok = false;
}
if(collideright == false){
    aok = true;
}
if(collideleft == true){
    dok = false;
}
if(collideleft == false){
    dok = true;
} 

My problem is: if the tank doesn't collide the other object any more, the keys stay blocked... Could you help me with that?

Source Link

deactivate keyboard input on collision

I am creating an online-canvas-game with a tank as player object,
Now I have several structures in my canvas, that shouldn't be able to be overdriven by the tank...
My solution is to detect the collision like that:

        if(hero.x > reactor[i]['x'] - 32 && hero.x <= reactor[i]['x'] + 32 && hero.y > reactor[i]['y'] - 32 && hero.y <= reactor[i]['y']){
        collidetop = true;
    }

    if(hero.x > reactor[i]['x'] - 32 && hero.x <= reactor[i]['x'] + 32 && hero.y >= reactor[i]['y'] && hero.y < reactor[i]['y'] + 32){
        collidebottom = true;
    }

    if(hero.x > reactor[i]['x'] - 32 && hero.x <= reactor[i]['x'] && hero.y > reactor[i]['y'] - 32 && hero.y <= reactor[i]['y'] + 32){
        collideleft = true;
    }

    if(hero.x > reactor[i]['x'] && hero.x <= reactor[i]['x'] + 32 && hero.y > reactor[i]['y'] - 32 && hero.y <= reactor[i]['y'] + 32){
        collideright = true;
    }  

the hero object is the tank, hero.x the x-coordinate, and so on...
Now I'd like to deactivate the keyboard input for the direction key, if the objects collide...
For this reason I have the variables wok, aok, sok and dok - they all contain booleans.
If wok = false, then the key "w" is deactivated...
I've connected the collidevariables to the keyboardinputs:

if(collidetop == true){
    sok = false;
}
if(collidetop == false){
    sok = true;
}
if(collidebottom == true){
    wok = false;
}
if(collidebottom == false){
    wok = true;
}
if(collideright == true){
    aok = false;
}
if(collideright == false){
    aok = true;
}
if(collideleft == true){
    dok = false;
}
if(collideleft == false){
    dok = true;
}  

My Problem is: if the tank doesn't collide the other object any more, the keys stay blocked... Could you help me with that?

Tried many things, but nothing really worked...

Already now, thank you for your answers ;)

Btw.: Sorry for my particular badly English...