Bennu Game Development

English Forums => General => Topic started by: MisterN on February 12, 2012, 03:02:57 AM

Title: Perfect Player Collision w/ level editor
Post by: MisterN on February 12, 2012, 03:02:57 AM
as the title says. I have worked on my platform engine to be a little better and use less resources. I have made a level editor, and I removed the need for the player to collide with a zillion different processes.
(http://forum.bennugd.org/index.php?action=dlattach;topic=2970.0;attach=2336)
(http://forum.bennugd.org/index.php?action=dlattach;topic=2970.0;attach=2338)
it only uses 8mb of ram, can you see why its not working on the dreamcast? thanks
Title: Re:Perfect Player Collision w/ level editor
Post by: handsource-dyko on February 12, 2012, 12:40:43 PM
Ahhh. It works nicely!  :) Very good job. You see, with a lot perservation and experimenting and patience you eventually reach your goal. ;)
Title: Re:Perfect Player Collision w/ level editor
Post by: MisterN on February 12, 2012, 04:31:18 PM
If I change the speed of the gravity it completely throws off the collision
Title: Re:Perfect Player Collision w/ level editor
Post by: handsource-dyko on February 12, 2012, 06:11:44 PM
That's weird. But, this may heve someting to do with the loop counter conditions. I hanven't looked at the code, but I recall a problem I had years back of a moving logo that moved down the screen. When the logo reached a certain y-value, the loop had to stop. But it didn't work because I used == and a even number as condition and my counter added in different steps. So the counter overshoot it's mark and the condion was never met. So, maybe your problem is simlair.
Title: Re:Perfect Player Collision w/ level editor
Post by: MisterN on February 12, 2012, 11:35:35 PM
Ok.

Now how do I spawn an enemy with structs?

enemy_a[0] = enemy_a();
enemy_a[0].x = x;
enemy_a[0].y = y;


does not work
Title: Re:Perfect Player Collision w/ level editor
Post by: handsource-dyko on February 13, 2012, 08:17:09 AM
A processes (like from an enemy for example) is a struct by itself. You have to modify the process instance data.
So you create process instances in a for loop. It is similair to blocks.


Title: Re:Perfect Player Collision w/ level editor
Post by: MisterN on February 13, 2012, 12:35:35 PM
example?
Title: Re:Perfect Player Collision w/ level editor
Post by: handsource-dyko on February 13, 2012, 04:16:36 PM
An array (list) that is used to store process id's. Note you can only change the processes' local and/or public data with this.


// array with process id's
int my_procs[9];


// code for putting processes on screen (a for loop is better if you have a lot of instances)
my_procs[0]=enemy(100,100);
my_procs[1]=enemy(100,200);
my_procs[2]=enemy(100,300);
my_procs[3]=enemy(100,400);
my_procs[4]=enemy(100,500);
my_procs[5]=enemy(100,600);
my_procs[6]=enemy(100,700);
my_procs[7]=enemy(100,800);
my_procs[8]=enemy(100,900);
my_procs[9]=enemy(100,1000);




Each process instance get's it's own id code when it's created, and we have stored them in the array for conveince.
This way, you can easily change the value's of a particulair enemy.

