Skip to content

Commit

Permalink
unfinished runner and jpanel code while trying to implement bullet. I…
Browse files Browse the repository at this point in the history
…ssue ucsb-cs56-projects#50 is done
  • Loading branch information
UCSBWillHuang1997 committed Nov 8, 2016
1 parent d1273ea commit c1be4f8
Show file tree
Hide file tree
Showing 45 changed files with 1,277 additions and 853 deletions.
101 changes: 101 additions & 0 deletions #build.xml#
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<project default ="compile">

<!-- build.xml for Country Runner, cs56, S13
name: Mathew Glodack, Christina Morris
name: Sidney Rhoads, Tom Craig
-->


<property environment="env"/> <!-- load environment vars -->
<property name="webRoot" value="${env.HOME}/public_html/cs56/13S/${env.USER}/country_runner" />
<property name="webBaseURL" value="http://www.cs.ucsb.edu/~${env.USER}/cs56" />
<property name="webBaseURL1" value="https://foo.cs.ucsb.edu/56mantis/view.php?id=805" />

<property name="course" value="cs56" />
<property name="quarter" value="13S" />
<property name="projectName" value="country_runner" />
<property name="projectPath" value="${course}/projects/games/${projectName}"/>
<property name="javadocDest" value="${webRoot}/${projectName}/javadoc" />
<property name="javadocURL" value="${webBaseURL}/${projectName}/javadoc" />
<property name="mainClass" value="edu.ucsb.cs56.projects.games.country_runner/CountryRunnerGui" />

<path id="project.class.path">
<pathelement location="build"/>
<pathelement location="lib/junit-4.8.2.jar"/>
</path>

<!-- target that compiles the src codes and make a build folder to store the class file -->
<target name="compile" description="Compiles Country Runner">
<mkdir dir="build" />
<javac srcdir="src" destdir="build" debug="true" debuglevel="lines,source">
<classpath>
<pathelement location="build" />
<pathelement location="lib/junit-4.8.2.jar" />
</classpath>
</javac>
</target>

<!-- target that runs the program -->
<target name="run" description="Runs Country Runner" depends="compile">
<java classname="${mainClass}" fork="true">
<classpath refid="project.class.path"/>
</java>
</target>

<!-- target that deletes unnecessary files and directories -->
<target name="clean" description="Deletes unnecessary files and dir" >
<delete failonerror="false" verbose="true">
<fileset dir="build" includes="**/*.class"/>
</delete>
<delete dir="javadoc" quiet="true" />
</target>

<!-- target that generates javadoc files -->
<target name="javadoc" description="Generates JavaDoc files for Country Runner" depends="compile">
<delete dir="javadoc" quiet="true" />
<javadoc destdir="javadoc" author="true" version="true" use="true">
<fileset dir="src" includes="**/*.java" />
<classpath refid="project.class.path" />
</javadoc>
<delete quiet="true" dir="${javadocDest}" />
<copy todir="${javadocDest}" >
<fileset dir="javadoc"/>
</copy>
<!-- Note: this only does the chmod command on the javadoc
subdirectory and its contents. You MIGHT have to MANUALLY do the
chmod on the parent directories. However, you should only need to do
that once.
-->
<chmod dir="${javadocDest}" perm="755" type="dir" includes="**" />
<chmod dir="${javadocDest}" perm="755" type="file" includes="**/*" />
<echo>Javadoc deployed to ${javadocURL}</echo>
</target>

<!-- target that create a jar file -->
<target name="jar" description = "Creates a jar file" depends="compile">
<mkdir dir="dist" />
<copy todir="build/images">
<fileset dir="images"/>
</copy>
<jar destfile="dist/${course}_${quarter}_${projectName}.jar"
basedir="build" >
<manifest>
<attribute name="Main-Class" value="${mainClass}" />
</manifest>
</jar>
</target>

<!-- target that runs Junit Tests -->
<target name="test" description="Run JUnit tests on Country Runner" depends="compile">
<junit haltonerror="no" haltonfailure="no">
<classpath refid="project.class.path" />
<batchtest fork="yes">
<fileset dir="src">
<include name="**/*Test.java"/>
</fileset>
</batchtest>
<formatter type="plain" usefile="false"/>
</junit>
</target>

</project>
10 changes: 5 additions & 5 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@

<!-- target that compiles the src codes and make a build folder to store the class file -->
<target name="compile" description="Compiles Country Runner">
<mkdir dir="build" />
<mkdir dir="build" />
<javac srcdir="src" destdir="build" debug="true" debuglevel="lines,source">
<classpath>
<pathelement location="build" />
<pathelement location="lib/junit-4.8.2.jar" />
<pathelement location="build" />
<pathelement location="lib/junit-4.8.2.jar" />
</classpath>
</javac>
</target>

<!-- target that runs the program -->
<target name="run" description="Runs Country Runner" depends="compile">
<java classname="${mainClass}" fork="true">
<java classname="${mainClass}" fork="true">
<classpath refid="project.class.path"/>
</java>
</target>
Expand All @@ -49,7 +49,7 @@
</delete>
<delete dir="javadoc" quiet="true" />
</target>

<!-- target that generates javadoc files -->
<target name="javadoc" description="Generates JavaDoc files for Country Runner" depends="compile">
<delete dir="javadoc" quiet="true" />
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added res/redLaserRay.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

This file was deleted.

80 changes: 80 additions & 0 deletions src/edu/ucsb/cs56/projects/games/country_runner/Bullet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package edu.ucsb.cs56.projects.games.country_runner;
import java.lang.Math;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import java.io.IOException;
/**Draws the Bullet object on the screen
* @author Christina Morris, Mathew Glodack
* @author Sidney Rhoads, Tom Craig
* @author William Huang, Ray Ouyang
* @version cs56, F16, proj2
*
*/
public class Bullet extends Sprite
{
//initialXPosition goes into the super constructor
private static double initialXPosition;
private static int xPosition;
private double t;
//the speed of bullet
private static final double speed = 15.0;
//the amount of time that each bullet can be fired in milliseconds
private static final int fireInterval = 1000;
//holds the time of when a bullet was last fired
private static int lastFire = 0;
//Image of the bullet
private BufferedImage image;


/** Default Constructor makes a Bullet.
* sets up the spriteSheet and fills the
* sequences with images from it
*/
public Bullet(Runner runner)
{
//reference a runner so one can get the position from where the bullet is to be shot
super(290,74, runner.returnXPosition(),runner.returnYPosition());
try {
image = ImageIO.read(new File("redLaserRay.png"));
} catch (IOException e) {
}
}
/** public boolean canShoot()
* determines if you can shoot based on
* the last fire that was made and the fireInterval
*/
public boolean canShoot(){
if((int)System.currentTimeMillis() - lastFire > fireInterval)
return true;
return false;
}
/** public BufferedImage returnImage()
* returns the current image of the bullet
*/
public BufferedImage returnImage()
{
return image;
}
/** updateCurrentPosition
* Moves the bullet to left until it is off screen.
*/
public void updateCurrentPosition()
{
if(!offTheScreen())
if(canShoot())
xPosition = (int)(speed * t);
this.setX(xPosition);
t++;
}
/** public boolean offTheScreen()
* checks if the bullet is off the screen
*/
public boolean offTheScreen()
{
if(xPosition - 600 == 0)
return true;
return false;
}
}

67 changes: 67 additions & 0 deletions src/edu/ucsb/cs56/projects/games/country_runner/Bullet.java~
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package edu.ucsb.cs56.projects.games.country_runner;
import java.lang.Math;

/**Draws the Sheep object on the screen
* @author Christina Morris, Mathew Glodack
* @author Sidney Rhoads, Tom Craig
* @author William Huang, Ray Ouyang
* @version cs56, F16, proj2
*
*/
public class Bullet extends Sprite
{
//initialXPosition goes into the super constructor
private static double initialXPosition;
private static int xPosition;
private double t;
//the speed of bullet
private static final double speed = 15.0;
//the amount of time that each bullet can be fired in milliseconds
private static final int fireInterval = 1000;
//holds the time of when a bullet was last fired
private static int lastFire = 0;
//Image of the bullet
private BufferedImage image;


/** Default Constructor makes a Bullet.
* sets up the spriteSheet and fills the
* sequences with images from it
*/
public Bullet(Runner runner)
{
//reference a runner so one can get the position from where the bullet is to be shot
super(290,74, runner.getXPosition(),runner.getYPosition);
try {
image = ImageIO.read(new File("redLaserRay.png"));
} catch (IOException e) {
}
}
public boolean canShoot(){
if(System.currentTimeMillis() - lastFire > fireInterval)
return true;
return false;
}
public boolean returnImage()
{
return image;
}
/** updateCurrentPosition
* Moves the bullet to left until it is off screen.
*/
public void updateCurrentPosition()
{
if(!offTheScreen())
if(canShoot())
xPosition = speed * t;
this.setX(xPosition);
t++;
}
public boolean offTheScreen()
{
if(xPosition - 600 == 0)
return true;
return false;
}
}

Loading

0 comments on commit c1be4f8

Please sign in to comment.