📄 cplayership.java
字号:
/*
* CPlayerShip.java
*
* Created on 2006年4月16日, 下午12:02
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package gamepacket;
import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
/**
*
* @author zxh
*=======玩家船类=========
*/
public class CPlayerShip
{
public CPlayerBomb[] Bomb;//玩家炸弹
public CBao m_Bao;
public int dx,dy;//玩家在屏幕上的坐标
public int Life;//玩家生命
public int Score;//玩家得分
private int Speed;//玩家移动速度
public boolean IsDead;//玩家是否死亡
private int width,height;//屏幕大小
public int MapX,MapY;//显示玩家在背景的坐标
//玩家船
public Sprite spt_playership;
/** Creates a new instance of CPlayerShip */
//构造,初始数据
public CPlayerShip (int scrWidth,int scrHeight,LayerManager lm)
{
this.Life=3;
this.Score=0;
this.Speed=3;
this.IsDead=false;//玩家没有死亡
this.width=scrWidth;
this.height=scrHeight;
//初始玩家在屏幕的位置
dx=width/2-20;
dy=70;
//初始玩家在背景的位置
MapY=0;
MapX=0;
m_Bao=new CBao(lm);
Bomb=new CPlayerBomb[]{
new CPlayerBomb(width,height,lm),
new CPlayerBomb(width,height,lm),
new CPlayerBomb(width,height,lm)
};//玩家炸弹
//Bomb=new CPlayerBomb(scrWidth,scrHeight,lm);
try
{
spt_playership=new Sprite(Image.createImage("/img/playership.png"),40,17);
} catch (IOException ex)
{}
lm.append (spt_playership);
spt_playership.setPosition (dx,dy);
spt_playership.setVisible (true);
}
//左移动
public void MoveLeft()
{
if(dx<360-width/2-20)
{
MapX-=Speed;
}
dx-=Speed;
if(dx<0)
{
dx=0;
}
if(MapX<0)
{
MapX=0;
}
spt_playership.setPosition (this.dx,this.dy);
}
//右移动
public void MoveRight()
{
if(dx>width/2-20)
{
MapX+=Speed;
}
dx+=Speed;
if(dx>360-40)
{
dx=320;
}
if(MapX>360-width)
{
MapX=360-width;
}
spt_playership.setPosition (this.dx,this.dy);
}
//发射炸弹
public void SendBomb()
{
for(int i=0;i<3;i++)
{
if(Bomb[i].GetShow ()==false)
{
Bomb[i].SetShow (true);//显示炸弹
Bomb[i].SetPoint (this.dx+20,this.dy+10);
break;
}
}
}
//==================
//得到速度
public int GetSpeed()
{
return this.Speed;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -