import java.awt.Rectangle; import java.io.*; import org.newdawn.slick.*; public class GameV1 extends BasicGame { static File playerStats = new File("PlayerStats.txt"); Image player = null; Image player_Waypoint = null; Rectangle rect_mouse_Test = new Rectangle(2,2); Rectangle rect_player_Test = new Rectangle(2,2); double player_waypoint_X = 0; double player_waypoint_Y = 0; float velocityX = 0; float velocityY = 0; double player_X = 400; //the player's X position double player_Y = 300; //the player's Y position float length; public GameV1() throws IOException { super("Slick2D Path2Glory - SlickBasicGame"); if (playerStats .exists()) { fileLoad(); } else { fileCreate(); } } public static void fileCreate() throws IOException { // Set up the FileWriter with our file name. FileWriter saveFile = new FileWriter("PlayerStats.txt"); // Write the data to the file. saveFile.write("\n"); saveFile.write(PlayerStats.player.str_player_Name + "\n"); saveFile.write(PlayerStats.player.int_player_Level + "\n"); saveFile.write(PlayerStats.player.int_player_Exp + "\n"); saveFile.write(PlayerStats.player.int_player_maxExp + "\n"); saveFile.write(PlayerStats.player.int_player_skillPoints + "\n"); saveFile.write(PlayerStats.player.int_player_Skill + "\n"); saveFile.write(PlayerStats.player.db_player_Speed + "\n"); saveFile.write(PlayerStats.player.int_player_maxEnergy + "\n"); saveFile.write(PlayerStats.player.int_player_Regen + "\n"); saveFile.write(PlayerStats.player.str_player_Ability + "\n"); saveFile.write("\n"); // All done, close the FileWriter. saveFile.close(); } public static void fileLoad() throws FileNotFoundException, IOException { BufferedReader saveFile= new BufferedReader(new FileReader("PlayerStats.txt")); // Throw away the blank line at the top. saveFile.readLine(); // Get the integer value from the String. PlayerStats.player.str_player_Name = saveFile.readLine(); PlayerStats.player.int_player_Level = Integer.parseInt(saveFile.readLine()); PlayerStats.player.int_player_Exp = Integer.parseInt(saveFile.readLine()); PlayerStats.player.int_player_maxExp = Integer.parseInt(saveFile.readLine()); PlayerStats.player.int_player_skillPoints = Integer.parseInt(saveFile.readLine()); PlayerStats.player.int_player_Skill = Integer.parseInt(saveFile.readLine()); PlayerStats.player.db_player_Speed = Double.parseDouble(saveFile.readLine()); PlayerStats.player.int_player_maxEnergy = Integer.parseInt(saveFile.readLine()); PlayerStats.player.int_player_Regen = Integer.parseInt(saveFile.readLine()); PlayerStats.player.str_player_Ability = saveFile.readLine(); // Not needed, but read blank line at the bottom. saveFile.readLine(); saveFile.close(); } public void init(GameContainer gc) throws SlickException { player = new Image("src/Game/v1/res/Player Blue.png"); player_Waypoint = new Image("src/Game/v1/res/Waypoint.png"); } public void update(GameContainer gc, int delta) throws SlickException { Input input = gc.getInput(); //Player Movement if(input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON)) { length = (float) Math.sqrt((player_waypoint_X - player_X)*(player_waypoint_X - player_X) + (player_waypoint_Y - player_Y)*(player_waypoint_Y - player_Y)); velocityX = (float) (player_waypoint_X - player_X) /length * (float) PlayerStats.player.db_player_Speed; velocityY = (float) (player_waypoint_Y - player_Y) /length * (float) PlayerStats.player.db_player_Speed; player_waypoint_X = input.getMouseX() - 2; player_waypoint_Y = input.getMouseY() - 2; rect_mouse_Test.x = (int) player_waypoint_X; rect_mouse_Test.y = (int) player_waypoint_Y; } if (rect_player_Test.intersects(rect_mouse_Test)) { velocityX = 0; velocityY = 0; } rect_player_Test.x = (int) player_X; rect_player_Test.y = (int) player_Y; player_X=player_X+velocityX; player_Y=player_Y+velocityY; } public void render(GameContainer gc, Graphics g) throws SlickException { player.draw((float) player_X-15, (float) player_Y-15); player_Waypoint.draw((float) player_waypoint_X-6, (float) player_waypoint_Y-6); //g.drawRect(rect_player_Test.x, rect_player_Test.y, rect_player_Test.width, rect_player_Test.height); //g.drawRect(rect_mouse_Test.x, rect_mouse_Test.y, rect_mouse_Test.width, rect_mouse_Test.height); } public static void main(String[] args) throws SlickException, IOException { AppGameContainer app = new AppGameContainer( new GameV1() ); //app.setMaximumLogicUpdateInterval(60); //app.setMinimumLogicUpdateInterval(1); app.setDisplayMode(800, 600, false); app.start(); } }