Ejemplo n.º 1
0
 public void render(ShaderHandler sh, DisplaySetup d, DataUtils util) {
   for (int i = 0; i < size(); i++) {
     pellet.changePos(get(i).getPos().x - currentpos.x, get(i).getPos().y - currentpos.y);
     pellet.changeTexture(get(i).getTexid());
     if (get(i).getAnimationWait() > 3) {
       if (get(i).getTexid() < 11) {
         get(i).changeTexid(1);
       } else {
         get(i).setTexid(0);
       }
       get(i).resetWait();
     } else {
       get(i).animationWait();
     }
     currentpos = new Vector2f(get(i).getPos().x, get(i).getPos().y);
     pellet.render(sh, util, 0);
     if (get(i)
         .contains(
             player.getPos(),
             (float) player.getWidth() / Display.getWidth(),
             (float) player.getHeight() / Display.getHeight(),
             d)) {
       parent.score(get(i).getScore());
       remove(i);
     }
   }
 }
Ejemplo n.º 2
0
 public void render(ShaderHandler sh, DisplaySetup d) {
   update(d);
   animate();
   if (Math.abs(d.getPos().y) + 1.0f > pos.y && !stopped) {
     for (int i = 0; i < playerbullets.size(); i++) {
       Vector4f tempos =
           new Vector4f(
               playerbullets.get(i).getPos().x + ((25 / Display.getWidth()) / 2.0f),
               playerbullets.get(i).getPos().y - ((25 / Display.getHeight()) / 2.0f),
               0.0f,
               1.0f);
       tempos = Matrix4f.transform(d.getModelViewMatrixAsMatrix(), tempos, tempos);
       Vector2f p1 = new Vector2f((float) myrect.getX(), (float) myrect.getY());
       Vector2f p2 =
           new Vector2f((float) (myrect.getX() + myrect.getWidth()), (float) myrect.getY());
       Vector2f p3 =
           new Vector2f(
               (float) (myrect.getX() + myrect.getWidth()),
               (float) (myrect.getY() - myrect.getHeight()));
       Vector2f p4 =
           new Vector2f((float) myrect.getX(), (float) (myrect.getY() - myrect.getHeight()));
       if (Math.abs(Math.sqrt(Math.pow(p1.x - tempos.x, 2) + Math.pow(p1.y - tempos.y, 2)))
               < (float) 40.0f / Display.getWidth()
           || Math.abs(Math.sqrt(Math.pow(p2.x - tempos.x, 2) + Math.pow(p2.y - tempos.y, 2)))
               < (float) 40.0f / Display.getWidth()
           || Math.abs(Math.sqrt(Math.pow(p3.x - tempos.x, 2) + Math.pow(p3.y - tempos.y, 2)))
               < (float) 40.0f / Display.getWidth()
           || Math.abs(Math.sqrt(Math.pow(p4.x - tempos.x, 2) + Math.pow(p4.y - tempos.y, 2)))
               < (float) 40.0f / Display.getWidth()) {
         // parent.bulletexplode(i);
         stopped = true;
       }
     }
     if (started) {
       if (stage >= dist) {
         index += 1;
         stage = 0;
         if (index >= ep.getSize()) {
           if (index == ep.getSize()) {
             this.lastp = ep.getPoint(index - 1);
             this.p = new PathPoint(new Vector2f(0.0f, 0.0f), ep.getPoint(index - 1).getIndex());
             this.p.setPos(new Vector2f(lastp.getPos().x, lastp.getPos().y - 0.6f));
             dist = 30;
           } else {
             this.stopped = true;
           }
         } else {
           this.p = ep.getPoint(index);
           this.lastp = ep.getPoint(index - 1);
           dist =
               (int)
                   (Math.sqrt(
                           Math.pow(p.getPos().x - lastp.getPos().x, 2)
                               + Math.pow(p.getPos().y - lastp.getPos().y, 2))
                       * 100.0f);
         }
       } else {
         me.changePos(
             (p.getPos().x - lastp.getPos().x) / dist, (p.getPos().y - lastp.getPos().y) / dist);
         stage += 1;
       }
     } else {
       this.index = 1;
       this.p = ep.getPoint(1);
       this.lastp = ep.getPoint(0);
       dist =
           (int)
                   Math.sqrt(
                       Math.pow(p.getPos().x - lastp.getPos().x, 2)
                           + Math.pow(p.getPos().y - lastp.getPos().y, 2))
               * 10;
       started = true;
       Vector2f startpos = ep.getPoint(0).getPos();
       me.setPos(startpos.x, startpos.y + pos.y + 1.0f);
     }
     me.render(sh);
   }
   for (int i = 0; i < explosions.size(); i++) {
     explosion.changeTexture((explosions.get(i).getAge() / 5));
     explosions.get(i).age();
     explosion.changePos(
         explosions.get(i).getPos().x - epos.x, explosions.get(i).getPos().y - epos.y);
     epos = new Vector2f(explosions.get(i).getPos().x, explosions.get(i).getPos().y);
     explosion.render(sh);
     if (explosions.get(i).getAge() > 24) {
       explosions.remove(i);
       i -= 1;
     }
   }
   if (textstage >= 35) {
     textstage = 0;
   }
   textstage += 1;
   boolean changed = true;
   for (int i = 0; i < bullets.size(); i++) {
     if (changed) {
       bullet.changeTexture((textstage / 5));
       changed = false;
     }
     boolean stopped = false;
     if (!bullets.get(i).getDestroying()) {
       bullets
           .get(i)
           .setPos(
               new Vector2f(
                   (float)
                       (bullets.get(i).getPos().x - (Math.sin(bullets.get(i).getRot()) / 200.0f)),
                   (float)
                       (bullets.get(i).getPos().y
                           - (Math.cos(bullets.get(i).getRot()) / 200.0f))));
       if (bullets.get(i).getAge() > 100) {
         bullets.get(i).setDestroyingSelf(true);
         explosions.add(new EnemyBullet(bullets.get(i).getPos(), 0.0f));
         changed = true;
         bullet.changeTexture(8);
       }
     } else {
       if (bullets.get(i).getAge() < bullets.get(i).getLastAge() + 20) {
         bullet.changeTexture(8 + ((bullets.get(i).getAge() - bullets.get(i).getLastAge()) / 5));
         changed = true;
       } else {
         stopped = true;
         bullets.remove(i);
         i -= 1;
       }
     }
     if (!stopped) {
       bullets.get(i).age();
       bullet.changePos(bullets.get(i).getPos().x - bpos.x, bullets.get(i).getPos().y - bpos.y);
       bpos = new Vector2f(bullets.get(i).getPos().x, bullets.get(i).getPos().y);
       bullet.render(sh);
       if (!bullets.get(i).getDestroying()) {
         Vector4f tempos =
             new Vector4f(
                 bullets.get(i).getPos().x + ((bullet.getWidth() / Display.getWidth()) / 2.0f),
                 bullets.get(i).getPos().y - ((bullet.getHeight() / Display.getHeight()) / 2.0f),
                 0.0f,
                 1.0f);
         tempos = Matrix4f.transform(d.getModelViewMatrixAsMatrix(), tempos, tempos);
         Vector2f p1 = new Vector2f((float) player.getX(), (float) player.getY());
         Vector2f p2 =
             new Vector2f((float) (player.getX() + player.getWidth()), (float) player.getY());
         Vector2f p3 =
             new Vector2f(
                 (float) (player.getX() + player.getWidth()),
                 (float) (player.getY() - player.getHeight()));
         Vector2f p4 =
             new Vector2f((float) player.getX(), (float) (player.getY() - player.getHeight()));
         if (Math.abs(Math.sqrt(Math.pow(p1.x - tempos.x, 2) + Math.pow(p1.y - tempos.y, 2)))
                 < (float) 40.0f / Display.getWidth()
             || Math.abs(Math.sqrt(Math.pow(p2.x - tempos.x, 2) + Math.pow(p2.y - tempos.y, 2)))
                 < (float) 40.0f / Display.getWidth()
             || Math.abs(Math.sqrt(Math.pow(p3.x - tempos.x, 2) + Math.pow(p3.y - tempos.y, 2)))
                 < (float) 40.0f / Display.getWidth()
             || Math.abs(Math.sqrt(Math.pow(p4.x - tempos.x, 2) + Math.pow(p4.y - tempos.y, 2)))
                 < (float) 40.0f / Display.getWidth()) {
           bullets.get(i).setDestroyingSelf(true);
           explosions.add(new EnemyBullet(bullets.get(i).getPos(), 0.0f));
           explosions.add(
               new EnemyBullet(
                   new Vector2f(
                       (float) (bullets.get(i).getPos().x + (Math.random() * 0.2f) - 0.1f),
                       (float) (bullets.get(i).getPos().y + (Math.random() * 0.08f) - 0.04f)),
                   0.0f));
           explosions.add(
               new EnemyBullet(
                   new Vector2f(
                       (float) (bullets.get(i).getPos().x + (Math.random() * 0.2f) - 0.1f),
                       (float) (bullets.get(i).getPos().y + (Math.random() * 0.08f) - 0.04f)),
                   0.0f));
           parent.damage(5);
         }
       }
     }
   }
 }