//************************************************************************ // creates animated card show for idle time or a win situation // Programmer: H K Gupta Date: 25 Oct1997 //************************************************************************ import java.awt.*; import java.awt.image.*; import java.applet.Applet; import java.lang.Math; public class HridayeshCardShow { private HridayeshLoadCards deckImages; private int x = -100; private int y; private int card; private int type = 0; public HridayeshCardShow(HridayeshLoadCards deckImages) { this.deckImages = deckImages; } private int steps = 0; private final int maxSteps = 250; public void draw(Graphics g, Canvas parent) { switch (type) { case 0: doSpiral(parent); break; case 1: doRandom(parent); break; case 2: doCrawl(parent); break; case 3: doPyramid(parent); break; case 4: doDoubleSpiral(g, parent); break; default: type = 0; steps = 0; } if(steps > maxSteps) { type++; steps = 0; Dimension d = parent.size(); g.setColor(Color.black); g.fillRect(0, 0, d.width, d.height); } else { g.drawImage(deckImages.getCardImage(card), x, y, parent); steps++; } } private double angle = 0.0; private void doSpiral(Canvas parent) { if(steps == 0) { angle = 0.0; } Dimension d = parent.size(); int radius = (steps * d.width / maxSteps / 2) + 50; double angInc = ((double)(maxSteps - steps)) / maxSteps / 5; angle += angInc; x = d.width / 2 + (int)(Math.sin(angle) * radius); y = d.height / 2 + (int)(Math.cos(angle) * radius); card = randomNumber(0, 51); } private void doDoubleSpiral(Graphics g, Canvas parent) { if(steps == 0) { angle = 0.0; } Dimension d = parent.size(); int radius = (steps * d.width / maxSteps / 4) + 50; double angInc = ((double)(maxSteps - steps)) / maxSteps / 5; angle += angInc; x = d.width / 3 + (int)(Math.sin(angle) * radius); y = d.height / 2 - 40 + (int)(Math.cos(angle) * radius); card = randomNumber(0, 51); g.drawImage(deckImages.getCardImage(51), x + d.width / 3, y, parent); } private int count = 0; private int xDir = -1; private int yDir = -1; private void doRandom(Canvas parent) { Dimension d = parent.size(); count++; if(count > 6) { count = 0; x = -100; } if((x < - 70) || (x > (d.width - 10)) || (y < - 80) || (y > (d.height - 10)) || ((xDir == 0) && (yDir == 0))) { card = randomNumber(0, 51); x = randomNumber(- 80, d.width - 10); y = randomNumber(- 90 + 10, d.height - 10); xDir = randomNumber(-1, 1); yDir = randomNumber(-1, 1); } else { x = x + xDir * 12; y = y + yDir * 12; } } private int directX = 1; private int directY = 1; private void doCrawl(Canvas parent) { Dimension d = parent.size(); if(steps == 0) { directX = 1; directY = 1; x = d.width / 2; y = d.height / 2; } if(x < - 70) directX = 1; if(x > (d.width - 10)) directX = -1; if(y < - 80) directY = 1; if(y > (d.height - 10)) directY = -1; card = randomNumber(0, 51); x = x + directX * 15; y = y + directY * 12; } private int miniSteps = 1; private int miniStepsTaken = 0; private void doPyramid(Canvas parent) { Dimension d = parent.size(); if(steps == 0) { miniSteps = 1; miniStepsTaken = 0; x = d.width / 2; y = 0; } if(miniStepsTaken >= miniSteps) { miniStepsTaken = 0; miniSteps += 2; y += 16; } card = randomNumber(0, 51); x = d.width / 2- 40 - (miniSteps / 2) * 15 + miniStepsTaken * 17; miniStepsTaken++; } private int randomNumber(int min, int max) { return (int)(Math.random() * (max - min + 1)) + min; } }