Advertisement
Guest User

TinyTowerSquad

a guest
Dec 5th, 2014
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. static int _WIDTH = 640; // set me
  2.  
  3. //Auto Generated from _WIDTH ---
  4. static int _HEIGHT = (int)(_WIDTH * .8);
  5. static float playWindowHeight = _WIDTH * .65;
  6. static float cellSize = _WIDTH/20;
  7. static float menuPosY = playWindowHeight + 1;
  8. static float menuHeight = _HEIGHT - menuPosY;
  9. float lives = 5;
  10. //--------------
  11.  
  12. Cell[][] Grid = new Cell[20][13];
  13. PImage[] TowerSprites;
  14. CreepSprite[] CreepSprites;
  15.  
  16. PImage field;
  17. PImage path;
  18. PImage pathMask;
  19.  
  20. Cell hoverCell = null;
  21.  
  22. //Level Variables---
  23. Path Level;
  24. //Gameplay Variables----
  25. ArrayList<Tower> AllTowers = new ArrayList<Tower>();
  26. ArrayList<Creep> AllCreeps = new ArrayList<Creep>();
  27. //------------------
  28.  
  29. void setup() {
  30. size(_WIDTH, _HEIGHT);
  31.  
  32. //initialize Grid ---
  33. for (int x = 0; x < Grid.length; x++) {
  34. for (int y = 0; y < Grid[0].length; y++) {
  35. Grid[x][y] = new Cell(x, y);
  36. }
  37. }
  38. //--------
  39.  
  40. field = loadImage("grass.png");
  41. path = loadImage("dirt.png");
  42. pathMask = loadImage("dirt-mask2.png");
  43. path.mask(pathMask);
  44.  
  45. TowerSprites = new PImage[] {
  46. loadImage("towers/t1.png"),
  47. //more sprites
  48. };
  49.  
  50. CreepSprites = new CreepSprite[] {
  51. new CreepSprite("gob"),
  52. new CreepSprite("ticky"),
  53. };
  54.  
  55. Vector[] _path = new Vector[] {
  56. new Vector(0, 5),
  57. new Vector(3, 5),
  58. new Vector(3, 8),
  59. new Vector(1, 8),
  60. new Vector(1, 11),
  61. new Vector(9, 11),
  62. new Vector(9, 8),
  63. new Vector(6, 8),
  64. new Vector(6, 3),
  65. new Vector(10, 3),
  66. new Vector(10, 5),
  67. new Vector(11, 5),
  68. new Vector(11, 10),
  69. new Vector(14, 10),
  70. new Vector(14, 8),
  71. new Vector(17, 8),
  72. new Vector(17, 5),
  73. new Vector(13, 5),
  74. new Vector(13, 0),
  75. };
  76.  
  77. Level = new Path(_path);
  78.  
  79. setUnbuildable(new Vector(0, 0));
  80. setUnbuildable(new Vector(1, 0));
  81. setUnbuildable(new Vector(1, 2));
  82. setUnbuildable(new Vector(0, 2));
  83. setUnbuildable(new Vector(0, 3));
  84. }
  85.  
  86. void draw() {
  87. image(field, 0, 0, width, playWindowHeight);
  88. image(path, 0, 0, width, playWindowHeight);
  89.  
  90. for (int i = 0; i < AllTowers.size(); i++) {
  91. AllTowers.get(i).drawMe();
  92. }
  93.  
  94. for (int i = 0; i < AllCreeps.size(); i++) AllCreeps.get(i).move();
  95.  
  96. mouseCheck();
  97. }
  98.  
  99. void mouseCheck() {
  100. int x = (int)(mouseX / cellSize);
  101. int y = (int)(mouseY / cellSize);
  102.  
  103. if (x < Grid.length && y < Grid[0].length) {
  104. hoverCell = Grid[x][y];
  105. hoverCell.outlineMe();
  106. }
  107. }
  108.  
  109. void keyPressed() {
  110. if (key == 'a') AllCreeps.add(new Creep(0));
  111. else if (key == 's') AllCreeps.add(new Creep(1));
  112. }
  113.  
  114. void mousePressed() {
  115. if (hoverCell != null) {
  116. println("new Vector(" + hoverCell.x + ", " + hoverCell.y + "),");
  117. if (hoverCell.buildable()) hoverCell.buildOn(new Tower(hoverCell.x, hoverCell.y, 0));
  118. }
  119. }
  120.  
  121.  
  122. void setUnbuildable(Vector v) {
  123. Grid[v.x][v.y].isPath = true;
  124. }
  125.  
  126. void leak(Creep c) {
  127. AllCreeps.remove(c);
  128. println("A creep has leaked!");
  129.  
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement