put more information in gameobject

This commit is contained in:
yugecin 2016-09-27 18:17:53 +02:00
parent 4769c1cfda
commit e7e33cd406
2 changed files with 25 additions and 9 deletions

View File

@ -25,13 +25,25 @@ import org.newdawn.slick.Graphics;
/**
* Interface for hit object types used during gameplay.
*/
public interface GameObject {
public abstract class GameObject {
public Vec2f start;
public Vec2f end;
private int time;
public void updateStartEndPositions(int startTime) {
time = startTime;
start = getPointAt(startTime);
end = getPointAt(getEndTime());
}
/**
* Draws the hit object to the graphics context.
* @param g the graphics context
* @param trackPosition the current track position
*/
public void draw(Graphics g, int trackPosition);
public abstract void draw(Graphics g, int trackPosition);
/**
* Updates the hit object.
@ -43,7 +55,7 @@ public interface GameObject {
* @param trackPosition the track position
* @return true if object ended
*/
public boolean update(boolean overlap, int delta, int mouseX, int mouseY, boolean keyPressed, int trackPosition);
public abstract boolean update(boolean overlap, int delta, int mouseX, int mouseY, boolean keyPressed, int trackPosition);
/**
* Processes a mouse click.
@ -52,28 +64,32 @@ public interface GameObject {
* @param trackPosition the track position
* @return true if a hit result was processed
*/
public boolean mousePressed(int x, int y, int trackPosition);
public abstract boolean mousePressed(int x, int y, int trackPosition);
/**
* Returns the coordinates of the hit object at a given track position.
* @param trackPosition the track position
* @return the position vector
*/
public Vec2f getPointAt(int trackPosition);
public abstract Vec2f getPointAt(int trackPosition);
public int getTime() {
return time;
}
/**
* Returns the end time of the hit object.
* @return the end time, in milliseconds
*/
public int getEndTime();
public abstract int getEndTime();
/**
* Updates the position of the hit object.
*/
public void updatePosition();
public abstract void updatePosition();
/**
* Resets all internal state so that the hit object can be reused.
*/
public void reset();
public abstract void reset();
}

View File

@ -1216,8 +1216,8 @@ public class Game extends BasicGameState {
ErrorHandler.error(String.format("Failed to create %s at index %d:\n%s",
hitObject.getTypeName(), i, hitObject.toString()), e, true);
gameObjects[i] = new DummyObject(hitObject);
continue;
}
gameObjects[i].updateStartEndPositions(hitObjectTime);
}
// stack calculations