Need help with missiles in spaceshooter
Author |
Message |
PhOeNiX-47
|
Posted: Wed May 19, 2004 4:49 pm Post subject: Need help with missiles in spaceshooter |
|
|
Here's my code:
code: | View.Set ("offscreenonly")
colourback (black)
cls
var chars : array char of boolean
var fb := 200 % Up / Down
var lr := 300 % Left / Right
var fire := 0 % Check if the thing is fired!
var sb := maxy - 10 % Missiles going up
var su := 0 % Missile starting point left or right
var pic : int := Pic.FileNew ("spaceship2.bmp")
loop
cls
Input.KeyDown (chars)
if chars (KEY_UP_ARROW) then
fb := fb + 5
end if
if chars (KEY_DOWN_ARROW) then
fb := fb - 5
end if
if chars (KEY_LEFT_ARROW) then
lr := lr - 5
end if
if chars (KEY_RIGHT_ARROW) then
lr := lr + 5
end if
if lr <= 25 then
lr := 25
elsif lr >= maxx - 25 then
lr := maxx - 25
end if
if fb <= 25 then
fb := 25
elsif fb >= maxy - 25 then
fb := maxy - 25
end if
Pic.Draw (pic, lr - 25, fb - 24, picMerge)
if chars ('x') then
fire := 1
end if
if fire = 1 then
sb := sb + 1
drawfillbox (su - 1, sb, su + 1, sb + 10, yellow)
Pic.Draw (pic, lr - 25, fb - 24, picMerge)
end if
if sb + 10 = maxy then
fire := 0
sb := fb
su := lr
end if
View.Update
end loop
|
I know I'm doing something wrong but it's not the starting point of the missiles. I can fix that part. I want to be able to shoot more than 1 missiles. I cant seem to figure out what to use. Any help would be appreciated! Thanks! |
|
|
|
|
|
Sponsor Sponsor
|
|
|
PhOeNiX-47
|
|
|
|
|
MyPistolsIn3D
|
Posted: Wed May 19, 2004 4:53 pm Post subject: (No subject) |
|
|
post ur spaceship pic |
|
|
|
|
|
MyPistolsIn3D
|
Posted: Wed May 19, 2004 5:08 pm Post subject: (No subject) |
|
|
This?
code: | if fire = 1 then
sb := sb + 1
drawfillbox (su - 1, sb, su + 1, sb + 10, yellow)
drawfillbox (su + 5, sb, su + 7, sb + 10, yellow)
drawfillbox (su + 12, sb, su + 10, sb + 10, yellow)
Pic.Draw (pic, lr - 25, fb - 24, picMerge)
end if |
|
|
|
|
|
|
s_climax
|
Posted: Wed May 19, 2004 5:15 pm Post subject: (No subject) |
|
|
Obviously he means more than one in a line, not row. He wants it so that you can press a button and many bullets are made. |
|
|
|
|
|
Cervantes
|
Posted: Wed May 19, 2004 6:48 pm Post subject: (No subject) |
|
|
the best way to do this is to use a flexible array. initilize it as 1 .. 0 and then whenever the player hits x have it create a new element to the array, using the new command. have it go forward and then after a certain amount of time have delete the element in the array, i think using the free command. I'm not sure if this is the command though, so whoever knows can enlighten us.
(you can delete elements in a flexible array in turing can't you? I haven't needed to yet, so im not sure) |
|
|
|
|
|
Catalyst
|
Posted: Wed May 19, 2004 7:01 pm Post subject: (No subject) |
|
|
an easier way to this would just to use a normal array with a max value (lets say 50) and have each one (along with x,y,speed, etc) have if its alive or dead. Set them all dead to start then when someone goes to fire loop through the array then initialize the first dead one you encounter (in the intialization set that one to alive,etc then exit the loop ) Once the bullet leaves the screen or hits an enemy set it back to dead (dont draw the dead bullets tho)
This method should be less costy as the whole array doesnt need to be shifted if one of the earlier values goes dead |
|
|
|
|
|
Cervantes
|
Posted: Wed May 19, 2004 7:25 pm Post subject: (No subject) |
|
|
less costy? that way you've got 50 elements, with flexible array you've only got as many elements as you need |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Catalyst
|
Posted: Wed May 19, 2004 7:29 pm Post subject: (No subject) |
|
|
i was refering to processing time
in my method only need to search loop through part of the array each time (worst case: entire array) to add another shot.
Ur method is costly in the fact to remove an element from an array (when it is not at the end) the array must be recopied and shifted over, also youd be allocating new memory all the time which also take speed, and that assuming you can even delete an element of a flexible array in turing |
|
|
|
|
|
PhOeNiX-47
|
Posted: Wed May 19, 2004 7:59 pm Post subject: (No subject) |
|
|
So flexible array would make me be able to do infinite missles. Normal will set a limited about of it? Am I right or hullucinating? |
|
|
|
|
|
s_climax
|
Posted: Wed May 19, 2004 8:04 pm Post subject: (No subject) |
|
|
Not really. It is unlikely no will have 50 bullets on the screen at the same time. |
|
|
|
|
|
PhOeNiX-47
|
Posted: Wed May 19, 2004 9:13 pm Post subject: (No subject) |
|
|
Damn, I tried... Array stuff is so new and basic to me... Any can help me out by giving me some info on the coding itself? |
|
|
|
|
|
|
|