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

Username:   Password: 
 RegisterRegister   
 Using arrays to create more then one same kind of objects
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
zedx_26




PostPosted: Sat Jan 20, 2007 10:45 pm   Post subject: Using arrays to create more then one same kind of objects

Hello every one. I am a nwebie programmer this my first time attempting to make a game. I neede help with making bullets for my ship. I know i am suppose to use array but dont know how to. I want to creat 20 bullets with same size. one of them is fired every time i hit space bar.

thanks in Advance
Sponsor
Sponsor
Sponsor
sponsor
Ultrahex




PostPosted: Sun Jan 21, 2007 11:07 am   Post subject: Re: Using arrays to create more then one same kind of objects

Well there is actually many ways to do this;

for each bullet you need an x and y im supposing, cause you didn't give enough information.

so you could create 2 arrays

code:
var bullet_x:array 1..20 of int
var bullet_y:array 1..20 of int


or you could create a new type, and make an array of it.
code:
type bullet :
      record
           x:int
           y:int
      end record

var bullets:array 1..20 of bullet


both have their own learning curves to them, expessially the second one, im supposing you are almost finished and this is for class, so if you never did the second way; i would recommend doing the first way to save you some time.
zedx_26




PostPosted: Sun Jan 21, 2007 12:31 pm   Post subject: Re: Using arrays to create more then one same kind of objects

THANKS MAN THIS HELPED A LOT
Robert




PostPosted: Sun Jan 21, 2007 12:37 pm   Post subject: RE:Using arrays to create more then one same kind of objects

If you plan on adding more properties (like damage, size, and speed) to the bullets, then use the array of records.
zedx_26




PostPosted: Sun Jan 21, 2007 1:05 pm   Post subject: Re: Using arrays to create more then one same kind of objects

i just made a sample program using 2 array. I was wondering that how can i chek that first bullet is = 600. I would like you to inform me if i am on right track..

It would be good if there wouldbe some more examples

her is the code:

var x: array 1..20 of int
var y: array 1..20 of int

var count:= 0

for i: 1..20
delay(1000)
x(i):= 10
y(i):= 10
count:= count + 10
Draw.Oval(x(i) ,y(i) ,10,10,1)

for k: 1..20

delay(100)
x(k):= x(i) + 10
%y(k):= x(i) + 10
Draw.Oval(x(i) ,y(i) ,10,10,1)
if x(1) = 600 then


exit
end if

end loop
end for
end for
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  [ 5 Posts ]
Jump to:   


Style:  
Search: