📄 startscreen.java
字号:
import java.applet.Applet;
import java.awt.*;
class StartScreen
{
int width,height;
int ImageLeftBound,ImageRightBound,ImageX,ImageY,ImageWidth,
ImageHeight,VX;
Font F1,F2;
Image Image1,Image2,currentImage;
String ChineseTitle,tsTitle;
Applet Game;
boolean showPressEnter;
int js;
public StartScreen(int AppletWidth,int AppletHeight,Applet Game,
Image Image1,Image Image2)
{//开始界面
F1 = new Font("TimesRoman",Font.BOLD + Font.ITALIC,50);
F2 = new Font("TimesRoman",Font.BOLD,20);
ChineseTitle = "飞机大战";
tsTitle = "按回车开始,按ESC退出";
width = AppletWidth;
height = AppletHeight;
this.Image1 = Image1;
this.Image2 = Image2;
ImageWidth = Image1.getWidth(Game);
ImageHeight = Image1.getHeight(Game);
ImageLeftBound = 2;
ImageRightBound = AppletWidth - (2 + ImageWidth);
ImageX = ImageRightBound;
VX = -1;
this.Game = Game;
currentImage = Image2;
showPressEnter = true;
js=0;
}
public void UpdateStatus()
{
ImageX = ImageX + VX;
if(ImageX <= ImageLeftBound)
{
currentImage = Image1;
ImageX = ImageLeftBound;
VX = -VX;
}
if(ImageX >= ImageRightBound)
{
currentImage = Image2;
ImageX = ImageRightBound;
VX = -VX;
js++;
if(js==2){
js=0;}
}
}
public void paintScreen(Graphics g)
{
int bj,yd;
g.setFont(F1);
g.setColor(Color.blue); //字体颜色
g.drawString(ChineseTitle,90,40); //中英文标题
g.setColor(Color.red); //字体颜色
g.setFont(F2);
g.drawString(tsTitle,92,280);
//ImageY = Y + Descent + 30;
//直线
// ImageY = Y +10+ImageX/2;
if (js==0){
if (VX>0)
{
ImageY=100-(int)(Math.sin((ImageX-ImageLeftBound)*6.28/(ImageRightBound-ImageLeftBound))*100);
}
else
{
ImageY= 100-(int)(Math.cos((ImageX-ImageLeftBound)*6.28/(ImageRightBound-ImageLeftBound)+1.57)*100);
}
}else if (js==1){
bj=(ImageRightBound-ImageLeftBound)/2;
yd=(ImageRightBound+ImageLeftBound)/2;
if (VX>0)
{
ImageY= 100-(int)(Math.sqrt(bj*bj-(yd-ImageX)*(yd-ImageX))*0.6);
}
else
{
ImageY= 100+(int)Math.sqrt(bj*bj-(yd-ImageX)*(yd-ImageX));
}
}
g.drawImage(currentImage,ImageX,ImageY,Game);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -