Disabled external gits
This commit is contained in:
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();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user