StartScreenLevel.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. package me.hammerle.supersnuvi.gamelogic;
  2. import java.util.Random;;
  3. import me.hammerle.supersnuvi.Game;
  4. import me.hammerle.supersnuvi.entity.Entity;
  5. import me.hammerle.supersnuvi.entity.EntityBuilder;
  6. import me.hammerle.supersnuvi.tiles.Tile;
  7. public final class StartScreenLevel extends Level
  8. {
  9. // level data
  10. private final LevelData data;
  11. // level stats
  12. private float time = 0.0f;
  13. // controlling
  14. private float heroSpawnX;
  15. private float heroSpawnY;
  16. public StartScreenLevel()
  17. {
  18. Entity hero = EntityBuilder.buildStartScreenHero(this, 0.0f, 0.0f);
  19. setHero(hero);
  20. spawnEntity(hero);
  21. this.data = generate();
  22. }
  23. // -------------------------------------------------------------------------
  24. // level data
  25. // -------------------------------------------------------------------------
  26. @Override
  27. public LevelData getData()
  28. {
  29. return data;
  30. }
  31. private void placeLamp(LevelData ld, int ox, int oy)
  32. {
  33. ox -= 2;
  34. oy -= 3;
  35. for(int x = 0; x < 5; x++)
  36. {
  37. for(int y = 0; y < 5; y++)
  38. {
  39. ld.setTile(3, ox + x, y + oy, 45 + 5 * y + x);
  40. }
  41. }
  42. }
  43. private LevelData generate()
  44. {
  45. int modules = 20;
  46. int l = 4;
  47. int w = modules * 10;
  48. int h = 50;
  49. int hh = h / 2;
  50. heroSpawnX = 0;
  51. heroSpawnY = (hh - 2) * Tile.SIZE;
  52. getHero().setPosition(heroSpawnX, heroSpawnY);
  53. LevelData ld = new LevelData(null, 1, l, w, h);
  54. // fill background with london background tile and clear foreground
  55. for(int x = 0; x < w; x++)
  56. {
  57. for(int y = 0; y < h; y++)
  58. {
  59. ld.setTile(0, x, y, 44);
  60. ld.setTile(3, x, y, -1);
  61. }
  62. }
  63. // base interact layer
  64. for(int x = 0; x < w; x++)
  65. {
  66. for(int y = 0; y < hh; y++)
  67. {
  68. ld.setTile(1, x, y, -1);
  69. }
  70. for(int y = hh; y < h; y++)
  71. {
  72. ld.setTile(1, x, y, 43);
  73. }
  74. }
  75. // generate modules
  76. Random r = new Random();
  77. // base ground for start and end
  78. for(int x = 0; x < 10; x++)
  79. {
  80. ld.setTile(1, x, hh, 42);
  81. }
  82. for(int x = 0; x < 10; x++)
  83. {
  84. ld.setTile(1, x + (modules - 1) * 10, hh, 42);
  85. }
  86. for(int i = 1; i < modules - 1; i++)
  87. {
  88. int ox = i * 10;
  89. switch(r.nextInt(9))
  90. {
  91. case 0:
  92. ld.setTile(1, ox, hh, 42);
  93. ld.setTile(1, ox + 1, hh, 42);
  94. ld.setTile(1, ox + 7, hh, 42);
  95. ld.setTile(1, ox + 8, hh, 42);
  96. ld.setTile(1, ox + 9, hh, 42);
  97. ld.setTile(1, ox + 2, hh - 1, 36);
  98. ld.setTile(1, ox + 3, hh - 1, 43);
  99. ld.setTile(1, ox + 4, hh - 1, 43);
  100. ld.setTile(1, ox + 5, hh - 1, 43);
  101. ld.setTile(1, ox + 6, hh - 1, 43);
  102. ld.setTile(1, ox + 3, hh - 2, 36);
  103. ld.setTile(1, ox + 4, hh - 2, 43);
  104. ld.setTile(1, ox + 5, hh - 2, 43);
  105. ld.setTile(1, ox + 6, hh - 2, 43);
  106. ld.setTile(1, ox + 4, hh - 3, 36);
  107. ld.setTile(1, ox + 5, hh - 3, 42);
  108. ld.setTile(1, ox + 6, hh - 3, 42);
  109. placeLamp(ld, ox + 5, hh - 4);
  110. break;
  111. case 1:
  112. ld.setTile(1, ox, hh - 1, 37);
  113. ld.setTile(1, ox + 1, hh - 1, 38);
  114. ld.setTile(1, ox + 2, hh - 1, 43);
  115. ld.setTile(1, ox + 3, hh - 1, 43);
  116. ld.setTile(1, ox + 4, hh - 1, 43);
  117. ld.setTile(1, ox + 5, hh - 1, 43);
  118. ld.setTile(1, ox + 6, hh - 1, 43);
  119. ld.setTile(1, ox + 7, hh - 1, 43);
  120. ld.setTile(1, ox + 8, hh - 1, 41);
  121. ld.setTile(1, ox + 9, hh - 1, 40);
  122. ld.setTile(1, ox + 2, hh - 2, 37);
  123. ld.setTile(1, ox + 3, hh - 2, 38);
  124. ld.setTile(1, ox + 4, hh - 2, 42);
  125. ld.setTile(1, ox + 5, hh - 2, 42);
  126. ld.setTile(1, ox + 6, hh - 2, 41);
  127. ld.setTile(1, ox + 7, hh - 2, 40);
  128. placeLamp(ld, ox + 4, hh - 3);
  129. break;
  130. case 2:
  131. for(int x = 0; x < 5; x++)
  132. {
  133. for(int y = 0; y < 3; y++)
  134. {
  135. ld.setTile(1, ox + x + 3, hh - y, 43);
  136. }
  137. }
  138. for(int x = 0; x < 2; x++)
  139. {
  140. for(int y = 0; y < 3; y++)
  141. {
  142. ld.setTile(1, ox + x + 6, hh - y - 3, 43);
  143. }
  144. }
  145. ld.setTile(1, ox, hh, 42);
  146. ld.setTile(1, ox + 1, hh, 42);
  147. ld.setTile(1, ox + 2, hh, 42);
  148. ld.setTile(1, ox + 3, hh - 3, 42);
  149. ld.setTile(1, ox + 4, hh - 3, 42);
  150. ld.setTile(1, ox + 5, hh - 3, 42);
  151. ld.setTile(1, ox + 6, hh - 6, 42);
  152. ld.setTile(1, ox + 7, hh - 6, 42);
  153. ld.setTile(1, ox + 8, hh, 42);
  154. ld.setTile(1, ox + 9, hh, 42);
  155. placeLamp(ld, ox + 3, hh - 4);
  156. break;
  157. case 3:
  158. ld.setTile(1, ox, hh, 42);
  159. ld.setTile(1, ox + 1, hh, 42);
  160. ld.setTile(1, ox + 2, hh + 1, 42);
  161. ld.setTile(1, ox + 3, hh + 1, 42);
  162. ld.setTile(1, ox + 4, hh + 2, 42);
  163. ld.setTile(1, ox + 5, hh + 2, 42);
  164. ld.setTile(1, ox + 6, hh + 3, 42);
  165. ld.setTile(1, ox + 7, hh + 3, 42);
  166. ld.setTile(1, ox + 8, hh, 42);
  167. ld.setTile(1, ox + 9, hh, 42);
  168. placeLamp(ld, ox + 6, hh + 2);
  169. for(int x = 0; x < 6; x += 2)
  170. {
  171. for(int x2 = x; x2 < 6; x2++)
  172. {
  173. ld.setTile(1, ox + x2 + 2, hh + (x / 2), -1);
  174. }
  175. }
  176. break;
  177. case 4:
  178. for(int x = 0; x < 10; x++)
  179. {
  180. ld.setTile(1, x + ox, hh, 42);
  181. }
  182. placeLamp(ld, ox + 5, hh - 1);
  183. break;
  184. case 5:
  185. for(int x = 0; x < 6; x++)
  186. {
  187. for(int y = 0; y < 4; y++)
  188. {
  189. ld.setTile(1, x + ox + 2, hh + y, -1);
  190. }
  191. }
  192. for(int x = 0; x < 2; x++)
  193. {
  194. for(int y = 0; y < 3; y++)
  195. {
  196. ld.setTile(1, x + ox + 4, hh + y + 4, -1);
  197. }
  198. }
  199. ld.setTile(1, ox, hh, 42);
  200. ld.setTile(1, ox + 1, hh, 42);
  201. ld.setTile(1, ox + 2, hh + 4, 42);
  202. ld.setTile(1, ox + 3, hh + 4, 42);
  203. ld.setTile(1, ox + 4, hh + 7, 42);
  204. ld.setTile(1, ox + 5, hh + 7, 42);
  205. ld.setTile(1, ox + 6, hh + 4, 42);
  206. ld.setTile(1, ox + 7, hh + 4, 42);
  207. ld.setTile(1, ox + 8, hh, 42);
  208. ld.setTile(1, ox + 9, hh, 42);
  209. placeLamp(ld, ox + 3, hh + 3);
  210. break;
  211. case 6:
  212. {
  213. int start = 0;
  214. int end = 10;
  215. int y = 0;
  216. while(start < end)
  217. {
  218. for(int x = start; x < end; x++)
  219. {
  220. ld.setTile(1, x + ox, hh - y, 43);
  221. }
  222. ld.setTile(1, start + ox, hh - y, 42);
  223. ld.setTile(1, end - 1 + ox, hh - y, 42);
  224. y++;
  225. start++;
  226. end--;
  227. }
  228. break;
  229. }
  230. case 7:
  231. ld.setTile(1, ox, hh, 41);
  232. ld.setTile(1, ox + 1, hh, 40);
  233. ld.setTile(1, ox + 2, hh, -1);
  234. ld.setTile(1, ox + 3, hh, -1);
  235. ld.setTile(1, ox + 4, hh, -1);
  236. ld.setTile(1, ox + 5, hh, -1);
  237. ld.setTile(1, ox + 6, hh, -1);
  238. ld.setTile(1, ox + 7, hh, -1);
  239. ld.setTile(1, ox + 8, hh, 37);
  240. ld.setTile(1, ox + 9, hh, 38);
  241. ld.setTile(1, ox + 2, hh + 1, 41);
  242. ld.setTile(1, ox + 3, hh + 1, 40);
  243. ld.setTile(1, ox + 4, hh + 1, -1);
  244. ld.setTile(1, ox + 5, hh + 1, -1);
  245. ld.setTile(1, ox + 6, hh + 1, 37);
  246. ld.setTile(1, ox + 7, hh + 1, 38);
  247. ld.setTile(1, ox + 4, hh + 2, 42);
  248. ld.setTile(1, ox + 5, hh + 2, 42);
  249. placeLamp(ld, ox + 4, hh + 1);
  250. break;
  251. case 8:
  252. for(int x = 0; x < 8; x++)
  253. {
  254. for(int y = 0; y < 7; y++)
  255. {
  256. ld.setTile(1, x + ox + 1, hh + y, -1);
  257. }
  258. }
  259. ld.setTile(1, ox, hh, 42);
  260. ld.setTile(1, ox + 9, hh, 42);
  261. for(int x = 1; x < 9; x++)
  262. {
  263. ld.setTile(1, ox + x, hh + 7, 42);
  264. }
  265. placeLamp(ld, ox + 4, hh + 6);
  266. ld.setTile(1, ox + 8, hh + 6,5);
  267. break;
  268. }
  269. }
  270. return ld;
  271. }
  272. @Override
  273. public float getTime()
  274. {
  275. return time;
  276. }
  277. // -------------------------------------------------------------------------
  278. // controlling
  279. // -------------------------------------------------------------------------
  280. @Override
  281. public void tick()
  282. {
  283. time += Game.SECS_PER_TICK;
  284. Game.get().tickTiles();
  285. tickEntities();
  286. if(getHero().getX() > data.getWidth() * Tile.SIZE)
  287. {
  288. getHero().setPosition(heroSpawnX, heroSpawnY);
  289. }
  290. }
  291. }