package com.naughtyzombie.demo.game;

import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.MathUtils;

/**
 * Created by pram on 17/05/2015.
 */
public class WorldController {
    private static final String TAG = WorldController.class.getName();

    public Sprite[] testSprites;
    public int selectedSprite;

    public WorldController() {
        init();
    }

    private void init() {
        initTestObjects();
    }

    private void initTestObjects() {
        testSprites = new Sprite[5];
        int width = 32;
        int height = 32;

        Pixmap pixmap = createProceduralPixmap(width, height);

        Texture texture = new Texture(pixmap);

        for (int i = 0; i < testSprites.length; i++) {
            Sprite spr = new Sprite(texture);
            spr.setSize(1, 1);

            spr.setOrigin(spr.getWidth() / 2.0f, spr.getHeight() / 2.0f);

            float randomX = MathUtils.random(-2.0f, 2.0f);
            float randomY = MathUtils.random(-2.0f, 2.0f);

            spr.setPosition(randomX, randomY);

            testSprites[i] = spr;
        }

        selectedSprite = 0;
    }

    private Pixmap createProceduralPixmap(int width, int height) {
        Pixmap pixmap = new Pixmap(width,height, Pixmap.Format.RGBA8888);
        pixmap.setColor(1,0,0,0.5f);
        pixmap.fill();

        pixmap.setColor(1,1,0,1);
        pixmap.drawLine(0,0,width,height);
        pixmap.drawLine(width,0,0,height);

        pixmap.setColor(0,1,1,1);

        pixmap.drawRectangle(0,0,width,height);

        return pixmap;
    }

    public void update(float deltaTime) {
        updateTestObjects(deltaTime);
    }

    private void updateTestObjects(float deltaTime) {
        float rotation = testSprites[selectedSprite].getRotation();
        rotation += 90 * deltaTime;
        rotation %= 360;
        testSprites[selectedSprite].setRotation(rotation);
    }
}

@@ -31,16 +31,82 @@
 .game;%0A%0A
+import com.badlogic.gdx.Application;%0Aimport com.badlogic.gdx.Gdx;%0A
 import c
@@ -266,16 +266,53 @@
 Utils;%0A%0A
+import com.badlogic.gdx.Input.Keys;%0A%0A
 /**%0A * C
@@ -1809,35 +1809,699 @@
     
-updateTestObjects(deltaTime
+handleDebugInput(deltaTime);%0A        updateTestObjects(deltaTime);%0A    %7D%0A%0A    private void handleDebugInput(float deltaTime) %7B%0A        if (Gdx.app.getType() != Application.ApplicationType.Desktop) return;%0A%0A        float sprMoveSpeed = 5 * deltaTime;%0A%0A        if (Gdx.input.isKeyPressed(Keys.A)) moveSelectedSprite(-sprMoveSpeed, 0);%0A        if (Gdx.input.isKeyPressed(Keys.D)) moveSelectedSprite(sprMoveSpeed, 0);%0A        if (Gdx.input.isKeyPressed(Keys.W)) moveSelectedSprite(0, sprMoveSpeed);%0A        if (Gdx.input.isKeyPressed(Keys.S)) moveSelectedSprite(0, -sprMoveSpeed);%0A%0A    %7D%0A%0A    private void moveSelectedSprite(float x, float y) %7B%0A        testSprites%5BselectedSprite%5D.translate(x, y
 );%0A 

debug movement keypresses