Skip to content

Commit

Permalink
109 - fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lijwent committed Dec 13, 2017
1 parent ace45b4 commit 64c01fe
Show file tree
Hide file tree
Showing 61 changed files with 811 additions and 838 deletions.
Binary file removed res/saves/crate.object
Binary file not shown.
2 changes: 0 additions & 2 deletions res/saves/test.txt

This file was deleted.

8 changes: 0 additions & 8 deletions res/saves/test2.txt

This file was deleted.

9 changes: 4 additions & 5 deletions src/main/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public static void main(String[] args) {
// Game game = new PolyLineGame();
// Game game = new CrateGame();

// Game game = new TestGame();
Game game = new BikeGame();
// Game game = new TestGame();
Game game = new BikeGame();
if (game.begin(window, fileSystem)) {

// Use system clock to keep track of time progression
Expand All @@ -60,8 +60,7 @@ public static void main(String[] args) {
try {
int timeDiff = Math.max(0, (int) (1E9 / 300 - deltaTime));
Thread.sleep((int) (timeDiff / 1E6), (int) (timeDiff % 1E6));
} catch (InterruptedException ignored) {
}
} catch (InterruptedException ignored) {}

now = System.nanoTime();
deltaTime = (now - before) / 1E9f;
Expand All @@ -72,7 +71,7 @@ public static void main(String[] args) {
deltaTime = MAX_DELTA_TIME;

}
// System.out.println(deltaTime);
// System.out.println(deltaTime);
// Let the game do its stuff
game.update(deltaTime);

Expand Down
58 changes: 20 additions & 38 deletions src/main/game/ActorGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@
import java.io.File;
import java.util.ArrayList;
import java.util.ConcurrentModificationException;
import java.util.LinkedList;
import java.util.List;

/** Represent a {@linkplain Game}, with its {@linkplain Actor}s */
public class ActorGame implements Game {
/** The Viewport properties. */
private Camera camera;

/** A {@linkplain ArrayList<Actor>} containing all {@linkplain Actor}.*/
private LinkedList<Actor> actors = new LinkedList<Actor>();
/** An {@linkplain ArrayList} containing all {@linkplain Actor}.*/
private ArrayList<Actor> actors = new ArrayList<Actor>();

// main character of the game
/** The main {@linkplain Actor} of this {@linkplain Game} */
Expand All @@ -54,9 +53,6 @@ public class ActorGame implements Game {
/** The given save directory : {@value}*/
private static final String saveDirectory = "saves/";

/** The player's score. */
private int score;

@Override
public boolean begin(Window window, FileSystem fileSystem) {
if (window == null)
Expand All @@ -71,7 +67,6 @@ public boolean begin(Window window, FileSystem fileSystem) {
this.window = window;
this.fileSystem = fileSystem;

this.score = 0;
this.camera = new Camera(this, window);
this.gameManager = new GameManager(this);
return true;
Expand Down Expand Up @@ -114,6 +109,10 @@ public void update(float deltaTime) {
this.world.update(deltaTime);
this.camera.update(deltaTime);

// TODO remove
if (this.getKeyboard().get(KeyEvent.VK_4).isDown()) {
window.setRelativeTransform(Transform.I.scaled(40));
}
for (int i = this.actors.size() - 1; i >= 0; i--) {
try {
this.actors.get(i).update(deltaTime);
Expand Down Expand Up @@ -335,29 +334,6 @@ public void setPayload(PlayableEntity player) {
this.player = player;
}

/**
* Save all {@linkplain Actor}s of the current game.
* @param saveName : The path to the folder to save the game.
*/
public void save(ArrayList<Actor> actorsToSave, String saveName) {

// if the save folder does not exist, create it
File folder = new File(saveDirectory + saveName);
Save.deleteDirectory(folder);
folder.mkdirs();

int n = 0;
for (Actor a : actorsToSave) {
File file = new File(folder.getPath() + "/actor" + n + ".object");
if (Save.saveActor(a, file))
n++;
}
// Save.saveParameters(viewCandidateNumber, playerNumber, this.fileSystem,
// new File(folder.getPath() + "/params.param"));

System.out.println("saved sucesfully " + (folder.listFiles().length - 1) + " actors");
}

/**
* Load all saved {@linkplain Actor}s.
* @param saveName : The name of the save to load.
Expand Down Expand Up @@ -386,24 +362,30 @@ public boolean load(String saveName) {
toAdd.add(actor);
}
}

// int[] params = Save.getParams(fileSystem, new File(save.getPath() + "/params.param"));

// System.out.println(" - loading params");

// this.setViewCandidate(toAdd.get(params[0]));
// this.setPayload((PlayableEntity) toAdd.get(params[1]));
toAdd.add(new EndGameGraphics(this));
this.actorsToAdd.addAll(toAdd);
System.out.println(toAdd.size() + " actors loaded");
toAdd.clear();
return true;
}

}
System.out.println("Unexistant save");
return false;
}

// public boolean saveCurrentActors() {
//
// Save.saveParameters(getGameManager().getLastCheckpoint(), new File(saveDirectory + "temp/params.object"));
// String s =
// Save.saveCurrent(fileSystem, "", new File(saveDirectory + "temp/params.param"));
// return true;
// }

// public boolean loadTempSave() {
// load("temp");
// Save.loadCheckpoint(this, new File(saveDirectory + "temp/params.object"));
// return true;
// }

/**
* Sets the game's view candidate, to be followed by the camera.
Expand Down
8 changes: 4 additions & 4 deletions src/main/game/ComplexBikeGame.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main.game;

import main.game.GUI.menu.InGameMenu;
import main.game.GUI.menu.MainMenu;
import main.game.GUI.menu.PauseMenu;
import main.game.actor.Actor;
import main.game.actor.sensors.SpawnCheckpoint;
import main.game.levels.Level;
Expand All @@ -21,15 +21,15 @@ public abstract class ComplexBikeGame extends ActorGame {
private int currentLevel = 0;
private boolean wasPlayed = false;

private InGameMenu ingameMenu;
private PauseMenu ingameMenu;
private MainMenu mainMenu;

@Override
public boolean begin(Window window, FileSystem fileSystem) {
super.begin(window, fileSystem);

this.levels = createLevelList();
this.ingameMenu = new InGameMenu(this, window);
this.ingameMenu = new PauseMenu(this, window);

this.mainMenu = new MainMenu(this, window);

Expand Down Expand Up @@ -98,7 +98,7 @@ public void beginLevel(int i) {
System.out.println("loading level");
this.levels.get(currentLevel).createAllActors();
super.addActor(levels.get(currentLevel).getActors());
super.addActor(levels.get(currentLevel));
// super.addActor(levels.get(currentLevel));

SpawnCheckpoint sc = levels.get(currentLevel).getSpawnCheckpoint();
if (!wasPlayed) {
Expand Down
1 change: 1 addition & 0 deletions src/main/game/GUI/actorBuilder/CrateBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public void destroy() {
@Override
public void edit() {
this.placed = false;
this.isDone = false;
}

}
4 changes: 3 additions & 1 deletion src/main/game/GUI/actorBuilder/ObstacleBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.geom.Area;
import java.util.ArrayList;

/** Use in the {@linkplain LevelEditor} to build and add a new {@linkplain Obstacle} */
Expand Down Expand Up @@ -125,7 +126,8 @@ public boolean isHovered() {
if (points.size() < 3)
return false;
Polygon p = new Polygon(points);
return p.getGeomArea().contains(getMousePosition().x, getMousePosition().y);
Area a = new Area(p.toPath());
return a.contains(getMousePosition().x, getMousePosition().y);
}

}
8 changes: 2 additions & 6 deletions src/main/game/GUI/actorBuilder/TrampolineBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,13 @@ public void update(float deltaTime, float zoom) {
isDone = true;
}
trampoline.setPosition(position);
} else

if (isHovered() && isRightPressed())
isDone = false;
}
}

@Override
public void draw(Canvas canvas) {
if (trampoline != null)
trampoline.draw(canvas);

}

@Override
Expand All @@ -76,7 +72,7 @@ public void reCreate() {

@Override
public boolean isHovered() {
return ExtendedMath.isInRectangle(position.sub(-.5f, -.5f), position.add(4.5f, .5f), getMousePosition());
return ExtendedMath.isInRectangle(position.add(-.5f, -.5f), position.add(6f, .5f), getMousePosition());
}

@Override
Expand Down
75 changes: 0 additions & 75 deletions src/main/game/GUI/menu/InGameMenu.java

This file was deleted.

Loading

0 comments on commit 64c01fe

Please sign in to comment.