Java动画 重力弹球 如鹏游戏引擎 精灵 设计一个小球加速落地又减速弹起并反复直到停止的Java程序

package com.swift;

import com.rupeng.game.GameCore;

public class BouncingBall implements Runnable {

    public static void main(String[] args) {
        GameCore.start(new BouncingBall());
    }

    @Override
    public void run() {
        GameCore.setGameSize(1024, 500);
        GameCore.setGameTitle("重力弹球");
        GameCore.createSprite(0, "ball1");
        GameCore.playSpriteAnimate(0, "rotate", true);
        GameCore.setSpritePosition(0, 200, 1);
        double y = 0;
        double g = 9.8;
        int t = 1;
        double v = 0;
        int flag = 0;
        for (;;) {
            if (flag == 0) {
                v = v + g * t;
                y = y + v * t;
            }
            System.out.println(t + " " + v + " " + y);
            if (y >= 450) {
                flag = 1;
            }
            System.out.println(flag == 1);
            if (flag == 1) {
                v = v - g * t;
                System.out.println(v);
                y = y - v * t;
            }
            if (v < 0) {
                flag = 0;
            }
            if (v < 0 && y > 450) {
                break;
            }
            GameCore.setSpritePosition(0, 200, (int) y);
            GameCore.pause(200);
        }
        GameCore.setSpritePosition(0, 200, 450);

        GameCore.pause(5000);
    }

}

 

posted @ 2017-10-18 22:08  Advancing-Swift  阅读(1172)  评论(0编辑  收藏  举报