
-----------------------------------
sliverofshadows475
Tue Nov 25, 2008 12:45 pm

Problem with Shooting (Space Invaders Game)
-----------------------------------
Hey guys, I've just come to ask about a question about shooting. You know Space Invader's laser beam that destroys the aliens? I've got the sprite part down, but not the laser beam that comes out. I've tried using the Draw.Line, and changing the x and y based on the movement of the laser cannon, but instead of getting what I need, a diagonal line appears from a point, and it's length and direction just changes when I move the cannon..

If anyone could help me, it would be greatly appreciated.

Thanks,

sliverofshadows475

-----------------------------------
The_Bean
Tue Nov 25, 2008 3:12 pm

Re: Problem with Shooting (Space Invaders Game)
-----------------------------------
It's hard to troubleshoot something without the code, but if your getting a diagonal line then that means that your 2 x coordinates of the line are different, so if the line is suppose to be a perfect vertical try making them the same.

-----------------------------------
sliverofshadows475
Wed Nov 26, 2008 10:45 am

Re: Problem with Shooting (Space Invaders Game)
-----------------------------------
Sorry that I didn't post the code, I just learned how to. >.>

 
var x : int := 300
var y : int := 100 
var keys : array char of boolean

loop 
    Input.KeyDown (keys) 

    if keys (KEY_LEFT_ARROW) and x > 0 then 
        x -= 1 
    end if 

    if keys (KEY_RIGHT_ARROW) and x < maxx then 
        x += 1   
    end if 
    
    if keys (' ') then
        drawline (200,200+x,100,100,red)
        delay(7)
        drawline (200,200+x,100,100,white)
    end if
    Draw.Oval (x, y, 10, 10, black) 
    delay (4) 
    cls
end loop 


So right now, there's this, which changes the angle of the line as the ball moves around. I've tried playing around with the coordinates, but I can't seem to get the line to come out of the point where the ball is. So is it possible to get the 'drawline' to draw so that it looks like it's coming out of the ball?

(Oh, and thanks, The_Bean for looking at my problem)

-----------------------------------
MihaiG
Wed Nov 26, 2008 2:59 pm

Re: Problem with Shooting (Space Invaders Game)
-----------------------------------

var ballx : int := 300
var bally : int := 100
var keys : array char of boolean
var x, y : real
var tx, ty : real
x := 20
y :=10
loop
    Input.KeyDown (keys)
    if keys (KEY_LEFT_ARROW) and x > 0 then
        ballx -= 1
    end if
    if keys (KEY_RIGHT_ARROW) and x < maxx then
        ballx += 1
    end if
    if keys (KEY_UP_ARROW) then
        tx := x
        ty := y
        x := cosd (1) * tx + sind (1) * ty
        y := cosd(1)*ty -sind(1)*tx
    end if
    if keys (KEY_DOWN_ARROW) then
        tx := x
        ty := y
        x := cosd (1) * tx - sind (1) * ty
        y := sind (1) * tx + cosd (1) * ty
    end if
    Draw.Line (ballx, bally, ballx + round (x), bally + round (y), 7)
    Draw.Oval (ballx, bally, 10, 10, black)
    delay (4)
    cls
end loop

i think that is what you were trying to do,

essnetially to create the rotating/swiveling cannon, i used a rotation matrix

http://en.wikipedia.org/wiki/Transformation_matrix

you can read up on it there,

basically using that i rotate an arbritary point around the origin and then i shift it to the position of the ball, i suggest just playing around with the code to get a good understanding of how it works, if you do not understand how it works i suggest against it, since yuor teacher might become suspicious as to how you know transformation matricies/ matrix multiplication :)

-----------------------------------
Parker
Thu Nov 27, 2008 8:20 am

Re: Problem with Shooting (Space Invaders Game)
-----------------------------------
I have made it so you shoot from your circle when you move. It doesn't shoot diagonally, just straight you can figure that part out I hope (because I can't lol.)

var x : int := 300 
var y : int := 100 
var keys : array char of boolean 

loop 
    Input.KeyDown (keys) 

    if keys (KEY_LEFT_ARROW) and x > 0 then 
        x -= 1 
    end if 

    if keys (KEY_RIGHT_ARROW) and x < maxx then 
        x += 1    
    end if 
    
    if keys (' ') then 
        drawline (x,300,x,100,red) 
        delay(7) 
        drawline (x,300,x,100,white) 
    end if 
    Draw.Oval (x, y, 10, 10, black) 
    delay (4) 
    cls 
end loop 


-----------------------------------
sliverofshadows475
Sun Nov 30, 2008 11:32 am

Re: Problem with Shooting (Space Invaders Game)
-----------------------------------
Thank you both, Parker and MihaiG, both were very helpful (though yes, I admit, matrix manipulation is a bit hardcore for me.)
