📄 fireworkscanvas.java
字号:
// Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3)
// Source File Name: FireworksCanvas.java
package matchit2;
import java.util.Random;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;
// Referenced classes of package matchit2:
// DoublyLinkedList, Spark, GameScreen
class FireworksCanvas extends GameCanvas
implements Runnable
{
FireworksCanvas(GameScreen g)
{
super(false);
x = 0;
animationThread = null;
setFullScreenMode(true);
gamescreen = g;
try
{
won = Image.createImage("/res/img/wonall.png");
Image img = Image.createImage("/res/img/cong.png");
len = img.getWidth();
cong = Image.createImage(len + getWidth() * 2, img.getHeight());
cong.getGraphics().setColor(0);
cong.getGraphics().fillRect(0, 0, cong.getWidth(), cong.getHeight());
cong.getGraphics().drawImage(img, getWidth(), 0, 0);
img = null;
}
catch(Exception e)
{
e.printStackTrace();
}
x = getWidth();
}
synchronized void start()
{
animationThread = new Thread(this);
animationThread.start();
}
synchronized void stop()
{
animationThread = null;
}
public void run()
{
Thread currentThread = Thread.currentThread();
try
{
while(currentThread == animationThread)
{
long startTime = System.currentTimeMillis();
tick();
repaint(0, 0, getWidth(), getHeight());
serviceRepaints();
long timeTaken = System.currentTimeMillis() - startTime;
if(timeTaken < 100L)
{
synchronized(this)
{
wait(100L - timeTaken);
x = x + 1;
if(x > getWidth() + len)
x = 0;
}
} else
{
Thread _tmp = currentThread;
Thread.yield();
}
}
}
catch(InterruptedException e) { }
}
public void paint(Graphics g)
{
g.setColor(0);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0xffff00);
Image img = Image.createImage(cong, x, 0, getWidth(), cong.getHeight(), 0);
g.drawImage(img, 0, 25, 0);
img = null;
g.drawImage(won, (getWidth() - won.getWidth()) / 2, 55, 0);
g.setColor(65535);
g.drawString("By Xinyun Liu", 5, getHeight() - 55, 0);
g.drawString("robotskin@hotmail.com", 5, getHeight() - 40, 0);
g.drawString("Nov.2004. All rights reserved", 5, getHeight() - 25, 0);
drawAllSparks(g);
}
protected void pointerPressed(int x, int y)
{
gamescreen.goMain();
}
public void keyPressed(int keyCode)
{
keyCode = getGameAction(keyCode);
if(keyCode == 8)
gamescreen.goMain();
}
private synchronized void tick()
{
Spark nextSpark;
for(Spark currentSpark = (Spark)sparkList.getFirst(); currentSpark != null; currentSpark = nextSpark)
{
nextSpark = (Spark)sparkList.getNext(currentSpark);
currentSpark.tick();
}
if(sparkList.isEmpty() || rand(5) == 0)
explode();
}
private void explode()
{
int colour;
if(useColour)
colour = colours[rand(colours.length)];
else
colour = 0xffffff;
int x = rand(getWidth() / 2) + getWidth() / 4 << 8;
int y = rand(getHeight() / 2) + getHeight() / 4 << 8;
for(int i = 0; i < 6; i++)
{
for(int j = 0; j < 6; j++)
{
int projectedAngle = i * 3 + rand(3);
int planeAngle = j * 3 + rand(3);
int magnitudeTimes256 = 2 * cosineTimes256(planeAngle);
int vx = (cosineTimes256(projectedAngle) * magnitudeTimes256 << 8) >> 16;
int vy = (sineTimes256(projectedAngle) * magnitudeTimes256 << 8) >> 16;
int timeToLive = 30 + rand(30);
Spark spark = new Spark(x, y, vx, vy, colour, timeToLive);
sparkList.addFirst(spark);
}
}
}
private synchronized void drawAllSparks(Graphics g)
{
Spark nextSpark;
for(Spark currentSpark = (Spark)sparkList.getFirst(); currentSpark != null; currentSpark = nextSpark)
{
nextSpark = (Spark)sparkList.getNext(currentSpark);
currentSpark.draw(g);
}
}
private int rand(int scale)
{
return ((random.nextInt() << 1) >>> 1) % scale;
}
private static int sineTimes256(int angle)
{
angle %= 36;
if(angle <= 9)
return SINES[angle];
if(angle <= 18)
return SINES[18 - angle];
if(angle <= 27)
return -SINES[angle - 18];
else
return -SINES[36 - angle];
}
private static int cosineTimes256(int angle)
{
return sineTimes256(angle + 9);
}
private static final int KEY_SOFTKEY1 = -6;
private static final int KEY_SOFTKEY2 = -7;
private static final int KEY_SOFTKEY3 = -5;
private int x;
private int len;
private Image cong;
private Image won;
static final int FIXED_POINT_SHIFT = 8;
private static final int MILLIS_PER_TICK = 100;
private static final int TICKS_PER_EXPLOSION = 5;
private static final int SPARK_LIFE_IN_TICKS = 30;
private static final int SPARK_RANDOM_LIFE_IN_TICKS = 20;
private static final int SPARK_VELOCITY = 2;
private static final int colours[] = {
0xff0000, 65280, 0xffff00, 0xff00ff, 65535
};
private final GameScreen gamescreen;
private final boolean useColour = true;
private final Random random = new Random();
private final DoublyLinkedList sparkList = new DoublyLinkedList();
private volatile Thread animationThread;
private static final int SINES[] = {
0, 44, 88, 128, 165, 196, 222, 241, 252, 256
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -