⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myman.java

📁 这是一个跳跳板的游戏的源代码,是一个不错的小游戏!
💻 JAVA
字号:
import javax.microedition.lcdui.*;


class myMan  {
	/** 储存主角图像的变量*/
	Image				meLeft;
    Image               meRight;
    Image               jumpLeft;
    Image               jumpRight;
    Image               img3;
	Image               img4;
    Image               handLeft;
    Image               handRight;
    int x,y;
    protected int				width;
    protected int				height;
    int state=2;
    boolean isAlive=true;
    boolean drop=true;
    GameCanvas gc;
   
	/** 构造函数 */
	myMan(GameCanvas gc) {
		this.gc=gc;
		// 取得图像
		try {
			meLeft = Image.createImage("/meLeft.png");
			meRight = Image.createImage("/meRight.png");
			jumpLeft = Image.createImage("/jumpLeft.png");//
			jumpRight = Image.createImage("/jumpRight.png");//
			img3  =Image.createImage("/img3.png");
			img4  =Image.createImage("/img4.png");
			handLeft = Image.createImage("/handLeft.png");//
			handRight = Image.createImage("/handRight.png");//
		 }catch(Exception e) {}
		//设定宽度与高度
		width = meLeft.getWidth();//图片的高宽都一致
		height = meLeft.getHeight();
		
		
   }
   
   
   
   	void setX(int x) {
		this.x = x;
	}

	int getX() {
		return x;
	}

	void setY(int y) {
		this.y = y;
	}

	
	int getY() {
		return y;
	}
	
	int getWidth() {
		return width;
	}

	
	int getHeight() {
		return height;
	}

	
	void setAlive(boolean isAlive) {
		this.isAlive = isAlive;
	}

	
	boolean isAlive() {
		return isAlive;
	}
   
   
    int getState(){
    	return state;
    }
    
    void setState(int state){
    	this.state=state;
    }

   void doMove()   { 
   
		
	  if(!isAlive){//如果撞到板子
	  
		 y=y+5;
	     if(y>128)
	     gc.GameOver=true;
      
		
      }
    }



 
	void doDraw(Graphics g) {
		 if(isAlive){	
		   if(state==1){
		   	  g.drawImage(meLeft,x,y,Graphics.TOP|Graphics.LEFT);
		   }else if(state==2){
		   	  g.drawImage(meRight,x,y,Graphics.TOP|Graphics.LEFT);
		   }else if(state==3){//向左跳向右跳,也是向上跳和向下跳
		   	  g.drawImage(jumpLeft,x,y,Graphics.TOP|Graphics.LEFT);
		   }else if(state==4){
		   	  g.drawImage(jumpRight,x,y,Graphics.TOP|Graphics.LEFT);
		   }else if(state==5){
		   	  g.drawImage(handLeft,x,y,Graphics.TOP|Graphics.LEFT);
		   }else if(state==6){
		   	  g.drawImage(handRight,x,y,Graphics.TOP|Graphics.LEFT);
		   }
		 }else{
		 	if(drop){
		 	  g.drawImage(img3,x,y,Graphics.TOP|Graphics.LEFT);
		 	  drop=!drop;
		 	}else{
		 	  g.drawImage(img4,x,y,Graphics.TOP|Graphics.LEFT);
		 	  drop=!drop;
		 	}

		 }
	
	}



	
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -