コード例 #1
0
ファイル: PhoenixShot.java プロジェクト: herbertrlee/Cards
  public static void initialize(JSONArray shotDefs) throws JSONException {
    for (int i = 0; i < shotDefs.length(); i++) {
      JSONObject shotDef = shotDefs.getJSONObject(i);
      int type = shotDef.getInt("type");
      types.add(type);

      widths.put(type, (float) shotDef.getDouble("width"));
      heights.put(type, (float) shotDef.getDouble("height"));
      speeds.put(type, (float) shotDef.getDouble("speed"));
      damages.put(type, shotDef.getInt("damage"));
      textures.put(type, shotDef.getString("texture"));
      upgradeables.put(type, shotDef.getBoolean("upgradeable"));
    }
  }
コード例 #2
0
ファイル: OpenALAudio.java プロジェクト: Sasun/libgdx
  int obtainSource(boolean isMusic) {
    if (noDevice) return 0;
    for (int i = 0, n = idleSources.size; i < n; i++) {
      int sourceId = idleSources.get(i);
      int state = alGetSourcei(sourceId, AL_SOURCE_STATE);
      if (state != AL_PLAYING && state != AL_PAUSED) {
        if (isMusic) {
          idleSources.removeIndex(i);
        } else {
          if (sourceToSoundId.containsKey(sourceId)) {
            long soundId = sourceToSoundId.get(sourceId);
            sourceToSoundId.remove(sourceId);
            soundIdToSource.remove(soundId);
          }

          long soundId = nextSoundId++;
          sourceToSoundId.put(sourceId, soundId);
          soundIdToSource.put(soundId, sourceId);
        }
        alSourceStop(sourceId);
        alSourcei(sourceId, AL_BUFFER, 0);
        AL10.alSourcef(sourceId, AL10.AL_GAIN, 1);
        AL10.alSourcef(sourceId, AL10.AL_PITCH, 1);
        AL10.alSource3f(sourceId, AL10.AL_POSITION, 0, 0, 1f);
        return sourceId;
      }
    }
    return -1;
  }
コード例 #3
0
  @Override
  public IntMap read(Json json, JsonValue jsonData, Class type) {
    IntMap intMap = new IntMap(json.readValue(VALUE_SIZE, int.class, jsonData));

    for (JsonValue entry = jsonData.getChild(VALUE_ENTRIES); entry != null; entry = entry.next) {
      intMap.put(Integer.parseInt(entry.name), json.readValue(entry.name, null, jsonData));
    }

    return intMap;
  }
コード例 #4
0
ファイル: GwtControllers.java プロジェクト: libgdx/libgdx
 @Override
 public void onGamepadConnected(int index) {
   Gamepad gamepad = Gamepad.getGamepad(index);
   GwtController controller = new GwtController(gamepad.getIndex(), gamepad.getId());
   controllerMap.put(index, controller);
   synchronized (eventQueue) {
     GwtControllerEvent event = eventPool.obtain();
     event.type = GwtControllerEvent.CONNECTED;
     event.controller = controller;
     eventQueue.add(event);
   }
 }
コード例 #5
0
  public CommandCardContainer(final InputSystem inputSystem, final Skin skin, Stage stage) {
    this.skin = skin;
    this.inputSystem = inputSystem;

    dragAndDrop = new DragAndDrop();

    for (int i = 0; i < Constants.maxSquads; i++) {
      final CommandCardSlot slot = new CommandCardSlot(i, skin);
      cardSlots.put(i, slot);
      add(slot).size(slotWidth, slotHeight);

      Target target =
          new Target(slot) {

            @Override
            public void drop(Source source, Payload payload, float x, float y, int pointer) {
              CommandCardSlot slotA = slot;
              CommandCardSlot slotB = cardSlots.get((Integer) source.getActor().getUserObject());

              CommandCard cardA = (CommandCard) source.getActor();
              CommandCard cardB = (CommandCard) slotA.getUserObject();

              slotA.setCard(cardA);
              slotB.setCard(cardB);

              inputSystem.swapSquadSlot(slotA.index, slotB.index);
            }

            @Override
            public boolean drag(Source source, Payload payload, float x, float y, int pointer) {
              return true;
            }
          };

      dragAndDrop.addTarget(target);

      addSquad(null, i);
    }
  }
コード例 #6
0
ファイル: AndroidInput.java プロジェクト: HH-Ding/libgdx
  @Override
  public boolean onKey(View v, int keyCode, android.view.KeyEvent e) {
    for (int i = 0, n = keyListeners.size(); i < n; i++)
      if (keyListeners.get(i).onKey(v, keyCode, e)) return true;

    synchronized (this) {
      KeyEvent event = null;

      if (e.getKeyCode() == android.view.KeyEvent.KEYCODE_UNKNOWN
          && e.getAction() == android.view.KeyEvent.ACTION_MULTIPLE) {
        String chars = e.getCharacters();
        for (int i = 0; i < chars.length(); i++) {
          event = usedKeyEvents.obtain();
          event.keyCode = 0;
          event.keyChar = chars.charAt(i);
          event.type = KeyEvent.KEY_TYPED;
          keyEvents.add(event);
        }
        return false;
      }

      char character = (char) e.getUnicodeChar();
      // Android doesn't report a unicode char for back space. hrm...
      if (keyCode == 67) character = '\b';

      switch (e.getAction()) {
        case android.view.KeyEvent.ACTION_DOWN:
          event = usedKeyEvents.obtain();
          event.keyChar = 0;
          event.keyCode = e.getKeyCode();
          event.type = KeyEvent.KEY_DOWN;

          // Xperia hack for circle key. gah...
          if (keyCode == android.view.KeyEvent.KEYCODE_BACK && e.isAltPressed()) {
            keyCode = Keys.BUTTON_CIRCLE;
            event.keyCode = keyCode;
          }

          keyEvents.add(event);
          keys.put(event.keyCode, null);
          break;
        case android.view.KeyEvent.ACTION_UP:
          event = usedKeyEvents.obtain();
          event.keyChar = 0;
          event.keyCode = e.getKeyCode();
          event.type = KeyEvent.KEY_UP;
          // Xperia hack for circle key. gah...
          if (keyCode == android.view.KeyEvent.KEYCODE_BACK && e.isAltPressed()) {
            keyCode = Keys.BUTTON_CIRCLE;
            event.keyCode = keyCode;
          }
          keyEvents.add(event);

          event = usedKeyEvents.obtain();
          event.keyChar = character;
          event.keyCode = 0;
          event.type = KeyEvent.KEY_TYPED;
          keyEvents.add(event);

          if (keyCode == Keys.BUTTON_CIRCLE) keys.remove(Keys.BUTTON_CIRCLE);
          else keys.remove(e.getKeyCode());
      }
      app.getGraphics().requestRendering();
    }

    // circle button on Xperia Play shouldn't need catchBack == true
    if (keyCode == Keys.BUTTON_CIRCLE) return true;
    if (catchBack && keyCode == android.view.KeyEvent.KEYCODE_BACK) return true;
    if (catchMenu && keyCode == android.view.KeyEvent.KEYCODE_MENU) return true;
    return false;
  }
コード例 #7
0
 /**
  * Adds or replaces tile with that id
  *
  * @param id the id of the {@link TiledMapTile} to add or replace.
  * @param tile the {@link TiledMapTile} to add or replace.
  */
 public void putTile(int id, TiledMapTile tile) {
   tiles.put(id, tile);
 }