summaryrefslogtreecommitdiff
path: root/java/org/neocities/autoart/ballbounce/MoveBall.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/org/neocities/autoart/ballbounce/MoveBall.java')
-rw-r--r--java/org/neocities/autoart/ballbounce/MoveBall.java100
1 files changed, 100 insertions, 0 deletions
diff --git a/java/org/neocities/autoart/ballbounce/MoveBall.java b/java/org/neocities/autoart/ballbounce/MoveBall.java
new file mode 100644
index 0000000..cc44fc4
--- /dev/null
+++ b/java/org/neocities/autoart/ballbounce/MoveBall.java
@@ -0,0 +1,100 @@
+package org.neocities.autoart.ballbounce;
+
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.graphics.Canvas;
+
+import java.util.Date;
+
+public class MoveBall implements Runnable
+{
+ public CanvasView cv;
+ public double[] ballVel;
+ public double gravity = 1;
+ public boolean running = true;
+ public long lastBounce;
+ public double a;
+ public double b;
+ public int t = 0;
+
+ @Override
+ public void run()
+ {
+
+
+
+
+ if (cv.w == 0 || !running)
+ {
+ cv.handler.postDelayed(this, 10);
+ return;
+ }
+
+ if (Game.MODE != Game.CRAZY_GRAVITY_MODE && Game.MODE != Game.FLIP_MODE)
+ gravity = 1;
+ else if (Game.MODE == Game.CRAZY_GRAVITY_MODE)
+ gravity = Math.abs(cv.w*(t*a*Math.sin(b*t)));
+ else if (Game.MODE == Game.FLIP_MODE && (t/500) % 2 == 0)
+ gravity = 1;
+ else if (Game.MODE == Game.FLIP_MODE)
+ gravity = -1;
+
+ cv.currentBallPosition[0] += ballVel[0];
+ cv.currentBallPosition[1] += ballVel[1];
+
+
+ if (cv.currentBallPosition[1] > cv.h || cv.currentBallPosition[1] < 0 || cv.currentBallPosition[0] > cv.w || cv.currentBallPosition[0] < 0)
+ {
+ running = false;
+ new AlertDialog.Builder(CanvasView.activity)
+ .setTitle("You lost!")
+ .setMessage("Score: " + CanvasView.score)
+ .setCancelable(false)
+ .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which)
+ {
+ CanvasView.started = false;
+ Intent intent = new Intent(CanvasView.activity, Menu.class);
+ CanvasView.activity.startActivity(intent);
+ }
+ }).create().show();
+ }
+
+ if (Math.abs(cv.currentBallPosition[0]-cv.paddlePosition[0]) < cv.paddleSize/2 &&
+ Math.abs(cv.currentBallPosition[1]-cv.paddlePosition[1]) < 5+cv.ballSize)
+ {
+ Date d = new Date();
+
+ if (d.getTime()-lastBounce < 100)
+ {
+ ballVel[1] += gravity;
+ cv.ballPositions.add(cv.currentBallPosition.clone());
+ cv.invalidate();
+ cv.handler.postDelayed(this, 10);
+ return;
+ }
+
+ ballVel[0] += cv.w*0.00005 * (cv.currentBallPosition[0]-cv.paddlePosition[0]) + Math.random()*cv.w*0.0005-cv.w*0.00025;
+ ballVel[1] = -gravity*cv.w*0.02;
+ CanvasView.score++;
+
+ lastBounce = d.getTime();
+ }
+
+
+ ballVel[1] += gravity;
+
+
+ cv.ballPositions.add(cv.currentBallPosition.clone());
+
+ cv.invalidate();
+
+ t++;
+
+ cv.handler.postDelayed(this, 10);
+
+
+ }
+}