Package plar.core

Examples of plar.core.KeyFlag


            ElementPlayer p = (ElementPlayer) me;
            int r = (int) (Math.random() * 250);
            switch (r) {
            case 1:

                p.actions.forceAction("input", new KeyFlag(KeyFlag.LEFT));
                break;

            case 2:

                p.actions.forceAction("input", new KeyFlag(KeyFlag.RIGHT));
                break;
            case 3:
            case 9:
            case 8:
            case 7:
                p.actions.forceAction("input", new KeyFlag(KeyFlag.FIRE));
                break;
            case 4:

                p.actions.forceAction("input", new KeyFlag(KeyFlag.JUMP));
                break;
            case 5:
                p.actions.forceAction("input", new KeyFlag(KeyFlag.NONE));
            case 6:
                double t = Math.random();
                p.directionX = (float) Math.sin(t);
                p.directionY = (float) Math.cos(t);
                break;
View Full Code Here


    addr = a;
    Common.info(7, "Connect: delay=");
    buffer = new ArrayList<SpriteSet>();
    screen = new ArrayList<ShownElement>();
    indexToSend = new ArrayList<Integer>();
    lastInput = new KeyFlag((short) 0);
   
  }
View Full Code Here

      }
      server.send(Signal.send(cData, (byte) 0, (byte) 0, Signal.SCREEN,
      addr));
    } else if (signal == Signal.INPUT) {
      KeyFlag strc = null;
      try {
        short key = (Short) Signal.toObject(data);
        strc = new KeyFlag(key);
      } catch (Exception e) {
        strc = lastInput;
      }

      lastInput = strc;
View Full Code Here

  public long remaning=0;

  public Client() throws SocketException {
    serverM="";
    resolution = new Point(Common.resx, Common.resy);
    lastPremuti = new KeyFlag((short) 0);
    buffer = new ArrayList<SpriteSet>();
    guns = new String();
    isBusy = false;
    scale = new Vec2();
    chat = new String();
View Full Code Here

    } else {
      // sendFlag(Signal.INPUT);

    }
    lastPremuti = new KeyFlag(input.Key);

  }
View Full Code Here

  public client() {
    super();
    Common.info(7, "new client()");
    initComponents();
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    premuti = new KeyFlag((short) 0);
    bufferedImages = new HashMap<String, BufferedImage>();
    clientusage=Common.product + " v" + Common.version + "\n\n"+
    "       to RUN use ARROWS or A,D keys\n"+
    "       to JUMP use UP key or SPACE or W\n"+
    "       to BEND use DOWN or S key\n"+
    "       to use the SPECIAL SKILLS use ALT or ALT GR key\n"+
    "       to AIM'n'FIRE use the MOUSE\n"+
    "       to change GUN use NUMBER keys\n"+
    "       to CHAT use C key\n";
    this.addMouseListener(new java.awt.event.MouseListener() {


      public void mouseClicked(MouseEvent e) {
        requestFocus();
      }

      public void mouseEntered(MouseEvent e) {
        requestFocus();
      }

      public void mouseExited(MouseEvent e) {
      }

      public void mousePressed(MouseEvent e) {

        double x = e.getX();
        double y = c.resolution.y - e.getY();
        x -= c.resolution.x / 2;
        y -= c.resolution.y / 2 ;
        double mod = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
        x /= mod;
        y /= mod;

        // x/=c.resolution.x/2;
        // y/=c.resolution.y/2;

        if (!premuti.check(KeyFlag.FIRE)) {
          premuti.add(KeyFlag.FIRE);
        }
        try {
          c.setDirection(x, -y);
        } catch (IOException ex) {
          Logger.getLogger(client.class.getName()).log(Level.SEVERE,
          null, ex);
        }

      }

      public void mouseReleased(MouseEvent e) {
      }
    });

    this.addKeyListener(new java.awt.event.KeyListener() {
      public void keyPressed(KeyEvent e) {
        if ((e.getKeyCode() == KeyEvent.VK_C)) {


          String str = Common.ask("chat: ");

          try {
            c.chat(str);
          } catch (IOException ex) {
            ex.printStackTrace();
          }

        }

        // premuti.add("special");
        if (e.getKeyCode() == KeyEvent.VK_F1)
        Common.message(clientusage,false,false);

        if (e.getKeyCode() == KeyEvent.VK_1
            && !premuti.check(KeyFlag.k1))
        premuti.add(KeyFlag.k1);
        if (e.getKeyCode() == KeyEvent.VK_2
            && !premuti.check(KeyFlag.k2))
        premuti.add(KeyFlag.k2);
        if (e.getKeyCode() == KeyEvent.VK_3
            && !premuti.check(KeyFlag.k3))
        premuti.add(KeyFlag.k3);

        if ((e.getKeyCode() == KeyEvent.VK_SPACE
              || e.getKeyCode() == KeyEvent.VK_UP || e.getKeyCode() == KeyEvent.VK_W))
        premuti.add(KeyFlag.JUMP);
        if ((e.getKeyCode() == KeyEvent.VK_RIGHT || e.getKeyCode() == KeyEvent.VK_D))
        premuti.add(KeyFlag.RIGHT);
        if ((e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_S))
        premuti.add(KeyFlag.DOWN);
        if ((e.getKeyCode() == KeyEvent.VK_LEFT || e.getKeyCode() == KeyEvent.VK_A))
        premuti.add(KeyFlag.LEFT);
        if ((e.getKeyCode() == KeyEvent.VK_ALT || e.getKeyCode() == KeyEvent.VK_ALT_GRAPH))
        premuti.add(KeyFlag.SPECIAL);

      }

      public void keyReleased(KeyEvent e) {
        // if (e.isAltDown())
        // premuti.remove("special");
        if (e.getKeyCode() == KeyEvent.VK_1)
        premuti.del(KeyFlag.k1);
        if (e.getKeyCode() == KeyEvent.VK_2)
        premuti.del(KeyFlag.k2);
        if (e.getKeyCode() == KeyEvent.VK_3)
        premuti.del(KeyFlag.k3);
        if (e.getKeyCode() == KeyEvent.VK_UP
            || e.getKeyCode() == KeyEvent.VK_SPACE
            || e.getKeyCode() == KeyEvent.VK_W)
        premuti.del(KeyFlag.JUMP);
        if (e.getKeyCode() == KeyEvent.VK_RIGHT
            || e.getKeyCode() == KeyEvent.VK_D)
        premuti.del(KeyFlag.RIGHT);
        if (e.getKeyCode() == KeyEvent.VK_LEFT
            || e.getKeyCode() == KeyEvent.VK_A)
        premuti.del(KeyFlag.LEFT);

        if (e.getKeyCode() == KeyEvent.VK_DOWN
            || e.getKeyCode() == KeyEvent.VK_S)
        premuti.del(KeyFlag.DOWN);
        if (e.getKeyCode() == KeyEvent.VK_ALT
            || e.getKeyCode() == KeyEvent.VK_ALT_GRAPH)
        premuti.del(KeyFlag.SPECIAL);

      }

      public void keyTyped(KeyEvent e) {
      }
    });

    class autoupdateGUI extends Thread {

      public void run() {
        try {
          long a, b, delay;

          while (c.isConnected) {
            a = Calendar.getInstance().getTimeInMillis();
            try {
              viewOutput();
            } catch (IOException ex) {
              Logger.getLogger(client.class.getName()).log(
              Level.SEVERE, null, ex);
            }
            b = Calendar.getInstance().getTimeInMillis();
            delay = b - a;
            if (delay < framerate)
            Thread.sleep(framerate - delay);
            delay = (int) delay;
            repaint();




          }
          JOptionPane.showMessageDialog(null, "ERROR: Connection timeout");
          System.exit(0);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
        // System.exit(0);
      }
    }

    class autoSEND extends Thread {

      public void run() {
        try {
          KeyFlag lastPremuti = new KeyFlag();
          while (true) {
            // Common.info("lastPremuti:"+lastPremuti+" premuti:"+premuti.toString());
            // if(premuti.size()>0 || (premuti.size()==0 &&
            // !lastPremuti.equals(premuti.toString())))
            try {
View Full Code Here

    class autoSEND extends Thread {

      public void run() {
        try {
          KeyFlag lastPremuti = new KeyFlag();
          while (true) {
            // Common.info("lastPremuti:"+lastPremuti+" premuti:"+premuti.toString());
            // if(premuti.size()>0 || (premuti.size()==0 &&
            // !lastPremuti.equals(premuti.toString())))
            try {
View Full Code Here

TOP

Related Classes of plar.core.KeyFlag

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.