java手机游戏设计源代码 第11页


java手机游戏设计源代码 第11页
if(i==menuIndex)
   { 
    g.setColor(highBGColor);
    g.fillRect(0,startHeight+(i*highfont.getHeight())+spacing,width,highfont.getHeight());
    g.setFont(highfont);
    g.setColor(highColor); g.drawString(mainmenu[i],(width-highfont.stringWidth(mainmenu[i]))/2,startHeight+(i*highfont.getHeight())+spacing,20);
   }else
   {
    g.setFont(lowfont);
    g.setColor(lowColor);
    g.drawString(mainmenu[i],(width-lowfont.stringWidth(mainmenu[i]))/2,startHeight+(i*highfont.getHeight())+spacing,20);
   }
  }
 }
 public void keyPressed(int code)
 {
  if(getGameAction(code)==Canvas.UP&&menuIndex-1>=0)
  {
   menuIndex--;
  }
  else if(getGameAction(code)==Canvas.DOWN&&menuIndex+1<mainmenu.length)
  {
   menuIndex++;
  }
 }
 public void commandAction(Command c,Displayable d)
 {
  if (c==ok)
  {
   switch(menuIndex)
   {
     case 0:
       co=false;
      midlet.gameShow();
      break;
     case 1:
      midlet.helShow();
      break;
     case 2:
      midlet.renwuShow();
      break;
   } 
  }
 }
}
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
public class mybullets extends Sprite
{   public  int score=0;
 private int[][] bullets;
 private int bulletstotal;
    public int width,bulletheight;
   public int no=0;
 public mybullets(Image img,int picwidth,int picheight,int bulletstotal,int width,int height)
 {      
   super(img,picwidth,picheight);
   this.bulletstotal=bulletstotal;
   bullets=new int[bulletstotal][4];
   this.width=width;
   this.bulletheight=height/7; 
 }
    public void initBullets(int i)
    {
      bullets[i][3]=1;
      bullets[i][2]=0;
    }
    public void updata(int i)
    {
     bullets[i][1]+=bullets[i][2];
    }
    public void setfirstposition(int x,int y,int nof,Sprite sprite[],Image img)
    {     
     sprite[nof].setVisible(true);
        sprite[nof+1].setVisible(true);
        sprite[nof+2].setVisible(true);
     bullets[nof][0]=x+10;
        bullets[nof][1]=y-24;
        sprite[nof].setImage(img,6,6);
        bullets[nof+1][1]=bullets[nof][1]+10;
        bullets[nof+1 ][0]=x+10;
        sprite[nof+1].setImage(img,6,6);
        bullets[nof+2][1]=bullets[nof+1][1]+10;
        bullets[nof+2 ][0]=x+10;
        sprite[nof+2].setImage(img,6,6);
    }
    public void newposition(Sprite sprite[],int i,int v,Sprite jp0,Sprite jp1,Sprite jp2,Sprite boss,Image img)
    {   
     bullets[i][2]-=5;
     sprite[i].setPosition(bullets[i][0],bullets[i][1]+bullets[i][2]);
     sprite[i+1].setPosition(bullets[i][0],bullets[i+1][1]+bullets[i][2]);
     sprite[i+2].setPosition(bullets[i][0],bullets[i+2][1]+bullets[i][2]);
        if (sprite[i].collidesWith(jp0,true))
        {
         sprite[i].setImage(img,32,32);
         sprite[i+1].setImage(img,32,32);
         sprite[i+2].setImage(img,32,32);
         sprite[i].setFrame(1);
         sprite[i+1].setFrame(1);
         sprite[i+2].setFrame(2);
         bullets[i][3]=0;
         bullets[i+1][3]=0;
         bullets[i+2][3]=0;
         jp0.setVisible(false);
         no=1; 
           score=score+1;
        }
        if (sprite[i].collidesWith(jp1,true))
        {
         sprite[i].setImage(img,32,32);
         sprite[i+1].setImage(img,32,32);
         sprite[i+2].setImage(img,32,32);
         sprite[i].setFrame(1);
         sprite[i+1].setFrame(1);
         sprite[i+2].setFrame(2);
         bullets[i][3]=0;
         bullets[i+1][3]=0;
         bullets[i+2][3]=0;
     751com.cn collidesWith(jp2,true))
        {
         sprite[i].setImage(img,32,32);
         sprite[i+1].setImage(img,32,32);
         sprite[i+2].setImage(img,32,32);
         sprite[i].setFrame(1);
         sprite[i+1].setFrame(1);
         sprite[i+2].setFrame(2);
         bullets[i][3]=0;
         bullets[i+1][3]=0;
         bullets[i+2][3]=0;
         jp2.setVisible(false);
         no=1;
        score=score+1;
        }
    }
    public boolean isAlive(int i)
    {
     if (bullets[i][3]==1) return true;
            else return false;

 << 上一页  [11] [12] [13] [14] [15] [16] [17] 下一页

Copyright © 2007-2012 www.chuibin.com 六维论文网 版权所有