All pastes #512042 Raw Edit

Stuff

public java v1 · immutable
#512042 ·published 2007-05-26 18:07 UTC
rendered paste body
import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.awt.image.BufferedImage;import java.awt.geom.AffineTransform;public class Ship extends Player{    private Point myLoc;    private double x = 0;    private double y = 0;    public double xvel = 0;    public double yvel = 0;    public double xaccel = 0;    public double yaccel = 0;    public int imageAngle;    public double angleAccel;    Toolkit T = this.getToolkit();    private Image originalImage =  T.getImage("game_ship" + playerNum + ".png"); //used in case of distortion    public Image rotatedImage;    public int mass = 50;        Ship(int playerNumber)    {        super(playerNumber);        rotatedImage = originalImage;        if (playerNum==0){            imageAngle=30;            myLoc= new Point(100,100);}        else if (playerNum==1){            imageAngle=45;            myLoc= new Point(300,300);}        x = (int) myLocation().getX();        y = (int) myLocation().getY();    }               /*accessor method for myLoc*/    Point myLocation()    {        return myLoc;    }        /*sets point accordingly. takes use of myLoc.move(x,y)*/    void move()     {        rotatedImage = rotate((int) (imageAngle+.5));        xvel +=xaccel;        yvel +=yaccel;        imageAngle +=angleAccel;        x += xvel;        y += yvel;        myLoc.move((int) (x+.5), (int) (y+.5));        if (myLocation().getX() <0) x=570;        if (myLocation().getX() >570) x=0;        if (myLocation().getY() <0) y=570;        if (myLocation().getY() >570) y=0;    }    /*taken and modified from:     * http://www.google.com/codesearch?hl=en&q=+lang:java+rotate+show:uR1i1qW9Taw:1Zq3A4enV88:Yqw1Wskl-aw&sa=N&cd=10&ct=rc&cs_p=:pserver:anon%40source.eecs.berkeley.edu:/home/cvs/cvsanon+ptII&cs_f=ptolemy/actor/lib/image/Transform.java#a0     * I HOPE IT WORKS!     */    public BufferedImage rotate(int rotate) {        rotate +=90;        int width = originalImage.getWidth(null);        int height = originalImage.getHeight(null);        int newWidth = width;        int newHeight = height;        if ((rotate == 90) || (rotate == 270)) {            newWidth = height;            newHeight = width;        }        // Create an image buffer in which to paint on.        BufferedImage outputImage = new BufferedImage(newWidth, newHeight,                BufferedImage.TYPE_INT_ARGB);        // Set the rotation        AffineTransform rotateAffineTransform = new AffineTransform();        // Convert rotate to radians.        rotateAffineTransform.rotate(rotate * (Math.PI / 180.0F), width / 2,                height / 2);        if (!((rotate == 180) || (rotate == 360))) {            rotateAffineTransform.translate((width / 2) - (height / 2),                    (width / 2) - (height / 2));        }        // Paint image.        Graphics2D graphics2d = outputImage.createGraphics();        graphics2d.drawImage(originalImage, rotateAffineTransform, null);        graphics2d.dispose();        return outputImage;    }        void destroy(){return;} //kills the ship}