Basically I have a grid of spans resembling a chess/checker board with players & ai taking turns moving.
During a players turn, they can "shoot" other players, however I'm having a hard time getting my head around how to tell if there is someone in the crossfire.
I consider a "chess piece" occupying a square as taking up the entire square, so really just need a way to find out if the "bullet" passes through a square as it travels from point a to point b.
Here is a brief example: http://jsfiddle.net/hnxs4cvq/9/
javascript/jquery:
$(window).load(function(){
$(function () {
$('.skillRangeSquare').click(function () {alert('hit!');})
})
});
html:
<span id="1" class="battlefieldSquare_Base battlefieldSquare_B " name="r1c1"> </span>
<span id="2" class="battlefieldSquare_Base battlefieldSquare_A skillRangeSquare" name="r1c2">monster</span>
<span id="3" class="battlefieldSquare_Base battlefieldSquare_B " name="r1c3"> </span>
<span id="4" class="battlefieldSquare_Base battlefieldSquare_A " name="r1c4"> </span>
<span id="5" class="battlefieldSquare_Base battlefieldSquare_B " name="r1c5"> </span>
<br>
<span id="11" class="battlefieldSquare_Base battlefieldSquare_A " name="r2c1"> </span>
<span id="12" class="battlefieldSquare_Base battlefieldSquare_B " name="r2c2"> </span>
<span id="13" class="battlefieldSquare_Base battlefieldSquare_A " name="r2c3"> </span>
<span id="14" class="battlefieldSquare_Base battlefieldSquare_B " name="r2c4"> </span>
<span id="15" class="battlefieldSquare_Base battlefieldSquare_A " name="r2c5"> </span>
<br>
<span id="21" class="battlefieldSquare_Base battlefieldSquare_B " name="r3c1"> </span>
<span id="22" class="battlefieldSquare_Base battlefieldSquare_A skillRangeSquare" name="r3c2"> monster</span>
<span id="23" class="battlefieldSquare_Base battlefieldSquare_B" name="r3c3"> </span>
<span id="24" class="battlefieldSquare_Base battlefieldSquare_A " name="r3c4"> </span>
<span id="25" class="battlefieldSquare_Base battlefieldSquare_B " name="r3c5"> </span>
<br>
<span id="31" class="battlefieldSquare_Base battlefieldSquare_A " name="r4c1"> </span>
<span id="32" class="battlefieldSquare_Base battlefieldSquare_B " name="r4c2"> </span>
<span id="33" class="battlefieldSquare_Base battlefieldSquare_A " name="r4c3">player </span>
<span id="34" class="battlefieldSquare_Base battlefieldSquare_B" name="r4c4"> </span>
<span id="35" class="battlefieldSquare_Base battlefieldSquare_A " name="r4c5"> </span>
The monster closest to the player is ok to hit, there is nothing in the way, however the one further back is "blocked" by the closer one since the projectile would pass through the upper corner of the square it occupies.
I'm looking for a way, in the onclick, to determine that.
Edit: I should have mentioned the projectile would be going from center square to center square.