📄 particlesystem.java
字号:
import java.util.Random;
import javax.microedition.lcdui.Graphics;
public class ParticleSystem
{
public static final int STATE_LEFT = 0;
public static final int STATE_RIGHT = 2;
public static final int STATE_NONE = 3;
private int windFactor;
private int nParticles;
private int positionX[];
private int positionY[];
private Random random;
private Imp particle;
public ParticleSystem(Landscape landscape)
{
random = new Random();
nParticles = 0;
if(Landscape.type == 0)
{
nParticles = 30;
positionX = new int[nParticles];
positionY = new int[nParticles];
particle = new Imp("/particle_snow.png", 1);
for(int i = 0; i < nParticles; i++)
{
positionX[i] = Math.abs(random.nextInt()) % 300;
positionY[i] = Math.abs(random.nextInt()) % 150;
}
} else
if(Landscape.type == 2 || Landscape.type == 3)
{
nParticles = 15;
positionX = new int[nParticles];
positionY = new int[nParticles];
particle = new Imp("/particle_leaf.png", 1);
for(int j = 0; j < nParticles; j++)
{
positionX[j] = Math.abs(random.nextInt()) % 300;
positionY[j] = Math.abs(random.nextInt()) % 150;
}
}
}
public void setWind(int i)
{
windFactor = i;
}
public void runFrame()
{
for(int i = 0; i < nParticles; i++)
{
if(Landscape.type == 0)
{
if(windFactor < 0)
positionX[i] += (Math.abs(random.nextInt()) & 0x7) - 4 - 2;
else
positionX[i] += ((Math.abs(random.nextInt()) & 0x7) - 4) + 2;
} else
if(Landscape.type == 2 || Landscape.type == 3)
if(windFactor < 0)
positionX[i] += (Math.abs(random.nextInt()) & 0x7) - 4 - 4;
else
positionX[i] += ((Math.abs(random.nextInt()) & 0x7) - 4) + 4;
positionY[i] += Math.abs(random.nextInt()) & 0x3;
if(positionY[i] > 150)
{
positionX[i] = Math.abs(random.nextInt()) % 300;
positionY[i] = -5;
}
}
}
public void paint(Graphics g)
{
for(int i = 0; i < nParticles; i++)
{
particle.setPosition(positionX[i] + Landscape.levelX, positionY[i] + Landscape.levelY);
particle.setFrame(((particle.curFrame++ >> 1) + 1) % particle.frameCount);
particle.paint(g);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -