SpaceShip - // Draws the ship using the graphics context...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
//******************************************************************** // SpaceShip.java Author: Lewis and Loftus // // Solution to Programming Project 7.15 //******************************************************************** / import java.awt.Graphics; import java.awt.Color; import java.awt.Polygon; i public class SpaceShip { private int x, y; private boolean shooting; private final int WIDTH = 40, HEIGHT = 20; //------------------------------------------------------------------ // Moves the ship //------------------------------------------------------------------ public void move(int xPos, int yPos) { x = xPos; y = yPos; } //------------------------------------------------------------------ // Sets the shooting mode of the ship //------------------------------------------------------------------ public void setShooting(boolean value) { shooting = value; } //------------------------------------------------------------------
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // Draws the ship using the graphics context page. If ship is // in shooting mode, draw laser. //------------------------------------------------------------------public void draw(Graphics page, int screenWidth) { int baseX = x-WIDTH; int baseY = y - HEIGHT/2; // antennae page.setColor(Color.green); page.drawLine(baseX + 10, baseY-10, baseX + WIDTH/2, y + HEIGHT/2); page.drawLine(baseX + WIDTH/2, y + HEIGHT/2, x - 10, baseY-10); // body page.setColor(Color.orange); page.fillArc(baseX, baseY, WIDTH, HEIGHT, 0, 180); page.setColor(Color.magenta); page.fillArc(baseX, baseY, WIDTH, HEIGHT, 0, -180); page.setColor(Color.blue); // windows for (int i = 0; i<4; i++) page.fillOval(baseX +(i+1)*7, baseY + 8, 6, 6); //laser if (shooting) { page.setColor(Color.yellow); page.drawLine(x, y, screenWidth, y); } } }...
View Full Document

This note was uploaded on 05/17/2011 for the course COP 3530 taught by Professor Davis during the Spring '08 term at University of Florida.

Page1 / 2

SpaceShip - // Draws the ship using the graphics context...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online