Made toolbuttons opengl rendered

Not clickable yet
Progressbar-filled-animation missing
This commit is contained in:
=
2018-05-10 17:31:26 +02:00
parent 0ec17dfe39
commit 7f7b53b8a0
38 changed files with 1066 additions and 457 deletions

View File

@ -3,30 +3,30 @@ package de.frajul.endlessroll.data;
/**
* Created by Julian on 02.08.2016.
*/
public class Color {
public class Color3f {
private float r, g, b;
public Color() {
public Color3f() {
}
public Color(float r, float g, float b) {
public Color3f(float r, float g, float b) {
this.r = r;
this.g = g;
this.b = b;
}
public Color(Color other) {
public Color3f(Color3f other) {
this.r = other.getR();
this.g = other.getG();
this.b = other.getB();
}
public Color interpolate(float leftValue, float rightValue, Color color2) {
public Color3f interpolate(float leftValue, float rightValue, Color3f color2) {
float r = this.r + (color2.r - this.r) * leftValue;
float g = this.g + (color2.g - this.g) * leftValue;
float b = this.b + (color2.b - this.b) * leftValue;
return new Color(r, g, b);
return new Color3f(r, g, b);
}
private void mul(float a) {
@ -35,7 +35,7 @@ public class Color {
b *= a;
}
private void add(Color other) {
private void add(Color3f other) {
r += other.getR();
g += other.getG();
b += other.getB();

View File

@ -0,0 +1,58 @@
package de.frajul.endlessroll.data;
/**
* Created by Julian on 02.08.2016.
*/
public class Color4f {
private float r, g, b, a;
public Color4f() {
}
public Color4f(float r, float g, float b, float a) {
this.r = r;
this.g = g;
this.b = b;
this.a = a;
}
public Color4f(Color4f other) {
this.r = other.getR();
this.g = other.getG();
this.b = other.getB();
this.a = other.getA();
}
public float getR() {
return r;
}
public void setR(float r) {
this.r = r;
}
public float getG() {
return g;
}
public void setG(float g) {
this.g = g;
}
public float getB() {
return b;
}
public void setB(float b) {
this.b = b;
}
public float getA() {
return a;
}
public void setA(float a) {
this.a = a;
}
}

View File

@ -1,4 +1,4 @@
package de.frajul.endlessroll.entities;
package de.frajul.endlessroll.entities.guis;
import java.util.concurrent.atomic.AtomicBoolean;
@ -13,7 +13,7 @@ import de.frajul.endlessroll.sounds.SoundStream;
/**
* Created by Julian on 31.07.2016.
*/
public class Countdown extends Entity {
public class Countdown extends Gui {
private Game game;
private SoundManager soundManager;

View File

@ -0,0 +1,33 @@
package de.frajul.endlessroll.entities.guis;
import de.frajul.endlessroll.data.Color4f;
import de.frajul.endlessroll.data.Vector;
import de.frajul.endlessroll.entities.Entity;
import de.frajul.endlessroll.entities.textures.Texture;
public class Gui extends Entity {
protected float roundValue = 0;
protected Color4f color = null;
public Gui(Texture texture, Vector position, float width, float height) {
super(texture, position, width, height);
}
public float getRoundValue() {
return roundValue;
}
public void setRoundValue(float roundValue) {
this.roundValue = roundValue;
}
public Color4f getColor() {
return color;
}
public void setColor(Color4f color) {
this.color = color;
}
}

View File

@ -0,0 +1,42 @@
package de.frajul.endlessroll.entities.guis;
import de.frajul.endlessroll.data.Vector;
import de.frajul.endlessroll.entities.textures.Texture;
import de.frajul.endlessroll.main.GameLog;
public class Progressbar extends Gui {
private float maxTime;
private float progress;
public Progressbar(Texture texture, Vector position, float width, float height, float maxTime) {
super(texture, position, width, height);
this.maxTime = maxTime;
}
public void update(float frameTime){
progress += frameTime / maxTime;
if (progress >= 1f)
progress = 1f;
}
public boolean hasFinished(){
return progress == 1;
}
public float getProgress() {
return progress;
}
public void setProgress(float progress) {
this.progress = progress;
}
public float getMaxTime() {
return maxTime;
}
public void setMaxTime(float maxTime) {
this.maxTime = maxTime;
}
}

View File

@ -0,0 +1,127 @@
package de.frajul.endlessroll.entities.guis;
import java.util.concurrent.atomic.AtomicBoolean;
import de.frajul.endlessroll.data.Color4f;
import de.frajul.endlessroll.data.Vector;
import de.frajul.endlessroll.entities.textures.Texture;
import de.frajul.endlessroll.entities.textures.TexturePack;
import de.frajul.endlessroll.entities.tools.ToolSlot;
import de.frajul.endlessroll.entities.tools.ToolType;
import de.frajul.endlessroll.entities.tools.ToolUpgradeType;
import de.frajul.endlessroll.main.game.Game;
public class ToolButton {
private final Color4f LOCKED = new Color4f(0.29f, 0.29f, 0.29f, 0.9f);
private final Color4f ACTIVE_READY = new Color4f(0.25f, 0.89f, 0.17f, 0.9f);
private final Color4f ACTIVE_NOT_READY = new Color4f(0.86f, 0.08f, 0.13f, 0.9f);
private final Color4f INACTIVE_READY = new Color4f(1.0f, 0.95f, 0.0f, 0.9f);
private final Color4f INACTIVE_NOT_READY = new Color4f(0.57f, 0.11f, 0.06f, 0.9f);
private Gui border;
private Gui background;
private Progressbar progressbar;
private Game game;
private ToolType toolType;
private boolean locked;
private AtomicBoolean active;
private Texture toolButtonLockedTexture;
private Texture toolButtonEmptyTexture;
public ToolButton(Vector position, float width, float height, TexturePack texturePack, Game game) {
this.game = game;
active = new AtomicBoolean(false);
toolButtonLockedTexture = texturePack.toolButtonLocked;
toolButtonEmptyTexture = texturePack.toolButtonEmpty;
border = new Gui(texturePack.white, position, width, height);
border.setRoundValue(0.3f);
background = new Gui(null, position, height, height);
progressbar = new Progressbar(texturePack.white, position, height, height, 0);
progressbar.setColor(new Color4f(0.55f, 0.55f, 0.55f, 0.62f));
progressbar.setRoundValue(1);
progressbar.setProgress(0.6f);
}
public void setToolSlot(ToolSlot toolSlot) {
this.toolType = toolSlot.getToolType();
this.locked = toolSlot.isLocked();
if (locked)
background.setTexture(toolButtonLockedTexture);
else if (toolType == null)
background.setTexture(toolButtonEmptyTexture);
else
background.setTexture(toolType.getToolButtonTexture());
if (toolType != null)
progressbar.setMaxTime(toolType.getCurrentUpgradeValue(ToolUpgradeType.COOLDOWN));
if (locked || toolType == null)
border.setColor(LOCKED);
else
border.setColor(INACTIVE_NOT_READY);
}
public void setProgress(float progress) {
progressbar.setProgress(progress);
updateBorderColor();
}
public boolean hasFinishedLoading() {
return progressbar.hasFinished();
}
public void update(float frameTime) {
if (progressbar.hasFinished())
return;
progressbar.update(frameTime);
if (progressbar.hasFinished()) {
if (active.get())
game.onToolButtonFinishedLoading(toolType);
}
updateBorderColor();
}
public synchronized void updateBorderColor() {
if (!locked && toolType != null) {
if (active.get()) {
if (progressbar.hasFinished())
border.setColor(ACTIVE_READY);
else
border.setColor(ACTIVE_NOT_READY);
} else {
if (progressbar.hasFinished())
border.setColor(INACTIVE_READY);
else
border.setColor(INACTIVE_NOT_READY);
}
}
}
public void setActive(boolean active) {
this.active.set(active);
}
public AtomicBoolean getActive() {
return active;
}
public Gui getBorder() {
return border;
}
public Gui getBackground() {
return background;
}
public Progressbar getProgressbar() {
return progressbar;
}
public ToolType getToolType() {
return toolType;
}
}

View File

@ -0,0 +1,75 @@
package de.frajul.endlessroll.entities.guis;
import java.util.ArrayList;
import java.util.List;
import de.frajul.endlessroll.data.Vector;
import de.frajul.endlessroll.entities.textures.TexturePack;
import de.frajul.endlessroll.main.game.Game;
import de.frajul.endlessroll.user.ToolSlotSettings;
import de.frajul.endlessroll.views.ToolButtonView;
public class ToolButtonBar {
private final int BUTTON_COUNT = 4;
private final float BUTTON_HEIGHT = 0.34f;
private final float BUTTON_WIDTH = BUTTON_HEIGHT * 1.17f;
private final float BUTTON_MARGIN = 0.012f;
private List<ToolButton> toolButtons = new ArrayList<>();
public ToolButtonBar(TexturePack texturePack, Game game, ToolSlotSettings toolSlotSettings) {
float buttonWidth = BUTTON_WIDTH + 2 * BUTTON_MARGIN;
float totalWidth = BUTTON_COUNT * buttonWidth;
for (int i = 0; i < BUTTON_COUNT; i++) {
Vector position = new Vector(-totalWidth / 2 + (i + 0.5f) * buttonWidth,
1 - (0.5f * BUTTON_HEIGHT + BUTTON_MARGIN * 2));
ToolButton toolButton = new ToolButton(position, BUTTON_WIDTH, BUTTON_HEIGHT,
texturePack, game);
toolButton.setToolSlot(toolSlotSettings.get(i));
toolButtons.add(toolButton);
}
}
public void update(float frameTime) {
for (ToolButton button : toolButtons)
button.update(frameTime);
}
public void changeToolButtonTypes(ToolSlotSettings toolSlotSettings) {
for (int i = 0; i < 4; i++) {
toolButtons.get(i).setToolSlot(toolSlotSettings.get(i));
}
}
public void reset(ToolSlotSettings toolSlotSettings) {
changeToolButtonTypes(toolSlotSettings);
for (int i = 0; i < 4; i++) {
if (toolSlotSettings.get(i).getToolType() != null) {
toolButtons.get(i).setActive(true);
toolButtons.get(i).updateBorderColor();
break;
}
}
for (ToolButton button : toolButtons)
button.setProgress(1);
}
public ToolButton getActiveButton(){
for(ToolButton button : toolButtons)
if(button.getActive().get())
return button;
return null;
}
public List<Gui> toGuiList() {
List<Gui> list = new ArrayList<>();
for (ToolButton button : toolButtons) {
list.add(button.getBorder());
list.add(button.getBackground());
list.add(button.getProgressbar());
}
return list;
}
}

View File

@ -2,7 +2,7 @@ package de.frajul.endlessroll.entities.particles;
import java.util.Random;
import de.frajul.endlessroll.data.Color;
import de.frajul.endlessroll.data.Color3f;
import de.frajul.endlessroll.data.Vector;
import de.frajul.endlessroll.entities.Entity;
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.Range;
@ -15,7 +15,7 @@ import de.frajul.endlessroll.main.game.Timer;
*/
public class Particle extends Entity {
private Color color;
private Color3f color;
private Random random;
private boolean active;
private float maxLife;
@ -101,11 +101,11 @@ public class Particle extends Entity {
return active;
}
public void setColor(Color color) {
public void setColor(Color3f color) {
this.color = color;
}
public Color getColor() {
public Color3f getColor() {
return color;
}
}

View File

@ -3,7 +3,7 @@ package de.frajul.endlessroll.entities.particles.attributes.attributeValues;
import java.util.ArrayList;
import java.util.List;
import de.frajul.endlessroll.data.Color;
import de.frajul.endlessroll.data.Color3f;
/**
* Created by Julian on 02.08.2016.
@ -30,7 +30,7 @@ public class TintTimeline extends ParticleAttributeValue {
points.get(index).setTime(time);
}
public Color getValueAtTime(float time) {
public Color3f getValueAtTime(float time) {
TintTimelinePoint left = null, right = null;
for (TintTimelinePoint point : points) {
if (point.getTime() <= time) {
@ -51,7 +51,7 @@ public class TintTimeline extends ParticleAttributeValue {
}
return left.getColor();
}
return new Color();
return new Color3f();
}
}

View File

@ -1,11 +1,11 @@
package de.frajul.endlessroll.entities.particles.attributes.attributeValues;
import de.frajul.endlessroll.data.Color;
import de.frajul.endlessroll.data.Color3f;
public class TintTimelinePoint {
private float time;
private Color color;
private Color3f color;
public float getTime() {
return time;
@ -15,13 +15,13 @@ public class TintTimelinePoint {
this.time = time;
}
public Color getColor() {
public Color3f getColor() {
return color;
}
public void setValue(int colorIndex, float value) {
if (color == null)
color = new Color();
color = new Color3f();
if (colorIndex == 0)
color.setR(value);
else if (colorIndex == 1)

View File

@ -14,19 +14,19 @@ import de.frajul.endlessroll.entities.textures.TexturePack;
public enum PlayerShape {
BALL(R.string.playershape_name_ball, R.string.playershape_description_ball,
R.drawable.playershapes_ball, new EmptyTask()),
CLOCK(R.string.playershape_name_clock, R.string.playershape_description_clock,
R.drawable.playershapes_clock, new CollectStarTask(15)),
HYPNO_SPIRAL(R.string.playershape_name_hypno_spiral,
R.string.playershape_description_hypno_spiral, R.drawable.playershapes_hypno_spiral,
new CollectEnergyTask(3)),
PACMAN(R.string.playershape_name_pacman, R.string.playershape_description_pacman,
R.drawable.playershapes_pacman, new CompleteWorldTask(1)),
SMILEY(R.string.playershape_name_smiley, R.string.playershape_description_smiley,
R.drawable.playershapes_smiley, new CollectStarTask(30)),
WHEEL(R.string.playershape_name_wheel, R.string.playershape_description_wheel,
R.drawable.playershapes_wheel, new CollectStarTask(45)),
CLOCK(R.string.playershape_name_clock, R.string.playershape_description_clock,
R.drawable.playershapes_clock, new CollectStarTask(15)),
SUN(R.string.playershape_name_sun, R.string.playershape_description_sun,
R.drawable.playershapes_sun, new CollectEnergyTask(10)),
SMILEY(R.string.playershape_name_smiley, R.string.playershape_description_smiley,
R.drawable.playershapes_smiley, new CollectStarTask(30)),
PACMAN(R.string.playershape_name_pacman, R.string.playershape_description_pacman,
R.drawable.playershapes_pacman, new CompleteWorldTask(1)),
WHEEL(R.string.playershape_name_wheel, R.string.playershape_description_wheel,
R.drawable.playershapes_wheel, new CollectStarTask(45)),
BLUE(R.string.playershape_name_blue, R.string.playershape_description_blue,
R.drawable.jury_playershapes_ball_omg_im_blue, new CompleteWorldTask(2));

View File

@ -15,23 +15,29 @@ public class TexturePack {
private TextureLoader loader;
public final Texture white;
public final Texture goal;
public final Texture playerArrow;
public final Texture star;
public final Texture energy;
public final Texture countdown3, countdown2, countdown1;
public final Texture toolButtonLocked;
public final Texture toolButtonEmpty;
public TexturePack(Context context) {
loader = new TextureLoader(context);
white = loadTexture(R.drawable.white);
goal = loadTexture(R.drawable.guis_goal);
playerArrow = loadTexture(R.drawable.guis_playerarrow);
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);
countdown3 = loadTexture(R.drawable.guis_countdown_3);
countdown2 = loadTexture(R.drawable.guis_countdown_2);
countdown1 = loadTexture(R.drawable.guis_countdown_1);
toolButtonLocked = loadTexture(R.drawable.tools_button_locked);
toolButtonEmpty = loadTexture(R.drawable.tools_button_empty);
PlayerShape.loadAllTextures(this);
ToolType.loadAllToolTextures(this);

View File

@ -52,6 +52,7 @@ public enum ToolType {
private final List<ToolUpgrade> upgrades;
private Texture toolTexture = null;
private Texture toolButtonTexture = null;
private boolean bought;
private int currentUpgradeLevel = 1;
@ -95,8 +96,9 @@ public enum ToolType {
}
public static void loadAllToolTextures(TexturePack texturePack) {
for (ToolType type : values())
for (ToolType type : values()){
type.loadToolTexture(texturePack);
type.loadToolButtonTexture(texturePack);}
}
private void loadToolTexture(TexturePack texturePack) {
@ -108,10 +110,20 @@ public enum ToolType {
toolTexture = texturePack.loadTexture(toolTextureId);
}
private void loadToolButtonTexture(TexturePack texturePack){
if (buttonDrawable == -1)
return;
toolButtonTexture = texturePack.loadTexture(buttonDrawable);
}
public Texture getToolTexture() {
return toolTexture;
}
public Texture getToolButtonTexture() {
return toolButtonTexture;
}
public int getButtonDrawable() {
return buttonDrawable;
}

View File

@ -30,7 +30,6 @@ public class DataStorageHandler {
private final String USER_PLAYER_SHAPE = "PlayerShape";
private final String TOOL_SHOP_TUTORIAL_FINISHED = "ToolShopTutorialFinished";
private final String SHOW_FPS = "ShowFps";
private final String PERFORMANCE_BOOST = "PerformanceBoost";
private SharedPreferences preferences;
private MyDatabase database;
@ -50,16 +49,6 @@ public class DataStorageHandler {
editor.apply();
}
public boolean readIsPerformanceBoost() {
return preferences.getBoolean(PERFORMANCE_BOOST, false);
}
public void writePerformanceBoost(boolean performanceBoost) {
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean(PERFORMANCE_BOOST, performanceBoost);
editor.apply();
}
public boolean readIsSoundsMuted() {
return preferences.getBoolean(SOUNDS_MUTED, false);
}

View File

@ -13,6 +13,8 @@ import de.frajul.endlessroll.entities.Player;
import de.frajul.endlessroll.entities.collectables.Energy;
import de.frajul.endlessroll.entities.collectables.Star;
import de.frajul.endlessroll.entities.collision.CollisionManager;
import de.frajul.endlessroll.entities.guis.ToolButton;
import de.frajul.endlessroll.entities.guis.ToolButtonBar;
import de.frajul.endlessroll.entities.particles.Firework;
import de.frajul.endlessroll.entities.particles.ParticleSystem;
import de.frajul.endlessroll.entities.textures.TexturePack;
@ -29,9 +31,9 @@ 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.entities.guis.Countdown;
import de.frajul.endlessroll.views.ToolButtonView;
import de.frajul.endlessroll.views.ToolButtonBarView;
import de.frajul.endlessroll.views.ViewManager;
/**
@ -46,6 +48,7 @@ public class Game extends Rendering<GameScene> {
private ParticleSystem particleSystem;
private Firework firework;
private Countdown countdown;
private ToolButtonBar toolButtonBar;
private ToolType currentTool;
private Player player;
@ -77,6 +80,8 @@ public class Game extends Rendering<GameScene> {
scene = new GameScene(gameActivity, texturePack, particleSystem);
firework = new Firework(particleSystem.firework, scene.getCamera());
countdown = new Countdown(this, gameActivity.getSoundManager(), texturePack);
toolButtonBar = new ToolButtonBar(texturePack, this, gameActivity.getUser().getToolSlotSettings());
scene.getGuis().addAll(toolButtonBar.toGuiList());
scene.getGuis().add(countdown);
if (level != null)
startGame(levelPack, level);
@ -107,11 +112,10 @@ public class Game extends Rendering<GameScene> {
scene.loadLevel(level, levelPack.getWorld(),
gameActivity.getUser().getCurrentPlayerShape());
player = scene.getPlayer();
viewManager.resetViews(gameActivity.getUser());
setCurrentTool(viewManager.toolButtonBar.getActiveButton().getToolType(), true);
viewManager.resetViews();
toolButtonBar.reset(gameActivity.getUser().getToolSlotSettings());
setCurrentTool(toolButtonBar.getActiveButton().getToolType(), true);
viewManager.setShowFps(gameActivity.getDataStorageHandler().readIsShowFps());
viewManager
.setBoostPerformance(gameActivity.getDataStorageHandler().readIsPerformanceBoost());
countdown.start();
}
} catch (Exception e) {
@ -142,6 +146,8 @@ public class Game extends Rendering<GameScene> {
viewManager.update(gameState == GameState.RUNNING, timer, playerProgress);
switch (gameState) {
case RUNNING:
toolButtonBar.update(timer.getFrameTimeSeconds());
if (player.getPosition().y < -2f) {
onGameOver(false);
return;
@ -170,9 +176,8 @@ public class Game extends Rendering<GameScene> {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (gameState == GameState.RUNNING) {
ToolButtonBar bar = viewManager.toolButtonBar;
ToolButton button = bar.getByToolType(currentTool);
if (button != null && button.finishedLoading() && button.getToolType() != null) {
ToolButton currentToolButton = toolButtonBar.getActiveButton();
if (currentToolButton != null && currentToolButton.hasFinishedLoading() && currentToolButton.getToolType() != null) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (currentTool == ToolType.BOMB) {
try {
@ -183,7 +188,7 @@ public class Game extends Rendering<GameScene> {
viewManager.showBombErrorMessage(event.getX(), event.getY());
return true;
} else {
button.setProgress(0);
currentToolButton.setProgress(0);
scene.getBombSelected().set(false);
Tool tool = addTool(event.getX(), event.getY());
if (tool != null && tool instanceof Bomb)
@ -195,7 +200,7 @@ public class Game extends Rendering<GameScene> {
return true;
}
}
button.setProgress(0);
currentToolButton.setProgress(0);
addTool(event.getX(), event.getY());
}
}
@ -205,15 +210,14 @@ public class Game extends Rendering<GameScene> {
}
public void resetViews() {
viewManager.resetViews(gameActivity.getUser());
viewManager.resetViews();
toolButtonBar.reset(gameActivity.getUser().getToolSlotSettings());
}
public void continueGame() {
viewManager.hideShortMenu();
gameState = GameState.COUNTDOWN;
viewManager.setShowFps(gameActivity.getDataStorageHandler().readIsShowFps());
viewManager
.setBoostPerformance(gameActivity.getDataStorageHandler().readIsPerformanceBoost());
countdown.start();
}

View File

@ -14,6 +14,7 @@ import de.frajul.endlessroll.entities.Entity;
import de.frajul.endlessroll.entities.Obstacle;
import de.frajul.endlessroll.entities.Player;
import de.frajul.endlessroll.entities.collectables.Collectables;
import de.frajul.endlessroll.entities.guis.Gui;
import de.frajul.endlessroll.entities.particles.ParticleSource;
import de.frajul.endlessroll.entities.particles.ParticleSystem;
import de.frajul.endlessroll.entities.textures.TexturePack;
@ -51,7 +52,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>());
protected final List<Gui> guis = Collections.synchronizedList(new ArrayList<Gui>());
public Scene(GameActivity gameActivity, TexturePack texturePack, ParticleSystem particleSystem) {
this.gameActivity = gameActivity;
@ -193,7 +194,7 @@ public abstract class Scene {
return collectables;
}
public synchronized List<Entity> getGuis() {
public synchronized List<Gui> getGuis() {
return guis;
}

View File

@ -2,21 +2,29 @@ package de.frajul.endlessroll.main.game;
import de.frajul.endlessroll.data.Vector;
import de.frajul.endlessroll.entities.Entity;
import de.frajul.endlessroll.entities.guis.ToolButtonBar;
import de.frajul.endlessroll.entities.particles.ParticleSystem;
import de.frajul.endlessroll.entities.shapes.PlayerShape;
import de.frajul.endlessroll.entities.textures.TexturePack;
import de.frajul.endlessroll.levels.worlds.World;
import de.frajul.endlessroll.main.GameActivity;
import de.frajul.endlessroll.user.ToolSlotSettings;
public class TestScreenScene extends Scene {
public TestScreenScene(GameActivity gameActivity, TexturePack texturePack, ParticleSystem particleSystem) {
super(gameActivity, texturePack, particleSystem);
// terrain.createEndless(World.GRASSLANDS, 0.6f);
// background.changeTextures(World.ICY_MOUNTAINS.getBackgroundTexture());
//
// player.init(PlayerShape.BALL, 0.6f, 0.5f, 0.5f, particleSystem);
// uncategorizedEntities.add(player);
uncategorizedEntities.add(new Entity(World.GRASSLANDS.getBackgroundTextures().get(0), new Vector(), 1, 1));
// terrain.createEndless(World.GRASSLANDS, 0.6f);
// background.changeTextures(World.ICY_MOUNTAINS.getBackgroundTexture());
//
// player.init(PlayerShape.BALL, 0.6f, 0.5f, 0.5f, particleSystem);
// uncategorizedEntities.add(player);
uncategorizedEntities
.add(new Entity(World.GRASSLANDS.getBackgroundTextures().get(0), new Vector(), 1,
1));
try {
guis.addAll(new ToolButtonBar(texturePack, null,
new ToolSlotSettings("RAMP", "STASIS", "BOMB", "MAGNET", 1)).toGuiList());
} catch (Exception ignore) {
}
}
}

View File

@ -27,7 +27,6 @@ public class SettingsScreen extends Screen<LinearLayout> implements View.OnClick
private ToggleButton musicToggle;
private ToggleButton soundToggle;
private CheckBox fpsCheckbox;
private CheckBox performanceCheckbox;
private Button creditsButton;
private Button resetButton;
@ -45,8 +44,6 @@ public class SettingsScreen extends Screen<LinearLayout> implements View.OnClick
soundToggle.setOnClickListener(this);
fpsCheckbox = (CheckBox) layout.findViewById(R.id.settings_fps_checkbox);
fpsCheckbox.setTypeface(gameActivity.getTypeface());
performanceCheckbox = (CheckBox) layout.findViewById(R.id.settings_performance_checkbox);
performanceCheckbox.setTypeface(gameActivity.getTypeface());
creditsButton = (Button) layout.findViewById(R.id.settings_credits);
creditsButton.setOnClickListener(this);
resetButton = (Button) layout.findViewById(R.id.settings_reset);
@ -72,8 +69,6 @@ public class SettingsScreen extends Screen<LinearLayout> implements View.OnClick
musicToggle.setChecked(!gameActivity.getSoundManager().isMusicMuted());
soundToggle.setChecked(!gameActivity.getSoundManager().isSoundsMuted());
fpsCheckbox.setChecked(gameActivity.getDataStorageHandler().readIsShowFps());
performanceCheckbox
.setChecked(gameActivity.getDataStorageHandler().readIsPerformanceBoost());
resetButton.setEnabled(super.caller != ScreenType.GAME);
}
@ -84,7 +79,6 @@ public class SettingsScreen extends Screen<LinearLayout> implements View.OnClick
gameActivity.getDataStorageHandler()
.writeMusicMuted(gameActivity.getSoundManager().isMusicMuted());
gameActivity.getDataStorageHandler().writeShowFps(fpsCheckbox.isChecked());
gameActivity.getDataStorageHandler().writePerformanceBoost(performanceCheckbox.isChecked());
flipToCaller();
}

View File

@ -12,6 +12,8 @@ import javax.microedition.khronos.opengles.GL10;
import de.frajul.endlessroll.entities.BackgroundLayer;
import de.frajul.endlessroll.entities.Entity;
import de.frajul.endlessroll.entities.Obstacle;
import de.frajul.endlessroll.entities.guis.Gui;
import de.frajul.endlessroll.entities.guis.Progressbar;
import de.frajul.endlessroll.entities.textures.TexturePack;
import de.frajul.endlessroll.entities.tileLists.Tile;
import de.frajul.endlessroll.entities.tileLists.TileList;
@ -130,23 +132,29 @@ public class GameRenderer implements GLSurfaceView.Renderer {
}
}
private void renderGuis(GL10 gl, List<Entity> guis) {
private void renderGuis(GL10 gl, List<Gui> guis) {
guiShader.start();
guiShader.loadMVPMatrix(matrixCreator);
synchronized (guis) {
for (Entity gui : guis)
for (Gui gui : guis)
renderGui(gl, gui);
}
guiShader.stop();
}
private void renderGui(GL10 gl, Entity gui) {
private void renderGui(GL10 gl, Gui gui) {
if (!gui.isVisible())
return;
gl.glActiveTexture(GL10.GL_TEXTURE0);
gl.glBindTexture(GL10.GL_TEXTURE_2D, gui.getTexture().getId());
guiShader.loadTransformationMatrix(matrixCreator, gui);
guiShader.loadCustomColor(gui.getColor());
guiShader.loadRoundValue(gui.getRoundValue());
if (gui instanceof Progressbar)
guiShader.loadVisibleAmount(((Progressbar) gui).getProgress());
else
guiShader.loadVisibleAmount(0);
quad.draw();
}

View File

@ -3,9 +3,8 @@ package de.frajul.endlessroll.rendering.shader;
import android.content.Context;
import android.opengl.GLES20;
import de.frajul.endlessroll.data.Color4f;
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;
/**
@ -15,15 +14,23 @@ public class GuiShader extends ShaderProgram {
private int location_mvpMatrix;
private int location_transformationMatrix;
private int location_useCustomColor;
private int location_color;
private int location_roundValue;
private int location_visibleAmount;
public GuiShader(Context context) throws Exception {
super(context, "shader/guiVertexShader.glsl", "shader/simpleFragmentShader.glsl");
super(context, "shader/guiVertexShader.glsl", "shader/guiFragmentShader.glsl");
}
@Override
protected void loadUniformLocations() {
location_mvpMatrix = super.getUniformLocation("mvpMatrix");
location_transformationMatrix = super.getUniformLocation("transformationMatrix");
location_useCustomColor = super.getUniformLocation("useCustomColor");
location_color = super.getUniformLocation("color");
location_roundValue = super.getUniformLocation("roundValue");
location_visibleAmount = super.getUniformLocation("visibleAmount");
}
public void loadMVPMatrix(MatrixCreator matrixCreator) {
@ -36,4 +43,19 @@ public class GuiShader extends ShaderProgram {
GLES20.glUniformMatrix4fv(location_transformationMatrix, 1, false, transformationMatrix, 0);
}
public void loadCustomColor(Color4f color) {
GLES20.glUniform1f(location_useCustomColor, color == null ? 0 : 1);
if (color != null)
GLES20.glUniform4f(location_color, color.getR(), color.getG(), color.getB(),
color.getA());
}
public void loadRoundValue(float roundValue) {
GLES20.glUniform1f(location_roundValue, roundValue);
}
public void loadVisibleAmount(float visibleAmount) {
GLES20.glUniform1f(location_visibleAmount, visibleAmount);
}
}

View File

@ -3,7 +3,7 @@ package de.frajul.endlessroll.rendering.shader;
import android.content.Context;
import android.opengl.GLES20;
import de.frajul.endlessroll.data.Color;
import de.frajul.endlessroll.data.Color3f;
import de.frajul.endlessroll.entities.Entity;
import de.frajul.endlessroll.main.game.Camera;
import de.frajul.endlessroll.rendering.MatrixCreator;
@ -44,7 +44,7 @@ public class ParticleShader extends ShaderProgram {
GLES20.glUniform1f(location_alpha, alpha);
}
public void loadColor(Color color) {
public void loadColor(Color3f color) {
GLES20.glUniform3f(location_color, color.getR(), color.getG(), color.getB());
}

View File

@ -2,8 +2,6 @@ package de.frajul.endlessroll.views;
import android.content.Context;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
@ -12,7 +10,6 @@ import java.util.List;
import de.frajul.endlessroll.R;
import de.frajul.endlessroll.entities.tools.ToolType;
import de.frajul.endlessroll.main.GameLog;
import de.frajul.endlessroll.main.game.Game;
import de.frajul.endlessroll.main.game.GameState;
import de.frajul.endlessroll.user.ToolSlotSettings;
@ -20,17 +17,17 @@ import de.frajul.endlessroll.user.ToolSlotSettings;
/**
* Created by Julian on 16.01.2016.
*/
public class ToolButtonBar implements View.OnClickListener{
public class ToolButtonBarView implements View.OnClickListener{
private Game game;
private List<ToolButton> buttons = new ArrayList<>(4);
private List<ToolButtonView> buttons = new ArrayList<>(4);
private RelativeLayout button1;
private RelativeLayout button2;
private RelativeLayout button3;
private RelativeLayout button4;
public ToolButtonBar(Game game, ToolSlotSettings toolSlotSettings, LinearLayout layout1) {
public ToolButtonBarView(Game game, ToolSlotSettings toolSlotSettings, LinearLayout layout1) {
this.game = game;
Context context = game.getContext();
@ -42,10 +39,10 @@ public class ToolButtonBar implements View.OnClickListener{
button3.setOnClickListener(this);
button4 = (RelativeLayout) layout1.findViewById(R.id.toolbutton_4);
button4.setOnClickListener(this);
buttons.add(new ToolButton(toolSlotSettings.get(0), game, context, button1));
buttons.add(new ToolButton(toolSlotSettings.get(1), game, context, button2));
buttons.add(new ToolButton(toolSlotSettings.get(2), game, context, button3));
buttons.add(new ToolButton(toolSlotSettings.get(3), game, context, button4));
buttons.add(new ToolButtonView(toolSlotSettings.get(0), game, context, button1));
buttons.add(new ToolButtonView(toolSlotSettings.get(1), game, context, button2));
buttons.add(new ToolButtonView(toolSlotSettings.get(2), game, context, button3));
buttons.add(new ToolButtonView(toolSlotSettings.get(3), game, context, button4));
}
public void changeToolButtonTypes(ToolSlotSettings toolSlotSettings) {
@ -62,34 +59,34 @@ public class ToolButtonBar implements View.OnClickListener{
break;
}
}
for (ToolButton button : buttons)
for (ToolButtonView button : buttons)
button.setProgress(100);
}
public void update(float frameTime, boolean showAnimation) {
for (ToolButton button : buttons)
for (ToolButtonView button : buttons)
button.update(frameTime, showAnimation);
}
public void setActive(ToolType activeType) {
for (ToolButton button : buttons)
for (ToolButtonView button : buttons)
button.setActive(button.getToolType() == activeType);
}
private void setActive(int index) {
for (ToolButton button : buttons)
for (ToolButtonView button : buttons)
button.setActive(buttons.indexOf(button) == index);
}
public ToolButton getByToolType(ToolType type) {
for (ToolButton button : buttons)
public ToolButtonView getByToolType(ToolType type) {
for (ToolButtonView button : buttons)
if (button.getToolType() == type)
return button;
return null;
}
public ToolButton getActiveButton() {
for (ToolButton button : buttons)
public ToolButtonView getActiveButton() {
for (ToolButtonView button : buttons)
if (button.isActive())
return button;
return null;
@ -98,7 +95,7 @@ public class ToolButtonBar implements View.OnClickListener{
@Override
public void onClick(View v) {
if (game.getGameState() == GameState.RUNNING) {
ToolButton clickedButton = null;
ToolButtonView clickedButton = null;
if (v.equals(button1) && !buttons.get(0).isLocked()) {
clickedButton = buttons.get(0);
} else if (v.equals(button2) && !buttons.get(1).isLocked()) {

View File

@ -18,7 +18,7 @@ import de.frajul.endlessroll.main.game.Game;
/**
* Created by Julian on 15.01.2016.
*/
public class ToolButton {
public class ToolButtonView {
private Game game;
private boolean locked;
@ -33,7 +33,7 @@ public class ToolButton {
private ImageView animationView;
private Animation scaleAnimation;
public ToolButton(ToolSlot slot, Game game, Context context, RelativeLayout layout) {
public ToolButtonView(ToolSlot slot, Game game, Context context, RelativeLayout layout) {
this.context = context;
this.game = game;
this.layout = layout;

View File

@ -33,11 +33,9 @@ public class ViewManager implements View.OnClickListener {
private ImageView pauseButton;
private GameOverMessage gameOverMessage;
private GoalMessage goalMessage;
public ToolButtonBar toolButtonBar;
public ShortMenu shortMenu;
private boolean showFps = false;
private boolean boostPerformance = false;
private List<BombErrorMessage> bombErrorMessages = new ArrayList<>();
@ -52,9 +50,6 @@ public class ViewManager implements View.OnClickListener {
gameViewHandler.startInUiThread(new Runnable() {
@Override
public void run() {
toolButtonBar = new ToolButtonBar(game,
gameActivity.getUser().getToolSlotSettings(),
(LinearLayout) layout.findViewById(R.id.game_toolbuttonbar));
shortMenu = new ShortMenu(game, gameScreen, gameActivity,
layout.findViewById(R.id.game_shortmenu));
gameOverMessage = new GameOverMessage(game, gameScreen, gameActivity,
@ -101,12 +96,10 @@ public class ViewManager implements View.OnClickListener {
game.tryToPause();
}
public void resetViews(final User user) {
public void resetViews() {
gameViewHandler.startInUiThread(new Runnable() {
@Override
public void run() {
toolButtonBar.reset(user.getToolSlotSettings());
toolButtonBar.update(0, false);
playerProgress.setText(R.string.game_playerprogress_placeholder);
}
});
@ -151,7 +144,6 @@ public class ViewManager implements View.OnClickListener {
fpsView.setText(String.format(fpsFormat, timer.getFps()));
if (gameRunning) {
playerProgress.setText(String.format(playerProgressFormat, toMeters(playerX)));
toolButtonBar.update(timer.getFrameTimeSeconds(), !boostPerformance);
}
}
});
@ -170,7 +162,4 @@ public class ViewManager implements View.OnClickListener {
this.showFps = showFps;
}
public void setBoostPerformance(boolean boostPerformance) {
this.boostPerformance = boostPerformance;
}
}