Java製作案頭彈球下載版 使用如鵬遊戲引擎製作 包含2個精靈球同時彈動,彈球
package com.swift;import com.rupeng.game.GameCore;public class DesktopBouncingBall implements Runnable { public static void main(String[] args) { GameCore.start(new DesktopBouncingBall()); } @Override public void run() { GameCore.setGameSize(800, 450); GameCore.setGameTitle("案頭彈球"); GameCore.loadBgView("little.jpg"); GameCore.createSprite(0, "ball1"); GameCore.createSprite(1, "ball2"); GameCore.playSpriteAnimate(0, "rotate", true); GameCore.playSpriteAnimate(1, "rotate", true); int vx=2; int vy=5; int x=0; int y=200; int vx2=2; int vy2=1; int x2=300; int y2=0; for (;;) { x=x+vx; y=y+vy; x2=x2+vx2; y2=y2+vy2; GameCore.setSpritePosition(0, x, y); GameCore.setSpritePosition(1, x2, y2); GameCore.pause(10); if(x<=0||x>=780) { vx=-vx; } if(x2<=0||x2>=780) { vx2=-vx2; } if(y<=0||y>=400) { vy=-vy; } if(y2<=0||y2>=400) { vy2=-vy2; } System.out.println(vx+" "+vy+" "+x+" "+y); } }}
上邊是源碼,下邊是打包好的程式,下載解壓後雙擊start檔案可以運行(不需安裝jre)
連結: https://pan.baidu.com/s/1eSyArOe 密碼: nb28
效果如: