fixed memory leak, diff types of enemies, factory
@@ -1,5 +1,5 @@
|
||||
info face="EA Sports Covers SC" size=32 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=1 aa=1 padding=0,0,0,0 spacing=1,1 outline=0
|
||||
common lineHeight=32 base=26 scaleW=256 scaleH=256 pages=1 packed=0 alphaChnl=1 redChnl=0 greenChnl=0 blueChnl=0
|
||||
common lineHeight=32 base=26 scaleW=256 scaleH=256 pages=1 packed=0 alphaChnl=0 redChnl=4 greenChnl=4 blueChnl=4
|
||||
page id=0 file="EA_0.png"
|
||||
chars count=95
|
||||
char id=32 x=22 y=25 width=3 height=1 xoffset=-1 yoffset=31 xadvance=7 page=0 chnl=15
|
||||
|
||||
BIN
assets/EA.png
|
Before Width: | Height: | Size: 7.2 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 116 KiB After Width: | Height: | Size: 116 KiB |
BIN
assets/images/golem.png
Normal file
|
After Width: | Height: | Size: 139 KiB |
BIN
assets/images/stellar.png
Normal file
|
After Width: | Height: | Size: 288 KiB |
BIN
assets/images/ultron.png
Normal file
|
After Width: | Height: | Size: 103 KiB |
@@ -7,17 +7,15 @@ import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
|
||||
import com.badlogic.gdx.physics.box2d.World;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import org.lumijiez.bugger.entities.Entity;
|
||||
import org.lumijiez.bugger.entities.Player;
|
||||
import org.lumijiez.bugger.entities.enemies.EnemyEntity;
|
||||
import org.lumijiez.bugger.entities.enemies.Stalker;
|
||||
import org.lumijiez.bugger.entities.enemies.Wasp;
|
||||
import org.lumijiez.bugger.entities.weapons.Arrow;
|
||||
import org.lumijiez.bugger.entities.enemies.*;
|
||||
import org.lumijiez.bugger.entities.weapons.Ray;
|
||||
import org.lumijiez.bugger.entities.weapons.Projectile;
|
||||
import org.lumijiez.bugger.factories.EnemyFactory;
|
||||
import org.lumijiez.bugger.handlers.GameContactListener;
|
||||
import org.lumijiez.bugger.vfx.ParticleManager;
|
||||
import org.lumijiez.bugger.vfx.SpaceBackground;
|
||||
@@ -40,6 +38,7 @@ public class Bugger {
|
||||
public static OrthographicCamera uiCam;
|
||||
public static SpriteBatch spriteBatch;
|
||||
public static SpriteBatch uiBatch;
|
||||
public static int kills = 0;
|
||||
private final BitmapFont bitmapFont;
|
||||
|
||||
private Bugger() {
|
||||
@@ -60,7 +59,7 @@ public class Bugger {
|
||||
cam.update();
|
||||
|
||||
uiCam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
uiCam.position.set(uiCam.viewportWidth / 2, uiCam.viewportHeight / 2, 0); // Center the camera
|
||||
uiCam.position.set(uiCam.viewportWidth / 2, uiCam.viewportHeight / 2, 0);
|
||||
uiCam.update();
|
||||
}
|
||||
|
||||
@@ -88,14 +87,34 @@ public class Bugger {
|
||||
|
||||
renderPlayer();
|
||||
renderEnemies(delta);
|
||||
renderDebug();
|
||||
// renderDebug();
|
||||
|
||||
spriteBatch.setProjectionMatrix(cam.combined);
|
||||
|
||||
uiBatch.begin();
|
||||
bitmapFont.draw(uiBatch, "Speed: " + Player.getInstance().getBody().getLinearVelocity().len(), 100, 150);
|
||||
|
||||
uiBatch.setColor(1, 1, 1, 1);
|
||||
bitmapFont.draw(uiBatch, String.format("Speed: %.2f", Player.getInstance().getBody().getLinearVelocity().len()),
|
||||
10, uiCam.viewportHeight - 10);
|
||||
bitmapFont.draw(uiBatch, "Kills: " + kills, 10, uiCam.viewportHeight - 40);
|
||||
|
||||
bitmapFont.setColor(0, 1, 0, 1);
|
||||
|
||||
|
||||
bitmapFont.draw(uiBatch, "Enemies: " + enemies.size(), 10, uiCam.viewportHeight - 70);
|
||||
bitmapFont.draw(uiBatch, "Projectiles: " + projectiles.size, 10, uiCam.viewportHeight - 100);
|
||||
bitmapFont.draw(uiBatch, "Entities to Destroy: " + entitiesToDestroy.size, 10, uiCam.viewportHeight - 130);
|
||||
bitmapFont.draw(uiBatch, String.format("Player Pos: (%.2f, %.2f)",
|
||||
Player.getInstance().getBody().getPosition().x,
|
||||
Player.getInstance().getBody().getPosition().y), 10, uiCam.viewportHeight - 160);
|
||||
bitmapFont.draw(uiBatch, "Bodies: " + world.getBodyCount(), 10, uiCam.viewportHeight - 190);
|
||||
bitmapFont.draw(uiBatch, "Proxies: " + world.getProxyCount(), 10, uiCam.viewportHeight - 220);
|
||||
|
||||
bitmapFont.setColor(1, 1, 1, 1);
|
||||
|
||||
uiBatch.end();
|
||||
|
||||
|
||||
uiBatch.setProjectionMatrix(uiCam.combined);
|
||||
uiCam.update();
|
||||
handleInput();
|
||||
@@ -106,10 +125,10 @@ public class Bugger {
|
||||
}
|
||||
|
||||
public void renderEnemies(float delta) {
|
||||
|
||||
enemySpawnTimer += delta;
|
||||
if (enemySpawnTimer >= ENEMY_SPAWN_INTERVAL) {
|
||||
enemies.add(new Stalker(world, Player.getInstance().getPosition()));
|
||||
enemies.add(new Wasp(world, Player.getInstance().getPosition()));
|
||||
enemies.add(EnemyFactory.createRandomEnemy(world, Player.getInstance().getPosition()));
|
||||
enemySpawnTimer = 0;
|
||||
}
|
||||
|
||||
@@ -159,17 +178,20 @@ public class Bugger {
|
||||
public void clearEntities() {
|
||||
for (Entity entity : entitiesToDestroy) {
|
||||
world.destroyBody(entity.getBody());
|
||||
if (entity instanceof Arrow) projectiles.removeValue((Arrow) entity, true);
|
||||
if (entity instanceof Projectile) {
|
||||
projectiles.removeValue((Projectile) entity, true);
|
||||
}
|
||||
if (entity instanceof EnemyEntity) {
|
||||
playParticle(entity.getBody().getPosition().x, entity.getBody().getPosition().y);
|
||||
enemies.remove(entity);
|
||||
}
|
||||
|
||||
}
|
||||
entitiesToDestroy.clear();
|
||||
}
|
||||
|
||||
public void step() {
|
||||
world.step(1 / 60f, 6, 2);
|
||||
world.step(1 / 30f, 6, 2);
|
||||
}
|
||||
|
||||
public void playParticle(float x, float y) {
|
||||
@@ -177,12 +199,12 @@ public class Bugger {
|
||||
}
|
||||
|
||||
public void shoot() {
|
||||
Arrow arrow = player.shootArrow();
|
||||
projectiles.add(arrow);
|
||||
Ray ray = player.shootArrow();
|
||||
projectiles.add(ray);
|
||||
}
|
||||
|
||||
public void handleInput() {
|
||||
if (Gdx.input.isButtonJustPressed(Input.Buttons.LEFT)) {
|
||||
if (Gdx.input.isButtonPressed(Input.Buttons.LEFT)) {
|
||||
shoot();
|
||||
}
|
||||
}
|
||||
@@ -193,9 +215,9 @@ public class Bugger {
|
||||
|
||||
public void dispose() {
|
||||
spriteBatch.dispose();
|
||||
uiBatch.dispose();
|
||||
world.dispose();
|
||||
spaceBackground.dispose();
|
||||
ParticleManager.getInstance().dispose();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package org.lumijiez.bugger;
|
||||
|
||||
import com.badlogic.gdx.Screen;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
|
||||
public class GameScreen implements Screen {
|
||||
public final Bugger bugger = Bugger.getInstance();
|
||||
@@ -20,13 +18,6 @@ public class GameScreen implements Screen {
|
||||
|
||||
@Override
|
||||
public void resize(int w, int h) {
|
||||
// float screenAR = w / (float) h;
|
||||
// Bugger.cam = new OrthographicCamera(20, 20 / screenAR);
|
||||
// Bugger.cam.position.set(Bugger.cam.viewportWidth / 2, Bugger.cam.viewportHeight / 2, 0);
|
||||
// Bugger.cam.update();
|
||||
//
|
||||
// Bugger.spriteBatch = new SpriteBatch();
|
||||
// Bugger.spriteBatch.setProjectionMatrix(Bugger.cam.combined);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -53,6 +53,7 @@ public abstract class Entity {
|
||||
|
||||
public void destroy() {
|
||||
if (!markedToDestroy) {
|
||||
this.sprite.getTexture().dispose();
|
||||
markedToDestroy = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,7 @@ import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.physics.box2d.*;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import org.lumijiez.bugger.Bugger;
|
||||
import org.lumijiez.bugger.entities.weapons.Arrow;
|
||||
import org.lumijiez.bugger.vfx.ParticleManager;
|
||||
import org.lumijiez.bugger.entities.weapons.Ray;
|
||||
|
||||
public class Player extends Entity {
|
||||
private static Player instance;
|
||||
@@ -88,7 +87,7 @@ public class Player extends Entity {
|
||||
sprite.setRotation(body.getAngle() * (180f / (float) Math.PI));
|
||||
}
|
||||
|
||||
public Arrow shootArrow() {
|
||||
public Ray shootArrow() {
|
||||
Vector2 direction = new Vector2();
|
||||
|
||||
float mouseX = Gdx.input.getX();
|
||||
@@ -98,9 +97,9 @@ public class Player extends Entity {
|
||||
|
||||
direction.set(mousePosition.x, mousePosition.y).sub(getPosition()).nor();
|
||||
|
||||
Arrow arrow = new Arrow(world, getPosition(), direction);
|
||||
arrow.body.setUserData(arrow);
|
||||
return arrow;
|
||||
Ray ray = new Ray(world, getPosition(), direction);
|
||||
ray.body.setUserData(ray);
|
||||
return ray;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.lumijiez.bugger.entities.enemies;
|
||||
|
||||
public enum Enemies {
|
||||
STALKER("Stalker"),
|
||||
WASP("Wasp"),
|
||||
ULTRON("Ultron"),
|
||||
GOLEM("Golem"),
|
||||
STELLAR("Stellar");
|
||||
|
||||
private final String className;
|
||||
|
||||
Enemies(String className) {
|
||||
this.className = className;
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return className;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ public class EnemyEntity extends Entity {
|
||||
|
||||
public void moveTowards(Vector2 target) {
|
||||
Vector2 direction = target.cpy().sub(body.getPosition()).nor();
|
||||
float speed = 50f;
|
||||
body.setLinearVelocity(direction.scl(speed / 100f));
|
||||
float speed = 10f;
|
||||
body.setLinearVelocity(direction.scl(speed));
|
||||
|
||||
float angle = direction.angleDeg() + 270f;
|
||||
body.setTransform(body.getPosition(), angle * (float) Math.PI / 180f);
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.lumijiez.bugger.entities.enemies;
|
||||
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.physics.box2d.World;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Golem extends EnemyEntity{
|
||||
private static final Random random = new Random();
|
||||
|
||||
public Golem(World world, Vector2 playerPosition) {
|
||||
super(world, "images/golem.png", 30f);
|
||||
float spawnRadius = 100;
|
||||
float angle = random.nextFloat() * 2 * (float) Math.PI;
|
||||
float spawnX = playerPosition.x + (float) Math.cos(angle) * (spawnRadius + size);
|
||||
float spawnY = playerPosition.y + (float) Math.sin(angle) * (spawnRadius + size);
|
||||
this.body = createBody(spawnX, spawnY);
|
||||
this.body.setUserData(this);
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ public class Stalker extends EnemyEntity {
|
||||
|
||||
public Stalker(World world, Vector2 playerPosition) {
|
||||
super(world, "images/stalker.png", 10f);
|
||||
float spawnRadius = 50;
|
||||
float spawnRadius = 100;
|
||||
float angle = random.nextFloat() * 2 * (float) Math.PI;
|
||||
float spawnX = playerPosition.x + (float) Math.cos(angle) * (spawnRadius + size);
|
||||
float spawnY = playerPosition.y + (float) Math.sin(angle) * (spawnRadius + size);
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.lumijiez.bugger.entities.enemies;
|
||||
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.physics.box2d.World;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Stellar extends EnemyEntity {
|
||||
private static final Random random = new Random();
|
||||
|
||||
public Stellar(World world, Vector2 playerPosition) {
|
||||
super(world, "images/stellar.png", 15f);
|
||||
float spawnRadius = 100;
|
||||
float angle = random.nextFloat() * 2 * (float) Math.PI;
|
||||
float spawnX = playerPosition.x + (float) Math.cos(angle) * (spawnRadius + size);
|
||||
float spawnY = playerPosition.y + (float) Math.sin(angle) * (spawnRadius + size);
|
||||
this.body = createBody(spawnX, spawnY);
|
||||
this.body.setUserData(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.lumijiez.bugger.entities.enemies;
|
||||
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.physics.box2d.World;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Ultron extends EnemyEntity {
|
||||
private static final Random random = new Random();
|
||||
|
||||
public Ultron(World world, Vector2 playerPosition) {
|
||||
super(world, "images/ultron.png", 10f);
|
||||
float spawnRadius = 100;
|
||||
float angle = random.nextFloat() * 2 * (float) Math.PI;
|
||||
float spawnX = playerPosition.x + (float) Math.cos(angle) * (spawnRadius + size);
|
||||
float spawnY = playerPosition.y + (float) Math.sin(angle) * (spawnRadius + size);
|
||||
this.body = createBody(spawnX, spawnY);
|
||||
this.body.setUserData(this);
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,10 @@ import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.physics.box2d.*;
|
||||
import org.lumijiez.bugger.Bugger;
|
||||
|
||||
public class Arrow extends Projectile {
|
||||
public class Ray extends Projectile {
|
||||
|
||||
public Arrow(World world, Vector2 position, Vector2 direction) {
|
||||
super(world, "images/arrow.png", 5f);
|
||||
public Ray(World world, Vector2 position, Vector2 direction) {
|
||||
super(world, "images/blaze.png", 5f);
|
||||
|
||||
Vector2 offsetPosition = position.cpy().add(direction.nor().scl(size + 1f));
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.lumijiez.bugger.factories;
|
||||
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.physics.box2d.World;
|
||||
import org.lumijiez.bugger.entities.enemies.*;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class EnemyFactory {
|
||||
private static final Random random = new Random();
|
||||
|
||||
public static EnemyEntity createRandomEnemy(World world, Vector2 position) {
|
||||
int enemyType = random.nextInt(Enemies.values().length);
|
||||
|
||||
return getEnemyEntity(Enemies.values()[enemyType], world, position);
|
||||
}
|
||||
|
||||
public static EnemyEntity createEnemy(Enemies enemyType, World world, Vector2 position) {
|
||||
return getEnemyEntity(enemyType, world, position);
|
||||
}
|
||||
|
||||
private static EnemyEntity getEnemyEntity(Enemies enemy, World world, Vector2 position) {
|
||||
return switch (enemy) {
|
||||
case STALKER -> new Stalker(world, position);
|
||||
case WASP -> new Wasp(world, position);
|
||||
case ULTRON -> new Ultron(world, position);
|
||||
case GOLEM -> new Golem(world, position);
|
||||
case STELLAR -> new Stellar(world, position);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package org.lumijiez.bugger.handlers;
|
||||
|
||||
public class EnemySpawner {
|
||||
private static enem
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package org.lumijiez.bugger.handlers;
|
||||
|
||||
public class FontRenderer {
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
package org.lumijiez.bugger.handlers;
|
||||
|
||||
import com.badlogic.gdx.physics.box2d.*;
|
||||
import org.lumijiez.bugger.Bugger;
|
||||
import org.lumijiez.bugger.entities.enemies.EnemyEntity;
|
||||
import org.lumijiez.bugger.entities.weapons.Arrow;
|
||||
import org.lumijiez.bugger.entities.weapons.Ray;
|
||||
|
||||
public class GameContactListener implements ContactListener {
|
||||
@Override
|
||||
@@ -15,19 +16,21 @@ public class GameContactListener implements ContactListener {
|
||||
}
|
||||
|
||||
if (isArrow(fixtureA) && isEntity(fixtureB)) {
|
||||
Arrow arrow = (Arrow) fixtureA.getBody().getUserData();
|
||||
Ray ray = (Ray) fixtureA.getBody().getUserData();
|
||||
EnemyEntity enemy = (EnemyEntity) fixtureB.getBody().getUserData();
|
||||
if (arrow != null) {
|
||||
arrow.destroy();
|
||||
if (ray != null) {
|
||||
Bugger.kills++;
|
||||
ray.destroy();
|
||||
enemy.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
if (isArrow(fixtureB) && isEntity(fixtureA)) {
|
||||
Arrow arrow = (Arrow) fixtureB.getBody().getUserData();
|
||||
Ray ray = (Ray) fixtureB.getBody().getUserData();
|
||||
EnemyEntity enemy = (EnemyEntity) fixtureA.getBody().getUserData();
|
||||
if (arrow != null) {
|
||||
arrow.destroy();
|
||||
if (ray != null) {
|
||||
Bugger.kills++;
|
||||
ray.destroy();
|
||||
enemy.destroy();
|
||||
}
|
||||
}
|
||||
@@ -47,7 +50,7 @@ public class GameContactListener implements ContactListener {
|
||||
}
|
||||
|
||||
private boolean isArrow(Fixture fixture) {
|
||||
return fixture.getBody().getUserData() instanceof Arrow;
|
||||
return fixture.getBody().getUserData() instanceof Ray;
|
||||
}
|
||||
|
||||
private boolean isEntity(Fixture fixture) {
|
||||
|
||||
@@ -15,7 +15,7 @@ public class ParticleManager {
|
||||
private ParticleManager() {
|
||||
ParticleEffect effect = new ParticleEffect();
|
||||
effect.load(Gdx.files.internal("particles/boom.p"), Gdx.files.internal("particles"));
|
||||
effect.scaleEffect(0.5f);
|
||||
effect.scaleEffect(0.3f);
|
||||
particleEffectPool = new ParticleEffectPool(effect, 1, 20);
|
||||
activeEffects = new Array<>();
|
||||
}
|
||||
|
||||
@@ -11,10 +11,14 @@ public class SpaceBackground {
|
||||
private final Texture nebulaTexture;
|
||||
private final float[] starPositionsX;
|
||||
private final float[] starPositionsY;
|
||||
private final int numStars = 10000;
|
||||
|
||||
// Scale factor for all textures
|
||||
private final float scaleFactor = 0.1f; // Scaling down by 0.1
|
||||
private final float[] galaxyPositionsX;
|
||||
private final float[] galaxyPositionsY;
|
||||
private final float[] nebulaPositionsX;
|
||||
private final float[] nebulaPositionsY;
|
||||
private final int numStars = 20000;
|
||||
private final int numGalaxies = 20;
|
||||
private final int numNebulae = 20;
|
||||
private final float scaleFactor = 0.1f;
|
||||
|
||||
public SpaceBackground() {
|
||||
starTexture = new Texture(Gdx.files.internal("images/star.png"));
|
||||
@@ -23,10 +27,24 @@ public class SpaceBackground {
|
||||
|
||||
starPositionsX = new float[numStars];
|
||||
starPositionsY = new float[numStars];
|
||||
galaxyPositionsX = new float[numGalaxies];
|
||||
galaxyPositionsY = new float[numGalaxies];
|
||||
nebulaPositionsX = new float[numNebulae];
|
||||
nebulaPositionsY = new float[numNebulae];
|
||||
|
||||
for (int i = 0; i < numStars; i++) {
|
||||
starPositionsX[i] = MathUtils.random(-Gdx.graphics.getWidth() * 10, Gdx.graphics.getWidth() * 10);
|
||||
starPositionsY[i] = MathUtils.random(-Gdx.graphics.getHeight() * 10, Gdx.graphics.getHeight() * 10);
|
||||
starPositionsX[i] = MathUtils.random(-Gdx.graphics.getWidth() * 2, Gdx.graphics.getWidth() * 2);
|
||||
starPositionsY[i] = MathUtils.random(-Gdx.graphics.getHeight() * 2, Gdx.graphics.getHeight() * 2);
|
||||
}
|
||||
|
||||
for (int i = 0; i < numGalaxies; i++) {
|
||||
galaxyPositionsX[i] = MathUtils.random(-Gdx.graphics.getWidth() * 2, Gdx.graphics.getWidth() * 2);
|
||||
galaxyPositionsY[i] = MathUtils.random(-Gdx.graphics.getHeight() * 2, Gdx.graphics.getHeight() * 2);
|
||||
}
|
||||
|
||||
for (int i = 0; i < numNebulae; i++) {
|
||||
nebulaPositionsX[i] = MathUtils.random(-Gdx.graphics.getWidth() * 2, Gdx.graphics.getWidth() * 2);
|
||||
nebulaPositionsY[i] = MathUtils.random(-Gdx.graphics.getHeight() * 2, Gdx.graphics.getHeight() * 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,68 +54,50 @@ public class SpaceBackground {
|
||||
float cameraX = Bugger.cam.position.x;
|
||||
float cameraY = Bugger.cam.position.y;
|
||||
|
||||
drawStars(cameraX, cameraY);
|
||||
drawGalaxies(cameraX, cameraY);
|
||||
drawNebulae(cameraX, cameraY);
|
||||
drawStars(cameraX, cameraY);
|
||||
|
||||
Bugger.getInstance().batch().end();
|
||||
}
|
||||
|
||||
private void drawStars(float cameraX, float cameraY) {
|
||||
for (int i = 0; i < numStars; i++) {
|
||||
float starScrollSpeedX = 0.5f;
|
||||
float starX = starPositionsX[i] - cameraX * starScrollSpeedX;
|
||||
float starScrollSpeedY = 0.5f;
|
||||
float starY = starPositionsY[i] - cameraY * starScrollSpeedY;
|
||||
float starScrollSpeed = 0.5f;
|
||||
float starX = starPositionsX[i] - (cameraX * starScrollSpeed);
|
||||
float starY = starPositionsY[i] - (cameraY * starScrollSpeed);
|
||||
|
||||
float offsetX = MathUtils.random(-2f, 2f);
|
||||
float offsetY = MathUtils.random(-2f, 2f);
|
||||
float scaledWidth = starTexture.getWidth() * scaleFactor / 5;
|
||||
float scaledHeight = starTexture.getHeight() * scaleFactor / 5;
|
||||
|
||||
// Scale the star size
|
||||
float scaledWidth = starTexture.getWidth() * scaleFactor;
|
||||
float scaledHeight = starTexture.getHeight() * scaleFactor;
|
||||
|
||||
Bugger.spriteBatch.draw(starTexture,
|
||||
starX + offsetX,
|
||||
starY + offsetY,
|
||||
scaledWidth,
|
||||
scaledHeight,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1
|
||||
);
|
||||
Bugger.spriteBatch.draw(starTexture, starX, starY, scaledWidth, scaledHeight);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawGalaxies(float cameraX, float cameraY) {
|
||||
float galaxyScrollSpeedY = 0.2f;
|
||||
float galaxyY1 = (cameraY * galaxyScrollSpeedY) % galaxyTexture.getHeight() - galaxyTexture.getHeight();
|
||||
float galaxyScrollSpeedX = 0.2f;
|
||||
float galaxyX1 = -cameraX * galaxyScrollSpeedX;
|
||||
float galaxyX2 = galaxyX1 + galaxyTexture.getWidth();
|
||||
for (int i = 0; i < numGalaxies; i++) {
|
||||
float galaxyScrollSpeed = 0.1f;
|
||||
float galaxyX = galaxyPositionsX[i] - (cameraX * galaxyScrollSpeed);
|
||||
float galaxyY = galaxyPositionsY[i] - (cameraY * galaxyScrollSpeed);
|
||||
|
||||
// Scale the galaxy size
|
||||
float scaledGalaxyWidth = galaxyTexture.getWidth() * scaleFactor;
|
||||
float scaledGalaxyHeight = galaxyTexture.getHeight() * scaleFactor;
|
||||
float scaledGalaxyWidth = galaxyTexture.getWidth() * scaleFactor * 2;
|
||||
float scaledGalaxyHeight = galaxyTexture.getHeight() * scaleFactor * 2;
|
||||
|
||||
Bugger.spriteBatch.draw(galaxyTexture, galaxyX1, galaxyY1, scaledGalaxyWidth, scaledGalaxyHeight);
|
||||
Bugger.spriteBatch.draw(galaxyTexture, galaxyX2, galaxyY1, scaledGalaxyWidth, scaledGalaxyHeight);
|
||||
Bugger.spriteBatch.draw(galaxyTexture, galaxyX, galaxyY, scaledGalaxyWidth, scaledGalaxyHeight);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawNebulae(float cameraX, float cameraY) {
|
||||
float nebulaScrollSpeedY = 0.025f;
|
||||
float nebulaY1 = (cameraY * nebulaScrollSpeedY) % nebulaTexture.getHeight() - nebulaTexture.getHeight();
|
||||
float nebulaScrollSpeedX = 0.025f;
|
||||
float nebulaX1 = -cameraX * nebulaScrollSpeedX;
|
||||
float nebulaX2 = nebulaX1 + nebulaTexture.getWidth();
|
||||
for (int i = 0; i < numNebulae; i++) {
|
||||
float nebulaScrollSpeed = 0.05f;
|
||||
float nebulaX = nebulaPositionsX[i] - (cameraX * nebulaScrollSpeed);
|
||||
float nebulaY = nebulaPositionsY[i] - (cameraY * nebulaScrollSpeed);
|
||||
|
||||
// Scale the nebula size
|
||||
float scaledNebulaWidth = nebulaTexture.getWidth() * scaleFactor;
|
||||
float scaledNebulaHeight = nebulaTexture.getHeight() * scaleFactor;
|
||||
float scaledNebulaWidth = nebulaTexture.getWidth() * scaleFactor * 1.5f;
|
||||
float scaledNebulaHeight = nebulaTexture.getHeight() * scaleFactor * 1.5f;
|
||||
|
||||
Bugger.spriteBatch.draw(nebulaTexture, nebulaX1, nebulaY1, scaledNebulaWidth, scaledNebulaHeight);
|
||||
Bugger.spriteBatch.draw(nebulaTexture, nebulaX2, nebulaY1, scaledNebulaWidth, scaledNebulaHeight);
|
||||
Bugger.spriteBatch.draw(nebulaTexture, nebulaX, nebulaY, scaledNebulaWidth, scaledNebulaHeight);
|
||||
}
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
|
||||