Introduced scalable obstacles, even though the texture could be polished a bit more

This commit is contained in:
=
2017-08-04 17:34:38 +02:00
parent 0437b0178e
commit 472c36aec7
22 changed files with 2026 additions and 1598 deletions

View File

@ -0,0 +1,101 @@
package de.frajul.endlessroll.entities;
import java.util.Random;
import de.frajul.endlessroll.data.Vector;
import de.frajul.endlessroll.entities.textures.Texture;
import de.frajul.endlessroll.levels.MoveComponent;
import de.frajul.endlessroll.levels.ObstacleData;
import de.frajul.endlessroll.levels.worlds.World;
/**
* Created by Julian on 20.11.2015.
*/
public class Obstacle extends Entity {
private boolean deadly;
private boolean floating;
private boolean moving;
private final float GRID_SQUARE_SIZE = 0.1f;
private Vector gridSize;
private MoveComponent moveComponent;
private Vertex zeroPoint;
private boolean clockwise;
private float totalMoveDistance;
private float moveProgress;
public Obstacle(World world, ObstacleData data, float terrainEdge) {
super(world.getObstacleTexture(), new Vector(data.getX(), data.getY()), data.getWidth(), data.getHeight());
this.deadly = data.isDeadly();
this.floating = data.isFloating();
this.moving = data.isMoving();
this.moveComponent = data.getMoveComponent();
if (moveComponent != null)
moveComponent.shrink(new Vector(super.getWidth(), super.getHeight()));
if (!floating)
super.setToTerrain(terrainEdge);
if (moving)
randomMovementData();
gridSize = calcGridSize();
}
private Vector calcGridSize(){
int gridWidth = (int) (width / GRID_SQUARE_SIZE);
int gridHeight = (int) (height / GRID_SQUARE_SIZE);
gridWidth = Math.max(gridWidth, 2);
gridHeight = Math.max(gridHeight, 2);
return new Vector(gridWidth, gridHeight);
}
public void moveWithMoveComponent(float value) {
float distance = value * moveComponent.getSpeed() * 0.001f;
moveProgress += distance / totalMoveDistance;
moveProgress %= 1.0f;
setPositionForMoveProgress();
}
private void setPositionForMoveProgress() {
float distance = 0;
Vertex lastVertex = zeroPoint;
while (true) {
Vertex nextVertex = lastVertex.getNext(clockwise);
float nextDistance = distance + (Math.abs(lastVertex.getX() - nextVertex.getX()) * 0.5f * moveComponent.getWidth()) + (Math.abs(lastVertex.getY() - nextVertex.getY()) * 0.5f * moveComponent.getHeight());
if (nextDistance >= moveProgress * totalMoveDistance) {
float distanceLeft = moveProgress * totalMoveDistance - distance;
Vector direction = new Vector(nextVertex.getX(), nextVertex.getY()).translate(new Vector(lastVertex.getX(), lastVertex.getY()).negate());
direction = direction.mul(0.5f * distanceLeft);
super.setPosition(moveComponent.getPositionOfVertex(lastVertex).translate(direction));
return;
}
distance = nextDistance;
lastVertex = nextVertex;
}
}
private void randomMovementData() {
Random random = new Random();
int index = random.nextInt(4);
zeroPoint = Vertex.values()[index];
clockwise = random.nextBoolean();
totalMoveDistance = moveComponent.getWidth() * 2 + moveComponent.getHeight() * 2;
}
public boolean isMoving() {
return moving;
}
public boolean isDeadly() {
return deadly;
}
public boolean isFloating() {
return floating;
}
public Vector getGridSize(){
return gridSize;
}
}

View File

@ -0,0 +1,37 @@
package de.frajul.endlessroll.main.game;
import de.frajul.endlessroll.entities.Entity;
import de.frajul.endlessroll.entities.Obstacle;
import de.frajul.endlessroll.entities.particles.ParticleSystem;
import de.frajul.endlessroll.entities.textures.TexturePack;
import de.frajul.endlessroll.levels.ObstacleData;
import de.frajul.endlessroll.levels.worlds.World;
public class TestScreenScene extends Scene {
private Obstacle testObstacle;
public TestScreenScene(TexturePack texturePack, ParticleSystem particleSystem) {
super(texturePack, particleSystem);
terrain.createEndless(World.ICY_MOUNTAINS, -.8f);
testObstacle = createObstacle(-1f, 1.139f, 0, 0.217f, true, false);
obstacles.add(testObstacle);
obstacles.add(createObstacle(-1f, 1.139f, 0, 0.217f, false, false));
}
private Obstacle createObstacle(float leftEdge, float rightEdge, float y, float height, boolean floating, boolean deadly){
ObstacleData data = new ObstacleData();
data.setLeftEdge(leftEdge);
data.setRightEdge(rightEdge);
data.setY(y);
data.setHeight(height);
data.setFloating(floating);
data.setDeadly(deadly);
return new Obstacle(World.GRASSLANDS, data, -.8f);
}
@Override
protected void removeEntityFromAllLists(Entity entity) {
}
}

