Home Game Development object array positioning-LibGdx – Game Development Stack Exchange

object array positioning-LibGdx – Game Development Stack Exchange

0
object array positioning-LibGdx – Game Development Stack Exchange

[ad_1]

In my sport,if I contact a specific object,coin objects will come out of them at random speeds and occupy random positions.

public void replace(delta){
if(isTouched()&& getY()<Constants.WORLD_HEIGHT/2){
         setY(getY()+(randomSpeed * delta));
         setX(getX()-(randomSpeed/4 * delta));
         }
  }

Now I wish to make this cash occupy positions in some patterns.Like if 3 cash come out,a triangle sample or if 4 cash, rectangular sample like that.

I attempted to make it work,however cash are popping out and moved,however overlapping one another.Not in a position to create any patterns.
patterns like:
enter image description hereenter image description here

This is what I attempted

int a = Math.abs(rndNo.subsequentInt() % 3)+1;//no of cash
        int no =0;

        float coinxPos = participant.getX()-coins[0].getWidth()/2;
        float coinyPos = participant.getY();
        int minCoinGap=20;
        swap (a) {
        case 1:
            for (int i = 0; i < cash.size; i++) {
                if (!cash[i].isCoinVisible() && no < a) {
                    cash[i].setCoinVisible(true);

                    coinxPos = coinxPos+rndNo.subsequentInt()%70;
                    coinyPos = coinyPos+rndNo.subsequentInt()%70;
                    cash[i].setPosition(coinxPos, coinyPos);
                    no++;
                }
            }
            break;
        case 2:
            for (int i = 0; i < cash.size; i++) {
                if (!cash[i].isCoinVisible() && no < a) {
                    cash[i].setCoinVisible(true);
                    coinxPos = coinxPos+minCoinGap+rndNo.subsequentInt()%70;
                    coinyPos = coinyPos+rndNo.subsequentInt()%150;
                    cash[i].setPosition(coinxPos, coinyPos);
                    no++;
                }
            }
           break:
          ......
          ......
          default:
            break;

could also be this can be a easy logic to implement,however I wasted loads of time on it and bought confused of make it work.
Any assist could be appreciated.

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here