123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- package me.hammerle.supersnuvi.gamelogic;
- import java.util.Random;;
- import me.hammerle.supersnuvi.Game;
- import me.hammerle.supersnuvi.entity.Entity;
- import me.hammerle.supersnuvi.entity.EntityBuilder;
- import me.hammerle.supersnuvi.tiles.Tile;
- public final class StartScreenLevel extends Level
- {
- // level data
- private final LevelData data;
- // level stats
- private float time = 0.0f;
- // controlling
- private float heroSpawnX;
- private float heroSpawnY;
-
- public StartScreenLevel()
- {
- Entity hero = EntityBuilder.buildStartScreenHero(this, 0.0f, 0.0f);
- setHero(hero);
- spawnEntity(hero);
-
- this.data = generate();
- }
-
- // -------------------------------------------------------------------------
- // level data
- // -------------------------------------------------------------------------
-
- @Override
- public LevelData getData()
- {
- return data;
- }
-
- private void placeLamp(LevelData ld, int ox, int oy)
- {
- ox -= 2;
- oy -= 3;
- for(int x = 0; x < 5; x++)
- {
- for(int y = 0; y < 5; y++)
- {
- ld.setTile(3, ox + x, y + oy, 45 + 5 * y + x);
- }
- }
- }
-
- private LevelData generate()
- {
- int modules = 20;
- int l = 4;
- int w = modules * 10;
- int h = 50;
- int hh = h / 2;
-
- heroSpawnX = 0;
- heroSpawnY = (hh - 2) * Tile.SIZE;
- getHero().setPosition(heroSpawnX, heroSpawnY);
-
- LevelData ld = new LevelData(null, 1, l, w, h);
-
- // fill background with london background tile and clear foreground
- for(int x = 0; x < w; x++)
- {
- for(int y = 0; y < h; y++)
- {
- ld.setTile(0, x, y, 44);
- ld.setTile(3, x, y, -1);
- }
- }
-
- // base interact layer
- for(int x = 0; x < w; x++)
- {
- for(int y = 0; y < hh; y++)
- {
- ld.setTile(1, x, y, -1);
- }
- for(int y = hh; y < h; y++)
- {
- ld.setTile(1, x, y, 43);
- }
- }
-
- // generate modules
- Random r = new Random();
- // base ground for start and end
- for(int x = 0; x < 10; x++)
- {
- ld.setTile(1, x, hh, 42);
- }
- for(int x = 0; x < 10; x++)
- {
- ld.setTile(1, x + (modules - 1) * 10, hh, 42);
- }
-
- for(int i = 1; i < modules - 1; i++)
- {
- int ox = i * 10;
- switch(r.nextInt(9))
- {
- case 0:
- ld.setTile(1, ox, hh, 42);
- ld.setTile(1, ox + 1, hh, 42);
- ld.setTile(1, ox + 7, hh, 42);
- ld.setTile(1, ox + 8, hh, 42);
- ld.setTile(1, ox + 9, hh, 42);
-
- ld.setTile(1, ox + 2, hh - 1, 36);
- ld.setTile(1, ox + 3, hh - 1, 43);
- ld.setTile(1, ox + 4, hh - 1, 43);
- ld.setTile(1, ox + 5, hh - 1, 43);
- ld.setTile(1, ox + 6, hh - 1, 43);
-
- ld.setTile(1, ox + 3, hh - 2, 36);
- ld.setTile(1, ox + 4, hh - 2, 43);
- ld.setTile(1, ox + 5, hh - 2, 43);
- ld.setTile(1, ox + 6, hh - 2, 43);
-
- ld.setTile(1, ox + 4, hh - 3, 36);
- ld.setTile(1, ox + 5, hh - 3, 42);
- ld.setTile(1, ox + 6, hh - 3, 42);
-
- placeLamp(ld, ox + 5, hh - 4);
- break;
- case 1:
- ld.setTile(1, ox, hh - 1, 37);
- ld.setTile(1, ox + 1, hh - 1, 38);
- ld.setTile(1, ox + 2, hh - 1, 43);
- ld.setTile(1, ox + 3, hh - 1, 43);
- ld.setTile(1, ox + 4, hh - 1, 43);
- ld.setTile(1, ox + 5, hh - 1, 43);
- ld.setTile(1, ox + 6, hh - 1, 43);
- ld.setTile(1, ox + 7, hh - 1, 43);
- ld.setTile(1, ox + 8, hh - 1, 41);
- ld.setTile(1, ox + 9, hh - 1, 40);
-
- ld.setTile(1, ox + 2, hh - 2, 37);
- ld.setTile(1, ox + 3, hh - 2, 38);
- ld.setTile(1, ox + 4, hh - 2, 42);
- ld.setTile(1, ox + 5, hh - 2, 42);
- ld.setTile(1, ox + 6, hh - 2, 41);
- ld.setTile(1, ox + 7, hh - 2, 40);
-
- placeLamp(ld, ox + 4, hh - 3);
- break;
- case 2:
- for(int x = 0; x < 5; x++)
- {
- for(int y = 0; y < 3; y++)
- {
- ld.setTile(1, ox + x + 3, hh - y, 43);
- }
- }
-
- for(int x = 0; x < 2; x++)
- {
- for(int y = 0; y < 3; y++)
- {
- ld.setTile(1, ox + x + 6, hh - y - 3, 43);
- }
- }
-
- ld.setTile(1, ox, hh, 42);
- ld.setTile(1, ox + 1, hh, 42);
- ld.setTile(1, ox + 2, hh, 42);
- ld.setTile(1, ox + 3, hh - 3, 42);
- ld.setTile(1, ox + 4, hh - 3, 42);
- ld.setTile(1, ox + 5, hh - 3, 42);
- ld.setTile(1, ox + 6, hh - 6, 42);
- ld.setTile(1, ox + 7, hh - 6, 42);
- ld.setTile(1, ox + 8, hh, 42);
- ld.setTile(1, ox + 9, hh, 42);
-
- placeLamp(ld, ox + 3, hh - 4);
- break;
- case 3:
- ld.setTile(1, ox, hh, 42);
- ld.setTile(1, ox + 1, hh, 42);
- ld.setTile(1, ox + 2, hh + 1, 42);
- ld.setTile(1, ox + 3, hh + 1, 42);
- ld.setTile(1, ox + 4, hh + 2, 42);
- ld.setTile(1, ox + 5, hh + 2, 42);
- ld.setTile(1, ox + 6, hh + 3, 42);
- ld.setTile(1, ox + 7, hh + 3, 42);
- ld.setTile(1, ox + 8, hh, 42);
- ld.setTile(1, ox + 9, hh, 42);
-
- placeLamp(ld, ox + 6, hh + 2);
-
- for(int x = 0; x < 6; x += 2)
- {
- for(int x2 = x; x2 < 6; x2++)
- {
- ld.setTile(1, ox + x2 + 2, hh + (x / 2), -1);
- }
- }
- break;
- case 4:
- for(int x = 0; x < 10; x++)
- {
- ld.setTile(1, x + ox, hh, 42);
- }
- placeLamp(ld, ox + 5, hh - 1);
- break;
- case 5:
- for(int x = 0; x < 6; x++)
- {
- for(int y = 0; y < 4; y++)
- {
- ld.setTile(1, x + ox + 2, hh + y, -1);
- }
- }
- for(int x = 0; x < 2; x++)
- {
- for(int y = 0; y < 3; y++)
- {
- ld.setTile(1, x + ox + 4, hh + y + 4, -1);
- }
- }
- ld.setTile(1, ox, hh, 42);
- ld.setTile(1, ox + 1, hh, 42);
- ld.setTile(1, ox + 2, hh + 4, 42);
- ld.setTile(1, ox + 3, hh + 4, 42);
- ld.setTile(1, ox + 4, hh + 7, 42);
- ld.setTile(1, ox + 5, hh + 7, 42);
- ld.setTile(1, ox + 6, hh + 4, 42);
- ld.setTile(1, ox + 7, hh + 4, 42);
- ld.setTile(1, ox + 8, hh, 42);
- ld.setTile(1, ox + 9, hh, 42);
- placeLamp(ld, ox + 3, hh + 3);
- break;
- case 6:
- {
- int start = 0;
- int end = 10;
- int y = 0;
- while(start < end)
- {
- for(int x = start; x < end; x++)
- {
- ld.setTile(1, x + ox, hh - y, 43);
- }
- ld.setTile(1, start + ox, hh - y, 42);
- ld.setTile(1, end - 1 + ox, hh - y, 42);
- y++;
- start++;
- end--;
- }
- break;
- }
- case 7:
- ld.setTile(1, ox, hh, 41);
- ld.setTile(1, ox + 1, hh, 40);
- ld.setTile(1, ox + 2, hh, -1);
- ld.setTile(1, ox + 3, hh, -1);
- ld.setTile(1, ox + 4, hh, -1);
- ld.setTile(1, ox + 5, hh, -1);
- ld.setTile(1, ox + 6, hh, -1);
- ld.setTile(1, ox + 7, hh, -1);
- ld.setTile(1, ox + 8, hh, 37);
- ld.setTile(1, ox + 9, hh, 38);
-
- ld.setTile(1, ox + 2, hh + 1, 41);
- ld.setTile(1, ox + 3, hh + 1, 40);
- ld.setTile(1, ox + 4, hh + 1, -1);
- ld.setTile(1, ox + 5, hh + 1, -1);
- ld.setTile(1, ox + 6, hh + 1, 37);
- ld.setTile(1, ox + 7, hh + 1, 38);
-
- ld.setTile(1, ox + 4, hh + 2, 42);
- ld.setTile(1, ox + 5, hh + 2, 42);
-
- placeLamp(ld, ox + 4, hh + 1);
- break;
- case 8:
- for(int x = 0; x < 8; x++)
- {
- for(int y = 0; y < 7; y++)
- {
- ld.setTile(1, x + ox + 1, hh + y, -1);
- }
- }
- ld.setTile(1, ox, hh, 42);
- ld.setTile(1, ox + 9, hh, 42);
- for(int x = 1; x < 9; x++)
- {
- ld.setTile(1, ox + x, hh + 7, 42);
- }
- placeLamp(ld, ox + 4, hh + 6);
- ld.setTile(1, ox + 8, hh + 6,5);
- break;
- }
- }
-
- return ld;
- }
- @Override
- public float getTime()
- {
- return time;
- }
- // -------------------------------------------------------------------------
- // controlling
- // -------------------------------------------------------------------------
-
- @Override
- public void tick()
- {
- time += Game.SECS_PER_TICK;
- Game.get().tickTiles();
- tickEntities();
-
- if(getHero().getX() > data.getWidth() * Tile.SIZE)
- {
- getHero().setPosition(heroSpawnX, heroSpawnY);
- }
- }
- }
|