View File

@ -0,0 +1,34 @@
package de.frajul.endlessroll.main.screens;
import android.support.annotation.LayoutRes;
import android.widget.RelativeLayout;
import de.frajul.endlessroll.R;
import de.frajul.endlessroll.main.GameActivity;
import de.frajul.endlessroll.main.MyGlSurfaceView;
import de.frajul.endlessroll.rendering.Rendering;
/**
* Created by Julian on 03.08.2017.
*/
public class GLTestScreen extends GLScreen<RelativeLayout> {
private Rendering rendering;
public GLTestScreen(GameActivity gameActivity, MyGlSurfaceView glView) throws Exception{
super(ScreenType.GL_TEST, gameActivity, R.layout.gl_test_screen, glView);
rendering = new TestScreenRendering(gameActivity);
glView.addRendering(rendering);
}
@Override
public void prepareToBeShown() {
glView.setCurrentRendering(rendering);
}
@Override
public void onBackKeyDown() {
gameActivity.flipToScreen(ScreenType.START);
}
}

View File

@ -0,0 +1,57 @@
package de.frajul.endlessroll.main.screens;
import android.view.MotionEvent;
import android.view.View;
import de.frajul.endlessroll.entities.particles.ParticleSystem;
import de.frajul.endlessroll.entities.textures.TexturePack;
import de.frajul.endlessroll.main.GameActivity;
import de.frajul.endlessroll.main.GameLog;
import de.frajul.endlessroll.main.game.Game;
import de.frajul.endlessroll.main.game.TestScreenScene;
import de.frajul.endlessroll.main.game.Timer;
import de.frajul.endlessroll.rendering.Rendering;
/**
* Created by Julian on 20.07.2016.
*/
public class TestScreenRendering extends Rendering<TestScreenScene> {
private Timer timer;
private ParticleSystem particleSystem;
public TestScreenRendering(GameActivity gameActivity) throws Exception{
super(gameActivity);
particleSystem = new ParticleSystem(gameActivity);
}
@Override
public TestScreenScene init(TexturePack texturePack, Timer timer, boolean isFirstTime) {
this.timer = timer;
try {
if (isFirstTime)
scene = new TestScreenScene(texturePack, particleSystem);
else
scene.setTexturePack(texturePack);
}catch (Exception e){
GameLog.e(e);
}
try {
particleSystem.loadTextures();
} catch (Exception e) {
}
return scene;
}
@Override
public void update() {
particleSystem.update(timer);
scene.update(timer);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
return false;
}
}

View File

@ -0,0 +1,71 @@
package de.frajul.endlessroll.rendering.shader;
import android.content.Context;
import android.opengl.GLES20;
import de.frajul.endlessroll.data.Vector;
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 ObstacleShader extends ShaderProgram {
private int location_mvpMatrix;
private int location_transformationMatrix;
private int location_alpha;
private int location_texAtlasSize;
private int location_gridSize;
private int location_deadly;
private int location_floating;
public ObstacleShader(Context context) throws Exception {
super(context, "shader/entityVertexShader.glsl", "shader/obstacleFragmentShader.glsl");
}
@Override
protected void loadUniformLocations() {
location_mvpMatrix = super.getUniformLocation("mvpMatrix");
location_transformationMatrix = super.getUniformLocation("transformationMatrix");
location_alpha = super.getUniformLocation("alpha");
location_texAtlasSize = super.getUniformLocation("texAtlasSize");
location_gridSize = super.getUniformLocation("gridSize");
location_deadly = super.getUniformLocation("deadly");
location_floating = super.getUniformLocation("floating");
}
public void loadMVPMatrix(MatrixCreator matrixCreator, Camera camera) {
float[] mvpMatrix = matrixCreator.createModelViewProjectionMatrix(camera);
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);
}
public void loadAlpha(float alpha) {
GLES20.glUniform1f(location_alpha, alpha);
}
public void loadTextureAtlasInfos(Texture texture) {
GLES20.glUniform2f(location_texAtlasSize, texture.getAtlasWidth(),
texture.getAtlasHeight());
}
public void loadGridSize(Vector gridSize) {
GLES20.glUniform2f(location_gridSize, gridSize.getX(), gridSize.getY());
}
public void loadDeadly(boolean deadly) {
GLES20.glUniform1f(location_deadly, deadly ? 1 : 0);
}
public void loadFloating(boolean floating) {
GLES20.glUniform1f(location_floating, floating ? 1 : 0);
}
}