Java動畫 重力彈球 如鵬遊戲引擎 精靈 設計一個小球加速落地又減速彈起並反復直到停止的Java程序
阿新 • • 發佈:2017-10-19
ble ack pause ani ring pen nts game 遊戲
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); } }
Java動畫 重力彈球 如鵬遊戲引擎 精靈 設計一個小球加速落地又減速彈起並反復直到停止的Java程序