|
boolean vanishOnImpact
|
If collision, the object disappears
|
|
boolean bounceOnImpact
|
If collision, the object bounce
|
|
boolean constrainedInFrame
|
If collision with edge, the object bounce
|
|
boolean mouseUse
|
The object will move with the mouse
|
|
boolean keyboardUse
|
The object will move with the keypresses
|
|
boolean keepXConstant
|
The object will only move along the y axis
|
|
Rectangle
|
Rect(position on X axis, position on Y axis, width, height, Velocity on X axis, Velocity on Y axis)
|
|
Circle
|
Circle(position on X axis, position on Y axis, radius of the circle, Velocity on X axis, Velocity on Y axis)
|
PhysicsEngine PE = new PhysicsEngine();
public Pong() {
p = new Player(width-30, mouseY, 10, rectSize, 0, 0);
c = new Circle(x, y, diam, 5, 5);
PE.add(p);
PE.add(c);
}
public class Player extends Rect {
//Constructs a Player object and sends the needed parameters to the superclass.
public Player(float posX, float posY, float w, float h, float xVelocity, float yVelocity) {
super(posX, posY, w, h, xVelocity, yVelocity);
mouseUse = true;
keepXConstant = true;
}
void draw() {
fill(c);
rect(pos.x, pos.y, w, h);
fill(255);
}
}
#1
//Example on custom class that extends Circle.
public class Shot extends Circle {
//Constructs a Player object and sends the needed parameters to the superclass.
public Shot(float posX, float posY, float radius, float xVelocity, float yVelocity) {
super(posX, posY, radius, xVelocity, yVelocity);
}
void draw() {
fill(c);
ellipse(pos.x, pos.y, radius*2, radius*2);
fill(255); }
}
//////////////////////////
#2
void borderCollisionShot(PhysicsObject PO)
{
Shot shot = (Shot)PO;
if (shot.pos.x <= shot.radius)
{
if (shot.gotHitX != true)
{
objectArray.remove(shot);
shot.gotHitX = true;
}
}
/////////////////////
#3
if (PO instanceof Shot)
borderCollisionShot(PO);
//////////////////////////
#2
void borderCollisionShot(PhysicsObject PO)
{
Shot shot = (Shot)PO;
if (shot.pos.x <= shot.radius)
{
if (shot.gotHitX != true)
{
objectArray.remove(shot);
shot.gotHitX = true;
}
}
/////////////////////
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.