Disabled external gits
This commit is contained in:
50
Permafrost/src/platform/Program.java
Normal file
50
Permafrost/src/platform/Program.java
Normal file
@@ -0,0 +1,50 @@
|
||||
package platform;
|
||||
|
||||
import java.awt.Color;
|
||||
import platform.game.Simulator;
|
||||
import platform.util.BufferedLoader;
|
||||
import platform.util.DefaultLoader;
|
||||
import platform.util.Display;
|
||||
import platform.util.FileLoader;
|
||||
import platform.util.Loader;
|
||||
import platform.util.SwingDisplay;
|
||||
|
||||
/**
|
||||
* Provides main entry point.
|
||||
*/
|
||||
public class Program {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
// Create components
|
||||
Loader loader = new BufferedLoader(new FileLoader("res/", DefaultLoader.INSTANCE));
|
||||
Display display = new SwingDisplay();
|
||||
display.setBackground(Color.BLACK);
|
||||
try {
|
||||
|
||||
// Game loop
|
||||
Simulator simulator = new Simulator(loader, args);
|
||||
double avg = 0.02;
|
||||
double last = display.getTime();
|
||||
while (!display.isCloseRequested()) {
|
||||
|
||||
// Do frame
|
||||
display.begin();
|
||||
simulator.update(display, display);
|
||||
display.end();
|
||||
|
||||
// Update framerate
|
||||
avg = avg * 0.95 + display.getDeltaTime() * 0.05;
|
||||
if (display.getTime() - last > 1) {
|
||||
last = display.getTime();
|
||||
//System.out.println(avg);
|
||||
}
|
||||
}
|
||||
|
||||
// Close window
|
||||
} finally {
|
||||
display.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
Permafrost/src/platform/game/GameType.java
Normal file
11
Permafrost/src/platform/game/GameType.java
Normal file
@@ -0,0 +1,11 @@
|
||||
/*
|
||||
* Author: Cédric Heozl
|
||||
* Sciper: 257844
|
||||
* Date: 13 Feb 2017
|
||||
*/
|
||||
|
||||
package platform.game;
|
||||
|
||||
public enum GameType {
|
||||
STORY, FREE
|
||||
}
|
243
Permafrost/src/platform/game/Simulator.java
Normal file
243
Permafrost/src/platform/game/Simulator.java
Normal file
@@ -0,0 +1,243 @@
|
||||
package platform.game;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import platform.util.Box;
|
||||
import platform.game.actor.*;
|
||||
import platform.util.Input;
|
||||
import platform.util.Loader;
|
||||
import platform.util.Output;
|
||||
import platform.util.SortedCollection;
|
||||
import platform.util.Vector;
|
||||
import platform.util.View;
|
||||
import platform.game.level.*;
|
||||
|
||||
/**
|
||||
* Basic implementation of world, managing a complete collection of actors.
|
||||
*/
|
||||
public class Simulator implements World {
|
||||
|
||||
private Vector currentCenter;
|
||||
private double currentRadius;
|
||||
private Vector expectedCenter;
|
||||
private double expectedRadius;
|
||||
private Loader loader;
|
||||
private View view;
|
||||
private SortedCollection<Actor> actors = new SortedCollection<Actor>();
|
||||
private ArrayList <Actor> registered = new ArrayList<Actor>();
|
||||
private ArrayList <Actor> unregistered = new ArrayList<Actor>();
|
||||
private Level next;
|
||||
private Level currentLevel;
|
||||
private boolean transition = true;
|
||||
private Difficulty diff;
|
||||
private int[] chrono = new int[3];
|
||||
private boolean respawn;
|
||||
private GameType type = GameType.FREE;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new simulator.
|
||||
* @param loader associated loader, not null
|
||||
* @param args level arguments, not null
|
||||
*/
|
||||
public Simulator(Loader loader, String[] args) {
|
||||
if (loader == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
this.loader = loader;
|
||||
currentCenter = Vector.ZERO;
|
||||
currentRadius = 10.0;
|
||||
expectedCenter = Vector.ZERO;
|
||||
expectedRadius = 10.0;
|
||||
diff = Difficulty.NORMAL;
|
||||
respawn = true;
|
||||
}
|
||||
|
||||
public void setDifficulty(Difficulty diff) {
|
||||
this.diff = diff;
|
||||
}
|
||||
|
||||
public Difficulty getDifficulty() {
|
||||
return diff;
|
||||
}
|
||||
|
||||
public int[] getChrono() {
|
||||
return chrono;
|
||||
}
|
||||
|
||||
public void setChrono(int[] time) {
|
||||
this.chrono=time;
|
||||
}
|
||||
|
||||
public void resetChrono(){
|
||||
this.chrono = new int[3];
|
||||
}
|
||||
|
||||
public void setGameType(GameType type){
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public GameType getGameType(){
|
||||
return type;
|
||||
}
|
||||
|
||||
public boolean isGameTypeStory(){
|
||||
return type==GameType.STORY;
|
||||
}
|
||||
|
||||
public void setRespawn(boolean respawn) {
|
||||
this.respawn = respawn;
|
||||
}
|
||||
|
||||
public boolean getRespawn() {
|
||||
return respawn;
|
||||
}
|
||||
|
||||
public double getWWidth(){
|
||||
if(view!=null)
|
||||
return view.getSizeX();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
public double getWHeight(){
|
||||
if(view!=null)
|
||||
return view.getSizeY();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setView(Vector center, double radius) {
|
||||
if (center == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
if (radius <= 0) {
|
||||
throw new IllegalArgumentException ("radius must be positive");
|
||||
}
|
||||
expectedCenter = center;
|
||||
expectedRadius = radius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector getViewCenter() {
|
||||
return this.currentCenter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getViewRadius() {
|
||||
return this.currentRadius;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulate a single step of the simulation.
|
||||
* @param input input object to use, not null
|
||||
* @param output output object to use, not null
|
||||
*/
|
||||
public void update(Input input, Output output) {
|
||||
double factor = 0.06;
|
||||
currentCenter = currentCenter.mul(1.0 - factor).add(expectedCenter.mul(factor));
|
||||
currentRadius = currentRadius * (1.0 - factor) + expectedRadius * factor;
|
||||
|
||||
this.view = new View(input, output);
|
||||
this.view.setTarget(currentCenter, currentRadius);
|
||||
|
||||
for (Actor a : actors) {
|
||||
a.preUpdate(this.view);
|
||||
}
|
||||
|
||||
for (Actor actor : actors) for (Actor other : actors) {
|
||||
if (actor.getPriority() > other.getPriority()) {
|
||||
actor.interact(other);
|
||||
}
|
||||
}
|
||||
|
||||
// Update Actors
|
||||
for (Actor a : actors) {
|
||||
a.update(this.view);
|
||||
}
|
||||
|
||||
// Display Actors
|
||||
for (Actor a : actors.descending()) {
|
||||
a.draw(this.view, this.view);
|
||||
}
|
||||
|
||||
for (Actor a : actors) {
|
||||
a.postUpdate(this.view);
|
||||
}
|
||||
|
||||
//Add registered actors
|
||||
for (int i = 0; i < registered.size(); ++i) {
|
||||
Actor actor = registered.get(i);
|
||||
if (!actors.contains(actor)) {
|
||||
actors.add(actor);
|
||||
}
|
||||
}
|
||||
registered.clear();
|
||||
|
||||
//Remove unregistered actors
|
||||
for (int i= 0; i < unregistered.size(); ++i) {
|
||||
Actor actor = unregistered.get(i);
|
||||
actors.remove(actor);
|
||||
}
|
||||
unregistered.clear();
|
||||
|
||||
//si un acteur change next à true
|
||||
//à un autre niveau :
|
||||
if (transition) {
|
||||
transition = false;
|
||||
if (next == null) {
|
||||
next = Level.createDefaultLevel();
|
||||
}
|
||||
//si un acteur a appelé setNextLevel, next ne sera pas null:
|
||||
Level level = next;
|
||||
currentLevel = level;
|
||||
next = null;
|
||||
actors.clear();
|
||||
//tous les anciens acteurs sont désenregistrés,
|
||||
//y compris le level précédent:
|
||||
register(level);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(Actor actor) {
|
||||
registered.add(actor);
|
||||
actor.register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister(Actor actor) {
|
||||
unregistered.add(actor);
|
||||
actor.unregister();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hurt(Box area, Actor instigator, Damage type,
|
||||
double amount, Vector location) {
|
||||
int victims = 0;
|
||||
for (Actor actor : actors)
|
||||
if (area.isColliding(actor.getBox()))
|
||||
if (actor.hurt(instigator, type, amount, location))
|
||||
++victims;
|
||||
return victims;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Loader getLoader() {
|
||||
return loader;
|
||||
}
|
||||
|
||||
public void nextLevel() {
|
||||
this.transition = true;
|
||||
}
|
||||
|
||||
public void setNextLevel(Level level) {
|
||||
this.next = level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Level getCurrentLevel() {
|
||||
return currentLevel;
|
||||
}
|
||||
}
|
65
Permafrost/src/platform/game/World.java
Normal file
65
Permafrost/src/platform/game/World.java
Normal file
@@ -0,0 +1,65 @@
|
||||
package platform.game;
|
||||
|
||||
import platform.game.actor.*;
|
||||
import platform.util.Box;
|
||||
import platform.util.Loader;
|
||||
import platform.util.Vector;
|
||||
import platform.game.level.*;
|
||||
|
||||
/**
|
||||
* Represents an environment populated by actors.
|
||||
*/
|
||||
public interface World {
|
||||
|
||||
/** @return associated loader, not null */
|
||||
public Loader getLoader();
|
||||
|
||||
public void setView(Vector center, double radius);
|
||||
|
||||
public Vector getViewCenter();
|
||||
|
||||
public double getViewRadius();
|
||||
|
||||
//marque le moment de passage au niveau suivant
|
||||
public void nextLevel();
|
||||
|
||||
//permet de passer au niveau level
|
||||
public void setNextLevel(Level level);
|
||||
|
||||
public Level getCurrentLevel();
|
||||
|
||||
public Difficulty getDifficulty();
|
||||
|
||||
public void setDifficulty(Difficulty diff);
|
||||
|
||||
public int[] getChrono();
|
||||
|
||||
public void setChrono(int[] time);
|
||||
|
||||
public void resetChrono();
|
||||
|
||||
public void setGameType(GameType type);
|
||||
|
||||
public GameType getGameType();
|
||||
|
||||
public boolean isGameTypeStory();
|
||||
|
||||
public void setRespawn(boolean respawn);
|
||||
|
||||
public boolean getRespawn();
|
||||
|
||||
public double getWWidth();
|
||||
|
||||
public double getWHeight();
|
||||
|
||||
public int hurt(Box area, Actor instigator, Damage type, double amount, Vector location);
|
||||
|
||||
public void register(Actor actor);
|
||||
|
||||
public void unregister(Actor actor);
|
||||
|
||||
public static Vector getGravity() {
|
||||
return new Vector(0.0, -19.62);
|
||||
}
|
||||
}
|
||||
|
123
Permafrost/src/platform/game/actor/Actor.java
Normal file
123
Permafrost/src/platform/game/actor/Actor.java
Normal file
@@ -0,0 +1,123 @@
|
||||
package platform.game.actor;
|
||||
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Vector;
|
||||
import platform.util.Output;
|
||||
import platform.util.Sprite;
|
||||
import platform.game.World;
|
||||
|
||||
/**
|
||||
* Base class of all simulated actors, attached to a world.
|
||||
*/
|
||||
public abstract class Actor implements Comparable<Actor>{
|
||||
private int priority;
|
||||
private World world;
|
||||
|
||||
//Pre-update
|
||||
public void preUpdate (Input input) {}
|
||||
|
||||
// Update / Evolve
|
||||
public void update(Input input) {}
|
||||
|
||||
//Post-update
|
||||
public void postUpdate(Input input) {}
|
||||
|
||||
// Draw on screeń
|
||||
public void draw(Input input, Output output) {}
|
||||
|
||||
//Returns Actor Priority
|
||||
public int getPriority(){
|
||||
return priority;
|
||||
}
|
||||
|
||||
public void setPriority(int priority){
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
//Interaction between Actors
|
||||
public void interact(Actor other) {}
|
||||
|
||||
public Vector getSpeed() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isSolid() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isPlayer(){
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isClimbable(){
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isSticky(){
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isInteract(){
|
||||
return false;
|
||||
};
|
||||
|
||||
public Box getBox() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Vector getPosition() {
|
||||
Box box = getBox();
|
||||
if (box == null)
|
||||
return null;
|
||||
return box.getCenter();
|
||||
}
|
||||
|
||||
//Compares to actors
|
||||
@Override
|
||||
public int compareTo(Actor other) {
|
||||
int prio1 = this.getPriority();
|
||||
int prio2 = other.getPriority();
|
||||
|
||||
if (prio1 > prio2)
|
||||
return -1;
|
||||
else if (prio1 < prio2)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void register(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public void unregister() {
|
||||
world = null;
|
||||
}
|
||||
|
||||
protected World getWorld() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
protected Sprite getSprite(String name) {
|
||||
if (getWorld() == null) {
|
||||
return null;
|
||||
} else {
|
||||
return getWorld().getLoader().getSprite(name);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hurt(Actor instigator, Damage type, double amount, Vector location) {
|
||||
switch(type) {
|
||||
case VOID:
|
||||
this.getWorld().unregister(this);
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public double getFriction() {
|
||||
return 0.001;
|
||||
}
|
||||
}
|
27
Permafrost/src/platform/game/actor/Background.java
Normal file
27
Permafrost/src/platform/game/actor/Background.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package platform.game.actor;
|
||||
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
|
||||
public class Background extends Actor {
|
||||
|
||||
private Box box;
|
||||
private String skin;
|
||||
|
||||
|
||||
public Background(Box box, String skin){
|
||||
setPriority(-1);
|
||||
this.box = box;
|
||||
this.skin = skin;
|
||||
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output){
|
||||
output.drawSprite(getSprite(skin), getBox(), 0, 0.9);
|
||||
}
|
||||
|
||||
public Box getBox(){
|
||||
return box;
|
||||
}
|
||||
}
|
89
Permafrost/src/platform/game/actor/Chrono.java
Normal file
89
Permafrost/src/platform/game/actor/Chrono.java
Normal file
@@ -0,0 +1,89 @@
|
||||
package platform.game.actor;
|
||||
|
||||
//import java.util.Date;
|
||||
import platform.game.actor.GUI.Text;
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Chrono extends Text{
|
||||
//private int time = 0;
|
||||
private double width = 0;
|
||||
private int[] time = new int[3];
|
||||
private boolean run = true;
|
||||
|
||||
public Chrono(Vector position, int[] time) {
|
||||
super(99999999, 1.0, "00:00:000");
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public Chrono(boolean run) {
|
||||
super(999999999, 1.0, "00:00:000");
|
||||
this.run = run;
|
||||
}
|
||||
|
||||
public Chrono() {
|
||||
super(999999999, 1.0, "00:00:000");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Input input) {
|
||||
if(time[1]==0 && time[2]==0 && (getWorld().getChrono()[1]!=0 || getWorld().getChrono()[2]!=2)){
|
||||
time = getWorld().getChrono();
|
||||
super.setText(timeToString(time[2],time[1],time[0]));
|
||||
}
|
||||
super.setPosition(getWorld().getViewCenter().sub(new Vector(0,getWorld().getViewRadius()-0.6)));
|
||||
this.width = getWorld().getWWidth();
|
||||
if(run){
|
||||
if(time[2]<60){
|
||||
time[0] += input.getDeltaTime()*1000.;
|
||||
while(time[0]>=1000.){
|
||||
time[0]-=1000.;
|
||||
++time[1];
|
||||
}
|
||||
if(time[1]>=60){
|
||||
time[1]-=60;
|
||||
++time[2];
|
||||
}
|
||||
super.setText(timeToString(time[2],time[1],time[0]));
|
||||
}else{
|
||||
run=false;
|
||||
time[2] = 99;
|
||||
time[1] = 99;
|
||||
time[0] = 999;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void postUpdate (Input input){
|
||||
if(run){
|
||||
getWorld().setChrono(time);
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output){
|
||||
output.drawSprite(getSprite("ui/limits"), new Box(getBox().getCenter(),width,1.4));
|
||||
super.draw(input, output);
|
||||
}
|
||||
|
||||
private static String timeToString(int m, int s, int ms){
|
||||
return numToString(m,2)+":"+numToString(s,2)+":"+numToString(ms,3);
|
||||
}
|
||||
|
||||
private static String numToString(int num, int digits){
|
||||
int count = digits;
|
||||
String out = "";
|
||||
while(num<Math.pow(10, count) && count>0){
|
||||
--count;
|
||||
}
|
||||
for(int i=0; i<digits-count-1;++i){
|
||||
out+="0";
|
||||
}
|
||||
return out+num;
|
||||
}
|
||||
|
||||
public boolean hurt(Actor instigator, Damage type, double amount, Vector location) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
75
Permafrost/src/platform/game/actor/Cloud.java
Normal file
75
Permafrost/src/platform/game/actor/Cloud.java
Normal file
@@ -0,0 +1,75 @@
|
||||
package platform.game.actor;
|
||||
|
||||
import platform.game.actor.particle.Particle;
|
||||
import platform.game.signals.Signal;
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Cloud extends Actor {
|
||||
private Vector position;
|
||||
private double width;
|
||||
private double height;
|
||||
private double size;
|
||||
private Vector direction;
|
||||
private static final double STRENGTH = 6.0;
|
||||
private double cooldown=0.0 ;
|
||||
private Signal signal= null;
|
||||
|
||||
public Cloud(Vector position, double width, double height, double size) {
|
||||
this.setPriority(55);
|
||||
this.position = position;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.size = size;
|
||||
}
|
||||
public Cloud(Vector position, double width, double height, double size, Signal signal) {
|
||||
this.setPriority(55);
|
||||
this.position = position;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.size = size;
|
||||
this.signal = signal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Input input) {
|
||||
super.update(input);
|
||||
if(signal== null || signal.isActive())
|
||||
cooldown -= input.getDeltaTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postUpdate(Input input) {
|
||||
if (cooldown <= 0.0) {
|
||||
double flakeSize = size*(Math.random()/2.0+0.3);
|
||||
String skin = Math.random()>=0.5?"particules/snowflake/1":"particules/snowflake/2";
|
||||
getWorld().register(new Particle(new Vector(getPosition().getX() + ((Math.random()-0.5)*width),
|
||||
getPosition().getY() + ((Math.random()-0.5)*height)),
|
||||
flakeSize,flakeSize, 15.0, skin, true,
|
||||
new Vector(0,-(2+4.0*Math.random()))));
|
||||
cooldown = (Math.random()/width*2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interact(Actor other) {
|
||||
super.interact(other);
|
||||
if (getBox().isColliding(other.getBox())) {
|
||||
other.hurt(this, Damage.AIR, STRENGTH, direction);
|
||||
}
|
||||
}
|
||||
|
||||
public Box getBox() {
|
||||
return new Box(position, width, height);
|
||||
}
|
||||
|
||||
public void setSize(double size){
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public Vector getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
}
|
5
Permafrost/src/platform/game/actor/Damage.java
Normal file
5
Permafrost/src/platform/game/actor/Damage.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package platform.game.actor;
|
||||
|
||||
public enum Damage {
|
||||
FIRE, AIR, PHYSICAL, VOID, ACTIVATION, HEAL, STICK, COLD, HEAT, NULL;
|
||||
}
|
16
Permafrost/src/platform/game/actor/Difficulty.java
Normal file
16
Permafrost/src/platform/game/actor/Difficulty.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package platform.game.actor;
|
||||
|
||||
public enum Difficulty {
|
||||
NORMAL("Normal"), HARDCORE("Hardcore");
|
||||
|
||||
private String text;
|
||||
|
||||
Difficulty(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
public String getText() {
|
||||
return this.text;
|
||||
}
|
||||
|
||||
}
|
||||
|
62
Permafrost/src/platform/game/actor/GUI/Button.java
Normal file
62
Permafrost/src/platform/game/actor/GUI/Button.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package platform.game.actor.GUI;
|
||||
|
||||
import platform.game.level.*;
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
import platform.util.Sprite;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Button extends Text {
|
||||
private boolean active = false;
|
||||
Cursor cursor;
|
||||
Level level = null;
|
||||
|
||||
public Button(Vector position, double height, String text, Cursor cursor, Level level){
|
||||
super(position,height,text);
|
||||
this.cursor = cursor;
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public Button(Vector position, double height, String text, Cursor cursor){
|
||||
super(position,height,text);
|
||||
this.cursor = cursor;
|
||||
|
||||
}
|
||||
|
||||
public Box getBox() {
|
||||
Box pBox = super.getBox();
|
||||
return new Box(pBox.getCenter(),pBox.getWidth()+1.0,pBox.getHeight()+0.5);
|
||||
}
|
||||
|
||||
private Sprite getSprite(){
|
||||
if(active)
|
||||
return getSprite("/ui/buttonSelected");
|
||||
else
|
||||
return getSprite("/ui/buttonDefault");
|
||||
}
|
||||
|
||||
public void update(Input input){
|
||||
Vector position = getBox().getCenter();
|
||||
double width = getBox().getWidth();
|
||||
double height = getBox().getHeight();
|
||||
double deltaX = Math.abs(input.getMouseLocation().getX()-position.getX());
|
||||
double deltaY = Math.abs(input.getMouseLocation().getY()-position.getY());
|
||||
if(deltaX<=width/2.0 && deltaY<=height/2.0){
|
||||
active=true;
|
||||
}else{
|
||||
active = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Input input, Output output){
|
||||
output.drawSprite(getSprite(), getBox());
|
||||
super.draw(input, output);
|
||||
}
|
||||
|
||||
public boolean getActive() {
|
||||
return this.active;
|
||||
}
|
||||
|
||||
}
|
51
Permafrost/src/platform/game/actor/GUI/Cursor.java
Normal file
51
Permafrost/src/platform/game/actor/GUI/Cursor.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package platform.game.actor.GUI;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import platform.game.actor.Actor;
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
import platform.util.Sprite;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Cursor extends Actor{
|
||||
private boolean click;
|
||||
private Vector position;
|
||||
private double size;
|
||||
|
||||
public Cursor(){
|
||||
setPriority(100001);
|
||||
click = false;
|
||||
size = 1;
|
||||
}
|
||||
|
||||
private Sprite getSprite(){
|
||||
if(click)
|
||||
return getSprite("ui/tapTick");
|
||||
else
|
||||
return getSprite("ui/tap");
|
||||
}
|
||||
|
||||
public Box getBox(){
|
||||
return new Box(position,size,size);
|
||||
}
|
||||
|
||||
public void update(Input input){
|
||||
position = input.getMouseLocation();
|
||||
if(input.getMouseButton(1).isDown()){
|
||||
click=true;
|
||||
}else{
|
||||
click=false;
|
||||
}
|
||||
if(input.getKeyboardButton(KeyEvent.VK_ESCAPE).isPressed()){
|
||||
getWorld().setView(Vector.ZERO, 11);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Input input, Output output){
|
||||
output.drawSprite(getSprite(), getBox());
|
||||
}
|
||||
|
||||
}
|
24
Permafrost/src/platform/game/actor/GUI/MoveView.java
Normal file
24
Permafrost/src/platform/game/actor/GUI/MoveView.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package platform.game.actor.GUI;
|
||||
|
||||
import platform.util.Input;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class MoveView extends Button {
|
||||
private Vector target;
|
||||
|
||||
public MoveView(Vector position, double height, String text, Cursor cursor, Vector target) {
|
||||
super(position, height, text, cursor);
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Input input) {
|
||||
super.update(input);
|
||||
if(super.getActive() && input.getMouseButton(1).isPressed()){
|
||||
getWorld().setView(target, 11);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
24
Permafrost/src/platform/game/actor/GUI/OneLife.java
Normal file
24
Permafrost/src/platform/game/actor/GUI/OneLife.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package platform.game.actor.GUI;
|
||||
|
||||
import platform.util.Input;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class OneLife extends Button{
|
||||
|
||||
public OneLife(Vector position, double height, Cursor cursor){
|
||||
super(position,height,"off",cursor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Input input) {
|
||||
super.update(input);
|
||||
if(super.getActive() && input.getMouseButton(1).isPressed()){
|
||||
getWorld().setRespawn(!getWorld().getRespawn());
|
||||
}
|
||||
if (getWorld().getRespawn()) {
|
||||
super.setText("on");
|
||||
} else {
|
||||
super.setText("off");
|
||||
}
|
||||
}
|
||||
}
|
19
Permafrost/src/platform/game/actor/GUI/Quit.java
Normal file
19
Permafrost/src/platform/game/actor/GUI/Quit.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package platform.game.actor.GUI;
|
||||
|
||||
import platform.util.Input;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Quit extends Button{
|
||||
|
||||
public Quit(Vector position, double height, Cursor cursor){
|
||||
super(position, height, "Exit", cursor);
|
||||
}
|
||||
@Override
|
||||
public void update(Input input) {
|
||||
super.update(input);
|
||||
if(super.getActive() && input.getMouseButton(1).isPressed()){
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
21
Permafrost/src/platform/game/actor/GUI/SelectLevel.java
Normal file
21
Permafrost/src/platform/game/actor/GUI/SelectLevel.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package platform.game.actor.GUI;
|
||||
|
||||
import platform.game.level.Level;
|
||||
import platform.util.Input;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class SelectLevel extends Button{
|
||||
|
||||
public SelectLevel(Vector position, double height, String text, Cursor cursor, Level level){
|
||||
super(position,height,text,cursor,level);
|
||||
}
|
||||
@Override
|
||||
public void update(Input input) {
|
||||
super.update(input);
|
||||
if(super.getActive() && input.getMouseButton(1).isPressed()){
|
||||
getWorld().setNextLevel(level);
|
||||
getWorld().nextLevel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
32
Permafrost/src/platform/game/actor/GUI/SetDifficulty.java
Normal file
32
Permafrost/src/platform/game/actor/GUI/SetDifficulty.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package platform.game.actor.GUI;
|
||||
|
||||
import platform.game.actor.Difficulty;
|
||||
import platform.util.Input;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class SetDifficulty extends Button{
|
||||
private Difficulty diffSelect = Difficulty.values()[0];
|
||||
private int selected = -1;
|
||||
|
||||
public SetDifficulty(Vector position, double height, Cursor cursor) {
|
||||
super(position,height,"",cursor);
|
||||
}
|
||||
@Override
|
||||
public void update(Input input) {
|
||||
super.update(input);
|
||||
if(selected==-1){
|
||||
selected = getWorld().getDifficulty().ordinal();
|
||||
super.setText(getWorld().getDifficulty().getText());
|
||||
}
|
||||
if(super.getActive() && input.getMouseButton(1).isPressed()){
|
||||
++selected;
|
||||
if (selected >= Difficulty.values().length)
|
||||
selected = 0;
|
||||
diffSelect = Difficulty.values()[selected];
|
||||
getWorld().setDifficulty(diffSelect);
|
||||
super.setText(getWorld().getDifficulty().getText());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
147
Permafrost/src/platform/game/actor/GUI/Text.java
Normal file
147
Permafrost/src/platform/game/actor/GUI/Text.java
Normal file
@@ -0,0 +1,147 @@
|
||||
package platform.game.actor.GUI;
|
||||
|
||||
import platform.game.actor.Actor;
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Text extends Actor {
|
||||
private Vector position;
|
||||
private double size;
|
||||
private double width;
|
||||
private String text;
|
||||
|
||||
public Text(Vector position,double size, String text){
|
||||
this.setPriority(41);
|
||||
this.position = position;
|
||||
this.size = size;
|
||||
this.width = getTextWidth(size,text);
|
||||
this.text = text.toLowerCase();
|
||||
|
||||
}
|
||||
|
||||
public Text(int priority ,double size, String text){
|
||||
this.setPriority(priority);
|
||||
this.size = size;
|
||||
this.width = getTextWidth(size,text);
|
||||
this.text = text.toLowerCase();
|
||||
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text.toLowerCase();
|
||||
this.width = getTextWidth(this.size,this.text);
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public void setPosition(Vector position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public Vector getPosition() {
|
||||
return this.position;
|
||||
}
|
||||
|
||||
public Box getBox() {
|
||||
return new Box(position, width, size);
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output){
|
||||
double posX = position.getX();
|
||||
double posY = position.getY();
|
||||
char current;
|
||||
for(int i = 0; i<text.length();++i){
|
||||
current = text.charAt(i);
|
||||
if(current!=' '){
|
||||
output.drawSprite(getSprite(getCharSprite(current)),
|
||||
new Box(new Vector(posX-width/2.0+size*getCharSize(current)/2,posY),
|
||||
size*getCharSize(current),size));
|
||||
}
|
||||
posX+=size*getCharSize(current);
|
||||
}
|
||||
}
|
||||
|
||||
private static double getTextWidth(double size, String s){
|
||||
char current;
|
||||
double width=0;
|
||||
for(int i = 0; i<s.length();++i){
|
||||
current = s.charAt(i);
|
||||
width+=size*getCharSize(current);
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
private static String getCharSprite(char c){
|
||||
switch(c){
|
||||
case 'a': return "ui/txt/a";
|
||||
case 'b': return "ui/txt/b";
|
||||
case 'c': return "ui/txt/c";
|
||||
case 'd': return "ui/txt/d";
|
||||
case 'e': return "ui/txt/e";
|
||||
case 'f': return "ui/txt/f";
|
||||
case 'g': return "ui/txt/g";
|
||||
case 'h': return "ui/txt/h";
|
||||
case 'i': return "ui/txt/i";
|
||||
case 'j': return "ui/txt/j";
|
||||
case 'k': return "ui/txt/k";
|
||||
case 'l': return "ui/txt/l";
|
||||
case 'm': return "ui/txt/m";
|
||||
case 'n': return "ui/txt/n";
|
||||
case 'o': return "ui/txt/o";
|
||||
case 'p': return "ui/txt/p";
|
||||
case 'q': return "ui/txt/q";
|
||||
case 'r': return "ui/txt/r";
|
||||
case 's': return "ui/txt/s";
|
||||
case 't': return "ui/txt/t";
|
||||
case 'u': return "ui/txt/u";
|
||||
case 'v': return "ui/txt/v";
|
||||
case 'w': return "ui/txt/w";
|
||||
case 'x': return "ui/txt/x";
|
||||
case 'y': return "ui/txt/y";
|
||||
case 'z': return "ui/txt/z";
|
||||
case '0': return "ui/num/0";
|
||||
case '1': return "ui/num/1";
|
||||
case '2': return "ui/num/2";
|
||||
case '3': return "ui/num/3";
|
||||
case '4': return "ui/num/4";
|
||||
case '5': return "ui/num/5";
|
||||
case '6': return "ui/num/6";
|
||||
case '7': return "ui/num/7";
|
||||
case '8': return "ui/num/8";
|
||||
case '9': return "ui/num/9";
|
||||
case '?': return "ui/txt/int";
|
||||
case '!': return "ui/txt/exc";
|
||||
case '\'': return "ui/txt/apo";
|
||||
case '-' : return "ui/txt/-";
|
||||
case '.' : return "ui/txt/dot";
|
||||
|
||||
default:
|
||||
return "box.empty";
|
||||
}
|
||||
}
|
||||
|
||||
private static double getCharSize(char c){
|
||||
switch(c){
|
||||
case 'b':
|
||||
case 'q': return 0.9;
|
||||
case 'z':
|
||||
case 'n':
|
||||
case 'e':
|
||||
case 'f':
|
||||
case 'j':
|
||||
case 'k':
|
||||
case 'l': return 0.8;
|
||||
case '?': return 0.7;
|
||||
case 'i':
|
||||
case '!':
|
||||
case '\'': return 0.5;
|
||||
case '.': return 0.3;
|
||||
default:
|
||||
return 1.0;
|
||||
}
|
||||
}
|
||||
}
|
51
Permafrost/src/platform/game/actor/Heart.java
Normal file
51
Permafrost/src/platform/game/actor/Heart.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package platform.game.actor;
|
||||
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Heart extends Actor {
|
||||
private double cooldown;
|
||||
private Vector position;
|
||||
private double width = 0.5;
|
||||
private double height = 0.5;
|
||||
|
||||
public Heart(Vector position) {
|
||||
this.setPriority(45);
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Input input) {
|
||||
super.update(input);
|
||||
cooldown -= input.getDeltaTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interact(Actor other) {
|
||||
super.interact(other);
|
||||
Vector delta = other.getBox().getCollision(getBox());
|
||||
if (cooldown <= 0 && delta !=null) {
|
||||
if (other.isPlayer() && other.hurt(this, Damage.HEAL, 1, Vector.ZERO)) {
|
||||
cooldown = 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output) {
|
||||
if (cooldown <= 0) {
|
||||
output.drawSprite(getSprite("ui/health/heart.full"), getBox());
|
||||
}
|
||||
}
|
||||
|
||||
public Box getBox() {
|
||||
return new Box(position, width, height);
|
||||
}
|
||||
|
||||
public Vector getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
}
|
||||
|
71
Permafrost/src/platform/game/actor/Jumper.java
Normal file
71
Permafrost/src/platform/game/actor/Jumper.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package platform.game.actor;
|
||||
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
import platform.util.Sprite;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Jumper extends Actor {
|
||||
private double cooldown;
|
||||
private Vector position;
|
||||
private double width;
|
||||
private double height;
|
||||
|
||||
public Jumper(Vector position, double width, double height) {
|
||||
this.setPriority(44);
|
||||
this.position = position;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Input input) {
|
||||
super.update(input);
|
||||
cooldown -= input.getDeltaTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interact(Actor other) {
|
||||
super.interact(other);
|
||||
Vector delta = other.getBox().getCollision(getBox());
|
||||
if(delta!=null){
|
||||
if(other.isPlayer()){
|
||||
other.interact(this);
|
||||
}
|
||||
if(cooldown <= 0.0){
|
||||
Vector below = new Vector(0.0,15.0);
|
||||
if (other.hurt(this, Damage.AIR, 1.0, below)) {
|
||||
cooldown = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Sprite getSprite() {
|
||||
if (cooldown > 0.0) {
|
||||
return getSprite("jumper.extended");
|
||||
} else {
|
||||
return getSprite("jumper.normal");
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output) {
|
||||
output.drawSprite(getSprite(), getBox());
|
||||
}
|
||||
|
||||
public Box getBox() {
|
||||
return new Box(position, width, height);
|
||||
}
|
||||
|
||||
public Vector getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
}
|
50
Permafrost/src/platform/game/actor/Ladder.java
Normal file
50
Permafrost/src/platform/game/actor/Ladder.java
Normal file
@@ -0,0 +1,50 @@
|
||||
package platform.game.actor;
|
||||
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Ladder extends Actor{
|
||||
|
||||
private Vector position;
|
||||
private double height;
|
||||
private double width;
|
||||
|
||||
public Ladder(Vector position, double width, double height) {
|
||||
this.setPriority(0);
|
||||
this.position = position;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
public Ladder(Box box) {
|
||||
this.setPriority(0);
|
||||
this.position = box.getCenter();
|
||||
this.height = box.getHeight();
|
||||
this.width = box.getWidth();
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output) {
|
||||
Box box = getBox();
|
||||
for(int i =0; i<width;++i){
|
||||
for(int j = 0; j<2*height; ++j){
|
||||
output.drawSprite( getSprite("ladder"), new Box(new Vector(box.getMin().getX()+i+0.5,box.getMax().getY()-(j+0.5)/2.0), 1, 0.5));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Box getBox() {
|
||||
return new Box(position,width, height);
|
||||
}
|
||||
|
||||
public Vector getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClimbable(){
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
45
Permafrost/src/platform/game/actor/Limits.java
Normal file
45
Permafrost/src/platform/game/actor/Limits.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package platform.game.actor;
|
||||
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Limits extends Actor {
|
||||
private Vector position;
|
||||
private double height;
|
||||
private double width;
|
||||
|
||||
public Limits(Vector position, double width, double height) {
|
||||
this.setPriority(11111);
|
||||
this.position = position;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public Box getBox() {
|
||||
return new Box(position,width, height);
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output){
|
||||
Vector min = getBox().getMin();
|
||||
Vector max = getBox().getMax();
|
||||
Vector center = getBox().getCenter();
|
||||
output.drawSprite(getSprite("ui/limits"), new Box(new Vector(center.getX(),min.getY()),width,2));
|
||||
|
||||
output.drawSprite(getSprite("ui/limits"), new Box(new Vector(min.getX(),center.getY()),height,2),Math.PI/-2.0);
|
||||
|
||||
output.drawSprite(getSprite("ui/limits"), new Box(new Vector(center.getX(),max.getY()),width,2),Math.PI);
|
||||
|
||||
output.drawSprite(getSprite("ui/limits"), new Box(new Vector(max.getX(),center.getY()),height,2),Math.PI/2.0);
|
||||
|
||||
}
|
||||
|
||||
public void interact(Actor other) {
|
||||
super.interact(other);
|
||||
Vector delta = other.getBox().getCollision(getBox());
|
||||
if (delta == null){
|
||||
other.hurt(this, Damage.VOID, Double.POSITIVE_INFINITY, Vector.ZERO);
|
||||
}
|
||||
}
|
||||
}
|
91
Permafrost/src/platform/game/actor/Overlay.java
Normal file
91
Permafrost/src/platform/game/actor/Overlay.java
Normal file
@@ -0,0 +1,91 @@
|
||||
package platform.game.actor;
|
||||
|
||||
import platform.game.actor.interactors.Keys;
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
import platform.util.Sprite;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Overlay extends Actor{
|
||||
Player player;
|
||||
private final static double SIZE = 1.0/3.0;
|
||||
private final static double MAXHEARTS = 5;
|
||||
|
||||
public Overlay(Player player){
|
||||
this.setPriority(1000);
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public Box getBox() {
|
||||
return player.getBox();
|
||||
}
|
||||
|
||||
public void postUpdate(Input input){
|
||||
if(player == null || player.getWorld() == null){
|
||||
getWorld().unregister(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output){
|
||||
if(this.getWorld()!=null){
|
||||
Sprite skin;
|
||||
double trans;
|
||||
double maxHealth = player.getMaxHealth();
|
||||
double health = player.getHealth();
|
||||
double hearts = maxHealth;
|
||||
if(maxHealth > MAXHEARTS) {
|
||||
health = MAXHEARTS * player.getHealth() / maxHealth;
|
||||
hearts = MAXHEARTS;
|
||||
}
|
||||
Vector playerPos = player.getPosition();
|
||||
trans = ((hearts+1) / 6.0) ;
|
||||
for (int i = 1; i <= hearts; ++i) {
|
||||
String name;
|
||||
if (health >= i)
|
||||
name = "ui/health/heart.full";
|
||||
else if (health >= i - 0.5)
|
||||
name = "ui/health/heart.half";
|
||||
else
|
||||
name = "ui/health/heart.empty";
|
||||
skin = this.getSprite(name);
|
||||
output.drawSprite(skin, new Box(new Vector(
|
||||
playerPos.getX()+(i*SIZE)-trans,
|
||||
playerPos.getY()+2*SIZE),
|
||||
SIZE, SIZE));
|
||||
}
|
||||
|
||||
Keys keys[] = player.getKeys();
|
||||
int i = 0;
|
||||
trans = ((keys.length-1)/2.0) ;
|
||||
for(Keys key : keys){
|
||||
skin =this.getSprite(key.getText());
|
||||
output.drawSprite(skin,
|
||||
new Box(new Vector(
|
||||
playerPos.getX()+(i*SIZE)-trans,
|
||||
playerPos.getY()+4*SIZE),
|
||||
SIZE, SIZE));
|
||||
++i;
|
||||
}
|
||||
double vigor = player.getVigor();
|
||||
double MAXVIGOR = player.getMaxVigor();
|
||||
vigor = vigor<0.0?0.0:vigor;
|
||||
skin = getSprite("ui/vigour/blue");
|
||||
output.drawSprite(skin,
|
||||
new Box(new Vector(
|
||||
playerPos.getX(),
|
||||
playerPos.getY()+3*SIZE),
|
||||
5*SIZE, SIZE/2.0));
|
||||
skin = getSprite("ui/vigour/orange");
|
||||
output.drawSprite(skin,
|
||||
new Box(new Vector(
|
||||
playerPos.getX()+(vigor/MAXVIGOR)-1,
|
||||
playerPos.getY()+3*SIZE),
|
||||
5*SIZE*(vigor/MAXVIGOR), SIZE/2.0));
|
||||
if(player.getInteractor()!=null){
|
||||
skin = getSprite("ui/txt/E");
|
||||
output.drawSprite(skin, new Box(player.getInteractor().getBox().getCenter().add(new Vector(0,1)),0.5,0.5));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
367
Permafrost/src/platform/game/actor/Player.java
Normal file
367
Permafrost/src/platform/game/actor/Player.java
Normal file
@@ -0,0 +1,367 @@
|
||||
package platform.game.actor;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import platform.game.World;
|
||||
import platform.game.actor.interactors.Keys;
|
||||
import platform.game.actor.projectiles.Fireball;
|
||||
import platform.game.level.GameOver;
|
||||
import platform.game.level.Menu;
|
||||
import platform.game.actor.projectiles.Snowball;
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
import platform.util.Sprite;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Player extends Actor {
|
||||
private Vector position;
|
||||
private Vector velocity = Vector.ZERO;
|
||||
private Sprite skin;
|
||||
private double fat = 0.8;
|
||||
private boolean grounding = false;
|
||||
private boolean climbing = false;
|
||||
private double friction = 0.001;
|
||||
private final static double MAXHEALTH = 5;
|
||||
private double health;
|
||||
private final static double MAXVIGOR = 5;
|
||||
private double vigor;
|
||||
private double cooldown;
|
||||
private Actor interactor = null;
|
||||
private double interactorDist = 10.0;
|
||||
private ArrayList<Keys> keychain = new ArrayList<Keys>();
|
||||
private Vector fvelocity = Vector.ZERO;
|
||||
private boolean stuck = false;
|
||||
private double stamina;
|
||||
private boolean canSprint;
|
||||
|
||||
public Player(Vector position, Vector velocity){
|
||||
this.setPriority(42);
|
||||
this.position = position;
|
||||
this.velocity = velocity;
|
||||
this.health = this.MAXHEALTH;
|
||||
this.vigor = this.MAXVIGOR;
|
||||
this.stamina = 3.0;
|
||||
}
|
||||
|
||||
public Player(Vector position, boolean stuck){
|
||||
this.setPriority(42);
|
||||
this.position = position;
|
||||
this.stuck = stuck;
|
||||
this.health = this.MAXHEALTH;
|
||||
this.vigor = this.MAXVIGOR;
|
||||
this.stamina = 3.0;
|
||||
}
|
||||
|
||||
public Difficulty getDifficulty() {
|
||||
return getWorld().getDifficulty();
|
||||
}
|
||||
|
||||
public Sprite getSprite() {
|
||||
if (health > (MAXHEALTH/2) && vigor > 0.0) {
|
||||
skin = getSprite("creature/player/happy");
|
||||
} else if (health <= MAXHEALTH/2 && health > 0 && vigor > 0.0) {
|
||||
skin = getSprite("creature/player/sad");
|
||||
} else if (health <= 0 && vigor > 0.0) {
|
||||
skin = getSprite("creature/player/dead");
|
||||
} else if (vigor <= 0.0 && health > 2.5) {
|
||||
skin = getSprite("creature/player/PlayerCold");
|
||||
} else if ((vigor<=0.0 && health<2.5)) {
|
||||
skin = getSprite("creature/player/PlayerCold2");
|
||||
}
|
||||
return skin;
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output){
|
||||
output.drawSprite(getSprite(), getBox());
|
||||
}
|
||||
|
||||
public void preUpdate(Input input){
|
||||
grounding = false;
|
||||
climbing = false;
|
||||
interactor = null;
|
||||
interactorDist = 10.0;
|
||||
fvelocity = Vector.ZERO;
|
||||
friction = 0.001;
|
||||
}
|
||||
|
||||
public void update(Input input) {
|
||||
double delta = input.getDeltaTime();
|
||||
if (getDifficulty() == Difficulty.HARDCORE)
|
||||
cooldown -= delta/2;
|
||||
else
|
||||
cooldown -= delta;
|
||||
double maxSpeed = 4.0;
|
||||
|
||||
//SPRINT
|
||||
if(stamina > 0.0 && canSprint && grounding && input.getKeyboardButton(KeyEvent.VK_SHIFT).isDown()){
|
||||
maxSpeed = 7.0;
|
||||
stamina -= delta;
|
||||
} else {
|
||||
if (stamina <= 0.0 && canSprint)
|
||||
canSprint = false;
|
||||
if (!canSprint)
|
||||
stamina += delta/2;
|
||||
else {
|
||||
stamina += delta;
|
||||
}
|
||||
}
|
||||
if (stamina > 3.0 && !input.getKeyboardButton(KeyEvent.VK_SHIFT).isDown()) {
|
||||
stamina = 3.0;
|
||||
canSprint = true;
|
||||
}
|
||||
|
||||
//GO RIGHT
|
||||
if (input.getKeyboardButton(KeyEvent.VK_RIGHT).isDown()) {
|
||||
if (velocity.getX() < maxSpeed) {
|
||||
double speed = 60.0 * delta;
|
||||
if (speed > maxSpeed)
|
||||
speed = maxSpeed;
|
||||
velocity = velocity.add(new Vector(speed*(1.0-friction), 0));
|
||||
}
|
||||
}
|
||||
//GO LEFT
|
||||
if (input.getKeyboardButton(KeyEvent.VK_LEFT).isDown()) {
|
||||
if (velocity.getX() > -maxSpeed) {
|
||||
double speed = 60.0 * delta;
|
||||
if (speed < -maxSpeed) {
|
||||
speed = -maxSpeed;
|
||||
}
|
||||
velocity = velocity.sub(new Vector(speed*(1.0-friction), 0));
|
||||
}
|
||||
}
|
||||
//BLOW
|
||||
if (input.getKeyboardButton(KeyEvent.VK_B).isPressed()) {
|
||||
if (cooldown <= 0) {
|
||||
getWorld().hurt(getBox(), this, Damage.AIR, 0.0, getPosition());
|
||||
cooldown = 1.5;
|
||||
}
|
||||
}
|
||||
//INTERACT WITH INTERACTOR
|
||||
if (grounding && input.getKeyboardButton(KeyEvent.VK_E).isPressed() && (interactor!=null)) {
|
||||
interactor.hurt(this, Damage.ACTIVATION, 0.0, getPosition());
|
||||
}
|
||||
|
||||
//MENU
|
||||
if (input.getKeyboardButton(KeyEvent.VK_ESCAPE).isPressed()) {
|
||||
getWorld().setNextLevel(new Menu());
|
||||
getWorld().nextLevel();
|
||||
}
|
||||
|
||||
//CLIMBING MOVEMENT
|
||||
if (climbing) {
|
||||
if (input.getKeyboardButton(KeyEvent.VK_UP).isDown()) {
|
||||
velocity = new Vector(velocity.getX(), 5);
|
||||
} else if (input.getKeyboardButton(KeyEvent.VK_DOWN).isDown()) {
|
||||
velocity = new Vector(velocity.getX(), -5);
|
||||
}
|
||||
|
||||
} else {
|
||||
//JUMP
|
||||
if (grounding && (velocity.getY() == 0.0 ) && input.getKeyboardButton(KeyEvent.VK_UP).isDown()) {
|
||||
velocity = new Vector(velocity.getX(), 11);
|
||||
}
|
||||
//FIREBALL and SNOWBALL
|
||||
if (input.getKeyboardButton(KeyEvent.VK_SPACE).isPressed()) {
|
||||
if((vigor<=0.0 && health<2.5)){
|
||||
this.getWorld().register(new Snowball(position, new Vector(velocity.getX()*3,velocity.getY()+3), this));
|
||||
}else{
|
||||
if(vigor<0.0){
|
||||
vigor=0.0;
|
||||
if (getDifficulty() == Difficulty.HARDCORE)
|
||||
health -= 2.0;
|
||||
else
|
||||
health -= 1.0;
|
||||
}
|
||||
if (getDifficulty() == Difficulty.HARDCORE)
|
||||
vigor -= 2.5;
|
||||
else
|
||||
vigor -= 1.0;
|
||||
this.getWorld().register(new Fireball(position, new Vector(velocity.getX()*3,velocity.getY()+3), this));
|
||||
}
|
||||
}
|
||||
//GRAVITY
|
||||
Vector acceleration = World.getGravity();
|
||||
velocity = velocity.add(acceleration.mul(delta));
|
||||
}
|
||||
//FRICTION
|
||||
if ((grounding || climbing)) {
|
||||
double scale = Math.pow(friction, delta);
|
||||
velocity = velocity.mul(scale);
|
||||
}
|
||||
position = position.add(velocity.mul(delta)).add(fvelocity.mul(delta));
|
||||
}
|
||||
|
||||
public void postUpdate(Input input) {
|
||||
if(!stuck)
|
||||
getWorld().setView(position, 8);
|
||||
if((health <= 0.0) || (input.getKeyboardButton(KeyEvent.VK_Q).isPressed())){
|
||||
getWorld().register(new PlayerDead(position, fat));
|
||||
if (getWorld().getRespawn()) {
|
||||
getWorld().setNextLevel(getWorld().getCurrentLevel());
|
||||
} else {
|
||||
getWorld().setNextLevel(new GameOver());
|
||||
}
|
||||
|
||||
getWorld().unregister(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Box getBox() {
|
||||
return new Box(position, fat, fat);
|
||||
}
|
||||
|
||||
public Vector getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public double getHealth(){
|
||||
return health;
|
||||
}
|
||||
|
||||
public double getMaxHealth(){
|
||||
return MAXHEALTH;
|
||||
}
|
||||
|
||||
public double getVigor(){
|
||||
return vigor;
|
||||
}
|
||||
|
||||
public double getMaxVigor(){
|
||||
return MAXVIGOR;
|
||||
}
|
||||
|
||||
public Keys[] getKeys(){
|
||||
Keys output[] = new Keys[keychain.size()];
|
||||
int i=0;
|
||||
for(Keys key : keychain){
|
||||
output[i]=key;
|
||||
++i;
|
||||
}
|
||||
return output;
|
||||
}
|
||||
public void addKey(Keys key){
|
||||
keychain.add(key);
|
||||
}
|
||||
|
||||
public boolean hasKey(Keys key){
|
||||
return(keychain.indexOf(key)>=0);
|
||||
}
|
||||
|
||||
public void removeKey(Keys key){
|
||||
keychain.remove(keychain.indexOf(key));
|
||||
}
|
||||
|
||||
public boolean isPlayer() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interact(Actor other) {
|
||||
super.interact(other);
|
||||
Vector delta = other.getBox().getCollision(getBox());
|
||||
if(delta!=null){
|
||||
if (other.isSolid()) {
|
||||
friction = other.getFriction();
|
||||
position = position.add(delta);
|
||||
if (delta.getX() != 0.0)
|
||||
velocity = new Vector(0.0, velocity.getY());
|
||||
if (delta.getY() != 0.0){
|
||||
if (getDifficulty() == Difficulty.HARDCORE) {
|
||||
if(velocity.getY() < -13 )
|
||||
health -= 2;
|
||||
} else {
|
||||
if(velocity.getY() <-17 )
|
||||
health -= 0.5;
|
||||
}
|
||||
velocity = new Vector(velocity.getX(), 0.0);
|
||||
}
|
||||
Vector offset = other.getBox().getCenter().sub(getBox().getCenter());
|
||||
if(Math.abs(offset.getX())+0.05<(other.getBox().getWidth()+fat)/2.0 && offset.getY()<=other.getBox().getHeight()/2.0){
|
||||
grounding = true;
|
||||
}
|
||||
|
||||
if (other.hurt(this, Damage.STICK, 1.0, Vector.ZERO)) {
|
||||
this.fvelocity = other.getSpeed();
|
||||
}
|
||||
}
|
||||
|
||||
if(other.isClimbable()) {
|
||||
climbing = true;
|
||||
}
|
||||
if(other.isInteract()){
|
||||
Double newInteractDist = other.getBox().getCenter().sub(this.getBox().getCenter()).getLength();
|
||||
if(interactorDist > newInteractDist){
|
||||
interactor = other;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Actor getInteractor(){
|
||||
return interactor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hurt(Actor instigator, Damage type, double amount, Vector location) {
|
||||
switch (type) {
|
||||
case FIRE:
|
||||
return true;
|
||||
case AIR:
|
||||
velocity = velocity.add(location.mul(amount));
|
||||
if(velocity.getLength() > amount)
|
||||
velocity = velocity.resized(location.mul(amount).getLength());
|
||||
return true;
|
||||
case VOID:
|
||||
health = -1.;
|
||||
return true;
|
||||
case HEAL:
|
||||
if (health < MAXHEALTH) {
|
||||
if (getDifficulty() == Difficulty.HARDCORE)
|
||||
health += amount/2;
|
||||
else
|
||||
health += amount;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case PHYSICAL:
|
||||
if (getDifficulty() == Difficulty.HARDCORE)
|
||||
health -= amount * 2;
|
||||
health -= amount;
|
||||
return true;
|
||||
|
||||
case COLD:
|
||||
if (getDifficulty() == Difficulty.HARDCORE)
|
||||
amount = amount *2 ;
|
||||
if(vigor > 0.0) {
|
||||
this.vigor -= amount;
|
||||
}else{
|
||||
this.vigor -= amount;
|
||||
if(vigor < 0.0) {
|
||||
vigor = 0.0;
|
||||
if (getDifficulty() == Difficulty.HARDCORE)
|
||||
health -= 0.75;
|
||||
else
|
||||
health -= 0.5;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
case HEAT:
|
||||
if (getDifficulty() == Difficulty.HARDCORE) {
|
||||
this.vigor += amount/2;
|
||||
} else {
|
||||
this.vigor += amount;
|
||||
}
|
||||
if(vigor > MAXVIGOR) {
|
||||
vigor = MAXVIGOR;
|
||||
}
|
||||
return true;
|
||||
|
||||
default:
|
||||
return super.hurt(instigator, type, amount, location);
|
||||
}
|
||||
}
|
||||
}
|
51
Permafrost/src/platform/game/actor/PlayerDead.java
Normal file
51
Permafrost/src/platform/game/actor/PlayerDead.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package platform.game.actor;
|
||||
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class PlayerDead extends Actor{
|
||||
private Vector position;
|
||||
private Vector spiritPosition;
|
||||
private double fat;
|
||||
private double cooldown = 2;
|
||||
|
||||
public PlayerDead(Vector position, double fat){
|
||||
this.setPriority(42);
|
||||
this.position = position;
|
||||
this.spiritPosition = position;
|
||||
this.fat = fat;
|
||||
}
|
||||
|
||||
public void update(Input input){
|
||||
double delta = input.getDeltaTime();
|
||||
cooldown-=delta;
|
||||
|
||||
spiritPosition = spiritPosition.add(new Vector(2.0*Math.cos(cooldown*8.0),4.0).mul(delta));
|
||||
if(cooldown<=0.0)
|
||||
getWorld().nextLevel();
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output){
|
||||
output.drawSprite(getSprite("creature/wing_left"), getSBox().add(new Vector(-0.5,0.2)),0,0.8);
|
||||
output.drawSprite(getSprite("creature/wing_right"), getSBox().add(new Vector(0.5,0.2)),0,0.8);
|
||||
output.drawSprite(getSprite("creature/player/dead"), getSBox(),0,0.7);
|
||||
output.drawSprite(getSprite("creature/player/dead"), getBox());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Box getBox() {
|
||||
return new Box(position, fat, fat);
|
||||
}
|
||||
|
||||
public Box getSBox() {
|
||||
return new Box(spiritPosition, fat, fat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hurt(Actor instigator, Damage type, double amount, Vector location) {
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
52
Permafrost/src/platform/game/actor/Portal.java
Normal file
52
Permafrost/src/platform/game/actor/Portal.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package platform.game.actor;
|
||||
|
||||
import platform.game.signals.Signal;
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Portal extends Actor{
|
||||
private Vector position;
|
||||
private Signal signal;
|
||||
|
||||
public Portal(Vector position, double width, double height,Signal signal) {
|
||||
this.setPriority(1111);
|
||||
this.position = position;
|
||||
this.signal = signal;
|
||||
}
|
||||
public Portal(Vector vect, Signal signal) {
|
||||
this.setPriority(1111);
|
||||
this.position = vect;
|
||||
this.signal = signal;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void interact(Actor other) {
|
||||
super.interact(other);
|
||||
Vector delta = other.getBox().getCollision(getBox());
|
||||
if (delta !=null) {
|
||||
if (other.isPlayer() && signal.isActive()) {
|
||||
getWorld().nextLevel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output) {
|
||||
if(signal.isActive()){
|
||||
output.drawSprite(getSprite("portal"), getBox(),input.getDeltaTime()*50);
|
||||
output.drawSprite(getSprite("particules/bubble"), getBox().add(new Vector(Math.random()/10,Math.random()/10)));
|
||||
}else{
|
||||
output.drawSprite(getSprite("particules/bubble"), getBox(),input.getDeltaTime());
|
||||
}
|
||||
}
|
||||
|
||||
public Box getBox() {
|
||||
return new Box(position,1, 1);
|
||||
}
|
||||
|
||||
public Vector getPosition() {
|
||||
return position;
|
||||
}
|
||||
}
|
58
Permafrost/src/platform/game/actor/SnowStorm.java
Normal file
58
Permafrost/src/platform/game/actor/SnowStorm.java
Normal file
@@ -0,0 +1,58 @@
|
||||
package platform.game.actor;
|
||||
|
||||
import platform.game.actor.particle.Particle;
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class SnowStorm extends Actor {
|
||||
private Vector position;
|
||||
private double width;
|
||||
private double height;
|
||||
private Vector direction;
|
||||
private static final double STRENGTH = 9.0;
|
||||
private double cooldown = 1.0;
|
||||
|
||||
public SnowStorm(Vector position, double width, double height, Vector direction) {
|
||||
this.setPriority(55);
|
||||
this.position = position;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Input input) {
|
||||
super.update(input);
|
||||
cooldown -= input.getDeltaTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postUpdate(Input input) {
|
||||
if (cooldown <= 0.0) {
|
||||
getWorld().register(new Particle(new Vector(getPosition().getX() + ((Math.random()-0.5)*width),
|
||||
getPosition().getY() + ((Math.random()-0.5)*height)),
|
||||
0.02,0.4+Math.random(), 1.0, "particules/smoke/white.1", true, direction.mul(STRENGTH)));
|
||||
cooldown = Math.random()/16.0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interact(Actor other) {
|
||||
super.interact(other);
|
||||
if (getBox().isColliding(other.getBox())) {
|
||||
other.hurt(this, Damage.AIR, STRENGTH, direction);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Box getBox() {
|
||||
return new Box(position, width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
}
|
77
Permafrost/src/platform/game/actor/Spike.java
Normal file
77
Permafrost/src/platform/game/actor/Spike.java
Normal file
@@ -0,0 +1,77 @@
|
||||
package platform.game.actor;
|
||||
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
import platform.util.Sprite;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Spike extends Actor {
|
||||
|
||||
private double cooldown;
|
||||
private Vector position;
|
||||
private double width;
|
||||
private double height = 0.5;
|
||||
private Sprite skin;
|
||||
private Box collision;
|
||||
|
||||
public Spike(Vector position, double width) {
|
||||
this.setPriority(45);
|
||||
this.position = position;
|
||||
this.width = width;
|
||||
collision = new Box(position, width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Input input) {
|
||||
super.update(input);
|
||||
cooldown -= input.getDeltaTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interact(Actor other) {
|
||||
super.interact(other);
|
||||
Vector delta = other.getBox().getCollision(getBox());
|
||||
if (cooldown <= 0 && delta !=null) {
|
||||
if (other.hurt(this, Damage.PHYSICAL, 2.5, delta)) {
|
||||
cooldown = 0.5;
|
||||
}
|
||||
}
|
||||
if(other.isPlayer()) {
|
||||
other.interact(this);
|
||||
}
|
||||
}
|
||||
|
||||
public Sprite setSprite() {
|
||||
skin = getWorld().getLoader().getSprite("spikes");
|
||||
return skin;
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output) {
|
||||
if (width > 1) {
|
||||
for (int i = 0; i < width; ++i) {
|
||||
output.drawSprite(setSprite(), new Box(new Vector(position.getX()+i, position.getY()), 1, height));
|
||||
}
|
||||
collision = new Box(new Vector((position.getX()+0.5*(width-1)), position.getY()), width, height);
|
||||
} else {
|
||||
output.drawSprite(setSprite(), getBox());
|
||||
collision = new Box(new Vector((position.getX()), position.getY()), width, height);
|
||||
}
|
||||
}
|
||||
|
||||
public Box getBox() {
|
||||
return collision;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Vector getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
62
Permafrost/src/platform/game/actor/StuckItem.java
Normal file
62
Permafrost/src/platform/game/actor/StuckItem.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package platform.game.actor;
|
||||
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Sprite;
|
||||
import platform.util.Vector;
|
||||
import platform.util.Output;
|
||||
|
||||
public class StuckItem extends Actor {
|
||||
private Actor actor;
|
||||
private Vector position;
|
||||
private String skin;
|
||||
private double cooldown;
|
||||
private double height;
|
||||
private double width;
|
||||
private Vector offset;
|
||||
|
||||
public StuckItem(Vector delta, Actor other, double width, double height, String skin) {
|
||||
this.setPriority(55);
|
||||
this.actor = other;
|
||||
this.cooldown = 5;
|
||||
this.skin = skin;
|
||||
offset = delta;
|
||||
this.position = other.getPosition().add(delta);
|
||||
this.height = height;
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Box getBox() {
|
||||
return new Box(position, height, width);
|
||||
}
|
||||
|
||||
public void update(Input input){
|
||||
double delta = input.getDeltaTime();
|
||||
cooldown-=delta;
|
||||
position = actor.getPosition().add(offset);
|
||||
}
|
||||
|
||||
public void postUpdate(Input input) {
|
||||
if (actor.getWorld() == null || actor == null || cooldown <= 0.0) {
|
||||
getWorld().unregister(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output) {
|
||||
if(getWorld()!=null)
|
||||
output.drawSprite(getSprite(), getBox());
|
||||
}
|
||||
|
||||
public Sprite getSprite() {
|
||||
if (cooldown >= 0.35) {
|
||||
return getSprite(skin);
|
||||
} else if (cooldown >= 0.25) {
|
||||
return getSprite("particules/smoke/gray.1");
|
||||
} else if (cooldown >= 0.1) {
|
||||
return getSprite("particules/smoke/gray.2");
|
||||
} else{
|
||||
return getSprite("particules/smoke/gray.3");
|
||||
}
|
||||
}
|
||||
}
|
114
Permafrost/src/platform/game/actor/Torch.java
Normal file
114
Permafrost/src/platform/game/actor/Torch.java
Normal file
@@ -0,0 +1,114 @@
|
||||
package platform.game.actor;
|
||||
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
import platform.util.Sprite;
|
||||
import platform.util.Vector;
|
||||
import platform.game.actor.particle.Particle;
|
||||
import platform.game.signals.*;
|
||||
|
||||
public class Torch extends Actor implements Signal {
|
||||
private Vector position;
|
||||
private Signal signal = null;
|
||||
private double width = 0.8;
|
||||
private double height = 0.8;
|
||||
private Sprite skin;
|
||||
private boolean lit = false;
|
||||
private double variation;
|
||||
private double cooldown = 1.0;
|
||||
|
||||
public Torch(Vector position, boolean lit) {
|
||||
this.setPriority(25);
|
||||
this.position = position;
|
||||
this.lit = lit;
|
||||
}
|
||||
|
||||
public Torch(Vector position) {
|
||||
this.setPriority(25);
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public Torch(Vector position, Signal signal) {
|
||||
this.setPriority(25);
|
||||
this.position = position;
|
||||
this.signal = signal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return lit;
|
||||
}
|
||||
|
||||
public Sprite setSprite() {
|
||||
if (lit) {
|
||||
String name = "torch.lit.1";
|
||||
if (variation < 0.3) {
|
||||
name = "torch.lit.2";
|
||||
}
|
||||
skin = getWorld().getLoader().getSprite(name);
|
||||
} else {
|
||||
skin = getWorld().getLoader().getSprite("torch");
|
||||
}
|
||||
return skin;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(Input input) {
|
||||
super.update(input);
|
||||
variation -= input.getDeltaTime();
|
||||
cooldown -= input.getDeltaTime();
|
||||
if (variation < 0.0) {
|
||||
variation = 0.6;
|
||||
}
|
||||
if(signal!=null){
|
||||
if(signal.isActive())
|
||||
lit=true;
|
||||
else
|
||||
lit = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postUpdate(Input input) {
|
||||
if (lit && cooldown <= 0.0) {
|
||||
getWorld().register(new Particle(new Vector(getPosition().getX() + (Math.random()-0.5)/4.0,
|
||||
getPosition().getY()+0.2),
|
||||
0.1, 0.1, 0.5, "particules/smoke/white.1", true, new Vector(0.0,3.0)));
|
||||
cooldown = Math.random();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hurt(Actor instigator, Damage type, double amount, Vector location) {
|
||||
switch (type) {
|
||||
case AIR:
|
||||
lit = false;
|
||||
return true;
|
||||
case FIRE:
|
||||
if(!lit){
|
||||
lit = true;
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output) {
|
||||
if (lit) {
|
||||
output.drawSprite(getSprite("particules/heat.zone"),new Box(position, 3, 3));
|
||||
}
|
||||
output.drawSprite(setSprite(), getBox());
|
||||
}
|
||||
|
||||
public Box getBox() {
|
||||
return new Box(position, width, height);
|
||||
}
|
||||
|
||||
public Vector getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
}
|
||||
|
91
Permafrost/src/platform/game/actor/Tree.java
Normal file
91
Permafrost/src/platform/game/actor/Tree.java
Normal file
@@ -0,0 +1,91 @@
|
||||
package platform.game.actor;
|
||||
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
import platform.util.Sprite;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Tree extends Actor {
|
||||
private Vector position;
|
||||
private double width = 1;
|
||||
private double height = 2;
|
||||
private Sprite skin;
|
||||
private boolean dead = false;
|
||||
private boolean burning = false;
|
||||
private boolean burnt = false;
|
||||
private double burntime = 3.0;
|
||||
|
||||
public Tree(Vector position) {
|
||||
this.setPriority(40);
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public Sprite getSprite() {
|
||||
if (dead) {
|
||||
skin = this.getSprite("tree.dead");
|
||||
} else {
|
||||
skin = this.getSprite("tree");
|
||||
}
|
||||
return skin;
|
||||
}
|
||||
|
||||
public void update(Input input){
|
||||
double delta = input.getDeltaTime();
|
||||
if(burning) {
|
||||
burntime -= delta;
|
||||
if(burntime <= 0.0) {
|
||||
burnt=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hurt(Actor instigator, Damage type, double amount, Vector location) {
|
||||
switch (type) {
|
||||
case AIR:
|
||||
dead = true;
|
||||
burning = false;
|
||||
return true;
|
||||
case FIRE:
|
||||
burning = true;
|
||||
dead = true;
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output) {
|
||||
output.drawSprite(getSprite(), getBox());
|
||||
double y = this.getBox().getMin().getY();
|
||||
double x = this.getBox().getMin().getX();
|
||||
if(dead && !burnt){
|
||||
|
||||
output.drawSprite(this.getSprite("leaf.left"), new Box(new Vector(x-0.5,y+0.5),1.0,1.0));
|
||||
output.drawSprite(this.getSprite("leaf.center"), new Box(new Vector(x+0.5,y+0.5),1.0,1.0));
|
||||
output.drawSprite(this.getSprite("leaf.right"), new Box(new Vector(x+1.5,y+0.5),1.0,1.0));
|
||||
}
|
||||
if(burning){
|
||||
Sprite fire = this.getSprite("particules/flame");
|
||||
if(!burnt){
|
||||
output.drawSprite(fire, new Box(new Vector(x-0.1,y+0.3),0.25,0.6), 3.1415);
|
||||
output.drawSprite(fire, new Box(new Vector(x+0.8,y+0.2),0.2,0.5), 3.1415);
|
||||
output.drawSprite(fire, new Box(new Vector(x+0.5,y+0.2),0.25,0.55), 3.1415);
|
||||
}
|
||||
output.drawSprite(fire, new Box(new Vector(x+0.4,y+2),0.2,0.5), 3.1415);
|
||||
output.drawSprite(fire, new Box(new Vector(x+0.9,y+1.2),0.2,0.5), 3.1415);
|
||||
output.drawSprite(fire, new Box(new Vector(x+0.1,y+1),0.2,0.5), 3.1415);
|
||||
output.drawSprite(fire, new Box(new Vector(x+0.8,y+1.8),0.3,0.6), 3.1415);
|
||||
}
|
||||
}
|
||||
|
||||
public Box getBox() {
|
||||
return new Box(position, width, height);
|
||||
}
|
||||
|
||||
public Vector getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
}
|
||||
|
127
Permafrost/src/platform/game/actor/Worm.java
Normal file
127
Permafrost/src/platform/game/actor/Worm.java
Normal file
@@ -0,0 +1,127 @@
|
||||
package platform.game.actor;
|
||||
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
import platform.util.Vector;
|
||||
import platform.game.actor.particle.PoufEffect;
|
||||
import platform.game.actor.zone.EffectArea;
|
||||
import platform.game.level.InterLevel;
|
||||
import platform.game.level.Levels;
|
||||
import platform.game.signals.*;
|
||||
|
||||
public class Worm extends Actor implements Signal{
|
||||
private Vector position;
|
||||
private double width = 0.8;
|
||||
private double height = 0.8;
|
||||
private double variation;
|
||||
private double cooldown = 1.0;
|
||||
private boolean dead = false;
|
||||
private boolean freeze = false;
|
||||
private boolean stuck = false;
|
||||
private Actor other = null;
|
||||
|
||||
public Worm(Vector position) {
|
||||
this.setPriority(44);
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public String getSpriteString() {
|
||||
if(freeze){
|
||||
return "creature/worm/freeze";
|
||||
}else if(dead){
|
||||
return "creature/worm/dead";
|
||||
}else{
|
||||
if (variation < 0.2) {
|
||||
return "creature/worm/1";
|
||||
}else{
|
||||
return "creature/worm/2";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(Input input) {
|
||||
super.update(input);
|
||||
double delta = input.getDeltaTime();
|
||||
cooldown -= delta;
|
||||
if(dead && cooldown<=0.0){
|
||||
getWorld().register(new Cloud(new Vector(0,6), 12, 1, Math.random()/2.0));
|
||||
getWorld().register(new Cloud(new Vector(0,6), 12, 1, Math.random()/2.0));
|
||||
getWorld().register(new Cloud(new Vector(0,6), 12, 1, Math.random()));
|
||||
getWorld().register(new Cloud(new Vector(0,6), 12, 1, Math.random()));
|
||||
getWorld().register(new EffectArea(new Box(Vector.ZERO,12,13), Damage.COLD, 1,new Constant(true)));
|
||||
cooldown = 1.0;
|
||||
|
||||
}
|
||||
if(!stuck && !dead){
|
||||
variation -= delta;
|
||||
if (variation < 0.0) {
|
||||
variation = 0.4;
|
||||
}
|
||||
position = position.add(new Vector(-2,0).mul(delta));
|
||||
}
|
||||
if(stuck && other!=null){
|
||||
position = other.getPosition().add(new Vector(0,0.75));
|
||||
}
|
||||
|
||||
if (dead){
|
||||
getWorld().setNextLevel(new InterLevel(Levels.BADEND));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interact(Actor other) {
|
||||
super.interact(other);
|
||||
Vector delta = other.getBox().getCollision(getBox());
|
||||
if(delta!=null && other.isPlayer() && !stuck){
|
||||
stuck = true;
|
||||
getWorld().register(new PoufEffect(this.getBox(), 0.6));
|
||||
this.other = other;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hurt(Actor instigator, Damage type, double amount, Vector location) {
|
||||
switch (type) {
|
||||
case VOID:
|
||||
dead = true;
|
||||
case COLD:
|
||||
freeze = true;
|
||||
dead = true;
|
||||
return true;
|
||||
case FIRE:
|
||||
dead = true;
|
||||
return true;
|
||||
default:
|
||||
return super.hurt(instigator, type, amount, location);
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output) {
|
||||
if(getWorld()!=null)
|
||||
output.drawSprite(getSprite(getSpriteString()), getBox());
|
||||
}
|
||||
|
||||
public boolean isDead() {
|
||||
return dead;
|
||||
}
|
||||
|
||||
public Box getBox() {
|
||||
return new Box(position, width, height);
|
||||
}
|
||||
|
||||
public boolean isSolid() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Vector getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return stuck;
|
||||
}
|
||||
|
||||
}
|
||||
|
63
Permafrost/src/platform/game/actor/block/Block.java
Normal file
63
Permafrost/src/platform/game/actor/block/Block.java
Normal file
@@ -0,0 +1,63 @@
|
||||
package platform.game.actor.block;
|
||||
|
||||
import platform.game.actor.Actor;
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Sprite;
|
||||
import platform.util.Vector;
|
||||
import platform.util.Output;
|
||||
|
||||
/**
|
||||
* Simple solid actor that does nothing.
|
||||
*/
|
||||
public class Block extends Actor {
|
||||
private Vector position;
|
||||
private double height;
|
||||
private double width;
|
||||
private String skin;
|
||||
private boolean drawing = true;
|
||||
|
||||
public Block(Vector position, double width, double height, String skin) {
|
||||
this.setPriority(0);
|
||||
this.position = position;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.skin = skin;
|
||||
}
|
||||
|
||||
public Block(Box box) {
|
||||
this.setPriority(0);
|
||||
this.position = box.getCenter();
|
||||
this.height = box.getHeight();
|
||||
this.width = box.getWidth();
|
||||
}
|
||||
public Block(Box box, boolean drawing) {
|
||||
this.setPriority(0);
|
||||
this.drawing = drawing;
|
||||
this.position = box.getCenter();
|
||||
this.height = box.getHeight();
|
||||
this.width = box.getWidth();
|
||||
}
|
||||
|
||||
public Sprite getSprite() {
|
||||
return getSprite(skin);
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output) {
|
||||
if(drawing)
|
||||
output.drawSprite(getSprite(), getBox());
|
||||
}
|
||||
|
||||
public Box getBox() {
|
||||
return new Box(position,width, height);
|
||||
}
|
||||
|
||||
public boolean isSolid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Vector getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
}
|
35
Permafrost/src/platform/game/actor/block/Destruct.java
Normal file
35
Permafrost/src/platform/game/actor/block/Destruct.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package platform.game.actor.block;
|
||||
|
||||
import platform.game.actor.Actor;
|
||||
import platform.game.actor.Damage;
|
||||
import platform.game.actor.particle.PoufEffect;
|
||||
import platform.util.Input;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Destruct extends Block {
|
||||
private boolean hit;
|
||||
|
||||
public Destruct(Vector position) {
|
||||
super(position, 1, 1, "box.single");
|
||||
this.setPriority(4);
|
||||
}
|
||||
|
||||
public void postUpdate(Input input) {
|
||||
if (hit) {
|
||||
getWorld().register(new PoufEffect(this.getBox(),0.40));
|
||||
getWorld().unregister(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hurt(Actor instigator, Damage type, double amount, Vector location) {
|
||||
switch (type) {
|
||||
case FIRE:
|
||||
hit = true;
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
51
Permafrost/src/platform/game/actor/block/Door.java
Normal file
51
Permafrost/src/platform/game/actor/block/Door.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package platform.game.actor.block;
|
||||
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
import platform.util.Vector;
|
||||
import platform.game.signals.*;
|
||||
|
||||
public class Door extends Block{
|
||||
private Signal signal;
|
||||
private boolean open = false;
|
||||
private boolean invisible = false;
|
||||
|
||||
public Door(Vector position, Signal signal) {
|
||||
super(position, 1, 1,"lock.red");
|
||||
this.setPriority(41);
|
||||
this.signal = signal;
|
||||
}
|
||||
|
||||
public Door(Vector position, Signal signal, boolean invisible) {
|
||||
super(position, 1, 1,"lock.red");
|
||||
this.setPriority(41);
|
||||
this.signal = signal;
|
||||
this.invisible = invisible;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Input input) {
|
||||
super.update(input);
|
||||
if(signal.isActive())
|
||||
this.open = true;
|
||||
}
|
||||
public void postUpdate(Input input){
|
||||
if(this.open && !this.invisible)
|
||||
getWorld().unregister(this);
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output) {
|
||||
if(!open)
|
||||
output.drawSprite(getSprite(), getBox());
|
||||
}
|
||||
|
||||
public boolean isSolid() {
|
||||
if(!open)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
26
Permafrost/src/platform/game/actor/block/Material.java
Normal file
26
Permafrost/src/platform/game/actor/block/Material.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package platform.game.actor.block;
|
||||
|
||||
public enum Material {
|
||||
GRASS("grass"), SNOW("dirtsnow",0.001), SNOWS("stonesnow",0.001), STONEICE("stoneice"), STONE("castle"),ICE("ice",0.7);
|
||||
|
||||
private String text;
|
||||
private double friction = 0.01;
|
||||
|
||||
Material(String text, double friction) {
|
||||
this.text = text;
|
||||
this.friction = friction;
|
||||
}
|
||||
|
||||
Material(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return this.text;
|
||||
}
|
||||
|
||||
public double getFriction(){
|
||||
return this.friction;
|
||||
}
|
||||
|
||||
}
|
116
Permafrost/src/platform/game/actor/block/Mover.java
Normal file
116
Permafrost/src/platform/game/actor/block/Mover.java
Normal file
@@ -0,0 +1,116 @@
|
||||
package platform.game.actor.block;
|
||||
|
||||
import platform.util.Vector;
|
||||
import platform.game.signals.*;
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
import platform.game.actor.Actor;
|
||||
import platform.game.actor.Damage;
|
||||
|
||||
public class Mover extends Block {
|
||||
private Vector on;
|
||||
private Vector off;
|
||||
private Signal state = null;
|
||||
private double current = 0.0;
|
||||
private double height;
|
||||
private double width;
|
||||
private double position;
|
||||
private Vector lastPosition;
|
||||
private double dT;
|
||||
private double speed = 0.5;
|
||||
private boolean status = false;
|
||||
|
||||
public Mover(Vector on, Vector off, double width, double height, String skin, Signal signal) {
|
||||
super(off, 1, 1, skin);
|
||||
this.on = on;
|
||||
this.off = off;
|
||||
this.height = height;
|
||||
this.width = width;
|
||||
state = signal;
|
||||
}
|
||||
|
||||
public Mover(Vector on, Vector off, double width, double height, String skin) {
|
||||
super(off, 1, 1, skin);
|
||||
this.on = on;
|
||||
this.off = off;
|
||||
this.height = height;
|
||||
this.width = width;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update (Input input) {
|
||||
super.update(input);
|
||||
double delta = input.getDeltaTime();
|
||||
this.dT = delta;
|
||||
this.lastPosition = getBox().getCenter();
|
||||
if (state == null) {
|
||||
if (!status) {
|
||||
current += delta*speed;
|
||||
if (current > 1.0) {
|
||||
status = !status;
|
||||
}
|
||||
} else {
|
||||
current -= delta*speed;
|
||||
if (current < 0.0) {
|
||||
status = !status;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (state.isActive()) {
|
||||
if (!status) {
|
||||
current += input.getDeltaTime()*speed;
|
||||
if (current > 1.0) {
|
||||
current = 1.0;
|
||||
status = !status;
|
||||
}
|
||||
} else {
|
||||
current -= delta*speed;
|
||||
if (current < 0.0) {
|
||||
status = !status;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
current -= input.getDeltaTime()*speed;
|
||||
if (current < 0.0)
|
||||
current = 0.0;
|
||||
status = !status;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Box getBox() {
|
||||
this.position = - 2 * current * current * current + 3 * current * current;
|
||||
//this.position = current;
|
||||
return new Box(off.mixed(on, position),width, height);
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output) {
|
||||
output.drawSprite(getSprite(), getBox());
|
||||
}
|
||||
|
||||
public Vector getSpeed(){
|
||||
return getBox().getCenter().sub(lastPosition).div(dT);
|
||||
}
|
||||
|
||||
public Vector getPosition() {
|
||||
return getBox().getCenter();
|
||||
}
|
||||
|
||||
public boolean isSticky(){
|
||||
return state.isActive();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hurt(Actor instigator, Damage type, double amount, Vector location) {
|
||||
switch (type) {
|
||||
case STICK:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
22
Permafrost/src/platform/game/actor/block/Sign.java
Normal file
22
Permafrost/src/platform/game/actor/block/Sign.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package platform.game.actor.block;
|
||||
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Sign extends Block {
|
||||
private double rotation;
|
||||
|
||||
public Sign(Vector position, double rotation, String skin) {
|
||||
super(position, 1, 1, skin);
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output) {
|
||||
output.drawSprite(getSprite(), getBox(), rotation);
|
||||
}
|
||||
|
||||
public boolean isSolid() {
|
||||
return false;
|
||||
}
|
||||
}
|
41
Permafrost/src/platform/game/actor/block/Terrain.java
Normal file
41
Permafrost/src/platform/game/actor/block/Terrain.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package platform.game.actor.block;
|
||||
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
import platform.util.Sprite;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Terrain extends Block {
|
||||
Material type;
|
||||
|
||||
public Terrain(Box box, Material type) {
|
||||
super(box);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output) {
|
||||
Box box = this.getBox();
|
||||
Sprite skin;
|
||||
double minX = box.getMin().getX();
|
||||
double maxY = box.getMax().getY();
|
||||
double width = box.getWidth();
|
||||
double height = box.getHeight();
|
||||
for(int i = 0; i<width; ++i){
|
||||
for(int j = 0; j<height; ++j){
|
||||
if(j==0){
|
||||
skin = getSprite("terrain/"+type.getText()+"/middle");
|
||||
}else{
|
||||
skin = this.getWorld().getLoader().getSprite("terrain/"+type.getText()+"/center");
|
||||
}
|
||||
output.drawSprite(skin, new Box(new Vector(minX+i+0.5, maxY-j-0.5), 1, 1));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public double getFriction() {
|
||||
return this.type.getFriction();
|
||||
}
|
||||
|
||||
}
|
29
Permafrost/src/platform/game/actor/block/Trap.java
Normal file
29
Permafrost/src/platform/game/actor/block/Trap.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package platform.game.actor.block;
|
||||
|
||||
import platform.util.Input;
|
||||
import platform.util.Vector;
|
||||
import platform.game.actor.projectiles.Arrow;
|
||||
import platform.game.signals.*;
|
||||
|
||||
|
||||
public class Trap extends Block {
|
||||
private double cooldown = 0;
|
||||
private Signal triggered;
|
||||
|
||||
public Trap(Vector position, Signal signal, String skin) {
|
||||
super(position, 1, 1, skin);
|
||||
triggered = signal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update (Input input) {
|
||||
super.update(input);
|
||||
cooldown -= input.getDeltaTime();
|
||||
if (triggered.isActive()) {
|
||||
if (cooldown <= 0) {
|
||||
this.getWorld().register(new Arrow(getPosition(), new Vector(20, 0),this));
|
||||
cooldown = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
4
Permafrost/src/platform/game/actor/block/WorldGen.java
Normal file
4
Permafrost/src/platform/game/actor/block/WorldGen.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package platform.game.actor.block;
|
||||
|
||||
public class WorldGen {
|
||||
}
|
@@ -0,0 +1,96 @@
|
||||
package platform.game.actor.interactors;
|
||||
|
||||
import platform.util.Sprite;
|
||||
import platform.util.Vector;
|
||||
import platform.util.Output;
|
||||
import java.util.ArrayList;
|
||||
import platform.game.actor.*;
|
||||
import platform.game.signals.Signal;
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
|
||||
public class Activator extends Actor implements Signal {
|
||||
ArrayList<Keys> requiredKeys = new ArrayList<Keys>();
|
||||
ArrayList<Keys> activeKeys = new ArrayList<Keys>();
|
||||
Box box;
|
||||
String skin;
|
||||
int display;
|
||||
double displayTime = 1.0;
|
||||
|
||||
public Activator(Box box, String skin, Keys[] keys){
|
||||
setPriority(40);
|
||||
this.box = box;
|
||||
this.skin = skin;
|
||||
this.display = 0;
|
||||
for(Keys key : keys)
|
||||
requiredKeys.add(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return(requiredKeys.size()==0);
|
||||
}
|
||||
|
||||
public Box getBox(){
|
||||
return box;
|
||||
}
|
||||
|
||||
public void update(Input input){
|
||||
if(displayTime>=0.0){
|
||||
displayTime-=input.getDeltaTime();
|
||||
}else{
|
||||
displayTime = 1.0;
|
||||
if(display<requiredKeys.size()-1){
|
||||
++display;
|
||||
}else{
|
||||
display=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output){
|
||||
//if(!isActive()&&getSprite()==null){
|
||||
output.drawSprite(getSprite(), box,0,0.9);
|
||||
if(!isActive()){
|
||||
Keys current = requiredKeys.get(display);
|
||||
output.drawSprite(getSprite("particules/bubble"), new Box(box.getCenter(),0.5,0.5));
|
||||
output.drawSprite(getSprite(current.getText()), new Box(box.getCenter(),0.5,0.5));
|
||||
}
|
||||
}
|
||||
|
||||
public Sprite getSprite(){
|
||||
return getSprite(skin);
|
||||
}
|
||||
|
||||
public boolean isInteract(){
|
||||
if(this.isActive())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hurt(Actor instigator, Damage type, double amount, Vector location) {
|
||||
switch (type) {
|
||||
case ACTIVATION:
|
||||
if ( instigator.isPlayer()) {
|
||||
instigator.interact(this);
|
||||
for(Keys key : requiredKeys){
|
||||
display=0;
|
||||
if(((Player) instigator).hasKey(key)){
|
||||
activeKeys.add(key);
|
||||
((Player) instigator).removeKey(key);
|
||||
}
|
||||
|
||||
}for(Keys key : activeKeys){
|
||||
if(requiredKeys.indexOf(key)>=0)
|
||||
requiredKeys.remove(key);
|
||||
}
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
73
Permafrost/src/platform/game/actor/interactors/Exit.java
Normal file
73
Permafrost/src/platform/game/actor/interactors/Exit.java
Normal file
@@ -0,0 +1,73 @@
|
||||
package platform.game.actor.interactors;
|
||||
|
||||
import platform.game.actor.Actor;
|
||||
import platform.game.actor.Damage;
|
||||
import platform.game.signals.Signal;
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Exit extends Actor{
|
||||
private Vector position;
|
||||
private Signal signal = null;
|
||||
private boolean open = false;
|
||||
|
||||
public Exit(Vector position, double width, double height, Signal signal) {
|
||||
this.setPriority(35);
|
||||
this.position = position;
|
||||
this.signal = signal;
|
||||
}
|
||||
public Exit(Vector position,Signal signal) {
|
||||
this.setPriority(35);
|
||||
this.position = position;
|
||||
this.signal = signal;
|
||||
}
|
||||
|
||||
public Exit(Vector vect, boolean open) {
|
||||
this.setPriority(35);
|
||||
this.position = vect;
|
||||
this.open = open;
|
||||
}
|
||||
|
||||
public void update(Input input){
|
||||
if(!this.open && signal !=null){
|
||||
if(signal.isActive()){
|
||||
this.open=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output) {
|
||||
if(this.open)
|
||||
output.drawSprite(getSprite("door.open"), getBox());
|
||||
else
|
||||
output.drawSprite(getSprite("door.closed"), getBox());
|
||||
}
|
||||
|
||||
public Box getBox() {
|
||||
return new Box(position,1, 1);
|
||||
}
|
||||
|
||||
public boolean isInteract(){
|
||||
return open;
|
||||
}
|
||||
|
||||
public Vector getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hurt(Actor instigator, Damage type, double amount, Vector location) {
|
||||
switch (type) {
|
||||
case ACTIVATION:
|
||||
if(this.open){
|
||||
getWorld().nextLevel();
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
79
Permafrost/src/platform/game/actor/interactors/Key.java
Normal file
79
Permafrost/src/platform/game/actor/interactors/Key.java
Normal file
@@ -0,0 +1,79 @@
|
||||
package platform.game.actor.interactors;
|
||||
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
import platform.util.Sprite;
|
||||
import platform.util.Vector;
|
||||
import platform.game.actor.Actor;
|
||||
import platform.game.actor.Player;
|
||||
import platform.game.signals.*;
|
||||
|
||||
public class Key extends Actor implements Signal {
|
||||
private Vector position;
|
||||
private double width = 0.8;
|
||||
private double height = 0.8;
|
||||
private Keys key;
|
||||
private boolean taken = false;
|
||||
|
||||
public Key(Vector position, Keys key) {
|
||||
this.setPriority(45);
|
||||
this.position = position;
|
||||
this.key = key;
|
||||
}
|
||||
public Key(Vector position,double size, Keys key) {
|
||||
this.setPriority(45);
|
||||
this.position = position;
|
||||
this.key = key;
|
||||
this.width = size;
|
||||
this.height = size;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return taken;
|
||||
}
|
||||
|
||||
public Keys getId(){
|
||||
return key;
|
||||
}
|
||||
|
||||
public Sprite getSprite() {
|
||||
return getSprite(key.getText());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void update(Input input) {
|
||||
super.update(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interact(Actor other) {
|
||||
super.interact(other);
|
||||
Vector delta = other.getBox().getCollision(getBox());
|
||||
if (!taken && delta !=null) {
|
||||
if (other.isPlayer()) {
|
||||
((Player) other).addKey(key);
|
||||
taken = true;
|
||||
getWorld().unregister(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output) {
|
||||
if (!taken) {
|
||||
output.drawSprite(getSprite(), getBox());
|
||||
}
|
||||
}
|
||||
|
||||
public Box getBox() {
|
||||
return new Box(position, width, height);
|
||||
}
|
||||
|
||||
public Vector getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
}
|
||||
|
25
Permafrost/src/platform/game/actor/interactors/Keys.java
Normal file
25
Permafrost/src/platform/game/actor/interactors/Keys.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package platform.game.actor.interactors;
|
||||
|
||||
public enum Keys {
|
||||
RED("keys/key.red"), BLUE("keys/key.blue"),
|
||||
YELLOW("keys/key.yellow"), GREEN("keys/key.green"),
|
||||
GRED("keys/gem.red"), GBLUE("keys/gem.blue"),
|
||||
GYELLOW("keys/gem.yellow"), GGREEN("keys/gem.green"),
|
||||
COAL("keys/ore.coal"), DIAMOND("keys/ore.diamond"),
|
||||
EMERALD("keys/ore.emerald"), GOLD("keys/ore.gold"),
|
||||
IRON("keys/ore.iron"), RUBY("keys/ore.ruby"),
|
||||
SILVER("keys/ore.silver"), WOOD("keys/wood");
|
||||
|
||||
private String text;
|
||||
|
||||
Keys(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
|
||||
public String getText() {
|
||||
return this.text;
|
||||
}
|
||||
|
||||
}
|
||||
|
71
Permafrost/src/platform/game/actor/interactors/Lever.java
Normal file
71
Permafrost/src/platform/game/actor/interactors/Lever.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package platform.game.actor.interactors;
|
||||
|
||||
import platform.game.actor.Actor;
|
||||
import platform.game.actor.Damage;
|
||||
import platform.game.signals.*;
|
||||
import platform.util.Vector;
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
import platform.util.Sprite;
|
||||
|
||||
public class Lever extends Actor implements Signal{
|
||||
private boolean value = false;
|
||||
private double duration;
|
||||
private double time = 0;
|
||||
private Vector position;
|
||||
private double width = 0.5;
|
||||
private double height = 0.5;
|
||||
|
||||
public Lever(Vector position, double duration) {
|
||||
this.setPriority(22);
|
||||
//set duration to Double.POSITIVE_INFINITY to remove the timer functionality
|
||||
this.duration = duration;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Input input) {
|
||||
super.update(input);
|
||||
if (time > 0) {
|
||||
time -= input.getDeltaTime();
|
||||
} else if (time <= 0) {
|
||||
value = false;
|
||||
}
|
||||
}
|
||||
|
||||
public Sprite setSprite() {
|
||||
if (value) {
|
||||
return getSprite("lever.left");
|
||||
} else {
|
||||
return getSprite("lever.right");
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output) {
|
||||
output.drawSprite(setSprite(), getBox());
|
||||
}
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Box getBox() {
|
||||
return new Box(position, width, height);
|
||||
}
|
||||
public boolean isInteract(){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hurt(Actor instigator, Damage type, double amount, Vector location) {
|
||||
switch (type) {
|
||||
case ACTIVATION:
|
||||
value = !value;
|
||||
time = duration;
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
package platform.game.actor.interactors;
|
||||
|
||||
import platform.game.actor.Actor;
|
||||
import platform.game.signals.*;
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
import platform.util.Sprite;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class PressurePlate extends Actor implements Signal{
|
||||
private boolean value = false;
|
||||
private Vector position;
|
||||
private double width = 1;
|
||||
private double height = 0.1;
|
||||
|
||||
public PressurePlate(Vector position) {
|
||||
this.setPriority(52);
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preUpdate(Input input){
|
||||
value = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Input input) {
|
||||
super.update(input);
|
||||
|
||||
if (value) {
|
||||
height = 0.05;
|
||||
} else {
|
||||
height = 0.2;
|
||||
}
|
||||
}
|
||||
|
||||
public void interact(Actor other) {
|
||||
Vector delta = other.getBox().getCollision(getBox());
|
||||
if (delta!=null && other.isPlayer()) {
|
||||
value = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Sprite getSprite() {
|
||||
return getSprite("box.double");
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output) {
|
||||
output.drawSprite(getSprite(), getBox());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Box getBox() {
|
||||
return new Box(position, width, height);
|
||||
}
|
||||
|
||||
}
|
105
Permafrost/src/platform/game/actor/mob/BossBlob.java
Normal file
105
Permafrost/src/platform/game/actor/mob/BossBlob.java
Normal file
@@ -0,0 +1,105 @@
|
||||
package platform.game.actor.mob;
|
||||
|
||||
import platform.game.actor.Actor;
|
||||
import platform.game.actor.Damage;
|
||||
import platform.game.actor.Difficulty;
|
||||
import platform.game.actor.projectiles.Snowball;
|
||||
import platform.game.signals.Signal;
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
import platform.util.Sprite;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class BossBlob extends Mob {
|
||||
|
||||
private MobState state;
|
||||
private double stateCd;
|
||||
private Signal trigger;
|
||||
private double cooldown;
|
||||
private double mobCd;
|
||||
|
||||
public BossBlob(Vector position, Signal trigger) {
|
||||
super(position, 15.0, 3.5, 3.0);
|
||||
this.trigger = trigger;
|
||||
}
|
||||
|
||||
private Sprite getSprite() {
|
||||
if(super.getDirection()){
|
||||
return getSprite("creature/slime/boss.r");
|
||||
}else{
|
||||
return getSprite("creature/slime/boss.l");
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output){
|
||||
if(getWorld()!=null)
|
||||
output.drawSprite(getSprite(), getBox());
|
||||
}
|
||||
|
||||
|
||||
public void update(Input input) {
|
||||
super.update(input);
|
||||
double delta = input.getDeltaTime();
|
||||
if (getWorld().getDifficulty() == Difficulty.HARDCORE) {
|
||||
stateCd -= delta * 4;
|
||||
cooldown -= delta * 4;
|
||||
mobCd -= delta * 4;
|
||||
} else {
|
||||
stateCd -= delta;
|
||||
cooldown -= delta;
|
||||
mobCd -= delta;
|
||||
}
|
||||
|
||||
if(state!=MobState.FRENZY){
|
||||
if(trigger.isActive() ){
|
||||
state = MobState.AGGRESSIVE;
|
||||
}else{
|
||||
state = MobState.ROAMING;
|
||||
}
|
||||
}
|
||||
if(getHealth()<=3 && stateCd<=0.0){
|
||||
state = MobState.FRENZY;
|
||||
}
|
||||
|
||||
switch(state){
|
||||
case FRENZY:
|
||||
if(mobCd <=0.0){
|
||||
getWorld().register(new IceBlob(this.getPosition(), this.trigger));
|
||||
mobCd = 1.2 + Math.random();
|
||||
}
|
||||
if(cooldown<=0.0){
|
||||
getWorld().register(new Snowball(this.getPosition(),new Vector(getVelocity().getX()*3.5,1.0),this));
|
||||
cooldown = Math.random()/6.0+0.1;
|
||||
}
|
||||
super.setSpeed(7.0);
|
||||
break;
|
||||
case AGGRESSIVE:
|
||||
if(mobCd <=0.0){
|
||||
getWorld().register(new IceBlob(this.getPosition(), this.trigger));
|
||||
mobCd = 1.0 + Math.random() * 2;
|
||||
}
|
||||
if(cooldown<=0.0){
|
||||
getWorld().register(new Snowball(this.getPosition(),new Vector(getVelocity().getX()*3,1.0),this));
|
||||
cooldown = Math.random()/4.0+0.2;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hurt(Actor instigator, Damage type, double amount, Vector location) {
|
||||
switch (type) {
|
||||
case HEAT:
|
||||
if(amount<3){
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
return super.hurt(instigator, type, amount, location);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
95
Permafrost/src/platform/game/actor/mob/IceBlob.java
Normal file
95
Permafrost/src/platform/game/actor/mob/IceBlob.java
Normal file
@@ -0,0 +1,95 @@
|
||||
package platform.game.actor.mob;
|
||||
|
||||
import platform.game.actor.Actor;
|
||||
import platform.game.actor.Damage;
|
||||
import platform.game.actor.Difficulty;
|
||||
import platform.game.actor.projectiles.Snowball;
|
||||
import platform.game.signals.Signal;
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
import platform.util.Sprite;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class IceBlob extends Mob {
|
||||
|
||||
private MobState state;
|
||||
private double stateCd;
|
||||
private Signal trigger;
|
||||
private double cooldown;
|
||||
|
||||
public IceBlob(Vector position, Signal trigger) {
|
||||
super(position, 3.0, 0.6, 0.5);
|
||||
this.trigger = trigger;
|
||||
}
|
||||
|
||||
public void update(Input input) {
|
||||
super.update(input);
|
||||
double delta = input.getDeltaTime();
|
||||
if (getWorld().getDifficulty() == Difficulty.HARDCORE) {
|
||||
stateCd -= delta * 4;
|
||||
cooldown -= delta * 4;
|
||||
} else {
|
||||
stateCd -= delta;
|
||||
cooldown -= delta;
|
||||
}
|
||||
|
||||
if(state != MobState.FRENZY){
|
||||
if(trigger.isActive() ){
|
||||
state = MobState.AGGRESSIVE;
|
||||
}else{
|
||||
state = MobState.ROAMING;
|
||||
}
|
||||
}
|
||||
if(getHealth() <=1.0 && stateCd <= 0.0){
|
||||
state = MobState.FRENZY;
|
||||
}
|
||||
|
||||
switch(state){
|
||||
case FRENZY:
|
||||
super.setSize(1.2, 0.9);
|
||||
if(cooldown<=0.0){
|
||||
getWorld().register(new Snowball(this.getPosition(),new Vector(getVelocity().getX()*2,1.0),this));
|
||||
cooldown = Math.random()+0.5;
|
||||
}
|
||||
super.setSpeed(6.0);
|
||||
break;
|
||||
case AGGRESSIVE:
|
||||
if(cooldown<=0.0){
|
||||
getWorld().register(new Snowball(this.getPosition(),new Vector(getVelocity().getX()*3,1.0),this));
|
||||
cooldown = Math.random()*2.0+1.0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private Sprite getSprite() {
|
||||
if(super.getDirection()){
|
||||
return getSprite("creature/slime/mob.r");
|
||||
}else{
|
||||
return getSprite("creature/slime/mob.l");
|
||||
}
|
||||
}
|
||||
public void draw(Input input, Output output){
|
||||
if(getWorld()!=null)
|
||||
output.drawSprite(getSprite(), getBox());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hurt(Actor instigator, Damage type, double amount, Vector location) {
|
||||
switch (type) {
|
||||
case COLD:
|
||||
if(instigator.isPlayer()){
|
||||
state = MobState.ROAMING;
|
||||
super.setSize(0.6, 0.5);
|
||||
stateCd = 2.0;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
default:
|
||||
return super.hurt(instigator, type, amount, location);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
180
Permafrost/src/platform/game/actor/mob/Mob.java
Normal file
180
Permafrost/src/platform/game/actor/mob/Mob.java
Normal file
@@ -0,0 +1,180 @@
|
||||
package platform.game.actor.mob;
|
||||
|
||||
|
||||
|
||||
import platform.game.World;
|
||||
import platform.game.actor.Actor;
|
||||
import platform.game.actor.Damage;
|
||||
import platform.game.actor.Difficulty;
|
||||
import platform.game.actor.particle.PoufEffect;
|
||||
import platform.game.signals.Signal;
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Vector;
|
||||
|
||||
public abstract class Mob extends Actor implements Signal{
|
||||
private Vector position;
|
||||
private boolean dead = false;
|
||||
private double width=0.6;
|
||||
private double height=0.5;
|
||||
private double damageCd = 0.5;
|
||||
private double friction = 0.001;
|
||||
private double health;
|
||||
private double maxSpeed = 3.0;
|
||||
private Vector velocity = Vector.ZERO;
|
||||
private boolean grounding = false;
|
||||
|
||||
private boolean direction = true;//left = true , right = false
|
||||
|
||||
public Mob(Vector position, double health, double width, double height) {
|
||||
setPriority(43);
|
||||
this.position = position;
|
||||
this.health = health;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
}
|
||||
|
||||
public void preUpdate(Input input) {
|
||||
grounding = false;
|
||||
}
|
||||
|
||||
public void update(Input input) {
|
||||
double delta = input.getDeltaTime();
|
||||
damageCd -= delta;
|
||||
//MOVE
|
||||
if (direction) {
|
||||
if (velocity.getX() < maxSpeed) {
|
||||
double speed = 60.0 * delta;
|
||||
if (speed > maxSpeed)
|
||||
speed = maxSpeed;
|
||||
velocity = velocity.add(new Vector(speed*(1.0-friction), 0));
|
||||
}
|
||||
}
|
||||
else if(!direction){
|
||||
if (velocity.getX() > -maxSpeed) {
|
||||
double speed = 60.0 * delta;
|
||||
if (speed < -maxSpeed)
|
||||
speed = -maxSpeed;
|
||||
velocity = velocity.sub(new Vector(speed*(1.0-friction), 0));
|
||||
}
|
||||
}
|
||||
|
||||
//GRAVITY
|
||||
Vector acceleration = World.getGravity();
|
||||
velocity = velocity.add(acceleration.mul(delta));
|
||||
|
||||
//FRICTION
|
||||
if (grounding) {
|
||||
double scale = Math.pow(friction, delta);
|
||||
velocity = velocity.mul(scale);
|
||||
}
|
||||
|
||||
position = position.add(velocity.mul(delta));
|
||||
}
|
||||
|
||||
public void postUpdate(Input input) {
|
||||
if(health <= 0.0){
|
||||
getWorld().register(new PoufEffect(getBox(), 0.5));
|
||||
dead = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interact(Actor other) {
|
||||
super.interact(other);
|
||||
Vector delta = other.getBox().getCollision(getBox());
|
||||
if(delta!=null){
|
||||
if (other.isSolid()) {
|
||||
friction = other.getFriction();
|
||||
position = position.add(delta);
|
||||
if (delta.getX() != 0.0)
|
||||
velocity = new Vector(0.0, velocity.getY());
|
||||
if (delta.getY() != 0.0){
|
||||
velocity = new Vector(velocity.getX(), 0.0);
|
||||
}
|
||||
Vector offset = other.getBox().getCenter().sub(getBox().getCenter());
|
||||
if(Math.abs(offset.getX())<(other.getBox().getWidth()+width-0.001)/2.0 && offset.getY()<=other.getBox().getHeight()/2.0){
|
||||
grounding = true;
|
||||
}
|
||||
if(Math.abs(offset.getX())>=(other.getBox().getWidth()+width-0.001)/2.0)
|
||||
direction=!direction;
|
||||
|
||||
}
|
||||
if(other.isPlayer() && damageCd<0.0){
|
||||
other.hurt(this, Damage.COLD, 0.5, getPosition());
|
||||
damageCd=0.5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Box getBox() {
|
||||
if(!dead)
|
||||
return new Box(position, width, height);
|
||||
return Box.EMPTY;
|
||||
}
|
||||
|
||||
public Vector getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public Vector getVelocity(){
|
||||
return velocity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return dead;
|
||||
}
|
||||
|
||||
public boolean getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
public double getHealth(){
|
||||
return health;
|
||||
}
|
||||
|
||||
public void setSize(double width, double height){
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public void setSpeed(double speed){
|
||||
this.maxSpeed = speed;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hurt(Actor instigator, Damage type, double amount, Vector location) {
|
||||
|
||||
if (getWorld().getDifficulty() == Difficulty.HARDCORE)
|
||||
amount /= 2;
|
||||
|
||||
switch (type) {
|
||||
case FIRE:
|
||||
health -=amount;
|
||||
return true;
|
||||
case AIR:
|
||||
//velocity = velocity.add(location.mul(amount));
|
||||
return false;
|
||||
case VOID:
|
||||
health = -1.;
|
||||
return true;
|
||||
case HEAL:
|
||||
return false;
|
||||
case PHYSICAL:
|
||||
health -= amount;
|
||||
return true;
|
||||
case COLD:
|
||||
return false;
|
||||
case HEAT:
|
||||
this.health -= amount;
|
||||
return true;
|
||||
default:
|
||||
return super.hurt(instigator, type, amount, location);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
7
Permafrost/src/platform/game/actor/mob/MobState.java
Normal file
7
Permafrost/src/platform/game/actor/mob/MobState.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package platform.game.actor.mob;
|
||||
|
||||
public enum MobState {
|
||||
SPAWN,IDLE(), ROAMING, AGGRESSIVE, FRENZY, FRIENDLY;
|
||||
|
||||
|
||||
}
|
92
Permafrost/src/platform/game/actor/particle/Particle.java
Normal file
92
Permafrost/src/platform/game/actor/particle/Particle.java
Normal file
@@ -0,0 +1,92 @@
|
||||
package platform.game.actor.particle;
|
||||
|
||||
import platform.util.Vector;
|
||||
import platform.game.actor.Actor;
|
||||
import platform.util.Box;
|
||||
import platform.util.Sprite;
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
|
||||
public class Particle extends Actor {
|
||||
private Vector position;
|
||||
private double width;
|
||||
private double height;
|
||||
private String skin;
|
||||
private double duration;
|
||||
private boolean moving;
|
||||
private Vector speed;
|
||||
private double angle;
|
||||
|
||||
|
||||
public Particle(Vector position, double width, double height, double duration, String name, boolean moving, Vector speed) {
|
||||
setPriority(10);
|
||||
this.position = position;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.duration = duration;
|
||||
this.skin = name;
|
||||
this.moving = moving;
|
||||
this.speed = speed;
|
||||
this.angle = speed.getAngle()+Math.PI/2.0;
|
||||
}
|
||||
|
||||
public Particle() {
|
||||
super();
|
||||
setPriority(10);
|
||||
}
|
||||
|
||||
public void Move() {
|
||||
moving = true;
|
||||
}
|
||||
|
||||
public boolean isMoving() {
|
||||
return moving;
|
||||
}
|
||||
|
||||
public void setSpeed(Vector speed) {
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Input input) {
|
||||
super.update(input);
|
||||
double delta = input.getDeltaTime();
|
||||
duration -= delta;
|
||||
if (moving) {
|
||||
this.position = position.add(speed.mul(delta));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postUpdate(Input input) {
|
||||
if (duration < 0.0 && getWorld()!=null) {
|
||||
getWorld().unregister(this);
|
||||
}
|
||||
}
|
||||
|
||||
public String setSprite(String name) {
|
||||
skin = name;
|
||||
return skin;
|
||||
}
|
||||
|
||||
public void setPosition(Vector position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public void setDuration(double duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
public Box getBox() {
|
||||
return new Box(position, width, height);
|
||||
}
|
||||
|
||||
public Sprite getSprite() {
|
||||
return getSprite(skin);
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output) {
|
||||
if(getWorld()!=null)
|
||||
output.drawSprite(getSprite(), getBox(),angle);
|
||||
}
|
||||
}
|
51
Permafrost/src/platform/game/actor/particle/PoufEffect.java
Normal file
51
Permafrost/src/platform/game/actor/particle/PoufEffect.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package platform.game.actor.particle;
|
||||
|
||||
import platform.game.actor.Actor;
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Sprite;
|
||||
import platform.util.Output;
|
||||
|
||||
public class PoufEffect extends Actor{
|
||||
|
||||
private Box box;
|
||||
private double cooldown;
|
||||
|
||||
public PoufEffect(Box box, double cooldown) {
|
||||
this.setPriority(99);
|
||||
this.cooldown = cooldown;
|
||||
this.box = box;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Box getBox() {
|
||||
return box;
|
||||
}
|
||||
|
||||
public void update(Input input){
|
||||
double delta = input.getDeltaTime();
|
||||
cooldown-=delta;
|
||||
}
|
||||
|
||||
public void postUpdate(Input input) {
|
||||
if(cooldown<=0.0){
|
||||
getWorld().unregister(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output) {
|
||||
if(getWorld()!=null)
|
||||
output.drawSprite(getSprite(), getBox());
|
||||
}
|
||||
|
||||
public Sprite getSprite() {
|
||||
if (cooldown >= 0.25) {
|
||||
return getSprite("particules/smoke/gray.1");
|
||||
} else if (cooldown >= 0.1) {
|
||||
return getSprite("particules/smoke/gray.2");
|
||||
} else{
|
||||
return getSprite("particules/smoke/gray.3");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
47
Permafrost/src/platform/game/actor/projectiles/Arrow.java
Normal file
47
Permafrost/src/platform/game/actor/projectiles/Arrow.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package platform.game.actor.projectiles;
|
||||
|
||||
import platform.game.actor.Actor;
|
||||
import platform.game.actor.Damage;
|
||||
import platform.game.actor.StuckItem;
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Arrow extends Projectile {
|
||||
private boolean hit = false;
|
||||
private double height = 0.25;
|
||||
private double width = 0.42;
|
||||
|
||||
public Arrow(Vector position, Vector velocity,Actor owner) {
|
||||
super(position,velocity,owner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Box getBox() {
|
||||
return new Box(getPosition(), width, height);
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output) {
|
||||
if(getWorld() != null && !hit)
|
||||
output.drawSprite(getSprite("arrow"), getBox());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interact(Actor other) {
|
||||
super.interact(other);
|
||||
Vector delta = getBox().getCenter().sub(other.getBox().getCenter());
|
||||
if (!hit && other.getBox().isColliding(getBox())) {
|
||||
if ((other.isSolid()&&other!=getOwner()) || other.hurt(this, Damage.PHYSICAL, 3.0, getPosition())) {
|
||||
getWorld().register(new StuckItem (delta, other, 0.15, 0.70, "arrow"));
|
||||
hit = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void postUpdate() {
|
||||
if (hit) {
|
||||
getWorld().unregister(this);
|
||||
}
|
||||
}
|
||||
}
|
60
Permafrost/src/platform/game/actor/projectiles/Fireball.java
Normal file
60
Permafrost/src/platform/game/actor/projectiles/Fireball.java
Normal file
@@ -0,0 +1,60 @@
|
||||
package platform.game.actor.projectiles;
|
||||
|
||||
import platform.util.Output;
|
||||
import platform.game.actor.Actor;
|
||||
import platform.game.actor.Damage;
|
||||
import platform.game.actor.particle.PoufEffect;
|
||||
import platform.util.Input;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Fireball extends Projectile {
|
||||
|
||||
private String skin = "fireball";
|
||||
private int jumps = 5;
|
||||
|
||||
public Fireball(Vector position, Vector velocity, Actor owner) {
|
||||
super(position, velocity, owner);
|
||||
|
||||
}
|
||||
|
||||
public void postUpdate(Input input){
|
||||
if(jumps<=0){
|
||||
getWorld().register(new PoufEffect(this.getBox(),0.40));
|
||||
getWorld().unregister(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output) {
|
||||
if(getWorld()!=null)
|
||||
output.drawSprite(getSprite(skin), getBox(), (-20) * input.getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interact(Actor other) {
|
||||
super.interact(other);
|
||||
Vector delta = other.getBox().getCollision(getPosition());
|
||||
if (delta != null) {
|
||||
if (other.isSolid()) {
|
||||
--jumps;
|
||||
setPosition(getPosition().add(delta));
|
||||
setVelocity(getVelocity().mirrored(delta));
|
||||
}
|
||||
if (other!=getOwner() && other.hurt(this, Damage.FIRE, 1.0, getPosition())) {
|
||||
jumps = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public boolean hurt(Actor instigator, Damage type, double amount, Vector location) {
|
||||
switch (type) {
|
||||
case AIR:
|
||||
jumps = 0;
|
||||
return true;
|
||||
default:
|
||||
return super.hurt(instigator, type, amount, location);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,57 @@
|
||||
package platform.game.actor.projectiles;
|
||||
|
||||
import platform.game.World;
|
||||
import platform.game.actor.Actor;
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Projectile extends Actor {
|
||||
private Vector position;
|
||||
private Vector velocity;
|
||||
private Actor owner;
|
||||
|
||||
public Projectile(Vector position, Vector velocity, Actor owner){
|
||||
this.setPriority(666);
|
||||
this.position = position;
|
||||
this.velocity = velocity;
|
||||
this.owner = owner;
|
||||
|
||||
if (position == null || velocity == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
}
|
||||
|
||||
public void update(Input input) {
|
||||
super.update(input);
|
||||
double delta = input.getDeltaTime();
|
||||
Vector acceleration = World.getGravity();
|
||||
velocity = velocity.add(acceleration.mul(delta));
|
||||
position = position.add(velocity.mul(delta));
|
||||
}
|
||||
|
||||
public Vector getPosition(){
|
||||
return position;
|
||||
}
|
||||
public void setPosition(Vector position){
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public Vector getVelocity(){
|
||||
return velocity;
|
||||
}
|
||||
public void setVelocity(Vector velocity){
|
||||
this.velocity = velocity;
|
||||
}
|
||||
|
||||
public Actor getOwner(){
|
||||
return owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Box getBox() {
|
||||
double SIZE = 0.42;
|
||||
return new Box(position, SIZE, SIZE);
|
||||
}
|
||||
|
||||
}
|
68
Permafrost/src/platform/game/actor/projectiles/Snowball.java
Normal file
68
Permafrost/src/platform/game/actor/projectiles/Snowball.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package platform.game.actor.projectiles;
|
||||
|
||||
import platform.util.Output;
|
||||
import platform.game.actor.Actor;
|
||||
import platform.game.actor.Damage;
|
||||
import platform.game.actor.particle.Particle;
|
||||
import platform.game.actor.particle.PoufEffect;
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Snowball extends Projectile {
|
||||
|
||||
|
||||
private String skin = "particules/snowball/1";
|
||||
private int jumps = 1;
|
||||
|
||||
public Snowball(Vector position, Vector velocity, Actor owner) {
|
||||
super(position, velocity, owner);
|
||||
|
||||
}
|
||||
|
||||
public Box getBox(){
|
||||
return new Box(getPosition(),1,1);
|
||||
}
|
||||
|
||||
|
||||
public void postUpdate(Input input){
|
||||
if(jumps<=0){
|
||||
getWorld().unregister(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Input input, Output output) {
|
||||
if(getWorld()!=null)
|
||||
output.drawSprite(getSprite(skin), getBox(), 20 * input.getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interact(Actor other) {
|
||||
super.interact(other);
|
||||
Vector delta = other.getBox().getCollision(getPosition());
|
||||
if (delta != null) {
|
||||
if (other.isSolid()) {
|
||||
setPosition(getPosition().add(delta));
|
||||
getWorld().register(new Particle(this.getPosition(), 1, 1, 10, "particules/snowball/1", false, Vector.ZERO));
|
||||
jumps=0;
|
||||
}
|
||||
if (other!=getOwner() && other.hurt(this, Damage.COLD, 1.0, getPosition())){
|
||||
getWorld().register(new PoufEffect(this.getBox(),0.40));
|
||||
jumps=0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public boolean hurt(Actor instigator, Damage type, double amount, Vector location) {
|
||||
switch (type) {
|
||||
case HEAT:
|
||||
jumps = 0;
|
||||
return true;
|
||||
default:
|
||||
return super.hurt(instigator, type, amount, location);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
38
Permafrost/src/platform/game/actor/zone/EffectArea.java
Normal file
38
Permafrost/src/platform/game/actor/zone/EffectArea.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package platform.game.actor.zone;
|
||||
|
||||
import platform.game.actor.Damage;
|
||||
import platform.game.actor.Torch;
|
||||
import platform.game.signals.Signal;
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
|
||||
public class EffectArea extends Zone {
|
||||
private Damage type;
|
||||
private double amount;
|
||||
private Signal signal;
|
||||
private double cooldown = 1.0;
|
||||
|
||||
|
||||
public EffectArea(Box box, Damage type, double amount, Signal signal) {
|
||||
super(box);
|
||||
this.type = type;
|
||||
this.amount = amount;
|
||||
this.signal = signal;
|
||||
}
|
||||
|
||||
public EffectArea(Torch torch) {
|
||||
super(new Box(torch.getPosition(),3,3));
|
||||
this.type = Damage.HEAT;
|
||||
this.amount = 0.5;
|
||||
this.signal = torch;
|
||||
}
|
||||
|
||||
public void update(Input input){
|
||||
cooldown-=input.getDeltaTime();
|
||||
if(signal.isActive() && cooldown <=0.0){
|
||||
getWorld().hurt(getBox(), this, type, amount, getPosition());
|
||||
cooldown = 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
33
Permafrost/src/platform/game/actor/zone/Trigger.java
Normal file
33
Permafrost/src/platform/game/actor/zone/Trigger.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package platform.game.actor.zone;
|
||||
|
||||
import platform.game.actor.Actor;
|
||||
import platform.game.signals.Signal;
|
||||
import platform.util.Box;
|
||||
import platform.util.Input;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Trigger extends Zone implements Signal {
|
||||
private boolean active = false;
|
||||
|
||||
public Trigger(Box box){
|
||||
super(box);
|
||||
}
|
||||
|
||||
public void preUpdate(Input input){
|
||||
active = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
public void interact(Actor other) {
|
||||
super.interact(other);
|
||||
Vector delta = other.getBox().getCollision(super.getBox());
|
||||
if(delta!=null && other.isPlayer()){
|
||||
active = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
23
Permafrost/src/platform/game/actor/zone/Zone.java
Normal file
23
Permafrost/src/platform/game/actor/zone/Zone.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package platform.game.actor.zone;
|
||||
|
||||
import platform.game.actor.Actor;
|
||||
import platform.util.Box;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Zone extends Actor {
|
||||
private Box box;
|
||||
|
||||
public Zone(Box box) {
|
||||
setPriority(56);
|
||||
this.box = box;
|
||||
}
|
||||
|
||||
public Box getBox() {
|
||||
return box;
|
||||
}
|
||||
|
||||
public Vector getPosition(){
|
||||
return box.getCenter();
|
||||
}
|
||||
|
||||
}
|
68
Permafrost/src/platform/game/level/BasicInteract.java
Normal file
68
Permafrost/src/platform/game/level/BasicInteract.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package platform.game.level;
|
||||
|
||||
import platform.game.World;
|
||||
import platform.game.actor.*;
|
||||
import platform.game.actor.block.*;
|
||||
import platform.game.actor.interactors.Activator;
|
||||
import platform.game.actor.interactors.Exit;
|
||||
import platform.game.actor.interactors.Key;
|
||||
import platform.game.actor.interactors.Keys;
|
||||
import platform.game.actor.interactors.Lever;
|
||||
import platform.game.signals.*;
|
||||
import platform.util.Box;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class BasicInteract extends Level{
|
||||
@Override
|
||||
public void register(World world) {
|
||||
super.register(world);
|
||||
world.setNextLevel(new InterLevel(Levels.MENU));
|
||||
|
||||
Player player = new Player(new Vector(1,1),new Vector(0.0,10.0));
|
||||
world.register(player);
|
||||
world.register(new Overlay(player));
|
||||
|
||||
Key ki = new Key(new Vector(-4, 4), Keys.BLUE);
|
||||
Key ki2 = new Key(new Vector(-5, 7), Keys.YELLOW);
|
||||
Key ki3 = new Key(new Vector(-13, 4), Keys.RED);
|
||||
Lever lev1 = new Lever(new Vector(-15, 3.25), 3);
|
||||
world.register(new SnowStorm(new Vector(-14, 4),2.0 , 3.0, new Vector(0.5,0)));
|
||||
Lever lev = new Lever(new Vector(-4, 3.3), 3);
|
||||
Mover mov = new Mover(new Vector(-5, 5), new Vector(-5, 9), 2, 1, "stone.2");
|
||||
|
||||
world.register(new Exit(new Vector(6,2),lev1));
|
||||
world.register(new Mover(new Vector(-6, 2.5),new Vector(-9.5, 2.5), 3, 1, "stone.2"));
|
||||
world.register(new Block (new Vector(-8, 1.5), 8, 1, "stone.2"));
|
||||
Keys keys[] = {Keys.RED,Keys.YELLOW,Keys.BLUE};
|
||||
Activator keydoor = new Activator(new Box(new Vector(3,2),1,1), "stone.2", keys );
|
||||
world.register(mov);
|
||||
world.register(lev);
|
||||
world.register(lev1);
|
||||
world.register(new Block (Vector.ZERO, 5, 2, "stone.2"));
|
||||
world.register(new Block (new Vector(4.5, 0.5), 4, 2, "stone.2"));
|
||||
world.register(new Trap (new Vector(-16, 4),lev1, "stone.2"));
|
||||
world.register(new Block (new Vector(-15, 2), 8, 2, "stone.2"));
|
||||
world.register(new Block (new Vector(-3.5, 1), 2, 4, "stone.8"));
|
||||
world.register(new Spike(new Vector(-0.2,1.25), 1));
|
||||
world.register(new Jumper(new Vector(-1.5, 1.5), 1, 1));
|
||||
world.register(new Torch(new Vector(2,2), false));
|
||||
world.register(new Tree(new Vector(1,2)));
|
||||
world.register(new Heart(new Vector(-3, 4)));
|
||||
world.register(ki);
|
||||
world.register(ki2);
|
||||
world.register(ki3);
|
||||
world.register(keydoor);
|
||||
world.register(lev);
|
||||
//world.register(new Key(new Vector(6, 2),2));
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
world.register(new Door(new Vector(4, 2 + i),new Or(new And(ki,lev),keydoor),true));
|
||||
}
|
||||
for (int i = 1; i < 5; ++i) {
|
||||
world.register(new Door(new Vector(4 + i, 6),new Or(new And(ki,lev),keydoor),true));
|
||||
}
|
||||
|
||||
//world.register(new Door(new Vector(-5, 4),2,true));
|
||||
|
||||
world.register(new Limits(Vector.ZERO, 50, 50));
|
||||
}
|
||||
}
|
97
Permafrost/src/platform/game/level/BasicLevel.java
Normal file
97
Permafrost/src/platform/game/level/BasicLevel.java
Normal file
@@ -0,0 +1,97 @@
|
||||
package platform.game.level;
|
||||
|
||||
import platform.game.World;
|
||||
import platform.game.actor.*;
|
||||
import platform.game.actor.block.*;
|
||||
import platform.game.actor.interactors.Exit;
|
||||
import platform.game.actor.interactors.Key;
|
||||
import platform.game.actor.interactors.Keys;
|
||||
import platform.game.actor.interactors.PressurePlate;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class BasicLevel extends Level {
|
||||
// UNCOMMENT ME WHEN NEEDED
|
||||
@Override
|
||||
public void register(World world) {
|
||||
super.register(world);
|
||||
|
||||
// Register a new instance, to restart level automatically
|
||||
world.setNextLevel(new InterLevel(Levels.MENU));
|
||||
|
||||
// Create blocks
|
||||
// world.register(new Block(new Box(new Vector(0, 0), 4, 2), world.getLoader().getSprite("stone.broken.2")));
|
||||
//world.register(new Block(new Box(new Vector(-1.5, 1.5), 1, 1), world.getLoader().getSprite("stone.broken.1")));
|
||||
|
||||
|
||||
Player player = new Player(new Vector(0,0),new Vector(0.0,10.0));
|
||||
|
||||
world.register(player);
|
||||
world.register(new Overlay(player));
|
||||
world.register(new Destruct(new Vector(0, -4)));
|
||||
world.register(new Jumper(new Vector(15, -9), 1, 1));
|
||||
world.register(new Jumper(new Vector(10, -4), 1, 1));
|
||||
world.register(new Block(new Vector(0.0, 1.0),8 ,1,"box.empty"));
|
||||
world.register(new Exit(new Vector(7,-4),true));
|
||||
world.register(new Destruct(new Vector(5, -4)));
|
||||
world.register(new Destruct(new Vector(5, -3)));
|
||||
world.register(new Destruct(new Vector(5, -2)));
|
||||
world.register(new Destruct(new Vector(5, -1)));
|
||||
world.register(new Destruct(new Vector(6, -1)));
|
||||
world.register(new Destruct(new Vector(7, -1)));
|
||||
world.register(new Destruct(new Vector(7, 0)));
|
||||
world.register(new Destruct(new Vector(6, 0)));
|
||||
world.register(new Destruct(new Vector(5, 0)));
|
||||
world.register(new Destruct(new Vector(4, 0)));
|
||||
world.register(new Destruct(new Vector(3, 0)));
|
||||
world.register(new Destruct(new Vector(2, 0)));
|
||||
world.register(new Destruct(new Vector(1, 0)));
|
||||
world.register(new Destruct(new Vector(0, -1)));
|
||||
world.register(new Destruct(new Vector(-1, 0)));
|
||||
world.register(new Destruct(new Vector(-2, 0)));
|
||||
world.register(new Destruct(new Vector(-3, 0)));
|
||||
world.register(new Destruct(new Vector(-4, 0)));
|
||||
world.register(new Destruct(new Vector(-5, 0)));
|
||||
world.register(new Destruct(new Vector(-6, 0)));
|
||||
world.register(new Destruct(new Vector(-7, -1)));
|
||||
world.register(new Destruct(new Vector(-7, -2)));
|
||||
world.register(new Destruct(new Vector(-7, -3)));
|
||||
world.register(new Destruct(new Vector(-7, -4)));
|
||||
world.register(new Destruct(new Vector(-6, -4)));
|
||||
PressurePlate plat = (new PressurePlate(new Vector(5,-4.5)));
|
||||
world.register(plat);
|
||||
world.register(new Door(new Vector(6, -4),plat,true));
|
||||
world.register(new Block(new Vector (0, -5), 25, 1, "box.empty"));
|
||||
world.register(new Block(new Vector(-8, -0.5),1 ,10,"box.empty"));
|
||||
world.register(new Block(new Vector(8, -0.5),1 ,10,"box.empty"));
|
||||
world.register(new Block(new Vector(-7, -2), 1, 1, "box.empty"));
|
||||
world.register(new Block(new Vector(7, -2), 1, 1, "box.empty"));
|
||||
world.register(new Block(new Vector(-10, 6.5), 1, 1, "box.empty"));
|
||||
world.register(new Block(new Vector(-14, 9), 2, 1, "stone.2"));
|
||||
world.register(new Block(new Vector(-10, 11.5), 1, 1, "box.empty"));
|
||||
world.register(new Block(new Vector(-3, 10), 1, 1, "box.empty"));
|
||||
world.register(new Block(new Vector(3, 10), 3, 1, "stone.3"));
|
||||
world.register(new Block(new Vector(8, 10), 2, 1, "box.empty"));
|
||||
world.register(new Block(new Vector(12, 13), 1, 1, "box.empty"));
|
||||
world.register(new Block(new Vector(8, 15), 1, 1, "box.empty"));
|
||||
world.register(new Block(new Vector(5, 17), 1, 1, "box.empty"));
|
||||
world.register(new Block(new Vector(3, 19), 1, 1, "box.empty"));
|
||||
world.register(new Block(new Vector(1, 21), 1, 1, "box.empty"));
|
||||
world.register(new Block(new Vector(6, 23), 1, 1, "box.empty"));
|
||||
world.register(new Ladder(new Vector(9, 27), 1, 4));
|
||||
world.register(new Block(new Vector(11, 28), 1, 1, "box.empty"));
|
||||
world.register(new Jumper(new Vector(11, 29), 1, 1));
|
||||
world.register(new Block(new Vector(5, 30), 1, 1, "box.empty"));
|
||||
Key ki = new Key(new Vector(-4, 29), Keys.GREEN);
|
||||
world.register(ki);
|
||||
world.register(new Block(new Vector(-3, 27), 3, 1, "stone.3"));
|
||||
world.register(new Block(new Vector(-14, 22), 15, 1, "stone.3"));
|
||||
world.register(new Exit(new Vector(-21,23),true));
|
||||
world.register(new Door(new Vector(-19, 23),ki));
|
||||
world.register(new Block(new Vector(0.0, -10), 45, 1, "box.empty"));
|
||||
world.register(new Block(new Vector(0, 40), 45, 1, "box.empty"));
|
||||
world.register(new Block(new Vector(-22, 15), 1, 50, "box.empty"));
|
||||
world.register(new Block(new Vector(22, 15), 1, 50, "box.empty"));
|
||||
|
||||
}
|
||||
|
||||
}
|
39
Permafrost/src/platform/game/level/BoxLevel.java
Normal file
39
Permafrost/src/platform/game/level/BoxLevel.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package platform.game.level;
|
||||
|
||||
import platform.game.World;
|
||||
import platform.game.actor.*;
|
||||
import platform.game.actor.block.*;
|
||||
import platform.game.actor.zone.EffectArea;
|
||||
import platform.game.signals.Constant;
|
||||
import platform.util.Box;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class BoxLevel extends Level {
|
||||
// UNCOMMENT ME WHEN NEEDED
|
||||
@Override
|
||||
public void register(World world) {
|
||||
super.register(world);
|
||||
|
||||
// Register a new instance, to restart level automatically
|
||||
world.setNextLevel(new InterLevel(Levels.MENU));
|
||||
|
||||
Player player = new Player(new Vector(0,0),new Vector(0.0,0.0));
|
||||
|
||||
world.register(player);
|
||||
world.register(new Overlay(player));
|
||||
final int SIZE = 15;
|
||||
for(int i=-SIZE; i<=SIZE;++i){
|
||||
for(int j=-SIZE; j<=SIZE;++j){
|
||||
if(i!=0 || j !=0)
|
||||
world.register(new Destruct(new Vector(i, j)));
|
||||
}
|
||||
}
|
||||
world.register(new EffectArea(new Box(Vector.ZERO,SIZE*2,SIZE*2), Damage.HEAT, 3, new Constant(true)));
|
||||
world.register(new EffectArea(new Box(Vector.ZERO,SIZE*2,SIZE*2), Damage.HEAL, 1, new Constant(true)));
|
||||
|
||||
world.register(new Limits(Vector.ZERO, 40, 40));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
100
Permafrost/src/platform/game/level/Cave1.java
Normal file
100
Permafrost/src/platform/game/level/Cave1.java
Normal file
@@ -0,0 +1,100 @@
|
||||
package platform.game.level;
|
||||
|
||||
import platform.game.World;
|
||||
import platform.game.actor.*;
|
||||
import platform.game.actor.interactors.*;
|
||||
import platform.game.signals.*;
|
||||
import platform.game.actor.block.Material;
|
||||
import platform.game.actor.block.Mover;
|
||||
import platform.game.actor.block.Terrain;
|
||||
import platform.game.actor.Spike;
|
||||
import platform.game.actor.Torch;
|
||||
import platform.util.Box;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Cave1 extends Level {
|
||||
|
||||
@Override
|
||||
public void register(World world) {
|
||||
super.register(world);
|
||||
world.setNextLevel(new InterLevel(Levels.CAVE2));
|
||||
|
||||
Player player = new Player(new Vector(-24.0,1.0),new Vector(0.0,3.0));
|
||||
world.register(player);
|
||||
world.register(new Overlay(player));
|
||||
|
||||
world.register(new Chrono());
|
||||
world.register(new Terrain(new Box(new Vector (-26.5, -4.0),3 ,32.0),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-23.0, -5.5), 6, 11),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-13.5, 3.0), 9, 14),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-19.0, -9.0), 2, 4),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-13.5, -10.0), 9, 2),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-8.0, -15.0), 8, 2),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-6.5, -19.0), 11, 2),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-17.5, -17.5), 5, 5),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-22.5, -19.0), 5, 2),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (20.5, -15.0), 7, 2),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (25.5, -9.0), 3, 14),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (22.0, -10.5), 2, 1),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (20.0, -6.5), 2, 1),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (18.0, -2.0), 2, 20),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (24.0, -1.5), 6, 1),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-7.0, -5.0), 2, 14),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-1.0, 3.0), 2, 6),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-4.0, 1.0), 8, 2),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (3.0, 13.5), 2, 1),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (5.5, 15.5), 1, 1),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (8, 12.5), 2, 1),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (11.5, 11.5), 1, 1),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (15.0, 8.5), 2, 1),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (17.5, 10.5), 1, 1),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (20.0, 11.5), 2, 1),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (18.0, 15.5), 2, 1),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (15.5, 16.5), 1, 1),Material.STONE));
|
||||
|
||||
world.register(new Spike(new Vector (-17.5, -8.75), 9));
|
||||
world.register(new Spike(new Vector (-24.5, -17.75), 5));
|
||||
|
||||
Lever lev1 = new Lever(new Vector(-18.5, -6.75), Double.POSITIVE_INFINITY);
|
||||
Lever lev2 = new Lever(new Vector(-1.5, -17.75), Double.POSITIVE_INFINITY);
|
||||
world.register(lev1);
|
||||
world.register(lev2);
|
||||
|
||||
Key key1 = new Key(new Vector(5.5, 16.5), Keys.RED);
|
||||
Key key2 = new Key(new Vector(15.5, 17.5), Keys.BLUE);
|
||||
Keys[] keys1 = {Keys.BLUE, Keys.RED};
|
||||
world.register(key1);
|
||||
world.register(key2);
|
||||
|
||||
Torch tor1 = new Torch(new Vector(-17.5, -14.0));
|
||||
Torch tor2 = new Torch(new Vector(9.0, -13.0));
|
||||
world.register(tor1);
|
||||
world.register(tor2);
|
||||
|
||||
Activator activ = new Activator(new Box(new Vector (25.0,-0.6), 0.8, 0.8), "box.empty", keys1);
|
||||
world.register(activ);
|
||||
|
||||
world.register(new Mover(new Vector(-17.0, -7.5), new Vector(-10.0, -7.5), 2, 1,"stone.2", lev1));
|
||||
world.register(new Mover(new Vector(0.0, -18.5), new Vector(7.0, -18.5), 2, 1,"stone.2", lev2));
|
||||
world.register(new Mover(new Vector(-13.5, -19.0), new Vector(-13.5, -16.0), 1, 1,"stone.1", tor1));
|
||||
world.register(new Mover(new Vector(16.0, -14.5), new Vector(11.0, -14.5), 2, 1,"stone.2", tor2));
|
||||
world.register(new Mover(new Vector(9.0, -18.5), new Vector(9.0, -14.5), 2, 1,"stone.2"));
|
||||
|
||||
world.register(new Jumper(new Vector (23.5, -13.60), 0.8, 0.8));
|
||||
world.register(new Jumper(new Vector (22.0, -9.60), 0.8, 0.8));
|
||||
world.register(new Jumper(new Vector (19.5, -5.60), 0.8, 0.8));
|
||||
world.register(new Jumper(new Vector (-2.5, 2.4), 0.8, 0.8));
|
||||
world.register(new Jumper(new Vector (20.0, 12.4), 0.8, 0.8));
|
||||
|
||||
world.register(new SnowStorm(new Vector (1.0, 7.5), 2, 12, new Vector(0.0,0.5)));
|
||||
world.register(new SnowStorm(new Vector (9.5, 0.0), 16, 6, new Vector(0.0,0.5)));
|
||||
|
||||
world.register(new Ladder(new Vector(-8.5, -6.0), 1, 16));
|
||||
world.register(new Ladder(new Vector(19.5, 3.0), 1, 10));
|
||||
|
||||
world.register(new Exit(new Vector(-24.0, 0.5), false));
|
||||
world.register(new Exit(new Vector(26.0, -0.5), new Or(new And(tor1, tor2), activ)));
|
||||
world.register(new Background(new Box(new Vector(-0.5, 1.0), 56, 43), "terrain/bg/cave"));
|
||||
world.register(new Limits(new Vector(-0.5, 1.0), 56, 43));
|
||||
}
|
||||
}
|
130
Permafrost/src/platform/game/level/Cave2.java
Normal file
130
Permafrost/src/platform/game/level/Cave2.java
Normal file
@@ -0,0 +1,130 @@
|
||||
package platform.game.level;
|
||||
|
||||
import platform.game.World;
|
||||
import platform.game.actor.*;
|
||||
import platform.game.actor.interactors.*;
|
||||
import platform.game.actor.mob.IceBlob;
|
||||
import platform.game.actor.mob.Mob;
|
||||
import platform.game.actor.zone.EffectArea;
|
||||
import platform.game.actor.zone.Trigger;
|
||||
import platform.game.actor.block.*;
|
||||
import platform.util.Box;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Cave2 extends Level{
|
||||
|
||||
@Override
|
||||
public void register(World world) {
|
||||
super.register(world);
|
||||
world.setNextLevel(new InterLevel(Levels.CAVE3));
|
||||
|
||||
Player player = new Player(new Vector(-18.5,1.0),new Vector(0.0,3.0));
|
||||
world.register(player);
|
||||
world.register(new Overlay(player));
|
||||
|
||||
world.register(new Chrono());
|
||||
world.register(new Terrain(new Box(new Vector (-24.0, 4.0),2 ,12),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-20.5, -4.5),9 ,9),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-13.0, -7.5),6 ,3),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (10.0, 5.0),2 ,28.0),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (6.0, -7.5),8 ,3.0),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-1.0, -8.5),18 ,1.0),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (4.5, 15.5),7 ,1.0),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (6.0, 9.0),8 ,2.0),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (4.0, 3.0),6 ,2.0),Material.STONE));
|
||||
|
||||
world.register(new Destruct(new Vector(-21.5, 4.5)));
|
||||
for (int i = 0; i < 7; ++i)
|
||||
for(int j = i; j < 7; ++j)
|
||||
world.register(new Destruct(new Vector(-20.5 + j, 4.5 + i)));
|
||||
for (int i = 0; i < 3; ++i)
|
||||
for(int j = i; j < 3; ++j)
|
||||
world.register(new Destruct(new Vector(-13.5 + j, 8.5 + i)));
|
||||
for (int i = 0; i < 4; ++i)
|
||||
world.register(new Destruct(new Vector(-13.5 + i, 4.5)));
|
||||
for (int i = 0; i < 4; ++i)
|
||||
world.register(new Destruct(new Vector(-10.5 + i, 15.5)));
|
||||
for (int i = 0; i < 3; ++i)
|
||||
world.register(new Destruct(new Vector(5.5, 16.5 + i)));
|
||||
for (int i = 0; i < 3; ++i)
|
||||
world.register(new Destruct(new Vector(3.5, -5.5 + i)));
|
||||
|
||||
world.register(new Jumper(new Vector (-22.5, 0.4), 0.8, 0.8));
|
||||
world.register(new Jumper(new Vector (-11.5, 11.4), 0.8, 0.8));
|
||||
world.register(new SnowStorm(new Vector(-8.0, 8.0), 4, 8, new Vector(0.0, 0.5)));
|
||||
|
||||
Key key1 = new Key(new Vector(-11.5, 5.5), Keys.RED);
|
||||
Key key2 = new Key(new Vector(6.5, 16.5), Keys.YELLOW);
|
||||
Key key3 = new Key(new Vector(-13.5, 9.5), Keys.BLUE);
|
||||
Key key4 = new Key(new Vector(4.5, -5.5), Keys.GREEN);
|
||||
Keys[] keys1 = {Keys.RED, Keys.YELLOW};
|
||||
Keys[] keys2 = {Keys.BLUE};
|
||||
Keys[] keys3 = {Keys.GREEN};
|
||||
world.register(key1);
|
||||
world.register(key2);
|
||||
world.register(key3);
|
||||
world.register(key4);
|
||||
|
||||
Torch tor1 = new Torch(new Vector(-11.5 ,-4.5));
|
||||
Torch tor2 = new Torch(new Vector(-9.5, 17.0));
|
||||
Torch tor3 = new Torch(new Vector(-17.5, 1.5), true);
|
||||
Torch tor4 = new Torch(new Vector(4.5, 17.5), true);
|
||||
world.register(new EffectArea(new Box(new Vector(-11.5 ,-4.5),3,3), Damage.HEAT, 0.5, tor1));
|
||||
world.register(new EffectArea(new Box(new Vector(-9.5, 17.0),3,3), Damage.HEAT, 0.5, tor2));
|
||||
world.register(new EffectArea(new Box(new Vector(-17.5, 1.5),3,3), Damage.HEAT, 0.5, tor3));
|
||||
world.register(new EffectArea(new Box(new Vector(4.5, 17.5),3,3), Damage.HEAT, 0.5, tor4));
|
||||
world.register(tor1);
|
||||
world.register(tor2);
|
||||
world.register(tor3);
|
||||
world.register(tor4);
|
||||
|
||||
|
||||
world.register(new Ladder(new Vector(-15.5, -3.0), 1, 6));
|
||||
world.register(new Ladder(new Vector(8.5, 13.0), 1, 6));
|
||||
world.register(new Ladder(new Vector(1.5, 7.0), 1, 6));
|
||||
world.register(new Ladder(new Vector(7.5, 2.5), 1, 3));
|
||||
|
||||
world.register(new Mover(new Vector(-9.0, -6.5), new Vector(1.0, -6.5), 2, 1,"stone.2", tor1));
|
||||
world.register(new Mover(new Vector(0.0, 15.5), new Vector(-6.0, 15.5), 2, 1,"stone.2", tor2));
|
||||
world.register(new Spike(new Vector(-9.5, -7.75), 12));
|
||||
|
||||
Activator activ1 = new Activator(new Box(new Vector(5.5, -5.6), 0.8, 0.8),"box.empty", keys1);
|
||||
Activator activ2 = new Activator(new Box(new Vector(-13.5, 5.4), 0.8, 0.8),"box.empty", keys2);
|
||||
Activator activ3 = new Activator(new Box(new Vector(-20.5, 0.4), 0.8, 0.8),"box.empty", keys3);
|
||||
world.register(activ1);
|
||||
world.register(activ2);
|
||||
world.register(activ3);
|
||||
|
||||
Trigger trig1 = new Trigger(new Box(new Vector(5,6),8,4));
|
||||
Trigger trig2 = new Trigger(new Box(new Vector(5,12),8,4));
|
||||
world.register(trig1);
|
||||
world.register(trig2);
|
||||
|
||||
Mob mob1 = new IceBlob(new Vector(5.0,4.5), trig1);
|
||||
Mob mob2 = new IceBlob(new Vector(5.0,10.5), trig2);
|
||||
world.register(mob1);
|
||||
world.register(mob2);
|
||||
|
||||
for(int i = 0; i < 4; ++i)
|
||||
world.register(new Door(new Vector(7.5, 4.5 + i), mob1, false));
|
||||
for(int i = 0; i < 4; ++i)
|
||||
world.register(new Door(new Vector(0.5, 4.5 + i), mob1, false));
|
||||
for(int i = 0; i < 4; ++i)
|
||||
world.register(new Door(new Vector(1.5, 10.5 + i), mob2, false));
|
||||
world.register(new Door(new Vector(8.5, -3.5), activ1, false));
|
||||
world.register(new Door(new Vector(7.5, -3.5), activ1, false));
|
||||
world.register(new Door(new Vector(6.5, -3.5), activ1, false));
|
||||
world.register(new Door(new Vector(6.5, -4.5), activ1, false));
|
||||
world.register(new Door(new Vector(6.5, -5.5), activ1, false));
|
||||
world.register(new Door(new Vector(-10.5, 5.5), activ2, false));
|
||||
world.register(new Door(new Vector(-11.5, 6.5), activ2, false));
|
||||
world.register(new Door(new Vector(-12.5, 5.5), activ2, false));
|
||||
world.register(new Door(new Vector(-21.5, 0.5), activ3, false));
|
||||
world.register(new Door(new Vector(-22.5, 1.5), activ3, false));
|
||||
|
||||
world.register(new Exit(new Vector(-18.5,0.5), false));
|
||||
world.register(new Exit(new Vector(8.5,-5.5), activ1));
|
||||
world.register(new Background(new Box(new Vector(-7.0, 5.0), 36, 29), "terrain/bg/cave"));
|
||||
world.register(new Limits(new Vector(-7.0, 5.0), 36, 29));
|
||||
}
|
||||
}
|
136
Permafrost/src/platform/game/level/Cave3.java
Normal file
136
Permafrost/src/platform/game/level/Cave3.java
Normal file
@@ -0,0 +1,136 @@
|
||||
package platform.game.level;
|
||||
|
||||
import platform.game.World;
|
||||
import platform.game.actor.*;
|
||||
import platform.game.actor.block.*;
|
||||
import platform.game.actor.interactors.*;
|
||||
import platform.game.actor.mob.IceBlob;
|
||||
import platform.game.actor.zone.EffectArea;
|
||||
import platform.game.signals.And;
|
||||
import platform.game.signals.Constant;
|
||||
import platform.util.Box;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Cave3 extends Level {
|
||||
|
||||
@Override
|
||||
public void register(World world) {
|
||||
super.register(world);
|
||||
world.setNextLevel(new InterLevel(Levels.CAVEEND));
|
||||
|
||||
Player player = new Player(new Vector(0.5, 0.5),new Vector(0.0,3.0));
|
||||
world.register(player);
|
||||
world.register(new Overlay(player));
|
||||
|
||||
world.register(new Chrono());
|
||||
world.register(new Terrain(new Box(new Vector (1.0, -1.0),24 ,2.0),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (12.5, 11.0),1 ,24.0),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (6.5, 20.5),17 ,1),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-7.5, 23.0),1 ,6),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (6.0, 25.0),28 ,2),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (2.0, 25.5),38 ,1),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (10.0, 26.0),20 ,2),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (11.5, 27.0),5 ,2),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (15.5, 28.0),3 ,4),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-16.5, 26.5),1 ,3),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (10.5, 7.5),1 ,1),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (3.5, 7.0),1 ,6),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-2.5, 6.0),1 ,4),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (2.0, 4.5),10 ,1),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (0.5, 9.5),7 ,1),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-5.0, 7.5),6 ,1),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-7.5, 10.0),1 ,6),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-9.0, 12.5),2 ,1),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-15.0, 9.5),4 ,1),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-19.0, 7.5),2 ,1),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-16.5, -1.0),5 ,2),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-18.5, 1.0),1 ,4),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-14.5, 2.0),1 ,2),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-17.5, 3.5),1 ,1),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-15.5, 3.5),1 ,1),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-16.5, 4.5),1 ,1),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (2.0, -12.5),6 ,1),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (7.0, 24.0),2 ,2),Material.STONE));
|
||||
|
||||
world.register(new Tree (new Vector(4.5, 28.0)));
|
||||
world.register(new Heart(new Vector(-7.5, 6.5)));
|
||||
world.register(new Spike(new Vector(5.5, 21.25), 1));
|
||||
world.register(new Trap(new Vector(7.5, 22.5), new Constant(true), "stone.1"));
|
||||
world.register(new IceBlob(new Vector(9.5, 28.5), new Constant(false)));
|
||||
|
||||
world.register(new Ladder(new Vector(11.5, 4.0), 1, 8));
|
||||
world.register(new Ladder(new Vector(4.5, 7.5), 1, 5));
|
||||
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
world.register(new Destruct(new Vector(-6.5 + i, 20.5)));
|
||||
world.register(new Destruct(new Vector(-13.5, 10.5 + i)));
|
||||
}
|
||||
|
||||
world.register(new Jumper(new Vector(-6.5, 8.4), 0.8, 0.8));
|
||||
world.register(new Jumper(new Vector(2.5, 21.4), 0.8, 0.8));
|
||||
world.register(new Jumper(new Vector(-1.5, 5.4), 0.8, 0.8));
|
||||
|
||||
world.register(new SnowStorm(new Vector(-7.5, -10.0), 3, 6, new Vector(0.0, 0.8)));
|
||||
world.register(new SnowStorm(new Vector(-12.5, -7.0), 3, 6, new Vector(0.0, 0.8)));
|
||||
world.register(new SnowStorm(new Vector(-2.5, -12.5), 3, 3, new Vector(0.0, 1.0)));
|
||||
world.register(new SnowStorm(new Vector(16.5, 9.5), 1, 25, new Vector(0.0, 0.5)));
|
||||
world.register(new SnowStorm(new Vector(-4.5, 16.5), 5, 1, new Vector(0.0, 0.5)));
|
||||
//world.register(new SnowStorm(new Vector(1.5, 23.5), 5, 1, new Vector(0.5, 0.0)));
|
||||
|
||||
Torch tor1 = new Torch(new Vector(4.5, 1.5));
|
||||
Torch tor2 = new Torch(new Vector(-16.5, 1.5));
|
||||
Torch tor3 = new Torch(new Vector(1.5, 6.5));
|
||||
Torch tor4 = new Torch(new Vector(-6.5, 22.5));
|
||||
Torch tor5 = new Torch(new Vector(3.5, -10.5));
|
||||
Torch tor6 = new Torch(new Vector(-16.5, 11.5));
|
||||
And allTor = new And (tor1,new And(tor2,new And(tor3, new And(tor4, new And(tor5, tor6)))));
|
||||
world.register(new EffectArea(tor1));
|
||||
world.register(new EffectArea(tor2));
|
||||
world.register(new EffectArea(tor3));
|
||||
world.register(new EffectArea(tor4));
|
||||
world.register(new EffectArea(tor5));
|
||||
world.register(new EffectArea(tor6));
|
||||
world.register(tor1);
|
||||
world.register(tor2);
|
||||
world.register(tor3);
|
||||
world.register(tor4);
|
||||
world.register(tor5);
|
||||
world.register(tor6);
|
||||
|
||||
Lever lev1 = new Lever(new Vector(-17.5, 0.25), Double.POSITIVE_INFINITY);
|
||||
Lever lev2 = new Lever(new Vector(3.5, -11.75), Double.POSITIVE_INFINITY);
|
||||
world.register(lev1);
|
||||
world.register(lev2);
|
||||
|
||||
Key key1 = new Key(new Vector(-4.5, 21.5), Keys.YELLOW);
|
||||
Key key2 = new Key(new Vector(-15.5, 10.5), Keys.RED);
|
||||
Key key3 = new Key(new Vector(1.5, -11.5), Keys.BLUE);
|
||||
Keys[] keys1 = {Keys.YELLOW};
|
||||
Keys[] keys2 = {Keys.RED};
|
||||
Keys[] keys3 = {Keys.BLUE};
|
||||
world.register(key1);
|
||||
world.register(key2);
|
||||
world.register(key3);
|
||||
|
||||
Activator activ1 = new Activator(new Box(new Vector(-3.5, 8.4), 0.8, 0.8), "box.empty", keys1);
|
||||
Activator activ2 = new Activator(new Box(new Vector(-10.5, 0.4), 0.8, 0.8), "box.empty", keys2);
|
||||
Activator activ3 = new Activator(new Box(new Vector(8.5, 21.4), 0.8, 0.8), "box.empty", keys3);
|
||||
world.register(activ1);
|
||||
world.register(activ2);
|
||||
world.register(activ3);
|
||||
|
||||
world.register(new Mover(new Vector(-7.5, 4.5), new Vector(-12.5, -0.5), 3, 1, "stone.2", lev1));
|
||||
world.register(new Mover(new Vector(6.5, -12.5), new Vector(16.5, -3.5), 3, 1, "stone.2", lev2));
|
||||
|
||||
world.register(new Door(new Vector(-2.5, 8.5), activ1));
|
||||
world.register(new Door(new Vector(-14.5, 0.5), activ2));
|
||||
world.register(new Door(new Vector(7.5, 21.5), activ3));
|
||||
|
||||
world.register(new Exit(new Vector(0.5, 0.5), false));
|
||||
world.register(new Exit(new Vector(0.5, 5.5), allTor));
|
||||
|
||||
world.register(new Background(new Box(new Vector(0.0, 6.0), 40, 40), "terrain/bg/cave"));
|
||||
world.register(new Background(new Box(new Vector(0.0, 28.0), 40, 4), "terrain/bg/sky"));
|
||||
world.register(new Limits(new Vector(0.0, 8.0), 40, 44));
|
||||
}
|
||||
}
|
141
Permafrost/src/platform/game/level/CaveEnd.java
Normal file
141
Permafrost/src/platform/game/level/CaveEnd.java
Normal file
@@ -0,0 +1,141 @@
|
||||
package platform.game.level;
|
||||
|
||||
import platform.game.World;
|
||||
import platform.game.actor.*;
|
||||
import platform.game.actor.block.*;
|
||||
import platform.game.actor.interactors.*;
|
||||
import platform.game.actor.mob.BossBlob;
|
||||
import platform.game.actor.mob.Mob;
|
||||
import platform.game.actor.zone.EffectArea;
|
||||
import platform.game.actor.zone.Trigger;
|
||||
import platform.game.signals.And;
|
||||
import platform.game.signals.Constant;
|
||||
import platform.util.Box;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class CaveEnd extends Level {
|
||||
|
||||
@Override
|
||||
public void register(World world) {
|
||||
super.register(world);
|
||||
world.setNextLevel(new InterLevel(Levels.HAPPYEND));
|
||||
|
||||
Player player = new Player(new Vector(-24.5, 2.5),new Vector(0.0,3.0));
|
||||
world.register(player);
|
||||
world.register(new Overlay(player));
|
||||
world.register(new Chrono());
|
||||
world.register(new Terrain(new Box(new Vector (-26.0, 1.0),6 ,2.0),Material.SNOWS));
|
||||
world.register(new Terrain(new Box(new Vector (-21.0, 13.5),2 ,1.0),Material.SNOWS));
|
||||
world.register(new Terrain(new Box(new Vector (-1.0, 19.5),4 ,1.0),Material.SNOWS));
|
||||
world.register(new Terrain(new Box(new Vector (-2.0, 14.5),2 ,1.0),Material.SNOWS));
|
||||
world.register(new Terrain(new Box(new Vector (2.0, 13.5),2 ,1.0),Material.SNOWS));
|
||||
world.register(new Terrain(new Box(new Vector (5.0, 11.5),2 ,1.0),Material.SNOWS));
|
||||
world.register(new Terrain(new Box(new Vector (16.0, 11.5),4 ,1.0),Material.SNOWS));
|
||||
world.register(new Terrain(new Box(new Vector (16.0, 6.0),8 ,2.0),Material.SNOWS));
|
||||
world.register(new Terrain(new Box(new Vector (22.0, -4.0),2.0 ,6.0),Material.ICE));
|
||||
world.register(new Terrain(new Box(new Vector (-1.5, -2.0),43 ,2.0),Material.ICE));
|
||||
world.register(new Terrain(new Box(new Vector (-22.0, -8.0),2 ,14.0),Material.ICE));
|
||||
world.register(new Terrain(new Box(new Vector (-15.0, -14.0),12 ,2.0),Material.ICE));
|
||||
world.register(new Terrain(new Box(new Vector (-8.0, -12.0),2 ,6.0),Material.ICE));
|
||||
world.register(new Terrain(new Box(new Vector (3.0, -10.0),24 ,2.0),Material.ICE));
|
||||
world.register(new Terrain(new Box(new Vector (16.0, -8.0),2 ,6.0),Material.ICE));
|
||||
world.register(new Terrain(new Box(new Vector (18.0, -6.0),6 ,2.0),Material.ICE));
|
||||
|
||||
world.register(new Ladder(new Vector(-21.5, 18.0),1, 8));
|
||||
world.register(new Ladder(new Vector(-11.0, 21.5),20, 1));
|
||||
world.register(new Ladder(new Vector(3.5,10.5),1, 3));
|
||||
world.register(new Ladder(new Vector(5.0,9.5),2, 1));
|
||||
world.register(new Ladder(new Vector(6.5,10.5),1, 3));
|
||||
world.register(new Ladder(new Vector(20.5,1.0),1, 12));
|
||||
world.register(new Ladder(new Vector(-9.5,-11.0),1, 4));
|
||||
|
||||
for(int i = 0; i < 6; ++i)
|
||||
world.register(new Destruct(new Vector(-14.5 + i, 10.5)));
|
||||
for(int i = 0; i < 5; ++i)
|
||||
world.register(new Destruct(new Vector(-20.5 + i, 17.5)));
|
||||
|
||||
//for(int i = 0; i < 3; ++i)
|
||||
//world.register(new Trap(new Vector(-6.5, 1.5 + i), new Constant(true), "stone.1"));
|
||||
world.register(new Spike(new Vector(-22.5, -0.75), 42));
|
||||
|
||||
world.register(new SnowStorm(new Vector(-16.0, 5.0), 2, 10, new Vector(0.0, 1.0)));
|
||||
world.register(new SnowStorm(new Vector(-15.0, 0.5), 16, 4, new Vector(0.0, 1.0)));
|
||||
world.register(new SnowStorm(new Vector(-12.5, 16.0), 6, 3, new Vector(0.0, 1.0)));
|
||||
world.register(new SnowStorm(new Vector(5.0, 6.0), 2, 4, new Vector(0.0, 1.0)));
|
||||
world.register(new SnowStorm(new Vector(9.0, 6.0), 6, 4, new Vector(0.5, 1.0)));
|
||||
|
||||
world.register(new Jumper(new Vector(13.0, 7.4), 0.8, 0.8));
|
||||
world.register(new Jumper(new Vector(19.0, 7.4), 0.8, 0.8));
|
||||
|
||||
Torch tor1 = new Torch(new Vector(-11.5, 12.5));
|
||||
Torch tor2 = new Torch(new Vector(4.5, 18.5));
|
||||
Torch tor3 = new Torch(new Vector(16.0, 13.5));
|
||||
Torch tor4 = new Torch(new Vector(18.5, -3.5));
|
||||
Torch tor5 = new Torch(new Vector(11.5, -7.5));
|
||||
Torch tor6 = new Torch(new Vector(5.0, -7.5));
|
||||
Torch tor7 = new Torch(new Vector(-1.0, -7.5));
|
||||
world.register(new EffectArea(tor1));
|
||||
world.register(new EffectArea(tor2));
|
||||
world.register(new EffectArea(tor3));
|
||||
world.register(new EffectArea(tor4));
|
||||
world.register(new EffectArea(tor5));
|
||||
world.register(new EffectArea(tor6));
|
||||
world.register(new EffectArea(tor7));
|
||||
And tors = new And(tor5, new And(tor6, tor7));
|
||||
world.register(tor1);
|
||||
world.register(tor2);
|
||||
world.register(tor3);
|
||||
world.register(tor4);
|
||||
world.register(tor5);
|
||||
world.register(tor6);
|
||||
world.register(tor7);
|
||||
|
||||
world.register(new Heart(new Vector(-19.5, 15.0)));
|
||||
world.register(new Heart(new Vector(19.0, 20.0)));
|
||||
world.register(new Heart(new Vector(8.5, -8.0)));
|
||||
world.register(new Heart(new Vector(2.0, -8.0)));
|
||||
|
||||
Key key1 = new Key(new Vector(5.0, 10.5), Keys.RED);
|
||||
Key key2 = new Key(new Vector(13.0, 20.0), Keys.BLUE);
|
||||
Key rune = new Key(new Vector(-16.0, -11.0),4, Keys.GBLUE);
|
||||
Keys[] keys = {Keys.RED, Keys.BLUE};
|
||||
world.register(key1);
|
||||
world.register(key2);
|
||||
world.register(rune);
|
||||
|
||||
Trigger trig1 = new Trigger(new Box(new Vector(3.0,-6.0),24,6));
|
||||
world.register(trig1);
|
||||
|
||||
Mob boss = new BossBlob(new Vector(-6.0,-8.5), trig1);
|
||||
world.register(boss);
|
||||
|
||||
Lever lev1 = new Lever(new Vector(-19.5, 18.25), Double.POSITIVE_INFINITY);
|
||||
world.register(lev1);
|
||||
|
||||
Activator activ = new Activator(new Box(new Vector(16.5, -4.5), 0.8, 0.8), "box.empty", keys);
|
||||
world.register(activ);
|
||||
|
||||
world.register(new Mover(new Vector(-7.5, 10.5), new Vector(-7.5, 17.5), 3, 1, "stone.3", tor1));
|
||||
world.register(new Mover(new Vector(2.0, 19.5), new Vector(2.0, 15.5), 2, 1, "stone.2", tor2));
|
||||
world.register(new Mover(new Vector(13.0, 11.5), new Vector(13.0, 18.5), 2, 1, "stone.2", tor3));
|
||||
world.register(new Mover(new Vector(19.0, 11.5), new Vector(19.0, 18.5), 2, 1, "stone.2", tor3));
|
||||
|
||||
for(int i = 0; i < 2; ++i)
|
||||
world.register(new Door(new Vector(15.5, -4.5 + i), activ));
|
||||
for(int i = 0; i < 3; ++i)
|
||||
world.register(new Door(new Vector(-20.5, 18.5 + i), lev1));
|
||||
for(int i = 0; i < 5; ++i)
|
||||
world.register(new Door(new Vector(-3.5, -8.5 + i), tors));
|
||||
for (int i = 0; i < 4; ++i)
|
||||
world.register(new Door(new Vector(-9.5, -8.5 + i), boss));
|
||||
|
||||
world.register(new Exit(new Vector(-24.5, 2.5), false));
|
||||
world.register(new Exit(new Vector(-20.0, -12.5), rune));
|
||||
|
||||
world.register(new Cloud(new Vector(-15.0,-3.5), 10, 1, 0.6));
|
||||
world.register(new EffectArea(new Box(new Vector(-15.0, -8.0),10,10), Damage.COLD, 0.05, new Constant(true)));
|
||||
|
||||
world.register(new Background(new Box(new Vector(-3.0, 4.5), 52, 39), "terrain/bg/cave"));
|
||||
world.register(new Limits(new Vector(-3.0, 4.5), 52, 39));
|
||||
}
|
||||
}
|
126
Permafrost/src/platform/game/level/Dream.java
Normal file
126
Permafrost/src/platform/game/level/Dream.java
Normal file
@@ -0,0 +1,126 @@
|
||||
package platform.game.level;
|
||||
|
||||
import platform.game.World;
|
||||
import platform.game.actor.Overlay;
|
||||
import platform.game.actor.Player;
|
||||
import platform.game.actor.GUI.Text;
|
||||
import platform.game.actor.block.Material;
|
||||
import platform.game.actor.block.Terrain;
|
||||
import platform.game.signals.*;
|
||||
import platform.util.Box;
|
||||
import platform.util.Vector;
|
||||
import platform.game.actor.*;
|
||||
import platform.game.actor.block.*;
|
||||
import platform.game.actor.interactors.*;
|
||||
import platform.game.actor.mob.IceBlob;
|
||||
import platform.game.actor.mob.Mob;
|
||||
import platform.game.actor.zone.EffectArea;
|
||||
import platform.game.actor.zone.Trigger;
|
||||
|
||||
public class Dream extends Level{
|
||||
|
||||
@Override
|
||||
public void register(World world) {
|
||||
super.register(world);
|
||||
world.setNextLevel(new InterLevel(Levels.OUTSIDE1));
|
||||
|
||||
world.setView(new Vector(1.0, 6.0), 15);
|
||||
|
||||
Player player = new Player(new Vector(-26.0,1.0),new Vector(0.0,3.0));
|
||||
world.register(player);
|
||||
world.register(new Overlay(player));
|
||||
world.register(new Chrono());
|
||||
world.register(new Terrain(new Box(new Vector (-27.0, 4.0), 2, 12),Material.GRASS));
|
||||
world.register(new Terrain(new Box(new Vector (-23.5, 0.0), 1, 2),Material.GRASS));
|
||||
world.register(new Terrain(new Box(new Vector (-22.5, 0.0), 1, 4),Material.GRASS));
|
||||
world.register(new Terrain(new Box(new Vector (-21.5, 0.0), 1, 2),Material.GRASS));
|
||||
world.register(new Terrain(new Box(new Vector (-20.5, 2.0), 1, 8),Material.GRASS));
|
||||
world.register(new Terrain(new Box(new Vector (-19.0, 0.0), 2, 2),Material.GRASS));
|
||||
world.register(new Terrain(new Box(new Vector (-17.0, 0.0), 2, 4),Material.GRASS));
|
||||
world.register(new Terrain(new Box(new Vector (-22.0, -1.0), 12, 2),Material.GRASS));
|
||||
world.register(new Terrain(new Box(new Vector (-13.0, 0.0), 2, 4),Material.GRASS));
|
||||
world.register(new Terrain(new Box(new Vector (-8.0, 2.0), 4, 8),Material.GRASS));
|
||||
world.register(new Terrain(new Box(new Vector (-3.0, 8.0), 2, 10),Material.GRASS));
|
||||
world.register(new Terrain(new Box(new Vector (2.0, 5.5), 8, 5),Material.GRASS));
|
||||
world.register(new Terrain(new Box(new Vector (2.0, 5.5), 8, 5),Material.GRASS));
|
||||
world.register(new Terrain(new Box(new Vector (29.0, 1.0), 2, 6),Material.GRASS));
|
||||
world.register(new Terrain(new Box(new Vector (14.0, 7.0), 20, 2),Material.GRASS));
|
||||
world.register(new Terrain(new Box(new Vector (23.0, 5.0), 2, 6),Material.GRASS));
|
||||
world.register(new Terrain(new Box(new Vector (26.0, 3.0), 4, 2),Material.GRASS));
|
||||
world.register(new Terrain(new Box(new Vector (7.0, -1.0), 2, 2),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (9.0, -0.5), 2, 3),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (11.0, 1.0), 2, 6),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (10.0, 3.5), 4, 1),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (21.0, -1.0), 18, 2),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-4.0, -1.0), 4, 2),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-1.0, -0.5), 2, 3),Material.STONE));
|
||||
|
||||
world.register(new Jumper(new Vector (-21.5, 1.5), 1, 1));
|
||||
world.register(new Spike(new Vector (-19.5, 1.2), 2.0));
|
||||
world.register(new SnowStorm(new Vector(-11.0, 2.0), 2, 8, new Vector(0.0, 0.3)));
|
||||
|
||||
Torch tor1 = new Torch(new Vector(-3.5, 1.5));
|
||||
Torch tor2 = new Torch(new Vector(20.5, 1.5));
|
||||
world.register(new EffectArea(tor1));
|
||||
world.register(new EffectArea(tor2));
|
||||
world.register(tor1);
|
||||
world.register(tor2);
|
||||
|
||||
Lever lev1 = new Lever(new Vector(9.0, 1.25), 3.0);
|
||||
world.register(lev1);
|
||||
|
||||
Key key1 = new Key(new Vector (-17.5, 2.5), Keys.RED);
|
||||
Keys[] keys = {Keys.RED};
|
||||
world.register(key1);
|
||||
|
||||
Activator acti = new Activator(new Box(new Vector(-7.0,6.5),1,1), "box.empty", keys);
|
||||
world.register(acti);
|
||||
|
||||
Trigger trig1 = new Trigger(new Box(new Vector(18,4),8,8));
|
||||
world.register(trig1);
|
||||
|
||||
Mob mob1 = new IceBlob(new Vector(20.0,5.0), trig1);
|
||||
Mob mob2 = new IceBlob(new Vector(19.0,5.0), trig1);
|
||||
Mob mob3 = new IceBlob(new Vector(17.0,5.0), trig1);
|
||||
world.register(mob1);
|
||||
world.register(mob2);
|
||||
world.register(mob3);
|
||||
And mobAnd = new And(new And(mob1,mob2),mob3);
|
||||
|
||||
world.register(new Door(new Vector (-5.5, 5.5), acti,false));
|
||||
world.register(new Door(new Vector (-4.5, 5.5), acti,false));
|
||||
world.register(new Door(new Vector (22.5, 0.5),mobAnd, false));
|
||||
world.register(new Door(new Vector (22.5, 1.5),mobAnd, false));
|
||||
|
||||
world.register(new Mover(new Vector (1.0, 0.5), new Vector (7.0, 0.5),2,1,"stone.2", tor1));
|
||||
world.register(new Mover(new Vector (7.0, 0.5), new Vector (7.0, 3.5),2,1,"stone.2", lev1));
|
||||
|
||||
world.register(new Exit(new Vector (27.0, 0.5),true));
|
||||
world.register(new Background(new Box(new Vector(1.0, 6.0),58.0,16.0), "terrain/bg/dream"));
|
||||
world.register(new Limits(new Vector(1.0, 6.0), 58.0, 16.0));
|
||||
|
||||
//HELP
|
||||
world.register(new Text(new Vector(-20.0,0.0), 0.3, "Press 'up' to jump"));
|
||||
world.register(new Text(new Vector(-21.0,-0.8), 0.3, "The jumper throws you into the air"));
|
||||
world.register(new Text(new Vector(-17.5,7.6), 0.3, "Ouch those spikes"));
|
||||
world.register(new Text(new Vector(-17.5,7.0), 0.3, "look painfull"));
|
||||
world.register(new Text(new Vector(-17.0,4.0), 0.3, "Pick up the key"));
|
||||
world.register(new Text(new Vector(-15.0,3.0), 0.3, "Dodge the hole"));
|
||||
world.register(new Text(new Vector(-7.2,8.0), 0.3, "Use the key to continue"));
|
||||
world.register(new Text(new Vector(1,7.0), 0.3, "Press space to light the torch"));
|
||||
world.register(new Text(new Vector(1,6.4), 0.3, "Shooting fireballs drains vigor"));
|
||||
world.register(new Text(new Vector(1,5.8), 0.3, "then drains your life"));
|
||||
world.register(new Text(new Vector(1,5.2), 0.3, "up to 2 hearts"));
|
||||
world.register(new Text(new Vector(1,4.6), 0.3, "then you shoot snowballs"));
|
||||
world.register(new Text(new Vector(1,4.0), 0.3, "snowballs calm IceBlobs"));
|
||||
world.register(new Text(new Vector(1,3.4), 0.3,"and turn out torches"));
|
||||
world.register(new Text(new Vector(13,7.4), 0.3, "Kill the IceBlobs with your fireballs"));
|
||||
world.register(new Text(new Vector(13,6.8), 0.3, "A lit torch also hurts them"));
|
||||
world.register(new Text(new Vector(13,6.2), 0.3, "go close to a lit torch to regen your vigor"));
|
||||
|
||||
world.register(new Text(new Vector(26,3.4), 0.3, "Now go and"));
|
||||
world.register(new Text(new Vector(26,2.8), 0.3, "find your lost worm"));
|
||||
}
|
||||
|
||||
|
||||
}
|
27
Permafrost/src/platform/game/level/GameOver.java
Normal file
27
Permafrost/src/platform/game/level/GameOver.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package platform.game.level;
|
||||
|
||||
import platform.game.World;
|
||||
import platform.game.actor.Cloud;
|
||||
import platform.game.actor.GUI.Cursor;
|
||||
import platform.game.actor.GUI.SelectLevel;
|
||||
import platform.game.actor.GUI.Text;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class GameOver extends Level{
|
||||
|
||||
public void register(World world) {
|
||||
|
||||
super.register(world);
|
||||
world.setView(Vector.ZERO, 11);
|
||||
|
||||
// Register a new instance, to restart level automatically
|
||||
world.setNextLevel(new Menu());
|
||||
|
||||
Cursor cursor = new Cursor();
|
||||
// Create Button & text
|
||||
world.register(cursor);
|
||||
world.register(new Cloud(new Vector(0,15), 80, 3, 1.0));
|
||||
world.register(new Text(new Vector(0,2), 1.2, "Game Over"));
|
||||
world.register(new SelectLevel(new Vector(-7,-7),1,"Main Menu",cursor, new Menu()));
|
||||
}
|
||||
}
|
41
Permafrost/src/platform/game/level/HappyEnd.java
Normal file
41
Permafrost/src/platform/game/level/HappyEnd.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package platform.game.level;
|
||||
|
||||
import platform.game.World;
|
||||
import platform.game.actor.block.Material;
|
||||
import platform.game.actor.block.Terrain;
|
||||
import platform.util.Box;
|
||||
import platform.util.Vector;
|
||||
import platform.game.actor.*;
|
||||
import platform.game.actor.block.*;
|
||||
import platform.game.actor.interactors.*;
|
||||
|
||||
public class HappyEnd extends Level{
|
||||
|
||||
@Override
|
||||
public void register(World world) {
|
||||
super.register(world);
|
||||
world.setNextLevel(new InterLevel(Levels.END));
|
||||
world.setView(Vector.ZERO, 6);
|
||||
|
||||
world.register(new Player(new Vector(-4,-1),true));
|
||||
world.register(new Exit(new Vector(-4,-1.5), false));
|
||||
|
||||
Worm worm = new Worm(new Vector(6,-1.6));
|
||||
world.register(worm);
|
||||
|
||||
world.register(new Cloud(new Vector(0,6), 12, 1, 0.2));
|
||||
world.register(new Portal(new Vector(4.5,-1.5),worm));
|
||||
world.register(new Tree(new Vector(5.5,-1)));
|
||||
world.register(new Tree(new Vector(-3,-1)));
|
||||
world.register(new Terrain(new Box(new Vector(0,-4),12,4), Material.GRASS));
|
||||
world.register(new Limits(Vector.ZERO, 12, 12));
|
||||
|
||||
world.register(new Block(new Box(new Vector(-6,0), 0.5, 12), false));
|
||||
world.register(new Block(new Box(new Vector(6,0), 0.5, 12), false));
|
||||
world.register(new Background(new Box(Vector.ZERO,12,12), "terrain/bg/end"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
186
Permafrost/src/platform/game/level/InterLevel.java
Normal file
186
Permafrost/src/platform/game/level/InterLevel.java
Normal file
@@ -0,0 +1,186 @@
|
||||
package platform.game.level;
|
||||
|
||||
import platform.game.GameType;
|
||||
import platform.game.World;
|
||||
import platform.game.actor.*;
|
||||
import platform.game.actor.GUI.*;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class InterLevel extends Level {
|
||||
|
||||
private int id;
|
||||
private Level nextLevel;
|
||||
//private Levels level;
|
||||
|
||||
public InterLevel(Levels next){
|
||||
//this.level = next;
|
||||
this.id = next.getId();
|
||||
this.nextLevel = next.getLevel();
|
||||
}
|
||||
|
||||
public InterLevel(int id, Level next){
|
||||
this.id = id;
|
||||
this.nextLevel = next;
|
||||
}
|
||||
|
||||
public void register(World world) {
|
||||
super.register(world);
|
||||
world.setView(Vector.ZERO, 11);
|
||||
|
||||
// Register a new instance, to restart level automatically
|
||||
world.setNextLevel(new BasicInteract());
|
||||
|
||||
Cursor cursor = new Cursor();
|
||||
// Create Button & text
|
||||
world.register(cursor);
|
||||
|
||||
world.register(new Chrono(false));
|
||||
world.register(new Cloud(new Vector(0,15), 30, 3, 1.0));
|
||||
switch(id){
|
||||
case -3:
|
||||
world.register(new Text(new Vector(0,8), 1.2, "You found it ?"));
|
||||
break;
|
||||
case -2:
|
||||
world.register(new Text(new Vector(0,8), 1.2, "Credits"));
|
||||
break;
|
||||
case -1:
|
||||
break;
|
||||
default:
|
||||
world.register(new Text(new Vector(0,8), 1.2, "Chapter - "+id));
|
||||
}
|
||||
world.register(new SelectLevel(new Vector(0,-7),1,"Continue",cursor, nextLevel));
|
||||
|
||||
switch(id){
|
||||
case -1:
|
||||
world.register(new Text(new Vector(0,8), 1.2, "Level Completed"));
|
||||
break;
|
||||
case 0:
|
||||
world.setGameType(GameType.STORY);
|
||||
build0(world);//before dream
|
||||
break;
|
||||
case 1:
|
||||
build1(world);//before outside1
|
||||
break;
|
||||
case 2:
|
||||
build2(world);//before outside2
|
||||
break;
|
||||
case 3:
|
||||
build3(world);//before cave1
|
||||
break;
|
||||
case 4:
|
||||
build4(world);//before cave2
|
||||
break;
|
||||
case 5:
|
||||
build5(world);//before cave3
|
||||
break;
|
||||
case 6:
|
||||
build6(world);//before cave end
|
||||
break;
|
||||
case 7:
|
||||
build7(world);//before happy end
|
||||
break;
|
||||
case 8:
|
||||
build8(world);//the end !
|
||||
break;
|
||||
case 9:
|
||||
build9(world);//the bad end !
|
||||
break;
|
||||
case -2:
|
||||
buildC(world);
|
||||
break;
|
||||
case -3:
|
||||
world.register(new Text(new Vector(0,4), 1.1, "Good Job !"));
|
||||
world.register(new Text(new Vector(0,1), 0.8, "you found the hidden button"));
|
||||
world.register(new Text(new Vector(0,-2), 1.1, "Now what ?"));
|
||||
world.register(new Text(new Vector(0,-4), 1.0, "More playing ?"));
|
||||
break;
|
||||
default:
|
||||
world.register(new Text(new Vector(0,0), 1.1, "Unknown Chapter"));
|
||||
}
|
||||
}
|
||||
|
||||
private void build0(World world){
|
||||
world.register(new Text(new Vector(0,4), 0.7, "You lived a happy life with your worm"));
|
||||
world.register(new Text(new Vector(0,3), 0.7, "One day you went to his hole"));
|
||||
world.register(new Text(new Vector(0,2), 0.7, "and noticed something a bit abnormal"));
|
||||
world.register(new Text(new Vector(0,-1.5), 0.8, "You decided to investigate further"));
|
||||
}
|
||||
|
||||
private void build1(World world){
|
||||
world.register(new Text(new Vector(0,4), 0.7, "You found only IceBlobs !"));
|
||||
world.register(new Text(new Vector(0,3), 0.7, "Your worm was missing"));
|
||||
world.register(new Text(new Vector(0,2), 0.7, "Where did he go ?"));
|
||||
world.register(new Text(new Vector(0,-1.5), 0.8, "You went through a strange door"));
|
||||
}
|
||||
|
||||
private void build2(World world){
|
||||
world.register(new Text(new Vector(0,4), 0.7, "After going through that door"));
|
||||
world.register(new Text(new Vector(0,3), 0.7, "you found yourself outside"));
|
||||
world.register(new Text(new Vector(0,2), 0.7, "It was suddendly winter and cold"));
|
||||
world.register(new Text(new Vector(0,-1.5), 0.8, "What happened ?"));
|
||||
}
|
||||
|
||||
private void build3(World world){
|
||||
world.register(new Text(new Vector(0,4), 0.7, "you are stuck at the bottom of a cliff"));
|
||||
world.register(new Text(new Vector(0,3), 0.7, "Something strange is happening here"));
|
||||
world.register(new Text(new Vector(0,2), 0.7, "What does this door lead to ?"));
|
||||
world.register(new Text(new Vector(0,-1.5), 0.8, "So many questions but for now"));
|
||||
world.register(new Text(new Vector(0,-2.5), 0.8, "You have to go on"));
|
||||
}
|
||||
|
||||
private void build4(World world){
|
||||
world.register(new Text(new Vector(0,4), 0.7, "you are heading further into the cave "));
|
||||
world.register(new Text(new Vector(0,3), 0.7, "You hope to find something sooner or later"));
|
||||
world.register(new Text(new Vector(0,2), 0.7, "From where are those IceBlobs coming from ?"));
|
||||
world.register(new Text(new Vector(0,-1.5), 0.8, "So many questions but for now"));
|
||||
world.register(new Text(new Vector(0,-2.5), 0.8, "You have to go on"));
|
||||
}
|
||||
private void build5(World world){
|
||||
world.register(new Text(new Vector(0,4), 0.7, "These puzzles aren't that easy"));
|
||||
world.register(new Text(new Vector(0,3), 0.7, "You hardly manage to continue"));
|
||||
world.register(new Text(new Vector(0,2), 0.7, "When does it end ?"));
|
||||
world.register(new Text(new Vector(0,-1.5), 0.8, "So many questions but for now"));
|
||||
world.register(new Text(new Vector(0,-2.5), 0.8, "You have to go on"));
|
||||
}
|
||||
private void build6(World world){
|
||||
world.register(new Text(new Vector(0,4), 0.7, "It's getting colder"));
|
||||
world.register(new Text(new Vector(0,3), 0.7, "You feel you are almost at the end"));
|
||||
world.register(new Text(new Vector(0,2), 0.7, "Is my worm close by ?"));
|
||||
world.register(new Text(new Vector(0,-1.5), 0.8, "So many questions but for now"));
|
||||
world.register(new Text(new Vector(0,-2.5), 0.8, "You have to go on"));
|
||||
}
|
||||
private void build7(World world){
|
||||
world.register(new Text(new Vector(0,4), 0.7, "You disabled the snow cristal"));
|
||||
world.register(new Text(new Vector(0,3), 0.7, "and you beat the enemies but"));
|
||||
world.register(new Text(new Vector(0,2), 0.7, "where is your worm ?"));
|
||||
world.register(new Text(new Vector(0,-1.5), 0.8, "That door led you back outside"));
|
||||
world.register(new Text(new Vector(0,-2.5), 0.8, "When you find something unexpected"));
|
||||
}
|
||||
private void build8(World world){
|
||||
world.register(new Text(new Vector(0,4), 0.7, "You found your worm !"));
|
||||
world.register(new Text(new Vector(0,3), 0.7, "And slowed down the"));
|
||||
world.register(new Text(new Vector(0,2), 0.7, "neverending frost"));
|
||||
world.register(new Text(new Vector(0,1), 0.7, "you can't run forever"));
|
||||
world.register(new Text(new Vector(0,-2.5), 0.8, "What is awaiting you ?"));
|
||||
world.register(new Text(new Vector(0,-3.5), 0.8, "Keep warm.."));
|
||||
}
|
||||
private void build9(World world) {
|
||||
world.register(new Text(new Vector(0,4), 0.7, "What have you done ? !"));
|
||||
world.register(new Text(new Vector(0,3), 0.7, "Was it all worth it?"));
|
||||
world.register(new Text(new Vector(0,2), 0.7, "are you proud of yourself"));
|
||||
world.register(new Text(new Vector(0,1), 0.7, "you can't run forever"));
|
||||
world.register(new Text(new Vector(0,-2.5), 0.8, "How long can you survive?"));
|
||||
world.register(new Text(new Vector(0,-3.5), 0.8, "no one knows..."));
|
||||
}
|
||||
private void buildC(World world){
|
||||
|
||||
world.register(new Text(new Vector(0,4), 0.7, "Code - CS-107"));
|
||||
world.register(new Text(new Vector(0,3), 0.7, "Code - Cedric Holzl"));
|
||||
world.register(new Text(new Vector(0,2), 0.7, "Code - Andrew Dobis"));
|
||||
world.register(new Text(new Vector(0,1), 0.7, "Sprites - 'kenney.nl'"));
|
||||
world.register(new Text(new Vector(0,0), 0.7, "Sprites - 'opengameart.org'"));
|
||||
world.register(new Text(new Vector(0,-1), 0.7, "Sprites - Drawn by us"));
|
||||
world.register(new Text(new Vector(0,-3.5), 0.9, "Thanks for playing"));
|
||||
}
|
||||
|
||||
}
|
40
Permafrost/src/platform/game/level/Level.java
Normal file
40
Permafrost/src/platform/game/level/Level.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package platform.game.level;
|
||||
|
||||
import platform.game.actor.*;
|
||||
import platform.util.Input;
|
||||
import platform.util.Output;
|
||||
|
||||
/**
|
||||
* Base class for level factories, which provides fade in transition. Subclasses
|
||||
* are requires to override <code>register</code>.
|
||||
*/
|
||||
public abstract class Level extends Actor {
|
||||
///UNCOMMENT ME WHEN NEEDED
|
||||
private double fadein;
|
||||
|
||||
public Level() {
|
||||
fadein = 1.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Input input) {
|
||||
fadein -= input.getDeltaTime();
|
||||
if (fadein <= 0.0)
|
||||
getWorld().unregister(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Input input, Output output) {
|
||||
output.drawSprite(getSprite("pixel.black"), output.getBox(), 0.0, fadein);
|
||||
}
|
||||
|
||||
/** @return a new instance of default level */
|
||||
public static Level createDefaultLevel() {
|
||||
return new Menu();
|
||||
}
|
||||
}
|
25
Permafrost/src/platform/game/level/Levels.java
Normal file
25
Permafrost/src/platform/game/level/Levels.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package platform.game.level;
|
||||
|
||||
public enum Levels {
|
||||
DREAM(0,new Dream()), OUTSIDE1(1,new Outside1()), OUTSIDE2(2,new Outside2()),
|
||||
CAVE1(3,new Cave1()),CAVE2(4,new Cave2()),CAVE3(5,new Cave3()),
|
||||
CAVEEND(6, new CaveEnd()), HAPPYEND(7, new HappyEnd()), END(8,new Menu()), BADEND(9,new Survival()),
|
||||
MENU(-1,new Menu()), CREDITS(-2,new Menu()), EGG(-3,new Menu());
|
||||
|
||||
private int id;
|
||||
private Level level;
|
||||
|
||||
Levels(int id, Level level) {
|
||||
this.id = id;
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public Level getLevel(){
|
||||
return this.level;
|
||||
}
|
||||
|
||||
}
|
105
Permafrost/src/platform/game/level/Menu.java
Normal file
105
Permafrost/src/platform/game/level/Menu.java
Normal file
@@ -0,0 +1,105 @@
|
||||
package platform.game.level;
|
||||
|
||||
import platform.game.GameType;
|
||||
import platform.game.World;
|
||||
import platform.game.actor.*;
|
||||
import platform.game.actor.GUI.*;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Menu extends Level {
|
||||
|
||||
public void register(World world) {
|
||||
super.register(world);
|
||||
world.setView(Vector.ZERO, 11);
|
||||
world.resetChrono();
|
||||
world.setGameType(GameType.FREE);
|
||||
// Register a new instance, to restart level automatically
|
||||
world.setNextLevel(new BasicInteract());
|
||||
|
||||
Cursor cursor = new Cursor();
|
||||
// Create Button & text
|
||||
world.register(cursor);
|
||||
world.register(new Cloud(new Vector(0,15), 80, 3, 1.0));
|
||||
world.register(new Text(new Vector(0,9), 1.2, "Permafrost Tilter"));
|
||||
world.register(new SelectLevel(new Vector(0,5),1,"Start Game",cursor, new InterLevel(Levels.DREAM)));
|
||||
|
||||
world.register(new MoveView(new Vector(0,2.5),1, "Options", cursor, new Vector(26,42)));
|
||||
world.register(new Text(new Vector(26,47.5), 1.2, "Difficulty"));
|
||||
world.register(new SetDifficulty(new Vector(26,45.5),1,cursor));
|
||||
world.register(new Text(new Vector(26,41.5), 1.2, "Respawn"));
|
||||
world.register(new OneLife(new Vector(26,39.5),1, cursor));
|
||||
world.register(new MoveView(new Vector(18.0,34.0),1, "Back", cursor, Vector.ZERO));
|
||||
|
||||
world.register(new MoveView(new Vector(0,0),1, "Select Level", cursor, new Vector(-26,0)));
|
||||
world.register(new Text(new Vector(-26,7.5), 1.2, "Main Game Levels"));
|
||||
|
||||
world.register(new SelectLevel(new Vector(-30.5,4),1,"0",cursor, new Dream()));
|
||||
world.register(new SelectLevel(new Vector(-27.5,4),1,"1",cursor, new Outside1()));
|
||||
world.register(new SelectLevel(new Vector(-24.5,4),1,"2",cursor, new Outside2()));
|
||||
world.register(new SelectLevel(new Vector(-21.5,4),1,"3",cursor, new Cave1()));
|
||||
world.register(new SelectLevel(new Vector(-30.5,1),1,"4",cursor, new Cave2()));
|
||||
world.register(new SelectLevel(new Vector(-27.5,1),1,"5",cursor, new Cave3()));
|
||||
world.register(new SelectLevel(new Vector(-24.5,1),1,"6",cursor, new CaveEnd()));
|
||||
world.register(new SelectLevel(new Vector(-21.5,1),1,"7",cursor, new HappyEnd()));
|
||||
//world.register(new SelectLevel(new Vector(-21.5,1),1,"8",cursor, new Survival()));
|
||||
|
||||
world.register(new MoveView(new Vector(-26,-4),1, "Back", cursor, Vector.ZERO));
|
||||
|
||||
|
||||
world.register(new MoveView(new Vector(0,-3),1, "More Levels", cursor, new Vector(26,0)));
|
||||
|
||||
world.register(new Text(new Vector(26,7.5), 1.2, "Dev Levels"));
|
||||
world.register(new SelectLevel(new Vector(26,5),1,"BasicInteract",cursor, new BasicInteract()));
|
||||
world.register(new SelectLevel(new Vector(26,3),1,"Test Level",cursor, new TestLevel()));
|
||||
world.register(new SelectLevel(new Vector(26,1),1,"Basic Level",cursor, new BasicLevel()));
|
||||
world.register(new SelectLevel(new Vector(26,-1),1,"Box",cursor, new BoxLevel()));
|
||||
world.register(new MoveView(new Vector(26,-4),1, "Back", cursor, Vector.ZERO));
|
||||
|
||||
world.register(new SelectLevel(new Vector(0,30),2, "CLICK ME", cursor, new InterLevel(Levels.EGG)));
|
||||
|
||||
world.register(new SelectLevel(new Vector(0,-9),0.5, "Credits", cursor, new InterLevel(Levels.CREDITS)));
|
||||
world.register(new MoveView(new Vector(-3,-6.5),1, "Help", cursor, new Vector(0,-26)));
|
||||
world.register(new Quit(new Vector(3,-6.5),1,cursor));
|
||||
|
||||
|
||||
world.register(new Text(new Vector(0,-20), 1.2, "Help"));
|
||||
world.register(new MoveView(new Vector(0,-24.5),1, "Controls", cursor, new Vector(-26,-26)));
|
||||
world.register(new MoveView(new Vector(0,-27.5),1, "Mechanics", cursor, new Vector(26,-26)));
|
||||
|
||||
world.register(new MoveView(new Vector(18,-35),1, "Back", cursor, new Vector(0,-26)));
|
||||
world.register(new MoveView(new Vector(-18,-35),1, "Back", cursor, new Vector(0,-26)));
|
||||
|
||||
world.register(new Text(new Vector(-26,-18), 1.0, "Controls"));
|
||||
world.register(new Text(new Vector(-26,-21), 0.6, "Q - Restart"));
|
||||
world.register(new Text(new Vector(-26,-22), 0.6, "E - Interact "));
|
||||
world.register(new Text(new Vector(-26,-23), 0.6, "B - Blow"));
|
||||
world.register(new Text(new Vector(-26,-24), 0.6, "Space - Shoot"));
|
||||
world.register(new Text(new Vector(-26,-25), 0.6, "Arrow Keys - Move"));
|
||||
world.register(new Text(new Vector(-26,-26), 0.6, "ESC - Menu"));
|
||||
|
||||
world.register(new Text(new Vector(26,-18), 1.0, "Mecanics"));
|
||||
world.register(new Text(new Vector(26,-20.5), 0.4, "You controll a little green block to solve puzzles"));
|
||||
world.register(new Text(new Vector(26,-21.5), 0.4, "Use your arrow keys to move and jump"));
|
||||
world.register(new Text(new Vector(26,-22), 0.4, "Use you space bar to shoot fireballs"));
|
||||
world.register(new Text(new Vector(26,-22.5), 0.4, "Fireballs turn on torches and hurt enemies"));
|
||||
world.register(new Text(new Vector(26,-23), 0.4, "Fireball drain your vigor and then your life !"));
|
||||
world.register(new Text(new Vector(26,-23.5), 0.4, "At 2 heart you will shoot snowballs"));
|
||||
world.register(new Text(new Vector(26,-24), 0.4, "Snowballs calm frenzy mobs and turn of torches"));
|
||||
world.register(new Text(new Vector(26,-24.5), 0.4, "To regain vigor you need to stand close to a heat source"));
|
||||
world.register(new Text(new Vector(26,-25), 0.4, "Being close to a cold source drains your vigor"));
|
||||
world.register(new Text(new Vector(26,-25.5), 0.4, "If no vigor is left you will take damage"));
|
||||
world.register(new Text(new Vector(26,-26.5), 0.4, "During your quest you will meet IceBlobs"));
|
||||
world.register(new Text(new Vector(26,-27), 0.4, "IceBlobs shoot snowballs and drain your vigor"));
|
||||
world.register(new Text(new Vector(26,-27.5), 0.4, "When low life they enter a frenzy !"));
|
||||
world.register(new Text(new Vector(26,-28), 0.4, "They take damage from heat sources"));
|
||||
world.register(new Text(new Vector(26,-28.5), 0.4, "You can kill them with torches without exposing yourself"));
|
||||
world.register(new Text(new Vector(26,-29.5), 0.4, "The Activator is a block who activate other elements"));
|
||||
world.register(new Text(new Vector(26,-30), 0.4, "The necessary keys are displayed on it"));
|
||||
world.register(new Text(new Vector(26,-31), 0.4, "The wind zones are pushing you in a certain direction"));
|
||||
world.register(new Text(new Vector(26,-32), 0.4, ""));
|
||||
|
||||
world.register(new MoveView(new Vector(0,-34),1, "Back", cursor, Vector.ZERO));
|
||||
|
||||
}
|
||||
|
||||
}
|
125
Permafrost/src/platform/game/level/Outside1.java
Normal file
125
Permafrost/src/platform/game/level/Outside1.java
Normal file
@@ -0,0 +1,125 @@
|
||||
package platform.game.level;
|
||||
|
||||
import platform.game.World;
|
||||
import platform.game.actor.*;
|
||||
import platform.game.actor.block.*;
|
||||
import platform.game.actor.interactors.*;
|
||||
import platform.game.actor.zone.EffectArea;
|
||||
import platform.game.signals.Constant;
|
||||
import platform.util.Box;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Outside1 extends Level {
|
||||
|
||||
@Override
|
||||
public void register(World world) {
|
||||
super.register(world);
|
||||
world.setNextLevel(new InterLevel(Levels.OUTSIDE2));
|
||||
|
||||
Player player = new Player(new Vector(-25.5, -4.5),new Vector(0.0,3.0));
|
||||
world.register(player);
|
||||
world.register(new Overlay(player));
|
||||
world.register(new Chrono());
|
||||
world.register(new Terrain(new Box(new Vector (-25.0, -6.0),8 ,2.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-26.0, 0.0),4 ,2.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-28.0, -2.0),2 ,6.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-27.0, 5.0),2 ,12.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-25.0, 10.0),6 ,2.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-23.0, 13.0),2 ,6.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-17.0, 15.0),14 ,2.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-11.0, 11.0),2 ,8.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-16.0, 9.5),8 ,1.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-17.0, 10.0),4 ,2.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-13.0, 10.5),2 ,1.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-12.5, 11.0),1 ,2.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-10.0, 7.5),4 ,1.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-3.0, 8.0),4 ,2.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-2.0, 4.0),2 ,10.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-4.0, 4.0),4, 2.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-5.0, 3.0),2 ,4.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-5.0, 2.0),8 ,2.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-9.0, 1.0),2 ,6.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-9.5, 4.5),1 ,1.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-5.5, 7.5),1 ,1.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-13.0, -1.0),10 ,2.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-17.0, 0.0),2 ,12.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-19.0, -6.0),6 ,2.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-22.0, -4.0),2 ,6.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-21.5, -2.0),3 ,1.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-20.0, 3.5),4 ,1.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-22.5, 4.5),1 ,3.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-23.5, 5.5),3 ,1.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (-19.0, 5.5),2 ,1.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (4.5, 0.0),17 ,2.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (12.0, 5.0),2 ,12.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (6.0, 6.0),2 ,6.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (11.0, 2.0),4 ,2.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (16.0, 11.0),2 ,6.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (19.0, 13.0),4 ,2.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (20.0, 16.0),2 ,8.0),Material.SNOW));
|
||||
world.register(new Terrain(new Box(new Vector (15, 19.0),12 ,2.0),Material.SNOW));
|
||||
|
||||
world.register(new Sign(new Vector(-0.5, 6.5), Math.PI/-2, "sign.r"));
|
||||
world.register(new Sign(new Vector(4.5, 6.5), Math.PI/2, "sign.l"));
|
||||
|
||||
world.register(new Ladder(new Vector(-23.5, -2.5), 1, 3));
|
||||
world.register(new Ladder(new Vector(-25.5, 3.5), 1, 5));
|
||||
world.register(new Ladder(new Vector(-15.5, 2.5), 1, 7));
|
||||
|
||||
for ( int i = 0; i < 2; ++i) {
|
||||
world.register(new Destruct(new Vector(-19.5 + i, -2.5)));
|
||||
world.register(new Destruct(new Vector(-19.5 + i, -3.5)));
|
||||
}
|
||||
|
||||
world.register(new Jumper(new Vector(-10.5, 0.4), 0.8, 0.8));
|
||||
world.register(new Jumper(new Vector(-6.5, 3.4), 0.8, 0.8));
|
||||
world.register(new Jumper(new Vector(8.5, 1.4), 0.8, 0.8));
|
||||
world.register(new Jumper(new Vector(-18.5, -4.6), 0.8, 0.8));
|
||||
|
||||
world.register(new SnowStorm(new Vector(9.0, 7.5), 4, 6, new Vector(0.0, 0.5)));
|
||||
world.register(new SnowStorm(new Vector(14.0, 11.5), 2, 4, new Vector(0.0, 0.5)));
|
||||
|
||||
Torch tor1 = new Torch(new Vector(-21.5, 0.5), true);
|
||||
Torch tor2 = new Torch(new Vector(-21.5, 0.5), true);
|
||||
world.register(new EffectArea(tor1));
|
||||
world.register(new EffectArea(tor2));
|
||||
world.register(tor1);
|
||||
world.register(tor2);
|
||||
|
||||
Lever lev1 = new Lever(new Vector(-3.5, 5.25), Double.POSITIVE_INFINITY);
|
||||
world.register(lev1);
|
||||
|
||||
Key key1 = new Key(new Vector(-20.5, -4.5), Keys.RED);
|
||||
Key key2 = new Key(new Vector(-18.5, 4.5), Keys.BLUE);
|
||||
Key key3 = new Key(new Vector(-12.5, 12.5), Keys.GREEN);
|
||||
Key key4 = new Key(new Vector(5.5, 1.5), Keys.YELLOW);
|
||||
Keys[] keys1 = {Keys.RED, Keys.BLUE, Keys.GREEN};
|
||||
Keys[] keys2 = {Keys.YELLOW};
|
||||
world.register(key1);
|
||||
world.register(key2);
|
||||
world.register(key3);
|
||||
world.register(key4);
|
||||
|
||||
Activator activ1 = new Activator(new Box(new Vector(-23.5, 6.4),0.8, 0.8), "box.empty",keys1);
|
||||
Activator activ2 = new Activator(new Box(new Vector(15.5, 14.5),0.8, 0.8), "box.empty",keys2);
|
||||
world.register(activ1);
|
||||
world.register(activ2);
|
||||
|
||||
world.register(new Mover(new Vector(-21.0, 9.5), new Vector(-21.0, 5.5), 2, 1, "stone.2"));
|
||||
world.register(new Mover(new Vector(-9.5, 6.0), new Vector(-5.5, 6.0), 1, 2, "stone.8"));
|
||||
world.register(new Mover(new Vector(4.0, 8.5), new Vector(0.0, 8.5), 2, 1, "stone.2"));
|
||||
|
||||
for(int i = 0; i < 3; ++i)
|
||||
world.register(new Door(new Vector(-19.5, 6.5 + i), activ1));
|
||||
world.register(new Door(new Vector(-7.5, 7.5), lev1));
|
||||
world.register(new Door(new Vector(-6.5, 7.5), lev1));
|
||||
|
||||
world.register(new Exit(new Vector(-25.5, -4.5), false));
|
||||
world.register(new Exit(new Vector(17.5, 14.5), activ2));
|
||||
|
||||
world.register(new Cloud(new Vector(-4.0,19.0), 50, 1, 0.6));
|
||||
world.register(new EffectArea(new Box(new Vector(-4.0, 6.5),50,27), Damage.COLD, 0.05, new Constant(true)));
|
||||
world.register(new Background(new Box(new Vector(-4.0, 6.5), 50, 27),"terrain/bg/snow"));
|
||||
world.register(new Limits(new Vector(-4.0, 6.5), 50, 27));
|
||||
}
|
||||
}
|
117
Permafrost/src/platform/game/level/Outside2.java
Normal file
117
Permafrost/src/platform/game/level/Outside2.java
Normal file
@@ -0,0 +1,117 @@
|
||||
package platform.game.level;
|
||||
|
||||
import platform.game.World;
|
||||
import platform.game.actor.block.Material;
|
||||
import platform.game.actor.block.Terrain;
|
||||
import platform.game.signals.And;
|
||||
import platform.game.signals.Constant;
|
||||
import platform.util.Box;
|
||||
import platform.util.Vector;
|
||||
import platform.game.actor.*;
|
||||
import platform.game.actor.block.*;
|
||||
import platform.game.actor.interactors.*;
|
||||
import platform.game.actor.mob.BossBlob;
|
||||
import platform.game.actor.mob.IceBlob;
|
||||
import platform.game.actor.mob.Mob;
|
||||
import platform.game.actor.zone.EffectArea;
|
||||
import platform.game.actor.zone.Trigger;
|
||||
|
||||
public class Outside2 extends Level{
|
||||
|
||||
@Override
|
||||
public void register(World world) {
|
||||
super.register(world);
|
||||
world.setNextLevel(new InterLevel(Levels.CAVE1));
|
||||
|
||||
Player player = new Player(new Vector(-27.0,1.0),new Vector(0.0,3.0));
|
||||
world.register(player);
|
||||
world.register(new Overlay(player));
|
||||
|
||||
world.register(new Chrono());
|
||||
world.register(new Terrain(new Box(new Vector (-29, 3.0), 2, 12),Material.ICE));
|
||||
world.register(new Exit(new Vector(-27.0,0.5), false));
|
||||
world.register(new Terrain(new Box(new Vector (-27.5, 5), 1,1),Material.STONE));
|
||||
world.register(new Key(new Vector (-27.5, 6), Keys.RED));
|
||||
Torch tor1 = new Torch(new Vector(-26.5, 1.5),true);
|
||||
world.register(new EffectArea(tor1));
|
||||
world.register(tor1);
|
||||
world.register(new Terrain(new Box(new Vector (-25.0, -0.5), 2, 3),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-27.0, -1.5), 6, 3),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-23.5, 2.5), 5, 1),Material.STONE));
|
||||
world.register(new Destruct(new Vector(-24.5,1.5)));
|
||||
world.register(new Terrain(new Box(new Vector (-22.5, -2.0), 3, 2),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-20.5, -2.5), 1, 1),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-22.0, 1.5), 2, 3),Material.STONE));
|
||||
world.register(new Key(new Vector (-23.5, -0.5), Keys.COAL));
|
||||
world.register(new Jumper(new Vector (-20.5, -1.5), 1, 1));
|
||||
world.register(new Terrain(new Box(new Vector (-19.0, 0.5), 2,7),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-17.0, 1.5), 4,1),Material.STONE));
|
||||
world.register(new Key(new Vector (-17.5, 2.5), Keys.COAL));
|
||||
world.register(new Terrain(new Box(new Vector (-16.0, -2.0), 6,2),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-12.0, -1.5), 2,3),Material.STONE));
|
||||
Keys[] keys1 = {Keys.RED};
|
||||
Activator acti1 = new Activator(new Box(new Vector(-14.5,-0.5),1,1), "box.empty", keys1);
|
||||
world.register(acti1);
|
||||
world.register(new Door(new Vector (-11.5, 0.5), acti1,false));
|
||||
world.register(new Terrain(new Box(new Vector (-10, 1.5), 4,1),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (-10.5, -2), 3,2),Material.STONE));
|
||||
Keys[] keys2 = {Keys.COAL, Keys.COAL};
|
||||
Activator acti2 = new Activator(new Box(new Vector(-9.5,-0.5),1,1), "oven", keys2);
|
||||
world.register(acti2);
|
||||
Torch tor2 = new Torch(new Vector(-9.5,-0.5), acti2);
|
||||
world.register(new EffectArea(tor2));
|
||||
world.register(tor2);
|
||||
world.register(new Trap(new Vector(-6.5,-0.5), tor2, "stone.2"));
|
||||
world.register(new Terrain(new Box(new Vector (-8, -0.5), 2,5),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (0, -2), 14,2),Material.STONE));
|
||||
|
||||
Trigger trig1 = new Trigger(new Box(new Vector(0,0),14,4));
|
||||
world.register(trig1);
|
||||
|
||||
world.register(new IceBlob(new Vector(-2.0,-1.0), trig1));
|
||||
world.register(new IceBlob(new Vector(-6.0,-1.0), trig1));
|
||||
world.register(new IceBlob(new Vector(6.0,-1.0), trig1));
|
||||
world.register(new IceBlob(new Vector(2.0,-1.0), trig1));
|
||||
world.register(new BossBlob(new Vector(4.0,-1.0), trig1));
|
||||
|
||||
Torch tor3 = new Torch(new Vector(-2, -0.5));
|
||||
world.register(new EffectArea(tor3));
|
||||
world.register(tor3);
|
||||
|
||||
world.register(new Terrain(new Box(new Vector (8, -1), 2,4),Material.STONE));
|
||||
|
||||
world.register(new Terrain(new Box(new Vector (11.5, 8.5), 5,1),Material.ICE));
|
||||
world.register(new Ladder(new Vector(8.5,4),1.0,10.0));
|
||||
world.register(new Terrain(new Box(new Vector (9.5, 3.0), 1,12),Material.STONE));
|
||||
world.register(new SnowStorm(new Vector(12.0, 10.0), 6, 5, new Vector(0.5, -0.5)));
|
||||
world.register(new Terrain(new Box(new Vector (12, 3.0), 4,12),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (19, -1), 18,4),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (23, 7), 10,8),Material.STONE));
|
||||
world.register(new Terrain(new Box(new Vector (29, 4), 2,14),Material.STONE));
|
||||
|
||||
|
||||
Torch tor4 = new Torch(new Vector(16, 2.0));
|
||||
world.register(new EffectArea(tor4));
|
||||
world.register(tor4);
|
||||
Mob mob1 = new IceBlob(new Vector(24.0,2.0), trig1);
|
||||
Mob mob2 = new IceBlob(new Vector(22.0,2.0), trig1);
|
||||
Mob mob3 = new IceBlob(new Vector(21.0,2.0), trig1);
|
||||
world.register(mob1);
|
||||
world.register(mob2);
|
||||
world.register(mob3);
|
||||
And mobAnd = new And(new And(mob1,mob2),mob3);
|
||||
|
||||
Torch tor5 = new Torch(new Vector(24, 2.0));
|
||||
world.register(new EffectArea(tor5));
|
||||
world.register(tor5);
|
||||
|
||||
world.register(new Exit(new Vector (26.0, 1.5),mobAnd));
|
||||
world.register(new Cloud(new Vector(0,13.0), 60, 1, 0.6));
|
||||
world.register(new EffectArea(new Box(new Vector(0.0, 5.0),60.0,16.0), Damage.COLD, 0.05, new Constant(true)));
|
||||
world.register(new Background(new Box(new Vector(0.0, 5.0),60.0,16.0), "terrain/bg/snow"));
|
||||
world.register(new Limits(new Vector(0.0, 5.0), 60.0, 16.0));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
29
Permafrost/src/platform/game/level/Survival.java
Normal file
29
Permafrost/src/platform/game/level/Survival.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package platform.game.level;
|
||||
|
||||
import platform.game.World;
|
||||
import platform.game.actor.Background;
|
||||
import platform.game.actor.Limits;
|
||||
import platform.game.actor.Overlay;
|
||||
import platform.game.actor.Player;
|
||||
import platform.game.actor.block.Material;
|
||||
import platform.game.actor.block.Terrain;
|
||||
import platform.util.Box;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class Survival extends Level{
|
||||
|
||||
@Override
|
||||
public void register(World world) {
|
||||
super.register(world);
|
||||
world.setNextLevel(new InterLevel(Levels.CAVEEND));
|
||||
|
||||
Player player = new Player(new Vector(0.5, 0.5),new Vector(0.0,3.0));
|
||||
world.register(player);
|
||||
world.register(new Overlay(player));
|
||||
|
||||
world.register(new Terrain(new Box(new Vector (0.0, 0.0),256 ,1.0),Material.GRASS));
|
||||
|
||||
world.register(new Background(new Box(new Vector(0.0, 0.0), 256, 256), "terrain/bg/sky"));
|
||||
world.register(new Limits(new Vector(0.0, 0.0), 256, 256));
|
||||
}
|
||||
}
|
41
Permafrost/src/platform/game/level/TestLevel.java
Normal file
41
Permafrost/src/platform/game/level/TestLevel.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package platform.game.level;
|
||||
|
||||
import platform.game.World;
|
||||
import platform.game.actor.*;
|
||||
import platform.game.actor.block.*;
|
||||
import platform.game.actor.interactors.Exit;
|
||||
import platform.util.Box;
|
||||
import platform.util.Vector;
|
||||
|
||||
public class TestLevel extends Level {
|
||||
@Override
|
||||
public void register(World world) {
|
||||
super.register(world);
|
||||
|
||||
// Register a new instance, to restart level automatically
|
||||
world.setNextLevel(new InterLevel(Levels.MENU));
|
||||
|
||||
world.register(new Exit(new Vector(15,-4),true));
|
||||
world.register(new Limits(Vector.ZERO, 100, 100));
|
||||
world.register(new Heart(Vector.ZERO));
|
||||
world.register(new Spike(new Vector(0, -4.25), 6));
|
||||
Player player = new Player(new Vector(1.0,1.0),new Vector(0.0,10.0));
|
||||
world.register(player);
|
||||
world.register(new Overlay(player));
|
||||
//world.register(new Block(new Vector(-1, -4),1 ,1,skinBlock));
|
||||
//world.register(new Block(new Vector(3, -4),1 ,1,skinBlock));
|
||||
world.register(new Torch(new Vector(-2,-3), false));
|
||||
world.register(new Jumper(new Vector(10, -4), 1, 1));
|
||||
world.register(new Jumper(new Vector(-6, -4), 1, 1));
|
||||
world.register(new Terrain(new Box(new Vector(0.0, 1.0),8 ,1),Material.ICE));
|
||||
world.register(new Terrain(new Box(new Vector (0, -5.5), 25, 2),Material.GRASS));
|
||||
world.register(new Terrain(new Box(new Vector(-8.5, -0.5),2 ,10),Material.STONE));
|
||||
world.register(new Ladder(new Vector(8, -0.5),1 ,10));
|
||||
world.register(new Block(new Vector(15, -5), 1, 1, "box.empty"));
|
||||
world.register(new Block(new Vector(-7, -2), 1, 1, "box.empty"));
|
||||
//world.register(new Background(new Box(Vector.ZERO,100 ,100),Material.CASTLE));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
16
Permafrost/src/platform/game/signals/And.java
Normal file
16
Permafrost/src/platform/game/signals/And.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package platform.game.signals;
|
||||
|
||||
public class And implements Signal {
|
||||
private Signal left;
|
||||
private Signal right;
|
||||
|
||||
public And (Signal left, Signal right) {
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return left.isActive() && right.isActive();
|
||||
}
|
||||
}
|
13
Permafrost/src/platform/game/signals/Constant.java
Normal file
13
Permafrost/src/platform/game/signals/Constant.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package platform.game.signals;
|
||||
|
||||
public class Constant implements Signal {
|
||||
private boolean constant;
|
||||
|
||||
public Constant (boolean constant) {
|
||||
this.constant = constant;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return constant;
|
||||
}
|
||||
}
|
17
Permafrost/src/platform/game/signals/Not.java
Normal file
17
Permafrost/src/platform/game/signals/Not.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package platform.game.signals;
|
||||
|
||||
public class Not implements Signal {
|
||||
private final Signal signal;
|
||||
|
||||
public Not (Signal signal) {
|
||||
if (signal == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
this.signal = signal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return !signal.isActive();
|
||||
}
|
||||
}
|
17
Permafrost/src/platform/game/signals/Or.java
Normal file
17
Permafrost/src/platform/game/signals/Or.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package platform.game.signals;
|
||||
|
||||
public class Or implements Signal {
|
||||
private Signal left;
|
||||
private Signal right;
|
||||
|
||||
public Or (Signal left, Signal right) {
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return left.isActive() || right.isActive();
|
||||
}
|
||||
}
|
||||
|
6
Permafrost/src/platform/game/signals/Signal.java
Normal file
6
Permafrost/src/platform/game/signals/Signal.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package platform.game.signals;
|
||||
public interface Signal {
|
||||
|
||||
public boolean isActive();
|
||||
|
||||
}
|
167
Permafrost/src/platform/util/Box.java
Normal file
167
Permafrost/src/platform/util/Box.java
Normal file
@@ -0,0 +1,167 @@
|
||||
package platform.util;
|
||||
|
||||
/**
|
||||
* Represents an immutable bounding-box, defined by a minimum and maximum.
|
||||
*/
|
||||
public final class Box {
|
||||
|
||||
/** The empty box */
|
||||
public static final Box EMPTY = new Box(Vector.ZERO, Vector.ZERO);
|
||||
|
||||
private final Vector min, max;
|
||||
|
||||
/**
|
||||
* Create a new box.
|
||||
* @param min lower-left corner, not null
|
||||
* @param max upper-right corner, not null
|
||||
*/
|
||||
public Box(Vector min, Vector max) {
|
||||
if (min.getX() > max.getX() || min.getY() > max.getY())
|
||||
throw new IllegalArgumentException();
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new box.
|
||||
* @param center middle of the box, not null
|
||||
* @param width horizontal size
|
||||
* @param height vertical size
|
||||
*/
|
||||
public Box(Vector center, double width, double height) {
|
||||
this.min = new Vector(center.getX() - width * 0.5, center.getY() - height * 0.5);
|
||||
this.max = new Vector(center.getX() + width * 0.5, center.getY() + height * 0.5);
|
||||
}
|
||||
|
||||
/** @return lower-left corner */
|
||||
public Vector getMin() {
|
||||
return min;
|
||||
}
|
||||
|
||||
/** @return upper-right corner */
|
||||
public Vector getMax() {
|
||||
return max;
|
||||
}
|
||||
|
||||
/** @return middle point */
|
||||
public Vector getCenter() {
|
||||
return min.add(max).mul(0.5);
|
||||
}
|
||||
|
||||
/** @return horizontal size */
|
||||
public double getWidth() {
|
||||
return getSize().getX();
|
||||
}
|
||||
|
||||
/** @return vertical size */
|
||||
public double getHeight() {
|
||||
return getSize().getY();
|
||||
}
|
||||
|
||||
/** @return width and height */
|
||||
public Vector getSize() {
|
||||
return max.sub(min);
|
||||
}
|
||||
|
||||
/** @return radius of largest circle inside box */
|
||||
public double getInnerRadius() {
|
||||
Vector size = getSize();
|
||||
return Math.min(size.getX(), size.getY());
|
||||
}
|
||||
|
||||
/** @return radius of smallest circle outside box */
|
||||
public double getOuterRadius() {
|
||||
return getSize().getLength() * 0.5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return min.hashCode() ^ max.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (object == null || !(object instanceof Box))
|
||||
return false;
|
||||
Box other = (Box)object;
|
||||
return min.equals(other.min) && max.equals(other.max);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return min + "->" + max;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param point value, not null
|
||||
* @return whether specified point is inside the box
|
||||
*/
|
||||
public boolean isColliding(Vector point) {
|
||||
if (point == null)
|
||||
return false;
|
||||
return point.getX() > min.getX() && point.getX() < max.getX() && point.getY() > min.getY() && point.getY() < max.getY();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param box value, not null
|
||||
* @return whether specified box intersects this rectangle
|
||||
*/
|
||||
public boolean isColliding(Box box) {
|
||||
if (box == null)
|
||||
return false;
|
||||
Vector min = this.min.max(box.min);
|
||||
Vector max = this.max.min(box.max);
|
||||
return min.getX() < max.getX() && min.getY() < max.getY();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param point value, not null
|
||||
* @return smallest direction to move the point outside this box
|
||||
*/
|
||||
public Vector getCollision(Vector point) {
|
||||
return getCollision(new Box(point, point));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param box value, not null
|
||||
* @return smallest direction to move the box outside this box
|
||||
*/
|
||||
public Vector getCollision(Box box) {
|
||||
double left = box.getMax().getX() - min.getX();
|
||||
if (left <= 0.0)
|
||||
return null;
|
||||
double right = max.getX() - box.getMin().getX();
|
||||
if (right <= 0.0)
|
||||
return null;
|
||||
double bottom = box.getMax().getY() - min.getY();
|
||||
if (bottom <= 0.0)
|
||||
return null;
|
||||
double top = max.getY() - box.getMin().getY();
|
||||
if (top <= 0.0)
|
||||
return null;
|
||||
double horizontal = Math.min(left, right);
|
||||
double vertical = Math.min(bottom, top);
|
||||
if (horizontal < vertical)
|
||||
return new Vector(left < right ? -left : right, 0.0);
|
||||
return new Vector(0.0, bottom < top ? -bottom : top);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates this box.
|
||||
* @param other delta to apply, not null
|
||||
* @return new box, not null
|
||||
*/
|
||||
public Box add(Vector other) {
|
||||
return new Box(min.add(other), max.add(other));
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates this box.
|
||||
* @param other delta to apply, not null
|
||||
* @return new box, not null
|
||||
*/
|
||||
public Box sub(Vector other) {
|
||||
return new Box(min.sub(other), max.sub(other));
|
||||
}
|
||||
|
||||
}
|
35
Permafrost/src/platform/util/BufferedLoader.java
Normal file
35
Permafrost/src/platform/util/BufferedLoader.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package platform.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Provides caching capabilities to avoid multiple sprite fetch.
|
||||
*/
|
||||
public class BufferedLoader implements Loader {
|
||||
|
||||
private Map<String, Sprite> sprites;
|
||||
private Loader loader;
|
||||
|
||||
/**
|
||||
* Creates a new buffered loader.
|
||||
* @param loader underlying loader, not null
|
||||
*/
|
||||
public BufferedLoader(Loader loader) {
|
||||
if (loader == null)
|
||||
throw new NullPointerException();
|
||||
sprites = new HashMap<>();
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sprite getSprite(String name) {
|
||||
Sprite sprite = sprites.get(name);
|
||||
if (sprite == null) {
|
||||
sprite = loader.getSprite(name);
|
||||
sprites.put(name, sprite);
|
||||
}
|
||||
return sprite;
|
||||
}
|
||||
|
||||
}
|
51
Permafrost/src/platform/util/Button.java
Normal file
51
Permafrost/src/platform/util/Button.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package platform.util;
|
||||
|
||||
/**
|
||||
* Enumeration of all possible states of a button.
|
||||
*/
|
||||
public enum Button {
|
||||
|
||||
/** The button is released for more than one frame */
|
||||
UP,
|
||||
|
||||
/** The button was just released */
|
||||
RELEASED,
|
||||
|
||||
/** The button was just pressed */
|
||||
PRESSED,
|
||||
|
||||
/** The button was pressed for more than one frame */
|
||||
DOWN;
|
||||
|
||||
/**
|
||||
* Compute the new state, after one frame.
|
||||
* @param down whether the button was down during last frame
|
||||
* @return updated state
|
||||
*/
|
||||
public Button updated(boolean down) {
|
||||
if (this == UP || this == RELEASED)
|
||||
return down ? PRESSED : UP;
|
||||
return down ? DOWN : RELEASED;
|
||||
}
|
||||
|
||||
/** @return whether the button is released */
|
||||
public boolean isUp() {
|
||||
return this == UP || this == RELEASED;
|
||||
}
|
||||
|
||||
/** @return whether the button was just released */
|
||||
public boolean isReleased() {
|
||||
return this == RELEASED;
|
||||
}
|
||||
|
||||
/** @return whether the button was just pressed */
|
||||
public boolean isPressed() {
|
||||
return this == PRESSED;
|
||||
}
|
||||
|
||||
/** @return whether the button is pressed */
|
||||
public boolean isDown() {
|
||||
return this == PRESSED || this == DOWN;
|
||||
}
|
||||
|
||||
}
|
27
Permafrost/src/platform/util/DefaultLoader.java
Normal file
27
Permafrost/src/platform/util/DefaultLoader.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package platform.util;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
/**
|
||||
* Dummy loader that always provides a 1x1 red sprite.
|
||||
*/
|
||||
public enum DefaultLoader implements Loader {
|
||||
|
||||
/** The singleton instance */
|
||||
INSTANCE;
|
||||
|
||||
private final Sprite sprite;
|
||||
|
||||
private DefaultLoader() {
|
||||
BufferedImage image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
|
||||
image.setRGB(0, 0, Color.RED.getRGB());
|
||||
sprite = new Sprite(image);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sprite getSprite(String name) {
|
||||
return sprite;
|
||||
}
|
||||
|
||||
}
|
30
Permafrost/src/platform/util/Display.java
Normal file
30
Permafrost/src/platform/util/Display.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package platform.util;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
/**
|
||||
* Combines Output and Input interfaces.
|
||||
* @see Output
|
||||
* @see Input
|
||||
*/
|
||||
public interface Display extends Output, Input {
|
||||
|
||||
/**
|
||||
* Sets background color.
|
||||
* @param color any color, not null
|
||||
*/
|
||||
public void setBackground(Color color);
|
||||
|
||||
/** Initiates new frame rendering */
|
||||
public void begin();
|
||||
|
||||
/** Finalizes the current frame and displays the result on the screen */
|
||||
public void end();
|
||||
|
||||
/** Closes window and releases resources */
|
||||
public void close();
|
||||
|
||||
/** @return whether the user requested to close the window */
|
||||
public boolean isCloseRequested();
|
||||
|
||||
}
|
47
Permafrost/src/platform/util/FileLoader.java
Normal file
47
Permafrost/src/platform/util/FileLoader.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package platform.util;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Loads sprites from specified folder, guessing necessary file extensions.
|
||||
*/
|
||||
public class FileLoader implements Loader {
|
||||
|
||||
private static final String[] EXTENSIONS = {
|
||||
"", ".png", ".jpg", ".jpeg", ".bmp"
|
||||
};
|
||||
|
||||
private String prefix;
|
||||
private Loader fallback;
|
||||
|
||||
/**
|
||||
* Creates a new file loader.
|
||||
* @param prefix path prefix used to form absolute or relative path when concatenated with an identifier, not null
|
||||
* @param fallback loader used in case of error, not null
|
||||
*/
|
||||
public FileLoader(String prefix, Loader fallback) {
|
||||
if (prefix == null || fallback == null)
|
||||
throw new NullPointerException();
|
||||
this.prefix = prefix;
|
||||
this.fallback = fallback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sprite getSprite(String name) {
|
||||
Sprite sprite = null;
|
||||
|
||||
// Try each extension, until we are able to successfully read the file
|
||||
for (String extension : EXTENSIONS) {
|
||||
try {
|
||||
sprite = new Sprite(prefix + name + extension);
|
||||
break;
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
|
||||
// On failure, use fallback loader
|
||||
if (sprite == null)
|
||||
sprite = fallback.getSprite(name);
|
||||
return sprite;
|
||||
}
|
||||
|
||||
}
|
37
Permafrost/src/platform/util/Input.java
Normal file
37
Permafrost/src/platform/util/Input.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package platform.util;
|
||||
|
||||
/**
|
||||
* Provides informations about input, such as time, mouse and keyboard.
|
||||
*/
|
||||
public interface Input {
|
||||
|
||||
/** @return time elapsed since the game started, in seconds */
|
||||
public double getTime();
|
||||
|
||||
/** @return time elapsed since last frame, in seconds */
|
||||
public double getDeltaTime();
|
||||
|
||||
/** @return mouse location, in pixels, with origin at lower-left corner */
|
||||
public Vector getMouseLocation();
|
||||
|
||||
/**
|
||||
* Gets state of specified mouse button.
|
||||
* @param index valid button identifier (1 - left, 2 - right, 3 - middle)
|
||||
* @return button state
|
||||
*/
|
||||
public Button getMouseButton(int index);
|
||||
|
||||
/** @return mouse wheel rotation units since last frame (positive is upward) */
|
||||
public int getMouseScroll();
|
||||
|
||||
/**
|
||||
* Gets state of specified keyboard button.
|
||||
* @param code valid button identifier (see values in {@link java.awt.KeyEvent})
|
||||
* @return button state
|
||||
*/
|
||||
public Button getKeyboardButton(int code);
|
||||
|
||||
/** @return window user focus (i.e. down means focused) */
|
||||
public Button getFocus();
|
||||
|
||||
}
|
16
Permafrost/src/platform/util/Loader.java
Normal file
16
Permafrost/src/platform/util/Loader.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package platform.util;
|
||||
|
||||
/**
|
||||
* Provides sprite loading by name.
|
||||
* @see Sprite
|
||||
*/
|
||||
public interface Loader {
|
||||
|
||||
/**
|
||||
* Gets the sprite associated to specified name.
|
||||
* @param name identifier, not null
|
||||
* @return valid sprite, not null
|
||||
*/
|
||||
public Sprite getSprite(String name);
|
||||
|
||||
}
|
37
Permafrost/src/platform/util/Output.java
Normal file
37
Permafrost/src/platform/util/Output.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package platform.util;
|
||||
|
||||
/**
|
||||
* Provides a rendering context, with its own coordinate system (i.e. unit is not guaranteed to be the pixel, the implementation is free to scale objects).
|
||||
*/
|
||||
public interface Output {
|
||||
|
||||
/** @return visible bounds, i.e. elements outside this area are not visible */
|
||||
public Box getBox();
|
||||
|
||||
/**
|
||||
* Draws a sprite in specified area.
|
||||
* @param sprite image to render, not null
|
||||
* @param location rectangular area, not null
|
||||
*/
|
||||
public void drawSprite(Sprite sprite, Box location);
|
||||
|
||||
/**
|
||||
* Draw a sprite in specified area, rotated around the center.
|
||||
* @param sprite image to render, not null
|
||||
* @param location rectangular area, not null
|
||||
* @param angle counter-clockwise angle, in radians
|
||||
*/
|
||||
public void drawSprite(Sprite sprite, Box location, double angle);
|
||||
|
||||
/**
|
||||
* Draw an alpha-blended sprite in specified area, rotated around the center.
|
||||
* @param sprite image to render, not null
|
||||
* @param location rectangular area, not null
|
||||
* @param angle counter-clockwise angle, in radians
|
||||
* @param transparency transparency multiplier, between 0.0 and 1.0
|
||||
*/
|
||||
public void drawSprite(Sprite sprite, Box location, double angle, double transparency);
|
||||
|
||||
|
||||
|
||||
}
|
65
Permafrost/src/platform/util/SortedCollection.java
Normal file
65
Permafrost/src/platform/util/SortedCollection.java
Normal file
@@ -0,0 +1,65 @@
|
||||
package platform.util;
|
||||
|
||||
import java.util.AbstractCollection;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.ListIterator;
|
||||
|
||||
/**
|
||||
* Provides an ordered collection of elements.
|
||||
* @param <E> type of element, must be self-comparable
|
||||
*/
|
||||
public class SortedCollection<E extends Comparable<? super E>> extends AbstractCollection<E> {
|
||||
|
||||
private LinkedList<E> list;
|
||||
|
||||
/**
|
||||
* Creates a new empty ordered collection.
|
||||
*/
|
||||
public SortedCollection() {
|
||||
list = new LinkedList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new ordered collection with specified elements.
|
||||
* @param other an existing collection of elements, not null
|
||||
*/
|
||||
public SortedCollection(Collection<? extends E> other) {
|
||||
this();
|
||||
addAll(other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(E e) {
|
||||
ListIterator<E> iterator = list.listIterator();
|
||||
while (iterator.hasNext()) {
|
||||
E next = iterator.next();
|
||||
if (e.compareTo(next) < 0) {
|
||||
iterator.previous();
|
||||
iterator.add(e);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
list.add(e);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<E> iterator() {
|
||||
return list.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return list.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a reversed view of elements, not null
|
||||
*/
|
||||
public Iterable<E> descending() {
|
||||
return () -> list.descendingIterator();
|
||||
}
|
||||
|
||||
}
|
80
Permafrost/src/platform/util/Sprite.java
Normal file
80
Permafrost/src/platform/util/Sprite.java
Normal file
@@ -0,0 +1,80 @@
|
||||
package platform.util;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Image;
|
||||
import java.awt.Transparency;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
/**
|
||||
* An immutable RGBA image.
|
||||
*/
|
||||
public final class Sprite {
|
||||
|
||||
private final BufferedImage image;
|
||||
|
||||
/**
|
||||
* Creates a sprite from specified image.
|
||||
* @param image valid image to be copied, not null
|
||||
*/
|
||||
public Sprite(Image image) {
|
||||
// See
|
||||
// http://stackoverflow.com/questions/196890/java2d-performance-issues
|
||||
// http://stackoverflow.com/questions/13605248/java-converting-image-to-bufferedimage
|
||||
// http://stackoverflow.com/questions/148478/java-2d-drawing-optimal-performance
|
||||
|
||||
// Get system graphical configuration
|
||||
GraphicsConfiguration config = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
|
||||
|
||||
// Get image size
|
||||
int width = image.getWidth(null);
|
||||
int height = image.getHeight(null);
|
||||
|
||||
// Create optimized buffered image
|
||||
this.image = config.createCompatibleImage(width, height, Transparency.TRANSLUCENT);
|
||||
|
||||
// Draw original image in buffer
|
||||
Graphics2D graphics = this.image.createGraphics();
|
||||
graphics.drawImage(image, 0, 0, null);
|
||||
graphics.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a sprite from specified image file.
|
||||
* @param file valid image file identifier, not null
|
||||
* @throws IOException if an error occurs during reading
|
||||
*/
|
||||
public Sprite(File file) throws IOException {
|
||||
this(ImageIO.read(file));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a sprite from specified image file.
|
||||
* @param path valid image file path, not null
|
||||
* @throws IOException if an error occurs during reading
|
||||
*/
|
||||
public Sprite(String path) throws IOException {
|
||||
this(new File(path));
|
||||
}
|
||||
|
||||
/** @return underlying buffered image, not null */
|
||||
public BufferedImage getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
/** @return image width, in pixels */
|
||||
public int getWidth() {
|
||||
return image.getWidth();
|
||||
}
|
||||
|
||||
/** @return image height, in pixels */
|
||||
public int getHeight() {
|
||||
return image.getHeight();
|
||||
}
|
||||
|
||||
}
|
337
Permafrost/src/platform/util/SwingDisplay.java
Normal file
337
Permafrost/src/platform/util/SwingDisplay.java
Normal file
@@ -0,0 +1,337 @@
|
||||
package platform.util;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Canvas;
|
||||
import java.awt.Color;
|
||||
import java.awt.Composite;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.MouseInfo;
|
||||
import java.awt.Point;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.event.MouseWheelListener;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.image.BufferStrategy;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.SwingUtilities;
|
||||
import java.awt.Cursor;
|
||||
|
||||
/**
|
||||
* Swing and AWT implementation of Output and Input interfaces.
|
||||
* @see Output
|
||||
* @see Input
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class SwingDisplay implements Display, KeyListener, MouseListener, MouseWheelListener {
|
||||
|
||||
// Encapsulates a collection of buttons
|
||||
private static class ButtonManager {
|
||||
|
||||
private Map<Integer, Button> current;
|
||||
private Map<Integer, Boolean> buffer;
|
||||
|
||||
private ButtonManager() {
|
||||
current = new HashMap<>();
|
||||
buffer = new HashMap<>();
|
||||
}
|
||||
|
||||
public Button get(int key) {
|
||||
Button state = current.get(key);
|
||||
if (state == null)
|
||||
return Button.UP;
|
||||
return state;
|
||||
}
|
||||
|
||||
public void set(int key, boolean value) {
|
||||
buffer.put(key, value);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
for (Map.Entry<Integer, Boolean> entry : buffer.entrySet())
|
||||
current.put(entry.getKey(), get(entry.getKey()).updated(entry.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
// Rendering-related objects
|
||||
private JFrame frame;
|
||||
private Canvas canvas;
|
||||
private BufferStrategy strategy;
|
||||
private Graphics2D graphics;
|
||||
private Box box;
|
||||
|
||||
// Input-related objects
|
||||
private double deltaTime, time;
|
||||
private long before;
|
||||
private Vector mouseLocation;
|
||||
private ButtonManager keyboardButtons;
|
||||
private ButtonManager mouseButtons;
|
||||
private int mouseScroll;
|
||||
private int mouseScrollBuffer;
|
||||
private Button focus;
|
||||
private volatile boolean closeRequested;
|
||||
|
||||
/** Creates a new display */
|
||||
public SwingDisplay() {
|
||||
|
||||
// Create canvas
|
||||
canvas = new Canvas();
|
||||
canvas.setFocusable(true);
|
||||
canvas.setFocusTraversalKeysEnabled(false);
|
||||
canvas.setIgnoreRepaint(true);
|
||||
canvas.setBackground(Color.BLACK);
|
||||
|
||||
// Create input buffers
|
||||
deltaTime = 0.0;
|
||||
time = 0.0;
|
||||
before = System.nanoTime();
|
||||
keyboardButtons = new ButtonManager();
|
||||
mouseButtons = new ButtonManager();
|
||||
canvas.addKeyListener(this);
|
||||
canvas.addMouseListener(this);
|
||||
canvas.addMouseWheelListener(this);
|
||||
|
||||
// Create frame
|
||||
frame = new JFrame();
|
||||
frame.setFocusable(false);
|
||||
frame.setFocusTraversalKeysEnabled(false);
|
||||
frame.setIgnoreRepaint(true);
|
||||
frame.setBackground(Color.BLACK);
|
||||
frame.add(canvas);
|
||||
frame.pack();
|
||||
frame.setSize(1024, 768);
|
||||
frame.setVisible(true);
|
||||
BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
|
||||
Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImg, new Point(0,0), "Blank Cursor");
|
||||
frame.getContentPane().setCursor(blankCursor);
|
||||
|
||||
// Add window manager
|
||||
focus = Button.UP;
|
||||
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||
closeRequested = false;
|
||||
frame.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent we) {
|
||||
closeRequested = true;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBackground(Color color) {
|
||||
canvas.setBackground(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void begin() {
|
||||
|
||||
// Setup double buffering if needed
|
||||
if (strategy == null) {
|
||||
canvas.createBufferStrategy(2);
|
||||
strategy = canvas.getBufferStrategy();
|
||||
}
|
||||
|
||||
// Recreate graphic context
|
||||
graphics = (Graphics2D)strategy.getDrawGraphics();
|
||||
|
||||
// Get current size
|
||||
int width = canvas.getWidth();
|
||||
int height = canvas.getHeight();
|
||||
box = new Box(Vector.ZERO, new Vector(width, height));
|
||||
|
||||
// Clear background
|
||||
graphics.setColor(canvas.getBackground());
|
||||
graphics.fillRect(0, 0, width, height);
|
||||
|
||||
// Enable anti-aliasing
|
||||
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
|
||||
// Set transform to have origin at lower left corner
|
||||
graphics.setTransform(new AffineTransform(1.0, 0.0, 0.0, -1.0, 0.0, height));
|
||||
|
||||
// Update mouse location
|
||||
if (MouseInfo.getPointerInfo() != null) {
|
||||
Point point = MouseInfo.getPointerInfo().getLocation();
|
||||
SwingUtilities.convertPointFromScreen(point, canvas);
|
||||
mouseLocation = new Vector(point.getX(), height - point.getY());
|
||||
} else
|
||||
mouseLocation = Vector.ZERO;
|
||||
|
||||
// Update input buffers
|
||||
synchronized (this) {
|
||||
keyboardButtons.update();
|
||||
mouseButtons.update();
|
||||
mouseScroll = mouseScrollBuffer;
|
||||
mouseScrollBuffer = 0;
|
||||
}
|
||||
|
||||
// Update time
|
||||
long now = System.nanoTime();
|
||||
deltaTime = (now - before) * 1e-9;
|
||||
if (deltaTime > 0.1) {
|
||||
System.out.println("Delta time too large (" + deltaTime + "), clamped to 0.1.");
|
||||
deltaTime = 0.1;
|
||||
}
|
||||
time += deltaTime;
|
||||
before = now;
|
||||
|
||||
// Update focus
|
||||
focus = focus.updated(canvas.hasFocus());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void end() {
|
||||
|
||||
// Dispose context
|
||||
graphics.dispose();
|
||||
graphics = null;
|
||||
box = null;
|
||||
|
||||
// Flip buffer
|
||||
strategy.show();
|
||||
Toolkit.getDefaultToolkit().sync();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
frame.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCloseRequested() {
|
||||
return closeRequested;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Box getBox() {
|
||||
return box;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawSprite(Sprite sprite, Box location) {
|
||||
drawSprite(sprite, location, 0.0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawSprite(Sprite sprite, Box location, double angle) {
|
||||
drawSprite(sprite, location, angle, 1.0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawSprite(Sprite sprite, Box location, double angle, double transparency) {
|
||||
if (transparency <= 0.0)
|
||||
return;
|
||||
|
||||
// Center sprite at origin
|
||||
AffineTransform center = AffineTransform.getTranslateInstance(sprite.getWidth() / -2.0, sprite.getHeight() / -2.0);
|
||||
|
||||
// Rescale sprite according to box (images have inverted Y-axis)
|
||||
AffineTransform scale = AffineTransform.getScaleInstance(location.getWidth() / sprite.getWidth(), -location.getHeight() / sprite.getHeight());
|
||||
|
||||
// Rotate sprite
|
||||
AffineTransform rotate = AffineTransform.getRotateInstance(angle);
|
||||
|
||||
// Move to desired location
|
||||
AffineTransform move = AffineTransform.getTranslateInstance(location.getCenter().getX(), location.getCenter().getY());
|
||||
|
||||
// Combine everything
|
||||
AffineTransform transform = move;
|
||||
transform.concatenate(rotate);
|
||||
transform.concatenate(scale);
|
||||
transform.concatenate(center);
|
||||
|
||||
// Draw image with alpha modifier
|
||||
if (transparency < 1.0) {
|
||||
Composite original = graphics.getComposite();
|
||||
AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float)transparency);
|
||||
graphics.setComposite(composite);
|
||||
graphics.drawImage(sprite.getImage(), transform, null);
|
||||
graphics.setComposite(original);
|
||||
} else
|
||||
graphics.drawImage(sprite.getImage(), transform, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDeltaTime() {
|
||||
return deltaTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector getMouseLocation() {
|
||||
return mouseLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Button getMouseButton(int index) {
|
||||
return mouseButtons.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMouseScroll() {
|
||||
return mouseScroll;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Button getKeyboardButton(int code) {
|
||||
return keyboardButtons.get(code);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Button getFocus() {
|
||||
return focus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void keyPressed(KeyEvent e) {
|
||||
keyboardButtons.set(e.getKeyCode(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void keyReleased(KeyEvent e) {
|
||||
keyboardButtons.set(e.getKeyCode(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {}
|
||||
|
||||
@Override
|
||||
public synchronized void mousePressed(MouseEvent e) {
|
||||
mouseButtons.set(e.getButton(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void mouseReleased(MouseEvent e) {
|
||||
mouseButtons.set(e.getButton(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void mouseWheelMoved(MouseWheelEvent e) {
|
||||
mouseScrollBuffer -= e.getWheelRotation();
|
||||
}
|
||||
|
||||
}
|
120
Permafrost/src/platform/util/Transform.java
Normal file
120
Permafrost/src/platform/util/Transform.java
Normal file
@@ -0,0 +1,120 @@
|
||||
package platform.util;
|
||||
|
||||
/**
|
||||
* Applies a simple coordinate transform.
|
||||
*/
|
||||
public abstract class Transform implements Input, Output {
|
||||
|
||||
private Input input;
|
||||
private Output output;
|
||||
|
||||
/**
|
||||
* Create a new view with identity transform.
|
||||
* @param input underlying input, not null
|
||||
* @param output underlying output, not null
|
||||
*/
|
||||
public Transform(Input input, Output output) {
|
||||
if (input == null || output == null)
|
||||
throw new NullPointerException();
|
||||
this.input = input;
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
/** @return underlying input, not null */
|
||||
public Input getInput() {
|
||||
return input;
|
||||
}
|
||||
|
||||
/** @return underlying output, not null */
|
||||
public Output getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform point to view coordinates.
|
||||
* @param x point in underlying system coordinates, not null
|
||||
* @return point in view coordinates, not null
|
||||
*/
|
||||
public abstract Vector convertToView(Vector x);
|
||||
|
||||
/**
|
||||
* Transform box to view coordinates.
|
||||
* @param x box in underlying system coordinates, not null
|
||||
* @return box in view coordinates, not null
|
||||
*/
|
||||
public Box convertToView(Box x) {
|
||||
return new Box(convertToView(x.getMin()), convertToView(x.getMax()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform point to underlying system coordinates.
|
||||
* @param x point in view coordinates, not null
|
||||
* @return point in underlying system coordinates, not null
|
||||
*/
|
||||
public abstract Vector convertFromView(Vector x);
|
||||
|
||||
/**
|
||||
* Transform box to underlying system coordinates.
|
||||
* @param x box in view coordinates, not null
|
||||
* @return box in underlying system coordinates, not null
|
||||
*/
|
||||
public Box convertFromView(Box x) {
|
||||
return new Box(convertFromView(x.getMin()), convertFromView(x.getMax()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Box getBox() {
|
||||
return convertToView(output.getBox());
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTime() {
|
||||
return input.getTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDeltaTime() {
|
||||
return input.getDeltaTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector getMouseLocation() {
|
||||
return convertToView(input.getMouseLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Button getMouseButton(int index) {
|
||||
return input.getMouseButton(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMouseScroll() {
|
||||
return input.getMouseScroll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Button getKeyboardButton(int code) {
|
||||
return input.getKeyboardButton(code);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Button getFocus() {
|
||||
return input.getFocus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawSprite(Sprite sprite, Box location) {
|
||||
output.drawSprite(sprite, convertFromView(location));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawSprite(Sprite sprite, Box location, double angle) {
|
||||
output.drawSprite(sprite, convertFromView(location), angle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawSprite(Sprite sprite, Box location, double angle, double transparency) {
|
||||
output.drawSprite(sprite, convertFromView(location), angle, transparency);
|
||||
}
|
||||
|
||||
}
|
205
Permafrost/src/platform/util/Vector.java
Normal file
205
Permafrost/src/platform/util/Vector.java
Normal file
@@ -0,0 +1,205 @@
|
||||
package platform.util;
|
||||
|
||||
/**
|
||||
* Represents an immutable 2D floating-point vector.
|
||||
*/
|
||||
public final class Vector {
|
||||
|
||||
/** The zero vector (0, 0) */
|
||||
public static final Vector ZERO = new Vector(0.0, 0.0);
|
||||
|
||||
/** The unit X vector (1, 0) */
|
||||
public static final Vector X = new Vector(1.0, 0.0);
|
||||
|
||||
/** The unit Y vector (0, 1) */
|
||||
public static final Vector Y = new Vector(0.0, 1.0);
|
||||
|
||||
private final double x, y;
|
||||
|
||||
/**
|
||||
* Create a new vector.
|
||||
* @param x abscissa
|
||||
* @param y ordinate
|
||||
*/
|
||||
public Vector(double x, double y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/** @return abscissa */
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/** @return ordinate */
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/** @return euclidian length */
|
||||
public double getLength() {
|
||||
return Math.sqrt(x * x + y * y);
|
||||
}
|
||||
|
||||
/** @return angle in standard trigonometrical system, in radians */
|
||||
public double getAngle() {
|
||||
return Math.atan2(y, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Double.hashCode(x) ^ Double.hashCode(y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (object == null || !(object instanceof Vector))
|
||||
return false;
|
||||
Vector other = (Vector)object;
|
||||
return x == other.x && y == other.y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + x + "," + y + ")";
|
||||
}
|
||||
|
||||
/** @return negated vector */
|
||||
public Vector opposite() {
|
||||
return new Vector(-x, -y);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param other right-hand operand, not null
|
||||
* @return sum, not null
|
||||
*/
|
||||
public Vector add(Vector other) {
|
||||
return new Vector(x + other.x, y + other.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param other right-hand operand, not null
|
||||
* @return difference, not null
|
||||
*/
|
||||
public Vector sub(Vector other) {
|
||||
return new Vector(x - other.x, y - other.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param other right-hand operand
|
||||
* @return scaled vector, not null
|
||||
*/
|
||||
public Vector mul(double other) {
|
||||
return new Vector(x * other, y * other);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param other right-hand operand, not null
|
||||
* @return component-wise multiplication, not null
|
||||
*/
|
||||
public Vector mul(Vector other) {
|
||||
return new Vector(x * other.x, y * other.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param other right-hand operand
|
||||
* @return scaled vector, not null
|
||||
*/
|
||||
public Vector div(double other) {
|
||||
return new Vector(x / other, y / other);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param other right-hand operand, not null
|
||||
* @return component-wise division, not null
|
||||
*/
|
||||
public Vector div(Vector other) {
|
||||
return new Vector(x / other.x, y / other.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param other right-hand operand, not null
|
||||
* @return dot product
|
||||
*/
|
||||
public double dot(Vector other) {
|
||||
return x * other.x + y * other.y;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param other right-hand operand, not null
|
||||
* @return component-wise minimum, not null
|
||||
*/
|
||||
public Vector min(Vector other) {
|
||||
return new Vector(Math.min(x, other.x), Math.min(y, other.y));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param other right-hand operand, not null
|
||||
* @return component-wise maximum, not null
|
||||
*/
|
||||
public Vector max(Vector other) {
|
||||
return new Vector(Math.max(x, other.x), Math.max(y, other.y));
|
||||
}
|
||||
|
||||
/** @return smallest component */
|
||||
public double min() {
|
||||
return Math.min(x, y);
|
||||
}
|
||||
|
||||
/** @return largest component */
|
||||
public double max() {
|
||||
return Math.max(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes unit vector of same direction, or (1, 0) if zero.
|
||||
* @return rescaled vector, not null
|
||||
*/
|
||||
public Vector normalized() {
|
||||
double length = getLength();
|
||||
if (length > 1e-6)
|
||||
return div(length);
|
||||
return Vector.X;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resizes vector to specified length, or (<code>length</code>, 0) if zero.
|
||||
* @param length new length
|
||||
* @return rescaled vector, not null
|
||||
*/
|
||||
public Vector resized(double length) {
|
||||
return normalized().mul(length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes mirrored vector, with respect to specified normal.
|
||||
* @param normal vector perpendicular to the symmetry plane, not null
|
||||
* @return rotated vector, not null
|
||||
*/
|
||||
public Vector mirrored(Vector normal) {
|
||||
normal = normal.normalized();
|
||||
return sub(normal.mul(2.0 * dot(normal)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes rotated vector, in a counter-clockwise manner.
|
||||
* @param angle rotation, in radians
|
||||
* @return rotated vector, not null
|
||||
*/
|
||||
public Vector rotated(double angle) {
|
||||
double c = Math.cos(angle);
|
||||
double s = Math.sin(angle);
|
||||
return new Vector(x * c - y * s, x * s + y * c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes linear interpolation between two vectors.
|
||||
* @param other second vector, not null
|
||||
* @param factor weight of the second vector
|
||||
* @return interpolated vector, not null
|
||||
*/
|
||||
public Vector mixed(Vector other, double factor) {
|
||||
return new Vector(x * (1.0 - factor) + other.x * factor, y * (1.0 - factor) + other.y * factor);
|
||||
}
|
||||
|
||||
}
|
69
Permafrost/src/platform/util/View.java
Normal file
69
Permafrost/src/platform/util/View.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package platform.util;
|
||||
|
||||
/**
|
||||
* Transform viewport to render specific area of the world.
|
||||
*/
|
||||
public class View extends Transform {
|
||||
|
||||
private double scale;
|
||||
private Vector translation;
|
||||
|
||||
/**
|
||||
* Create a new view with identity transform.
|
||||
* @param input underlying input, not null
|
||||
* @param output underlying output, not null
|
||||
*/
|
||||
public View(Input input, Output output) {
|
||||
super(input, output);
|
||||
scale = 1.0;
|
||||
translation = Vector.ZERO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set viewport location and size.
|
||||
* @param center viewport center, not null
|
||||
* @param radius viewport radius, positive
|
||||
*/
|
||||
public void setTarget(Vector center, double radius) {
|
||||
if (radius <= 0.0)
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
// Get window ratio
|
||||
Vector size = getOutput().getBox().getSize();
|
||||
double ratio = size.getY() / size.getX();
|
||||
|
||||
// Use largest dimension as reference
|
||||
double length;
|
||||
Vector extent;
|
||||
if (ratio < 1.0) {
|
||||
length = size.getY();
|
||||
extent = new Vector(radius / ratio, radius);
|
||||
} else {
|
||||
length = size.getX();
|
||||
extent = new Vector(radius, radius * ratio);
|
||||
}
|
||||
|
||||
// Compute scale and translation
|
||||
scale = 2.0 * radius / length;
|
||||
translation = center.sub(extent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector convertToView(Vector x) {
|
||||
return x.mul(scale).add(translation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector convertFromView(Vector x) {
|
||||
return x.sub(translation).div(scale);
|
||||
}
|
||||
|
||||
public double getSizeX(){
|
||||
return getOutput().getBox().getSize().getX();
|
||||
}
|
||||
|
||||
public double getSizeY(){
|
||||
return getOutput().getBox().getSize().getY();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user