A few fixes and finishing 7 year old features :D
This commit is contained in:
parent
4241327bbd
commit
a4dd209f84
@ -9,7 +9,7 @@ import com.badlogic.gdx.audio.Music;
|
||||
import de.samdev.colorrunner.screens.menu.impl.SplashScreen;
|
||||
|
||||
public class CRGame extends Game {
|
||||
public final static boolean DEBUG = true;
|
||||
public static boolean DEBUG = false;
|
||||
public static AssetManager manager;
|
||||
|
||||
|
||||
|
@ -3,11 +3,13 @@ package de.samdev.colorrunner.screens.menu;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.InputMultiplexer;
|
||||
import com.badlogic.gdx.Screen;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
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 com.badlogic.gdx.input.GestureDetector;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -42,6 +44,8 @@ public abstract class BaseMenu implements Screen {
|
||||
elements.add(e);
|
||||
}
|
||||
|
||||
protected abstract Color getClearColor();
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
Gdx.input.setInputProcessor(new InputMultiplexer(input, new GestureDetector(input)));
|
||||
@ -52,13 +56,15 @@ public abstract class BaseMenu implements Screen {
|
||||
|
||||
// ####### UPDATE #########
|
||||
|
||||
var cc = getClearColor();
|
||||
if (cc != null) Gdx.gl.glClearColor(cc.r, cc.g, cc.b, 1f);
|
||||
|
||||
for (BaseMenuElement e : elements) {
|
||||
e.update(delta);
|
||||
}
|
||||
|
||||
// ####### DEBUG RENDER #########
|
||||
|
||||
Gdx.gl.glClearColor(1, 0, 1, 1f);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
|
||||
if (CRGame.DEBUG) {
|
||||
@ -144,6 +150,16 @@ public abstract class BaseMenu implements Screen {
|
||||
}
|
||||
|
||||
public void touchDown(int screenX, int screenY) {
|
||||
//
|
||||
|
||||
var up = cam.unproject(new Vector3(screenX, screenY, 0));
|
||||
|
||||
var x = up.x;
|
||||
var y = up.y;
|
||||
|
||||
for (BaseMenuElement e: elements) {
|
||||
if (e.getBounds().contains(x, y)) {
|
||||
e.clickTest(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,13 @@
|
||||
package de.samdev.colorrunner.screens.menu;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
|
||||
public abstract class BaseMenuElement {
|
||||
|
||||
public abstract void render(SpriteBatch batch);
|
||||
public abstract void update(float delta);
|
||||
public abstract Rectangle getBounds();
|
||||
public abstract boolean clickTest(float x, float y);
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,14 @@
|
||||
package de.samdev.colorrunner.screens.menu.impl;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
|
||||
import de.samdev.colorrunner.CRGame;
|
||||
import de.samdev.colorrunner.game.world.map.CRMapStorage;
|
||||
import de.samdev.colorrunner.game.world.map.CRTiledMap;
|
||||
import de.samdev.colorrunner.game.world.map.provider.EndlessMapProvider;
|
||||
import de.samdev.colorrunner.game.world.map.provider.MapProvider;
|
||||
import de.samdev.colorrunner.game.world.map.provider.StaticMapProvider;
|
||||
import de.samdev.colorrunner.screens.gameScreen.GameScreen;
|
||||
import de.samdev.colorrunner.screens.menu.BaseMenu;
|
||||
import de.samdev.colorrunner.screens.menu.impl.elements.CRMenuRectangle;
|
||||
@ -13,19 +17,46 @@ public class LevelSelectMenu extends BaseMenu {
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
var dbg0 = new Texture("dbg_off.png");
|
||||
var dbg1 = new Texture("dbg_on.png");
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
var c = new Color(0.25f, 0.25f, 0.25f, 1f);
|
||||
|
||||
add(new CRMenuRectangle(48, 480, 128, 128, c, new Texture("lvl_01.png"), (cx, cy, r) -> CRGame.Inst().setScreen(new GameScreen(new StaticMapProvider(CRMapStorage.lvl_01)))));
|
||||
add(new CRMenuRectangle(208, 480, 128, 128, c, new Texture("lvl_02.png"), (cx, cy, r) -> CRGame.Inst().setScreen(new GameScreen(new StaticMapProvider(CRMapStorage.lvl_02)))));
|
||||
add(new CRMenuRectangle(368, 480, 128, 128, c, new Texture("lvl_03.png"), (cx, cy, r) -> CRGame.Inst().setScreen(new GameScreen(new StaticMapProvider(CRMapStorage.lvl_03)))));
|
||||
add(new CRMenuRectangle(528, 480, 128, 128, c, new Texture("lvl_04.png"), (cx, cy, r) -> CRGame.Inst().setScreen(new GameScreen(new StaticMapProvider(CRMapStorage.lvl_04)))));
|
||||
add(new CRMenuRectangle(688, 480, 128, 128, c, new Texture("lvl_05.png"), (cx, cy, r) -> { }));
|
||||
add(new CRMenuRectangle(848, 480, 128, 128, c, new Texture("lvl_06.png"), (cx, cy, r) -> { }));
|
||||
add(new CRMenuRectangle(48, 336, 128, 128, c, new Texture("lvl_07.png"), (cx, cy, r) -> { }));
|
||||
add(new CRMenuRectangle(208, 336, 128, 128, c, null, (cx, cy, r) -> { }));
|
||||
add(new CRMenuRectangle(368, 336, 128, 128, c, null, (cx, cy, r) -> { }));
|
||||
add(new CRMenuRectangle(528, 336, 128, 128, c, null, (cx, cy, r) -> { }));
|
||||
add(new CRMenuRectangle(688, 336, 128, 128, c, null, (cx, cy, r) -> { }));
|
||||
add(new CRMenuRectangle(848, 336, 128, 128, c, null, (cx, cy, r) -> { }));
|
||||
add(new CRMenuRectangle(48, 192, 128, 128, c, null, (cx, cy, r) -> { }));
|
||||
add(new CRMenuRectangle(208, 192, 128, 128, c, null, (cx, cy, r) -> { }));
|
||||
add(new CRMenuRectangle(368, 192, 128, 128, c, null, (cx, cy, r) -> { }));
|
||||
add(new CRMenuRectangle(528, 192, 128, 128, c, null, (cx, cy, r) -> { }));
|
||||
add(new CRMenuRectangle(688, 192, 128, 128, c, null, (cx, cy, r) -> { }));
|
||||
add(new CRMenuRectangle(848, 192, 128, 128, c, null, (cx, cy, r) -> { }));
|
||||
add(new CRMenuRectangle(48, 48, 128, 128, c, CRGame.DEBUG ? dbg1 : dbg0, (cx, cy, r) -> { CRGame.DEBUG = !CRGame.DEBUG; r.Tex = CRGame.DEBUG ? dbg1 : dbg0; }));
|
||||
add(new CRMenuRectangle(208, 48, 128, 128, c, null, (cx, cy, r) -> { }));
|
||||
add(new CRMenuRectangle(368, 48, 128, 128, c, null, (cx, cy, r) -> { }));
|
||||
add(new CRMenuRectangle(528, 48, 128, 128, c, null, (cx, cy, r) -> { }));
|
||||
add(new CRMenuRectangle(688, 48, 128, 128, c, null, (cx, cy, r) -> { }));
|
||||
add(new CRMenuRectangle(848, 48, 128, 128, c, new Texture("lvl_x1.png"), (cx, cy, r) -> CRGame.Inst().setScreen(new GameScreen(new EndlessMapProvider(System.currentTimeMillis())))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Color getClearColor() {
|
||||
return new Color(0, 0, 0, 1f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void touchDown(int screenX, int screenY) {
|
||||
CRGame.Inst().setScreen(new GameScreen(new EndlessMapProvider(System.currentTimeMillis())));
|
||||
super.touchDown(screenX, screenY);
|
||||
//CRGame.Inst().setScreen(new GameScreen(new EndlessMapProvider(System.currentTimeMillis())));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package de.samdev.colorrunner.screens.menu.impl.elements;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
|
||||
@ -10,19 +10,35 @@ import de.samdev.colorrunner.screens.menu.BaseMenuElement;
|
||||
|
||||
public class CRMenuRectangle extends BaseMenuElement {
|
||||
|
||||
public interface ClickHandler {
|
||||
void onClick(float screenX, float screenY, CRMenuRectangle rect);
|
||||
}
|
||||
|
||||
public final Rectangle Bounds;
|
||||
public final Color Color;
|
||||
public final ClickHandler Handler;
|
||||
public Texture Tex;
|
||||
|
||||
public CRMenuRectangle(float x, float y, float w, float h, Color c) {
|
||||
public CRMenuRectangle(float x, float y, float w, float h, Color c, Texture tx, ClickHandler clickHandler) {
|
||||
Bounds = new Rectangle(x, y, w, h);
|
||||
Color = c;
|
||||
Handler = clickHandler;
|
||||
Tex = tx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(SpriteBatch batch) {
|
||||
|
||||
batch.setColor(Color);
|
||||
batch.draw(CRAssets.TEX_BLANK, Bounds.x, Bounds.y, Bounds.width, Bounds.height);
|
||||
|
||||
if (Tex != null) {
|
||||
batch.setColor(com.badlogic.gdx.graphics.Color.WHITE);
|
||||
batch.draw(Tex, Bounds.x, Bounds.y, Bounds.width, Bounds.height);
|
||||
}
|
||||
else {
|
||||
batch.setColor(Color);
|
||||
batch.draw(CRAssets.TEX_BLANK, Bounds.x, Bounds.y, Bounds.width, Bounds.height);
|
||||
}
|
||||
|
||||
batch.setColor(com.badlogic.gdx.graphics.Color.BLACK);
|
||||
|
||||
}
|
||||
@ -32,4 +48,17 @@ public class CRMenuRectangle extends BaseMenuElement {
|
||||
//Gdx.app.log("crmenurect", "> " + delta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rectangle getBounds() {
|
||||
return Bounds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clickTest(float x, float y) {
|
||||
if (this.Bounds.contains(x, y)) {
|
||||
this.Handler.onClick(x, y, this);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
BIN
data/Debug.xcf
Normal file
BIN
data/Debug.xcf
Normal file
Binary file not shown.
BIN
data/Levels.xcf
Normal file
BIN
data/Levels.xcf
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user