Problem with Shooting (Space Invaders Game)
Author |
Message |
sliverofshadows475
![](http://compsci.ca/v3/uploads/user_avatars/454875928494e809837490.jpg)
|
Posted: Tue Nov 25, 2008 12:45 pm Post subject: 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 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
The_Bean
![](http://compsci.ca/v3/uploads/user_avatars/8459755754b4009cee84e9.jpg)
|
Posted: Tue Nov 25, 2008 3:12 pm Post subject: 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. |
|
|
|
|
![](images/spacer.gif) |
sliverofshadows475
![](http://compsci.ca/v3/uploads/user_avatars/454875928494e809837490.jpg)
|
Posted: Wed Nov 26, 2008 10:45 am Post subject: Re: Problem with Shooting (Space Invaders Game) |
|
|
Sorry that I didn't post the code, I just learned how to. >.>
Turing: |
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) |
|
|
|
|
![](images/spacer.gif) |
MihaiG
![](http://compsci.ca/v3/uploads/user_avatars/2070081168483773c3dead4.png)
|
Posted: Wed Nov 26, 2008 2:59 pm Post subject: Re: Problem with Shooting (Space Invaders Game) |
|
|
code: |
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 ![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
Parker
|
Posted: Thu Nov 27, 2008 8:20 am Post subject: 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.)
Turing: | 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
|
|
|
|
|
|
![](images/spacer.gif) |
sliverofshadows475
![](http://compsci.ca/v3/uploads/user_avatars/454875928494e809837490.jpg)
|
Posted: Sun Nov 30, 2008 11:32 am Post subject: 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.) |
|
|
|
|
![](images/spacer.gif) |
|
|