Ejemplo n.º 1
0
 /** Draw a string with letters that move up and down individually. */
 public void drawWavyString(
     String s,
     int x,
     int y,
     int align,
     int increment_x,
     double tmr,
     double amplitude,
     double pos_phaseshift,
     double timer_phaseshift,
     JGFont font,
     JGColor col) {
   setFont(font);
   setColor(col);
   if (align == 0) {
     x -= increment_x * s.length() / 2;
   } else if (align == 1) {
     x -= increment_x * s.length();
   }
   for (int i = 0; i < s.length(); i++)
     drawString(
         s.substring(i, i + 1),
         x + i * increment_x,
         y
             + (int)
                 (amplitude * -Math.cos(Math.PI * (pos_phaseshift * i + tmr * timer_phaseshift))),
         0);
 }
Ejemplo n.º 2
0
 public JGImage rotateAny(double angle) {
   JGPoint size = getSize();
   int sw = size.x;
   int sh = size.y;
   // destination size is upper bound size. Upper bound is the max
   // of the longest dimension and the figure's dimension at 45 degrees
   // = sw*sin(45)+sh*cos(45) ~= 1.5*(sw+sh)
   int dw = (int) Math.max(Math.max(sw, sh), 0.75 * (sw + sh));
   int dh = dw;
   int xtrans = (dw - sw) / 2;
   int ytrans = (dh - sh) / 2;
   BufferedImage dst = createCompatibleImage(dw, dh, Transparency.BITMASK);
   Graphics2D g = (Graphics2D) dst.getGraphics();
   AffineTransform tt = AffineTransform.getTranslateInstance(xtrans, ytrans);
   AffineTransform tr = AffineTransform.getRotateInstance(angle, sw / 2, sh / 2);
   tt.concatenate(tr);
   g.drawImage(img, tt, null);
   return new JREImage(dst);
 }
Ejemplo n.º 3
0
 public void move() {
   objtimer++;
   // move
   if (xmot.random && objtimer % (int) (35 * xmot.randomchg) == 0) {
     xspeed = xmot.speed * random(-1, 1, 2);
   }
   if (ymot.random && objtimer % (int) (35 * ymot.randomchg) == 0) {
     yspeed = ymot.speed * random(-1, 1, 2);
   }
   if (player != null) {
     double playerdist =
         Math.sqrt((player.x - x) * (player.x - x) + (player.y - y) * (player.y - y))
             * 100.0
             / (pfWidth());
     if (xmot.toplayer && playerdist > xmot.toplayermin && playerdist < xmot.toplayermax) {
       xspeed = 0;
       x += xmot.speed * (player.x > x ? 1 : -1);
     } else if (xmot.frplayer
         && playerdist > xmot.frplayermin
         && playerdist < xmot.frplayermax) {
       xspeed = 0;
       x += xmot.speed * (player.x < x ? 1 : -1);
     }
     if (ymot.toplayer && playerdist > ymot.toplayermin && playerdist < ymot.toplayermax) {
       yspeed = 0;
       y += ymot.speed * (player.y > y ? 1 : -1);
     } else if (ymot.frplayer
         && playerdist > ymot.frplayermin
         && playerdist < ymot.frplayermax) {
       yspeed = 0;
       y += ymot.speed * (player.y < y ? 1 : -1);
     }
   }
   // react to background
   int bounces = 0;
   if (bouncesides.equals("any")) {
     bounces |= 15;
   } else if (bouncesides.equals("top")) {
     bounces |= 1;
   } else if (bouncesides.equals("bottom")) {
     bounces |= 2;
   } else if (bouncesides.equals("topbottom")) {
     bounces |= 3;
   } else if (bouncesides.equals("left")) {
     bounces |= 4;
   } else if (bouncesides.equals("right")) {
     bounces |= 8;
   } else if (bouncesides.equals("leftright")) {
     bounces |= 12;
   }
   if ((bounces & 1) != 0 && y < 0) {
     y = 0;
     if (yspeed < 0) yspeed = -yspeed;
   }
   if ((bounces & 2) != 0 && y > pfHeight() - 16) {
     y = pfHeight() - 16;
     if (yspeed > 0) yspeed = -yspeed;
   }
   if ((bounces & 4) != 0 && x < 0) {
     x = 0;
     if (xspeed < 0) xspeed = -xspeed;
   }
   if ((bounces & 8) != 0 && x > pfWidth() - 16) {
     x = pfWidth() - 16;
     if (xspeed > 0) xspeed = -xspeed;
   }
   // shoot
   if (shoot && shootfreq > 0.0 && objtimer % (int) (shootfreq * 35) == 0) {
     if (shootdir.equals("left")) {
       new AgentBullet(x, y, bullettype, sprite, diebgtype | blockbgtype, -shootspeed, 0);
     } else if (shootdir.equals("right")) {
       new AgentBullet(x, y, bullettype, sprite, diebgtype | blockbgtype, shootspeed, 0);
     } else if (shootdir.equals("up")) {
       new AgentBullet(x, y, bullettype, sprite, diebgtype | blockbgtype, 0, -shootspeed);
     } else if (shootdir.equals("down")) {
       new AgentBullet(x, y, bullettype, sprite, diebgtype | blockbgtype, 0, shootspeed);
     } else if (shootdir.equals("player") && player != null) {
       double angle = Math.atan2(player.x - x, player.y - y);
       new AgentBullet(
           x,
           y,
           bullettype,
           sprite,
           diebgtype | blockbgtype,
           shootspeed * Math.sin(angle),
           shootspeed * Math.cos(angle));
     }
   }
 }