Question on breeding script

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
User avatar
Xen
Posts: 36
Joined: Fri Apr 02, 2010 11:41 am

Question on breeding script

Post by Xen »

Hello, just have a quick question.
I have been following Halls tutorials and couldn't see any information on this anywhere.
Basically my browser game is centered on training the creatures you own. Having looked at similiar sites and done some market research, I am considering implementing a breeding system. I have been searching for months on information regarding this, but whether I am using the wrong search words, or just looking in the wrong places, I can't seem to find any substantial info on what goes into making one. I have put together a brief design document on it, but without knowing what is and isn't possible it has stalled.
I'm not looking for a complex system just yet, I am more than aware of learning to walk before I run as I have only been learning php a few months.
So I would be more than happy with a simple system, for example, offspring having 50% chance of inheriting one of the parents phenotype etc.
So my question is does anyone have any experience of this type of script? Would I be right in thinking php and GD library or ImageMagick would be a good place to start? Please forgive my lack of knowledge :oops:
Any advice, thoughts, knowledge etc would be greatly appreciated.
I just need a shove in the right direction and I will do the rest.
Thank you.
Don't play games with a girl that can play them better...
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Question on breeding script

Post by hallsofvallhalla »

well you can get very complicated or very simple on this.

A simple way is just having check for every stat. Lets say you have a horse and a donkey mate.
Horse (dad)
strength = 10
speed = 20
size = large

Donkey(mom)
strength = 20
speed = 8
size = medium

psuedo code

Code: Select all

$strengthroll = rand(0,100)
if($strengthroll > 49)
{
$offspringstrength = $dadstrength / 5;////which will equal 2
$offspringstrength =(int)$offspringstrength;
}
else
{
$offspringstrength = $momstrength / 5; ////which will equal 4
$offspringstrength =(int)$offspringstrength;
}
$speedroll = rand(0,100)
if($speedroll > 49)
{
$offspringspeed = $dadspeed / 5;////which will equal 4
$offspringspeed =(int)$offspringspeed;
}
else
{
$offspringspeed = $momspeed / 5; ////which will equal 2
$offspringspeed =(int)$offspringspeed;
}
and so on

then you could implement breeding facilities, like a level 1 facility is crappy and a level 5 is great

Code: Select all

$strengthmod = $offspringstrength * ($facilitylevel /100);
$offspringstrength = $offspringstrength + $strengthmod;
there is just so many ways to do it.
User avatar
Xen
Posts: 36
Joined: Fri Apr 02, 2010 11:41 am

Re: Question on breeding script

Post by Xen »

Ah I see, thanks very much Halls.
I can imagine there are are a 1001 ways to do it. I can see I am a little way off trying to code this for myself, but I guess it will give me time to put alot of thought into what I would like it to be.
Would you recommend storing the images in a folder and pulling them via image path in mysql or using an image library for this kind of thing?
I ask this because the creatures (or Equids as they are called) have sets of armour players can buy, which of course will need to be displayed on the Equid once it is equipped/bought. Once I know what direction I should be going in I can put in the effort to learn it.
Thanks very much for your time.
Don't play games with a girl that can play them better...
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Question on breeding script

Post by Jackolantern »

Definitely many ways. Considering that you mention GD and ImageMagick, if you want to actually make generated images of them, that would get difficult in both coding and in art asset management. Imagemagick is a bit more powerful, but I have also heard it has some slower functions as well that GD cuts out. You would likely want to really think about how much the pet images would add to the game compared to how much work would be required. If the majority of your game is text-based like most other PBBGs, then having the pets be primarily text-based would likely be no problem, either. It would also allow you to devote more time to creating more pet types.

As far as the actual coding, there are many ways to do it, just like most coding problems. If you watch all of the videos in the series, you should have all of the logic and techniques you need to create a text-based pet system. Just create a newPet table with all of the possible stats you may need in it. Then write your game logic that fills rows in the table as needed with new pets. Likely give it a primary key, and then use connect it with your 'players' table to show who owns the pets. Anything beyond that would be implementation-specific depending on your game logic and design. Good luck with it :)

EDIT: If your pet are going to wear armor, that would end up being quite demanding on the art side if the pets come in different shapes. If they are all the same shape, then you could likely have one-piece-fits-all for the armor, but if not, it would either be a art nightmare to create every piece of every armor to fit every pet, or a coding nightmare to try to dynamically manipulate the armor to fit the pets and would be a very advanced ImageMagick project.
The indelible lord of tl;dr
User avatar
Xen
Posts: 36
Joined: Fri Apr 02, 2010 11:41 am

Re: Question on breeding script

Post by Xen »

