Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,534 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 3 1 2 3
Re: Best way to do things ( random grass generator [Re: Ready] #179731
01/24/08 19:43
01/24/08 19:43
Joined: Aug 2007
Posts: 286
DestroyTheRunner Offline OP
Member
DestroyTheRunner  Offline OP
Member

Joined: Aug 2007
Posts: 286
Nice thanks Ready
that article in AUM47 might solve my problem, Ill try it when i get home today, and tomorrow IŽll post the results at work.

In case anyone else have any idea, tip, opinion about the original post please post it up, i am always gathering Render, FPS , memory information as much as I can to improve my game since its aimed to average strength computers.(something like P3 1000mhz 128 or 256mb of ram, GeForce2 64mb, is it too weak?)

Re: Best way to do things ( random grass generator [Re: DestroyTheRunner] #179732
01/24/08 19:45
01/24/08 19:45
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
Quote:


So am i really going to define 200 ENTITIES MANUALLY?




Noo noo, of course not manually . You can store entity pointers in variable arrays. But I can not provide you the full code now, it would take time to figure out a good method, but this is how you should basicly do it (code in green is code you should add, orange is psuedo thus you yet need to define it):

Code:

var grass_array_x[1000];
var grass_array_y[1000];
var grass_pointer[200];
var grass_array_index;


function create_grass()
{
while(grass_array_index < 1000) {
grass_array_x[grass_array_index] = random(10000);
grass_array_y[grass_array_index] = random(10000);

grass_array_index += 1;
}
}


function run_grass() {
var i;
while(i < 200) {
grass_pointer[i] = ent_create ("grass.tga", nullvector, NULL);
i += 1;
}

while(1) {
while(i < grass_array_index) {
you = grass_array_index[i];

if (vec_dist (you.x, player.x) > 1000) {
you.x = closest_stored_xpoint_to_player; //that is not already taken by a grass sprite
you.y = closest_stored_ypoint_to_player;

}
}
wait(1);
}
}




Now the orange part is most certainly not the easiest part, and because you have predefined positions, it's alot more calculating and loops than just placing at random places. I do advise you to not use fixed positions for this reason, but there might be a different method I have not thought of to handle this (maybe involve an entity it's skill variables).


Click and join the 3dgs irc community!
Room: #3dgs
Re: Best way to do things ( random grass generator [Re: Joozey] #179733
01/24/08 19:47
01/24/08 19:47
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
As for the pointers, their pointers are also stored in variables without using ptr_for_handle. There's use for this function, but it is slow and I think you wont need it here.


Click and join the 3dgs irc community!
Room: #3dgs
Re: Best way to do things ( random grass generator [Re: Joozey] #179734
01/24/08 20:09
01/24/08 20:09
Joined: Aug 2007
Posts: 286
DestroyTheRunner Offline OP
Member
DestroyTheRunner  Offline OP
Member

Joined: Aug 2007
Posts: 286
Alright thanks Joozey
IŽll try to do the code at home, and tomorrow IŽll post it.

thanks and good night (its 18:00 here in brazil)


Re: Best way to do things ( random grass generator [Re: DestroyTheRunner] #179735
01/25/08 19:42
01/25/08 19:42
Joined: Aug 2007
Posts: 286
DestroyTheRunner Offline OP
Member
DestroyTheRunner  Offline OP
Member

Joined: Aug 2007
Posts: 286
OK
i made it work ( not really) Im still implementing some features to make it more reallistic but the OVERALL IDEA works but with ONE BLOODY PROBLEM.
here is the code
Code:

function put_grass()
{

if(grass_index < 200)
{

teste2 =grass_index; //just for debugging purposes
you = grass_pointer[grass_index];

you.x = nearest_pos_x;
you.y = nearest_pos_y;

grass_index += 1;

}

return;

}


function define_nearest_pos()
{
grass_index = 0; //reset
grass_array_index = 0; //reset


while(grass_array_index < 1000)
{
if(vec_dist(global_player_pos.x,grass_array_x[grass_array_index] ) < 8000)&&(vec_dist (global_player_pos.y, grass_array_y[grass_array_index]) < 8000)
{

nearest_pos_x = grass_array_x[grass_array_index];
nearest_pos_y = grass_array_y[grass_array_index];
put_grass();
}

grass_array_index += 1;
}

}

function initial_grass_func()
{
my.passable = on;
my.scale_x = 0.5;
my.scale_y = 0.5;
my.scale_z = 0.5;
my.z = 64;

}


function define_grass_and_positions()
{
i_max_grass = 0;//reset
i_grass_array_index = 0; //reset


while(i_grass_array_index < 1000)
{
grass_array_x[i_grass_array_index] = random(10000);
grass_array_y[i_grass_array_index] = random(10000);
i_grass_array_index += 1;
}

while(i_max_grass < 200)
{
grass_pointer[i_max_grass] = ent_create (grass1, nullvector, initial_grass_func);
i_max_grass += 1;
}

if(i_grass_array_index >= 1000)&&(i_max_grass >= 200){define_nearest_pos();}//IF its has finished defining and creating ...

}



At first the "define_grass_and_positions()" function is called first, then down the road the function "define_nearest_pos()" is called by another function(not listed here) eveytime the variable "grass_array_index" gets to a 1000 so its always updating.


The problem is
Everytime I start the Engine sometimes its just doesnt work, the variable "grass_index" stays at 0 (zero) and sometimes it works fine.


anyone has any idea why?

Re: Best way to do things ( random grass generator [Re: DestroyTheRunner] #179736
01/25/08 23:39
01/25/08 23:39
Joined: Dec 2006
Posts: 1,086
Queensland - Australia
Nidhogg Offline
Serious User
Nidhogg  Offline
Serious User

Joined: Dec 2006
Posts: 1,086
Queensland - Australia
Maybe you need to add the wait(1) statement after the while(something) statements.

I believe your supposed to add them otherwise it does casue problems.

best of luck..


Windows XP SP3
Intel Dual Core CPU: E5200 @ 2.5GHz
4.00GB DDR3 Ram
ASUS P5G41T-M LX
PCIE x16 GeForce GTS 450 1Gb
SB Audigy 4
Spyware Doctor with AntiVirus
Re: Best way to do things ( random grass generator [Re: Nidhogg] #179737
01/28/08 11:55
01/28/08 11:55
Joined: Aug 2007
Posts: 286
DestroyTheRunner Offline OP
Member
DestroyTheRunner  Offline OP
Member

Joined: Aug 2007
Posts: 286
yeah i thought about that. IŽve trying to test Wait(1) statements everywhere, and the same happens, sometimes work sometimes not, something that i could figure out is that when it doesnt work means that the Put_Grass() has not even been CALLED!
anymore ideas?



Re: Best way to do things ( random grass generator [Re: DestroyTheRunner] #179738
01/28/08 17:55
01/28/08 17:55
Joined: Aug 2007
Posts: 286
DestroyTheRunner Offline OP
Member
DestroyTheRunner  Offline OP
Member

Joined: Aug 2007
Posts: 286
HEELP
lol

Re: Best way to do things ( random grass generator [Re: DestroyTheRunner] #179739
01/28/08 19:57
01/28/08 19:57
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands


if(i_grass_array_index >= 1000)&&(i_max_grass >= 200){define_nearest_pos();}//IF its has finished defining and creating ...


Well heres a mistake, should give a compile error. you close the if but youre not done with your statement yet.

Code:

if(i_grass_array_index >= 1000&&i_max_grass >= 200){define_nearest_pos();}//IF its has finished defining and creating ...



You do not need the IF at all anyway, for you will only reach the call to function define_nearest_pos() if the while loops are completed.
I don't think it will work if I look to the rest of your code, but ;et's first see what happens now...


EDIT
Where do you fill the variable grass_index at all? Only in the function put_grass and surely nowhere else?

Last edited by Joozey; 01/28/08 20:04.

Click and join the 3dgs irc community!
Room: #3dgs
Re: Best way to do things ( random grass generator [Re: Joozey] #179740
01/29/08 14:01
01/29/08 14:01
Joined: Aug 2007
Posts: 286
DestroyTheRunner Offline OP
Member
DestroyTheRunner  Offline OP
Member

Joined: Aug 2007
Posts: 286
hey joozey
doing ifs like this ()&&() never gave me any problem.
and now that i found the problem yesterday i know the problem isnt there.
a friend of mine helped me figure it out.

As far as i could understand this is wrong:

Code:
if(vec_dist(global_player_pos.x,grass_array_x[grass_array_index] ) < 8000)&&(vec_dist (global_player_pos.y, grass_array_y[grass_array_index]) < 8000)



because vec_dist compares vectors with 3 values, so, global_player_pos.x is actually global_player_pos.x.y.z together comparing with grass_array_x[x x x] which is not what i want to compare, so i had to do something more arcaic.

Code:

temp.x = grass_array_x[grass_array_index];
temp.y = grass_array_y[grass_array_index];
temp.z = global_player_pos.z;

if((temp.x - global_player_pos.x ) < 8000)&&((temp.y -global_player_pos.y ) < 8000)
{
...




and for some reason it works fine!!
So IŽll begin been more careful when using Vec_Dist func.

thanks you all for the attention.


Page 2 of 3 1 2 3

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1