Created
August 22, 2013 07:35
-
-
Save bongtrop/6304140 to your computer and use it in GitHub Desktop.
Test ucigame Bongtrop Ball
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ucigame.*; | |
public class Pong extends Ucigame | |
{ | |
Sprite ball; | |
Sprite paddle; | |
boolean checkDrag; | |
public void setup() | |
{ | |
checkDrag = false; | |
window.size(200, 200); | |
window.title("Bongtrop Ball"); | |
framerate(30); | |
canvas.background(200, 230, 255); | |
ball = makeSprite(getImage("images/ball.gif", 255, 255, 255)); | |
ball.position(canvas.width()/2 - ball.width()/2, | |
canvas.height()/2 - ball.height()/2); | |
ball.motion(0, 4); | |
} | |
public void draw() | |
{ | |
canvas.clear(); | |
if (!checkDrag) { | |
ball.motion(0, 4, ADD); | |
} | |
ball.move(); | |
ball.bounceIfCollidesWith(paddle); | |
ball.bounceIfCollidesWith(TOPEDGE, BOTTOMEDGE, LEFTEDGE, RIGHTEDGE); | |
ball.draw(); | |
} | |
public void onMouseDragged() | |
{ | |
if (mouse.button() == mouse.LEFT) | |
{ | |
ball.motion(0, 0); | |
ball.motion(mouse.Xchange(), mouse.Ychange(), ADDONCE); | |
checkDrag = true; | |
} | |
} | |
public void onMouseReleased() | |
{ | |
if (mouse.button() == mouse.LEFT) | |
{ | |
checkDrag = false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment