It's death? Huh, I didn't know that.
By the way: I wish I had the means to do what you're able to. I like to call myself a good, courageous man, but I've never been tested. In a way, I envy you.
StickFig:
import java.awt.*;
public class StickFig extends PFig
{
public StickFig(Panel p)
{
super(200, 100, 80, 80, p);
}
public void move ( int deltaX, int deltaY )
{
super.move(deltaX, deltaY);
if ( x < -width / 2 )
x = panel.getSize().width - width / 2;
else if ( (x + width / 2) > panel.getSize().width )
x = -width / 2;
if ( y < -height / 2 )
y = panel.getSize().height - height / 2;
else if ( (y + height / 2) > panel.getSize().height )
y = -height / 2;
}
public void draw()
{
Graphics g = panel.getGraphics();
g.setColor(Color.blue);
g.drawOval(x + width / 4 , y + 1, width / 2, height / 2);
g.setColor(Color.red);
g.drawLine( x + width / 2, y + height / 2 + 1, x + width / 2, y + 3 * height / 4 );
g.setColor(Color.green);
g.drawLine( x + width / 4, y + 5 * height / 8 + 1, x + 3 * width / 4, y + 5 * height / 8 + 1);
g.setColor(Color.blue);
g.drawLine( x + width / 2, y + 3 * height / 4, x + width / 4, y + 7 * height / 8 );
g.drawLine( x + width / 2, y + 3 * height / 4, x + 3 * width / 4, y + 7 * height / 8 );
}
}
PFig:
import java.awt.*;
public abstract class PFig
{
protected int x, y; // Current position of the figure
protected int width, height; // Drawn or displayed this size
protected Panel panel; // Panel the figure lives on
public PFig ( int startX, int startY, int _width, int _height, Panel p )
{
x = startX;
y = startY;
width = _width;
height = _height;
panel = p;
}
public boolean collidedWith ( PFig p )
{
if ( p == null )
return false;
return ( x + width ) >= p.x && ( p.x + p.width ) >= x &&
( y + height ) >= p.y && ( p.y + p.height ) >= y;
}
public void move ( int deltaX, int deltaY )
{
x = x + deltaX;
y = y + deltaY;
}
public void move()
{
}
// Draw the figure.
abstract public void draw();
public void hide()
{
Graphics g = panel.getGraphics();
Color oldColor = g.getColor();
g.setColor(panel.getBackground() );
g.fillRect(x, y, width, height);
g.setColor(oldColor);
}
}
import java.awt.*;
import javax.imageio.*;
import java.io.*;
public class PicFig extends PFig
{
private int xVel = 20;
private int yVel = 20;
private Image img;
public PicFig(Panel p)
{
super(50, 50, 110, 78, p );
try
{
File file = new File("gof.jpg");
img = ImageIO.read(file);
}
catch ( Exception e )
{
System.out.println("Crashing: " + e);
// Whatever???
}
}
public void move()
{
if ( xVel < 0 && x <= 0 ||
xVel > 0 && x + width >= panel.getSize().width )
xVel = - xVel;
if ( yVel < 0 && y <= 0 ||
yVel > 0 && y + height >= panel.getSize().height )
yVel = - yVel;
x = x + xVel;
y = y + yVel;
}
public void draw()
{
if( img != null )
{
Graphics g = panel.getGraphics();
g.drawImage( img, x, y, width, height, null );
}
}
}