diff --git a/core/src/de/samdev/colorrunner/game/renderer/CRAssets.java b/core/src/de/samdev/colorrunner/game/renderer/CRAssets.java index e5d4882..ace2103 100644 --- a/core/src/de/samdev/colorrunner/game/renderer/CRAssets.java +++ b/core/src/de/samdev/colorrunner/game/renderer/CRAssets.java @@ -6,6 +6,8 @@ import com.badlogic.gdx.graphics.Pixmap.Format; import com.badlogic.gdx.graphics.Texture; public class CRAssets { + public static Texture TEX_BLANK; + public static Texture TEX_PLAYER_UP; public static Texture TEX_PLAYER_RIGHT; public static Texture TEX_PLAYER_LEFT; @@ -20,6 +22,13 @@ public class CRAssets { public static Texture TEX_COLORWHEEL; static { + { + Pixmap pixmap = new Pixmap(32, 32, Format.RGBA8888); + pixmap.setColor(1, 1, 1, 1); + pixmap.fill(); + TEX_BLANK = new Texture(pixmap); + } + { Pixmap pixmap = new Pixmap(32, 32, Format.RGBA8888); pixmap.setColor(1, 0, 0, 1); diff --git a/core/src/de/samdev/colorrunner/screens/menu/BaseMenu.java b/core/src/de/samdev/colorrunner/screens/menu/BaseMenu.java index 3707b60..1e5163d 100644 --- a/core/src/de/samdev/colorrunner/screens/menu/BaseMenu.java +++ b/core/src/de/samdev/colorrunner/screens/menu/BaseMenu.java @@ -5,31 +5,29 @@ import com.badlogic.gdx.Screen; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import java.util.ArrayList; import java.util.List; +import de.samdev.colorrunner.CRGame; + public abstract class BaseMenu implements Screen { - private final int VIEWPORT_WIDTH = 100; - private final int VIEWPORT_HEIGHT = 100; + private final int VIRTUAL_VIEWPORT_WIDTH = 1024; + private final int VIRTUAL_VIEWPORT_HEIGHT = 640; private List elements = new ArrayList(); private OrthographicCamera cam; private SpriteBatch sbatch = new SpriteBatch(); + private ShapeRenderer linebatch = new ShapeRenderer(); public BaseMenu() { super(); cam = new OrthographicCamera(); - cam.position.x += VIEWPORT_WIDTH/2; - cam.position.y += VIEWPORT_HEIGHT/2; - cam.viewportWidth += VIEWPORT_WIDTH; - cam.viewportHeight += VIEWPORT_HEIGHT; - cam.update(); - - sbatch.setProjectionMatrix(cam.combined); + updateCam(); init(); } @@ -53,21 +51,71 @@ public abstract class BaseMenu implements Screen { e.update(delta); } - // ####### RENDER ######### + // ####### DEBUG RENDER ######### - Gdx.gl.glClearColor(0.22f, 0.22f, 0.22f, 1f); + Gdx.gl.glClearColor(1, 0, 1, 1f); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + if (CRGame.DEBUG) { + + linebatch.begin(ShapeRenderer.ShapeType.Line); + linebatch.setColor(0, 0, 1, 1); + + linebatch.rect(0, 0, VIRTUAL_VIEWPORT_WIDTH, VIRTUAL_VIEWPORT_HEIGHT); + + linebatch.end(); + + } + + // ####### REAL RENDER ######### + sbatch.begin(); for (BaseMenuElement e : elements) { e.render(sbatch); } sbatch.end(); + + + } + + private void updateCam() { + + float deviceW = Gdx.graphics.getWidth(); + float deviceH = Gdx.graphics.getHeight(); + + float real_ratio = deviceW / deviceH; + float virt_ratio = VIRTUAL_VIEWPORT_WIDTH * 1f / VIRTUAL_VIEWPORT_HEIGHT; + + if (real_ratio > virt_ratio) { + + // fix to height + + cam.viewportHeight = VIRTUAL_VIEWPORT_HEIGHT; + cam.viewportWidth = real_ratio * VIRTUAL_VIEWPORT_HEIGHT; + + } else { + + // fix to width + + cam.viewportHeight = VIRTUAL_VIEWPORT_WIDTH / real_ratio; + cam.viewportWidth = VIRTUAL_VIEWPORT_WIDTH; + + } + + cam.position.x = VIRTUAL_VIEWPORT_WIDTH / 2f; + cam.position.y = VIRTUAL_VIEWPORT_HEIGHT / 2f; + + cam.update(); + + sbatch.setProjectionMatrix(cam.combined); + linebatch.setProjectionMatrix(cam.combined); } @Override public void resize(int width, int height) { - // NOP + + updateCam(); + } @Override diff --git a/core/src/de/samdev/colorrunner/screens/menu/impl/LevelSelectMenu.java b/core/src/de/samdev/colorrunner/screens/menu/impl/LevelSelectMenu.java index 38fc6a2..855e4c0 100644 --- a/core/src/de/samdev/colorrunner/screens/menu/impl/LevelSelectMenu.java +++ b/core/src/de/samdev/colorrunner/screens/menu/impl/LevelSelectMenu.java @@ -9,7 +9,14 @@ public class LevelSelectMenu extends BaseMenu { @Override protected void init() { - add(new CRMenuRectangle(1, 1, 30, 30, Color.RED)); + + for (int x = 0; x < 6; x++) { + for (int y = 0; y < 4; y++) { + add(new CRMenuRectangle(48 + (32+128)*x, 48 + (32+112)*y, 128, 128, Color.YELLOW)); + } + } + + } } diff --git a/core/src/de/samdev/colorrunner/screens/menu/impl/elements/CRMenuRectangle.java b/core/src/de/samdev/colorrunner/screens/menu/impl/elements/CRMenuRectangle.java index 2094e0f..3349018 100644 --- a/core/src/de/samdev/colorrunner/screens/menu/impl/elements/CRMenuRectangle.java +++ b/core/src/de/samdev/colorrunner/screens/menu/impl/elements/CRMenuRectangle.java @@ -21,13 +21,15 @@ public class CRMenuRectangle extends BaseMenuElement { @Override public void render(SpriteBatch batch) { - batch.draw(CRAssets.TEX_PLAYER_UP, Bounds.x, Bounds.y, Bounds.width, Bounds.height); + batch.setColor(Color); + batch.draw(CRAssets.TEX_BLANK, Bounds.x, Bounds.y, Bounds.width, Bounds.height); + batch.setColor(0); } @Override public void update(float delta) { - Gdx.app.log("crmenurect", "> " + delta); + //Gdx.app.log("crmenurect", "> " + delta); } }