diff --git a/assets/images/galaxy.png b/assets/images/galaxy.png new file mode 100644 index 0000000..8ffd162 Binary files /dev/null and b/assets/images/galaxy.png differ diff --git a/assets/images/nebula.png b/assets/images/nebula.png new file mode 100644 index 0000000..52d0bd0 Binary files /dev/null and b/assets/images/nebula.png differ diff --git a/assets/images/star.png b/assets/images/star.png new file mode 100644 index 0000000..fa79d8d Binary files /dev/null and b/assets/images/star.png differ diff --git a/core/src/main/java/org/lumijiez/bugger/GameScreen.java b/core/src/main/java/org/lumijiez/bugger/GameScreen.java index 427cac0..4c0fe6c 100644 --- a/core/src/main/java/org/lumijiez/bugger/GameScreen.java +++ b/core/src/main/java/org/lumijiez/bugger/GameScreen.java @@ -4,6 +4,7 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; 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.math.Vector2; import com.badlogic.gdx.physics.box2d.*; @@ -18,6 +19,8 @@ import java.util.ArrayList; import java.util.List; public class GameScreen implements Screen { + public static OrthographicCamera cam; + private SpaceBackground spaceBackground = new SpaceBackground(); private final World world; private final Player player; public static final SpriteBatch spriteBatch = new SpriteBatch(); @@ -36,6 +39,11 @@ public class GameScreen implements Screen { arrows = new Array<>(); entitiesToDestroy = new Array<>(); world.setContactListener(new GameContactListener()); + + cam = new OrthographicCamera(); + cam.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); + cam.position.set(Player.getInstance().getPosition().x / 2f, Player.getInstance().getPosition().y / 2f, 0); + cam.update(); } @Override @@ -45,9 +53,14 @@ public class GameScreen implements Screen { @Override public void render(float delta) { + cam.update(); + spriteBatch.setProjectionMatrix(cam.combined); + Gdx.gl.glClearColor(0.1f, 0.1f, 0.1f, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + spaceBackground.render(); + world.step(1f, 6, 2); if (Gdx.input.isButtonJustPressed(Input.Buttons.LEFT)) { @@ -100,6 +113,8 @@ public class GameScreen implements Screen { } debugRenderer.render(world, spriteBatch.getProjectionMatrix()); + + cam.position.set(Player.getInstance().getPosition().x, Player.getInstance().getPosition().y, 0); } @@ -127,5 +142,6 @@ public class GameScreen implements Screen { public void dispose() { spriteBatch.dispose(); world.dispose(); + spaceBackground.dispose(); } } diff --git a/core/src/main/java/org/lumijiez/bugger/ParticleManager.java b/core/src/main/java/org/lumijiez/bugger/ParticleManager.java index 719a7a2..8a24629 100644 --- a/core/src/main/java/org/lumijiez/bugger/ParticleManager.java +++ b/core/src/main/java/org/lumijiez/bugger/ParticleManager.java @@ -1,5 +1,6 @@ package org.lumijiez.bugger; +import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.g2d.ParticleEffect; import com.badlogic.gdx.graphics.g2d.ParticleEffectPool; @@ -45,11 +46,11 @@ public class ParticleManager { } public void render(SpriteBatch spriteBatch) { - spriteBatch.begin(); for (ParticleEffectPool.PooledEffect effect : activeEffects) { + GameScreen.spriteBatch.begin(); effect.draw(spriteBatch); + GameScreen.spriteBatch.end(); } - spriteBatch.end(); } public void dispose() { diff --git a/core/src/main/java/org/lumijiez/bugger/SpaceBackground.java b/core/src/main/java/org/lumijiez/bugger/SpaceBackground.java new file mode 100644 index 0000000..24f5dad --- /dev/null +++ b/core/src/main/java/org/lumijiez/bugger/SpaceBackground.java @@ -0,0 +1,108 @@ +package org.lumijiez.bugger; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.math.MathUtils; + +public class SpaceBackground { + private Texture starTexture; + private Texture galaxyTexture; + private Texture nebulaTexture; + + private float[] starPositionsX; + private float[] starPositionsY; + private int numStars = 1000; // Number of stars to generate + + private float galaxyScrollSpeed = 0.1f; // Galaxy scroll speed + private float nebulaScrollSpeed = 0.05f; // Nebula scroll speed + private float starScrollSpeed = 0.2f; // Star scroll speed + + private float galaxyOffset = 0; + private float nebulaOffset = 0; + + public SpaceBackground() { + starTexture = new Texture(Gdx.files.internal("images/star.png")); + galaxyTexture = new Texture(Gdx.files.internal("images/galaxy.png")); + nebulaTexture = new Texture(Gdx.files.internal("images/nebula.png")); + + starPositionsX = new float[numStars]; + starPositionsY = new float[numStars]; + + for (int i = 0; i < numStars; i++) { + starPositionsX[i] = MathUtils.random(0, Gdx.graphics.getWidth()); + starPositionsY[i] = MathUtils.random(0, Gdx.graphics.getHeight()); + } + } + + public void render() { + GameScreen.spriteBatch.begin(); + + // Draw galaxies with parallax effect + drawGalaxies(); + + // Draw nebulae with parallax effect + drawNebulae(); + + // Draw star particles + drawStars(); + + GameScreen.spriteBatch.end(); + + // Update offsets for parallax scrolling + updateOffsets(); + } + + private void drawStars() { + float starScale = 0.1f; // Scale factor for stars + for (int i = 0; i < numStars; i++) { + // Draw the star with scaling + GameScreen.spriteBatch.draw(starTexture, starPositionsX[i], starPositionsY[i], + starTexture.getWidth() * starScale / 2, // Origin X + starTexture.getHeight() * starScale / 2, // Origin Y + starTexture.getWidth() * starScale, // Width + starTexture.getHeight() * starScale, // Height + 1, // Scale X + 1 // Scale Y + ); // Rotation + } + } + + private void drawGalaxies() { + float screenHeight = Gdx.graphics.getHeight(); + float galaxyY = (float) (Gdx.graphics.getHeight() - galaxyTexture.getHeight()) / 2 + galaxyOffset; + + // Draw the galaxy texture + GameScreen.spriteBatch.draw(galaxyTexture, 0, galaxyY); + GameScreen.spriteBatch.draw(galaxyTexture, 0, galaxyY + galaxyTexture.getHeight()); + } + + private void drawNebulae() { + float screenHeight = Gdx.graphics.getHeight(); + float nebulaY = (float) (Gdx.graphics.getHeight() - nebulaTexture.getHeight()) / 2 + nebulaOffset; + + // Draw the nebula texture + GameScreen.spriteBatch.draw(nebulaTexture, 0, nebulaY); + GameScreen.spriteBatch.draw(nebulaTexture, 0, nebulaY + nebulaTexture.getHeight()); + } + + private void updateOffsets() { + // Update offsets for scrolling + galaxyOffset -= galaxyScrollSpeed; // Move galaxy layer up + nebulaOffset -= nebulaScrollSpeed; // Move nebula layer up + + // Reset offset if it goes out of bounds + if (galaxyOffset <= -galaxyTexture.getHeight()) { + galaxyOffset = 0; + } + if (nebulaOffset <= -nebulaTexture.getHeight()) { + nebulaOffset = 0; + } + } + + public void dispose() { + starTexture.dispose(); + galaxyTexture.dispose(); + nebulaTexture.dispose(); + } +} diff --git a/core/src/main/java/org/lumijiez/bugger/entities/Player.java b/core/src/main/java/org/lumijiez/bugger/entities/Player.java index 3121d97..5f28dd7 100644 --- a/core/src/main/java/org/lumijiez/bugger/entities/Player.java +++ b/core/src/main/java/org/lumijiez/bugger/entities/Player.java @@ -6,6 +6,8 @@ import com.badlogic.gdx.physics.box2d.World; import com.badlogic.gdx.math.Vector2; import org.lumijiez.bugger.entities.weapons.Arrow; +import static org.lumijiez.bugger.GameScreen.cam; + public class Player extends Entity { private static Player instance; private final float speed = 5f; @@ -52,7 +54,7 @@ public class Player extends Entity { float mouseX = Gdx.input.getX(); float mouseY = Gdx.input.getY(); Vector2 mousePosition = new Vector2(mouseX, Gdx.graphics.getHeight() - mouseY); - Vector2 direction = mousePosition.cpy().sub(body.getPosition()).nor(); + Vector2 direction = mousePosition.cpy().sub(new Vector2(cam.position.x, cam.position.y)).nor(); float angle = direction.angleDeg() + 270f; body.setTransform(body.getPosition(), angle * (float) Math.PI / 180f); sprite.setRotation(body.getAngle() * (180f / (float) Math.PI)); @@ -63,7 +65,7 @@ public class Player extends Entity { float mouseX = Gdx.input.getX(); float mouseY = Gdx.input.getY(); Vector2 mousePosition = new Vector2(mouseX, Gdx.graphics.getHeight() - mouseY); - direction.set(mousePosition).sub(getPosition()).nor(); + direction.set(mousePosition).sub(new Vector2(cam.position.x, cam.position.y)).nor(); Arrow arrow = new Arrow(world, getPosition(), direction); arrow.body.setUserData(arrow); diff --git a/core/src/main/java/org/lumijiez/bugger/entities/weapons/Arrow.java b/core/src/main/java/org/lumijiez/bugger/entities/weapons/Arrow.java index 21bbbd8..4763116 100644 --- a/core/src/main/java/org/lumijiez/bugger/entities/weapons/Arrow.java +++ b/core/src/main/java/org/lumijiez/bugger/entities/weapons/Arrow.java @@ -5,7 +5,7 @@ import com.badlogic.gdx.physics.box2d.*; import org.lumijiez.bugger.entities.Entity; public class Arrow extends Entity { - private final float speed = 5000f; + private final float speed = 4000f; private final float lifetime = 3f; private float timeAlive = 0f;