Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //-----------------
- //
- // Circular Hitbox
- //
- //-----------------
- import java.applet.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.util.*;
- public class CircularHitbox extends Applet implements Runnable, KeyListener, MouseListener, MouseWheelListener
- {
- Random gen = new Random();
- int a = gen.nextInt(256), b = gen.nextInt(256), d = gen.nextInt(256);
- int rad = 50;
- int xDim = 500, yDim = 500, time = 20;
- Color color = new Color(a, b, d);
- Circle c = new Circle(250, 250, rad);
- Color antiColor = new Color (256 - a, 256 - b, 256 - d);
- Font font = new Font("Arial", Font.BOLD, 20);
- int mouseX = 0, mouseY = 0;
- int distance = 5000;
- int xDiff = 1000;
- int yDiff = 1000;
- Image i;
- Graphics gg;
- public CircularHitbox()
- {
- setFocusable(true);
- setFocusTraversalKeysEnabled(false);
- }
- public void init()
- {
- this.setSize(xDim, yDim);
- setBackground(Color.black);
- }
- public void start()
- {
- Thread time = new Thread(this);
- time.start();
- addKeyListener (this);
- addMouseListener (this);
- addMouseWheelListener (this);
- }
- public void stop(){}
- public void keyPressed(KeyEvent e)
- {
- if (e.getKeyCode() == KeyEvent.VK_RIGHT)
- {
- }
- }
- public void mouseWheelMoved(MouseWheelEvent e)
- {
- int notches = e.getWheelRotation();
- if (notches < 0)
- rad += 5;
- else
- rad -= 5;
- }
- public void keyTyped(KeyEvent e)
- {
- }
- public void keyReleased(KeyEvent e)
- {
- }
- public void mouseEntered(MouseEvent e)
- {
- }
- public void mouseExited(MouseEvent e)
- {
- }
- public void mouseClicked(MouseEvent e)
- {
- }
- public void mouseReleased(MouseEvent e)
- {
- }
- public void mousePressed(MouseEvent e)
- {
- xDiff = e.getX() - c.x();
- yDiff = e.getY() - c.y();
- distance = (int) Math.sqrt((Math.pow(xDiff, 2) + Math.pow(yDiff, 2)));
- if (distance < c.radius)
- {
- a = gen.nextInt(256);
- b = gen.nextInt(256);
- d = gen.nextInt(256);
- color = new Color(a, b, d);
- antiColor = new Color( 256 - a, 256 - b, 256 - d);
- if (e.getButton() == e.BUTTON1)
- {
- rad += 5;
- }
- if (e.getButton() == e.BUTTON3)
- {
- if (rad > 6)
- {
- rad -= 5;
- }
- }
- }
- }
- public void paint(Graphics g)
- {
- g.setColor(color);
- g.fillOval(c.x() - c.radius(), c.y() - c.radius(), c.diameter(), c.diameter());
- g.setFont(font);
- g.setColor(antiColor);
- g.drawString("Click Me!", xDim / 2 - 43, yDim / 2);
- }
- public void update(Graphics g){
- if(i == null){
- i = createImage(getSize().width, getSize().height);
- gg = i.getGraphics();}
- gg.setColor(getBackground());
- gg.fillRect(0,0, this.getSize().width, this.getSize().height);
- gg.setColor(getForeground());
- paint(gg);
- g.drawImage(i, 0, 0, this);
- }
- public void run()
- {
- Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
- while(true)
- {
- c.setRadius(rad);
- try
- {
- Thread.sleep(time);
- }
- catch(InterruptedException Ex){}
- repaint();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement