java Enemy.java

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java Enemy.java相关的知识,希望对你有一定的参考价值。


import java.awt.*;

import javax.swing.ImageIcon;

public class Enemy {

	Image img;
	int x, y;
	boolean isAlive = true;
	
	public Enemy(int startX, int startY, String location)
	{
		x = startX;
		y = startY;
		ImageIcon l = new ImageIcon(location);
		img = l.getImage();
	}
	
	public int getX()
	{
		return x;
	}
	public int getY()
	{
		return y;
	}
	public boolean Alive()
	{
		return isAlive;
	}
	public Image getImage()
	{
		return img;
	}
	
	public void move(int dx, int left)
	{
		if (dx == 1 && !((left + dx )< 150))//Added this to only move enemy when character moves forward (not back)
		x = x - dx;
	}

	public Rectangle getBounds()
	{
		return new Rectangle(x,y, 19, 23);
	}
	
}

以上是关于java Enemy.java的主要内容,如果未能解决你的问题,请参考以下文章

Java Math

Java 布尔运算

java [Java] Java常用代码#java

Java - 35 Java 实例

Java While 循环

Java 字符串