网站页面一般做多大,做属于公司的网站有什么好处,wordpress出错,建立网站怎么搞游戏玩法#xff1a;通过鼠标点击使小鸟上下移动穿过柱子并完成得分#xff0c;小鸟碰到柱子或掉落到地面上都会结束游戏。
游戏内图片 Brid类#xff1a;
package bird;import org.omg.CORBA.IMP_LIMIT;import javax.imageio.ImageIO;
import java.awt.image.BufferedIma…游戏玩法通过鼠标点击使小鸟上下移动穿过柱子并完成得分小鸟碰到柱子或掉落到地面上都会结束游戏。
游戏内图片 Brid类
package bird;import org.omg.CORBA.IMP_LIMIT;import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;public class Brid {int x,y;int width,height;int size;//鸟的大小用于检测碰撞BufferedImage image;
BufferedImage[] images;
int index;double g; //重力加速度double t; //两次位置的时间间隔double v0; //初始上抛的速度double speed; //当前上抛的速度double s; //经过时间t以后的位移double alpha; //鸟的倾角单位是弧度public Brid() throws Exception {image ImageIO.read(getClass().getResource(0.png));width image.getWidth();height image.getHeight();x 132;y 280;size 40;g 4;v0 20;t 0.25;speed v0;s 0;alpha 0;images new BufferedImage[8];for (int i 0; i 8; i) {images[i] ImageIO.read(getClass().getResource(i .png));}
index0;}
public void fly(){index;imageimages[(index/12)%8];
}public void step(){
double v0speed;
sv0*tg*t*t/2; //计算上抛运动的位移;
yy-(int)s;//计算鸟的位置坐标
double v v0-g*t;//计算下次的速度
speedv;
alphaMath.atan(s/8);}
public void flappy(){speedv0; //重新设置初始速度重新向上飞
}public boolean hit( Ground ground){boolean hitysize/2ground.y;if(hit){y ground.y-size/2;alpha-3.1415926/2;}return hit;}public boolean hit(Column column) {if (x column.x - column.width / 2 - size / 2 x column.x column.width / 2 size / 2) {if (y column.y - column.gap / 2 size / 2 y column.y column.gap / 2 - size / 2) {return false;}return true;}return false;}
} BridGame类
package bird;import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;public class BridGame extends JPanel {Brid brid;Column column1,column2;Ground ground;BufferedImage background;int score;// boolean gameOver;//游戏状态int state;public static final int START0;public static final int RUNNING1;public static final int GAME_OVER2;BufferedImage gameOverImage;
BufferedImage startImage;public BridGame() throws Exception{//gameOverfalse;stateSTART;gameOverImage ImageIO.read(getClass().getResource(gameover.png));startImageImageIO.read(getClass().getResource(start.png));bridnew Brid();column1new Column(1);column2new Column(2);groundnew Ground();background ImageIO.read(getClass().getResource(bg.png));score0;
}Overridepublic void paint(Graphics g) {super.paint(g);g.drawImage(background,0,0,null);g.drawImage(column1.image,column1.x-column1.width/2,column1.y-column1.height/2,null);g.drawImage(column2.image,column2.x-column2.width/2,column2.y-column2.height/2,null);g.drawImage(ground.image,ground.x,ground.y,null);Graphics2D g2(Graphics2D) g;g2.rotate(-brid.alpha,brid.x,brid.y);g.drawImage(brid.image,brid.x-brid.width/2,brid.y-brid.width/2,null);g2.rotate(brid.alpha,brid.x,brid.y);Font fnew Font(Font.SANS_SERIF,Font.BOLD,40);g.setFont(f);g.drawString(score,40,60);g.setColor(Color.white);g.drawString(score,40-3,60-3);switch (state){case GAME_OVER:g.drawImage(gameOverImage,0,0,null);break;case START:g.drawImage(startImage,0,0,null);break;}}public void action() throws Exception{ //让地面动起来MouseListener lnew MouseAdapter(){Overridepublic void mousePressed(MouseEvent e) { //鼠标按下// brid.flappy(); //鸟向上飞try {switch (state) {case GAME_OVER:column1 new Column(1);column2 new Column(2);brid new Brid();score 0;state START;break;case START:state RUNNING;case RUNNING:brid.flappy();}}catch (Exception e2){}}};addMouseListener(l);while(true){switch (state){case START:brid.fly();ground.step();break;case RUNNING:ground.step();column1.step();column2.step();brid.step();brid.fly();if(brid.xcolumn1.x||brid.xcolumn2.x){score;}if(brid.hit(ground)||brid.hit(column1)||brid.hit(column2)){stateGAME_OVER;}break;}repaint();Thread.sleep(1000/30);}
}public static void main(String[] args) throws Exception {JFrame framenew JFrame();BridGame gamenew BridGame();frame.add(game);frame.setSize(440,670);frame.setLocationRelativeTo(null);frame.setVisible(true);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);game.action();}
}
Column类
package bird;import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.font.LineMetrics;
import java.awt.image.BufferedImage;
import java.util.Random;//柱子
public class Column {int x,y;int width,height;int gap;int distance;BufferedImage image;Random randomnew Random();public Column(int n) throws Exception{image ImageIO.read(getClass().getResource(column.png));widthimage.getWidth();height image.getHeight();gap144;distance245;x550(n-1)*distance;yrandom.nextInt(218)132;}
public void step(){x--;if(x-width/2){xdistance*2-width/2;yrandom.nextInt(218)132;}
}
}
Ground类
package bird;import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;public class Ground {int x,y;int width,height;BufferedImage image;public Ground() throws Exception{image ImageIO.read(getClass().getResource(ground.png));widthimage.getWidth();height image.getHeight();x0;y500;}//添加方法让地面移动public void step(){x--;if(x-109){x0;}}}