Thanks for the advice. Very informative and has given me some food for thought. I am more than half way through the videos and it is beginning to sink in.
Jackolantern wrote: EDIT: If your pet are going to wear armor, that would end up being quite demanding on the art side if the pets come in different shapes. If they are all the same shape, then you could likely have one-piece-fits-all for the armor, but if not, it would either be a art nightmare to create every piece of every armor to fit every pet, or a coding nightmare to try to dynamically manipulate the armor to fit the pets and would be a very advanced ImageMagick project.
.

I presently have 25 Equids, which are all different breeds and hence, shapes >.< However, I have fitted the armour to each breed by just rotating it slightly. But I can see how that would be a coding nightmare.
I have seen it done in Flash, where each animal has it's own accessories that seem to fit them precisely. I am getting on well with Flash so maybe that is an option? Of course, I would then need to learn how to use Flash with php. Fun, fun!
Thanks for the info.
Don't play games with a girl that can play them better...
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Question on breeding script

Post by Jackolantern »

Flash really doesn't mesh very well with PHP (or anything besides Action Script, really), so that would likely be quite complex. Also, I don't think Flash would really give you an edge in the armor to pet situation because it would be very complex scripting to dynamically fit the armor pieces to the pets while avoiding distortions. The developers of the game you are referring to likely just made a single piece for each pet.

Honestly, for 25 or so pets, that would not be too bad to just make one for each. I was thinking 50 or so, and if each had 4 stages of growth, that would be 200 different versions of each single piece of armor. However, if there is only one stage for each pet, then that would just be 25 alternates for each one. I guess if you are aiming for a couple hundred pieces of armor then it would be worth it to look into dynamically altering the armor pieces at runtime, but you may need to get help from an Actionscript veteran :)
The indelible lord of tl;dr
User avatar
Xen
Posts: 36
Joined: Fri Apr 02, 2010 11:41 am

Re: Question on breeding script

Post by Xen »

Yes I am starting small. :D The Equids only have one stage and although there are only 25 breeds, there's lots of colours of each and only 18 sets of armour. 90% of them are finished and fitted so it's just a case of finding the best way to code/display them. Maybe I will go lurk on a Flash forum and see what a seasoned Flasher says. Will let you know if I find out!
Thanks for the advice and tips, much appreciated.
Don't play games with a girl that can play them better...
User avatar
Torniquet
Posts: 869
Joined: Sun Aug 02, 2009 6:18 am

Re: Question on breeding script

Post by Torniquet »

i would go with absolute positioned divs to display the armour.

although its probably not the best way to go about it, it saves fighting with flash to do it....

give each equipment a designated layer to sit on.... the images will just stack ontop of themselves.

eg..

creature layer 0
body armour layer 1
weapon layer 2

etc.....
New Site Coming Soon! Stay tuned :D
User avatar
Xen
Posts: 36
Joined: Fri Apr 02, 2010 11:41 am

Re: Question on breeding script

Post by Xen »

Cool, ok I will give that a go first as I'm much more familiar with div's and such.
I get on great with Flash to a certain point.....then I start hurling obscenities at it and we have a major lover's tiff!
Thanks for the advice. :)
Don't play games with a girl that can play them better...
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Question on breeding script

Post by Jackolantern »

Or, since you have relatively few armor and pet combinations, you could just create a flattened image for each pet with each piece of armor. Then you give them each specific names, following along a code guide that corresponds to each pet and armor piece. You could use the master pet ID (only one ID for each type of pet) from your database combined with an ID for each piece of armor (one ID for each type of armor, not one per fitting). That way, you could reference a specific pet image by combining the two numbers in the image name:

Code: Select all

// get pet info from MySQL into $petinfo variable

$petID = $petInfo[id];
$armorID = $petInfo[currentArmor];

//insert correct pet image
echo "<img src=\"../images/$petID $armorID.png\" />";
In the above code, say the player is currently using a pet with an ID of 4 and armor with an ID of 11. You would need to have a PNG file with the name: "4 11.png" (no double quotes, of course).

This way you don't have to worry about the browser window resizing problems of absolutely positioned elements, the tangle of code likely required to execute it, or old browser and mobile device inconsistencies of AP elements. However, the downside of using this method would be that it may not be as expandable as the system could be. If you did later decide to add growth stages, or expand the game to include many more pieces of armor, the workload would grow exponentially to create all of the images (although this would have little impact on the website performance since you aren't using spaghetti "if/else" statements to choose the correct image).

It may also have a tiny impact on player's loading times if they change between pets fairly often in your game, since you may get the advantage of a bit of browser-side caching if they keep seeing the same elements used in different ways. With this method, each different use of the same object (a piece of armor or a pet) would be a different image, thus, it would need to be downloaded and displayed again. However, if players typically stay with the same pet and/or armor for longer periods of time, caching would likely provide little benefit over this method.
The indelible lord of tl;dr
Post Reply

Return to “Advanced Help and Support”