Erkunng des Triggertypes zum gegeben x und y Wertes

This commit is contained in:
Armin Benz 2017-04-18 20:02:13 +02:00
parent 7bb50b7275
commit 28f1b4d1de
7 changed files with 100 additions and 54 deletions

View File

@ -249,7 +249,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -749,7 +749,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -1249,7 +1249,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -1749,7 +1749,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -2249,7 +2249,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -2749,7 +2749,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -3249,7 +3249,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -3749,7 +3749,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -4249,7 +4249,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -4749,7 +4749,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -5249,7 +5249,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -5749,7 +5749,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -6249,7 +6249,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -6749,7 +6749,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -7249,7 +7249,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -7749,7 +7749,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -8249,7 +8249,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -8749,7 +8749,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -9249,7 +9249,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -10253,7 +10253,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -10753,7 +10753,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -11253,7 +11253,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -11753,7 +11753,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -12253,7 +12253,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -12753,7 +12753,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -13253,7 +13253,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -13753,7 +13753,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -14253,7 +14253,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -14753,7 +14753,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -15253,7 +15253,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -15753,7 +15753,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -16253,7 +16253,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -16753,7 +16753,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -17253,7 +17253,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -17753,7 +17753,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -18253,7 +18253,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -18753,7 +18753,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
@ -19253,7 +19253,7 @@
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="18"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>

View File

@ -22,9 +22,9 @@ public class CRTiledMap {
public final static int GID_RIGHT = 24;
public final static int GID_DOWN = 33;
public final static int GID_LEFT = 22;
public final static int GID_INTER_UP = 16;
public final static int GID_INTER_DOWN = 17;
public final static int GID_INTER_RIGHT = 18;
public final static int GID_INTER_UP = 18;
public final static int GID_INTER_DOWN = 19;
public final static int GID_INTER_RIGHT = 20;
public int width;
public int height;

View File

@ -1,14 +1,18 @@
package de.samdev.colorrunner.game.world.map;
public class MapSection {
public float start;
public float end;
public int start;
public int end;
public String piece_name;
public CRTiledMap crTiledMap = new CRTiledMap();
public MapSection(float x, float width, String name) {
public MapSection(int x, int width, String name, CRTiledMap crTiledMap) {
start = x;
end = x + width;
piece_name = name;
this.crTiledMap = crTiledMap;
}
}

View File

@ -19,7 +19,7 @@ public class EndlessMapProvider extends MapProvider {
private final Random random;
public List<MapSection> sections;
private float mapRightBoundary = 0;
private int mapRightBoundary = 0;
public EndlessMapProvider(long seed) {
random = new Random(seed);
@ -28,7 +28,7 @@ public class EndlessMapProvider extends MapProvider {
@Override
public void init(CRGameWorld world) {
sections = new ArrayList<MapSection>();
mapRightBoundary = appendMap(world, CRMapStorage.map_start, new Vector2(0, 0));
mapRightBoundary = appendMap(world, CRMapStorage.map_start, 0);
}
@Override
@ -36,6 +36,28 @@ public class EndlessMapProvider extends MapProvider {
return true;
}
@Override
public TriggerType getTrigger(int x, int y) {
for(int i = sections.size()-1; i >= 0; i--)
{
int start = sections.get(i).start;
int end = sections.get(i).end;
if(start <= x && end > x){
if( sections.get(i).crTiledMap.interaktionen[x - start][y] == CRTiledMap.GID_INTER_UP)
return TriggerType.RUNTOP;
else if( sections.get(i).crTiledMap.interaktionen[x - start][y] == CRTiledMap.GID_INTER_DOWN)
return TriggerType.RUNTOP;
else if( sections.get(i).crTiledMap.interaktionen[x - start][y] == CRTiledMap.GID_INTER_RIGHT)
return TriggerType.FLY;
else
return TriggerType.NOTHING;
}
}
return TriggerType.NOTHING;
}
@Override
public MapProvider createNew() {
EndlessMapProvider endlessMapProvider = new EndlessMapProvider(System.currentTimeMillis());
@ -45,29 +67,29 @@ public class EndlessMapProvider extends MapProvider {
@Override
public void update(CRGameWorld world, Rectangle player)
{
while (player.x + AbstractGameRenderer.MAX_GAME_WIDTH*2 > mapRightBoundary) {
float width = appendMap(world, CRMapStorage.getMap(random), new Vector2(mapRightBoundary, 0));
while (player.x + AbstractGameRenderer.MAX_GAME_WIDTH*2 > mapRightBoundary * FloorTileEntity.FLOORTILE_WIDTH) {
float width = appendMap(world, CRMapStorage.getMap(random), mapRightBoundary);
mapRightBoundary += width;
}
}
private float appendMap(CRGameWorld world, CRTiledMap map, Vector2 pos) {
private int appendMap(CRGameWorld world, CRTiledMap map, int posX) {
int height = map.getHeight();
int width = map.getWidth();
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
float px = pos.x + x * FloorTileEntity.FLOORTILE_WIDTH;
float py = pos.y + (height - y) * FloorTileEntity.FLOORTILE_WIDTH;
float px = posX * FloorTileEntity.FLOORTILE_WIDTH + x * FloorTileEntity.FLOORTILE_WIDTH;
float py = (height - y) * FloorTileEntity.FLOORTILE_WIDTH;
CRGameEntity e = CRTiledMap.CreateTile(world, map.getGID(x, y), px, py);
if (e != null) world.addEntity(e);
}
}
sections.add(new MapSection(pos.x, width * FloorTileEntity.FLOORTILE_WIDTH, map.name));
sections.add(new MapSection(posX, width, map.name, map));
return width * FloorTileEntity.FLOORTILE_WIDTH;
return width;
}
public MapSection getCurrentSection(Rectangle player) {
@ -76,6 +98,6 @@ public class EndlessMapProvider extends MapProvider {
return sec;
}
return new MapSection(0, 0, "NULL");
return new MapSection(0, 0, "NULL", null);
}
}

View File

@ -13,4 +13,6 @@ public abstract class MapProvider {
public abstract boolean isNextEndlessMenu();
public abstract MapProvider createNew();
public abstract Enum<TriggerType> getTrigger(int x, int y);
}

View File

@ -28,6 +28,18 @@ public class StaticMapProvider extends MapProvider {
return false;
}
@Override
public TriggerType getTrigger(int x, int y) {
if(map.interaktionen[x][y] == CRTiledMap.GID_INTER_UP)
return TriggerType.RUNTOP;
else if(map.interaktionen[x][y] == CRTiledMap.GID_INTER_DOWN)
return TriggerType.RUNBOTTOM;
else if(map.interaktionen[x][y] == CRTiledMap.GID_INTER_RIGHT)
return TriggerType.FLY;
else
return TriggerType.NOTHING;
}
@Override
public MapProvider createNew() {
StaticMapProvider mapProvider = new StaticMapProvider(map);

View File

@ -0,0 +1,6 @@
package de.samdev.colorrunner.game.world.map.provider;
public enum TriggerType
{
RUNBOTTOM, RUNTOP, FLY, NOTHING
}