All pastes #499465 Raw Edit

Unnamed

public java v1 · immutable
·published 2007-05-21 02:14 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 int xaccel;    private int yaccel;    public int imageAngle;    Toolkit T = this.getToolkit();    private Image originalImage =  T.getImage("game_ship" + playerNum + ".png");; //used in case of distortion    public Image rotatedImage;    public int weight = 50;        Ship(int playerNumber)    {        super(playerNumber);        rotatedImage = originalImage;        if (playerNum==0){            imageAngle=30;            myLoc= new Point(10,10);}        else if (playerNum==1){            imageAngle=60;            myLoc= new Point(100,100);}    }               /*creates the player. Initializes myLoc as a point to keep track    of location.*/    void initialize ()    {        }    /*accessor method for myLoc*/    Point myLocation()    {        return new Point();    }        /*sets point accordingly. takes use of myLoc.move(x,y)*/    void move()     {        rotatedImage = rotate(imageAngle);    }    /*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 Image rotate(int rotate) {        int width = originalImage.getWidth(null);        int height = originalImage.getHeight(null);        //int newWidth = (int) (width*(Math.sin(rotate)) + height*(Math.cos(rotate)));        //int newHeight = height*((int)Math.ceil(Math.sin(rotate))) + width*((int)Math.ceil(Math.cos(rotate)));        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_RGB);        // 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}