Skip to content

Commit

Permalink
Release 0.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
sebaslavigne committed Jan 26, 2019
2 parents 9a8c1b9 + 56590a3 commit 5570a0e
Show file tree
Hide file tree
Showing 30 changed files with 722 additions and 133 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# java-unterzee
# Java Unterzee
Java Unterzee is a submarine simulation game written in Java using the Swing toolkit with a custom game engine.

## Planned and possible features
Expand All @@ -21,6 +21,18 @@ License: Free use license

## Changelog

### v0.0.7
* Added side panel with data and command sections
* Commands are now given through the game's command license
* Crew messages now appear in game loading
* Map is now zoomable by scroll wheel

### v0.0.6
* Perfected ship turning dynamics
* Added camera class, all vessels are displayed in the map relative to it. Can free roam or follow the player submarine
* Added scenario class for game object creation and handling
* Added classes for each kind of ship

### v0.0.5
* Map zoom now uses floating point variable
* All sprites scale accordingly when zooming the map
Expand Down
2 changes: 1 addition & 1 deletion src/commons/Clock.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public final class Clock {
public final static long FRAME_PERIOD = 16;
public final static long FRAME_NANO = 16666666;
/** The time spent in frame in seconds */
public final static double TICK_TIME = 0.016;
public final static double TICK_TIME = 0.016666666;

private static long gameStartTime;

Expand Down
98 changes: 88 additions & 10 deletions src/commons/ImageResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
import javax.imageio.ImageIO;

import main.Main;
import ships.Battleship;
import ships.Cruiser;
import ships.Destroyer;
import ships.PatrolShip;
import ships.RescueShip;
import submarine.Submarine;

/**
*@author Sebas Lavigne
Expand All @@ -17,47 +23,119 @@ public class ImageResource {
public static final int BG_TILE_HEIGHT = 144;


public static BufferedImage submarine;
public static BufferedImage[] background;
private static BufferedImage submarine;
private static BufferedImage battleship;
private static BufferedImage cruiser;
private static BufferedImage destroyer;
private static BufferedImage patrolShip;
private static BufferedImage rescueShip;
private static BufferedImage[] background;

public static void instantiateImages() {
try {
submarine = ImageIO.read(Main.class.getResource("../sprites/vessels/ShipSubMarineHull.png"));
loadBackground();
loadVessels();
} catch (IOException e) {
e.printStackTrace();
}
}


public static void loadBackground() throws IOException {
background = new BufferedImage[21];
String url;
for (int i = 0; i < background.length; i++) {
url = "../sprites/bg/ocean" + String.format("%02d", i+1) + ".png";
url = "/sprites/bg/ocean" + String.format("%02d", i+1) + ".png";
background[i] = ImageIO.read(Main.class.getResource(url));
}
}

/**
* @throws IOException
*/
private static void loadVessels() throws IOException {
submarine = ImageIO.read(Main.class.getResource("/sprites/vessels/ShipSubMarineHull.png"));
battleship = ImageIO.read(Main.class.getResource("/sprites/vessels/ShipBattleshipHull.png"));
cruiser = ImageIO.read(Main.class.getResource("/sprites/vessels/ShipCruiserHull.png"));
destroyer = ImageIO.read(Main.class.getResource("/sprites/vessels/ShipDestroyerHull.png"));
patrolShip = ImageIO.read(Main.class.getResource("/sprites/vessels/ShipPatrolHull.png"));
rescueShip = ImageIO.read(Main.class.getResource("/sprites/vessels/ShipRescue.png"));
}

public static BufferedImage getImageForVessel(Vessel vessel) {
if (vessel instanceof Submarine) {
return submarine;
} else if (vessel instanceof Battleship) {
return battleship;
} else if (vessel instanceof Cruiser) {
return cruiser;
} else if (vessel instanceof Destroyer) {
return destroyer;
} else if (vessel instanceof PatrolShip) {
return patrolShip;
} else if (vessel instanceof RescueShip) {
return rescueShip;
} else {
return null;
}
}

/**
* @return the submarine
*/
public static BufferedImage getSubmarine() {
return submarine;
}



/**
* @return the background
* @return the battleship
*/
public static BufferedImage[] getBackground() {
return background;
public static BufferedImage getBattleship() {
return battleship;
}


/**
* @return the cruiser
*/
public static BufferedImage getCruiser() {
return cruiser;
}


/**
* @return the destroyer
*/
public static BufferedImage getDestroyer() {
return destroyer;
}


/**
* @return the patrolShip
*/
public static BufferedImage getPatrolShip() {
return patrolShip;
}


/**
* @param background the background to set
* @return the rescueShip
*/
public static void setBackground(BufferedImage[] background) {
ImageResource.background = background;
public static BufferedImage getRescueShip() {
return rescueShip;
}


/**
* @return the background
*/
public static BufferedImage[] getBackground() {
return background;
}




Expand Down
68 changes: 11 additions & 57 deletions src/commons/Vessel.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@

public abstract class Vessel {

protected int behaviourMode;

/* Vessel magnitudes */
protected double beam;
protected double length;

/* Vessel capabilities */
/** Desired speed */
protected double mySpeed;
Expand All @@ -39,12 +33,6 @@ public abstract class Vessel {
/** A collection of points that define this vessel's course */
protected LinkedHashSet<Point2D> course;

/* Solution and detection between 0 and 1 */
/** The player's solution on this ship */
protected double solution;
/** This ships's solution on the player */
protected double detection;

public void tick() {
steer();
sail();
Expand Down Expand Up @@ -76,10 +64,17 @@ private void steer() {
double angleDiff = (2 * Math.PI + myHeading - heading) % (2 * Math.PI);
//Determine left or right
int rotDir = (angleDiff < Math.PI) ? 1 : -1;
//Determine turning coefficient based on speed, will turn slower if below 1/3 speed
double rotCof = 1;
if (Math.abs(speed) < standardSpeed / 3) {
rotCof = Math.abs(speed) / (standardSpeed / 3);
//Determine turning coefficient based on speed and desired speed, will turn slower if below 1/3 speed
double rotCof = 1; //base rotation
//bonus due to speed (more force by rudder)
double rotRudder = (Math.abs(speed) < standardSpeed / 3) ?
-1 + Math.abs(speed) / (standardSpeed / 3) :
(Math.abs(speed) - standardSpeed / 3) / (standardSpeed / 3);
double rotPropeller =Math.abs(mySpeed - speed) / maxSpeed;
rotCof += rotRudder + rotPropeller;
// System.out.println(speed + "\t" + rotCof + "\t" + rotRudder + "\t" + rotPropeller);
if (Double.isNaN(rotCof)) {
rotCof = 0;
}
double deltaRot = rotationSpeed * Clock.TICK_TIME * rotDir * rotCof;
//If turning overshoots the desired heading
Expand Down Expand Up @@ -161,27 +156,13 @@ public double getMaxSpeed() {
return maxSpeed;
}

/**
* @param maxSpeed the maxSpeed to set
*/
public void setMaxSpeed(double maxSpeed) {
this.maxSpeed = maxSpeed;
}

/**
* @return the acceleration
*/
public double getAcceleration() {
return acceleration;
}

/**
* @param acceleration the acceleration to set
*/
public void setAcceleration(double acceleration) {
this.acceleration = acceleration;
}

/**
* @return the myHeading
*/
Expand Down Expand Up @@ -224,54 +205,27 @@ public void setPosition(Point2D position) {
this.position = position;
}

/**
* @return the solution
*/
public double getSolution() {
return solution;
}

/**
* @return the rotationSpeed
*/
public double getRotationSpeed() {
return rotationSpeed;
}

/**
* @param rotationSpeed the rotationSpeed to set
*/
public void setRotationSpeed(double rotationSpeed) {
this.rotationSpeed = rotationSpeed;
}

/**
* @return the standardSpeed
*/
public double getStandardSpeed() {
return standardSpeed;
}

/**
* @param standardSpeed the standardSpeed to set
*/
public void setStandardSpeed(double standardSpeed) {
this.standardSpeed = standardSpeed;
}

/**
* @return the maxSpeedReverse
*/
public double getMaxSpeedReverse() {
return maxSpeedReverse;
}

/**
* @param maxSpeedReverse the maxSpeedReverse to set
*/
public void setMaxSpeedReverse(double maxSpeedReverse) {
this.maxSpeedReverse = maxSpeedReverse;
}



Expand Down
Binary file added src/fonts/CamingoCode-Bold.ttf
Binary file not shown.
Binary file added src/fonts/CamingoCode-Regular.ttf
Binary file not shown.
Binary file added src/fonts/Courier Prime Sans Bold.ttf
Binary file not shown.
Binary file added src/fonts/Courier Prime Sans.ttf
Binary file not shown.
Binary file added src/fonts/HelveticaNeueLTCom-Bd.ttf
Binary file not shown.
Binary file added src/fonts/cmunbl.ttf
Binary file not shown.
Binary file added src/fonts/cmunobx.ttf
Binary file not shown.
Binary file added src/fonts/joystix monospace.ttf
Binary file not shown.
Binary file added src/fonts/unispace bd.ttf
Binary file not shown.
4 changes: 1 addition & 3 deletions src/main/GamePanel.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package main;

import java.awt.Graphics;
import java.awt.Toolkit;

import javax.swing.JPanel;

import commons.Screen;
import master.Master;
import screens.MapScreen;

/**
*@author Sebas Lavigne
*/

public class GamePanel extends JPanel {

private static final long serialVersionUID = 1L;
private Screen currentScreen;

public void initializePanel() {
Expand Down
33 changes: 26 additions & 7 deletions src/main/MainWindow.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main;

import java.awt.GridLayout;
import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JFrame;

Expand All @@ -13,33 +14,51 @@

public class MainWindow {

public static final int WINDOW_WIDTH = 1300;
public static final int WINDOW_HEIGHT = 800;
public static final int COMMAND_HEIGHT = 300;

private JFrame window;
private Master master;
private GamePanel gamePanel;
private SidePanel sidePanel;

public MainWindow() {
window = new JFrame("Java Unterzee");
window.setBounds(100, 100, 800, 800);
window.setBounds(100, 100, WINDOW_WIDTH, WINDOW_HEIGHT);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public void initializeComponents() {
window.setLayout(new GridLayout(1, 1));
window.setLayout(new BorderLayout());
gamePanel = new GamePanel();
master = new Master(gamePanel);
gamePanel.setPreferredSize(new Dimension(WINDOW_HEIGHT, WINDOW_HEIGHT));

sidePanel = new SidePanel();
sidePanel.setPreferredSize(new Dimension(WINDOW_WIDTH - WINDOW_HEIGHT, WINDOW_HEIGHT));

master = new Master(gamePanel, sidePanel);
gamePanel.initializePanel();
window.add(gamePanel);
sidePanel.setMaster(master);
sidePanel.initializePanel();
sidePanel.initializeComponents();

master.initializeMaster();

window.getContentPane().add(gamePanel, BorderLayout.CENTER);
window.getContentPane().add(sidePanel, BorderLayout.LINE_END);
}

public void initializeListeners() {

sidePanel.initializeListeners();
window.addMouseWheelListener(master.getScenario().getCamera());
}

public void initialize() {
initializeComponents();
initializeListeners();
window.setVisible(true);
master.initializeMaster();
master.startGame();
}

}
Loading

0 comments on commit 5570a0e

Please sign in to comment.