首页>代码>java swing开发FlappyBird游戏—仅供娱乐>/FlappyBird/src/com/tarena/bird/Column.java
package com.tarena.bird;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Random;

import javax.imageio.ImageIO;
/**
 * x, y 是空隙中间位置. 
 */
public class Column {
	BufferedImage image;
	//以柱子的中间作为柱子的位置
	int x;
	int y; // 140 ~ 280
	int width;
	int height;
	int gap = 109;
	Random r = new Random();
	
	public Column(int x) throws IOException { 
		image = ImageIO.read(getClass().getResource("column.png"));
		width = image.getWidth();
		height = image.getHeight();
		this.x = x;
		this.y = r.nextInt(140) + 140;
	}
	
	public void step(){
		x--;
		if(x<-width){
			x = 320;
			this.y = r.nextInt(140) + 140;
		}
	}
	public void paint(Graphics g){
		//g.drawRect(x-width/2, y-height/2, width, height/2-gap/2);
		//g.drawRect(x-width/2, y+gap/2, width, height/2-gap/2);
		g.drawImage(image, x-width/2, y-height/2, null);
	}
}
最近下载更多
alexcheung  LV3 2022年12月17日
杨少聪  LV5 2021年6月10日
一两天_  LV1 2021年5月27日
675104182  LV14 2020年9月22日
荒唐的羊  LV27 2020年7月1日
java小书童  LV18 2020年6月9日
15966848095  LV22 2020年2月8日
635969151  LV12 2019年12月18日
candice123  LV7 2019年12月11日
qweqweqwe321321233  LV10 2019年11月5日
最近浏览更多
随便取个名字_哈哈  LV27 6月23日
1661950467  LV2 2024年10月12日
ggflqq  LV1 2024年6月25日
鬼屋报道  LV3 2024年6月1日
long123_356  LV8 2024年5月18日
陈小灏  LV18 2023年12月15日
微信网友_6699076084797440  LV7 2023年10月30日
jiemomo  LV12 2023年10月19日
yangxb2  LV10 2023年7月11日
hougui  LV1 2023年6月20日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友