package Shoot; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.FileInputStream; import javax.imageio.ImageIO; public class BigPlane extends Enemy { private static BufferedImage[] images=new BufferedImage[5]; final private static int speed=1; private int image_index=0; static{ for(int i=0;i<images.length;i++){ try{ images[i]=ImageIO.read(new FileInputStream("image\\bigPlane"+i+".png")); }catch(Exception e){ e.printStackTrace(); } } } public BigPlane() { super((int)(Math.random()*(World.frameWidth-images[0].getWidth())), -images[0].getWidth(), images[0].getWidth(), images[0].getHeight()); } public int getAward() { return Award.twoScorePlus; } public void step(){ y+=speed; } public void paint(Graphics g){ if(lifeState==Enemy.alive){ g.drawImage(images[image_index], x, y, null); }else if(lifeState==Enemy.dying&&image_index<images.length-1){ image_index++; g.drawImage(images[image_index], x, y, null); }else{ lifeState=Enemy.dead; } } }
时间: 2024-03-14 13:49:28 浏览: 19
这段代码定义了一个名称为"BigPlane"的类,它继承了"Enemy"类,并实现了"Award"接口。这个类表示一个大型敌机,具有不同的奖励和图片。
该类有一个静态成员变量"images",表示大型敌机的不同状态对应的不同图片。它还有一个静态常量"speed",表示大型敌机的速度。
在静态代码块中,使用循环为"images"数组中的每个元素加载对应的图片。
在构造方法中,随机生成大型敌机的x坐标,并将y坐标设置为图片高度的相反数。
实现"Award"接口中的"getAward()"方法,返回加2分奖励的类型。
实现"step()"方法,表示大型敌机的移动,它的y坐标每次增加"speed"个像素点。
实现"paint()"方法,表示大型敌机的绘制。当大型敌机处于存活状态时,绘制当前状态对应的图片。当大型敌机处于死亡状态时,将生命状态设置为死亡状态。
相关问题
plt.plot添加colorbar
要在plt.plot中添加colorbar,需要使用plt.colorbar()函数。具体步骤如下:
1. 在plt.plot中设置c参数,该参数用于指定颜色映射的数据。
2. 在plt.plot后面添加plt.colorbar()函数,该函数会自动创建一个颜色条。
示例代码如下:
```
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
y = np.sin(x)
z = np.cos(x)
plt.plot(x, y, c=z)
plt.colorbar()
plt.show()
```
“Bullet(int, int)”在“com.scy.shoot.entity.Bullet”中具有私有访问权限
这个问题看起来是关于Java编程语言的错误提示信息。这个错误提示信息是说在Java程序的“com.scy.shoot.entity.Bullet”类中,有一个名为“Bullet”的构造方法,它带有两个整数类型的参数,但是这个构造方法的访问权限是私有的,不能从类的外部访问。因此,如果你想要在类的外部创建一个Bullet对象,你需要使用类中提供的公共构造方法或者工厂方法。如果你需要进一步了解如何访问私有构造方法,请参考Java编程语言的相关资料。