From 6117a5c369af95b9c6a65584884ea704fcaf150d Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Mon, 2 Apr 2012 11:28:30 -0400 Subject: [PATCH] Heres the shot file Signed-off-by: Ricky Barrette --- .../src/com/RickBarrette/asteroids/Shot.java | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Asteroids/src/com/RickBarrette/asteroids/Shot.java diff --git a/Asteroids/src/com/RickBarrette/asteroids/Shot.java b/Asteroids/src/com/RickBarrette/asteroids/Shot.java new file mode 100644 index 0000000..0b4fd2f --- /dev/null +++ b/Asteroids/src/com/RickBarrette/asteroids/Shot.java @@ -0,0 +1,69 @@ +/** + * Shot.java + * @date Apr 2, 2012 + * @author ricky barrette + * @author Twenty Codes, LLC + * + * Copyright 2012 Richard Barrette + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ +package com.RickBarrette.asteroids; + +import java.awt.Color; +import java.awt.Graphics; + +/** + * This class will bt the shots fired bt the ship. Their job is to destroy the asteroids + * @author ricky barrette + */ +public class Shot extends MovingSpaceObject implements Drawable { + + public static final int TOTAL_DRAWS = 50; + public static final int SPEED = 10; + private int mCount = 0; + private AsteroidGame mGame;; + + /** + * Creates a new shot + * @author ricky barrette + * @param mGame + */ + public Shot(double x, double y, double angle, double shipXVel, double shipYVel, AsteroidGame game) { + mX = x; + mY = y; + mAngle = angle; + mAcceleration = SPEED; + mColor = Color.WHITE; + mGame = game; + isActive = true; + mXVelocity = SPEED*Math.cos(angle)+shipXVel; + mYVelocity = SPEED*Math.sin(angle)+shipYVel; + mVelocityDecay = 1; + + } + + @Override + public void draw(Graphics g) { + g.setColor(mColor); + + g.fillOval((int)(mX-.5), (int)(mY-.5), 3, 3); + + /* + * only stick around for x draws + */ + if(++mCount > TOTAL_DRAWS) + mGame.removeElement(this); + } + +}