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); } }