
-----------------------------------
Degensquared
Wed Oct 10, 2007 2:42 pm

Help with collision detection for Space Invaders Remake.
-----------------------------------
Thanks in advance for any help I you can give me :D

I fire the lazer, and it just goes right through enemy, and does not do damage to the enemy.
But, certain times, it kills enemys when you are sitting dirrectly below them, without the lazer damaging them.


View.Set ("graphics:800;600,offscreenonly")
%Variables
var x, hitleftwall, hitrightwall, firedelay, firedelaytime, totalfired, topenemy : int := 0
var lazerx, lazery, fired : array 1 .. 10 of int
var enemyhp, enemyx, enemyy : array 1 .. 20 of int
var chars : array char of boolean
%settings
x := 400
topenemy := 10
colorback (black)
cls
%Sets up the arrays
for count : 1 .. topenemy
    enemyhp (count) := 3
    enemyx (count) := 50 + (50 * count)
    enemyy (count) := 500
end for
for count : 1 .. 10
    fired (count) := 0
end for
loop
    Input.KeyDown (chars)
    %Handles shooting the lazer
    if chars (KEY_UP_ARROW) then
        if firedelay = 0 then
            if totalfired = enemyy (count) - 10 and lazerx (count1) = enemyx (count) - 30 or lazery (count1) = 1 then
                        enemyhp (count) -= 1
                    end if
                end if
            end if
        end for
    end for
    %Draws enemys with correct color
    for count : 1 .. topenemy
        if enemyhp (count) = 3 then
            drawoval (enemyx (count), enemyy (count), 7, 7, green)
        elsif enemyhp (count) = 2 then
            drawoval (enemyx (count), enemyy (count), 7, 7, yellow)
        elsif enemyhp (count) = 1 then
            drawoval (enemyx (count), enemyy (count), 7, 7, red)
        end if
    end for

    %Draws lazers and checks if they are off the screen.
    for count : 1 .. upper (fired)
        if fired (count) = 1 then
            if lazery (count) = enemyy (count) - 10 and lazerx (count1) = enemyx (count) - 30 or lazery (count1) = 1 then
                        enemyhp (count) -= 1
                    end if
                end if
            end if
        end for
    end for
    %Draws player
    drawoval (x, 30, 8, 8, white)
    drawline (x, 30, x, 43, white)
    View.Update
    delay (10)
    cls
end loop


Thanks :D

Degen.

-----------------------------------
isaiahk9
Tue May 06, 2008 5:34 pm

Re: Help with collision detection for Space Invaders Remake.
-----------------------------------
In theory here is what you should do :
   Make it so that when the user fires a bullet, that bullet will have coordinates - x will be the x coordinate of your tank when the bullet was fired and the y will increase so it will fly across the screen.
    Put the bullet in a for loop so that it's y coordinate will be slowly increased, and thus it will be moving upward when you draw it with its y coordinate.
    Make x and y coordinates for the enemies or targets.
    Say that if bullet x and y coordinates equal the target x and y coordinates, then that target is damaged.
     That works - I tried it - but there might be something more efficient out there.  However, this is the best I can come up with.

-----------------------------------
Zampano
Tue May 06, 2008 5:51 pm

Re: Help with collision detection for Space Invaders Remake.
-----------------------------------
He knows the entirety of coordinates, and used that. Theory is no object. The problem, I think, is here:
if lazery (count1) >= enemyy (count) - 10 and lazerx (count1) = enemyx (count) - 30 or lazery (count1) 