diff --git a/build.json b/build.json new file mode 100644 index 0000000..4d36cf2 --- /dev/null +++ b/build.json @@ -0,0 +1,10 @@ +{ + "platform": "windows64", + "jdk": "C:\\Program Files\\Eclipse Foundation\\jdk-11.0.12.7-hotspot", + "executable": "Drop", + "classpath": [ + "desktop\\build\\libs\\desktop-1.0.jar" + ], + "mainclass": "com.badlogic.drop.Drop", + "output": "out-windows" +} diff --git a/core/src/com/badlogic/drop/Drop.java b/core/src/com/badlogic/drop/Drop.java index c177b5d..4ceaa21 100644 --- a/core/src/com/badlogic/drop/Drop.java +++ b/core/src/com/badlogic/drop/Drop.java @@ -1,12 +1,14 @@ package com.badlogic.drop; import com.badlogic.gdx.ApplicationAdapter; +import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.audio.Sound; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Rectangle; @@ -16,103 +18,22 @@ import com.badlogic.gdx.utils.ScreenUtils; import com.badlogic.gdx.utils.TimeUtils; import java.util.Iterator; -public class Drop extends ApplicationAdapter { - private Texture dropImage; - private Texture bucketImage; - private Sound dropSound; - private Music rainMusic; +public class Drop extends Game { + public SpriteBatch batch; + public BitmapFont font; - private OrthographicCamera camera; - private SpriteBatch batch; - - private Rectangle bucket; - - private Array raindrops; - - private long lastDropTime; - - @Override public void create() { - dropImage = new Texture(Gdx.files.internal("droplet.png")); - bucketImage = new Texture(Gdx.files.internal("bucket.png")); - - dropSound = Gdx.audio.newSound(Gdx.files.internal("drop.wav")); - rainMusic = Gdx.audio.newMusic(Gdx.files.internal("rain.mp3")); - - rainMusic.setLooping(true); - rainMusic.play(); - - camera = new OrthographicCamera(); - camera.setToOrtho(false, 800, 480); - batch = new SpriteBatch(); - - bucket = new Rectangle(); - bucket.x = 800 / 2 - 64 / 2; - bucket.y = 20; - bucket.width = 64; - bucket.height = 64; - - raindrops = new Array(); - spawnRainDrop(); + font = new BitmapFont(); + this.setScreen(new MainMenuScreen(this)); } - @Override public void render() { - ScreenUtils.clear(0, 0, 0.2f, 1); - - camera.update(); - - batch.setProjectionMatrix(camera.combined); - batch.begin(); - batch.draw(bucketImage, bucket.x, bucket.y); - for (Rectangle raindrop:raindrops) { - batch.draw(dropImage, raindrop.x, raindrop.y); - } - batch.end(); - - if (Gdx.input.isTouched()) { - Vector3 touchPos = new Vector3(); - touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0); - camera.unproject(touchPos); - bucket.x = touchPos.x - 64 / 2; - } - - if (Gdx.input.isKeyPressed(Keys.LEFT)) bucket.x -= 200 * Gdx.graphics.getDeltaTime(); - if (Gdx.input.isKeyPressed(Keys.RIGHT)) bucket.x += 200 * Gdx.graphics.getDeltaTime(); - - if (bucket.x < 0) bucket.x = 0; - if (bucket.x > 800 - 64) bucket.x = 800 - 64; - - if (TimeUtils.nanoTime() - lastDropTime > 1000000000) spawnRainDrop(); - - for (Iterator iter = raindrops.iterator(); iter.hasNext(); ) { - Rectangle raindrop = iter.next(); - raindrop.y -= 200 * Gdx.graphics.getDeltaTime(); - if (raindrop.y + 64 < 0) iter.remove(); - if (raindrop.overlaps(bucket)) { - dropSound.play(); - iter.remove(); - } - } + super.render(); } - private void spawnRainDrop() { - Rectangle raindrop = new Rectangle(); - raindrop.x = MathUtils.random(0, 800 - 64); - raindrop.y = 480; - raindrop.width = 64; - raindrop.height = 64; - raindrops.add(raindrop); - lastDropTime = TimeUtils.nanoTime(); - } - - @Override public void dispose() { - dropImage.dispose(); - bucketImage.dispose(); - dropSound.dispose(); - rainMusic.dispose(); batch.dispose(); + font.dispose(); } } diff --git a/core/src/com/badlogic/drop/GameScreen.java b/core/src/com/badlogic/drop/GameScreen.java new file mode 100644 index 0000000..eed42b5 --- /dev/null +++ b/core/src/com/badlogic/drop/GameScreen.java @@ -0,0 +1,147 @@ +package com.badlogic.drop; + +import com.badlogic.gdx.Game; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Input.Keys; +import com.badlogic.gdx.Screen; +import com.badlogic.gdx.audio.Music; +import com.badlogic.gdx.audio.Sound; +import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.math.MathUtils; +import com.badlogic.gdx.math.Rectangle; +import com.badlogic.gdx.math.Vector3; +import com.badlogic.gdx.utils.Array; +import com.badlogic.gdx.utils.ScreenUtils; +import com.badlogic.gdx.utils.TimeUtils; +import java.util.Iterator; + +public class GameScreen implements Screen { + final Drop game; + + private Texture dropImage; + private Texture bucketImage; + private Sound dropSound; + private Music rainMusic; + + private OrthographicCamera camera; + + private Rectangle bucket; + + private Array raindrops; + + private long lastDropTime; + int dropGathered; + + public GameScreen(final Drop game) { + this.game = game; + + dropImage = new Texture(Gdx.files.internal("droplet.png")); + bucketImage = new Texture(Gdx.files.internal("bucket.png")); + + dropSound = Gdx.audio.newSound(Gdx.files.internal("drop.wav")); + rainMusic = Gdx.audio.newMusic(Gdx.files.internal("rain.mp3")); + rainMusic.setLooping(true); + + camera = new OrthographicCamera(); + camera.setToOrtho(false, 800, 480); + + bucket = new Rectangle(); + bucket.x = 800 / 2 - 64 / 2; + bucket.y = 20; + bucket.width = 64; + bucket.height = 64; + + raindrops = new Array(); + spawnRainDrop(); + } + + @Override + public void render(float delta) { + ScreenUtils.clear(0, 0, 0.2f, 1); + + camera.update(); + + game.batch.setProjectionMatrix(camera.combined); + game.batch.begin(); + game.font.draw(game.batch, "Drops Collected: " + dropGathered, 0, 480 ); + game.batch.draw(bucketImage, bucket.x, bucket.y, bucket.width, bucket.height); + for (Rectangle raindrop:raindrops) { + game.batch.draw(dropImage, raindrop.x, raindrop.y); + } + game.batch.end(); + + if (Gdx.input.isTouched()) { + Vector3 touchPos = new Vector3(); + touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0); + camera.unproject(touchPos); + bucket.x = touchPos.x - 64 / 2; + } + + if (Gdx.input.isKeyPressed(Keys.LEFT)) + bucket.x -= 200 * Gdx.graphics.getDeltaTime(); + if (Gdx.input.isKeyPressed(Keys.RIGHT)) + bucket.x += 200 * Gdx.graphics.getDeltaTime(); + + if (bucket.x < 0) bucket.x = 0; + if (bucket.x > 800 - 64) bucket.x = 800 - 64; + + if (TimeUtils.nanoTime() - lastDropTime > 1000000000) + spawnRainDrop(); + + for (Iterator iter = raindrops.iterator(); iter.hasNext(); ) { + Rectangle raindrop = iter.next(); + raindrop.y -= 200 * Gdx.graphics.getDeltaTime(); + if (raindrop.y + 64 < 0) iter.remove(); + if (raindrop.overlaps(bucket)) { + dropGathered++; + dropSound.play(); + iter.remove(); + } + } + } + + private void spawnRainDrop() { + Rectangle raindrop = new Rectangle(); + raindrop.x = MathUtils.random(0, 800 - 64); + raindrop.y = 480; + raindrop.width = 64; + raindrop.height = 64; + raindrops.add(raindrop); + lastDropTime = TimeUtils.nanoTime(); + } + + @Override + public void dispose() { + dropImage.dispose(); + bucketImage.dispose(); + dropSound.dispose(); + rainMusic.dispose(); + } + + @Override + public void show() { + rainMusic.play(); + } + + @Override + public void resize(int width, int height) { + + } + + @Override + public void pause() { + + } + + @Override + public void resume() { + + } + + @Override + public void hide() { + + } +} diff --git a/core/src/com/badlogic/drop/MainMenuScreen.java b/core/src/com/badlogic/drop/MainMenuScreen.java new file mode 100644 index 0000000..4197f0e --- /dev/null +++ b/core/src/com/badlogic/drop/MainMenuScreen.java @@ -0,0 +1,53 @@ +package com.badlogic.drop; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Screen; +import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.utils.ScreenUtils; + +public class MainMenuScreen implements Screen { + final Drop game; + OrthographicCamera camera; + + public MainMenuScreen(final Drop game) { + this.game = game; + camera = new OrthographicCamera(); + camera.setToOrtho(false, 800, 480); + } + + @Override + public void show() {} + + @Override + public void render(float delta) { + ScreenUtils.clear(0, 0, 0.2f, 1); + + camera.update(); + game.batch.setProjectionMatrix(camera.combined); + + game.batch.begin(); + game.font.draw(game.batch, "Welcome to Drop!!!", 100, 150); + game.font.draw(game.batch, "Tap anywhere to begin!", 100, 100); + game.batch.end(); + + if (Gdx.input.isTouched()) { + game.setScreen(new GameScreen(game)); + dispose(); + } + } + + @Override + public void resize(int width, int height) {} + + @Override + public void pause() {} + + @Override + public void resume() {} + + @Override + public void hide() {} + + @Override + public void dispose() {} +} diff --git a/html/src/com/badlogic/drop/GdxDefinition.gwt.xml b/html/src/com/badlogic/drop/GdxDefinition.gwt.xml index 5c18a05..2bc47c6 100644 --- a/html/src/com/badlogic/drop/GdxDefinition.gwt.xml +++ b/html/src/com/badlogic/drop/GdxDefinition.gwt.xml @@ -1,14 +1,12 @@ - + - - + diff --git a/packr-all-4.0.0.jar b/packr-all-4.0.0.jar new file mode 100644 index 0000000..4fcf201 Binary files /dev/null and b/packr-all-4.0.0.jar differ