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

📄 gamedisplay.java

📁 一款手机游戏
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            int x = bullet[i-1].getX();
            int y = bullet[i-1].getY();
            bullet[i].setPosition(x,y);
        }
    }
    private void kickbullet(int Bi){   	
    	bullet[Bi].setPosition(-10, -10);
    	for(int i=Bi; i<count; i++)
        {
    		int x = bullet[i+1].getX();
            int y = bullet[i+1].getY();
            bullet[i].setPosition(x,y);
        }
    	count--;
    }
     
     /* 子弹的移动 */
    private void moveBullet()
    { 
        for(int i=0; i<count; i++)
        {
            if(bullet[i].getY()>0)
                bullet[i].move(0,-10);
            else
            {
                bullet[i].setPosition(-10,-10);
                count --;
            }
        }
    }
    
    private synchronized void MovePina(int X,int Y){
    	pina.move(X,Y);
    }
    
    public void crashGround(){
    	crashGround.setVisible(true);
    	crashGround.setPosition(pina.getRefPixelX()+30, pina.getRefPixelY()+0);
    	if(crashGround.collidesWith(foreground, true)){
    		horre=0;
    		pina.move(0, 1);
    	}
    	crashGround.setPosition(pina.getRefPixelX()+42, pina.getRefPixelY()+2);
    	if(crashGround.collidesWith(foreground, true)){
    		horre=1;
    		horiz=-1;
    	}
    	crashGround.setPosition(pina.getRefPixelX()+48, pina.getRefPixelY()+5);
    	if(crashGround.collidesWith(foreground, true)){
    		horre=1;
    		horiz=-1;
    	}
    	crashGround.setPosition(pina.getRefPixelX()+50, pina.getRefPixelY()+14);
    	if(crashGround.collidesWith(foreground, true)){
    		horiz=-1;
    	}
    	crashGround.setPosition(pina.getRefPixelX()+48, pina.getRefPixelY()+22);
    	if(crashGround.collidesWith(foreground, true)){
    		horre=-Math.abs(horiz)+horre/2;
    		horiz=-1;
    	}
    	crashGround.setPosition(pina.getRefPixelX()+41, pina.getRefPixelY()+27);
    	if(crashGround.collidesWith(foreground, true)){
    		horre=-Math.abs(horiz)+horre/2;
    		horiz=-1;
    	}
    	crashGround.setPosition(pina.getRefPixelX()+28, pina.getRefPixelY()+30);
    	if(crashGround.collidesWith(foreground, true)){
    		horre=-horre*3/4;
            if(horiz>0) horiz-=1;
            else if(horiz<0) horiz+=1;
            if(horre==0) {
            	horre=-1;
            	note=12;
            	horre-=1;
            }
            if(142==pina.getY())
            {
            	horre+=1;
            }
            
            if(pina.getY()>144&&pina.getY()<146)
            {
            	//horre-=4;
            	pina.move(0, -4);
            	horre-=1;
            }
            if(pina.getY()>=146)
            {
            	//horre-=8;
            	pina.move(0, -6);
            	horre-=2;
            }
    	}
    	crashGround.setPosition(pina.getRefPixelX()+17, pina.getRefPixelY()+28);
    	if(crashGround.collidesWith(foreground, true)){
    		horre=-Math.abs(horiz)+horre/2;
    		horiz=1;
    	}
    	crashGround.setPosition(pina.getRefPixelX()+10, pina.getRefPixelY()+23);
    	if(crashGround.collidesWith(foreground, true)){
    		horre=-Math.abs(horiz)+horre/2;
    		horiz=1;
    	}
    	crashGround.setPosition(pina.getRefPixelX()+8, pina.getRefPixelY()+15);
    	if(crashGround.collidesWith(foreground, true)){
    		horiz=1;
    	}
    	crashGround.setPosition(pina.getRefPixelX()+9, pina.getRefPixelY()+8);
    	if(crashGround.collidesWith(foreground, true)){
    		horre=1;
    		horiz=1;
    	}
    	crashGround.setPosition(pina.getRefPixelX()+16, pina.getRefPixelY()+3);
    	if(crashGround.collidesWith(foreground, true)){
    		horre=1;
    		horiz=1;
    	}
    	crashGround.setVisible(false);
    }

    
    ////////////////////////////////////////////////////////////////////////////////////////气球的碰撞
    private synchronized void collides()
    {
    	/////////////////////////////和子弹的碰撞 
    	for(int i=0;i<count;i++)
    	{
    		if(pina.collidesWith(bullet[i],true))
    		{
    		PX=bullet[i].getX();
    		PY=bullet[i].getY();
    		int distance=bullet[i].getRefPixelX()-pina.getRefPixelX();
    		kickbullet(i);
    		if(distance>=0&&distance<=22){
    		   Rebound(PX,PY,1);//小球反弹
    		   if(horiz<2)
    		   horiz++;//水平速度
    		   if(horre>3) horre=0;
    		   horre-=1;//竖直速度
    	    }
    		else if(distance>=36&&distance<=56)
    		{
    			Rebound(PX,PY,2);
    			if(horiz>-2)
    				horiz--;
    			if(horre>3) horre=0;
    			horre-=1;
    		}
    		else if(distance>22&&distance<36)
    		{   

    	    	isdown=true;
    			Rebound(PX,PY,3);
    			if(horre>3) horre=0;
    			horre-=3;
    		}
    		}
    	}
    	
    	
    	
    	
    	/////////////////////////////////////////////////////和包子的碰撞
    	for(int i=0;i<Scene.nikumanNumber[Other.currentLevel-1];i++)
    	{
    		if(pina.collidesWith(nikuman[i],true))
    		{
    			nikuman[i].setVisible(false);
    			nikuNumber++;
    			getniku++;//吃3个包子增加一次生命
    			getlife+=getniku/3;
    			getniku%=3;
    			
    		}
    	}
    	if((nikuNumber==Scene.nikumanNumber[Other.currentLevel-1])&&(onlyone))//吃完包子后,进入下一关
    	{
    		//next.setVisible(true);
    		//next.setPosition(pina.getRefPixelX()+40,pina.getRefPixelY()+40);
    		onlyone=false;//保证此块只执行一次
    		mainMenu.isLevel = true;
            isStop=true;
         }
    	if(isStop==true){//循环3次后在结束此进程以便最后一个包子消失
    		if(continue3==3){
    			continue3=2;//使用户又能够选择下一关的机会
    			is=false;
    			if(mainMenu.issoundopen[1]==true)
    			try{
    				mainMenu.soundplayer[4].start();
    			}catch(Exception e){}
    			//menu.stop=true;
    			trans=false;
    			}
    		continue3++;	
    	}
    	//////////////////////////////////////////和sprite life 的碰撞
    	if(pina.collidesWith(life,true))
    	{
    		getlife++;
    		life.setVisible(false);
    		Other.pinaLife=Other.pinaLife+1;//吃生命宝物,生命值加一
    		get.setVisible(true);
    		get.setPosition(pina.getRefPixelX()+40,pina.getRefPixelY()+40);
    		try{
    				Thread.sleep(100);
    			}
    			catch(Exception e){
            		}
    	}
    	if(getlife!=0) getlife++;
    	if(getlife==4){
    		get.setVisible(false);
    	}
    	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    	//和障碍物的碰撞
    	for(int i=0;i<scene.togeNumber[Other.currentLevel-1];i++)
    	{
    	if(pina.collidesWith(toge[i],true))
    	{   
    		int dis=toge[i].getRefPixelX()-pina.getRefPixelX();
    		if(dis<=52&&dis>=-16){
    		if(mainMenu.issoundopen[1]==true)
    		try{
    		mainMenu.soundplayer[2].start();
    		}catch(Exception e){}
    		pina.setVisible(false);
    		PinaMiss.setVisible(true);
        	PinaMiss.setFrame(0);
    		misscount=10;
    		PinaMiss.setPosition(pina.getRefPixelX()-15,pina.getRefPixelY()-10);
    		miss.setVisible(true);
    		miss.setPosition(pina.getRefPixelX()+40,pina.getRefPixelY()+40);
    		if(gameover==false){
        		Other.pinaLife=Other.pinaLife-1;
        		miss.setVisible(false);
        		pina.setPosition(100,70);//碰撞后还有生命,则将气球放置初始位置
            	horiz=horre=0;
            	shooter.setPosition(pina.getRefPixelX(),shooter.getRefPixelY());
            	pina.setVisible(true);
            	}
    	}	
    	}
    	if(Other.pinaLife==0)//碰撞后没有生命,提示gameover,进入mainmenu
    		{
    			isgameover=true;
    			is=false;
    		}
        }
    }
        
    public void initialize(int lvl, int[][] nikumanPos, int[][] togePos,
            int[][] lifePos, int[] levelNumber)
    {
        Other.currentLevel = lvl;
        
        /* 加载对象 */
        nikuman = new Sprite[Scene.nikumanNumber[Other.currentLevel-1]];
        toge = new Sprite[scene.togeNumber[Other.currentLevel-1]];
        /* 创建背景 */
        background = scene.creatBackground(bgGround, 15, 7, 32, 32);
        backWall = scene.creatBackground(wall, 13, 1, 36, 10);
        foreground = scene.creatForeground(frGround, 20, 9, levelNumber, 20);
        /* 在层管理中插入各个图层 */
        for(int i=0; i<Scene.nikumanNumber[Other.currentLevel-1]; i++)
        { //包子
            nikuman[i] = new Sprite(niku,22,19);
            nikuman[i].setFrameSequence(scene.nikuSequence);
            gameManager.append(nikuman[i]);
            nikuman[i].setPosition(nikumanPos[0][i], nikumanPos[1][i]);
        }
        for(int i=0; i<scene.togeNumber[Other.currentLevel-1]; i++)
        { //障碍
            toge[i] = new Sprite(star,25,25);
            toge[i].setFrameSequence(scene.togeSequence);
            gameManager.append(toge[i]);
            toge[i].setPosition(togePos[0][i], togePos[1][i]);
        }
        for(int i=0; i<7; i++)
        { //子弹
            bullet[i] = new Sprite(ball);
            gameManager.append(bullet[i]);
            bullet[i].setPosition(-10,-10);
        }
        gameManager.append(pina);

        //子弹反弹精灵添加
        gameManager.append(BallRebound);
        BallRebound.setVisible(false);
        gameManager.append(BallDown);
        BallDown.setVisible(false);
        gameManager.append(PinaMiss);
        PinaMiss.setVisible(false);
        gameManager.append(crashGround);
        crashGround.setVisible(false);
        get=new Sprite(alert2);
    	gameManager.append(get);
        get.setVisible(false);
        miss =new Sprite(alert3);
        gameManager.append(miss);
        miss.setVisible(false);
        next =new Sprite(alert1);
        gameManager.append(next);
        next.setVisible(false);
        
        gameManager.append(shooter);
        gameManager.append(life);
        gameManager.append(backWall);
        gameManager.append(foreground);
        gameManager.append(background);
        
        
        /* 设置每个层的参数 */
        life.setFrameSequence(scene.lifeSequence);
        pina.setFrameSequence(scene.pinaSequence);
        pina.setPosition(100,70);
        BallRebound.setFrameSequence(scene.ballrebounds);
        BallDown.setFrameSequence(scene.ballrebounds);
        PinaMiss.setFrameSequence(scene.togeSequence);
        backWall.setPosition(0, 198);
        shooter.setPosition(10,176);
        life.setPosition(lifePos[0][Other.currentLevel-1],
                lifePos[1][Other.currentLevel-1]);
        gameManager.setViewWindow(0,0,176,220);
    }
}

⌨️ 快捷键说明

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