Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 A Shooting Array
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TheLastFall




PostPosted: Tue Dec 12, 2006 12:15 pm   Post subject: A Shooting Array

I browsed the posts and I could not find any that could help me. I'm trying to make a game similar to the famous Space Invaders (Which is still in my opinion the best game in the world). I wrote down my code during English class and I know it doesn't work now but I can't really seem to find out whats wrong with it. I know that there are the procedure codes but I'm not quite sure how to use them so I tried an array, which to me looks like it'd work. I've tried and and I've recived several errors.
This is what I have:
code:

var bulletX : array 1 .. 10 of int               %% So only ten bullets will appear on screen
var bulletY : array 1 .. 10 of int               %% So only ten bullets will appear on screen
var bulX, bulY, bRad : int                        %% The starting location of the shot

bulX := maxx div 2 The 'x' axis of the position
bulY := 34                                              %% The 'y' axis of the position
bRad := 1                                               %% Size of the oval
const bSPD := 10                                    %% The speed the bullet is going

if chars (UP_ARROW_KEY) then

      for n : 1 .. 10                                     %% Changing the array + 1
          bulletX(n) := bulX                 %% Making that specific array start at the bulX position
          bulletY(n) := bulY                  %% Making that specific array start at the bulX position
      end for

drawfilloval (bulletX(n), bulletY(n),bRad,bRad, 255)

bulletY(n) += bSPD                                  %% How fast the bullet will move up

elsif (bulletY(n) => maxy or bulletY(n) =< 0) then %% So the array will decrease if the bullet goes off screen

      for decreasing n : 1 .. 10
          bulletX(n)
          bulletY(n)
      end for

end if


I do know some of the errors but I have no idea how to fix them. Is there any way other then using procedures? Your help would be very much appreciated. I've been trying to create a code that will shoot for a while and everything I've tried failed. I've been hitting my head off the wall on this. Hit Wall
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Tue Dec 12, 2006 1:41 pm   Post subject: (No subject)

You should be using flexible arrays for this. Why? Because we don't know how many bullets will have been fired at any given time.

Now, your code is setting every bullet to the starting position when the up arrow is pressed. Instead, it should create a new bullet and set it to that, and leave the others alone. Each bullet should have its own x, y, vx, and vy (velocities) values. To do this, you should know about records. Create an array of a record, rather than running 4 arrays in parallel.

Be sure to check out the Turing Walkthrough to get links to more tutorials that you might need.
TheLastFall




PostPosted: Wed Dec 13, 2006 12:05 pm   Post subject: (No subject)

Well thanks for the help, I'm just trying to figure out a collision now. Really confusing.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: