User Tag List

Results 1 to 3 of 3

Thread: Sort of Array filling problem - need advice

  1. #1
    No Products Registered

    Join Date
    Sep 2006
    Location
    Germany
    Posts
    861
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sort of Array filling problem - need advice

    I would love to see some input and ideas on how to solve the following problem.

    Let's imagine we have a x16 y16 array, 256 "fields" in total.

    At the start of the application I randomise a few things.

    1. The player start position can be anywhere one the field.
    2. Each field has a chance to get an ID. 1-99 to be exact. And also a great chance to be just 0 (empty).

    After tweaking around a bit I get a nice filled array with around 100-200 "fields" that have an ID.

    Now I want to assign a "difficult level (1-20)" to all fields that have an ID. But the level of difficulty should raise on fields that are farther away from the player.

    Two solutions I came up so far would work:
    A. Each field around the player that is one field away raises it's difficulty by 1. So 3 x/y steps away = difficulty 3 and so on.

    B. I would also love to have it more random, so fields nearby can be more difficult why fields farther away could also be easier in difficulty.

    A solution to A. would be to make a loop and check for each field with an ID the distance to the player and adjust the difficulty value.

    For B I could just add a +random(2)-random(2) for example.

    Now on terms of MMF2 how would i do it the fastest way? Im 11 years out of school so a bit of math help would probably help (in case there is a easy mathematical solution) or maybe an extension that is capable of it? Also any other ideas on how to solve it?

    Thanks in advance!

  2. #2
    No Products Registered

    Join Date
    Sep 2006
    Location
    Germany
    Posts
    861
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Sort of Array filling problem - need advice

    In case anyone is looking for a similar solution im going to answer my own question just for completition

    Here is what I did:

    1. You need to define your player starting position and make sure the Array is 0-based and 3D (X16Y16Z16 will do). Write the player starting position to the Array. Use a Value that is not in your Random ID Range like 99 while your Random Range is 0-31 for example.

    Use Z=1 for IDs

    2. Run loops for X and Y axis, and fill the fields with random IDs, make sure you do not overwrite the player starting position (check if value in the array at current loopstep XY is not 99 [or whatever value you defined])

    3. Visuality is always good therefore an Active Object should do. Fill all 32 directions of the stopped animation with content.

    4. Add a new loop for X and Y to draw the actives and carry over the values from the array.

    5. Add a Always condition that the Active Objects look into the direction of the ID Value you stored into the Actives. Add a second one for the player start. [if ID = 99 then change animation whatever]

    6. Now you have a full array with random IDs and the unique start postion

    7. Now to drop off IDs you don't need just add a new event and if the active object is looking into various directions destroy the objects (tick and untick as many directions as you need until you find a suiting solution, make sure you run it a couple of times as the values are random!)

    8. For the Array cleanup you just loop through it again and set all those IDs to 0.

    9. The last part is the difficulty value based on distance. Use the Snippet Manager to get the distance formula between two points. Add this to the very first loop when you are writing the ID's. Just calculate the current XY based on the loopindexes to the player position XY. Use Z=2 in the Array for the difficult value.

    10. Almost done, now we want to have areas that are far away from the player position to be more difficult then the ones closer. Just add a new condition to the first loop call -> if distance between XY loopindex and XY player start is lower then 5 then alter the distance value by adding +random(3) for the final distance. You can make this progressive of course so first 5 difficult levels will be the actual distance to the player base, but after that for example 5-10 distance you could add a random(5) and after 10 distance a random(10).

    There is one thing you should not forget, the player position is random. If the position of the player base is at the edge of the array the maximum difficulty will be much higher then when the base is exactly in the middle. In math this means the following:

    1. lets assume your base is at X8Y8, and difficulty progresses (diff1-5=random(2);diff5-10=random(4);diff>10=random(8))
    Then the maximum difficulty a field can have based on distance is 7. Added a maximum of +7 by random means 14 in total.

    2. if your base is lets say at X1Y1 then the maximum difficulty based on distance is 15 and the maximum final difficulty base and +7 due to randomness is 22.

    Here is a picture of what it acutally looked like in Multimedia Fusion

    http://img3.abload.de/img/arrayodhq.png

    If you are asking yourself what the hell I do need this at all?

    Well I'm working on a strategy game right now, and I want to have a random Map generated each time the player starts a new game. All those IDs are actually resources like lumber, stone, herbs and so on. And the difficulty value represents the strenght of the army that is guarding those resources. My main goal was to have it random and progressive, which the above solution delivered.

    If you find anything that could speed up the process or make it easier and or faster, let me know

  3. #3
    Forum Moderator

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleXNA Export ModuleInstall Creator Pro
    nivram's Avatar
    Join Date
    Jul 2006
    Location
    Bandon, Oregon
    Posts
    6,773
    Mentioned
    12 Post(s)
    Tagged
    0 Thread(s)

    Re: Sort of Array filling problem - need advice

    Hi maVado. Lots of good info there. May I suggest you place this in the Articles section also, with hat you are trying to achieve, why and etc. In time it may be easier for people to find and read it. It won't take very long for this to be lost with hundreds of other topics.

    Marv
    ​458 TGF to CTF 2.5+ Examples and games
    http://www.castles-of-britain.com/mmf2examples.htm

Similar Threads

  1. Sort Objects problem
    By AftPeakTank in forum Multimedia Fusion 2 - Technical Support
    Replies: 13
    Last Post: 21st July 2013, 03:45 PM
  2. Dynamic Array - Sort 2 dimension array by Column 1
    By Ryan in forum Multimedia Fusion 2 - Technical Support
    Replies: 0
    Last Post: 16th December 2012, 04:54 AM
  3. List object sort problem
    By Sumo in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 4th December 2012, 05:01 PM
  4. Filling an array from a listbox
    By Farflame in forum Multimedia Fusion 2 - Technical Support
    Replies: 8
    Last Post: 19th June 2009, 03:26 PM
  5. Filling Enemy ID Gaps (FastLoop Problem)
    By BrandonC in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 21st September 2006, 01:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •