读书人

IGFrame Ball Test 示范

发布时间: 2013-02-24 17:58:56 作者: rapoo

IGFrame Ball Test 示例

package org.ioo.igframe.test;import java.awt.Color;import java.awt.Graphics2D;import java.util.Random;import org.ioo.igframe.core.GFrame;import org.ioo.igframe.core.GModel;/** * @(#):BallTest.java  * @author: ioozhuangzi  2013-2-20  * @Copyright: */public class BallTest extends GModel {//窗口宽高public static final int WIDTH = 480;public static final int HEIGHT = 320;//小球数量private static final int NUM_BALLS = 50;//0实心或1空心球private int ballType = 0;//0无  1连线 2连线并填充private int lineFillType = 1;//小球大小private int size = 5;//随机数生成器private Random rand;//小球数组private Ball[] ball;//当前小球坐标集合int[] x = null;int[] y = null;public void onLoad() {rand = new Random(System.currentTimeMillis());//以当前时间(毫秒)作为随机数种子ball = new Ball[NUM_BALLS];// 初始化小球for (int i = 0; i < NUM_BALLS; i++) {int x = rand.nextInt(WIDTH);int y = rand.nextInt(HEIGHT);int vx = rand.nextInt(3)+1;int vy = rand.nextInt(3)+1;ball[i] = new Ball(x, y, vx, vy, ballType, size);}x = new int[NUM_BALLS];y = new int[NUM_BALLS];}public void onExit() {}public void onUpdate() {//更新小球位置for (int i = 0; i < NUM_BALLS; i++) {ball[i].move();}}public void onRender(Graphics2D g) {if(lineFillType == 1 || lineFillType == 2) {g.setColor(Color.GREEN);//连线for (int i = 0; i < NUM_BALLS; i++) {if(i == 0) {g.drawLine(ball[NUM_BALLS - 1].getCx(), ball[NUM_BALLS - 1].getCy(), ball[i].getCx(), ball[i].getCy());}else {g.drawLine(ball[i - 1].getCx(), ball[i - 1].getCy(), ball[i].getCx(), ball[i].getCy());}//获取每个小球的中心点坐标x[i] = ball[i].getCx();y[i] = ball[i].getCy();}}if(lineFillType == 2) {//根据小球坐标集合填充多边形g.setColor(Color.GRAY);g.fillPolygon(x, y, NUM_BALLS);}// 分别绘制相应球体for (int i = 0; i < NUM_BALLS; i++) {ball[i].draw(g);}}public static void main(String[] args) {GFrame gFrame = new GFrame("IGFrame Ball Test",new BallTest(),50, WIDTH, HEIGHT);gFrame.setShowFPS(true);gFrame.setAlias(true);gFrame.setRenderQuality(true);gFrame.showFrame();}}

IGFrame的代码还在编写和整理当中,暂不发布~~有兴趣的可加Q群交流~

?

对Java Sound,Java Video,Java游戏开发等有兴趣的各位可以进来交流一下~

想要研究Java(包括Android)文字冒险游戏(AVG/ADV)的人有木有?欢迎交流~

Q群:210816248

验证:IGFrame
?

读书人网 >开源软件

热点推荐