gitignore ./out/*

Former-commit-id: 88e6aea40f35f7a0fbb4360798975250e012b154
Former-commit-id: 1648f35809ffc110f12722aa62e086979548bb4e
This commit is contained in:
Song Minjae
2016-03-14 23:24:49 +09:00
parent eca3a566b0
commit 0347720241
296 changed files with 2 additions and 2885 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
out/*
bin/*

View File

@@ -1,130 +0,0 @@
== CHALLENGING, NOT PUNISHING == https://www.youtube.com/watch?v=ea6UuRTjkKs
1. CONSISTENT RULES
- No arbitrary unstoppable death
2. Player's skill involved
- Can play around, not restart
3. Usability of in-game tools
- Players should be able to 'regret' their strategy and adjust.
4. Comfortable control
5. Make players overcome the challenge, not defeating them
6. Let players have "aha" moment when they failed.
- Make them hungry to retry with new strategies.
- Some small things they've could done differently
- e.g. "One-big-hit didn't worked, may I should've picked up high DPS one"
== MORE DEPTH, LESS COMPLEXITY == https://www.youtube.com/watch?v=jVL4st0blGU
1. Memorise less!
- Less burden to, even starting the game
- Start with gentle learning curve, getting slowly steep
- Intuitive UX (UI, control, ...)
- Good tutorial = lessens complexity
2. Intuitive!
3. Calculations per second
- reduce!
4. Players have to know everything to even begin the play == FAIL (irreducible complexity)
- Make them get familiar with rules of the game
- Dwarf Fortress failed this!
== Lots of things players can play with (aka don't make them bored) ==
- Combat, battle, building, mechanics, adventure, dungeon explore, spelunking
- Not scaled; easy combat, tough combat, tedious combat, etc.
== Achieving perfect imbalance == https://www.youtube.com/watch?v=e31OSVZF77w
- Make sure no matter how you skilled, your playable character cannot be good at everything
- Give players __wide pool of options__ to solve problem
(kill the boss, defend their adobe, fast transportation, etc.)
-=*## What feeling do you want to convey? ##*=-
== Always think WHY you want to add _something_ on the game ==
- e.g. Why are you adding RPG leveling system? What it would do to the players? How would they play with?
See also: HEARTS, CLUBS, DIAMONDS, SPADES: PLAYERS WHO SUIT MUDS
====================================
== Friendlier version of Dwarf Fortress Adventure mode ==
- Yet _lots of fun_
- Add Fortress mode features by 'make your own settling'
- Hard to actually die, but once you die, you're done.
+ Config: imtooyoungtodie for easy mode
- Genre: Adventure, Open world (towns in RPG, building, town managing (conquer existing one or
you build one and persuade existing people to move in) -> See Dwarf Fortress and Animal Crossing)
* Adventure: adventure this vast—5,5 km wide—world, discover new (and good/horrible) things
* Open world:
- Building: building your own houses, structures, etc.
- Town managing:
1. Build your own little hamlet and manage it
or-
2. Conquer existing one and become a ruler
The town is a special hamlet that can be tailored for your taste
- Survival:
mobs will trying to attack your assets (yourself, your hamlet, your people)
== Side view ==
== Interact menu w/ mouse right ==
== Pixelated sprites ==
- Use 2x sprites if rotating does not work well
== User experience ==
* Indicative mouse cursor
== Game mechanics ==
* 24 pixels == 1 metre
== Purpose of the game ==
* Boss
- Will be mentioned/shown as absolute _evil_.
- But actually is not.
* Theme
- Is an evil really really is what we think?
- Is there a thing as 'absolute evil'?
* Boss character
- From debugger character
- Name key: "Sigriðr hinn Dróttningin" (can be changed)
* Little setting
- A ruler, hated by people
* Mechanics
- Beating boss does not ends the game, but grants an ability to
create new character as it.

View File

@@ -1,18 +0,0 @@
package com.Torvald.Terrarum.Actors;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
/**
* Created by minjaesong on 15-12-31.
*/
public interface Actor {
void update(GameContainer gc, int delta_t);
/**
* Valid RefID is equal to or greater than 32768.
* @return Reference ID. (32768-0x7FFF_FFFF_FFFF_FFFF)
*/
long getRefID();
}

View File

@@ -1,20 +0,0 @@
package com.Torvald.Terrarum.Actors;
import com.Torvald.Terrarum.GameItem.InventoryItem;
/**
* Created by minjaesong on 16-01-31.
*/
public interface CanBeStoredAsItem {
void attachItemData();
float getItemWeight();
void stopUpdateAndDraw();
void resumeUpdateAndDraw();
InventoryItem getItemData();
}

View File

@@ -1,17 +0,0 @@
package com.Torvald.Terrarum.Actors;
import com.Torvald.spriteAnimation.SpriteAnimation;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
/**
* Created by minjaesong on 15-12-31.
*/
public interface Controllable {
void processInput(Input input);
void keyPressed(int key, char c);
}

View File

@@ -1,137 +0,0 @@
package com.Torvald.Terrarum.Actors;
import com.Torvald.JsonFetcher;
import com.Torvald.Rand.Fudge3;
import com.Torvald.Rand.HQRNG;
import com.Torvald.Terrarum.LangPack.Lang;
import com.google.gson.JsonObject;
import org.newdawn.slick.SlickException;
import java.io.IOException;
/**
* Created by minjaesong on 16-02-05.
*/
public class CreatureFactory {
private static final String JSONPATH = "./res/raw/";
public ActorWithBody build(String jsonFileName) throws IOException, SlickException {
JsonObject jsonObj = JsonFetcher.readJson(JSONPATH + jsonFileName);
ActorWithBody actor = new ActorWithBody();
String[] elementsString = {
"racename"
, "racenameplural"
};
String[] elementsFloat = {
"baseheight"
, "basemass"
, "accel"
, "toolsize"
, "encumbrance"
};
String[] elementsFloatVariable = {
"strength"
, "speed"
, "jumppower"
, "scale"
, "speed"
};
String[] elementsBoolean = {
"intelligent"
};
String[] elementsMultiplyFromOne = {
"physiquemult"
};
setAVStrings(actor, elementsString, jsonObj);
setAVFloats(actor, elementsFloat, jsonObj);
setAVFloatsVariable(actor, elementsFloatVariable, jsonObj);
setAVMultiplyFromOne(actor, elementsMultiplyFromOne, jsonObj);
setAVBooleans(actor, elementsBoolean, jsonObj);
actor.actorValue.set("accel", Player.WALK_ACCEL_BASE);
actor.actorValue.set("accelmult", 1f);
actor.inventory = new ActorInventory((int) actor.actorValue.get("encumberance"), true);
return actor;
}
/**
* Fetch and set actor values that have 'variable' appended. E.g. strength
* @param p
* @param elemSet
* @param jsonObject
*/
private void setAVFloatsVariable(ActorWithBody p, String[] elemSet, JsonObject jsonObject) {
for (String s : elemSet) {
float baseValue = jsonObject.get(s).getAsFloat();
// roll fudge dice and get value [-3, 3] as [0, 6]
int varSelected = new Fudge3(new HQRNG()).rollForArray();
// get multiplier from json. Assuming percentile
int multiplier = jsonObject.get(s + "variable").getAsJsonArray().get(varSelected).getAsInt();
float realValue = baseValue * multiplier / 100f;
p.actorValue.set(s, realValue);
}
}
/**
* Fetch and set string actor values
* @param p
* @param elemSet
* @param jsonObject
*/
private void setAVStrings(ActorWithBody p, String[] elemSet, JsonObject jsonObject) {
for (String s : elemSet) {
String key = jsonObject.get(s).getAsString();
p.actorValue.set(s, Lang.get(key));
}
}
/**
* Fetch and set float actor values
* @param p
* @param elemSet
* @param jsonObject
*/
private void setAVFloats(ActorWithBody p, String[] elemSet, JsonObject jsonObject) {
for (String s : elemSet) {
p.actorValue.set(s, jsonObject.get(s).getAsFloat());
}
}
/**
* Fetch and set actor values that should multiplier be applied to the base value of 1.
* E.g. physiquemult
* @param p
* @param elemSet
* @param jsonObject
*/
private void setAVMultiplyFromOne(ActorWithBody p, String[] elemSet, JsonObject jsonObject) {
for (String s : elemSet) {
float baseValue = 1f;
// roll fudge dice and get value [-3, 3] as [0, 6]
int varSelected = new Fudge3(new HQRNG()).rollForArray();
// get multiplier from json. Assuming percentile
int multiplier = jsonObject.get(s).getAsJsonArray().get(varSelected).getAsInt();
float realValue = baseValue * multiplier / 100f;
p.actorValue.set(s, realValue);
}
}
private void setAVBooleans(ActorWithBody p, String[] elemSet, JsonObject jsonObject) {
for (String s : elemSet) {
p.actorValue.set(s, jsonObject.get(s).getAsBoolean());
}
}
}

View File

@@ -1,17 +0,0 @@
package com.Torvald.Terrarum.Actors;
import com.Torvald.Terrarum.Actors.Faction.Faction;
import java.util.HashSet;
/**
* Created by minjaesong on 16-02-15.
*/
public interface Factionable {
void assignFaction(Faction f);
void unassignFaction(Faction f);
HashSet<Faction> getAssignedFactions();
void clearFactionAssigning();
}

View File

@@ -1,15 +0,0 @@
package com.Torvald.Terrarum.Actors;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
/**
* Created by minjaesong on 16-01-25.
*/
public interface Glowing {
void drawGlow(GameContainer gc, Graphics g);
void updateGlowSprite(GameContainer gc, int delta_t);
}

View File

@@ -1,16 +0,0 @@
package com.Torvald.Terrarum.Actors;
import java.util.ArrayList;
/**
* Created by minjaesong on 16-02-20.
*/
public interface Landholder {
ArrayList<Integer> getHouseDesignation();
void setHouseDesignation(ArrayList<Integer> list);
void addHouseTile(int x, int y);
void removeHouseTile(int x, int y);
void clearHouseDesignation();
}

View File

@@ -1,11 +0,0 @@
package com.Torvald.Terrarum.Actors;
/**
* Created by minjaesong on 16-02-19.
*/
public interface Luminous {
void setLuminance(char RGB);
char getLuminance();
}

View File

@@ -1,152 +0,0 @@
package com.Torvald.Terrarum.Actors;
import com.Torvald.Terrarum.Actors.AI.ActorAI;
import com.Torvald.Terrarum.Actors.Faction.Faction;
import com.Torvald.Terrarum.GameItem.InventoryItem;
import com.Torvald.Terrarum.Terrarum;
import org.newdawn.slick.GameContainer;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
/**
* Created by minjaesong on 16-01-31.
*/
public class NPCIntelligentBase extends ActorWithBody implements AIControlled, Pocketed, CanBeStoredAsItem,
Factionable, Landholder {
private InventoryItem itemData; // keep it for extendibility, like Carriers in SC1
private transient ActorAI ai;
private ActorInventory inventory;
private HashSet<Faction> factionSet = new HashSet<>();
/**
* Absolute tile index. index(x, y) = y * map.width + x <br />
* The arraylist will be saved in JSON format with GSON.
*/
private ArrayList<Integer> houseTiles = new ArrayList<>();
@Override
public void assignFaction(Faction f) {
factionSet.add(f);
}
@Override
public void unassignFaction(Faction f) {
factionSet.remove(f);
}
@Override
public HashSet<Faction> getAssignedFactions() {
return factionSet;
}
@Override
public void clearFactionAssigning() {
factionSet.clear();
}
@Override
public void attachItemData() {
itemData = new InventoryItem() {
@Override
public long getItemID() {
return 0;
}
@Override
public float getWeight() {
return 0;
}
@Override
public void effectWhileInPocket(GameContainer gc, int delta_t) {
}
@Override
public void effectWhenPickedUp(GameContainer gc, int delta_t) {
}
@Override
public void primaryUse(GameContainer gc, int delta_t) {
}
@Override
public void secondaryUse(GameContainer gc, int delta_t) {
}
@Override
public void effectWhenThrownAway(GameContainer gc, int delta_t) {
}
};
}
@Override
public float getItemWeight() {
return super.getMass();
}
@Override
public ArrayList<Integer> getHouseDesignation() {
return houseTiles;
}
@Override
public void setHouseDesignation(ArrayList<Integer> list) {
houseTiles = list;
}
@Override
public void addHouseTile(int x, int y) {
houseTiles.add(Terrarum.game.map.width * y + x);
}
@Override
public void removeHouseTile(int x, int y) {
houseTiles.remove(new Integer(Terrarum.game.map.width * y + x));
}
@Override
public void clearHouseDesignation() {
houseTiles.clear();
}
@Override
public void stopUpdateAndDraw() {
super.setUpdate(false);
super.setVisible(false);
}
@Override
public void resumeUpdateAndDraw() {
super.setUpdate(true);
super.setVisible(true);
}
@Override
public InventoryItem getItemData() {
return itemData;
}
@Override
public ActorInventory getInventory() {
return null;
}
@Override
public void overwriteInventory(ActorInventory inventory) {
this.inventory = inventory;
}
@Override
public void attachAI(ActorAI ai) {
this.ai = ai;
}
}

View File

@@ -1,104 +0,0 @@
package com.Torvald.Terrarum.Actors;
import com.Torvald.JsonFetcher;
import com.Torvald.Terrarum.Actors.Faction.Faction;
import com.Torvald.Terrarum.Game;
import com.Torvald.spriteAnimation.SpriteAnimation;
import com.google.gson.JsonObject;
import org.lwjgl.Sys;
import org.newdawn.slick.SlickException;
import java.io.IOException;
/**
* Created by minjaesong on 16-02-03.
*/
public class PFSigrid {
private static String FACTION_PATH = "./res/raw/";
public Player build() throws SlickException {
Player p = new Player();
p.sprite = new SpriteAnimation();
p.sprite.setDimension(28, 51);
p.sprite.setSpriteImage("res/graphics/sprites/test_player.png");
p.sprite.setDelay(200);
p.sprite.setRowsAndFrames(1, 1);
p.sprite.setAsVisible();
p.sprite.composeSprite();
p.spriteGlow = new SpriteAnimation();
p.spriteGlow.setDimension(28, 51);
p.spriteGlow.setSpriteImage("res/graphics/sprites/test_player_glow.png");
p.spriteGlow.setDelay(200);
p.spriteGlow.setRowsAndFrames(1, 1);
p.spriteGlow.setAsVisible();
p.spriteGlow.composeSprite();
p.actorValue = new ActorValue();
p.actorValue.set("scale", 1.0f);
p.actorValue.set("speed", 4.0f);
p.actorValue.set("speedmult", 1.0f);
p.actorValue.set("accel", Player.WALK_ACCEL_BASE);
p.actorValue.set("accelmult", 1.0f);
p.actorValue.set("jumppower", 5f);
p.actorValue.set("basemass", 80f);
p.actorValue.set("physiquemult", 1); // Constant 1.0 for player, meant to be used by random mobs
/**
* fixed value, or 'base value', from creature strength of Dwarf Fortress.
* Human race uses 1000. (see CreatureHuman.json)
*/
p.actorValue.set("strength", 1414);
p.actorValue.set("encumbrance", 1000);
p.actorValue.set("name", "Sigrid");
p.actorValue.set("intelligent", true);
p.actorValue.set("luminosity", 22819);
p.actorValue.set("selectedtile", 16);
p.setHitboxDimension(18, 46, 8, 0);
p.setInventory(new ActorInventory(0x7FFFFFFF, true));
p.setPosition(4096 * 16, 300 * 16);
p.assignFaction(loadFactioningData("FactionSigrid.json"));
return p;
}
private Faction loadFactioningData(String filename) {
JsonObject jsonObject = null;
try {
jsonObject = JsonFetcher.readJson(FACTION_PATH + filename);
}
catch (IOException e) {
e.printStackTrace();
System.exit(-1);
}
Faction faction = new Faction(jsonObject.get("factionname").getAsString());
jsonObject.get("factionamicable").getAsJsonArray().forEach(
jobj -> faction.addFactionAmicable(jobj.getAsString())
);
jsonObject.get("factionneutral").getAsJsonArray().forEach(
jobj -> faction.addFactionNeutral(jobj.getAsString())
);
jsonObject.get("factionhostile").getAsJsonArray().forEach(
jobj -> faction.addFactionHostile(jobj.getAsString())
);
jsonObject.get("factionfearful").getAsJsonArray().forEach(
jobj -> faction.addFactionFearful(jobj.getAsString())
);
return faction;
}
}

View File

@@ -1,29 +0,0 @@
package com.Torvald.Terrarum.Actors;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
/**
* Created by minjaesong on 16-03-05.
*/
public class PhysTestBall extends ActorWithBody {
public PhysTestBall() {
super();
setHitboxDimension(16, 16, 0, 0);
setVisible(true);
setMass(10f);
}
@Override
public void drawBody(GameContainer gc, Graphics g) {
g.setColor(Color.orange);
g.fillOval(
getHitbox().getPosX()
, getHitbox().getPosY()
, getHitbox().getWidth()
, getHitbox().getHeight()
);
}
}

View File

@@ -1,571 +0,0 @@
package com.Torvald.Terrarum.Actors;
import com.Torvald.Terrarum.Actors.Faction.Faction;
import com.Torvald.Terrarum.GameControl.EnumKeyFunc;
import com.Torvald.Terrarum.GameControl.KeyMap;
import com.Torvald.Terrarum.MapDrawer.MapDrawer;
import com.Torvald.Terrarum.Terrarum;
import com.Torvald.spriteAnimation.SpriteAnimation;
import com.jme3.math.FastMath;
import com.sun.istack.internal.NotNull;
import com.sun.istack.internal.Nullable;
import org.lwjgl.input.Controller;
import org.lwjgl.input.Controllers;
import org.newdawn.slick.*;
import java.io.Serializable;
import java.util.HashSet;
/**
* Created by minjaesong on 15-12-31.
*/
public class Player extends ActorWithBody implements Controllable, Pocketed, Factionable, Luminous {
public transient @Nullable Controllable vehicleRiding;
int jumpCounter = 0;
int walkPowerCounter = 0;
private transient final int MAX_JUMP_LENGTH = 17; // use 17; in internal frames
/**
* experimental value.
*/
// private transient final float JUMP_ACCELERATION_MOD = ???f / 10000f; //quadratic mode
private transient final float JUMP_ACCELERATION_MOD = 170f / 10000f; //linear mode
private transient final int WALK_FRAMES_TO_MAX_ACCEL = 6;
public float readonly_totalX = 0, readonly_totalY = 0;
boolean jumping = false;
@NotNull int walkHeading;
private transient final int LEFT = 1;
private transient final int RIGHT = 2;
private transient final int KEY_NULL = -1;
private transient int prevHMoveKey = KEY_NULL;
private transient int prevVMoveKey = KEY_NULL;
static transient final float ACCEL_MULT_IN_FLIGHT = 0.48f;
static transient final float WALK_STOP_ACCEL = 0.32f;
static transient final float WALK_ACCEL_BASE = 0.32f;
private boolean noClip = false;
public static transient final long PLAYER_REF_ID = 0x51621D;
private transient final float AXIS_POSMAX = 1.0f;
private transient final int GAMEPAD_JUMP = 5;
private transient final int TSIZE = MapDrawer.TILE_SIZE;
private HashSet<Faction> factionSet = new HashSet<>();
private transient final int BASE_DENSITY = 1020;
/**
* Creates new Player instance with empty elements (sprites, actorvalue, etc.). <br />
*
* <strong>Use PlayerBuildFactory to build player!</strong>
*
* @throws SlickException
*/
public Player() throws SlickException {
super();
referenceID = PLAYER_REF_ID;
setVisible(true);
super.setDensity(BASE_DENSITY);
}
@Override
public void update(GameContainer gc, int delta_t) {
if (vehicleRiding instanceof Player) throw new RuntimeException("Attempted to 'ride' " +
"player object.");
updatePhysicalInfos();
super.update(gc, delta_t);
updateSprite(delta_t);
updateMovementControl();
if (noClip) { super.setGrounded(true); }
}
private void updatePhysicalInfos() {
super.setScale(actorValue.getAsFloat("scale"));
super.setMass(actorValue.getAsFloat("basemass")
* FastMath.pow(super.getScale(), 3));
if (super.getElasticity() != 0) super.setElasticity(0);
}
/**
*
* @param left (even if the game is joypad controlled, you must give valid value)
* @param absAxisVal (set AXIS_POSMAX if keyboard controlled)
*/
private void walkHorizontal(boolean left, float absAxisVal) {
//if ((!super.isWalledLeft() && left) || (!super.isWalledRight() && !left)) {
readonly_totalX = super.getVeloX()
+
actorValue.getAsFloat("accel")
* actorValue.getAsFloat("accelmult")
* FastMath.sqrt(super.getScale())
* applyAccelRealism(walkPowerCounter)
* (left ? -1 : 1)
* absAxisVal;
super.setVeloX(readonly_totalX);
if (walkPowerCounter < WALK_FRAMES_TO_MAX_ACCEL) {
walkPowerCounter += 1;
}
// Clamp veloX
super.setVeloX(
absClamp(super.getVeloX()
, actorValue.getAsFloat("speed")
* actorValue.getAsFloat("speedmult")
* FastMath.sqrt(super.getScale())
)
);
// Heading flag
if (left) walkHeading = LEFT;
else walkHeading = RIGHT;
//}
}
/**
*
* @param up (even if the game is joypad controlled, you must give valid value)
* @param absAxisVal (set AXIS_POSMAX if keyboard controlled)
*/
private void walkVertical(boolean up, float absAxisVal) {
readonly_totalY = super.getVeloY()
+
actorValue.getAsFloat("accel")
* actorValue.getAsFloat("accelmult")
* FastMath.sqrt(super.getScale())
* applyAccelRealism(walkPowerCounter)
* (up ? -1 : 1)
* absAxisVal;
super.setVeloY(readonly_totalY);
if (walkPowerCounter < WALK_FRAMES_TO_MAX_ACCEL) {
walkPowerCounter += 1;
}
// Clamp veloX
super.setVeloY(
absClamp(super.getVeloY()
, actorValue.getAsFloat("speed")
* actorValue.getAsFloat("speedmult")
* FastMath.sqrt(super.getScale())
)
);
}
/**
* For realistic accelerating while walking.
*
* Naïve 'veloX += 3' is actually like:
*
* a
* | ------------
* |
* |
* 0+------············ t
*
* which is unrealistic, so this method tries to introduce some realism by doing:
*
* a
* | ------------
* | ---
* | -
* | ---
* 0+----··················· t
*
*
* @param x
*/
private float applyAccelRealism(int x) {
return 0.5f + 0.5f * -FastMath.cos(10 * x / (WALK_FRAMES_TO_MAX_ACCEL * FastMath.PI));
}
private void walkHStop() {
if (super.getVeloX() > 0) {
super.setVeloX(super.getVeloX()
-
actorValue.getAsFloat("accel")
* actorValue.getAsFloat("accelmult")
* FastMath.sqrt(super.getScale())
);
// compensate overshoot
if (super.getVeloX() < 0)
super.setVeloX(0);
}
else if (super.getVeloX() < 0) {
super.setVeloX(super.getVeloX()
+
actorValue.getAsFloat("accel")
* actorValue.getAsFloat("accelmult")
* FastMath.sqrt(super.getScale())
);
// compensate overshoot
if (super.getVeloX() > 0)
super.setVeloX(0);
}
else {
super.setVeloX(0);
}
walkPowerCounter = 0;
}
private void walkVStop() {
if (super.getVeloY() > 0) {
super.setVeloY(super.getVeloY()
-
WALK_STOP_ACCEL
* actorValue.getAsFloat("accelmult")
* FastMath.sqrt(super.getScale())
);
// compensate overshoot
if (super.getVeloY() < 0)
super.setVeloY(0);
}
else if (super.getVeloY() < 0) {
super.setVeloY(super.getVeloY()
+
WALK_STOP_ACCEL
* actorValue.getAsFloat("accelmult")
* FastMath.sqrt(super.getScale())
);
// compensate overshoot
if (super.getVeloY() > 0)
super.setVeloY(0);
}
else {
super.setVeloY(0);
}
walkPowerCounter = 0;
}
private void updateMovementControl() {
if (!noClip) {
if (super.isGrounded()) {
actorValue.set("accelmult", 1f);
} else {
actorValue.set("accelmult", ACCEL_MULT_IN_FLIGHT);
}
}
else {
actorValue.set("accelmult", 1f);
}
}
public void processInput(Input input) {
Controller gamepad = null;
float axisX = 0, axisY = 0, axisRX = 0, axisRY = 0;
if (Terrarum.hasController) {
gamepad = Controllers.getController(0);
axisX = gamepad.getAxisValue(0);
axisY = gamepad.getAxisValue(1);
axisRX = gamepad.getAxisValue(2);
axisRY = gamepad.getAxisValue(3);
if (Math.abs(axisX) < Terrarum.CONTROLLER_DEADZONE) axisX = 0;
if (Math.abs(axisY) < Terrarum.CONTROLLER_DEADZONE) axisY = 0;
if (Math.abs(axisRX) < Terrarum.CONTROLLER_DEADZONE) axisRX = 0;
if (Math.abs(axisRY) < Terrarum.CONTROLLER_DEADZONE) axisRY = 0;
}
/**
* L-R stop
*/
if (Terrarum.hasController) {
if (axisX == 0) {
walkHStop();
}
}
else {
// ↑F, ↑S
if (!isFuncDown(input, EnumKeyFunc.MOVE_LEFT)
&& !isFuncDown(input, EnumKeyFunc.MOVE_RIGHT)) {
walkHStop();
prevHMoveKey = KEY_NULL;
}
}
/**
* U-D stop
*/
if (Terrarum.hasController) {
if (axisY == 0) {
walkVStop();
}
}
else {
// ↑E
// ↑D
if (isNoClip()
&& !isFuncDown(input, EnumKeyFunc.MOVE_UP)
&& !isFuncDown(input, EnumKeyFunc.MOVE_DOWN)) {
walkVStop();
prevVMoveKey = KEY_NULL;
}
}
/**
* Left/Right movement
*/
if (Terrarum.hasController) {
if (axisX != 0) {
walkHorizontal(axisX < 0, AXIS_POSMAX);
}
}
else {
// ↑F, ↓S
if (isFuncDown(input, EnumKeyFunc.MOVE_RIGHT)
&& !isFuncDown(input, EnumKeyFunc.MOVE_LEFT)) {
walkHorizontal(false, AXIS_POSMAX);
prevHMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_RIGHT);
}
// ↓F, ↑S
else if (isFuncDown(input, EnumKeyFunc.MOVE_LEFT)
&& !isFuncDown(input, EnumKeyFunc.MOVE_RIGHT)) {
walkHorizontal(true, AXIS_POSMAX);
prevHMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_LEFT);
}
// ↓F, ↓S
else if (isFuncDown(input, EnumKeyFunc.MOVE_LEFT)
&& isFuncDown(input, EnumKeyFunc.MOVE_RIGHT)) {
if (prevHMoveKey == KeyMap.getKeyCode(EnumKeyFunc.MOVE_LEFT)) {
walkHorizontal(false, AXIS_POSMAX);
prevHMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_RIGHT);
}
else if (prevHMoveKey == KeyMap.getKeyCode(EnumKeyFunc.MOVE_RIGHT)) {
walkHorizontal(true, AXIS_POSMAX);
prevHMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_LEFT);
}
}
}
/**
* Up/Down movement
*/
if (noClip) {
if (Terrarum.hasController) {
if (axisY != 0) {
walkVertical(axisY > 0, AXIS_POSMAX);
}
}
else {
// ↑E
// ↓D
if (isFuncDown(input, EnumKeyFunc.MOVE_DOWN)
&& !isFuncDown(input, EnumKeyFunc.MOVE_UP)) {
walkVertical(false, AXIS_POSMAX);
prevVMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_DOWN);
}
// ↓E
// ↑D
else if (isFuncDown(input, EnumKeyFunc.MOVE_UP)
&& !isFuncDown(input, EnumKeyFunc.MOVE_DOWN)) {
walkVertical(true, AXIS_POSMAX);
prevVMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_UP);
}
// ↓E
// ↓D
else if (isFuncDown(input, EnumKeyFunc.MOVE_UP)
&& isFuncDown(input, EnumKeyFunc.MOVE_DOWN)) {
if (prevVMoveKey == KeyMap.getKeyCode(EnumKeyFunc.MOVE_UP)) {
walkVertical(false, AXIS_POSMAX);
prevVMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_DOWN);
}
else if (prevVMoveKey == KeyMap.getKeyCode(EnumKeyFunc.MOVE_DOWN)) {
walkVertical(true, AXIS_POSMAX);
prevVMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_UP);
}
}
}
}
/**
* Jump control
*/
if (isFuncDown(input, EnumKeyFunc.JUMP)
|| (Terrarum.hasController && gamepad.isButtonPressed(GAMEPAD_JUMP))) {
if (!noClip) {
if (super.isGrounded()) {
jumping = true;
}
jump();
}
else {
walkVertical(true, AXIS_POSMAX);
}
}
else {
jumping = false;
jumpCounter = 0;
}
}
public void keyPressed(int key, char c) {
}
/**
* See ./work_files/Jump\ power\ by\ pressing\ time.gcx
*/
private void jump() {
if (jumping) {
float len = MAX_JUMP_LENGTH;
float pwr = actorValue.getAsFloat("jumppower");
// increment jump counter
if (jumpCounter < len) jumpCounter += 1;
// quadratic time (convex) mode
/*
float sumT = (jumpCounter * (jumpCounter + 1)) / 2f;
float timedJumpCharge = ((len + 1) / 2f) - (sumT / len);
if (timedJumpCharge < 0) timedJumpCharge = 0;
float jumpAcc = pwr * timedJumpCharge * JUMP_ACCELERATION_MOD;
super.setVeloY(super.getVeloY()
- jumpAcc
);
*/
// linear time mode
float init = (len + 1) / 2f;
float timedJumpCharge = init - (init / len) * jumpCounter;
if (timedJumpCharge < 0) timedJumpCharge = 0;
float jumpAcc = pwr * timedJumpCharge * JUMP_ACCELERATION_MOD
* FastMath.sqrt(getScale());
super.setVeloY(super.getVeloY()
- jumpAcc
);
// concave mode?
}
// for mob AI:
//super.setVeloY(super.getVeloY()
// -
// pwr * FastMath.sqrt(super.getScale())
//);
}
private float jumpFuncLin(float pwr, float len) {
return -(pwr / len) * jumpCounter;
}
private float jumpFuncSqu(float pwr, float len) {
return (pwr / (len * len))
* (jumpCounter - len)
* (jumpCounter - len) // square
- pwr;
}
private float jumpFuncExp(float pwr, float len) {
float a = FastMath.pow(pwr + 1, 1 / len);
return -FastMath.pow(a, len) + 1;
}
private boolean isFuncDown(Input input, EnumKeyFunc fn) {
return input.isKeyDown(KeyMap.getKeyCode(fn));
}
private float absClamp(float i, float ceil) {
if (i > 0)
return (i > ceil) ? ceil : i;
else if (i < 0)
return (-i > ceil) ? -ceil : i;
else
return 0;
}
private void updateSprite(int delta_t) {
sprite.update(delta_t);
if (spriteGlow != null) {
spriteGlow.update(delta_t);
}
if (super.isGrounded()) {
if (walkHeading == LEFT) {
sprite.flip(true, false);
if (spriteGlow != null) {
spriteGlow.flip(true, false);
}
}
else {
sprite.flip(false, false);
if (spriteGlow != null) {
spriteGlow.flip(false, false);
}
}
}
}
public boolean isNoClip() {
return noClip;
}
public void setNoClip(boolean b) {
noClip = b;
}
public ActorValue getActorValue() {
return actorValue;
}
public SpriteAnimation getSpriteGlow() {
return spriteGlow;
}
@Override
public void assignFaction(Faction f) {
factionSet.add(f);
}
@Override
public void unassignFaction(Faction f) {
factionSet.remove(f);
}
@Override
public HashSet<Faction> getAssignedFactions() {
return factionSet;
}
@Override
public void clearFactionAssigning() {
factionSet.clear();
}
@Override
public void setLuminance(char RGB) {
actorValue.set("luminosity", (int) RGB);
}
@Override
public char getLuminance() {
return actorValue.hasKey("luminosity") ?
(char) actorValue.getAsInt("luminosity") : 0;
}
}

View File

@@ -1,46 +0,0 @@
package com.Torvald.Terrarum.Actors;
import com.Torvald.spriteAnimation.SpriteAnimation;
/**
* Created by minjaesong on 16-01-14.
*/
public class PlayerDebugger {
private Actor actor;
public PlayerDebugger(Actor actor) {
this.actor = actor;
}
public Player getPlayer() {
if (actor instanceof Player) {
return (Player) actor;
}
else {
throw new UnsupportedOperationException();
}
}
/**
* Delegates for Player instances
*/
public float baseHitboxW() { return getPlayer().getBaseHitboxW(); }
public float baseHitboxH() { return getPlayer().getBaseHitboxH(); }
public float hitboxTranslateX() { return getPlayer().getHitboxTranslateX(); }
public float hitboxTranslateY() { return getPlayer().getHitboxTranslateY(); }
public float veloX() { return getPlayer().getVeloX(); }
public float veloY() { return getPlayer().getVeloY(); }
public int baseSpriteWidth() { return getPlayer().baseSpriteWidth; }
public int baseSpriteHeight() { return getPlayer().baseSpriteHeight; }
public SpriteAnimation sprite() { return getPlayer().sprite; }
public float scale() { return getPlayer().getScale(); }
public Hitbox hitbox() { return getPlayer().getHitbox(); }
public Hitbox nextHitbox() { return getPlayer().getNextHitbox(); }
public boolean grounded() { return getPlayer().getGrounded(); }
public ActorValue actorValue() { return getPlayer().getActorValue(); }
public float mass() { return getPlayer().getMass(); }
public boolean noClip() { return getPlayer().isNoClip(); }
public int eventMoving() { return getPlayer().eventMoving; }
}

View File

@@ -1,15 +0,0 @@
package com.Torvald.Terrarum.Actors;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
/**
* Created by minjaesong on 16-01-25.
*/
public interface Visible {
void drawBody(GameContainer gc, Graphics g);
void updateBodySprite(GameContainer gc, int delta_t);
}

View File

@@ -1,6 +0,0 @@
* Terrarum by Torvald
Copyright 2015-2016 Torvald. All rights reserved.
mailto: alswo9628 *at* !gmail! *dot* !com!
* Simplex Noise Generator, version 2012-03-09 by Stefan Gustavson
Released as public domain

Some files were not shown because too many files have changed in this diff Show More