📄 gameplayer.java
字号:
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
public class GamePlayer{
static final String Name[] = {"刘翔", "杰克逊", "特拉梅尔", "约翰逊"};
static final String Country[] = {"中国", "美国", "", ""};
static final int Skill[] = { 10, 8, 9, 8};
static final int Power[] = { 7, 9, 8, 9};
static final int Speed[] = { 10, 9, 10, 9};
private static final int posmsg[][] = {
// act1
{0,0,26,20,0,14},
// act2
{26,0,18,20,0,13},
{112,37,11,8,-10,25},
{106,0,6,7,17,11},
// act3
{46,0,17,21,0,8},
{111,64,12,10,-12,20},
{113,29,12,8,15,12},
{106,0,6,7,15,6},
// act4
{63,0,25,23,0,9},
{111,21,12,8,-11,22},
{106,0,6,7,18,6},
{88,0,37,21,0,0},
{0,20,16,33,0,0},
{33,45,11,10,16,4},
{94,21,16,15,-16,14},
{110,74,7,10,15,22},
{106,0,6,7,14,-2},
{18,22,13,32,0,0},
{106,0,6,7,11,-3},
{32,21,19,24,0,-3},
{113,29,12,8,19,4},
{113,47,11,9,-10,11},
{98,38,15,17,11,15},
{106,0,6,7,16,-2},
{51,23,21,33,0,-1},
{111,21,12,8,-11,14},
{106,0,6,7,21,0},
{72,23,23,30,0,0},
{106,0,6,7,17,-4},
// act11
{24,55,29,27,0,5},
{106,0,6,7,23,1},
// act12
{54,56,32,23,0,0},
{106,0,6,7,23,3},
// act13
{24,83,26,15,0,0},
{0,89,24,13,5,14},
{106,0,6,7,14,-2},
// act14
{51,79,40,22,0,10},
// act15
{92,84,32,15,0,18},
{106,0,6,7,32,22}
};
private static final int act[] = {
0, 1, 4, 8, 11, 12, 17, 19, 24, 27, 29, 31, 33, 36, 37, 39
};
private static final int jumpPos[] = {-5,-3,-1,0,1,3,5};
//动作序列
static final int readyAct[] = {0,1}; //2 -goodReady / 3 -badReady
static final int runAct[] = {7,6,5,6};
static final int jumpAct[] = {9,9,4,4,4,12,12}; // 8 -冲线
static final int tripAct[] = {10,10,13,14,14};
static final int takeoff[] = {2,3};
static final int sprint[] = {8};
static final int stopAct[] = {6};
public GamePlayer(){
init();
}
public void init(){
currAct = readyAct;
frame = 0;
isJump = false;
isTrip = false;
isFinish = false;
isReady = false;
counter = 0;
time = 0;
speed = 0;
power = 0;
skill = 0;
score = 0;
jumpIndex = 0;
MaxSpeed = 0;
counter = 0; //计数器
finishNum = 0;
}
public void paint(Graphics g) {
for(int j=act[currAct[frame]]; j<act[currAct[frame]+1]; j++){
g.setClip(x+posmsg[j][4], y+posmsg[j][5], posmsg[j][2], posmsg[j][3]);
g.drawImage(img, x-posmsg[j][0]+posmsg[j][4], y-posmsg[j][1]+posmsg[j][5], 20);
}
g.setClip(0, 0, GameScreen.screenW, GameScreen.screenH);
}
public void run() {
/*
// when ready
if(currAct==readyAct){
if(counter==5){
changeFrame();
}
if(counter>11){
isReady = true;
counter = 0;
}
counter++;
}
*/
// when take-off
if(currAct==takeoff){
changeActSequence(runAct);
}
// when jump
if(isJump){
y += jumpPos[jumpIndex%jumpPos.length];
jumpIndex++;
}
if(jumpIndex>=jumpPos.length){
changeActSequence(runAct);
jumpIndex = 0;
isJump = false;
}
// when trip
if(isTrip){
if(frame>3){
speed = 0;
}
if(frame>=tripAct.length-1){
if(currAct!=stopAct)
currAct = stopAct;
}
}
if(currAct==stopAct)
counter++;
// when finish
if(currAct==sprint){
if(counter==0)
finishNum++;
if(counter++>3){
changeActSequence(stopAct);
speed = 0;
counter = 0;
}
}
if(currAct!=readyAct)
changeFrame();
}
public boolean comeBack(){
if(counter+power>11){
counter = 0;
return true;
}
return false;
}
public void move(int speed){
x += speed;
}
public void changeSpeed(int speed){
if(speed>MaxSpeed)
this.speed = MaxSpeed;
else{
if(speed<0)
speed = 0;
this.speed = speed;
}
}
public int getSpeed(){
return speed;
}
public void changeTripState(boolean now){
isTrip = now;
}
public boolean getTripState(){
return isTrip;
}
public void changeJumpState(boolean now){
isJump = now;
}
public boolean getJumpState(){
return isJump;
}
public void changeFinishState(boolean now){
isFinish = now;
}
public boolean getFinishState(){
return isFinish;
}
public void changeReadyState(boolean now){
isReady = now;
}
public boolean getReadyState(){
return isReady;
}
public void setPosition(int x,int y){
this.x = x;
this.y = y;
}
public int getX(){
return x;
}
public int getY(){
return y;
}
public void setImage(Image image){
img = image;
}
public void changeActSequence(int now[]){
currAct = now;
frame = 0;
counter = 0;
}
public void changeFrame(){
frame++;
if(frame>=currAct.length)
frame = 0;
}
public void changeTime(){
time++;
}
public int getTime(){
return time;
}
public void changePower(int curr){
power = curr;
}
public int getCileW(){
return posmsg[act[currAct[frame]]][2];
}
public int getCileH(){
return posmsg[act[currAct[frame]]][3];
}
public int getSkill(){
return skill;
}
public int getPower(){
return power;
}
public static int getFinishNum(){
return finishNum;
}
public int getMaxSpeed(){
return MaxSpeed;
}
public int getScore(){
return score;
}
public void setScore(int newScore){
score = newScore;
}
public void setup(int id){
name = Name[id];
skill = Skill[id];
power = Power[id];
MaxSpeed = Speed[id];
speed = 0;
}
private String name = null;
private int currAct[];
private int frame;
private Image img;
private int x;
private int y;
private int speed;
private int power;
private int skill;
private int score;
private boolean isJump;
private boolean isTrip;
private boolean isFinish;
private boolean isReady;
private int jumpIndex;
//
private int MaxSpeed;
//
private int counter; //计数器
private int time;
private static int finishNum;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -