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

📄 gamespringe.java

📁 Java游戏沙丘城堡源代码/Java游戏沙丘城堡源代码
💻 JAVA
字号:
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;
///////////////////////
//游戏元素类
//  封装游戏过程中所有的元素,陷阱效果
///////////////////////

public class GameSpringe extends Sprite
{
	//控制线程次数;
	public int num=0;
	public static int num2=0;
	public boolean isOK;
	public static boolean isNoDown;
	private boolean isL;
	static boolean collides=false;
	private static final int ThreadNum = 30; 
	
	//构造方法;
	public GameSpringe(Image img,int w ,int h) 
	{
		super(img,w,h);
		isOK   = false;
		isL    = true;
		isNoDown = false;
	}
	//推石头
	public void moveRock()
	{
		if (this.collidesWith(MyGame.player,false)
		 && MyGame.player.getY() - this.getY() <= 5 && !GamePlayer.isDie)
		{
			MyGame.player.setPosition(MyGame.player.getX(),this.getY() - MyGame.player.getHeight());
		}
	}
	
	public void moveLouti()
	{
		if (isOK && !GamePlayer.isDie)
		{
			MyGame.player.setPosition(this.getX() - MyGame.player.getWidth()/2,MyGame.player.getY());	
		}
	}
	
	public void moveJiGuan()
	{
		this.nextFrame();
	}
	
	//移动踏板
	

	public void moveGun(int statr,int end,int speed,boolean isL2R)
	{
		if (isL2R)
		{
			if (!isL)
			{
				if (this.getX() <= end)
				{
					if (this.collidesWith(MyGame.player,false)
					&& MyGame.player.getY() - this.getY() <= 5&& !GamePlayer.isDie)
					{
						isNoDown = true;
						MyGame.player.setPosition(MyGame.player.getX() + speed,this.getY() - MyGame.player.getHeight()+ 1);
					}
					else
					{
						isNoDown = false;
					}
					this.move(speed,0);
				}
				else
				{
					isL = true;
				}
			}
			else
			{
				if (this.getX() >= statr)
				{
					if (this.collidesWith(MyGame.player,false)
							&& MyGame.player.getY() - this.getY() <= 5&& !GamePlayer.isDie)
					{
						MyGame.player.setPosition(MyGame.player.getX() - speed,this.getY() - MyGame.player.getHeight()+ 1);
						isNoDown = true;
					}
					else
					{
						isNoDown = false;
					}
					this.move(-speed,0);
				}
				else
				{
					isL = false;
				}
			}
		}
		else
		{
			if (!isL)
			{
				if (this.getY() <= end)
				{
					if (this.collidesWith(MyGame.player,false)
							&& MyGame.player.getY() - this.getY() <= 5&& !GamePlayer.isDie)
					{
						MyGame.player.setPosition(MyGame.player.getX(),this.getY() - MyGame.player.getHeight()+ 1);
						isNoDown = true;
					}
					else
					{
						isNoDown = false;
					}
					this.move(0,speed);
				}
				else
				{
					isL = true;
				}
			}
			else
			{
				if (this.getY() >= statr)
				{
					if (this.collidesWith(MyGame.player,false)
							&& MyGame.player.getY() - this.getY() <= 5&& !GamePlayer.isDie)
					{
						MyGame.player.setPosition(MyGame.player.getX(),this.getY() - MyGame.player.getHeight() + 1);
						isNoDown = true;
					}
					else
					{
						isNoDown = false;
					}
					this.move(0,-speed);
				}
				else
				{
					isL = false;
				}
			}
		}
	}
	
