diff --git a/app/app.iml b/app/app.iml index 7e28fff..a90aae5 100644 --- a/app/app.iml +++ b/app/app.iml @@ -66,14 +66,6 @@ - - - - - - - - @@ -82,6 +74,14 @@ + + + + + + + + diff --git a/app/build/generated/source/r/debug/com/example/julian/endlessroll/R.java b/app/build/generated/source/r/debug/com/example/julian/endlessroll/R.java index f79f6d5..c54a123 100644 --- a/app/build/generated/source/r/debug/com/example/julian/endlessroll/R.java +++ b/app/build/generated/source/r/debug/com/example/julian/endlessroll/R.java @@ -22,12 +22,13 @@ public final class R { public static final int countdown=0x7f05000a; public static final int decrease=0x7f05000b; public static final int fade_in=0x7f05000c; - public static final int rotate=0x7f05000d; - public static final int scale_up=0x7f05000e; - public static final int shrink=0x7f05000f; - public static final int slide_in_left=0x7f050010; - public static final int slide_in_right=0x7f050011; - public static final int slide_in_top=0x7f050012; + public static final int fade_out=0x7f05000d; + public static final int rotate=0x7f05000e; + public static final int scale_up=0x7f05000f; + public static final int shrink=0x7f050010; + public static final int slide_in_left=0x7f050011; + public static final int slide_in_right=0x7f050012; + public static final int slide_in_top=0x7f050013; } public static final class attr { /**

Must be a reference to another resource, in the form "@[+][package:]type:name" diff --git a/app/build/intermediates/assets/debug/levelpacks/Grasslands.xml b/app/build/intermediates/assets/debug/levelpacks/Grasslands.xml index fc1fd33..bfdcc0b 100644 --- a/app/build/intermediates/assets/debug/levelpacks/Grasslands.xml +++ b/app/build/intermediates/assets/debug/levelpacks/Grasslands.xml @@ -1,4 +1,5 @@ - + + GRASSLANDS diff --git a/app/build/intermediates/assets/debug/levelpacks/Testcave.xml b/app/build/intermediates/assets/debug/levelpacks/Testcave.xml index 34902b7..b708464 100644 --- a/app/build/intermediates/assets/debug/levelpacks/Testcave.xml +++ b/app/build/intermediates/assets/debug/levelpacks/Testcave.xml @@ -1,4 +1,5 @@ - + + TESTCAVE diff --git a/app/build/intermediates/blame/res/debug/single/anim.json b/app/build/intermediates/blame/res/debug/single/anim.json index e1a60fd..78f37b2 100644 --- a/app/build/intermediates/blame/res/debug/single/anim.json +++ b/app/build/intermediates/blame/res/debug/single/anim.json @@ -47,6 +47,10 @@ "merged": "C:\\Users\\Julian\\AndroidStudioProjects\\EndlessRoll\\app\\build\\intermediates\\res\\merged\\debug\\anim\\abc_grow_fade_in_from_bottom.xml", "source": "C:\\Users\\Julian\\AndroidStudioProjects\\EndlessRoll\\app\\build\\intermediates\\exploded-aar\\com.android.support\\appcompat-v7\\23.1.1\\res\\anim\\abc_grow_fade_in_from_bottom.xml" }, + { + "merged": "C:\\Users\\Julian\\AndroidStudioProjects\\EndlessRoll\\app\\build\\intermediates\\res\\merged\\debug\\anim\\fade_out.xml", + "source": "C:\\Users\\Julian\\AndroidStudioProjects\\EndlessRoll\\app\\src\\main\\res\\anim\\fade_out.xml" + }, { "merged": "C:\\Users\\Julian\\AndroidStudioProjects\\EndlessRoll\\app\\build\\intermediates\\res\\merged\\debug\\anim\\shrink.xml", "source": "C:\\Users\\Julian\\AndroidStudioProjects\\EndlessRoll\\app\\src\\main\\res\\anim\\shrink.xml" diff --git a/app/build/intermediates/blame/res/debug/single/layout.json b/app/build/intermediates/blame/res/debug/single/layout.json index 6dbb5b3..93c411c 100644 --- a/app/build/intermediates/blame/res/debug/single/layout.json +++ b/app/build/intermediates/blame/res/debug/single/layout.json @@ -7,14 +7,14 @@ "merged": "C:\\Users\\Julian\\AndroidStudioProjects\\EndlessRoll\\app\\build\\intermediates\\res\\merged\\debug\\layout\\toolshop.xml", "source": "C:\\Users\\Julian\\AndroidStudioProjects\\EndlessRoll\\app\\src\\main\\res\\layout\\toolshop.xml" }, - { - "merged": "C:\\Users\\Julian\\AndroidStudioProjects\\EndlessRoll\\app\\build\\intermediates\\res\\merged\\debug\\layout\\worlds.xml", - "source": "C:\\Users\\Julian\\AndroidStudioProjects\\EndlessRoll\\app\\src\\main\\res\\layout\\worlds.xml" - }, { "merged": "C:\\Users\\Julian\\AndroidStudioProjects\\EndlessRoll\\app\\build\\intermediates\\res\\merged\\debug\\layout\\abc_screen_simple_overlay_action_mode.xml", "source": "C:\\Users\\Julian\\AndroidStudioProjects\\EndlessRoll\\app\\build\\intermediates\\exploded-aar\\com.android.support\\appcompat-v7\\23.1.1\\res\\layout\\abc_screen_simple_overlay_action_mode.xml" }, + { + "merged": "C:\\Users\\Julian\\AndroidStudioProjects\\EndlessRoll\\app\\build\\intermediates\\res\\merged\\debug\\layout\\worlds.xml", + "source": "C:\\Users\\Julian\\AndroidStudioProjects\\EndlessRoll\\app\\src\\main\\res\\layout\\worlds.xml" + }, { "merged": "C:\\Users\\Julian\\AndroidStudioProjects\\EndlessRoll\\app\\build\\intermediates\\res\\merged\\debug\\layout\\abc_screen_simple.xml", "source": "C:\\Users\\Julian\\AndroidStudioProjects\\EndlessRoll\\app\\build\\intermediates\\exploded-aar\\com.android.support\\appcompat-v7\\23.1.1\\res\\layout\\abc_screen_simple.xml" diff --git a/app/build/intermediates/incremental/mergeDebugAssets/merger.xml b/app/build/intermediates/incremental/mergeDebugAssets/merger.xml index 5ad049f..513b438 100644 --- a/app/build/intermediates/incremental/mergeDebugAssets/merger.xml +++ b/app/build/intermediates/incremental/mergeDebugAssets/merger.xml @@ -1,2 +1,2 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/app/build/intermediates/incremental/mergeDebugResources/merger.xml b/app/build/intermediates/incremental/mergeDebugResources/merger.xml index b001cfa..b88a02a 100644 --- a/app/build/intermediates/incremental/mergeDebugResources/merger.xml +++ b/app/build/intermediates/incremental/mergeDebugResources/merger.xml @@ -1359,4 +1359,4 @@ 2 2 2 - \ No newline at end of file + \ No newline at end of file diff --git a/app/build/intermediates/res/merged/debug/layout/worlds.xml b/app/build/intermediates/res/merged/debug/layout/worlds.xml index ee19fb2..1dafdbe 100644 --- a/app/build/intermediates/res/merged/debug/layout/worlds.xml +++ b/app/build/intermediates/res/merged/debug/layout/worlds.xml @@ -16,7 +16,8 @@ android:layout_height="match_parent" android:layout_below="@+id/worlds_topbar" android:layout_centerHorizontal="true" - android:layout_margin="10dp" > + android:layout_marginTop="10dp" + android:layout_marginBottom="10dp"> + + GRASSLANDS diff --git a/app/src/main/assets/levelpacks/Testcave.xml b/app/src/main/assets/levelpacks/Testcave.xml index 34902b7..b708464 100644 --- a/app/src/main/assets/levelpacks/Testcave.xml +++ b/app/src/main/assets/levelpacks/Testcave.xml @@ -1,4 +1,5 @@ - + + TESTCAVE diff --git a/app/src/main/java/com/example/julian/endlessroll/entities/Background.java b/app/src/main/java/com/example/julian/endlessroll/entities/Background.java index 2e327c2..ca0c2ce 100644 --- a/app/src/main/java/com/example/julian/endlessroll/entities/Background.java +++ b/app/src/main/java/com/example/julian/endlessroll/entities/Background.java @@ -19,6 +19,12 @@ public class Background extends ArrayList { super.add(createPart(-HALF_PART_WIDTH)); } + public void changeTexture(Texture texture) { + this.texture = texture; + for (Entity entity : this) + entity.setTexture(texture); + } + private Entity createPart(float xLeftEdge) { return new Entity(texture, new Vector(xLeftEdge + HALF_PART_WIDTH, 0), PART_WIDTH, 2); } @@ -28,10 +34,11 @@ public class Background extends ArrayList { for (Entity part : this) part.move(movement); if (!super.isEmpty()) { - Entity last = super.get(super.size()-1); - if (last.getRightEdge() -cameraX < 3) { - super.add(createPart(last.getRightEdge()-0.001f)); - }if(super.get(0).getRightEdge() -cameraX< -3){ + Entity last = super.get(super.size() - 1); + if (last.getRightEdge() - cameraX < 3) { + super.add(createPart(last.getRightEdge() - 0.001f)); + } + if (super.get(0).getRightEdge() - cameraX < -3) { super.remove(0); } } diff --git a/app/src/main/java/com/example/julian/endlessroll/entities/Obstacle.java b/app/src/main/java/com/example/julian/endlessroll/entities/Obstacle.java index 55ca967..09c6472 100644 --- a/app/src/main/java/com/example/julian/endlessroll/entities/Obstacle.java +++ b/app/src/main/java/com/example/julian/endlessroll/entities/Obstacle.java @@ -1,16 +1,16 @@ package com.example.julian.endlessroll.entities; import com.example.julian.endlessroll.data.Vector; -import com.example.julian.endlessroll.entities.textures.Texture; import com.example.julian.endlessroll.levels.ObstacleData; +import com.example.julian.endlessroll.levels.worlds.World; /** * Created by Julian on 20.11.2015. */ public class Obstacle extends Entity { - public Obstacle(Texture texture, ObstacleData data, float terrainEdge) { - super(texture, new Vector(data.getX(), data.getY()), data.getWidth(), data.getHeight()); + public Obstacle(World world, ObstacleData data, float terrainEdge) { + super(world.getObstacle(), new Vector(data.getX(), data.getY()), data.getWidth(), data.getHeight()); if (data.isAttachedToGround()) super.setToTerrain(terrainEdge); } diff --git a/app/src/main/java/com/example/julian/endlessroll/entities/Player.java b/app/src/main/java/com/example/julian/endlessroll/entities/Player.java index 2799dc2..e6fe466 100644 --- a/app/src/main/java/com/example/julian/endlessroll/entities/Player.java +++ b/app/src/main/java/com/example/julian/endlessroll/entities/Player.java @@ -26,6 +26,7 @@ public class Player extends Entity { } public void init(float terrainEdge, float startSpeed, float endSpeed) { + GameLog.i("init: "+startSpeed+"; "+endSpeed); super.setToTerrain(terrainEdge); super.getPosition().x = START_X; super.setMovement(new Vector(speed, 0)); @@ -37,7 +38,6 @@ public class Player extends Entity { public void setSpeedByProgress(float progress) { this.speed = ((endSpeed - startSpeed) * progress + startSpeed) * SPEED; super.getMovement().x = speed; - GameLog.i("Speed: "+ speed); } public float getProgress() { diff --git a/app/src/main/java/com/example/julian/endlessroll/entities/textures/TexturePack.java b/app/src/main/java/com/example/julian/endlessroll/entities/textures/TexturePack.java index f826be9..a94663b 100644 --- a/app/src/main/java/com/example/julian/endlessroll/entities/textures/TexturePack.java +++ b/app/src/main/java/com/example/julian/endlessroll/entities/textures/TexturePack.java @@ -1,9 +1,14 @@ package com.example.julian.endlessroll.entities.textures; import android.content.Context; +import android.support.annotation.DrawableRes; import com.example.julian.endlessroll.R; import com.example.julian.endlessroll.entities.tools.ToolType; +import com.example.julian.endlessroll.levels.worlds.World; + +import java.util.HashMap; +import java.util.Map; /** * Created by Julian on 05.12.2015. @@ -12,12 +17,9 @@ public class TexturePack { private TextureLoader loader; - public final Texture background; public final Texture goal; - public final Texture terrain; public final Texture playerArrow; public final Texture player; - public final Texture obstacle; public final Texture star; public final Texture blueParticle; public final Texture yellowParticle; @@ -25,13 +27,10 @@ public class TexturePack { public TexturePack(Context context) { loader = new TextureLoader(context); - background = loadTexture(R.drawable.background); goal = loadTexture(R.drawable.goal); - terrain = loadAtlas(R.drawable.terrain, 1, 1); player = loadTexture(R.drawable.ball); playerArrow = loadTexture(R.drawable.playerarrow); - obstacle = loadTexture(R.drawable.obstacle); star = loadTexture(R.drawable.star); blueParticle = loadTexture(R.drawable.blueparticle); @@ -39,14 +38,15 @@ public class TexturePack { redParticle = loadTexture(R.drawable.redparticle); ToolType.loadAllToolTextures(this); + World.loadAllSpecificTextures(this); } - private Texture loadTexture(int id) { + public Texture loadTexture(@DrawableRes int id) { int texId = loader.loadTextureId(id, false); return new Texture(texId, 1, 1); } - public Texture loadAtlas(int id, int atlasWidth, int atlasHeight) { + public Texture loadAtlas(@DrawableRes int id, int atlasWidth, int atlasHeight) { int texId = loader.loadTextureId(id, true); return new Texture(texId, atlasWidth, atlasHeight); } diff --git a/app/src/main/java/com/example/julian/endlessroll/entities/tileLists/Ceiling.java b/app/src/main/java/com/example/julian/endlessroll/entities/tileLists/Ceiling.java index eb2399e..9f04092 100644 --- a/app/src/main/java/com/example/julian/endlessroll/entities/tileLists/Ceiling.java +++ b/app/src/main/java/com/example/julian/endlessroll/entities/tileLists/Ceiling.java @@ -1,12 +1,13 @@ package com.example.julian.endlessroll.entities.tileLists; +import com.example.julian.endlessroll.entities.textures.Texture; import com.example.julian.endlessroll.entities.textures.TexturePack; @SuppressWarnings("serial") public class Ceiling extends TileList { - public Ceiling(TexturePack textures) { - super(Type.CEILING, textures.terrain); + public Ceiling(Texture texture) { + super(Type.CEILING, texture); } } diff --git a/app/src/main/java/com/example/julian/endlessroll/entities/tileLists/Terrain.java b/app/src/main/java/com/example/julian/endlessroll/entities/tileLists/Terrain.java index 09a800d..3a84510 100644 --- a/app/src/main/java/com/example/julian/endlessroll/entities/tileLists/Terrain.java +++ b/app/src/main/java/com/example/julian/endlessroll/entities/tileLists/Terrain.java @@ -1,12 +1,13 @@ package com.example.julian.endlessroll.entities.tileLists; +import com.example.julian.endlessroll.entities.textures.Texture; import com.example.julian.endlessroll.entities.textures.TexturePack; @SuppressWarnings("serial") public class Terrain extends TileList { - public Terrain(TexturePack textures) { - super(TileList.Type.TERRAIN, textures.terrain); + public Terrain(Texture texture) { + super(TileList.Type.TERRAIN, texture); } } diff --git a/app/src/main/java/com/example/julian/endlessroll/entities/tileLists/TileList.java b/app/src/main/java/com/example/julian/endlessroll/entities/tileLists/TileList.java index 2d7791c..fedb0d4 100644 --- a/app/src/main/java/com/example/julian/endlessroll/entities/tileLists/TileList.java +++ b/app/src/main/java/com/example/julian/endlessroll/entities/tileLists/TileList.java @@ -1,7 +1,9 @@ package com.example.julian.endlessroll.entities.tileLists; +import com.example.julian.endlessroll.entities.Entity; import com.example.julian.endlessroll.entities.textures.Texture; import com.example.julian.endlessroll.levels.TileData; +import com.example.julian.endlessroll.levels.worlds.World; import java.util.ArrayList; import java.util.List; @@ -34,7 +36,8 @@ public class TileList extends ArrayList { this.texture = texture; } - public void loadData(float edge, List tileData) { + public void loadData(World world, float edge, List tileData) { + this.texture = world.getTerrain(); this.endless = false; super.clear(); for (TileData data : tileData) @@ -42,8 +45,8 @@ public class TileList extends ArrayList { this.edge = edge; } - public void createEndless(float edge) { - loadData(edge, new ArrayList()); + public void createEndless(World world, float edge) { + loadData(world, edge, new ArrayList()); super.add(createEndlessTile(0)); this.endless = true; } diff --git a/app/src/main/java/com/example/julian/endlessroll/levels/LevelManager.java b/app/src/main/java/com/example/julian/endlessroll/levels/LevelManager.java index 58d0a66..9d0ebf8 100644 --- a/app/src/main/java/com/example/julian/endlessroll/levels/LevelManager.java +++ b/app/src/main/java/com/example/julian/endlessroll/levels/LevelManager.java @@ -23,7 +23,7 @@ public class LevelManager extends ArrayList { dataStorageHandler.readLevelProgress(pack); dataStorageHandler.readLevelPackLocked(pack); pack.tryToUnlockFirstLevel(); - if (pack.getId() == 0) + if (pack.getWorld().getIndex() == 0) pack.setLocked(false); super.add(pack); } catch (Exception e) { @@ -37,7 +37,7 @@ public class LevelManager extends ArrayList { Collections.sort(this, new Comparator() { @Override public int compare(LevelPack lhs, LevelPack rhs) { - return lhs.getId() - rhs.getId(); + return lhs.getWorld().getIndex() - rhs.getWorld().getIndex(); } }); } @@ -55,7 +55,7 @@ public class LevelManager extends ArrayList { public void reset() { for (LevelPack pack : this) { pack.reset(); - if (pack.getId() != 0) + if (pack.getWorld().getIndex() != 0) pack.setLocked(true); } } @@ -73,9 +73,9 @@ public class LevelManager extends ArrayList { } public LevelPack nextLevelPack(LevelPack old) { - int oldId = old.getId(); + int oldId = old.getWorld().getIndex(); for (LevelPack pack : this) { - if (pack.getId() == oldId + 1) + if (pack.getWorld().getIndex() == oldId + 1) return pack; } return null; diff --git a/app/src/main/java/com/example/julian/endlessroll/levels/LevelPack.java b/app/src/main/java/com/example/julian/endlessroll/levels/LevelPack.java index 89fce4f..6d2fd0f 100644 --- a/app/src/main/java/com/example/julian/endlessroll/levels/LevelPack.java +++ b/app/src/main/java/com/example/julian/endlessroll/levels/LevelPack.java @@ -1,6 +1,9 @@ package com.example.julian.endlessroll.levels; +import com.example.julian.endlessroll.levels.worlds.World; + import org.simpleframework.xml.Attribute; +import org.simpleframework.xml.Element; import org.simpleframework.xml.ElementList; import org.simpleframework.xml.Root; @@ -12,22 +15,12 @@ import java.util.List; @Root public class LevelPack { - @Attribute - private String name; - @Attribute - private int id; + @Element + private World world; @ElementList private List levels; private boolean locked; - public String getName() { - return name; - } - - public Integer getId() { - return id; - } - public List getLevels() { return levels; } @@ -51,6 +44,10 @@ public class LevelPack { return levels.size() * 3; } + public World getWorld() { + return world; + } + public void tryToUnlockFirstLevel() { try { levels.get(0).setUnlocked(true); diff --git a/app/src/main/java/com/example/julian/endlessroll/levels/worlds/World.java b/app/src/main/java/com/example/julian/endlessroll/levels/worlds/World.java new file mode 100644 index 0000000..b2fd432 --- /dev/null +++ b/app/src/main/java/com/example/julian/endlessroll/levels/worlds/World.java @@ -0,0 +1,77 @@ +package com.example.julian.endlessroll.levels.worlds; + +import android.support.annotation.DrawableRes; + +import com.example.julian.endlessroll.R; +import com.example.julian.endlessroll.entities.textures.Texture; +import com.example.julian.endlessroll.entities.textures.TexturePack; + +/** + * Created by Julian on 14.11.2016. + */ + +public enum World { + + GRASSLANDS(0, "Grasslands", R.drawable.grasslands_preview, R.drawable.background, R.drawable.terrain, R.drawable.obstacle), + TESTCAVE(1, "Testcave", R.drawable.grasslands_preview, R.drawable.background, R.drawable.terrain, R.drawable.obstacle), + ICY_MOUNTAINS(2, "Icy Mountains", R.drawable.grasslands_preview, R.drawable.background, R.drawable.terrain, R.drawable.obstacle); + + private int index; + private String name; + @DrawableRes + private int previewId; + @DrawableRes + private int backgroundId; + @DrawableRes + private int terrainId; + @DrawableRes + private int obstacleId; + + private Texture background; + private Texture terrain; + private Texture obstacle; + + World(int index, String name, @DrawableRes int previewId, @DrawableRes int backgroundId, @DrawableRes int terrainId, @DrawableRes int obstacleId) { + this.index = index; + this.name = name; + this.previewId = previewId; + this.backgroundId = backgroundId; + this.terrainId = terrainId; + this.obstacleId = obstacleId; + } + + public static void loadAllSpecificTextures(TexturePack texturePack){ + for(World world : values()) + world.loadSpecificTextures(texturePack); + } + + private void loadSpecificTextures(TexturePack texturePack) { + background = texturePack.loadTexture(backgroundId); + terrain = texturePack.loadTexture(terrainId); + obstacle = texturePack.loadTexture(obstacleId); + } + + public int getIndex() { + return index; + } + + public String getName() { + return name; + } + + public int getPreviewId() { + return previewId; + } + + public Texture getBackground() { + return background; + } + + public Texture getTerrain() { + return terrain; + } + + public Texture getObstacle() { + return obstacle; + } +} diff --git a/app/src/main/java/com/example/julian/endlessroll/main/DataStorageHandler.java b/app/src/main/java/com/example/julian/endlessroll/main/DataStorageHandler.java index a058d3f..1672b93 100644 --- a/app/src/main/java/com/example/julian/endlessroll/main/DataStorageHandler.java +++ b/app/src/main/java/com/example/julian/endlessroll/main/DataStorageHandler.java @@ -84,7 +84,7 @@ public class DataStorageHandler { public void readLevelProgress(LevelPack levelPack) { database.open(); for (Level level : levelPack.getLevels()) { - database.readLevelProgress(levelPack.getId(), level); + database.readLevelProgress(levelPack.getWorld().getIndex(), level); } database.close(); } diff --git a/app/src/main/java/com/example/julian/endlessroll/main/game/Game.java b/app/src/main/java/com/example/julian/endlessroll/main/game/Game.java index bf8805e..f374ded 100644 --- a/app/src/main/java/com/example/julian/endlessroll/main/game/Game.java +++ b/app/src/main/java/com/example/julian/endlessroll/main/game/Game.java @@ -95,7 +95,7 @@ public class Game extends Rendering { if (scene != null) { collectedStars.clear(); particleSystem.deleteAllSources(); - scene.loadLevel(level); + scene.loadLevel(level, levelPack.getWorld()); player = scene.getPlayer(); if (viewManager.isScreenSizeSet()) viewManager.resetViews(); @@ -124,11 +124,13 @@ public class Game extends Rendering { particleSystem.update(timer); float playerProgress = 0; float playerSpeed = 0; + float playerY = 0; if (player != null) { playerProgress = player.getProgress(); playerSpeed = player.getSpeed(); + playerY = player.getPosition().y; } - viewManager.update(gameState == GameState.RUNNING, timer, playerProgress, playerSpeed); + viewManager.update(gameState == GameState.RUNNING, timer, playerProgress, playerSpeed, playerY); switch (gameState) { case RUNNING: if (player.getPosition().y < -2f) { @@ -237,11 +239,11 @@ public class Game extends Rendering { } viewManager.showMessage(levelPack.isLastLevel(level), MessageType.WIN); - dataStorageHandler.writeLevelProgress(levelPack.getId(), level); + dataStorageHandler.writeLevelProgress(levelPack.getWorld().getIndex(), level); Level nextLevel = levelPack.getNextLevel(level); if (nextLevel != null) { nextLevel.setUnlocked(true); - dataStorageHandler.writeLevelProgress(levelPack.getId(), nextLevel); + dataStorageHandler.writeLevelProgress(levelPack.getWorld().getIndex(), nextLevel); }else{ LevelPack nextLevelPack = levelManager.nextLevelPack(levelPack); if(nextLevelPack != null){ diff --git a/app/src/main/java/com/example/julian/endlessroll/main/game/GameScene.java b/app/src/main/java/com/example/julian/endlessroll/main/game/GameScene.java index 7f7d804..3496b23 100644 --- a/app/src/main/java/com/example/julian/endlessroll/main/game/GameScene.java +++ b/app/src/main/java/com/example/julian/endlessroll/main/game/GameScene.java @@ -15,6 +15,7 @@ import com.example.julian.endlessroll.entities.tools.ToolType; import com.example.julian.endlessroll.levels.Level; import com.example.julian.endlessroll.levels.ObstacleData; import com.example.julian.endlessroll.levels.StarData; +import com.example.julian.endlessroll.levels.worlds.World; import com.example.julian.endlessroll.main.GameLog; import java.util.ArrayList; @@ -26,6 +27,7 @@ import java.util.List; */ public class GameScene extends Scene { + private World currentWorld; private CollisionDetector collisionDetector; private Goal goal; @@ -41,11 +43,13 @@ public class GameScene extends Scene { goal = new Goal(textures.goal); } - public void loadLevel(Level level) throws Exception { + public void loadLevel(Level level, World world) throws Exception { + this.currentWorld = world; reset(); lock.lock(); - terrain.loadData(level.getTerrainEdge(), level.getTerrainTiles()); - ceiling.loadData(level.getCeilingEdge(), level.getCeilingTiles()); + background.changeTexture(world.getBackground()); + terrain.loadData(world, level.getTerrainEdge(), level.getTerrainTiles()); + ceiling.loadData(world, level.getCeilingEdge(), level.getCeilingTiles()); super.add(goal); player.init(terrain.getEdge(), level.getStartSpeed(), level.getEndSpeed()); super.add(player); @@ -77,6 +81,7 @@ public class GameScene extends Scene { } public void onStarCollision(Star collisionStar) { + lock.lock(); Iterator iter = stars.iterator(); while (iter.hasNext()) { Star star = iter.next(); @@ -85,10 +90,12 @@ public class GameScene extends Scene { iter.remove(); } } + lock.unlock(); + //TODO: change lock with atomic lists!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! } public void addObstacle(ObstacleData data) { - Obstacle obstacle = new Obstacle(textures.obstacle, data, terrain.getEdge()); + Obstacle obstacle = new Obstacle(currentWorld, data, terrain.getEdge()); lock.lock(); super.add(obstacle); obstacles.add(obstacle); @@ -118,8 +125,8 @@ public class GameScene extends Scene { @Override public void update(Timer timer) { super.update(timer); - float playerProgress = player.getPosition().x / goalX; - player.setSpeedByProgress(playerProgress); + player.setSpeedByProgress(player.getProgress() / goalX); + lock.lock(); for (Tool tool : tools) { tool.update(timer); if (tool instanceof Bomb) { @@ -128,6 +135,7 @@ public class GameScene extends Scene { bomb.explode(obstacles, collisionDetector); } } + lock.unlock(); } @Override diff --git a/app/src/main/java/com/example/julian/endlessroll/main/game/Physics.java b/app/src/main/java/com/example/julian/endlessroll/main/game/Physics.java index b59f884..6283719 100644 --- a/app/src/main/java/com/example/julian/endlessroll/main/game/Physics.java +++ b/app/src/main/java/com/example/julian/endlessroll/main/game/Physics.java @@ -35,6 +35,7 @@ public class Physics { } public void applyGravity(GameScene scene) { + scene.lock.lock(); scene.getPlayer().getMovement().y -= GRAVITY_FORCE; for (Tool tool : scene.getTools()) { if (tool.isFloating()) @@ -70,6 +71,7 @@ public class Physics { tool.setToTerrain(orientingHeight); } } + scene.lock.unlock(); } @Nullable diff --git a/app/src/main/java/com/example/julian/endlessroll/main/game/Scene.java b/app/src/main/java/com/example/julian/endlessroll/main/game/Scene.java index ad02da3..c81a9c7 100644 --- a/app/src/main/java/com/example/julian/endlessroll/main/game/Scene.java +++ b/app/src/main/java/com/example/julian/endlessroll/main/game/Scene.java @@ -8,6 +8,7 @@ import com.example.julian.endlessroll.entities.particles.ParticleSystem; import com.example.julian.endlessroll.entities.textures.TexturePack; import com.example.julian.endlessroll.entities.tileLists.Ceiling; import com.example.julian.endlessroll.entities.tileLists.Terrain; +import com.example.julian.endlessroll.levels.worlds.World; import com.example.julian.endlessroll.rendering.Lock; import java.util.ArrayList; @@ -35,9 +36,9 @@ public abstract class Scene extends ArrayList { this.particleSystem = particleSystem; setTexturePack(texturePack); playerArrow = new Entity(textures.playerArrow, new Vector(0, 0.9f), .2f, .2f); - background = new Background(textures.background); - terrain = new Terrain(textures); - ceiling = new Ceiling(textures); + background = new Background(World.GRASSLANDS.getBackground()); + terrain = new Terrain(World.GRASSLANDS.getTerrain()); + ceiling = new Ceiling(World.GRASSLANDS.getTerrain()); player = new Player(textures.player); lock = new Lock(); } diff --git a/app/src/main/java/com/example/julian/endlessroll/main/game/StartScene.java b/app/src/main/java/com/example/julian/endlessroll/main/game/StartScene.java index 50f0253..00342e3 100644 --- a/app/src/main/java/com/example/julian/endlessroll/main/game/StartScene.java +++ b/app/src/main/java/com/example/julian/endlessroll/main/game/StartScene.java @@ -3,12 +3,13 @@ package com.example.julian.endlessroll.main.game; import com.example.julian.endlessroll.entities.Entity; import com.example.julian.endlessroll.entities.particles.ParticleSystem; import com.example.julian.endlessroll.entities.textures.TexturePack; +import com.example.julian.endlessroll.levels.worlds.World; public class StartScene extends Scene { public StartScene(TexturePack texturePack, ParticleSystem particleSystem) { super(texturePack, particleSystem); - terrain.createEndless(-.8f); + terrain.createEndless(World.ICY_MOUNTAINS, -.8f); player.init(terrain.getEdge(), 0.5f, 0.5f); super.add(player); } diff --git a/app/src/main/java/com/example/julian/endlessroll/main/screens/StartScreen.java b/app/src/main/java/com/example/julian/endlessroll/main/screens/StartScreen.java index cf13f7d..cfd4729 100644 --- a/app/src/main/java/com/example/julian/endlessroll/main/screens/StartScreen.java +++ b/app/src/main/java/com/example/julian/endlessroll/main/screens/StartScreen.java @@ -77,6 +77,7 @@ public class StartScreen extends GLScreen implements View.OnClic user.setStarCount(100); levelManager.unlockAllLevels(); levelManager.unlockAllPacks(); + } } diff --git a/app/src/main/java/com/example/julian/endlessroll/rendering/renderer/GameRenderer.java b/app/src/main/java/com/example/julian/endlessroll/rendering/renderer/GameRenderer.java index db49902..f1e5058 100644 --- a/app/src/main/java/com/example/julian/endlessroll/rendering/renderer/GameRenderer.java +++ b/app/src/main/java/com/example/julian/endlessroll/rendering/renderer/GameRenderer.java @@ -104,9 +104,11 @@ public class GameRenderer implements GLSurfaceView.Renderer { GLES20.glClearColor(1, 1, 1, 1.0f); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); + scene.lock.lock(); renderEntities(gl, scene); renderTileList(gl, scene.getTerrain(), scene); renderTileList(gl, scene.getCeiling(), scene); + scene.lock.unlock(); renderFbo(gl); } } @@ -114,12 +116,10 @@ public class GameRenderer implements GLSurfaceView.Renderer { private void renderEntities(GL10 gl, Scene scene) { entityShader.start(); entityShader.loadMVPMatrix(matrixCreator, scene.cameraX); - scene.lock.lock(); for (Entity backgroundPart : scene.getBackground()) renderEntity(gl, backgroundPart); for (Entity entity : scene) renderEntity(gl, entity); - scene.lock.unlock(); entityShader.stop(); } diff --git a/app/src/main/java/com/example/julian/endlessroll/sqlDatabase/MyDatabase.java b/app/src/main/java/com/example/julian/endlessroll/sqlDatabase/MyDatabase.java index fceb3af..f4a8793 100644 --- a/app/src/main/java/com/example/julian/endlessroll/sqlDatabase/MyDatabase.java +++ b/app/src/main/java/com/example/julian/endlessroll/sqlDatabase/MyDatabase.java @@ -19,7 +19,7 @@ import java.util.List; */ public class MyDatabase extends DatabaseAdapter { - private final static int VERSION = 5; + private final static int VERSION = 6; private final static String DATABASE_NAME = "DATABASE"; private SQLTableColumn levelpackColumn, levelColumn, unlockedColumn, completedColumn, starsColumn; private SQLTableColumn idColumn, toolTypeColumn, lockedColumn, boughtColumn; @@ -31,8 +31,6 @@ public class MyDatabase extends DatabaseAdapter { @Override protected void createColumns() { - //TODO: no names needed for columns and tables - //TODO: really use database adapter??? levelpackColumn = new SQLTableColumn("LEVELPACK", SQLTableColumn.ColumnType.INTEGER, SQLTableColumn.ColumnExtra.NOT_NULL); levelColumn = new SQLTableColumn("LEVEL", SQLTableColumn.ColumnType.INTEGER, SQLTableColumn.ColumnExtra.NOT_NULL); unlockedColumn = new SQLTableColumn("UNLOCKED", SQLTableColumn.ColumnType.INTEGER, SQLTableColumn.ColumnExtra.NOT_NULL); @@ -86,13 +84,13 @@ public class MyDatabase extends DatabaseAdapter { public void writeLevelPackLocked(LevelPack levelPack) { ContentValues values = new ContentValues(); - values.put(levelpackColumn.getKey(), levelPack.getId()); + values.put(levelpackColumn.getKey(), levelPack.getWorld().getIndex()); values.put(unlockedColumn.getKey(), levelPack.isLocked() ? 0 : 1); - super.update(levelPackTable, values, levelpackColumn, levelPack.getId()); + super.update(levelPackTable, values, levelpackColumn, levelPack.getWorld().getIndex()); } public void readLevelPackLocked(LevelPack levelPack) { - Cursor cursor = super.getCursor(levelPackTable, levelpackColumn, levelPack.getId()); + Cursor cursor = super.getCursor(levelPackTable, levelpackColumn, levelPack.getWorld().getIndex()); if (cursor.moveToFirst()) { boolean unlocked = cursor.getInt(1) == 1; levelPack.setLocked(!unlocked); diff --git a/app/src/main/java/com/example/julian/endlessroll/views/ToolButtonBar.java b/app/src/main/java/com/example/julian/endlessroll/views/ToolButtonBar.java index a0931e0..1ee0c58 100644 --- a/app/src/main/java/com/example/julian/endlessroll/views/ToolButtonBar.java +++ b/app/src/main/java/com/example/julian/endlessroll/views/ToolButtonBar.java @@ -2,12 +2,15 @@ package com.example.julian.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; import com.example.julian.endlessroll.R; import com.example.julian.endlessroll.entities.tools.ToolSlotSettings; import com.example.julian.endlessroll.entities.tools.ToolType; +import com.example.julian.endlessroll.main.GameLog; import com.example.julian.endlessroll.main.game.Game; import com.example.julian.endlessroll.main.game.GameState; @@ -17,8 +20,22 @@ import java.util.List; /** * Created by Julian on 16.01.2016. */ -public class ToolButtonBar implements View.OnClickListener { +public class ToolButtonBar implements View.OnClickListener, Animation.AnimationListener { + @Override + public void onAnimationStart(Animation animation) { + } + + @Override + public void onAnimationEnd(Animation animation) { + } + + @Override + public void onAnimationRepeat(Animation animation) { + + } + + private Animation fadeIn, fadeOut; private Game game; private ToolSlotSettings toolSlotSettings; private List buttons = new ArrayList<>(4); @@ -27,17 +44,22 @@ public class ToolButtonBar implements View.OnClickListener { private RelativeLayout button3; private RelativeLayout button4; - public ToolButtonBar(Game game, ToolSlotSettings toolSlotSettings, LinearLayout layout) { + + public ToolButtonBar(Game game, ToolSlotSettings toolSlotSettings, LinearLayout layout1) { this.game = game; this.toolSlotSettings = toolSlotSettings; Context context = game.getContext(); - button1 = (RelativeLayout) layout.findViewById(R.id.toolbutton_1); + fadeIn = AnimationUtils.loadAnimation(game.getContext(), R.anim.fade_in); + fadeIn.setAnimationListener(this); + fadeOut = AnimationUtils.loadAnimation(game.getContext(), R.anim.fade_out); + + button1 = (RelativeLayout) layout1.findViewById(R.id.toolbutton_1); button1.setOnClickListener(this); - button2 = (RelativeLayout) layout.findViewById(R.id.toolbutton_2); + button2 = (RelativeLayout) layout1.findViewById(R.id.toolbutton_2); button2.setOnClickListener(this); - button3 = (RelativeLayout) layout.findViewById(R.id.toolbutton_3); + button3 = (RelativeLayout) layout1.findViewById(R.id.toolbutton_3); button3.setOnClickListener(this); - button4 = (RelativeLayout) layout.findViewById(R.id.toolbutton_4); + button4 = (RelativeLayout) layout1.findViewById(R.id.toolbutton_4); button4.setOnClickListener(this); buttons.add(new ToolButton(toolSlotSettings.get(0), context, button1)); buttons.add(new ToolButton(toolSlotSettings.get(1), context, button2)); @@ -45,6 +67,20 @@ public class ToolButtonBar implements View.OnClickListener { buttons.add(new ToolButton(toolSlotSettings.get(3), context, button4)); } + public void setTopPrimary(){ + button1.startAnimation(fadeIn); + button2.startAnimation(fadeIn); + button3.startAnimation(fadeIn); + button4.startAnimation(fadeIn); + } + + public void setBottomPrimary(){ + button1.startAnimation(fadeOut); + button2.startAnimation(fadeOut); + button3.startAnimation(fadeOut); + button4.startAnimation(fadeOut); +} + public void changeToolButtonTypes() { for (int i = 0; i < 4; i++) { buttons.get(i).changeToolSlot(toolSlotSettings.get(i)); @@ -61,7 +97,6 @@ public class ToolButtonBar implements View.OnClickListener { } for (ToolButton button : buttons) button.setProgress(100); - } public void update(float frameTime) { @@ -97,7 +132,7 @@ public class ToolButtonBar implements View.OnClickListener { public void onClick(View v) { if (game.getGameState() == GameState.RUNNING) { ToolType clickedType = ToolType.NONE; - if (v.equals(button1) && !buttons.get(0).isLocked() && buttons.get(0).getToolType() != ToolType.NONE) { + if (v.equals(button1)&& !buttons.get(0).isLocked() && buttons.get(0).getToolType() != ToolType.NONE) { clickedType = buttons.get(0).getToolType(); } else if (v.equals(button2) && !buttons.get(1).isLocked() && buttons.get(0).getToolType() != ToolType.NONE) { clickedType = buttons.get(1).getToolType(); diff --git a/app/src/main/java/com/example/julian/endlessroll/views/ViewManager.java b/app/src/main/java/com/example/julian/endlessroll/views/ViewManager.java index e769036..3519ff6 100644 --- a/app/src/main/java/com/example/julian/endlessroll/views/ViewManager.java +++ b/app/src/main/java/com/example/julian/endlessroll/views/ViewManager.java @@ -118,7 +118,7 @@ public class ViewManager implements View.OnClickListener { countdown.stop(); } - public void update(final boolean gameRunning, final Timer timer, final float playerX, final float playerXMov) { + public void update(final boolean gameRunning, final Timer timer, final float playerX, final float playerXMov, final float playerY) { gameViewHandler.startInUiThread(new Runnable() { @Override public void run() { diff --git a/app/src/main/java/com/example/julian/endlessroll/views/WorldButton.java b/app/src/main/java/com/example/julian/endlessroll/views/WorldButton.java index a3f404c..e6304ba 100644 --- a/app/src/main/java/com/example/julian/endlessroll/views/WorldButton.java +++ b/app/src/main/java/com/example/julian/endlessroll/views/WorldButton.java @@ -10,6 +10,7 @@ import android.widget.TextView; import com.example.julian.endlessroll.R; import com.example.julian.endlessroll.levels.LevelPack; +import com.example.julian.endlessroll.levels.worlds.World; /** * Created by Julian on 01.08.2016. @@ -17,6 +18,7 @@ import com.example.julian.endlessroll.levels.LevelPack; public class WorldButton extends RelativeLayout { private LevelPack levelPack; + private World world; private TextView title; private ImageView previewImage; @@ -27,6 +29,8 @@ public class WorldButton extends RelativeLayout { public WorldButton(Context context, Typeface typeface, View.OnClickListener clickListener, LevelPack levelPack) { super(context); this.levelPack = levelPack; + this.world = levelPack.getWorld(); + LayoutInflater inflater = LayoutInflater.from(context); inflater.inflate(R.layout.world_button, this); super.setOnClickListener(clickListener); @@ -43,10 +47,11 @@ public class WorldButton extends RelativeLayout { updateInformation(); } - public void updateInformation(){ - title.setText(levelPack.getName()); + public void updateInformation() { + title.setText(world.getName()); + previewImage.setImageDrawable(getContext().getResources().getDrawable(world.getPreviewId())); levelCount.setText(levelPack.getUnlockedLevels() + "/" + levelPack.getLevels().size()); - starCount.setText(levelPack.getCollectedStars() + "/"+levelPack.getAvailableStars()); + starCount.setText(levelPack.getCollectedStars() + "/" + levelPack.getAvailableStars()); setLockVisible(levelPack.isLocked()); } diff --git a/app/src/main/res/anim/fade_out.xml b/app/src/main/res/anim/fade_out.xml new file mode 100644 index 0000000..1bf3f51 --- /dev/null +++ b/app/src/main/res/anim/fade_out.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/worlds.xml b/app/src/main/res/layout/worlds.xml index ee19fb2..1dafdbe 100644 --- a/app/src/main/res/layout/worlds.xml +++ b/app/src/main/res/layout/worlds.xml @@ -16,7 +16,8 @@ android:layout_height="match_parent" android:layout_below="@+id/worlds_topbar" android:layout_centerHorizontal="true" - android:layout_margin="10dp" > + android:layout_marginTop="10dp" + android:layout_marginBottom="10dp"> - - - - - - - - @@ -82,6 +74,14 @@ + + + + + + + +