📄 plane.java
字号:
// Plane class
import javax.microedition.lcdui.*;
class Plane
{
public int x; // X location of plane
public int y; // Y location of plane
public int oldX; // Old X location
public int oldY; // Old Y location
private int width; // Width of plane gfx
private int height; // Height of plane gfx
public int mx; // Amount of x pixels to move plane right
private int my; // Amount of y pixels to move plane down
private int xStart; // Plane column start location
private int xEnd; // Plane column end location
private int yStart; // Plane row start location
private int yEnd; // Plane row end location
public int down; // Amount of times the plane has moved down
public int speedInc; // How often the speed increases
// Create a Plane Class
// Store all required variables
Plane(int iWidth, int iHeight, int moveX, int moveY, int iXS, int iXE, int iYS, int iYE)
{
this.x = 0;
this.y = 0;
this.oldX = this.x;
this.oldY = this.y;
this.width = iWidth;
this.height = iHeight;
this.mx = moveX;
this.my = moveY;
this.xStart = iXS;
this.xEnd = iXE;
this.yStart = iYS;
this.yEnd = iYE;
}
// Get x
int getX()
{
return this.x;
}
// Get y
int getY()
{
return this.y;
}
// Get oldX
int getOldX()
{
return this.oldX;
}
// Get y
int getOldY()
{
return this.oldY;
}
// Get width
int getWidth()
{
return this.width;
}
// Get Height
int getHeight()
{
return this.height;
}
// Initialize a plane as per the start of a level
void init(int moveX, int howOften)
{
this.x = this.xStart;
this.y = this.yStart;
this.oldX = this.x;
this.oldY = this.y;
this.mx = moveX;
this.down = 0;
this.speedInc = howOften;
}
// Move the plane - return true if plane lands
// the level determines the how often the plane is sped up
boolean move()
{
// Save the location so we can replace the background
this.oldX = this.x;
this.oldY = this.y;
// First check to see if we have landed
if (this.y >= this.yEnd && (this.x + this.mx + this.width) >= this.xEnd) return true;
// Calculate the new location
this.x += this.mx;
if (this.x > xEnd)
{
this.x = this.xStart;
this.y += my;
this.down++;
if ((this.down % this.speedInc) == 0) this.mx++;
if (this.mx > 4) this.mx = 4;
}
return false;
}
void setSpeed(int moveX)
{
this.mx = moveX;
}
boolean moveDown()
{
// First check to see if we have landed
if (this.y >= this.yEnd) return true;
this.y += my;
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -