1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
| import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.awt.geom.*; import java.util.ArrayList; import java.util.*; import java.io.*;
public class LevelSelect extends JPanel implements MouseMotionListener,MouseListener { public static Image bufferImage; public Image background = Toolkit.getDefaultToolkit().getImage("images/misc/background1.png"); public Game GamePanel = new Game(); public int ctr; private ArrayList a = new ArrayList(); Random rnd = new Random(); FontMetrics fm; Font cookies; AnimUpdate update; public LevelSelect() { setDoubleBuffered(false); setIgnoreRepaint(true); rnd.setSeed(System.currentTimeMillis()); setLayout(new GridLayout()); addMouseListener(this); addMouseMotionListener(this); add(GamePanel); GamePanel.setSize(this.getWidth(),this.getHeight()); GamePanel.setVisible(false); cookies = GameScreens.cookies.deriveFont((float)24); fm = getFontMetrics(cookies); for (int i=0; i<1; i++) { FakeBlock fb = new FakeBlock(); fb.blockType=rnd.nextInt(8)+1; fb.speed=(rnd.nextInt(4)+2)*2; fb.xPos=rnd.nextInt(481); fb.yPos=15+i*65; fb.setImage(); a.add(fb); } update = new AnimUpdate(); update.start(); setVisible(true); } public void paintComponent(Graphics g) { Graphics2D g2; if (bufferImage == null) { bufferImage = createImage(this.getWidth(),this.getHeight()); g2 = (Graphics2D)bufferImage.getGraphics(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); } g2 = (Graphics2D)bufferImage.getGraphics(); g2.setFont(cookies);
String str2 = "Click to Continue"; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); g2.drawImage(GameScreens.background,0,0,null); AlphaComposite ac; ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER,(float).4); g2.setComposite(ac); for (int i=0; i<a.size(); i++) { FakeBlock fb = (FakeBlock)a.get(i); fb.move(); g2.drawImage(fb.myPicture,fb.xPos,fb.yPos,null); } ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER,(float)1); g2.setComposite(ac); g2.drawImage(GameScreens.titleScr,0,0,null); ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER,(float)Math.abs(Math.sin(Math.toRadians(ctr%180)))); g2.setComposite(ac); g2.drawString(str2,(int)((this.getWidth()-fm.stringWidth(str2))/2.0),320); g.drawImage(bufferImage,0,0,null); } public void update(Graphics g) { paintImmediately(0,0,480,400); } public void paint(Graphics g) { paintComponent(g); } public void mouseDragged(MouseEvent e) { } public void mouseMoved(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { GameScreens.goGameScreen(); } public void mouseClicked(MouseEvent e) { } public void mouseEntered(MouseEvent e){ } public void mouseExited(MouseEvent e) { } class FakeBlock { public int blockType; public AlphaComposite alpha; public int xPos; public int yPos; public double speed; public double alphaOffset; public double alphaSpeed; public Image myPicture; public FakeBlock() { } public void setImage() {
if (blockType == 0) { myPicture=GameScreens.one; } else if(blockType ==1) { myPicture=GameScreens.two; } else if (blockType == 2) { myPicture=GameScreens.thr; } else if (blockType == 3) { myPicture=GameScreens.fou; } else if(blockType == 4) { myPicture=GameScreens.fiv; } else if (blockType == 5) { myPicture=GameScreens.six; } else if (blockType == 6) { myPicture=GameScreens.sev; } else if (blockType == 7) { myPicture=GameScreens.eig; } else if (blockType == 8) { myPicture=GameScreens.nin; } } public void paint(Graphics g) { paintComponent(g); } public void move() { xPos += (int)speed; if (xPos > 481) { blockType=rnd.nextInt(8)+1; speed=(rnd.nextInt(4)+2)*2; xPos=-32-rnd.nextInt(200);
setImage(); } } } class AnimUpdate extends Thread { public void run() { while(Thread.currentThread() == update) { paintImmediately(0,0,480,400); ++ctr; try { Thread.sleep(16); } catch(InterruptedException e) { System.out.println("InterruptedException @ AnimUpdate"); } } } } } |