Java制作桌面弹球下载版 使用如鹏游戏引擎制作 包含2个精灵球同时弹动

时间:2021-12-29 11:57:40
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

效果如下图:

Java制作桌面弹球下载版 使用如鹏游戏引擎制作 包含2个精灵球同时弹动