	//门
	public void moveMen()
	{
		if (isOK)
		{
			if (num++ <= 18)
			{
				this.move(0,-1);
			}
		}
	}
	
	
	//移动箭 4个方向 2种类型的箭
	public void moveJian(int statr,int end,int GoTo,int speed,boolean isRepeat)
	{
		if (isOK)
		{
			switch(GoTo)
			{
			case 1:
				if (isRepeat)
				{
					this.setVisible(true);
					if  (this.getX() <= end)
					{
						this.move(speed,0);
					}
					else
					{
						this.setVisible(false);
						this.num++;
						if (num >= ThreadNum)
						{
							this.setPosition(statr,this.getY());
							num = 0;
						}
					}
				}
				else
				{
					if (this.getX() <= end)
					{
						this.move(speed,0);
					}
					else
					{
						this.num++;
						if (num >= ThreadNum -10 )
						{
							MyGame.lm.remove(this);
							num = 0;
						}
					}
				}
				break;
			case 2:
				if (isRepeat)
				{
					this.setVisible(true);
					this.setTransform(Sprite.TRANS_NONE);
					this.setTransform(Sprite.TRANS_ROT90);
					if  (this.getY() <= end)
					{
						this.move(0,speed);
					}
					else
					{
						this.setVisible(false);
						this.num++;
						if (num >= ThreadNum)
						{
							this.setPosition(this.getX(),statr);
							num = 0;
						}
					}
				}
				else
				{
					this.setTransform(Sprite.TRANS_NONE);
					this.setTransform(Sprite.TRANS_ROT90);
					if (this.getY() <= end)
					{
						this.move(0,speed);
					}
					else
					{
						this.num++;
						if (num >= ThreadNum -10  )
						{
							MyGame.lm.remove(this);
							num = 0;
						}
					}
				}
				break;
			case 3:
				if (isRepeat)
				{
					this.setVisible(true);
					this.setTransform(Sprite.TRANS_NONE);
					this.setTransform(Sprite.TRANS_ROT180);
					if  (this.getX() >= statr)
					{
						this.move(-speed,0);
					}
					else
					{
						this.setVisible(false);
						this.num++;
						if (num >= ThreadNum)
						{
							this.setPosition(end,this.getY());
							num = 0;
						}
					}
				}
				else
				{
					this.setTransform(Sprite.TRANS_NONE);
					this.setTransform(Sprite.TRANS_ROT180);
					if (this.getX() >= statr)
					{
						this.move(-speed,0);
					}
					else
					{
						this.num++;
						if (num >= ThreadNum -10 )
						{
							MyGame.lm.remove(this);
							num = 0;
						}
					}
				}
				break;
			case 4:
				if (isRepeat)
				{
					this.setVisible(true);
					this.setTransform(Sprite.TRANS_NONE);
					this.setTransform(Sprite.TRANS_ROT270);
					if  (this.getY() >= end)
					{
						this.move(0,-speed);
					}
					else
					{
						this.setVisible(false);
						this.num++;
						if (num >= ThreadNum)
						{
							this.setPosition(this.getX(),statr);
							num = 0;
						}
					}
				}
				else
				{
					this.setTransform(Sprite.TRANS_NONE);
					this.setTransform(Sprite.TRANS_ROT270);
					if (this.getY() >= end)
					{
						this.move(0,-speed);
					}
					else
					{
						this.num++;
						if (num >= ThreadNum -10 )
						{
							MyGame.lm.remove(this);
							num = 0;
						}
					}
				}
				break;
			}
		}
	}

	//陷阱落石
	public void moveDownRock(int x,int y)
	{
	    if (isOK)
	    {
	    	num2++;
			if (num2 <=ThreadNum)
			{
				if (num2%4==1)
				{
					move(1,0);							
				}
				
				else if(num2%4==3)
				{
					move(-1,0);
				}
				else
				{
					setPosition(x,y);				
				}
			}		
			else
			{
				if(!collides)
				{
					this.move(0,2);							
				}
				if (collidesWith(MyGame.tlqiang,false))			
				{
					setVisible(false);					
					collides=true;
				}
				if (num2 >= ThreadNum*3)
				{
						setVisible(true);
						setPosition(x,y);
						num2 = 0;
						collides=false;
				}
			}
	    }
	}
	
	//宝藏效果
	public void moveMoney()
	{
		this.setPosition(-50,-50);
		MyGame.lm.remove(this);
		MyGame.score += 1000;
	}
	
}


⌨️ 快捷键说明

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