mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Added position update in yacht #story[1047]
This commit is contained in:
@@ -1,8 +1,12 @@
|
|||||||
package seng302.gameServer;
|
package seng302.gameServer;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import seng302.models.Player;
|
import seng302.models.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import seng302.models.Yacht;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Static class to hold information about the current state of the game (model)
|
* A Static class to hold information about the current state of the game (model)
|
||||||
@@ -10,8 +14,10 @@ import java.util.ArrayList;
|
|||||||
*/
|
*/
|
||||||
public class GameState {
|
public class GameState {
|
||||||
|
|
||||||
|
private static Long previousUpdateTime;
|
||||||
private static String hostIpAddress;
|
private static String hostIpAddress;
|
||||||
private static ArrayList<Player> players;
|
private static List<Player> players;
|
||||||
|
private static Map<Integer, Yacht> yachts;
|
||||||
private static Boolean isRaceStarted;
|
private static Boolean isRaceStarted;
|
||||||
private static GameStages currentStage;
|
private static GameStages currentStage;
|
||||||
|
|
||||||
@@ -20,13 +26,15 @@ public class GameState {
|
|||||||
players = new ArrayList<>();
|
players = new ArrayList<>();
|
||||||
currentStage = GameStages.LOBBYING;
|
currentStage = GameStages.LOBBYING;
|
||||||
isRaceStarted = false;
|
isRaceStarted = false;
|
||||||
|
//set this when game stage changes to prerace
|
||||||
|
previousUpdateTime = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getHostIpAddress() {
|
public static String getHostIpAddress() {
|
||||||
return hostIpAddress;
|
return hostIpAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Player> getPlayers() {
|
public static List<Player> getPlayers() {
|
||||||
return players;
|
return players;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,16 +58,11 @@ public class GameState {
|
|||||||
GameState.currentStage = currentStage;
|
GameState.currentStage = currentStage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void update() {
|
||||||
* This iterates through all players and updates each players info to its new state based on its current data
|
Long timeInterval = System.currentTimeMillis() - previousUpdateTime;
|
||||||
*/
|
previousUpdateTime = System.currentTimeMillis();
|
||||||
private void update(){
|
for (Yacht yacht : yachts.values()) {
|
||||||
for(Player player : players) {
|
yacht.update(timeInterval);
|
||||||
// TODO: 10/07/17 wmu16 - Update all player info
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,6 +81,19 @@ public class Yacht {
|
|||||||
this.position = "-";
|
this.position = "-";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param timeInterval since last update in milliseconds
|
||||||
|
*/
|
||||||
|
public void update(Long timeInterval) {
|
||||||
|
Double secondsElapsed = timeInterval / 1000000.0;
|
||||||
|
Double metersCovered = velocity * secondsElapsed;
|
||||||
|
// 111111 meters is approximately 1 degree of lat/long at the equator
|
||||||
|
lat = lat + (metersCovered * Math.sin(heading * (2 * Math.PI / 360))) / 111111;
|
||||||
|
lon = lon + (metersCovered * Math.cos(heading * (2 * Math.PI / 360))) / (111111 * Math
|
||||||
|
.cos(lat * (2 * Math.PI / 360)));
|
||||||
|
// formula take from https://gis.stackexchange.com/questions/2951/algorithm-for-offsetting-a-latitude-longitude-by-some-amount-of-meters
|
||||||
|
}
|
||||||
|
|
||||||
public String getBoatType() {
|
public String getBoatType() {
|
||||||
return boatType;
|
return boatType;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user