package at.ggjg.evg.entities;

import at.ggjg.evg.State;
import at.ggjg.evg.gestures.Sequence;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.utils.Array;

import java.util.Random;

import at.ggjg.evg.helpers.Assets;
import at.ggjg.evg.helpers.Bounds;
import at.ggjg.evg.mechanic.World;

/**
 * Created by christophergalle on 30/01/16.
 */
public class Cornfield extends GameObject {
    private static final float SCALING_FACTOR = 1.2f;
    public TextureRegion tr;
    public TextureRegion bunniesmakingloooove;
    public Array<Bunny> bunnies = new Array<Bunny>();
    Random r = new Random();
    public float cooldown = 0;

    public Cornfield(Float posX, Float posY) {
        super(posX, posY);

    }

    @Override
    public void update(World world, float deltaTime) {
        stateTime+=deltaTime;
        cooldown-= deltaTime;
        if(bunnies.size>=2 && stateTime >= r.nextInt(10) + 5)
            {
                Bunny haeschjen = new Bunny(this.position.x, this.position.y);
                haeschjen.init(world);
                world.bunnies.add(haeschjen);
                world.entities.add(haeschjen);
                bunnies.add(haeschjen);
                for (Bunny bunny: bunnies) {
                    bunny.state = State.IDLE;
                    bunny.stateTime = 0;
                }
                cooldown = 25;
                bunnies.removeRange(0,bunnies.size-1);

            }
    }

    @Override
    public void init(World world) {
        tr = Assets.farm;
        bunniesmakingloooove = Assets.nastyBunnies;
        acceptedGesture = Sequence.SequenceName.SQUARE;
        origin.x = dimension.x / 2;
        origin.y = dimension.y / 2;
        scale.set(SCALING_FACTOR, SCALING_FACTOR);
        bounds = new Bounds(position.x, position.y, scale.x, scale.y);
    }

    @Override
    public void render(SpriteBatch batch) {
        batch.draw(tr, position.x, position.y, scale.x,scale.y);
        if(bunnies.size>=2)
            batch.draw(bunniesmakingloooove, position.x, position.y, scale.x,scale.y);
    }

    @Override
    public void onGestureAction() {

    }

    public void addBunny(Bunny bunny) {
        if(bunnies.size > 2 || cooldown>0){
            if(bunny.state != State.IDLE) {
                bunny.state = State.IDLE;
                bunny.stateTime = 0;
            }
        }
        else{
            bunnies.add(bunny);
            bunny.state = State.SCHNACKSELN;
            bunny.stateTime = 0;
            this.stateTime = 0;
        }
        }
}

@@ -2267,17 +2267,16 @@
 ldown%3E0)
-%7B
 %0A       
@@ -2284,156 +2284,19 @@
     
-if(bunny.state != State.IDLE) %7B%0A                bunny.state = State.IDLE;%0A                bunny.stateTime = 0;%0A            %7D%0A        %7D%0A        else%7B
+    return;
 %0A   
@@ -2394,32 +2394,32 @@
 .stateTime = 0;%0A
+
             this
@@ -2444,20 +2444,10 @@
       %7D%0A
-        %7D%0A
 %7D%0A

Fix Cornfield