Computer Science Canada shooting help |
Author: | mnorman [ Mon Apr 04, 2011 11:07 am ] | ||
Post subject: | shooting help | ||
What is it you are trying to achieve? Im trying to copy a game called Galaga for a school project What is the problem you are having? Im having problems with shooting and killing enemies, so any help you guys can provide will be greatly appreacited Describe what you have tried to solve this problem <Answer Here> Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) <Answer Here>
Please specify what version of Turing you are using <Answer Here> |
Author: | apython1992 [ Mon Apr 04, 2011 11:54 am ] |
Post subject: | RE:shooting help |
How about "Describe what you have tried to solve this problem" and "Post any relevant code"? |
Author: | Raknarg [ Mon Apr 04, 2011 3:02 pm ] |
Post subject: | RE:shooting help |
Well, I doubt you'd get it, but you could attempt at taking a look at my program in submissions... |
Author: | Raknarg [ Mon Apr 04, 2011 3:02 pm ] |
Post subject: | RE:shooting help |
Have you learned arrays yet? |
Author: | mnorman [ Tue Apr 12, 2011 11:24 am ] |
Post subject: | Re: shooting help |
yes i have |
Author: | apython1992 [ Tue Apr 12, 2011 11:37 am ] |
Post subject: | RE:shooting help |
You won't get much help until you show that you're trying to solve the problem and tell us everything you've tried, and exactly what you aren't sure how to do. You have to be specific. |
Author: | Raknarg [ Tue Apr 12, 2011 3:19 pm ] |
Post subject: | RE:shooting help |
You should post at least any code you have. If you don't know what to do at all, you should probs pick something easier. |
Author: | apython1992 [ Tue Apr 12, 2011 3:41 pm ] |
Post subject: | Re: RE:shooting help |
Raknarg @ Tue Apr 12, 2011 3:19 pm wrote: You should post at least any code you have. If you don't know what to do at all, you should probs pick something easier.
Well, one shouldn't resort to giving up and picking something easier just because he/she doesn't know how to do it. Learning is wonderful. |
Author: | Raknarg [ Tue Apr 12, 2011 3:44 pm ] |
Post subject: | RE:shooting help |
I know, but I'm just saying, for something as big as this, you should start with something easier if you don't know what to do, or at least in my opinion. Scratch my last post then. Give us any code if you have any. |
Author: | mnorman [ Wed Apr 13, 2011 10:22 am ] |
Post subject: | RE:shooting help |
heres what i have come up wiith so far and now i would appreicate help with adding enemies. Sorry for being such a nood but this is my first attempt at programming a game. Also how do i get to submissions? setscreen ("graphics:790;1050,nobuttonbar,position:center;center,offscreenonly") var bulletsX, bulletsY : flexible array 1 .. 0 of int var deadbullet : flexible array 1 .. 0 of boolean var chars : array char of boolean var counter : int := 50 var x : int := 450 var ship : int := Pic.FileNew ("small ship.bmp") var bullet : int := Pic.FileNew ("bullet.bmp") loop Input.KeyDown (chars) if chars (' ') and counter >= 50 then new bulletsX, upper (bulletsX) + 1 new bulletsY, upper (bulletsY) + 1 new deadbullet, upper (deadbullet) + 1 bulletsX (upper (bulletsX)) := 0 bulletsY (upper (bulletsX)) := x counter := 0 end if if chars (KEY_RIGHT_ARROW) and x - 10 >= 0 and x + 50 <= 790 then x := x + 2 elsif chars (KEY_LEFT_ARROW) and x - 10 >= 0 and x + 50 <= 790 then x := x - 2 elsif x - 10 <= 0 then x := x + 1 elsif x + 50 >= 790 then x := x - 1 end if colorback (7) Pic.Draw (ship, x, 70, picMerge) for i : lower (bulletsX) .. upper (bulletsX) if bulletsX (i) > maxx then deadbullet (i) := true bulletsX (i) := 10000 else deadbullet (i) := false end if if deadbullet (i) = false then bulletsX (i) := bulletsX (i) + 3 Pic.Draw (bullet, bulletsY (i) + 20, bulletsX (i) + 105, picMerge) end if end for View.Update counter := counter + 1 delay (5) cls end loop |
Author: | Raknarg [ Wed Apr 13, 2011 2:39 pm ] |
Post subject: | RE:shooting help |
On the home screen, go to turing then submissions. |
Author: | Raknarg [ Wed Apr 13, 2011 2:40 pm ] |
Post subject: | RE:shooting help |
could you link pictures too? just add an attachment |
Author: | apython1992 [ Wed Apr 13, 2011 2:51 pm ] | ||||
Post subject: | RE:shooting help | ||||
Just a side note, you're likely to get more help by posting properly formatted code using code/syntax tags. For example:
Would yield:
|
Author: | mnorman [ Thu Apr 14, 2011 10:16 am ] |
Post subject: | RE:shooting help |
do i have to do that for every line or just the first? |
Author: | mnorman [ Thu Apr 14, 2011 10:24 am ] | ||
Post subject: | Re: shooting help | ||
|
Author: | Raknarg [ Thu Apr 14, 2011 1:22 pm ] |
Post subject: | RE:shooting help |
Ok, thanks. So have you tried anything yet to get your enemies working? Wow, I just realized this is almost the exact same thing I started with XD |
Author: | mnorman [ Mon Apr 18, 2011 10:29 am ] |
Post subject: | Re: shooting help |
No but i want the enemies to spawn like this, also how do you upload a whole folder |
Author: | Raknarg [ Mon Apr 18, 2011 5:39 pm ] |
Post subject: | RE:shooting help |
Hmm... So, do you want to give the player the ability to shoot while this stuff is happening? |
Author: | mnorman [ Tue Apr 19, 2011 11:15 am ] |
Post subject: | RE:shooting help |
yes if that is possible |
Author: | Raknarg [ Tue Apr 19, 2011 3:43 pm ] | ||||
Post subject: | RE:shooting help | ||||
Indeed. Well, if you wanted that, I beleive you would have use arrays instead of separate placements, like this: Instead of:
you would have something like:
The reason for this is because you need to check every x and y position of your enemies compared to your bullets. @apython Any other ideas? |
Author: | mnorman [ Wed Apr 20, 2011 10:17 am ] |
Post subject: | RE:shooting help |
ok thanks ill give that a try |
Author: | apython1992 [ Wed Apr 20, 2011 4:14 pm ] |
Post subject: | RE:shooting help |
That looks good to me. As long as you have the bullets placed and directed properly with respect to whoever is firing, everything should take care of itself. |
Author: | mnorman [ Wed May 04, 2011 10:37 am ] |
Post subject: | Re: shooting help |
so this is what i cam up with and it mostly works, but i dont know what to do next. How do i get them to attack? |
Author: | Raknarg [ Wed May 04, 2011 3:54 pm ] | ||||
Post subject: | RE:shooting help | ||||
The same way you set up your bullets. The only difference would be is that you set enemubulletx and enemybullety as 2D flexible arrays. Ex. If you had 12 enemies:
Also, to use new in a flexible array, you do more or less the same thing as a 1D array. Ex. if you had an array 1 .. 0, 1 .. 0 and you wanted to change the second set of elements to 3:
|
Author: | mnorman [ Thu May 05, 2011 10:32 am ] |
Post subject: | Re: shooting help |
the way i have the bullets set up is that when the bullet "dies" its y value is just set to 10,000. So the bullet isn't removed from the array. So if the game goes on for a long time couldn't this slow down the computer because it has to track thousands of bullets? |
Author: | Raknarg [ Thu May 05, 2011 8:37 pm ] | ||
Post subject: | RE:shooting help | ||
Yes, I encountered the same problem when I started my game. What I did was just use an array. You don't actually need a flexible array, as I found out. You see, you porbably thought that "Oh, I don't know how many bullets are going to be on the screen, so I'll use a flexible array." No, you don't know how many there will be. But you know haw many there WON'T be. Using this, you can just use a simple array. When I set mine up, I had a bulletcounter that basically did this:
So when I did this, I could set the element at that counter number to whatever I needed. When the bullet dies, you can set the y to 10000 if you want. Then you have the bullets moving, draw statements, hit statements, etc. in opne for loop. See, the thing is that by the time it's the bullets turn again, it will most certainly already have died. Did you get all taht? Needs any clearing up? |
Author: | mnorman [ Fri May 06, 2011 10:16 am ] |
Post subject: | RE:shooting help |
ya sorry i do, i dont quite get the code |
Author: | Raknarg [ Fri May 06, 2011 3:34 pm ] | ||
Post subject: | RE:shooting help | ||
Ok. So first of all, you have an array. Now what I'm assuming you're doing right now is just checking to see if the gun timer meets the rate of fire number, then shooting. You'll do the same thing with a regular array, but there's going to be one more thing: You'll use a counter to keep track of the bullet number. So here's what I did. First off, set all bullets in the array to dead (lets assume there's 20 elements). Then, when the conditions of the shooting are all true (probably just gun timer > Rate of Fire number), we add one to the counter and set the conditions of the elements using that counter. I'll give you a snippet:
This way you can access the elements one by one and only when you need them. |
Author: | mnorman [ Mon May 09, 2011 11:26 am ] |
Post subject: | Re: shooting help |
i came up with something slightly different but it has a slight glitch |
Author: | Raknarg [ Mon May 09, 2011 4:46 pm ] | ||
Post subject: | RE:shooting help | ||
First of all:
Utterly useless. The only reason you need by is for jumping numbers. You don't need that here, so for i : 1 .. 50 is fine. |
Author: | Raknarg [ Mon May 09, 2011 5:45 pm ] | ||
Post subject: | Re: shooting help | ||
You have the checking for enemies AND the checking to see if the bullet is higher than maxy in the same line. I can't quite find the reason it's screwing up, but the infinite money glitch is most definitely in there. |
Author: | mnorman [ Tue May 10, 2011 8:15 am ] |
Post subject: | RE:shooting help |
ya your right, i seperated the maxy and it works better but now the enemies dont always die |
Author: | Raknarg [ Tue May 10, 2011 6:14 pm ] |
Post subject: | RE:shooting help |
hmm... do your enemies die separately on your new code? I tried your recent code and they all die if one is hit. |
Author: | mnorman [ Wed May 11, 2011 10:22 am ] |
Post subject: | RE:shooting help |
ya they do, do you want the new code, all i did was put the maxy line in a seperate elsif line |