summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2022-09-27 00:15:52 +0600
committerilotterytea <iltsu@alright.party>2022-09-27 00:15:52 +0600
commitc8c86db42e24915a8adc379b62fb129493c79ae0 (patch)
treebb8c09fc02e5d7a65b3522469741bfc7ef4c2da6 /core
parent35126f0c675f000fefeb10758cadf5d8a5af9c48 (diff)
make generation of new bg tiles as a function
Diffstat (limited to 'core')
-rw-r--r--core/src/com/ilotterytea/maxoning/screens/GameScreen.java49
-rw-r--r--core/src/com/ilotterytea/maxoning/screens/MenuScreen.java46
2 files changed, 43 insertions, 52 deletions
diff --git a/core/src/com/ilotterytea/maxoning/screens/GameScreen.java b/core/src/com/ilotterytea/maxoning/screens/GameScreen.java
index ad4a7e7..6ed9240 100644
--- a/core/src/com/ilotterytea/maxoning/screens/GameScreen.java
+++ b/core/src/com/ilotterytea/maxoning/screens/GameScreen.java
@@ -4,6 +4,7 @@ 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;
import com.badlogic.gdx.scenes.scene2d.Stage;
@@ -72,7 +73,8 @@ public class GameScreen implements Screen, InputProcessor {
}
// Make the background a little dimmed:
- blackBg = new Image(game.assetManager.get("sprites/black.png", Texture.class));
+ blackBg = new Image();
+ blackBg.setColor(0f, 0f, 0f, 1f);
blackBg.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
blackBg.addAction(Actions.parallel(Actions.alpha(0.25f)));
stage.addActor(blackBg);
@@ -205,30 +207,10 @@ public class GameScreen implements Screen, InputProcessor {
stage.addActor(pointsLabel);
- bgTile = game.assetManager.get("sprites/menu/tile_1.png", Texture.class);
- bgTileAlt = game.assetManager.get("sprites/menu/tile_2.png", Texture.class);
-
// Generate the background:
bgTiles = new ArrayList<>();
- for (int i = 0; i < Gdx.graphics.getHeight() / bgTile.getHeight() + 1; i++) {
- bgTiles.add(i, new ArrayList<Sprite>());
-
- for (int j = -1; j < Gdx.graphics.getWidth() / bgTile.getWidth(); j++) {
- Sprite spr = new Sprite();
-
- if ((j + i) % 2 == 0) {
- spr.setTexture(bgTile);
- } else {
- spr.setTexture(bgTileAlt);
- }
-
- spr.setSize(bgTile.getWidth(), bgTile.getHeight());
-
- spr.setPosition(bgTile.getWidth() * j, bgTile.getHeight() * i);
- bgTiles.get(i).add(spr);
- }
- }
+ genNewBgTiles((int) stage.getWidth(), (int) stage.getHeight());
// Table for Maxon cat:
mainTable = new Table();
@@ -359,26 +341,29 @@ public class GameScreen implements Screen, InputProcessor {
public void resize(int width, int height) {
bgTiles.clear();
- for (int i = 0; i < Gdx.graphics.getHeight() / bgTile.getHeight() + 1; i++) {
- bgTiles.add(i, new ArrayList<Sprite>());
+ genNewBgTiles(width, height);
- for (int j = -1; j < Gdx.graphics.getWidth() / bgTile.getWidth(); j++) {
- Sprite spr = new Sprite();
+ stage.getViewport().update(width, height, true);
+ }
+
+ private void genNewBgTiles(int width, int height) {
+ for (int i = 0; i < height / environmentAtlas.findRegion("tile").getRegionHeight() + 1; i++) {
+ bgTiles.add(i, new ArrayList<Sprite>());
+ for (int j = -1; j < width / environmentAtlas.findRegion("tile").getRegionWidth(); j++) {
+ Sprite spr = new Sprite(environmentAtlas.findRegion("tile"));
if ((j + i) % 2 == 0) {
- spr.setTexture(bgTile);
+ spr.setColor(0.98f, 0.71f, 0.22f, 1f);
} else {
- spr.setTexture(bgTileAlt);
+ spr.setColor(0.84f, 0.61f, 0.20f, 1f);
}
- spr.setSize(bgTile.getWidth(), bgTile.getHeight());
+ spr.setSize(64, 64);
- spr.setPosition(bgTile.getWidth() * j, bgTile.getHeight() * i);
+ spr.setPosition(spr.getWidth() * j, spr.getHeight() * i);
bgTiles.get(i).add(spr);
}
}
-
- stage.getViewport().update(width, height, true);
}
@Override public void pause() {}
diff --git a/core/src/com/ilotterytea/maxoning/screens/MenuScreen.java b/core/src/com/ilotterytea/maxoning/screens/MenuScreen.java
index f1d63df..0b3888d 100644
--- a/core/src/com/ilotterytea/maxoning/screens/MenuScreen.java
+++ b/core/src/com/ilotterytea/maxoning/screens/MenuScreen.java
@@ -3,8 +3,8 @@ package com.ilotterytea.maxoning.screens;
import com.badlogic.gdx.*;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.*;
-import com.badlogic.gdx.graphics.g2d.NinePatch;
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;
import com.badlogic.gdx.scenes.scene2d.Stage;
@@ -36,9 +36,8 @@ public class MenuScreen implements Screen, InputProcessor {
Table menuTable, optionsTable;
- final Texture bgTile1, bgTile2;
-
- NinePatch buttonUp, buttonDown, buttonOver, buttonDisabled;
+ // Atlases:
+ TextureAtlas environmentAtlas, brandAtlas;
private ArrayList<ArrayList<Sprite>> bgMenuTiles;
@@ -47,13 +46,8 @@ public class MenuScreen implements Screen, InputProcessor {
public MenuScreen(final MaxonGame game) {
this.game = game;
- buttonUp = new NinePatch(game.assetManager.get("sprites/ui/sqrbutton.png", Texture.class), 8, 8, 8, 8);
- buttonDown = new NinePatch(game.assetManager.get("sprites/ui/sqrbutton_down.png", Texture.class), 8, 8, 8, 8);
- buttonOver = new NinePatch(game.assetManager.get("sprites/ui/sqrbutton_over.png", Texture.class), 8, 8, 8, 8);
- buttonDisabled = new NinePatch(game.assetManager.get("sprites/ui/sqrbutton_disabled.png", Texture.class), 8, 8, 8, 8);
-
- bgTile1 = game.assetManager.get("sprites/menu/tile_1.png", Texture.class);
- bgTile2 = game.assetManager.get("sprites/menu/tile_2.png", Texture.class);
+ // Environment atlas for leafs, snowflakes and background tiles:
+ environmentAtlas = game.assetManager.get("sprites/env/environment.atlas", TextureAtlas.class);
bgMenuTiles = new ArrayList<>();
@@ -158,6 +152,11 @@ public class MenuScreen implements Screen, InputProcessor {
menuMusic.setVolume((game.prefs.getBoolean("music", true)) ? 1f : 0f);
menuMusic.play();
}
+
+ // Generate background tiles:
+ bgMenuTiles = new ArrayList<>();
+
+ genNewBgTiles((int) stage.getWidth(), (int) stage.getHeight());
}
@Override public void show() {
@@ -305,24 +304,31 @@ public class MenuScreen implements Screen, InputProcessor {
public void resize(int width, int height) {
bgMenuTiles.clear();
- for (int i = 0; i < height / bgTile1.getHeight() + 1; i++) {
+ genNewBgTiles(width, height);
+
+ stage.getViewport().update(width, height, true);
+ }
+
+ private void genNewBgTiles(int width, int height) {
+ bgMenuTiles.clear();
+
+ for (int i = 0; i < height / environmentAtlas.findRegion("tile").getRegionHeight() + 1; i++) {
bgMenuTiles.add(i, new ArrayList<Sprite>());
- for (int j = -1; j < width / bgTile1.getWidth(); j++) {
- Sprite spr = new Sprite();
+ for (int j = -1; j < width / environmentAtlas.findRegion("tile").getRegionWidth(); j++) {
+ Sprite spr = new Sprite(environmentAtlas.findRegion("tile"));
if ((j + i) % 2 == 0) {
- spr.setTexture(bgTile1);
+ spr.setColor(0.98f, 0.71f, 0.22f, 1f);
} else {
- spr.setTexture(bgTile2);
+ spr.setColor(0.84f, 0.61f, 0.20f, 1f);
}
- spr.setSize(bgTile1.getWidth(), bgTile1.getHeight());
- spr.setPosition(bgTile1.getWidth() * j, bgTile1.getHeight() * i);
+ spr.setSize(64, 64);
+
+ spr.setPosition(spr.getWidth() * j, spr.getHeight() * i);
bgMenuTiles.get(i).add(spr);
}
}
-
- stage.getViewport().update(width, height, true);
}
@Override public void pause() {}