Пример #1
0
  public void Create() {
    particleSource0 = new ParticleSource(70, ParticleSource.TYPE_BLUE, 5, 0.5f, 0.25f);
    particleSource0.x = 1.0f;
    particleSource0.y = 0.0f;
    particleSource0.rot = -3.141f;
    particleSource0.on = true;

    particleSource1 = new ParticleSource(70, ParticleSource.TYPE_RED, 5, 0.5f, 0.25f);
    particleSource1.x = -1.0f;
    particleSource1.y = -0.0f;
    particleSource1.rot = 0.0f;
    particleSource1.on = true;

    particleSource2 = new ParticleSource(70, ParticleSource.TYPE_BLUE, 5, 0.5f, 0.25f);
    particleSource2.x = -0.4f;
    particleSource2.y = -1.0f;
    particleSource2.rot = 3.141f / 2.0f;
    particleSource2.on = true;

    magnet0 = new Magnet(Magnet.TYPE_RED, 0.2f, 0.2f, 0.2f);
    magnet0.x = 0.2f;
    magnet0.y = -0.2f;

    magnet1 = new Magnet(Magnet.TYPE_BLUE, 0.2f, 0.2f, 0.2f);
    magnet1.x = 0.2f;
    magnet1.y = -0.4f;

    magnet2 = new Magnet(Magnet.TYPE_BLUE, 0.2f, 0.2f, 0.2f);
    magnet2.x = 0.2f;
    magnet2.y = 0.2f;

    detector = new Detector(0.8f, 40);
    detector.y = 0.7f;
    detector.x = -0.6f;

    mirror0 = new Mirror(0.8f, 0.0f);
    mirror0.x = -0.1f;
    mirror0.y = -0.12f;
    mirror0.rot = 3.141f / 2.0f;

    grid = new Grid(0.2f, 0.2f);

    complete0 = 0;
    complete1 = 0;
    complete2 = 0;
  }
Пример #2
0
  public void Render() {
    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    particleSource0.AddField(magnet0);
    particleSource0.AddField(magnet1);
    particleSource0.AddField(magnet2);

    particleSource1.AddField(magnet0);
    particleSource1.AddField(magnet1);
    particleSource1.AddField(magnet2);

    particleSource2.AddField(magnet0);
    particleSource2.AddField(magnet1);
    particleSource2.AddField(magnet2);

    boolean s0 = particleSource0.AddDetector(detector);
    boolean s1 = particleSource1.AddDetector(detector);
    boolean s2 = particleSource2.AddDetector(detector);
    int maxScore = 500;
    int incValue = 20;
    int decValue = 3;
    int winThreshold = maxScore - 20;
    if (s0) complete0 += incValue;
    else complete0 -= decValue;
    if (s1) complete1 += incValue;
    else complete1 -= decValue;
    if (s2) complete2 += incValue;
    else complete2 -= decValue;
    if (complete0 < 0) complete0 = 0;
    if (complete1 < 0) complete1 = 0;
    if (complete2 < 0) complete2 = 0;
    if (complete0 > maxScore) complete0 = maxScore;
    if (complete1 > maxScore) complete1 = maxScore;
    if (complete2 > maxScore) complete2 = maxScore;

    if (complete0 >= winThreshold && complete1 >= winThreshold && complete2 >= winThreshold) {
      SharedPreferences userPref = context.getSharedPreferences("userPref", 0);
      int saveState = userPref.getInt("saveState", 20);
      if (saveState < windowId + 1) {
        SharedPreferences.Editor editorPref = userPref.edit();
        editorPref.putInt("saveState", windowId + 1);
        editorPref.commit();
      }
      manager.Activate(windowId + 1);
    }

    particleSource0.AddMirror(mirror0);

    particleSource1.AddMirror(mirror0);

    particleSource2.AddMirror(mirror0);

    magnet0.AddSourceCollision(particleSource0);
    magnet0.AddSourceCollision(particleSource1);
    magnet0.AddSourceCollision(particleSource2);
    magnet0.AddMirrorCollision(mirror0);
    magnet0.AddMagnetCollision(magnet1);
    magnet0.AddMagnetCollision(magnet2);

    magnet1.AddSourceCollision(particleSource0);
    magnet1.AddSourceCollision(particleSource1);
    magnet1.AddSourceCollision(particleSource2);
    magnet1.AddMirrorCollision(mirror0);
    magnet1.AddMagnetCollision(magnet0);
    magnet1.AddMagnetCollision(magnet2);

    magnet2.AddSourceCollision(particleSource0);
    magnet2.AddSourceCollision(particleSource1);
    magnet2.AddSourceCollision(particleSource2);
    magnet2.AddMirrorCollision(mirror0);
    magnet2.AddMagnetCollision(magnet0);
    magnet2.AddMagnetCollision(magnet1);

    grid.Render();
    particleSource0.RenderSourceSprite();
    particleSource1.RenderSourceSprite();
    particleSource2.RenderSourceSprite();
    magnet0.Render();
    magnet1.Render();
    magnet2.Render();
    particleSource0.Render();
    particleSource1.Render();
    particleSource2.Render();
    mirror0.Render();
    detector.Render();
  }