diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 88d64fb2c78103d2341a1fcc9177eab886643d6b..4e89e0229513f71d3b79e5999aaefe0018d7f958 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -16,7 +16,7 @@ <activity android:name="com.buildasnowman.game.AndroidLauncher" android:label="@string/app_name" - android:screenOrientation="landscape" + android:screenOrientation="portrait" android:configChanges="keyboard|keyboardHidden|navigation|orientation|screenSize|screenLayout" android:exported="true"> <intent-filter> diff --git a/core/src/com/buildasnowman/game/BuildASnowman.java b/core/src/com/buildasnowman/game/BuildASnowman.java index 0678050d1d615c28795b408c3d537c3a1d6876f1..6de772d3c6b4b21f38b889435b606d3c69938ed4 100644 --- a/core/src/com/buildasnowman/game/BuildASnowman.java +++ b/core/src/com/buildasnowman/game/BuildASnowman.java @@ -1,31 +1,70 @@ package com.buildasnowman.game; import com.badlogic.gdx.ApplicationAdapter; +import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.utils.ScreenUtils; +import com.badlogic.gdx.graphics.g2d.BitmapFont; +import com.badlogic.gdx.Input; public class BuildASnowman extends ApplicationAdapter { SpriteBatch batch; Texture img; - + float screenWidth; + float screenHeight; + float imgWidth; + float imgHeight; + float scale; + int score; + BitmapFont font; + @Override public void create () { batch = new SpriteBatch(); - img = new Texture("badlogic.jpg"); + img = new Texture("Background.png"); + screenWidth = Gdx.graphics.getWidth(); + screenHeight = Gdx.graphics.getHeight(); + imgWidth = img.getWidth(); + imgHeight = img.getHeight(); + scale = screenWidth / imgWidth; //This is used to make the width of the image fit the width of the + imgWidth *= scale; + imgHeight *= scale; + font = new BitmapFont(); + score = 0; } @Override public void render () { - ScreenUtils.clear(1, 0, 0, 1); + ScreenUtils.clear(13 / 255f, 0 / 255f, 16 / 255f, 1); //Background color is set to the same color at the top of the image to allow for seamless scrolling should the score increase further than the height of the image, + batch.begin(); - batch.draw(img, 0, 0); + batch.draw(img, 0, (-1 * score), imgWidth, imgHeight); //Background is drawn, uses the score to set the start of the image further down to emulate scrolling when the score is increased. batch.end(); + + drawScore(); + + handleInput(); } - + + private void drawScore() { + batch.begin(); + font.draw(batch, "Score " + score + " ", 20, Gdx.graphics.getHeight() - 10); + batch.end(); + } + @Override public void dispose () { batch.dispose(); img.dispose(); } + + + //temporary function to show that the scrolling of the background is working in relation to the score. funker best i desktop + private void handleInput() { + if (Gdx.input.isKeyPressed(Input.Keys.SPACE)) { // Check if spacebar is pressed + score += 10; // Increase score by 10 + } + } + }