📄 weapon.java
字号:
import java.util.Random;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
public class Weapon
{
public static boolean wormHit = false;
public static final int WEAPON_NONE = -1;
public static final int WEAPON_ROCKET = 0;
public static final int WEAPON_MORTAR = 1;
public static final int WEAPON_CLUSTER = 2;
public static final int WEAPON_GRENADE = 3;
public static final int WEAPON_DYNAMITE = 4;
private static final int WEAPON_CLUSTLETS = 5;
private static final int gravity = -2501;
private static final int STATE_IDLE = 0;
private static final int STATE_IN_AIR = 1;
private static final int STATE_ON_GROUND = 2;
private static int state;
private static int collisionX;
private static int collisionY;
private static int positionX;
private static int positionY;
private static int oldPositionX;
private static int oldPositionY;
public static Imp rocket;
public static Imp grenade;
public static Imp mortar;
public static Imp cluster;
public static Imp clustlet;
public static Imp dynamite;
private static final int SMOKE_SIZE = 10;
private static Landscape landscape;
private static int initialX;
private static int initialY;
private static int time;
private static int deltaTime;
private static int sinAng[] = new int[4];
private static int cosAng[] = new int[4];
private static int sinAngleI[] = new int[4];
private static int cosAngleI[] = new int[4];
private static int gravityI[] = new int[4];
private static int gravityAdd[] = new int[4];
private static long launchTime;
private static int blowUpTime;
private static int activeWeapon;
private static Game game;
private static Random random = new Random();
private static int clustletX[] = new int[4];
private static int clustletY[] = new int[4];
private static int clustletStartFrame[] = new int[4];
private static boolean clustletExploded[] = new boolean[4];
private static int curExplosion;
private static int explosionX[] = new int[4];
private static int explosionY[] = new int[4];
private static long explosionStartTime[] = new long[4];
public static Imp explosion1;
public static Imp curExplosionSpr;
private static int velocity;
private static int angle;
private static int vectorX;
private static int vectorY;
private static int ox;
private static int oy;
private static int vx;
private static int vy;
private static int desiredRotFrame;
private static int curWind;
private static int windFactor;
private static int smokeTrailX[] = new int[15];
private static int smokeTrailY[] = new int[15];
private static int smokeTrailSize[] = new int[15];
private static int curTrail;
private static int weaponIterationCount;
private static Worm parentWorm;
public static Image WeaponIcons;
private static int deviceTimerDivide = 30;
private static boolean explodeTerrain[] = {
true, true, true, true
};
private static int explosionFrame[] = {
0, 0, 0, 0
};
private static int ppe_x;
private static int ppe_y;
private static int ppe_w;
private static int ppe_h;
private static final int explosionFrameCount = 70;
private static int explosionHeight;
private static boolean doneQuartile1[] = {
false, false, false, false
};
private static boolean doneQuartile2[] = {
false, false, false, false
};
private static boolean doneQuartile3[] = {
false, false, false, false
};
private static boolean doneQuartile4[] = {
false, false, false, false
};
public Weapon()
{
}
public static void init()
{
curExplosionSpr = explosion1;
for(int i = 0; i < explosionStartTime.length; i++)
explosionStartTime[i] = -1L;
}
public static void fire(Game game1, Landscape landscape1, Worm worm, int i, int j, int k, int l, int i1,
int j1, boolean flag)
{
parentWorm = worm;
windFactor = l;
game = game1;
activeWeapon = i;
if(i1 < 22)
i1 = 22;
if(i == 0 || i == 1 || i == 3 || i == 2)
state = 1;
if(i == 4)
state = 2;
landscape = landscape1;
weaponIterationCount = 0;
positionX = oldPositionX = vectorX = initialX = j;
positionY = oldPositionY = vectorY = initialY = k;
curWind = 0;
velocity = i1;
angle = j1;
rocket.setFrame(((angle + 270) % 360) / 20);
mortar.setFrame(rocket.getFrame());
if(flag)
launchTime = Worms.getTime();
curExplosion = 0;
for(int k1 = 0; k1 < explosionStartTime.length; k1++)
explosionStartTime[k1] = -1L;
for(int l1 = 0; l1 < clustletExploded.length; l1++)
clustletExploded[l1] = false;
for(int i2 = 0; i2 < clustletStartFrame.length; i2++)
clustletStartFrame[i2] = Math.abs(random.nextInt()) % 3;
deltaTime = 30;
sinAng[0] = Game.table[angle % 360] * velocity;
cosAng[0] = Game.table[(angle + 90) % 360] * velocity;
time = 60;
sinAng[0] *= deltaTime;
cosAng[0] *= deltaTime;
sinAngleI[0] = 0;
cosAngleI[0] = 0;
gravityAdd[0] = -2501 * deltaTime;
gravityI[0] = 0;
explosion1.setVisible(false);
for(int j2 = 0; j2 < smokeTrailX.length; j2++)
{
smokeTrailX[j2] = -1;
smokeTrailY[j2] = -1;
}
curTrail = 0;
}
private static void explode(int i, int j, int k)
{
curExplosion %= 3;
if(explosionStartTime[curExplosion] != -1L)
return;
curExplosionSpr = explosion1;
explosionX[curExplosion] = i;
explosionY[curExplosion] = j;
explosionStartTime[curExplosion] = Worms.getTime();
curExplosionSpr.setVisible(true);
char c = '\001';
char c1 = '\001';
if(k == 0)
{
explosionHeight = 15;
c1 = '\341';
c = '\u0CCC';
}
if(k == 1)
{
explosionHeight = 35;
c1 = '\u0271';
c = '\u0CCC';
}
if(k == 2)
{
explosionHeight = 50;
c1 = '\u09C4';
c = '\u03D7';
}
for(int l = 0; l < game.teams.length; l++)
{
for(int i1 = 0; i1 < game.teams[l].wormList.length; i1++)
{
Worm worm = game.teams[l].wormList[i1];
int j1 = worm.positionX - explosionX[curExplosion];
int k1 = worm.positionY - explosionY[curExplosion];
int l1 = j1 * j1 + k1 * k1;
if(l1 < c1)
{
int i2 = (c1 - l1) * c >> 16;
worm.healthCountStartTime = Worms.getTime();
worm.healthCountDown += i2;
wormHit = true;
}
}
}
curExplosion++;
curExplosion %= 3;
}
private static void weaponDone()
{
boolean flag = true;
for(int i = 0; i < explosionStartTime.length; i++)
if(explosionStartTime[i] != -1L)
flag = false;
for(int j = 0; j < smokeTrailSize.length; j++)
if(smokeTrailSize[j] != 0)
flag = false;
if(flag)
{
state = 0;
game.endTurn(true);
}
}
public static void runFrame()
{
label0:
{
label1:
{
label2:
{
if(state == 0)
return;
for(int i = 0; i < smokeTrailSize.length; i++)
{
smokeTrailSize[i]--;
if(smokeTrailSize[i] < 0)
smokeTrailSize[i] = 0;
}
if(activeWeapon == -1)
weaponDone();
if(state == 2 && activeWeapon != -1)
{
blowUpTime = 6 - (int)(Worms.getTime() - launchTime) / 1000;
positionX = initialX;
positionY = initialY;
if(activeWeapon == 4)
{
if(blowUpTime == 0)
{
explode(positionX, positionY, 2);
activeWeapon = -1;
}
dynamite.setFrame((Game.curFrame / 4) % dynamite.frameCount);
}
}
if(state != 1 || activeWeapon == -1)
break label0;
if(activeWeapon == 5)
break label1;
blowUpTime = 3 - (int)(Worms.getTime() - launchTime) / 1000;
weaponIterationCount++;
oldPositionX = positionX;
oldPositionY = positionY;
positionX = initialX + (cosAngleI[0] >> 16) + (curWind >> 8);
positionY = initialY - (sinAngleI[0] + (gravityI[0] >> 9) * time >> 16);
ox = cosAngleI[0] + (curWind >> 8);
oy = sinAngleI[0] + (gravityI[0] * time >> 9);
time += deltaTime;
curWind += windFactor;
sinAngleI[0] += sinAng[0];
cosAngleI[0] += cosAng[0];
gravityI[0] += gravityAdd[0];
vx = cosAngleI[0] - ox;
vy = (sinAngleI[0] + (gravityI[0] * time >> 9)) - oy;
vx >>= 15;
vy >>= 15;
if(vy > 0 && vx >= 0)
{
if(vx > 19)
vx = 19;
if(vy > 19)
vy = 19;
desiredRotFrame = 17 - Game.vectorTable[vy * 20 + vx] / 5120;
} else
if(vy <= 0 && vx >= 0)
{
vy = -vy;
if(vx > 19)
vx = 19;
if(vy > 19)
vy = 19;
desiredRotFrame = 9 + Game.vectorTable[vy * 20 + vx] / 5120;
} else
if(vy > 0 && vx < 0)
{
vx = -vx;
if(vx > 19)
vx = 19;
if(vy > 19)
vy = 19;
desiredRotFrame = Game.vectorTable[vy * 20 + vx] / 5120;
} else
if(vy <= 0 && vx < 0)
{
vy = -vy;
vx = -vx;
if(vx > 19)
vx = 19;
if(vy > 19)
vy = 19;
desiredRotFrame = 9 - Game.vectorTable[vy * 20 + vx] / 5120;
}
if(rocket.getFrame() < desiredRotFrame)
rocket.setFrame(rocket.getFrame() + 1);
else
if(rocket.getFrame() > desiredRotFrame)
rocket.setFrame(rocket.getFrame() - 1);
mortar.setFrame(rocket.getFrame());
vectorX = positionX;
vectorY = positionY;
curTrail++;
curTrail %= smokeTrailX.length - 1;
smokeTrailX[curTrail] = positionX;
smokeTrailY[curTrail] = positionY;
if(positionX >= 0)
{
Landscape _tmp = landscape;
if(positionX <= 300)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -