Advertisement
Slyth

Untitled

Jan 25th, 2013
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.96 KB | None | 0 0
  1. Tower Class:
  2.  
  3. package Engine;
  4.  
  5. import java.awt.Color;
  6. import java.awt.Graphics;
  7. import java.awt.Graphics2D;
  8. import java.awt.geom.Ellipse2D;
  9.  
  10. public class Tower {
  11.  
  12.     public int x, y, pixX, pixY, id, id1, id2, id3;
  13.     public int width = Screen.room.blockSize;
  14.     public int height = Screen.room.blockSize;
  15.     public int looseTime = 8000, looseFrame = 0;
  16.     public int shotMob = -1;
  17.     public int towerCircleSize = 130;
  18.     public int resalePrice;
  19.     public int slope;
  20.     public int damage;
  21.  
  22.     public int targetX;
  23.     public int targetY;
  24.  
  25.     public long lastIterationTime;
  26.     public int delayTime;
  27.     public int currentAnimationIndex;
  28.  
  29.     public long shotInterval;
  30.  
  31.     public double continuousDamage = 0;
  32.     public int hitDamage;
  33.  
  34.     public int[] radiusUpgradePrice = new int[3];
  35.     public int[] damageUpgradePrice = new int[3];
  36.     public int[] speedUpgradePrice = new int[3];
  37.     public int[] damageUpgradeAmount = new int[3];
  38.     public int urPrice;
  39.     public int udPrice;
  40.     public int usPrice;
  41.     public int offset = 1;
  42.  
  43.     public static int callCircleSize;
  44.  
  45.     public boolean shooting = false;
  46.     public boolean drawRadius = false;
  47.     public boolean inGame = false;
  48.     public boolean animated = false;
  49.  
  50.     public boolean upgradeRadiiFirst = false;
  51.     public boolean upgradeRadiiSecond = false;
  52.     public boolean upgradeRadiiThird = false;
  53.  
  54.     public boolean upgradeDamageFirst = false;
  55.     public boolean upgradeDamageSecond = false;
  56.     public boolean upgradeDamageThird = false;
  57.  
  58.     public boolean upgradeSpeedFirst = false;
  59.     public boolean upgradeSpeedSecond = false;
  60.     public boolean upgradeSpeedThird = false;
  61.  
  62.     public Ellipse2D.Double circle;
  63.  
  64.     public Tower() {
  65.  
  66.     }
  67.  
  68.     public void drawTowerAt(int x, int y, int pixX, int pixY, Tower tower) {
  69.         Screen.room.block[y][x].airID = id;
  70.         if (Screen.room.towers[y][x] == null) {
  71.             Screen.room.towers[y][x] = tower;
  72.             inGame = true;
  73.         }
  74.         this.x = x;
  75.         this.y = y;
  76.         this.pixX = pixX;
  77.         this.pixY = pixY;
  78.         circle = new Ellipse2D.Double(pixX - (towerCircleSize / 2), pixY - (towerCircleSize / 2), width + (towerCircleSize), height + (towerCircleSize));
  79.     }
  80.  
  81.     public void fight(Graphics g) {
  82.  
  83.     }
  84.  
  85.     public void setDamage(int dmg) {
  86.         damage = dmg;
  87.     }
  88.  
  89.     public void setDamageUpgradeAmount(int d1, int d2, int d3) {
  90.         damageUpgradeAmount[0] = d1;
  91.         damageUpgradeAmount[1] = d2;
  92.         damageUpgradeAmount[2] = d3;
  93.     }
  94.  
  95.     public void setAnimated(boolean animated) {
  96.         this.animated = animated;
  97.     }
  98.  
  99.     public void setResalePrice(int price) {
  100.         this.resalePrice = price;
  101.     }
  102.  
  103.     public void setTowerId(int id) {
  104.         this.id = id;
  105.     }
  106.  
  107.     public void setTowerId(int id1, int id2, int id3) {
  108.         this.id = id1;
  109.         this.id1 = id1;
  110.         this.id2 = id2;
  111.         this.id3 = id3;
  112.     }
  113.  
  114.     public void setRadius(int radius) {
  115.         towerCircleSize = radius;
  116.         callCircleSize = radius;
  117.     }
  118.  
  119.     public void physic() {
  120.  
  121.     }
  122.  
  123.     public void getMoney(int mobID) {
  124.         Screen.coinage += Value.deathReward[mobID];
  125.     }
  126.  
  127.     public void draw(Graphics g) {
  128.         if (animated) {
  129.             if ((System.currentTimeMillis() - lastIterationTime) >= (delayTime)) {
  130.                 lastIterationTime = System.currentTimeMillis();
  131.                 currentAnimationIndex = (currentAnimationIndex + 1) % Screen.room.towers.length;
  132.                 if (id == id1) {
  133.                     id = id2;
  134.                 } else if (id == id2) {
  135.                     id = id3;
  136.                 } else if (id == id3) {
  137.                     id = id1;
  138.                 }
  139.                 Screen.room.block[y][x].airID = id;
  140.             }
  141.         }
  142.  
  143.         if (Screen.room.block[y][x].contains(Screen.mscf) && !Screen.isDrawingGui) {
  144.             drawRadius(true);
  145.             Screen.hasSelectedTower = true;
  146.             Screen.selectedTower = this;
  147.             Block.drawFixedOutline = true;
  148.             Block.drawFixedOutline(x, y, g);
  149.             Screen.upgrades.setSelectedTower(this);
  150.         } else {
  151.             Screen.hasSelectedTower = false;
  152.             Screen.selectedTower = null;
  153.             drawRadius(false);
  154.             Block.drawFixedOutline = false;
  155.         }
  156.  
  157.         if (Screen.room.block[y][x].contains(Screen.mse) && drawRadius) {
  158.             Block.drawOutline = false;
  159.         } else {
  160.             Block.drawOutline = true;
  161.         }
  162.  
  163.         if (drawRadius) {
  164.             g.setColor(Color.BLACK);
  165.             g.drawOval((int) circle.x, (int) circle.y, (int) circle.width, (int) circle.height);
  166.         }
  167.  
  168.         Graphics2D g2d = (Graphics2D) g.create();
  169.  
  170.         double angle = Math.atan2(targetY - pixY, targetX - pixX) * 180 / Math.PI;
  171.         g2d.translate(pixX, pixY);
  172.         g2d.rotate(angle);
  173.         g2d.drawImage(Screen.tileset_air[id], 0, 0, Screen.room.blockSize, Screen.room.blockSize, null);
  174.         // g2d.drawImage(Screen.tileset_air[id], pixX, pixY,
  175.         // Screen.room.blockSize, Screen.room.blockSize, null);
  176.         // g2d.dispose();
  177.  
  178.         circle = new Ellipse2D.Double(circle.x, circle.y, width + (towerCircleSize), height + (towerCircleSize));
  179.     }
  180.  
  181.     public void drawRadius(boolean choice) {
  182.         if (choice) {
  183.             drawRadius = true;
  184.         } else {
  185.             drawRadius = false;
  186.         }
  187.     }
  188.  
  189.     public void setFirstUpgradePrice(int first, int second, int third) {
  190.         radiusUpgradePrice[0] = first;
  191.         radiusUpgradePrice[1] = second;
  192.         radiusUpgradePrice[2] = third;
  193.         urPrice = first;
  194.     }
  195.  
  196.     public void setSecondUpgradePrice(int first, int second, int third) {
  197.         damageUpgradePrice[0] = first;
  198.         damageUpgradePrice[1] = second;
  199.         damageUpgradePrice[2] = third;
  200.         udPrice = first;
  201.     }
  202.  
  203.     public void sell() {
  204.         Screen.coinage += resalePrice;
  205.         Screen.room.block[y][x].airID = Value.airAir;
  206.         Screen.room.towers[y][x] = null;
  207.     }
  208.  
  209.     public int getRadius() {
  210.         return towerCircleSize;
  211.     }
  212.  
  213.     public void upgradeRadius() {
  214.         if (Screen.coinage >= urPrice) {
  215.             if (!upgradeRadiiFirst) {
  216.                 upgradeRadiiFirst = true;
  217.                 towerCircleSize += 20;
  218.                 offset += 10;
  219.                 circle.x -= offset;
  220.                 circle.y -= offset;
  221.                 Screen.coinage -= radiusUpgradePrice[0];
  222.                 urPrice = radiusUpgradePrice[1];
  223.                 Screen.upgrades.resalePrice = resalePrice;
  224.                 resalePrice += 3;
  225.                 return;
  226.             } else if (!upgradeRadiiSecond) {
  227.                 upgradeRadiiSecond = true;
  228.                 towerCircleSize += 20;
  229.                 circle.x -= offset;
  230.                 circle.y -= offset;
  231.                 urPrice = radiusUpgradePrice[2];
  232.                 Screen.upgrades.resalePrice = resalePrice;
  233.                 Screen.coinage -= radiusUpgradePrice[1];
  234.                 resalePrice += 4;
  235.                 return;
  236.             } else if (!upgradeRadiiThird) {
  237.                 upgradeRadiiThird = true;
  238.                 towerCircleSize += 20;
  239.                 circle.x -= offset;
  240.                 circle.y -= offset;
  241.                 urPrice = 0;
  242.                 Screen.upgrades.resalePrice = resalePrice;
  243.                 Screen.coinage -= radiusUpgradePrice[2];
  244.                 resalePrice += 4;
  245.                 return;
  246.             }
  247.         }
  248.     }
  249.  
  250.     public void upgradeDamage() {
  251.         if (Screen.coinage >= udPrice) {
  252.             if (!upgradeDamageFirst) {
  253.                 upgradeDamageFirst = true;
  254.                 continuousDamage += .58;
  255.                 damage = damageUpgradeAmount[0];
  256.                 Screen.coinage -= damageUpgradePrice[0];
  257.                 udPrice = damageUpgradePrice[1];
  258.                 delayTime -= 100;
  259.                 resalePrice += 3;
  260.                 return;
  261.             } else if (!upgradeDamageSecond) {
  262.                 upgradeDamageSecond = true;
  263.                 continuousDamage += .58;
  264.                 damage = damageUpgradeAmount[1];
  265.                 Screen.coinage -= damageUpgradePrice[1];
  266.                 udPrice = damageUpgradePrice[2];
  267.                 delayTime -= 100;
  268.                 resalePrice += 4;
  269.                 return;
  270.             } else if (!upgradeDamageThird) {
  271.                 upgradeDamageThird = true;
  272.                 continuousDamage += .58;
  273.                 damage = damageUpgradeAmount[2];
  274.                 Screen.coinage -= damageUpgradePrice[2];
  275.                 udPrice = 0;
  276.                 delayTime -= 100;
  277.                 resalePrice += 4;
  278.                 return;
  279.             }
  280.         }
  281.     }
  282.  
  283.     public void upgradeSpeed() {
  284.         if (Screen.coinage >= udPrice && continuousDamage == 0) {
  285.             if (!upgradeSpeedFirst) {
  286.                 upgradeSpeedFirst = true;
  287.                 shotInterval += 1;
  288.                 Screen.coinage -= speedUpgradePrice[0];
  289.                 udPrice = speedUpgradePrice[1];
  290.                 delayTime -= 100;
  291.                 resalePrice += 3;
  292.                 return;
  293.             } else if (!upgradeSpeedSecond) {
  294.                 upgradeSpeedSecond = true;
  295.                 shotInterval += 1;
  296.                 Screen.coinage -= speedUpgradePrice[1];
  297.                 udPrice = speedUpgradePrice[2];
  298.                 delayTime -= 100;
  299.                 resalePrice += 4;
  300.                 return;
  301.             } else if (!upgradeSpeedThird) {
  302.                 upgradeSpeedThird = true;
  303.                 shotInterval += 1;
  304.                 Screen.coinage -= speedUpgradePrice[2];
  305.                 udPrice = 0;
  306.                 delayTime -= 100;
  307.                 resalePrice += 4;
  308.                 return;
  309.             }
  310.         }
  311.     }
  312.  
  313.     public void updateImage(int id) {
  314.         Screen.room.block[y][x].airID = id;
  315.     }
  316. }
  317.  
  318.  
  319. TowerCannon class:
  320.  
  321. package Engine;
  322.  
  323. import java.awt.Graphics;
  324.  
  325. public class TowerCannon extends Tower {
  326.  
  327.     public int fTime = 0;
  328.     public int sTime = 200;
  329.  
  330.     int xPos = (int) Screen.room.block[y][x].x;
  331.     int yPos = (int) Screen.room.block[y][x].y;
  332.  
  333.     public TowerCannon(int x, int y) {
  334.         setRadius(200);
  335.         setDamage(10);
  336.         setDamageUpgradeAmount(14, 16, 18);
  337.         setTowerId(Value.airTowerCannonUp);
  338.         setResalePrice(10);
  339.         setFirstUpgradePrice(5, 10, 15);
  340.         setSecondUpgradePrice(5, 10, 15);
  341.         drawTowerAt(x, y, Screen.room.block[y][x].x, Screen.room.block[y][x].y, this);
  342.     }
  343.  
  344.     public void fight(Graphics g) {
  345.         if (shooting && !Screen.mobs[shotMob].isDead() && Screen.inGame) {
  346.             if (fTime >= sTime) {
  347.                 if (Screen.gameSpeed == 3) {
  348.                     sTime = 200;
  349.                 } else {
  350.                     sTime = 67;
  351.                 }
  352.                 shoot(g);
  353.                 fTime = 0;
  354.             } else {
  355.                 fTime++;
  356.             }
  357.         }
  358.     }
  359.  
  360.     @Override
  361.     public void physic() {
  362.         if (shooting) {
  363.             for (int i = 0; i < Screen.mobs.length; i++) {
  364.                 if (Screen.mobs[i].inGame) {
  365.                     if (Screen.mobs[i] != null && circle != null) {
  366.                         targetX = Screen.mobs[i].x;
  367.                         targetY = Screen.mobs[i].y;
  368.  
  369.                         /*
  370.                          * if (targetY == x && targetX > x)
  371.                          * updateImage(Value.airTowerCannonRight); if (targetY
  372.                          * == y && x > targetX)
  373.                          * updateImage(Value.airTowerCannonLeft);
  374.                          */
  375.                     }
  376.                 }
  377.             }
  378.         }
  379.  
  380.         if (shotMob != -1 && circle.intersects(Screen.mobs[shotMob])) {
  381.             shooting = true;
  382.         } else {
  383.             shooting = false;
  384.         }
  385.  
  386.         if (!shooting) {
  387.             if (Screen.room.block[y][x].airID == id) {
  388.                 for (int i = 0; i < Screen.mobs.length; i++) {
  389.                     if (Screen.mobs[i].inGame) {
  390.                         if (Screen.mobs[i] != null && circle != null) {
  391.                             if (circle.intersects(Screen.mobs[i])) {
  392.                                 shooting = true;
  393.                                 shotMob = i;
  394.                             }
  395.                         }
  396.                     }
  397.                 }
  398.             }
  399.         }
  400.     }
  401.  
  402.     public void shoot(Graphics g) {
  403.         new CannonBall(shotMob, Screen.mobs[shotMob].x, Screen.mobs[shotMob].y, this, g);
  404.     }
  405. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement