public GameScreen() {
    addKeyListener(new TAdapter());
    addMouseListener(new CustomListener());
    addMouseMotionListener(new CustomListener());
    setFocusable(true);
    setBackground(Color.BLACK);
    setDoubleBuffered(true);
    player = new Sprite();
    player.setX(500);
    player.setY(250);
    player.set_speed(player_speed);
    bullet = new Vector<Bullet>();
    enemy = new Vector<Enemy>();
    v_explosion = new Vector<Explosion>();
    ImageIcon ii =
        new ImageIcon(this.getClass().getResource("Data/Sprite/background/background1.png"));
    fon = ii.getImage();
    timer = new Timer(5, this);
    timer.start();
    timerj = new java.util.Timer();
    timerj.schedule(task, 100);
    ImageIcon ii2 = new ImageIcon(this.getClass().getResource("Data/Sprite/player/explosion.png"));
    explosion = ii2.getImage();

    ImageIcon i3 = new ImageIcon(this.getClass().getResource("Data/Sprite/player/live.png"));
    live = i3.getImage();
    i3 = new ImageIcon(this.getClass().getResource("Data/Sprite/player/str.png"));
    pointer = i3.getImage();
    image_bullet = new Bullet();
    start_game();
  }
Beispiel #2
0
  @Override
  public void update() {
    if (Ball.velocity.getY() > 0) {
      Vector2 p0 = Ball.position;
      Vector2 p1 = Vector2.add(Ball.position, Vector2.one());

      float k = (p0.getY() - p1.getY()) / (p0.getX() - p1.getX());
      float m = p1.getY() - k * p1.getX();
      float x = (sprite.getPosition().getY() - m) / k;

      sprite.setX(Math.min(x, Application.WIDTH / 2));
      collider.shape.setX(Math.min(x, Application.WIDTH / 2));
    }
  }
  /** Update or add a sprite to the client side game. */
  public void addPacket(HacktendoPacket Packet) {
    while (!getInitialized()) { // Make sure things have loaded before we start mucking with stuff.
      try {
        Thread.sleep(5);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    do {
      Sprite S = (Sprite) Sprites.get(new Integer(Packet.getID()));
      boolean setRenderType = false;
      if (S == null) {
        S = new Sprite(this);
        setRenderType = true;
        S.setParameter("destroy", new TypeBoolean(false));
        S.setParameter("globalID", new TypeInteger(Packet.getID()));
        S.setParameter("id", new TypeInteger(Packet.getID()));
        Sprites.put(new Integer(Packet.getID()), S);
        S.setOffscreenProcessing(false);
      }
      S.setScriptID(Packet.getScriptID());
      S.setImageID(Packet.getImage());

      if (S.getSpriteID() != playerID || setRenderType) { // Allow the sprite to move client side.
        S.setX(Packet.getX());
        S.setY(Packet.getY());
        S.setZ(Packet.getZ());
        S.setParameter("xTarget", new TypeInteger(Packet.getTargetX()));
        S.setParameter("yTarget", new TypeInteger(Packet.getTargetY()));
        S.setParameter("newTarget", new TypeBoolean(true));
      }

      if (Packet.getExplodeSprite()) S.explode();
      if (Packet.getDestroySprite()) S.setParameter("destroy", new TypeBoolean(true));
      S.setFrame(Packet.getFrame());
      S.setXRotation(Packet.getXRotation());
      S.setYRotation(Packet.getYRotation());
      S.setZRotation(Packet.getZRotation());

      S.setWidth(Packet.getWidth());
      S.setHeight(Packet.getHeight());
      S.setDepth(Packet.getDepth());
      S.setZOffset(Packet.getZOffset() * -1);

      if (setRenderType) S.setRenderType(Packet.getRenderType());

    } while (Packet.next() > 0);

    // Takes the form Object[]{ID,IP,Name,NPC,BODY_ID}
    if (Packet.getReferenceArray() != null) {
      for (int i = 0; i < Packet.getReferenceArray().size(); i++) {
        Object O[] = (Object[]) Packet.getReferenceArray().get(i);
        Sprite S = (Sprite) Sprites.get((Integer) O[0]);

        System.out.println("ID: " + O[0]);
        if (S != null) {
          String ip = (String) O[1];
          String name = (String) O[2];
          boolean npc = (Boolean) O[3];

          S.setParameter("ip", new TypeString(ip));
          S.setParameter("name", new TypeString(name));
          S.setParameter("npc", new TypeBoolean(npc));

          if (S.getScriptID() == SPRITE_SCRIPT) {
            S.setOffscreenProcessing(true);
            S.setAutoCollide(true);
            Sprite S2 = (Sprite) Sprites.get((Integer) O[4]);
            S.setParameter("body", new TypeInteger(S2.getSpriteID()));
          }

          if (ip.equals(MyHacker.getIP())) {
            if (S.getScriptID() == SPRITE_SCRIPT) {
              playerSprite = S;
            }
            playerID = S.getSpriteID();
            System.out.println(
                "We are setting the player to equal : "
                    + S.getSpriteID()
                    + " This Is Sprite ID: "
                    + O[0]);
            HacktendoLinker.addGlobal("player", new TypeInteger(S.getSpriteID()));
          }
        }
      }
    }
  }
Beispiel #4
0
 public void reset() {
   super.setX(Board.W_WIDTH / 2);
   super.setY(Board.W_HEIGHT / 2);
 }