Ok Guys, its working ! But, i have a question, how do i calculate the rate “PASS_FRAME_SCORE” ? I want to calculate it in a way that the score calculus doesnt take more than 10 seconds.
Plus, the table is small… I will create a new topic about that. Anyway, heres the code :
package br.views.levels;
import br.data.Data;
import br.data.SaveData;
import br.dir.DirectoriesLevel_Extend;
import br.player.Player;
import br.tools.MyTimer;
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.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable;
/**
*
* @author André Lopes
*/
public class GameOver extends Level_Extend implements Screen {
private final int PASS_FRAME_SCORE = 50;
private Texture gameOver;
private MyTimer timer;
private int color;
private Data data;
private SaveData saveData;
private DrawText drawText;
private TextField dataScore, diamondScore, totalScore;
private Table scoreTable;
public GameOver(Data data) {
this.data = data;
}
@Override
public void updateCamera() {
}
@Override
public void configLoadedLevelData(Data data) {
}
@Override
public void configLevelData() {
}
@Override
public void script() {
}
@Override
public void nextLevel() {
}
@Override
public void teleportTile(TiledMapTileLayer collisionLayer, Player player) {
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
color++;
if (color > 240) {
color = 0;
}
batch.begin();
batch.draw(gameOver, 0, 0);
batch.end();
stage.act(delta);
stage.draw();
Table.drawDebug(stage);
update();
}
@Override
public void resize(int width, int height) {
stage.setViewport(width, height, true);
int w = (Gdx.graphics.getWidth() / 2);
int h = (Gdx.graphics.getHeight() - Gdx.graphics.getHeight() / 5);
scoreTable.setPosition(w, h);
scoreTable.invalidateHierarchy();
dataScore.invalidate();
totalScore.invalidate();
diamondScore.invalidate();
camera.position.set(0, 0, 0f);
camera.viewportWidth = 800;
camera.viewportHeight = 600;
}
@Override
public void show() {
color = 0;
stage = new Stage();
camera = new OrthographicCamera();
batch = new SpriteBatch();
drawText = new DrawText();
scoreTable = new Table();
scoreTable.pad(15f);
//
gameOver = new Texture(Gdx.files.internal("imagens/Resources/GameOver/BlackScreen.png"));
gameOver.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest);
//
DirectoriesLevel_Extend directoriesLevelExtend = new DirectoriesLevel_Extend();
simpleRedFont = directoriesLevelExtend.getSimpleRedFont();
simpleWhiteFont = directoriesLevelExtend.getSimpleWhiteFont();
timer = new MyTimer(60);
timer.start();
saveData = new SaveData();
LabelStyle ls = new LabelStyle();
ls.font = simpleWhiteFont;
Label titleLabel = new Label("Game Over", ls);
TextField.TextFieldStyle textFieldStyleDataScore = new TextField.TextFieldStyle();
textFieldStyleDataScore.font = simpleWhiteFont;
textFieldStyleDataScore.fontColor = Color.YELLOW;
Sprite sprite = new Sprite(new Texture(Gdx.files.internal("imagens/Resources/ui/textField/natyyr/box.png")));
SpriteDrawable sd = new SpriteDrawable(sprite);
textFieldStyleDataScore.background = sd;
textFieldStyleDataScore.background.setLeftWidth(10f);
TextField.TextFieldStyle textFieldStyleDiamondScore = new TextField.TextFieldStyle();
textFieldStyleDiamondScore.font = simpleWhiteFont;
textFieldStyleDiamondScore.fontColor = Color.RED;
textFieldStyleDiamondScore.background = (new SpriteDrawable(new Sprite(new Texture(Gdx.files.internal("imagens/Resources/ui/textField/natyyr/box.png")))));
textFieldStyleDiamondScore.background.setLeftWidth(10f);
TextField.TextFieldStyle textFieldStyleTotalScore = new TextField.TextFieldStyle();
textFieldStyleTotalScore.font = simpleWhiteFont;
textFieldStyleTotalScore.fontColor = Color.WHITE;
textFieldStyleTotalScore.background = (new SpriteDrawable(new Sprite(new Texture(Gdx.files.internal("imagens/Resources/ui/textField/natyyr/box_lit.png")))));
textFieldStyleTotalScore.background.setLeftWidth(10f);
dataScore = new TextField("123456789", textFieldStyleDataScore);
diamondScore = new TextField("123456789", textFieldStyleDiamondScore);
totalScore = new TextField("246913578", textFieldStyleTotalScore);
scoreTable.add(titleLabel);
scoreTable.row();
scoreTable.add(dataScore);
scoreTable.row();
scoreTable.add(diamondScore);
scoreTable.row();
scoreTable.add(totalScore);
int w = (Gdx.graphics.getWidth() / 2);
int h = (Gdx.graphics.getHeight() - Gdx.graphics.getHeight() / 5);
scoreTable.setPosition(w, h);
scoreTable.debug();
stage.addActor(scoreTable);
int current_Red_Diamond = data.getCurrent_Red_Diamond();
int current_Blue_Diamond = data.getCurrent_Blue_Diamond();
setDiamondScore(10 * (100 * current_Red_Diamond + 100 * current_Blue_Diamond));
setDataScore(data.getCurrent_Score());
setTotalScore(0);
}
private void update() {
int dataScoreInt = getDataScore();
int diamondScoreInt = getDiamondScore();
int totalScoreInt = getTotalScore();
if (dataScoreInt - PASS_FRAME_SCORE > 0) {
totalScoreInt = totalScoreInt + PASS_FRAME_SCORE;
setDataScore(dataScoreInt - PASS_FRAME_SCORE);
} else if (dataScoreInt > 0) {
totalScoreInt = totalScoreInt + dataScoreInt;
setDataScore(0);
}
if (diamondScoreInt - PASS_FRAME_SCORE > 0) {
totalScoreInt = totalScoreInt + PASS_FRAME_SCORE;
setDiamondScore(diamondScoreInt - PASS_FRAME_SCORE);
} else if (diamondScoreInt > 0) {
totalScoreInt = diamondScoreInt + totalScoreInt;
setDiamondScore(0);
}
setTotalScore(totalScoreInt);
}
private int getDiamondScore() {
String text = diamondScore.getText();
int parseInt = Integer.parseInt(text);
return parseInt;
}
private int getTotalScore() {
String text = totalScore.getText();
int parseInt = Integer.parseInt(text);
return parseInt;
}
private int getDataScore() {
String text = dataScore.getText();
int parseInt = Integer.parseInt(text);
return parseInt;
}
private void setDiamondScore(int score) {
diamondScore.setText("" + score);
}
private void setTotalScore(int score) {
totalScore.setText("" + score);
}
private void setDataScore(int score) {
dataScore.setText("" + score);
}
@Override
public void dispose() {
batch.dispose();
gameOver.dispose();
}
@Override
public void hide() {
}
}