コード例 #1
0
ファイル: Ball.java プロジェクト: Korvar/MyBreakout
 @Override
 public void update() {
   if (!_served && (_bat != null)) {
     velocity.x = 0;
     velocity.y = 0;
     x = _bat.x + 3 * _bat.width / 4;
     y = _bat.y - height;
   }
   if (FlxG.mouse.justPressed() && !_served && (_bat != null)) {
     _served = true;
     velocity.x = 100 * (1 + FlxG.level * (float) 0.1);
     velocity.y = -100 * (1 + FlxG.level * (float) 0.1);
   }
   if ((x > (FlxG.width - width))) {
     x = FlxG.width - width;
     velocity.x = -velocity.x;
     FlxG.play("Ping.mp3");
   }
   if (x <= 0) {
     x = 0;
     velocity.x = -velocity.x;
     FlxG.play("Ping.mp3");
   }
   if (y <= 0) {
     y = 0;
     velocity.y = -velocity.y;
     FlxG.play("Ping.mp3");
   }
   if (y >= FlxG.height) {
     FlxG.play("Ow.mp3");
     kill();
   }
   super.update();
 }
コード例 #2
0
 /**
  * Add a new blend mode.
  *
  * @param name The name of the blend mode
  * @param vertex The path of the vertex file.
  * @param fragment The path of the fragment file.
  * @return The program shader.
  */
 public static FlxShaderProgram addBlendMode(String name, String vertex, String fragment) {
   FlxShaderProgram shader;
   if (FlxG._cache.containsAsset(name, FlxShaderProgram.class))
     shader = FlxG._cache.load(name, FlxShaderProgram.class);
   else shader = FlxG.loadShader(name, vertex, fragment);
   return shader;
 }
コード例 #3
0
ファイル: Keyboard.java プロジェクト: Johnicholas/flixel-gdx
  /**
   * Event handler so FlxGame can toggle keys.
   *
   * @param FlashEvent A <code>KeyboardEvent</code> object.
   */
  public void handleKeyUp(KeyboardEvent FlashEvent) {
    KeyState object = _map.get(FlashEvent.keyCode);

    if (object == null) return;
    if (object.current > 0) object.current = -1;
    else object.current = 0;

    try {
      ClassReflection.getField(Keyboard.class, object.name).set(this, false);
    } catch (Exception e) {
      FlxG.log("Keyboard", e.getMessage());
    }
  }
コード例 #4
0
ファイル: Keyboard.java プロジェクト: Johnicholas/flixel-gdx
  /**
   * Event handler so FlxGame can toggle keys.
   *
   * @param FlashEvent A <code>KeyboardEvent</code> object.
   */
  public void handleKeyDown(KeyboardEvent FlashEvent) {
    KeyState object = _map.get(FlashEvent.keyCode);

    if (object == null) return;
    if (object.current > 0) object.current = 1;
    else object.current = 2;

    try { // TODO: Reflection is fairly slow, could we use a BooleanMap instead?
      ClassReflection.getField(Keyboard.class, object.name).set(this, true);
    } catch (Exception e) {
      FlxG.log("Keyboard", e.getMessage());
    }
  }
コード例 #5
0
  private void kill_player() {
    // The player has drowned; move them back to the last restore point
    RestorePoint restore_point = world.airbubble_restore_points.get(saved_restore_point);

    player.x = restore_point.x;
    player.y = restore_point.y;
    player.velocity.x = player.velocity.y = 0;

    // Re-set the 'death' timer which holds the blackout & countdown
    // for a couple seconds.
    player_dead = true;
    player_death_timer = player_death_length;

    // Complete blackout
    oxygen_timer_display.setText("0");
    darkness.setAlpha(1.0f);
    oxygen_timer_display.setAlpha(1.0f);

    // Play sound effect
    FlxG.play(RevNoiseSound);
  }
コード例 #6
0
 /**
  * Creates a shader program from the default vertex and blend mode. You may want to create the
  * shader during <code>FlxState.create()</code> and apply it later to the
  *
  * @param name The name of the blend mode, e.g. <code>BlendModeGL20.ADD</code>.
  * @return The program shader that is created.
  */
 public static FlxShaderProgram createProgram(String name) {
   FlxShaderProgram shader;
   if (FlxG._cache.containsAsset(name, FlxShaderProgram.class))
     shader = FlxG._cache.load(name, FlxShaderProgram.class);
   else {
     shader = FlxG.loadShader(name, VERTEX, name);
     IFlxShaderProgram callback =
         new IFlxShaderProgram() {
           @Override
           public void loadShaderSettings(ShaderProgram shader) {
             shader.begin();
             if (shader.hasUniform("u_texture")) shader.setUniformi("u_texture", 1);
             if (shader.hasUniform("u_texture1")) shader.setUniformi("u_texture1", 2);
             shader.end(); // TODO: set texture coordinates
           }
         };
     callback.loadShaderSettings(shader);
     shader.callback = callback;
   }
   return shader;
 }
コード例 #7
0
  @Override
  public void create() {
    FlxG.setBgColor(Breath.bgcolor);

    frame_buffer = new FrameBuffer(Pixmap.Format.RGBA8888, FlxG.width, FlxG.height, true);

    title_text =
        new FlxText(4, 24, 290, "\"I Can Hold My Breath Forever\"\nUse arrow keys to move.");
    title_text.setFormat(GardeniaFont, 8, 0xffffffff);

    PlayState.world_darkness = new FlxSprite(0, 0);
    world_darkness.scrollFactor.x = world_darkness.scrollFactor.y = 0;
    world_darkness.setPixels(
        new AtlasRegion(
            frame_buffer.getColorBufferTexture(),
            0,
            0,
            frame_buffer.getWidth(),
            frame_buffer.getHeight()));
    world_darkness.framePixels.flip(false, true);
    world_darkness.blend = "multiply";
    world_darkness.setAlpha(0);
    world_darkness.visible = false;

    frame_buffer_fill = new FlxSprite(0, 0);
    frame_buffer_fill.makeGraphic(FlxG.width, FlxG.height, darkness_color);
    frame_buffer_fill.scrollFactor.x = frame_buffer_fill.scrollFactor.y = 0;

    world = new World();

    background = new FlxSprite(0, 0, BackgroundImage);

    // Add restore point sprites
    notes = new FlxGroup();
    for (RestorePoint note : world.airbubble_restore_points.values()) {
      if (note.note) {
        notes.add(note);
      }
    }

    player = new Player(4 * World.TILE_SIZE, 9 * World.TILE_SIZE, world_darkness);

    darkness = new FlxSprite(0, 0);
    darkness.makeGraphic(FlxG.width, FlxG.height, 0xff000000);
    darkness.scrollFactor.x = darkness.scrollFactor.y = 0;
    darkness.setAlpha(0.0f);

    oxygen_timer_display = new FlxText(0, 0, FlxG.width, "10");
    oxygen_timer_display.setFormat(null, 160, 0xffffff, "center");
    oxygen_timer_display.setAlpha(0.0f);
    oxygen_timer_display.scrollFactor.x = oxygen_timer_display.scrollFactor.y = 0;

    story_overlay = new StoryOverlay(8, 2);

    world.walls_map.follow();
    // FlxG.followAdjust(0.5, 0.5);
    // FlxG.follow(player, 2.5);
    FlxG.camera.follow(player);

    // this.add(world.walls_map);
    // this.add(world.water_map);
    this.add(background);
    this.add(world.firefish_group);
    this.add(world.octopus);
    this.add(notes);
    this.add(player);
    this.add(world_darkness);
    this.add(darkness);
    this.add(oxygen_timer_display);
    this.add(story_overlay);
    this.add(title_text);
  }
