Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import java.applet.Applet;
- import java.applet.*;
- import java.util.Timer;
- import java.util.TimerTask;
- import javax.swing.*;
- public class Test1 extends Applet implements KeyListener
- {
- private int yPos, xPos, height, w, width, xFire=-20, yFire=-20,c1=0,c2=180,c3=0;
- private boolean firing;
- javax.swing.Timer t = new javax.swing.Timer(100, new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- repaint();
- }
- });
- public void init()
- {
- setBackground(Color.black);
- xPos = 250;
- yPos = 300;
- addKeyListener(this);
- }
- public void paint(Graphics g)
- {
- Color c = (new Color(81, 203, 255));
- goodGuy(xPos, yPos, 40, 40, 1000, c, g);
- t.start();
- }
- public void keyPressed(KeyEvent evt) {
- int x = evt.getKeyCode();
- if(x==KeyEvent.VK_UP)
- yPos -=10;
- else if(x==KeyEvent.VK_DOWN)
- yPos+=10;
- else if(x==KeyEvent.VK_LEFT)
- xPos-=10;
- else if(x==KeyEvent.VK_RIGHT)
- xPos+=10;
- else if(x==32)
- firing=true;
- repaint();
- }
- public void keyReleased(KeyEvent evt) {
- }
- public void keyTyped(KeyEvent evt) {
- }
- public void goodGuy(int xPos1, int yPos1, int height1, int width1, int fireRate1, Color c, Graphics g)
- {
- //delay=fireRate1;
- Timer timer=new Timer();
- g.setColor(c);
- xPos=xPos1;
- yPos=yPos1;
- height=height1;
- width=width1;
- g.drawOval(xPos, yPos, height, width);
- g.drawLine(xPos, (yPos+(height/2)), (xPos+width), (yPos+(height/2)));
- g.drawArc(xPos+4, yPos+4, height-8, width-8, c1, 160);
- g.drawArc(xPos+8, yPos+8, height-16, width-16, c2, 160);
- c2-=10;
- c1+=10;
- if(c2==0)
- c2=360;
- if(c1==360)
- c1=0;
- if(firing)
- {
- fire(g);
- }
- }
- public void fire(Graphics g)
- {
- if(xFire==-20 && yFire==-20)
- {
- xFire=xPos;
- yFire=yPos;
- }
- if(w>yFire)
- {
- w=0;
- xFire=-20;
- yFire=-20;
- firing=false;
- }
- g.fillArc(((int)(xPos+(width*(5/8)))), yPos, (int)(width*(1/8)), (int)(height*(1/15)), 0, 180);
- g.drawLine(xFire+(width/2), yFire-w, xFire+(width/2), yFire-w-3);
- w+=5;
- }
- public boolean hit()
- {
- return false;
- }
- }
Add Comment
Please, Sign In to add comment