Shooting (Redudant question probably)
Author |
Message |
Geostigma
|
Posted: Sun Apr 01, 2007 10:55 am Post subject: Shooting (Redudant question probably) |
|
|
Well, after about looking through 6 different programs on how to making something shoot and move properly you know I was like "Well its not hard" So I ended up making a shooting procedure. I failed to get the procedure to work and realized that "Hey not going to work anyways because the program won't do anything until the shooting is done. So I know forks can run processes so I took about 30mins figuring out processes and forks and found that its not as complicated as the example given in the reference file that comes with Turing.
I got my fork to work with my little music process when it touches a black hole, sound plays then the ship spins out. Then this is where things get hairy. I wrote my shooting process. Played around with it and got this.
code: | %Bullet process set (LOL I GOT BULLETS)
process bullet1
var bxpos, bypos: int
bxpos := ypos
bypos := xpos
if face = "right" then
for i : bxpos .. maxx by 5
b1 := i
Draw.FillOval (b1, b2, 5, 5, white)
delay(500)
end for
end if
if face = "left" then
for decreasing i : bxpos .. 1 by 5
b1 := i
Draw.FillOval (b1, b2, 5, 5, white)
delay(500)
end for
end if
if face = "up" then
for i : bypos .. maxy by 5
b2 := i
Draw.FillOval (b1, b2, 5, 5, white)
delay(500)
end for
end if
if face = "down" then
for decreasing i : bypos .. 1 by 5
b2 := i
Draw.FillOval (b1, b2, 5, 5, white)
delay(500)
end for
end if
end bullet1 |
2 problems.
1. I can fix this one, the position and direction that the bullets fly are wrong and messed up but thats something I can fix.
2. The bullets don't fly across the screen and just flicker or stay in the same spot.
I took a look at a bunch of other programs and some of them have Arrays for the bullet. I'm not sure how to do this. Every person who codes something ends up doing something that shoots and I must be the only person who hasn't gotten it lol. Oh extra info is that this process is in its own file that Turing includes in my main program, not sure if you need to see it or not. (wanted to save reading useless code)
Oh and should I even use a process for this? apparently processes are bad and if I can avoid using them I would like to know how |
|
|
|
|
|
Sponsor Sponsor
|
|
|
CodeMonkey2000
|
Posted: Sun Apr 01, 2007 3:40 pm Post subject: RE:Shooting (Redudant question probably) |
|
|
You shouldn't be using processes. Just use flexible arrays with records. Make a procedure called 'bullet' and have it take in a parameter (which will be the current element of your bullets array) then make a for loop from 1 to the number of bullets calling the procedure. If you don't know what I'm talking about check out the Turing Walkthrough |
|
|
|
|
|
Clayton
|
Posted: Sun Apr 01, 2007 3:56 pm Post subject: Re: Shooting (Redudant question probably) |
|
|
You're kind of close CodeMonkey, but you're not at the same time.
Basically, you need to have an array of bullets. This array is preferrably of the flexible variety. Now, each bullet has it's own pieces of information, or attributes that it knows about itself. We know that a standard regular old data type won't do. So instead, we make our own, using a record. With this, we can give each bullet the attributes it needs: x velocity, y velocity, it's speed, etc.
CodeMonkey's idea was right on how to control the bullets, although the explanation was a bit foggy. Basically you want a function that will take in a bullet parameter. This function will then create a new bullet's attributes based on the ones that are given through the parameter. After that, the function will return the new bullet for you to do with as you wish.
For help on any of these topics, check out the Turing Walkthrough for tutorials on their respective subject.
Also: Why You Should Avoid Processes. |
|
|
|
|
|
Geostigma
|
Posted: Sun Apr 01, 2007 7:30 pm Post subject: RE:Shooting (Redudant question probably) |
|
|
Yeah I read that like 3 times. Ill take a whack at it.
My brain seriously hurts from trying to figure this out. I probably just need a break from this. I understand how to use arrays(before hand) but the tutorial on records makes no sense at all other then giving a fancy name to a group of variables. I know thats not what its trying to explain but, I cant comprehend what its explaining. |
|
|
|
|
|
Expirant
|
Posted: Mon Apr 02, 2007 10:26 am Post subject: Re: Shooting (Redudant question probably) |
|
|
A record is a group of variables, yes, but it's a group of variables that are attached to an individual variable. So that each variable of that record type has its own subset of variables. Here's an example:
code: |
% This program has five bullets of type bulletType, and gives them each their own x and y coordinates then draws them.
type bulletType : % This is the name of the type.
record
xCoordinate : real % Each bullet has its own individual x coordinate
yCoordinate : real % Each bullet has its own individual y coordinate
end record
var bullets : array 1 .. 5 of bulletType % This is an array with 5 bullets
for bullet : 1 .. upper (bullets)
bullets (bullet).xCoordinate := bullet * 10 % This gives each bullet an x coordinate
bullets (bullet).yCoordinate := bullet * 10 % This gives each bullet a y coordinate
end for
for bullet : 1 .. upper (bullets)
Draw.FillOval (round (bullets (bullet).xCoordinate), round (bullets (bullet).yCoordinate), 5, 5, black) % Draw each bullet at its coordinate.
end for |
(if anyone could let me know how to put the code into Turing format here, I'd appreciate it.) |
|
|
|
|
|
Geostigma
|
Posted: Tue Apr 03, 2007 8:19 pm Post subject: Re: Shooting (Redudant question probably) |
|
|
Ah! Got my bullets working as a process. Bad I know, but its working at the moment! Now I just need to figure out how to apply it as a procedure or something other then process. |
|
|
|
|
|
ericfourfour
|
Posted: Tue Apr 03, 2007 11:15 pm Post subject: RE:Shooting (Redudant question probably) |
|
|
It is good to start with something small and work your way up.
Instead of working with bullets, try and get two circles moving around the screen, at the same time, in different directions and speeds. Use only one loop and keep your looping code in this order: calculate, clear screen, draw, delay. Do not use processes.
Repost what you come up with. |
|
|
|
|
|
Geostigma
|
Posted: Fri Apr 06, 2007 8:24 pm Post subject: RE:Shooting (Redudant question probably) |
|
|
I know how to make two balls move across the screen at the same time. Ill definitely write that program up for you and repost it. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|