Need help!

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Vellelzza
Posts: 8
Joined: December 19th, 2012, 8:50 pm

Need help!

Post by Vellelzza » December 19th, 2012, 8:55 pm

So, I am recreating a game that I made in VB.Net before but my problem is that I don't know how can I create an array of keyedsurfaces and how do you initialize it if I am not mistaken chili showed it in some tut but I can't remember for sure and I'm not trying to create animated thing but just array of enemies.

Musi
Posts: 106
Joined: November 25th, 2012, 1:06 am

Re: Need help!

Post by Musi » December 19th, 2012, 11:12 pm

Not sure if i understand the question. If you just want to create an array and initialize it.

Code: Select all

Enemy enemiesArray[ numberOfEnemies ];

//Initialize it in a for loop.
for( int i = 0; i < numberOfEnemies; i++ )
{
      enemiesArray[ i ] = //Whatever you want...
}
What is a keyedsurface? How are the enemies defined, as a structure?
Musi

There are 10 types of people that understand binary.
Those that do, and those that don't.

Vellelzza
Posts: 8
Joined: December 19th, 2012, 8:50 pm

Re: Need help!

Post by Vellelzza » December 20th, 2012, 8:48 am

Musi wrote:Not sure if i understand the question. If you just want to create an array and initialize it.

Code: Select all

Enemy enemiesArray[ numberOfEnemies ];

//Initialize it in a for loop.
for( int i = 0; i < numberOfEnemies; i++ )
{
      enemiesArray[ i ] = //Whatever you want...
}
What is a keyedsurface? How are the enemies defined, as a structure?
Yea, sorry my question was not very clear but I'm trying to create a game where theres enemies scrolling from top and you are in the bottom and you must shoot all the enemies, so I got to the point where I have the player and one enemy but I want multiple enemies to come from the top... I hope I made the question clearer :)

User avatar
natox1986
Posts: 53
Joined: December 14th, 2012, 1:11 pm

Re: Need help!

Post by natox1986 » December 20th, 2012, 12:13 pm

You want multiple enemies at the same time? Or only 1 at the time?

If you want multiple units then use the method Musi is showing you.
It's the method that Chili teaches in his videos ( I think lesson 12-13-14, something around there ).
I had a pretty hard time understanding that concept at first too.
But basically all that loop does for you is making multiple 'unique' entities because each of them has a different 'sub-name' ( [ index ] ) that is defined by the array index number.

So, in example.... if you want 3 entities... you make 3 unique entities of the same type by looping the entity (accessing) by index:

Code: Select all

for( int index = 0; index < numberOfTargets; index++)
{
     entity[ index ] = /* make them whatever you like */ ;
}
This creates multiple entities like entity[0], entity[1] and entity[2]. The amount depends on the value you assigned to "numberOfTargets" which is defined by yourself at first, ( see video Beginner Lesson 13: http://www.youtube.com/watch?v=rcx3VbSv0yI ).

And every time your frame is reloaded (like 60 times a second or '60 fps') this loop reads the entity array again. So then you can do all kind of freaky things with it because they all have the unique-subname.

You can make one disappear by making it collide with another, or with your target-reticle or whatever, or you could simply redefine the current location of an entity (make them move). All because they are seperate entities because of this array definition.

Isn't that beautiful :D

* Edit : Typos
Image

Vellelzza
Posts: 8
Joined: December 19th, 2012, 8:50 pm

Re: Need help!

Post by Vellelzza » December 20th, 2012, 1:14 pm

natox1986 wrote:You want multiple enemies at the same time? Or only 1 at the time?

If you want multiple units then use the method Musi is showing you.
It's the method that Chili teaches in his videos ( I think lesson 12-13-14, something around there ).
I had a pretty hard time understanding that concept at first too.
But basically all that loop does for you is making multiple 'unique' entities because each of them has a different 'sub-name' ( [ index ] ) that is defined by the array index number.

So, in example.... if you want 3 entities... you make 3 unique entities of the same type by looping the entity (accessing) by index:

Code: Select all

for( int index = 0; index < numberOfTargets; index++)
{
     entity[ index ] = /* make them whatever you like */ ;
}
This creates multiple entities like entity[0], entity[1] and entity[2]. The amount depends on the value you assigned to "numberOfTargets" which is defined by yourself at first, ( see video Beginner Lesson 13: http://www.youtube.com/watch?v=rcx3VbSv0yI ).

And every time your frame is reloaded (like 60 times a second or '60 fps') this loop reads the entity array again. So then you can do all kind of freaky things with it because they all have the unique-subname.

You can make one disappear by making it collide with another, or with your target-reticle or whatever, or you could simply redefine the current location of an entity (make them move). All because they are seperate entities because of this array definition.

Isn't that beautiful :D

* Edit : Typos
Okay, Thanks for help! :)

User avatar
natox1986
Posts: 53
Joined: December 14th, 2012, 1:11 pm

Re: Need help!

Post by natox1986 » December 20th, 2012, 1:32 pm

Vellelzza wrote:Okay, Thanks for help! :)
No problem, I hope it helps... if you don't understand parts of it, just check out the video again.
If you still have issues then, just ask! ;)
Image

Post Reply