Countdown now opengl-rendered -> no more bugs
Fixed minor bugs
This commit is contained in:
@ -0,0 +1,95 @@
|
||||
package de.frajul.endlessroll.entities;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.Entity;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
import de.frajul.endlessroll.entities.textures.TexturePack;
|
||||
import de.frajul.endlessroll.main.game.Game;
|
||||
import de.frajul.endlessroll.sounds.SoundManager;
|
||||
import de.frajul.endlessroll.sounds.SoundStream;
|
||||
|
||||
/**
|
||||
* Created by Julian on 31.07.2016.
|
||||
*/
|
||||
public class Countdown extends Entity {
|
||||
|
||||
private Game game;
|
||||
private SoundManager soundManager;
|
||||
private SoundStream soundStream;
|
||||
private Texture texture3;
|
||||
private Texture texture2;
|
||||
private Texture texture1;
|
||||
|
||||
private AtomicBoolean running;
|
||||
private int currentSeconds = 0;
|
||||
private float time = 0;
|
||||
|
||||
public Countdown(Game game, SoundManager soundManager, TexturePack texturePack) {
|
||||
super(texturePack.countdown3, new Vector(), 0.8f, 0.8f);
|
||||
this.game = game;
|
||||
this.soundManager = soundManager;
|
||||
this.texture3 = texturePack.countdown1;
|
||||
this.texture2 = texturePack.countdown2;
|
||||
this.texture1 = texturePack.countdown3;
|
||||
running = new AtomicBoolean(false);
|
||||
}
|
||||
|
||||
public void update(float delta) {
|
||||
if (running.get()) {
|
||||
time += delta;
|
||||
if (time >= 1000 && currentSeconds == 0) {
|
||||
currentSeconds = 1;
|
||||
onNextSecondThread(currentSeconds, true);
|
||||
|
||||
}
|
||||
if (time >= 2000 && currentSeconds == 1) {
|
||||
currentSeconds = 2;
|
||||
onNextSecondThread(currentSeconds, true);
|
||||
}
|
||||
if (time >= 3000 && currentSeconds == 2) {
|
||||
currentSeconds = 3;
|
||||
running.set(false);
|
||||
game.countdownFinished();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void start() {
|
||||
reset();
|
||||
running.set(true);
|
||||
soundStream = soundManager.playSound(soundManager.countdownSoundSingle);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
running.set(false);
|
||||
if (soundStream != null)
|
||||
soundManager.stopSound(soundStream);
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
time = 0;
|
||||
currentSeconds = 0;
|
||||
onNextSecondThread(0, false);
|
||||
}
|
||||
|
||||
private void onNextSecondThread(final int second, final boolean playSound) {
|
||||
if (playSound) {
|
||||
if (second == 2)
|
||||
soundStream = soundManager.playSound(soundManager.countdownSoundLast);
|
||||
else
|
||||
soundStream = soundManager.playSound(soundManager.countdownSoundSingle);
|
||||
}
|
||||
super.setTexture(texture1);
|
||||
if (second == 1)
|
||||
super.setTexture(texture2);
|
||||
else if (second == 2)
|
||||
super.setTexture(texture3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return running.get();
|
||||
}
|
||||
}
|
@ -19,6 +19,7 @@ public class TexturePack {
|
||||
public final Texture playerArrow;
|
||||
public final Texture star;
|
||||
public final Texture energy;
|
||||
public final Texture countdown3, countdown2, countdown1;
|
||||
|
||||
public TexturePack(Context context) {
|
||||
loader = new TextureLoader(context);
|
||||
@ -28,6 +29,10 @@ public class TexturePack {
|
||||
star = loadTexture(R.drawable.currency_star);
|
||||
energy = loadAtlas(R.drawable.currency_energy_atlas, 2, 2);
|
||||
|
||||
countdown3 = loadTexture(R.drawable.countdown_3);
|
||||
countdown2 = loadTexture(R.drawable.countdown_2);
|
||||
countdown1 = loadTexture(R.drawable.countdown_1);
|
||||
|
||||
PlayerShape.loadAllTextures(this);
|
||||
ToolType.loadAllToolTextures(this);
|
||||
World.loadAllSpecificTextures(this);
|
||||
|
@ -29,6 +29,7 @@ import de.frajul.endlessroll.main.screens.GameScreen;
|
||||
import de.frajul.endlessroll.main.screens.Screen;
|
||||
import de.frajul.endlessroll.rendering.Rendering;
|
||||
import de.frajul.endlessroll.sqlDatabase.MyDatabase;
|
||||
import de.frajul.endlessroll.entities.Countdown;
|
||||
import de.frajul.endlessroll.views.ToolButton;
|
||||
import de.frajul.endlessroll.views.ToolButtonBar;
|
||||
import de.frajul.endlessroll.views.ViewManager;
|
||||
@ -44,6 +45,7 @@ public class Game extends Rendering<GameScene> {
|
||||
private LevelPack levelPack;
|
||||
private ParticleSystem particleSystem;
|
||||
private Firework firework;
|
||||
private Countdown countdown;
|
||||
|
||||
private ToolType currentTool;
|
||||
private Player player;
|
||||
@ -74,6 +76,8 @@ public class Game extends Rendering<GameScene> {
|
||||
if (isFirstTime) {
|
||||
scene = new GameScene(gameActivity, texturePack, particleSystem);
|
||||
firework = new Firework(particleSystem.firework, scene.getCamera());
|
||||
countdown = new Countdown(this, gameActivity.getSoundManager(), texturePack);
|
||||
scene.getGuis().add(countdown);
|
||||
if (level != null)
|
||||
startGame(levelPack, level);
|
||||
} else {
|
||||
@ -108,7 +112,7 @@ public class Game extends Rendering<GameScene> {
|
||||
viewManager.setShowFps(gameActivity.getDataStorageHandler().readIsShowFps());
|
||||
viewManager
|
||||
.setBoostPerformance(gameActivity.getDataStorageHandler().readIsPerformanceBoost());
|
||||
viewManager.startCountdown();
|
||||
countdown.start();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
onException(e);
|
||||
@ -155,7 +159,7 @@ public class Game extends Rendering<GameScene> {
|
||||
collisionManager.update(physics, scene, timer);
|
||||
break;
|
||||
case COUNTDOWN:
|
||||
viewManager.updateCountdown(timer.getFrameTimeSeconds());
|
||||
countdown.update(timer.getFrameTimeSeconds());
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -210,7 +214,7 @@ public class Game extends Rendering<GameScene> {
|
||||
viewManager.setShowFps(gameActivity.getDataStorageHandler().readIsShowFps());
|
||||
viewManager
|
||||
.setBoostPerformance(gameActivity.getDataStorageHandler().readIsPerformanceBoost());
|
||||
viewManager.startCountdown();
|
||||
countdown.start();
|
||||
}
|
||||
|
||||
public void startNextLevel() {
|
||||
@ -251,7 +255,7 @@ public class Game extends Rendering<GameScene> {
|
||||
gameActivity.getSoundManager().getCurrentGameMusic().pause();
|
||||
viewManager.showShortMenu();
|
||||
if (gameState == GameState.COUNTDOWN)
|
||||
viewManager.stopCountdown();
|
||||
countdown.stop();
|
||||
gameState = GameState.PAUSED;
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,7 @@ public abstract class Scene {
|
||||
protected final List<Obstacle> obstacles = Collections.synchronizedList(new ArrayList<Obstacle>());
|
||||
protected final List<Tool> tools = Collections.synchronizedList(new ArrayList<Tool>());
|
||||
protected Collectables collectables = new Collectables();
|
||||
protected final List<Entity> guis = Collections.synchronizedList(new ArrayList<Entity>());
|
||||
|
||||
public Scene(GameActivity gameActivity, TexturePack texturePack, ParticleSystem particleSystem) {
|
||||
this.gameActivity = gameActivity;
|
||||
@ -192,6 +193,10 @@ public abstract class Scene {
|
||||
return collectables;
|
||||
}
|
||||
|
||||
public synchronized List<Entity> getGuis() {
|
||||
return guis;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.frajul.endlessroll.main.screens;
|
||||
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.main.GameActivity;
|
||||
@ -13,6 +14,8 @@ public class PreStartScreen extends Screen<RelativeLayout> {
|
||||
|
||||
public PreStartScreen(GameActivity gameActivity) {
|
||||
super(ScreenType.PRE_START, gameActivity, R.layout.pre_start_screen);
|
||||
TextView textView = (TextView) layout.findViewById(R.id.pre_start_screen_text);
|
||||
textView.setTypeface(gameActivity.getTypeface());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -18,6 +18,18 @@ public class MatrixCreator {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public float[] createGuiModelViewProjectionMatrix() {
|
||||
float[] mvpMatrix = new float[16];
|
||||
float[] projectionMatrix = new float[16];
|
||||
float[] viewMatrix = new float[16];
|
||||
|
||||
float ratio = width / height;
|
||||
Matrix.frustumM(projectionMatrix, 0, -ratio, ratio, -1, 1, 1, 2);
|
||||
Matrix.setLookAtM(viewMatrix, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0);
|
||||
Matrix.multiplyMM(mvpMatrix, 0, projectionMatrix, 0, viewMatrix, 0);
|
||||
return mvpMatrix;
|
||||
}
|
||||
|
||||
public float[] createModelViewProjectionMatrix(Camera camera) {
|
||||
float[] mvpMatrix = new float[16];
|
||||
float[] projectionMatrix = new float[16];
|
||||
|
@ -24,6 +24,7 @@ import de.frajul.endlessroll.rendering.MatrixCreator;
|
||||
import de.frajul.endlessroll.rendering.Quad;
|
||||
import de.frajul.endlessroll.rendering.Rendering;
|
||||
import de.frajul.endlessroll.rendering.shader.EntityShader;
|
||||
import de.frajul.endlessroll.rendering.shader.GuiShader;
|
||||
import de.frajul.endlessroll.rendering.shader.ObstacleShader;
|
||||
import de.frajul.endlessroll.rendering.shader.SimpleShader;
|
||||
import de.frajul.endlessroll.rendering.shader.TerrainShader;
|
||||
@ -46,6 +47,7 @@ public class GameRenderer implements GLSurfaceView.Renderer {
|
||||
private ObstacleShader obstacleShader;
|
||||
private TerrainShader terrainShader;
|
||||
private SimpleShader simpleShader;
|
||||
private GuiShader guiShader;
|
||||
|
||||
private TexturePack texturePack;
|
||||
private Timer timer;
|
||||
@ -78,6 +80,7 @@ public class GameRenderer implements GLSurfaceView.Renderer {
|
||||
obstacleShader = new ObstacleShader(activity);
|
||||
terrainShader = new TerrainShader(activity);
|
||||
simpleShader = new SimpleShader(activity);
|
||||
guiShader = new GuiShader(activity);
|
||||
texturePack = new TexturePack(activity);
|
||||
timer = new Timer();
|
||||
} catch (Exception e) {
|
||||
@ -122,17 +125,39 @@ public class GameRenderer implements GLSurfaceView.Renderer {
|
||||
renderEntityList(gl, scene.getUncategorizedEntities(), scene.getCamera());
|
||||
|
||||
renderFbo(gl);
|
||||
|
||||
renderGuis(gl, scene.getGuis());
|
||||
}
|
||||
}
|
||||
|
||||
private void renderGuis(GL10 gl, List<Entity> guis) {
|
||||
guiShader.start();
|
||||
guiShader.loadMVPMatrix(matrixCreator);
|
||||
synchronized (guis) {
|
||||
for (Entity gui : guis)
|
||||
renderGui(gl, gui);
|
||||
}
|
||||
guiShader.stop();
|
||||
}
|
||||
|
||||
private void renderGui(GL10 gl, Entity gui) {
|
||||
if (!gui.isVisible())
|
||||
return;
|
||||
|
||||
gl.glActiveTexture(GL10.GL_TEXTURE0);
|
||||
gl.glBindTexture(GL10.GL_TEXTURE_2D, gui.getTexture().getId());
|
||||
guiShader.loadTransformationMatrix(matrixCreator, gui);
|
||||
quad.draw();
|
||||
}
|
||||
|
||||
private void renderBackground(GL10 gl, Scene scene) {
|
||||
entityShader.start();
|
||||
entityShader.loadMVPMatrix(matrixCreator, scene.getCamera());
|
||||
List<BackgroundLayer> layers = scene.getBackground().getLayers();
|
||||
synchronized (layers) {
|
||||
for(BackgroundLayer layer : layers){
|
||||
synchronized (layer){
|
||||
for(Entity backgroundPart : layer)
|
||||
for (BackgroundLayer layer : layers) {
|
||||
synchronized (layer) {
|
||||
for (Entity backgroundPart : layer)
|
||||
renderEntity(gl, backgroundPart);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
package de.frajul.endlessroll.rendering.shader;
|
||||
|
||||
import android.content.Context;
|
||||
import android.opengl.GLES20;
|
||||
|
||||
import de.frajul.endlessroll.entities.Entity;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
import de.frajul.endlessroll.main.game.Camera;
|
||||
import de.frajul.endlessroll.rendering.MatrixCreator;
|
||||
|
||||
/**
|
||||
* Created by Julian on 10.08.2016.
|
||||
*/
|
||||
public class GuiShader extends ShaderProgram {
|
||||
|
||||
private int location_mvpMatrix;
|
||||
private int location_transformationMatrix;
|
||||
|
||||
public GuiShader(Context context) throws Exception {
|
||||
super(context, "shader/guiVertexShader.glsl", "shader/simpleFragmentShader.glsl");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadUniformLocations() {
|
||||
location_mvpMatrix = super.getUniformLocation("mvpMatrix");
|
||||
location_transformationMatrix = super.getUniformLocation("transformationMatrix");
|
||||
}
|
||||
|
||||
public void loadMVPMatrix(MatrixCreator matrixCreator) {
|
||||
float[] mvpMatrix = matrixCreator.createGuiModelViewProjectionMatrix();
|
||||
GLES20.glUniformMatrix4fv(location_mvpMatrix, 1, false, mvpMatrix, 0);
|
||||
}
|
||||
|
||||
public void loadTransformationMatrix(MatrixCreator matrixCreator, Entity entity) {
|
||||
float[] transformationMatrix = matrixCreator.createTransformationMatrix(entity);
|
||||
GLES20.glUniformMatrix4fv(location_transformationMatrix, 1, false, transformationMatrix, 0);
|
||||
}
|
||||
|
||||
}
|
@ -1,106 +0,0 @@
|
||||
package de.frajul.endlessroll.views;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.main.GameActivity;
|
||||
import de.frajul.endlessroll.main.GameLog;
|
||||
import de.frajul.endlessroll.main.game.Game;
|
||||
import de.frajul.endlessroll.sounds.SoundStream;
|
||||
|
||||
/**
|
||||
* Created by Julian on 31.07.2016.
|
||||
*/
|
||||
public class Countdown {
|
||||
|
||||
private Game game;
|
||||
private GameActivity gameActivity;
|
||||
private TextView textView;
|
||||
private SoundStream soundStream;
|
||||
|
||||
private AtomicBoolean running;
|
||||
private int currentSeconds = 0;
|
||||
private float time = 0;
|
||||
|
||||
public Countdown(Game game, GameActivity gameActivity, TextView textView) {
|
||||
this.game = game;
|
||||
this.gameActivity = gameActivity;
|
||||
this.textView = textView;
|
||||
this.textView.setTypeface(gameActivity.getTypeface());
|
||||
running = new AtomicBoolean(false);
|
||||
}
|
||||
|
||||
public void update(float delta) {
|
||||
if (running.get()) {
|
||||
time += delta;
|
||||
if (time >= 1000 && currentSeconds == 0) {
|
||||
currentSeconds = 1;
|
||||
onNextSecondInUiThread(currentSeconds, true);
|
||||
|
||||
}
|
||||
if (time >= 2000 && currentSeconds == 1) {
|
||||
currentSeconds = 2;
|
||||
onNextSecondInUiThread(currentSeconds, true);
|
||||
}
|
||||
if (time >= 3000 && currentSeconds == 2) {
|
||||
currentSeconds = 3;
|
||||
gameActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
textView.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
running.set(false);
|
||||
game.countdownFinished();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void start() {
|
||||
reset();
|
||||
running.set(true);
|
||||
textView.setVisibility(View.VISIBLE);
|
||||
soundStream = gameActivity.getSoundManager()
|
||||
.playSound(gameActivity.getSoundManager().countdownSoundSingle);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
textView.setVisibility(View.GONE);
|
||||
running.set(false);
|
||||
if (soundStream != null)
|
||||
gameActivity.getSoundManager().stopSound(soundStream);
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
time = 0;
|
||||
currentSeconds = 0;
|
||||
onNextSecondInUiThread(0, false);
|
||||
}
|
||||
|
||||
private void onNextSecondInUiThread(final int second, final boolean playSound) {
|
||||
gameActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if(playSound){
|
||||
if(second == 2)
|
||||
soundStream = gameActivity.getSoundManager()
|
||||
.playSound(gameActivity.getSoundManager().countdownSoundLast);
|
||||
else
|
||||
soundStream = gameActivity.getSoundManager()
|
||||
.playSound(gameActivity.getSoundManager().countdownSoundSingle);
|
||||
}
|
||||
textView.setText((3 - second) + "");
|
||||
int color = R.color.countdown1;
|
||||
if (second == 1)
|
||||
color = R.color.countdown2;
|
||||
else if (second == 2)
|
||||
color = R.color.countdown3;
|
||||
textView.setTextColor(game.getContext().getResources().getColor(color));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -35,7 +35,6 @@ public class ViewManager implements View.OnClickListener {
|
||||
private GoalMessage goalMessage;
|
||||
public ToolButtonBar toolButtonBar;
|
||||
public ShortMenu shortMenu;
|
||||
private Countdown countdown;
|
||||
|
||||
private boolean showFps = false;
|
||||
private boolean boostPerformance = false;
|
||||
@ -62,8 +61,6 @@ public class ViewManager implements View.OnClickListener {
|
||||
layout.findViewById(R.id.game_game_over_message));
|
||||
goalMessage = new GoalMessage(game, gameScreen, gameActivity,
|
||||
layout.findViewById(R.id.game_goal_message));
|
||||
countdown = new Countdown(game, gameActivity,
|
||||
(TextView) layout.findViewById(R.id.game_countdown));
|
||||
}
|
||||
});
|
||||
pauseButton = (ImageView) layout.findViewById(R.id.game_pausebutton);
|
||||
@ -86,10 +83,6 @@ public class ViewManager implements View.OnClickListener {
|
||||
goalMessage.prepareToBeShown();
|
||||
}
|
||||
|
||||
public void updateCountdown(float delta) {
|
||||
countdown.update(delta);
|
||||
}
|
||||
|
||||
public void showBombErrorMessage(float xPos, float yPos) {
|
||||
for (BombErrorMessage bombErrorMessage : bombErrorMessages) {
|
||||
if (!bombErrorMessage.isAnimationRunning()) {
|
||||
@ -150,14 +143,6 @@ public class ViewManager implements View.OnClickListener {
|
||||
shortMenu.setVisible(false);
|
||||
}
|
||||
|
||||
public void startCountdown() {
|
||||
countdown.start();
|
||||
}
|
||||
|
||||
public void stopCountdown() {
|
||||
countdown.stop();
|
||||
}
|
||||
|
||||
public void update(final boolean gameRunning, final Timer timer, final float playerX) {
|
||||
gameViewHandler.startInUiThread(new Runnable() {
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user