Let's change the x-value of enemy 7: my_procs[7].x=200;
This is similair to changing the values of a process  instance that causes a collision with another process instance. (Collision function
is based on id codes too, it's more or less the same).

In malvado I use a "hand cursor" in the editor. It simply uses the collision function, so I can affect the data of the object process instance I selected, but I also change the data structure. That's Why I stored the process id's in an array.

You can also inspect the data of instances with the debugger. Here's an example of the debugger in mampedit, showing th id code and the
data structure. http://dykodesigns.woelmuis.nl/bennu/malvado/dev-docs/entitytypes.html#mvs (http://dykodesigns.woelmuis.nl/bennu/malvado/dev-docs/entitytypes.html#mvs) (Right click on the images to enlarge them).

You may also look at this  http://code.google.com/p/malvado-bennuremake/wiki/ProcessIdentifiers] (http://code.google.com/p/malvado-bennuremake/wiki/ProcessIdentifiers) and  http://code.google.com/p/malvado-bennuremake/wiki/Defines (http://code.google.com/p/malvado-bennuremake/wiki/Defines) this as additional referencs.
Title: Re:Perfect Player Collision w/ level editor
Post by: MisterN on February 14, 2012, 12:44:05 AM
Can you take a look at this? The problem I am having is:
*if I place the objects and then press enter to load the level, everything is hidden behind what I just loaded.
*Same rule applies if I load the level first and then place objects
*The way things are, do you think itll work when loaded?

thanks
Title: Re:Perfect Player Collision w/ level editor
Post by: handsource-dyko on February 14, 2012, 08:25:33 AM
Do you clear the stucture first?
Title: Re:Perfect Player Collision w/ level editor
Post by: MisterN on February 14, 2012, 12:46:53 PM
I dont know
Title: Re:Perfect Player Collision w/ level editor
Post by: handsource-dyko on February 14, 2012, 03:47:54 PM
I noticed that old blocks stay in place.I see that you use the put function to place the blocks. What I mean is, that when you load/render a new level, you must clear (reset, same as rendering, but now putting default data in) the data structure, and replace the blocks with empty ones. Basically you just put black or "empty" tiles over the old ones. If you use processes, you just kill them before you create new ones (for enemies etc).
Title: Re:Perfect Player Collision w/ level editor
Post by: MisterN on February 14, 2012, 06:43:14 PM
can you please throw it all together for me? im not doing processes for the level because that rapes the dreamcasts ram. my method only uses about 48% of the dreamcasts ram at all times.
Title: Re:Perfect Player Collision w/ level editor
Post by: handsource-dyko on February 16, 2012, 03:54:33 PM
I described it in a more general way. Process killing only for enemies in your case. For the backgrounds, put black tiles in place before you place
the "loaded" tiles from the level file. Basically, you do the same thing twice (more or less).
Title: Re:Perfect Player Collision w/ level editor
Post by: MisterN on February 16, 2012, 07:34:53 PM
im confused
Title: Re:Perfect Player Collision w/ level editor
Post by: MisterN on February 20, 2012, 10:07:30 PM
This really makes absolutely no help at all unless I have some physical code to study from like I did the level editor (I got peices of that from the tiled example on fenixonfire). I switched back to the level editor published in this thread.
Title: Re:Perfect Player Collision w/ level editor
Post by: handsource-dyko on February 21, 2012, 04:13:29 PM
What I mean is that you should modify your editor/engine with the stuff I told you. It is not that hard really. Just be creative. ;D
Title: Re:Perfect Player Collision w/ level editor
Post by: MisterN on February 22, 2012, 04:08:31 AM
Yes but im just confused. I just see words. I have tried and tried and tried and tried to get a struct variable to load a process, it will not happen.

level.pellet_obj[0] = pellet();
level.pellet_obj[0].x = x;
level.pellet_obj[0].y = y;

will save, but it will not load, please understand. I can advance so much if someone shows my why this isnt working and what I can do to make it work without a million lines of code. please
Title: Re:Perfect Player Collision w/ level editor
Post by: handsource-dyko on February 22, 2012, 06:36:55 PM
The reason that is saves but not loads is because you'll assign the data from the pellet process into the struct member. In code you show you'll basically assign the default value's of the process to level_pellet_obj[0]. This will not work, you'll need the process instance, wich is different thing than a process type. In your code it's a process type. Sure it save's something, it's the default data! ??? :'( When it comes to loading, you'll go through a for loop that creates the instances. A couple of posts earlier I told something about using an array for storing process identifiers. Whenever a new instance is created, that instance get's it's own id code and data. So when you want to save the data, you'll need
to go through all instances and copy their data in each successive struct member. Hence, that's why you should store porcess id's in an array, so that with one for loop, you can copy the data of each instance.

You know, this code:


// array with process id's
int my_procs[9];

// the process instances have been created with these datas
my_procs[0]=enemy(100,100);
my_procs[1]=enemy(100,200);
my_procs[2]=enemy(100,300);
my_procs[3]=enemy(100,400);
my_procs[4]=enemy(100,500);
my_procs[5]=enemy(100,600);
my_procs[6]=enemy(100,700);
my_procs[7]=enemy(100,800);
my_procs[8]=enemy(100,900);
my_procs[9]=enemy(100,1000);

// code for saving 10 instances
For (i=0; <9; i+=1)

   level.pellet_obj.x[i]=my_procs[i].x;
   level.pellet_obj.y[i]=my_procs[i].y;
End

save ("level.dat",level);


// now load from file (creates 10 process instances)
load ("level.dat",level);

For (i=0; <9; i+=1)
   my_procs[i]=enemy(level.pellet_obj.x[i],level.pellet_obj.y[i]);
End

// after this loop you'll have 10 enemy processes loaded from a file.


I hope this finally answers your question. :'( ::)
Title: Re:Perfect Player Collision w/ level editor
Post by: MisterN on February 22, 2012, 07:42:27 PM
so that means there has to be a total of 10, no more no less of that object when loaded?
Title: Re:Perfect Player Collision w/ level editor
Post by: handsource-dyko on February 23, 2012, 08:17:01 AM
Well, the number is what you want it to be. Depends on what you think that fits in memory. If your struct can hold 100 items, you dont't have put all of them on screen. That's why I always add a "used" variable, wich is either true or false. So when the file is loaded, the for loop does an extra check, if the value is true, it creates the process instance, if it's false, it skips it. In the malvado editor, when you add an item or delete one, this flag is set. That's all really. (It uses an algorithm that looks for such an empty slot when you insert an item, and if there isn't any, it will give an error message saying that the struct is full). Just try to put more then 50 bears in a level, that's the limit. But if there's at least one empty slot in the struct (becasue it's marked false) it add's an item. I created it this way because I didn't want to do a linked list because pointers give me a headache.
Title: Re:Perfect Player Collision w/ level editor
Post by: MisterN on February 24, 2012, 01:53:50 AM
code doesnt work, did what you said.
Title: Re:Perfect Player Collision w/ level editor
Post by: handsource-dyko on February 25, 2012, 01:56:31 PM
Isn't there an example in bennupack? I've looked at the 3 advandce\rpg_engine tutorial and a few others that have an editor.
My bennupack version is old, maybe newer versions have more examples. But I think you should be able to do it, I know that the wiki is lacking, but bennupack is full of examples.
Title: Re:Perfect Player Collision w/ level editor
Post by: MisterN on February 25, 2012, 04:01:50 PM
its hard to rewrite the whole engine though. Cant you just spend that 10 minutes figuring out how the code will work? Im not gonna lie, the amount of time arguing, it could have been solved then and there and id be far more into my code for I will not continue until this is done, and if it exists, ive looked at it, doesnt help me.
Title: Re:Perfect Player Collision w/ level editor
Post by: handsource-dyko on February 25, 2012, 08:49:46 PM
Well, that's the thing. It's not a mater of looking 10 minutes at it. Something like requires more time to do it right, and I don't have the time for it.

I have to admid, it took me years, with a lot of failed attemts, but that's something you'll learn from. Projects like this are more than just coding,  you need to consider your design and that requires a certain level of familairity with the language and programming concepts. I don't want to discourage you, but you have to experiment and accept that not all attempts are imidiately successfull the first time. Projects like this are long term things, you'll have to let it rest for some time, then get some ideas, mess with it, let rest again, do some other (smaller, more manageble) projects, get some more ideas, and eventually you'll reach to a point where everything becomes clear and fits together. ;)

I suggest you put it on a low pace, and just read some books about programming. I do this a lot, I found out that a lot of the stuff and concepts I read in C and pascal books is very usefull for bennu as well.
Title: Re:Perfect Player Collision w/ level editor
Post by: MisterN on February 25, 2012, 10:46:28 PM
Oh my god this is like the time I spent at a c++ forum
(http://images.wikia.com/batman/images/a/a4/The_Riddler_%28BF%29.jpg)
ive wasted 6 months and I cant delay the deadline any further. Im good at game mechanics, im not good at structures (actually I am good at structures, but howcome structures dont load processes when theyre loaded?).
Title: Re:Perfect Player Collision w/ level editor
Post by: SplinterGU on February 25, 2012, 11:01:18 PM
I don't understand if you have a problem with your code or what...

If you have a problem, try ask in spanish.
Title: Re:Perfect Player Collision w/ level editor
Post by: MisterN on February 25, 2012, 11:07:41 PM
forgot about that lol
Title: Re:Perfect Player Collision w/ level editor
Post by: SplinterGU on February 25, 2012, 11:13:15 PM
sorry, is very hard understand you, for me...
Title: Re:Perfect Player Collision w/ level editor
Post by: gecko on March 15, 2012, 03:30:15 AM
i think that the way you're looking for help it's the problem.

We're here to help, of course, but you want and insist on on us to do the job that is yours.

Ask for ways of doing things, or ways to fix things, or ways to solve problems, but do not expect us to DO YOUR GAME. You can only learn by doing it yourself.

(and sorry for my english)