From e7d4ee914386c155ce34e56232edcd754d98810d Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sat, 10 Dec 2022 19:50:00 +0600 Subject: Use MovingChessBackground() instead of just generating them. --- .../ilotterytea/maxoning/screens/GameScreen.java | 62 +++------------------- 1 file changed, 8 insertions(+), 54 deletions(-) (limited to 'core/src') diff --git a/core/src/com/ilotterytea/maxoning/screens/GameScreen.java b/core/src/com/ilotterytea/maxoning/screens/GameScreen.java index b46f978..a767e88 100644 --- a/core/src/com/ilotterytea/maxoning/screens/GameScreen.java +++ b/core/src/com/ilotterytea/maxoning/screens/GameScreen.java @@ -3,7 +3,6 @@ package com.ilotterytea.maxoning.screens; import com.badlogic.gdx.*; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.Texture; -import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.math.Interpolation; import com.badlogic.gdx.scenes.scene2d.InputEvent; @@ -55,7 +54,7 @@ public class GameScreen implements Screen, InputProcessor { ArrayList items; Map invItems; - ArrayList> bgTiles; + MovingChessBackground bg; public GameScreen(MaxonGame game, MaxonSavegame sav, int slotId) throws IOException, ClassNotFoundException { this.game = game; @@ -154,9 +153,11 @@ public class GameScreen implements Screen, InputProcessor { stage.addActor(quickTable); // Generate the background: - bgTiles = new ArrayList<>(); - - genNewBgTiles((int) stage.getWidth(), (int) stage.getHeight()); + bg = new MovingChessBackground( + 1f, 0f, stage.getWidth(), stage.getHeight(), + skin.getDrawable("tile_01"), + skin.getDrawable("tile_02") + ); // Creating the Maxon cat: cat = new AnimatedImage( @@ -325,34 +326,10 @@ public class GameScreen implements Screen, InputProcessor { game.batch.begin(); - for (ArrayList array : bgTiles) { - for (Sprite spr : array) { - spr.setPosition(spr.getX() + 1, spr.getY()); - spr.draw(game.batch); - } - } + bg.draw(game.batch); game.batch.end(); - for (ArrayList array : bgTiles) { - for (int i = 0; i < array.size(); i++) { - Sprite spr = array.get(i); - Sprite f_spr = array.get(0); - - if (spr.getX() > Gdx.graphics.getWidth()) { - Sprite n_spr = spr; - n_spr.setPosition(f_spr.getX() - spr.getWidth(), f_spr.getY()); - - if (spr.getTexture() == f_spr.getTexture()) { - n_spr.setTexture(array.get(1).getTexture()); - } - - array.remove(spr); - array.add(0, n_spr); - } - } - } - // Update the points label: pointsLabel.setText(game.locale.FormattedText("game.points", MaxonConstants.DECIMAL_FORMAT.format(player.points) @@ -369,33 +346,10 @@ public class GameScreen implements Screen, InputProcessor { @Override public void resize(int width, int height) { - bgTiles.clear(); - - genNewBgTiles(width, height); - + bg.update(width, height); stage.getViewport().update(width, height, true); } - private void genNewBgTiles(int width, int height) { - for (int i = 0; i < height / mainAtlas.findRegion("tile").getRegionHeight() + 1; i++) { - bgTiles.add(i, new ArrayList()); - for (int j = -1; j < width / mainAtlas.findRegion("tile").getRegionWidth(); j++) { - Sprite spr = new Sprite(mainAtlas.findRegion("tile")); - - if ((j + i) % 2 == 0) { - spr.setColor(0.98f, 0.71f, 0.22f, 1f); - } else { - spr.setColor(0.84f, 0.61f, 0.20f, 1f); - } - - spr.setSize(64, 64); - - spr.setPosition(spr.getWidth() * j, spr.getHeight() * i); - bgTiles.get(i).add(spr); - } - } - } - private void showShop() { // - - - - - - S H O P T A B L E - - - - - - : final Table shopTable = new Table(skin); -- cgit v1.2.3