Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //the main vector controlling class that can be very useful
- import java.awt.Shape;
- /**
- * Write a description of class BaseVectorShape here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- //base vector shape class for polygonal shapes
- public class BaseVectorShape
- {
- //variables
- private Shape shape;
- private boolean alive;
- private double x,y;
- private double velX,velY;
- private double moveAngle, faceAngle;
- //accessor methods
- public Shape getShape() { return shape; }
- public boolean isAlive() { return alive; }
- public double getX() { return x; }
- public double getY() { return y; }
- public double getVelX() { return velX; }
- public double getVelY() { return velY; }
- public double getMoveAngle() { return moveAngle; }
- public double getFaceAngle() { return faceAngle; }
- //mutator and helper methods
- public void setShape(Shape shape) { this.shape = shape; }
- public void setAlive(boolean alive) { this.alive = alive; }
- public void setX(double x) { this.x = x; }
- public void incX(double i) { this.x += i; }
- public void setY(double y) { this.y = y; }
- public void incY(double i) { this.y += i; }
- public void setVelX(double velX) { this.velX = velX; }
- public void incVelX(double i) { this.velX += i; }
- public void decVelX(double i) { this.velX -= i; }
- public void setVelY(double velY) { this.velY = velY; }
- public void incVelY(double i) { this.velY += i; }
- public void decVelY(double i) { this.velY -= i; }
- public void setFaceAngle(double angle) { this.faceAngle = angle;}
- public void incFaceAngle(double i) { this.faceAngle += i; }
- public void setMoveAngle(double angle) { this.moveAngle = angle; }
- public void incMoveAngle(double i) { this.moveAngle += i; }
- //default constructor
- BaseVectorShape()
- {
- setShape(null);
- setAlive(false);
- setX(0.0);
- setY(0.0);
- setVelX(0.0);
- setVelY(0.0);
- setMoveAngle(0.0);
- setFaceAngle(0.0);
- }
- }
- //Remember the these are separate classes and not to have the code in the same class
- //Player's ship class I'll let you figure out the other two sprite classes
- import java.awt.Polygon;
- import java.awt.Rectangle;
- /**
- * Write a description of class ShipClass here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- //Ship class - polygonal shape of the player's ship
- public class ShipClass extends BaseVectorShape
- {
- //define the ship polygon
- private int[] shipx = { -6, -3 , 0, 3, 6, 0 };
- private int[] shipy = { 6, 7, 7, 7, 6, -7 };
- //bounding rectangle
- public Rectangle getBounds()
- {
- Rectangle r;
- r = new Rectangle( (int)getX() - 6, (int)getY() - 6, 12, 12);
- return r;
- }
- ShipClass()
- {
- setShape(new Polygon(shipx, shipy, shipx.length));
- setAlive(true);
- }
- }
- //Java Applet this thing runs on
- //Will be posted in another file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement