Commit 8d231aea authored by Sven Greiner's avatar Sven Greiner
Browse files

Reformat code and optimize imports

parent 47a9a788
......@@ -19,7 +19,6 @@ import com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import org.milderjoghurt.frozennumbers.screens.MainMenuScreen;
import java.util.HashMap;
......@@ -90,7 +89,6 @@ public class FrozenNumbersGame extends ApplicationAdapter {
assets.load("snd/hit.mp3", Sound.class);
assets.load("snd/shot.mp3", Sound.class);
assets.load("snd/theme.ogg", Sound.class);
//assets.load("snd/load.wav", Sound.class);
assets.load("snd/pop.mp3", Sound.class);
assets.finishLoading();
......
......@@ -9,6 +9,7 @@ import org.milderjoghurt.frozennumbers.FrozenNumbersGame;
import org.milderjoghurt.frozennumbers.util.HSL;
import com.badlogic.gdx.graphics.Color;
import java.util.Random;
public class Bubble extends Sprite {
......@@ -125,10 +126,10 @@ public class Bubble extends Sprite {
return (frozen_s <= 0);
}
public void setFalling() {
this.setColor(Color.GRAY);
falling = true;
}
public void setFalling() {
this.setColor(Color.GRAY);
falling = true;
}
}
package org.milderjoghurt.frozennumbers.screens;
import java.util.Map;
import org.milderjoghurt.frozennumbers.FrozenNumbersGame;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.math.Vector2;
public class GameOverScreen implements Screen {
Game game;
public static Map<String,Screen> m_Screens;
Sprite bg;
int p1 = 0;
int p2 = 0;
Sprite closeTop, closeBottom;
float wHeight;
float wWidth;
GlyphLayout glyphLayout = new GlyphLayout();
public GameOverScreen(int p1Score,int p2Score) {
p1 = p1Score;
p2 = p2Score;
wWidth = FrozenNumbersGame.viewport.getWorldWidth();
wHeight = FrozenNumbersGame.viewport.getWorldHeight();
game = FrozenNumbersGame.game;
m_Screens = FrozenNumbersGame.m_Screens;
//generating backround
bg = new Sprite(FrozenNumbersGame.assets.get("backgrounds/background.jpg", Texture.class));
float scaleX = wWidth / bg.getWidth();
float scaleY = wHeight / bg.getHeight();
bg.setScale(scaleX, scaleY);
bg.setCenter(wWidth / 2.0f, wHeight / 2.0f);
//generating Close button
closeBottom = new Sprite(FrozenNumbersGame.assets.get("sprites/btn_back.png", Texture.class));
closeBottom.setScale(scaleX, scaleY);
closeBottom.setCenter(wWidth / 4.0f, wHeight / 2.0f);
closeTop = new Sprite(FrozenNumbersGame.assets.get("sprites/btn_back.png", Texture.class));
closeTop.setScale(scaleX, scaleY);
closeTop.rotate(180);
closeTop.setCenter(wWidth / 4.0f * 3.0f, wHeight / 2.0f);
}
@Override
public void show() {
// TODO Auto-generated method stub
}
@Override
public void render(float delta) {
if (Gdx.input.justTouched()) {
Vector2 touchPoint = new Vector2();
FrozenNumbersGame.viewport.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY()));
//Clicking Close Button
if(closeBottom.getBoundingRectangle().contains(touchPoint.x, touchPoint.y) ||
closeTop.getBoundingRectangle().contains(touchPoint.x, touchPoint.y)) {
game.setScreen(m_Screens.get("MainMenu"));
}
}
// Drawing Stuff
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
Batch batch = FrozenNumbersGame.batch;
FrozenNumbersGame.viewport.apply(true);
batch.setProjectionMatrix(FrozenNumbersGame.viewport.getCamera().combined);
batch.begin();
bg.draw(batch);
closeBottom.draw(batch);
closeTop.draw(batch);
String p1String = new String();
String p2String = new String();
if(p1 > p2)
{
p1String = "WIN";
p2String = "LOSE";
}
if(p2 > p1)
{
p1String = "LOSE";
p2String = "WIN";
}
if(p2 == p1)
{
p1String = "DRAW";
p2String = "DRAW";
}
// Draw Players Results
Table container = new Table();
Label winLoose = new Label(null, new Label.LabelStyle(FrozenNumbersGame.assets.get("size60.ttf", BitmapFont.class), Color.WHITE));
Label points = new Label(null, new Label.LabelStyle(FrozenNumbersGame.assets.get("size40.ttf", BitmapFont.class), Color.WHITE));
// Bottom Player
winLoose.setText(p1String);
container.add(winLoose);
container.setPosition((wWidth / 2), wHeight / 4 + 30);
container.draw(batch, 1);
points.setText(p1 + " Points");
container.clearChildren();
container.add(points);
container.setPosition((wWidth / 2), wHeight / 4 - 30);
container.draw(batch, 1);
// Top Player
container.setTransform(true);
container.setRotation(180);
winLoose.setText(p2String);
container.clearChildren();
container.add(winLoose);
container.setPosition((wWidth / 2), wHeight / 4 * 3 - 30);
container.draw(batch, 1);
points.setText(p2 + " Points");
container.clearChildren();
container.add(points);
container.setPosition((wWidth / 2), wHeight / 4 * 3 + 30);
container.draw(batch, 1);
batch.end();
}
@Override
public void resize(int width, int height) {
wWidth = FrozenNumbersGame.viewport.getWorldWidth();
wHeight = FrozenNumbersGame.viewport.getWorldHeight();
}
@Override
public void pause() {
// TODO Auto-generated method stub
}
@Override
public void resume() {
// TODO Auto-generated method stub
}
@Override
public void hide() {
// TODO Auto-generated method stub
}
@Override
public void dispose() {
// TODO Auto-generated method stub
}
}
package org.milderjoghurt.frozennumbers.screens;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import org.milderjoghurt.frozennumbers.FrozenNumbersGame;
import java.util.Map;
public class GameOverScreen implements Screen {
Game game;
public static Map<String, Screen> m_Screens;
Sprite bg;
int p1 = 0;
int p2 = 0;
Sprite closeTop, closeBottom;
float wHeight;
float wWidth;
GlyphLayout glyphLayout = new GlyphLayout();
public GameOverScreen(int p1Score, int p2Score) {
p1 = p1Score;
p2 = p2Score;
wWidth = FrozenNumbersGame.viewport.getWorldWidth();
wHeight = FrozenNumbersGame.viewport.getWorldHeight();
game = FrozenNumbersGame.game;
m_Screens = FrozenNumbersGame.m_Screens;
//generating backround
bg = new Sprite(FrozenNumbersGame.assets.get("backgrounds/background.jpg", Texture.class));
float scaleX = wWidth / bg.getWidth();
float scaleY = wHeight / bg.getHeight();
bg.setScale(scaleX, scaleY);
bg.setCenter(wWidth / 2.0f, wHeight / 2.0f);
//generating Close button
closeBottom = new Sprite(FrozenNumbersGame.assets.get("sprites/btn_back.png", Texture.class));
closeBottom.setScale(scaleX, scaleY);
closeBottom.setCenter(wWidth / 4.0f, wHeight / 2.0f);
closeTop = new Sprite(FrozenNumbersGame.assets.get("sprites/btn_back.png", Texture.class));
closeTop.setScale(scaleX, scaleY);
closeTop.rotate(180);
closeTop.setCenter(wWidth / 4.0f * 3.0f, wHeight / 2.0f);
}
@Override
public void show() {
// TODO Auto-generated method stub
}
@Override
public void render(float delta) {
if (Gdx.input.justTouched()) {
Vector2 touchPoint = new Vector2();
FrozenNumbersGame.viewport.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY()));
//Clicking Close Button
if (closeBottom.getBoundingRectangle().contains(touchPoint.x, touchPoint.y) ||
closeTop.getBoundingRectangle().contains(touchPoint.x, touchPoint.y)) {
game.setScreen(m_Screens.get("MainMenu"));
}
}
// Drawing Stuff
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
Batch batch = FrozenNumbersGame.batch;
FrozenNumbersGame.viewport.apply(true);
batch.setProjectionMatrix(FrozenNumbersGame.viewport.getCamera().combined);
batch.begin();
bg.draw(batch);
closeBottom.draw(batch);
closeTop.draw(batch);
String p1String = new String();
String p2String = new String();
if (p1 > p2) {
p1String = "WIN";
p2String = "LOSE";
}
if (p2 > p1) {
p1String = "LOSE";
p2String = "WIN";
}
if (p2 == p1) {
p1String = "DRAW";
p2String = "DRAW";
}
// Draw Players Results
Table container = new Table();
Label winLoose = new Label(null, new Label.LabelStyle(FrozenNumbersGame.assets.get("size60.ttf", BitmapFont.class), Color.WHITE));
Label points = new Label(null, new Label.LabelStyle(FrozenNumbersGame.assets.get("size40.ttf", BitmapFont.class), Color.WHITE));
// Bottom Player
winLoose.setText(p1String);
container.add(winLoose);
container.setPosition((wWidth / 2), wHeight / 4 + 30);
container.draw(batch, 1);
points.setText(p1 + " Points");
container.clearChildren();
container.add(points);
container.setPosition((wWidth / 2), wHeight / 4 - 30);
container.draw(batch, 1);
// Top Player
container.setTransform(true);
container.setRotation(180);
winLoose.setText(p2String);
container.clearChildren();
container.add(winLoose);
container.setPosition((wWidth / 2), wHeight / 4 * 3 - 30);
container.draw(batch, 1);
points.setText(p2 + " Points");
container.clearChildren();
container.add(points);
container.setPosition((wWidth / 2), wHeight / 4 * 3 + 30);
container.draw(batch, 1);
batch.end();
}
@Override
public void resize(int width, int height) {
wWidth = FrozenNumbersGame.viewport.getWorldWidth();
wHeight = FrozenNumbersGame.viewport.getWorldHeight();
}
@Override
public void pause() {
// TODO Auto-generated method stub
}
@Override
public void resume() {
// TODO Auto-generated method stub
}
@Override
public void hide() {
// TODO Auto-generated method stub
}
@Override
public void dispose() {
// TODO Auto-generated method stub
}
}
......@@ -13,7 +13,6 @@ import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import org.milderjoghurt.frozennumbers.FrozenNumbersGame;
import java.util.Map;
......
......@@ -8,7 +8,6 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Vector2;
import org.milderjoghurt.frozennumbers.FrozenNumbersGame;
import java.util.Map;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment