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

📄 .#bird.java.1.11

📁 java编写的打鸟游戏
💻 11
字号:
/* * Bird.java * * Created on 2007年12月19日, 上午11:41 * * To change this template, choose Tools | Template Manager * and open the template in the editor. */package graphics;import SBGameCore.*;import java.awt.Point;import java.util.Random;import java.awt.Graphics;/** * * @author wusir */public class Bird extends Comp{    int[] randomYSpeed = new int[]{-2,0,2,0,0};    int[] randomXSpeed = new int[]{20,50,39};    public static boolean[] birdAlive = new boolean[]{false,false,false,false,false,false,false};    public static boolean[] pathUsed = new boolean[]{false,false,false,false,false,false,false};    int[] randomPosition = new int[]{60,160,260,360,460,560,660};    int num;    /**     * Creates a new instance of Bird     */    public Bird(GraphicsPanel a) {        this.a = a;        w = 100;        h = 100;                Random rbird = new Random();        int b = 0;        do{            b = rbird.nextInt(7);        }while(birdAlive[b]);        birdAlive[b] = true;        img = a.birds[b];        num = b;                if(b == 1 || b == 3){            do{                b = rbird.nextInt(7);            }while(pathUsed[b]);            px = opx =  0;            py = opy =  randomPosition[b];            pathUsed[b] = true;            face = 1;                    }else{            do{                b = rbird.nextInt(7);            }while(pathUsed[b]);            px = opx =  1000;            py = opy =  randomPosition[b];            pathUsed[b] = true;            face = -1;                    }                Random rndv = new Random();        int x = 0;        x = rndv.nextInt(3);        vx = randomXSpeed[x];                active = true;                //k = (k+1)%7;     /*   Random rndv = new Random();          int x = 0;        x = rndv.nextInt(3);         vx = randomv[x];        try {Thread.sleep(100);} catch(Exception e) {};         int y = rndv.nextInt(3);         vy = randomv[y];*/    }        public void move() {        opx = px;        opy = py;        px = px + vx * face;                Random rnd = new Random();        int x = 0;        x = rnd.nextInt(5);        py = randomYSpeed[x] + py;        if(face == 1&&px == 1000)            px=0;        else if(face == -1 && px == 0)            px = 1000;      /*  try {Thread.sleep(100);} catch(Exception e) {};        int y = rnd.nextInt(3);         py = randoms[y] + py;*/            }       /* public boolean has_moved(){        if((px - opx) != 0)return true;        return false;    }*/        public void draw(){        set_draw_rectangles(a.paint_area,a.new_area);        Graphics bg = a.buffer.getGraphics();        bg.clipRect(a.paint_area.x,a.paint_area.y,w,h);        bg.drawImage(a.backdrop,0,0,a);        bg.dispose();                bg = a.buffer.getGraphics();        bg.clipRect(a.new_area.x,a.new_area.y,w,h);        bg.drawImage(img,a.new_area.x,a.new_area.y,a);        bg.dispose();                a.paint_area.add(a.new_area);                Graphics g = a.getGraphics();        g.clipRect(a.paint_area.x,a.paint_area.y,a.paint_area.width,a.paint_area.height);        g.drawImage(a.buffer,0,0,a);        g.dispose();    }    public Point getPoint(){        return new Point(px,py);    }        public void reset(){        if(birdAlive[num] == false){     /*    Random rbird = new Random();        int b = 0;        do{            b = rbird.nextInt(7);        }while(birdAlive[b]);        birdAlive[b] = true;        img = a.birds[b];*/            birdAlive[num] = true;            Random rbird = new Random();            int b;            if(num == 1 || num == 3){              /*  do{                    b = rbird.nextInt(7);                }while(pathUsed[b]);*/                px = opx =  0;                py = opy =  randomPosition[num];                pathUsed[num] = true;                face = 1;                            }else{             /*   do{                    b = rbird.nextInt(7);                }while(pathUsed[num]);*/                px = opx =  1000;                py = opy =  randomPosition[num];                pathUsed[num] = true;                face = -1;                            }                        Random rndv = new Random();            int x = 0;            x = rndv.nextInt(3);            vx = randomXSpeed[x];        }            }    }

⌨️ 快捷键说明

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