1 registered members (TipmyPip),
18,633
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Can entities be stored in arrays?
#205233
05/05/08 10:25
05/05/08 10:25
|
Joined: Jul 2007
Posts: 24
noobie86
OP
Newbie
|
OP
Newbie
Joined: Jul 2007
Posts: 24
|
Hi i'm trying to make a 2D/2.5D game with Gamestudio. Here's the scenario:
i have a board with 49 tiles/nodes. There are 8 types of entities in the game. At the start, all the 49 tiles are filled with any of these 8 entities, created randomly. Whenever i select any entity with the mouse, the surrounding entities need to be checked for a particular characteristic, say color. The number of entities to be checked vary from minimum 4 to maximum 12.
Presently how i'm doing this is: i have 49 entity pointers, each pointing to an entity on the board. eg ball5= ent_create(ball_red,ball_pos5,ball);
Next, i have 12 pointers for the case where maximum 12 need to be checked. An entity's skill11 and skill12 are set to 2 numbers, one for its node number and one indicating its color or type. When i select, say ball5, i need to check ball6, ball7, ball12 (5+7) and a lot more. The algorithm i'm using is
if(ball5 is selected) {store pointers ptr1=ball6, ptr2=ball7, ptr3=ball12 and so on for the 12 pointers}
The problem is, if this method is used, this line needs to coded for all 49 balls. 49 is ok but when the board is expanded to bigger sizes, the program length increases exponentially. Rather if i could store the entities in arrays, i could write
if (ball[n] is selected) {store pointers ptr1=ball[n+1], ptr2=ball[n+2], ptr3=ball[n+7] and so on}
This would make the program more efficient and simpler. Can entites be somehow stored in arrays?
|
|
|
Re: Can entities be stored in arrays?
[Re: noobie86]
#205237
05/05/08 10:35
05/05/08 10:35
|
Joined: Oct 2007
Posts: 5,211 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,211
İstanbul, Turkey
|
you may try linked lists, or arrays aswell.
You can mostly treat entites as normal structs you can store them in arrays. You can use 2D arrays. like ENTITY* ball[50][50]
if ball[x][y] is selected
ball[x-1][y], ball[x-1][y-1],ball[x-1][y+1] .... etc will stand for surrounding balls, if you fill array this way. You can also try linked lists with your balls but this will be more comlicated, if your board wont change it's size during runtime i suggest usin 2d arrays.
3333333333
|
|
|
Re: Can entities be stored in arrays?
[Re: noobie86]
#205248
05/05/08 11:31
05/05/08 11:31
|
Joined: Oct 2007
Posts: 5,211 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,211
İstanbul, Turkey
|
Make sure you are using lite-c(your file ext. must be ".c")
and ENTITY is written all capital.
3333333333
|
|
|
Re: Can entities be stored in arrays?
[Re: Joey]
#205404
05/06/08 13:26
05/06/08 13:26
|
mercuryus
Unregistered
|
mercuryus
Unregistered
|
ENTITY* ball[50][50] are just pointers. You have to use ball[2][7]=ent_create(....) to create an object.
|
|
|
Re: Can entities be stored in arrays?
[Re: ]
#205414
05/06/08 14:11
05/06/08 14:11
|
Joined: Dec 2003
Posts: 1,225 germany
gri
Serious User
|
Serious User
Joined: Dec 2003
Posts: 1,225
germany
|
What about using object-handles?
Why dont you store the entity handles in the array and read them if you need?
,gri
"Make a great game or kill it early" (Bruce Shelley, Ensemble Studios)
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|