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

@ -177,7 +177,7 @@
<obstacleData floating="false" moving="false" deadly="false" leftEdge="6.166328" rightEdge="7.1603284" height="0.293" y="-0.45350003">
<moveComponent width="0.0" height="0.0" x="0.0" y="0.0" speed="0.0"/>
</obstacleData>
<obstacleData floating="true" moving="false" deadly="false" leftEdge="16.936665" rightEdge="19.076664" height="0.217" y="0.30666652">
<obstacleData floating="true" moving="false" deadly="false" leftEdge="16.929998" rightEdge="19.069998" height="0.217" y="0.28666654">
<moveComponent width="0.0" height="0.0" x="0.0" y="0.0" speed="0.0"/>
</obstacleData>
<obstacleData floating="true" moving="false" deadly="false" leftEdge="7.203003" rightEdge="8.6170025" height="0.127" y="-0.41333312">

View File

@ -0,0 +1,97 @@
precision mediump float;
uniform sampler2D texture;
uniform float alpha;
uniform vec2 texAtlasSize;
uniform vec2 gridSize;
uniform float deadly;
uniform float floating;
varying vec2 pass_TexCoords;
const float clampBorder = 0.05;
float itermod(in float x, in float y);
vec2 getInGridPos();
vec2 getTexCoordsInGridSquare();
vec2 getTexCoordsInAtlas(in vec2 texCoords, in float atlasIndex);
void main() {
vec2 gridPos = getInGridPos();
float index = 0.0;
bool top = gridPos.y == 0.0;
bool bottom = gridPos.y == gridSize.y - 1.0;
bool left = gridPos.x == 0.0;
bool right = gridPos.x == gridSize.x - 1.0;
if(top){
if(left)
index = 5.0 + itermod(gridSize.x, 2.0) + itermod(gridSize.y, 2.0);
else if(right)
index = 21.0 + itermod(gridSize.x, 2.0) + itermod(gridSize.y, 2.0);
else
index = itermod(gridPos.x, 3.0);
if(deadly == 1.0)
index += 8.0;
} else if(bottom){
if(left)
index = 37.0 + itermod(gridSize.x, 2.0) + itermod(gridSize.y, 2.0);
else if(right)
index = 53.0 + itermod(gridSize.x, 2.0) + itermod(gridSize.y, 2.0);
else
index = 16.0 + itermod(gridPos.x, 3.0);
if(floating == 1.0)
index += 8.0;
} else if(left){
index = 32.0 + itermod(gridPos.y, 3.0);
} else if(gridPos.x == gridSize.x - 1.0){
index = 40.0 + itermod(gridPos.y, 3.0);
} else{
index = 48.0 + itermod(gridPos.x, 2.0) + itermod(gridPos.y, 2.0);
}
vec2 texCoordsInGridSquare = getTexCoordsInGridSquare();
texCoordsInGridSquare = clamp(texCoordsInGridSquare, clampBorder, 1.0 - clampBorder);
vec2 texCoordsInAtlas = getTexCoordsInAtlas(texCoordsInGridSquare, index);
gl_FragColor = texture2D(texture, texCoordsInAtlas);
gl_FragColor.a = min(gl_FragColor.a, alpha);
}
float itermod(in float x, in float y){
while(x - y >= 0.0){
x -= y;
}
return x;
}
vec2 getInGridPos(){
float gridX = floor(pass_TexCoords.x * gridSize.x);
float gridY = floor(pass_TexCoords.y * gridSize.y);
return vec2(gridX, gridY);
}
vec2 getTexCoordsInGridSquare(){
float x = mod(pass_TexCoords.x, 1.0 / gridSize.x) * gridSize.x;
float y = mod(pass_TexCoords.y, 1.0 / gridSize.y) * gridSize.y;
return vec2(x, y);
}
vec2 getTexCoordsInAtlas(in vec2 texCoords, in float atlasIndex){
vec2 texAtlasCoords = vec2(0.0, 0.0);
texAtlasCoords.x = mod(texCoords.x, 1.0) / texAtlasSize.x;
texAtlasCoords.x += mod(atlasIndex, texAtlasSize.x) / texAtlasSize.x;
texAtlasCoords.y = mod(texCoords.y, 1.0) / texAtlasSize.y;
texAtlasCoords.y += floor(atlasIndex / texAtlasSize.y) / texAtlasSize.y;
return texAtlasCoords;
}

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);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 201 KiB

After

Width:  |  Height:  |  Size: 40 KiB

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
</RelativeLayout>

View File

@ -7,12 +7,12 @@
android:id="@+id/startscreen_sound"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/xml_selector_sound"
android:textOff=""
android:textOn=""
android:layout_alignEnd="@+id/startscreen_play"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/startscreen_play"
android:layout_alignEnd="@+id/startscreen_play"/>
android:background="@drawable/xml_selector_sound"
android:textOff=""
android:textOn=""/>
<Button
android:id="@+id/startscreen_play"
@ -33,20 +33,30 @@
style="@style/GameButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/start_screen_unlock_all_levels"
android:visibility="visible"
android:layout_alignParentRight="true"
android:layout_below="@+id/startscreen_play"
android:layout_alignParentRight="true"/>
android:text="@string/start_screen_unlock_all_levels"
android:visibility="visible"/>
<Button
android:id="@+id/startscreen_gain_90_ep"
style="@style/GameButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/start_screen_gain_90_ep"
android:visibility="visible"
android:layout_below="@+id/startscreen_play"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
android:layout_alignParentStart="true"
android:layout_below="@+id/startscreen_play"
android:text="@string/start_screen_gain_90_ep"
android:visibility="visible"/>
<Button
android:id="@+id/startscreen_to_gl_test_screen"
style="@style/GameButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="@string/start_screen_to_gl_test_screen"
android:visibility="visible"/>
</RelativeLayout>

View File

@ -6,7 +6,7 @@
<string name="percent_placeholder">85.1%</string>
<string name="game_playerprogress_placeholder">0.0m</string>
<string name="game_playerprogress_format_f">%.2fm</string>
<string name="game_playerprogress_format_f">%.1fm</string>
<string name="game_playerspeed_placeholder">0.0m/s</string>
<string name="game_playerspeed_format_f">%.1fm/s</string>
<string name="game_fps_placeholder">Fps: 00</string>
@ -27,6 +27,7 @@
<string name="start_screen_play">Play</string>
<string name="start_screen_unlock_all_levels">Unlock all levels (Yes! It\'s magic!)</string>
<string name="start_screen_gain_90_ep">Gain 90 ep (Nope! No magic at all!)</string>
<string name="start_screen_to_gl_test_screen">Test GL Stuff!!!</string>
<string name="tool_upgrade_title_placeholder">Time (Lv12)</string>
<string name="topbar_level_placeholder">Level: 24</string>
<string name="topbar_level_format_d">Level: %d</string>