コード例 #8
0
  @Override
  public void update() {
    // CHEAT CODE LOL
    if (cheats) {
      if (FlxG.keys.justPressed("N")) {
        skip_ahead();
        super.update();
        return;
      }
    }

    if (player.won_game) {
      oxygen_timer_display.setAlpha(0);
      darkness.setAlpha(0);

      int speed = 400;
      FlxPoint target = new FlxPoint(world.octopus.x - 16, world.octopus.y + 4);

      if (player.x < target.x) {
        player.velocity.x += speed * FlxG.elapsed;
      } else if (player.x > target.x) {
        player.velocity.x -= speed * FlxG.elapsed;
      }

      if (player.y > target.y) {
        player.velocity.y -= speed * FlxG.elapsed;
      } else if (player.y < target.y) {
        player.velocity.y += speed * FlxG.elapsed;
      }

      if (Math.abs(player.y - target.y) < 16 && Math.abs(player.x - target.x) <= 16 && !won_done) {
        player.setFacing(FlxSprite.RIGHT);
        won_done = true;

        FlxG.fade(
            0xff000000,
            5,
            new IFlxCamera() {

              @Override
              public void callback() {
                FlxG.switchState(new EndGameState());
              }
            });
      }

      super.update();
      return;
    }

    if (player_dead) {
      player.active = false;

      player_death_timer -= FlxG.elapsed;

      if (player_death_timer <= 0.0) {
        player_dead = false;
        player.active = true;
      }

      super.update();
      return;
    }

    FlxG.collide(player, world.walls_map);
    FlxG.collide(world.firefish_group, world.walls_map, Firefish.callback);

    if (world.water_map.overlaps(player)) {
      player.in_water = true;
      player.glow.scale.x = player.glow.scale.y = 4;
    } else {
      player.in_water = false;
      player.glow.scale.x = player.glow.scale.y = 8;
    }

    if (world.safezone_map.overlaps(player) || world.water_map.overlaps(player)) {
      player.gravity_on = false;
    } else {
      player.gravity_on = true;
    }

    // Nudge the player up if they're in the safe zone.
    if (world.safezone_map.overlaps(player)) {
      player.push_up = true;
    } else {
      player.push_up = false;
    }

    // Check air bubble entrances
    for (String bubble_id : world.airbubble_entrances.keySet()) {
      FlxObject air_bubble_entrance = world.airbubble_entrances.get(bubble_id);
      if (air_bubble_entrance.overlaps(player)) {
        if (bubble_id != saved_restore_point) {
          saved_restore_point = bubble_id;
        }
      }
    }

    // Check story points
    for (String restore_point_id : world.airbubble_restore_points.keySet()) {
      RestorePoint restore_point = world.airbubble_restore_points.get(restore_point_id);

      if (player.overlaps(restore_point)) {
        if (world.stories.containsKey(restore_point_id)) {
          story_overlay.showText(world.stories.get(restore_point_id));
        }
      }
    }

    // Check oxygen level & update label
    if (player.in_water) {
      oxygen_timer_display.setText(Integer.toString((int) (Math.ceil(oxygen_timer))));
      oxygen_timer_display.setAlpha(1.0f - (oxygen_timer / 10.0f));

      darkness.setAlpha((float) Math.pow(1.0f - (oxygen_timer / 10.0f), 2));

      float max_overlay_alpha = 0.9f;

      if (darkness.getAlpha() > max_overlay_alpha) {
        darkness.setAlpha(max_overlay_alpha);
      }

      if (oxygen_timer_display.getAlpha() > max_overlay_alpha) {
        oxygen_timer_display.setAlpha(max_overlay_alpha);
      }

      oxygen_timer -= FlxG.elapsed;

      if (oxygen_timer < 0.0f) {
        oxygen_timer = 0.0f;
        kill_player();
      }
    } else {
      oxygen_timer = 10.0f;
      darkness.setAlpha(0);
      oxygen_timer_display.setAlpha(0);
    }

    // Start music
    if (!game_started && player.overlaps(world.darkness_init_area)) {
      game_started = true;

      FlxG.playMusic(GameMusic);
    }

    // World darkness init and kill titles (when the player dives into the pond);
    if (world_darkness.getAlpha() < 1
        && (world_darkness.getAlpha() > 0 || player.overlaps(world.darkness_init_area))) {
      world_darkness.visible = true;
      world_darkness.setAlpha(world_darkness.getAlpha() + FlxG.elapsed);
      title_text.setAlpha(title_text.getAlpha() - FlxG.elapsed);
    }

    // Endgame init
    if (player.overlaps(world.endgame_area)) {
      player.won_game = true;
    }

    super.update();
  }
コード例 #9
0
 public void randomize() {
   targetY = (int) (16 + FlxG.random() * (208 - height));
   if (targetY < y) velocity.y = -SPEED;
   else velocity.y = SPEED;
 }