📄 capsule.java
字号:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.Random;
import java.lang.System;
public class Capsule extends MoveObject
{
private float right_r, left_r;
private float acc_r = 0.5f;
private RandomG randomG = new RandomG();
private boolean collisioned;
private boolean used = false;
public Capsule(String path, int x, int y, float vx, float vy, int type)
{
super(path, x, y, vx, vy, type);
}
public boolean CollisionWithObject(NormalObject ob)
{
float temp;
collisioned = false;
if ((ob.x - this.x - this.cx) < 3 && (ob.x - this.x - this.cx) > -1)
{
if ((this.y + this.cy >= ob.y) && (this.y <= ob.y + ob.cy))
{
if (this.vx - ob.vx > 0.0f)
{
collisioned = true;
this.vx = -1.0f * (this.vx - ob.vx);
ob.vx = -0.4f * ob.vx;
}
}
}
else
if ((this.x - (ob.x + ob.cx)) < 3 && (this.x - (ob.x + ob.cx)) > -1)
{
if ((this.y + this.cy >= ob.y) && (this.y <= ob.y + ob.cy))
{
if (ob.vx - this.vx > 0.0f)
{
collisioned = true;
this.vx = 1.0f * (ob.vx - this.vx);
ob.vx = -0.4f * ob.vx;
}
}
}
else
if ((ob.y - this.y - this.cy) < 2 && (ob.y - this.y - this.cy) > 0)
{
if ((this.x + this.cx >= ob.x) && (this.x <= ob.x + ob.cx))
{
if (this.vy - ob.vy > 0.0f)
{
collisioned = true;
this.vy = -1.0f * (this.vy - ob.vy);
this.vx += ((float)(randomG.nextG(5) % 30 - 15)) / 80.0f;
this.vx += ob.vx * 0.6;
}
}
}
else
if ((this.y - (ob.y + ob.cy)) < 2 && (this.y - (ob.y + ob.cy)) > 0)
{
if ((this.x + this.cx >= ob.x) && (this.x < ob.x + ob.cx))
{
if (ob.vy - this.vy > 0.0f)
{
collisioned = true;
this.vy = 1.0f * (ob.vy - this.vy);
this.vx += ((float)(randomG.nextG(5) % 30 - 15)) / 80.0f;
this.vx += ob.vx * 0.6;
}
}
}
return collisioned;
}
public void generateMove()
{
if ((vx - (int)vx) > 0.5f)
x += ((int)vx + 1);
else
x += (int)vx;
if ((vy - (int)vy) > 0.5f)
y += ((int)vy + 1);
else
y += (int)vy;
}
public void use()
{
this.used = true;
}
public boolean isUsed()
{
return this.used;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -