Guest User

Untitled

a guest
Apr 22nd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.applet.Applet;
  4. import java.applet.*;
  5. import java.util.Timer;
  6. import java.util.TimerTask;
  7. import javax.swing.*;
  8.  
  9. public class Test1 extends Applet implements KeyListener
  10. {
  11. private int yPos, xPos, height, w, width, xFire=-20, yFire=-20,c1=0,c2=180,c3=0;
  12. private boolean firing;
  13. javax.swing.Timer t = new javax.swing.Timer(100, new ActionListener() {
  14. public void actionPerformed(ActionEvent e) {
  15. repaint();
  16. }
  17. });
  18. public void init()
  19. {
  20. setBackground(Color.black);
  21. xPos = 250;
  22. yPos = 300;
  23. addKeyListener(this);
  24. }
  25.  
  26. public void paint(Graphics g)
  27. {
  28. Color c = (new Color(81, 203, 255));
  29. goodGuy(xPos, yPos, 40, 40, 1000, c, g);
  30. t.start();
  31.  
  32. }
  33.  
  34. public void keyPressed(KeyEvent evt) {
  35. int x = evt.getKeyCode();
  36. if(x==KeyEvent.VK_UP)
  37. yPos -=10;
  38. else if(x==KeyEvent.VK_DOWN)
  39. yPos+=10;
  40. else if(x==KeyEvent.VK_LEFT)
  41. xPos-=10;
  42. else if(x==KeyEvent.VK_RIGHT)
  43. xPos+=10;
  44. else if(x==32)
  45. firing=true;
  46. repaint();
  47. }
  48.  
  49. public void keyReleased(KeyEvent evt) {
  50. }
  51.  
  52. public void keyTyped(KeyEvent evt) {
  53. }
  54.  
  55. public void goodGuy(int xPos1, int yPos1, int height1, int width1, int fireRate1, Color c, Graphics g)
  56. {
  57. //delay=fireRate1;
  58. Timer timer=new Timer();
  59. g.setColor(c);
  60. xPos=xPos1;
  61. yPos=yPos1;
  62. height=height1;
  63. width=width1;
  64. g.drawOval(xPos, yPos, height, width);
  65. g.drawLine(xPos, (yPos+(height/2)), (xPos+width), (yPos+(height/2)));
  66. g.drawArc(xPos+4, yPos+4, height-8, width-8, c1, 160);
  67. g.drawArc(xPos+8, yPos+8, height-16, width-16, c2, 160);
  68. c2-=10;
  69. c1+=10;
  70. if(c2==0)
  71. c2=360;
  72. if(c1==360)
  73. c1=0;
  74. if(firing)
  75. {
  76. fire(g);
  77. }
  78. }
  79.  
  80. public void fire(Graphics g)
  81. {
  82. if(xFire==-20 && yFire==-20)
  83. {
  84. xFire=xPos;
  85. yFire=yPos;
  86. }
  87.  
  88. if(w>yFire)
  89. {
  90. w=0;
  91. xFire=-20;
  92. yFire=-20;
  93. firing=false;
  94. }
  95. g.fillArc(((int)(xPos+(width*(5/8)))), yPos, (int)(width*(1/8)), (int)(height*(1/15)), 0, 180);
  96. g.drawLine(xFire+(width/2), yFire-w, xFire+(width/2), yFire-w-3);
  97. w+=5;
  98. }
  99.  
  100. public boolean hit()
  101. {
  102. return false;
  103. }
  104. }
Add Comment
Please, Sign In to add comment