📄 ball.java
字号:
package com.soccer;
import javax.microedition.lcdui.Graphics;
public class Ball extends Sprite {
public Ball() {
ballSpeed = speeds[0].length;
lastBallOwner = -1;
super.x = 0;
super.y = 0;
super.speed = 1;
super.direction = 0;
super.frame = 0;
super.type = 2;
super.targetReached = true;
}
public int ballMove() {
if (ballSpeed < speeds[super.direction].length) {
if (ballSpeed >= 0) {
if (ballSpeed == 0) {
SPlayer.play(1);
}
ballSpeed++;
return move( (xCoeff * speeds[super.direction][ballSpeed - 1][0]) / 10,
speeds[super.direction][ballSpeed - 1][1]);
} else {
ballSpeed++;
return 0;
}
} else {
return 0;
}
}
public void draw(Graphics g) {
g.setClip( -GameScreen.fieldX + super.x,
-GameScreen.fieldY + GameScreen.infoHeight + super.y, super.sW,
super.sH);
g.drawImage(GameScreen.ballImage, -GameScreen.fieldX + super.x,
( -GameScreen.fieldY + GameScreen.infoHeight + super.y) -
super.frame * super.sH, 0);
g.setClip(0, 0, GameScreen.gWidth, GameScreen.gHeight);
}
public void kickBall(int i) {
kickBall(i, 0);
}
public void kickBall(int i, int j, int k) {
super.direction = i;
ballSpeed = j;
xCoeff = k;
}
public void kickBall(int i, int j) {
kickBall(i, j, 10);
}
public void setPos(int i, int j) {
super.frame = (super.frame + 1) % 2;
super.setPos(i, j);
}
public static final int speeds[][][] = { { {
0, -15
}
, {
0, -13
}
, {
0, -11
}
, {
0, -9
}
, {
0, -7
}
, {
0, -5
}
, {
0, -3
}
, {
0, -1
}
}
, { {
15, -15
}
, {
13, -13
}
, {
11, -11
}
, {
9, -9
}
, {
7, -7
}
, {
5, -5
}
, {
3, -3
}
, {
1, -1
}
}
, { {
15, 0
}
, {
13, 0
}
, {
11, 0
}
, {
9, 0
}
, {
7, 0
}
, {
5, 0
}
, {
3, 0
}
, {
1, 0
}
}
, { {
15, 15
}
, {
13, 13
}
, {
11, 11
}
, {
9, 9
}
, {
7, 7
}
, {
5, 5
}
, {
3, 3
}
, {
1, 1
}
}
, { {
0, 15
}
, {
0, 13
}
, {
0, 11
}
, {
0, 9
}
, {
0, 7
}
, {
0, 5
}
, {
0, 3
}
, {
0, 1
}
}
, { {
-15, 15
}
, {
-13, 13
}
, {
-11, 11
}
, {
-9, 9
}
, {
-7, 7
}
, {
-5, 5
}
, {
-3, 3
}
, {
-1, 1
}
}
, { {
-15, 0
}
, {
-13, 0
}
, {
-11, 0
}
, {
-9, 0
}
, {
-7, 0
}
, {
-5, 0
}
, {
-3, 0
}
, {
-1, 0
}
}
, { {
-15, -15
}
, {
-13, -13
}
, {
-11, -11
}
, {
-9, -9
}
, {
-7, -7
}
, {
-5, -5
}
, {
-3, -3
}
, {
-1, -1
}
}
};
public int ballSpeed;
public int lastBallOwner;
public int xCoeff;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -