Esempio n. 1
0
  public void move(int x, int y, boolean send) {
    Log.info("Moving unit " + data.id);
    if (data.x == x && data.y == y) {
      return;
    }
    if (moved && send) {
      return;
    }
    state.mapActors[data.x][data.y] = null;
    data.x = x;
    data.y = y;
    state.mapActors[data.x][data.y] = this;
    moved = true;

    PulsatioGame game = PulsatioGame.getSingleton();
    if (send && !PulsatioGame.getSingleton().testmode) {
      MoveUnit mu = new MoveUnit(data.id, x, y);
      game.opponent.sendTCP(mu);
    }
    MapState.clearSelectorActors();

    switch (data.team) {
      case UnitData.TEAM_SERVER_PURPLE:
        state.adrenalineteam0 += 0.1f;
        break;
      case UnitData.TEAM_CLIENT_RED:
        state.adrenalineteam1 += 0.1f;
        break;
    }
  }
Esempio n. 2
0
  public int attack(UnitActor a, boolean send) {
    if (attacked && send) {
      return 0;
    }
    int damage = data.attack - a.data.defense;
    switch (data.team) {
      case UnitData.TEAM_SERVER_PURPLE:
        if (state.adrenalineteam0 >= 1) {
          damage *= 2;
          state.adrenalineteam0 = 0;
        }
        state.adrenalineteam0 += .2f;
        state.adrenalineteam1 += .4f;
        break;
      case UnitData.TEAM_CLIENT_RED:
        if (state.adrenalineteam1 >= 1) {
          damage *= 2;
          state.adrenalineteam1 = 0;
        }
        state.adrenalineteam1 += .2f;
        state.adrenalineteam0 += .4f;
        break;
    }
    state.stage.addActor(new HitEffectActor(a.getX(), a.getY()));
    attacked = true;

    if (send && !PulsatioGame.getSingleton().testmode) {
      AttackUnit au = new AttackUnit(data.id, a.data.id);
      PulsatioGame.getSingleton().opponent.sendTCP(au);
    }

    a.data.health -= damage;
    if (a.data.health <= 0) {
      Log.info("KILLED");
      if (a.data.team == 0) {
        state.team0units.remove(a);
        a.remove();
        state.mapActors[a.data.x][a.data.y] = null;
      }
      if (a.data.team == 1) {
        state.team1units.remove(a);
        a.remove();
        state.mapActors[a.data.x][a.data.y] = null;
      }
    }
    return damage;
  }
Esempio n. 3
0
  @Override
  public void draw(SpriteBatch batch, float parentAlpha) {
    super.draw(batch, parentAlpha);

    batch.draw(split[0][animationFrame], getX(), getY());
    if (state.selected == this && selectVisible) {
      batch.draw(
          PulsatioGame.getSingleton().atlas.findRegion("unit_selection_box"), getX(), getY());
    }

    BitmapFont font = PulsatioGame.getSingleton().assets.get("b03-8.fnt", BitmapFont.class);
    font.setColor(Color.BLACK);
    font.draw(batch, "" + data.health, getX() + 1, getY() - 1);
    font.draw(batch, "" + data.id, getX(), getY() + 40);
    font.setColor(Color.GREEN);
    font.draw(batch, "" + data.health, getX(), getY());
    font.setColor(Color.WHITE);
  }
Esempio n. 4
0
  public UnitActor(final UnitData data, MapState state) {
    // load assets
    AssetManager m = PulsatioGame.getSingleton().assets;
    m.load("b03-8.fnt", BitmapFont.class);
    m.finishLoading();

    this.state = state;
    this.data = data;
    String sprite = null;
    switch (data.unitClass) {
      case UnitData.CLASS_ORCA:
        sprite = "orca";
        break;
      case UnitData.CLASS_TURTLE:
        sprite = "turtlegogo";
        break;
      case UnitData.CLASS_SEAHORSEDRAGON:
        sprite = "seahorsedargon";
        break;
      case UnitData.CLASS_MERMAN:
        sprite = "mermannn";
        break;
      case UnitData.CLASS_MERMAID:
        sprite = "ariel mermaid";
        break;
      case UnitData.CLASS_JELLYFISH:
        sprite = "superjellyawesome";
        break;
    }
    sprite = sprite + data.team;
    split = PulsatioGame.getSingleton().atlas.findRegion(sprite).split(50, 50);

    setWidth(50);
    setHeight(50);

    if (state.mapActors[data.x][data.y] != null) {
      throw new RuntimeException("space is occupied");
    }
    state.mapActors[data.x][data.y] = this;

    final MapState captureState = state;
    addCaptureListener(
        new EventListener() {
          @Override
          public boolean handle(Event event) {
            if (Gdx.input.isButtonPressed(Input.Buttons.LEFT)
                && captureState.whoseTurn == captureState.whoami
                && data.team == captureState.whoseTurn
                && captureState.selected != event.getListenerActor()
                && !captureState.placementPhase) {
              PulsatioGame.getSingleton().assets.get("sound/select.wav", Sound.class).play();
              captureState.selected = (UnitActor) event.getListenerActor();
              MapState.clearSelectorActors();
              if (!moved) {
                calculateMoveSpaces();
              }
              return true;
            }
            return false;
          }
        });
  }