Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. import java.awt.Graphics;
  2. import java.awt.Graphics2D;
  3. import java.awt.Image;
  4. import java.awt.Toolkit;
  5. import java.awt.geom.AffineTransform;
  6. import java.net.URL;
  7. import java.util.ArrayList;
  8.  
  9.  
  10.  
  11. public class Colt extends Brawler {
  12. double scale;
  13. int shotTimer;
  14.  
  15. public Colt(int t, int[] p) {
  16. super(t, p);
  17. maxCharge = 4620;
  18. reloadSpeed = 1.5;
  19. maxHP = 3920;
  20. HP = maxHP;
  21. scale = 2;
  22. img = getImage("colt.png");
  23. width = 128;
  24. height = 128;
  25. //range = 7
  26. init(p[0],p[1]);
  27. }
  28.  
  29.  
  30. public void shoot(ArrayList<Bullet> bullets){
  31. ammo--;
  32. reload = reloadSpeed;
  33. inCombat = true;
  34. shotTimer = 18;
  35. }
  36. public void update(int fps, ArrayList<Bullet> bullets){
  37. if (reload>0){
  38. reload-=1/fps;
  39. if (reload==0){
  40. ammo++;
  41. if (ammo != 3) reload=reloadSpeed;
  42. }
  43. }
  44.  
  45. if (HP<=0){
  46. HP = maxHP;
  47. x = xi;
  48. y = yi;
  49. ammo = 3;
  50. init(x,y);
  51. }
  52. shotPattern(bullets);
  53.  
  54. }
  55. public void shotPattern(ArrayList<Bullet> bullets){
  56. if (shotTimer<=0) return;
  57. if (shotTimer%3==0){
  58. for (int i = 0; i < 5; i++){
  59. bullets.add(new Bullet(team,x+64,y+60,18,theta,420,2,0));
  60. }
  61. }
  62. shotTimer --;
  63. }
  64. //MOVEMENT
  65.  
  66. public void move(){
  67. tx.translate(vy*Math.cos(Math.PI/2+theta)/scale,vy*Math.sin(Math.PI/2+theta)/scale);
  68. tx.translate(vx*Math.cos(theta)/scale,vx*Math.sin(theta)/scale);
  69. x+=vx;
  70. y+=vy;
  71. }
  72.  
  73. public void spin(double a){
  74. //By @ArkyLi
  75. double oldangle = theta;
  76. theta=a;
  77. tx.rotate(oldangle-theta, width/2/scale, height/2/scale);
  78. }
  79. //DRAWING
  80. private AffineTransform tx = AffineTransform.getTranslateInstance(x, y);
  81.  
  82. // draw the affinetransform
  83. public void paint(Graphics g) {
  84. Graphics2D g2 = (Graphics2D) g;
  85. g2.drawImage(img, tx, null);
  86. }
  87.  
  88. protected void init(double a, double b) {
  89. tx.setToTranslation(a, b);
  90. tx.scale(scale, scale);
  91. }
  92.  
  93. // converts image to make it drawable in paint
  94. protected Image getImage(String path) {
  95. Image tempImage = null;
  96. try {
  97. URL imageURL = Shelly.class.getResource(path);
  98. tempImage = Toolkit.getDefaultToolkit().getImage(imageURL);
  99. } catch (Exception e) {
  100. e.printStackTrace();
  101. }
  102. return tempImage;
  103. }
  104.  
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement