First pass at attacking

assumptions created:
creatures always have facing vector
animation frames for attack animation
items attached to attacking creatures have hitboxes
This commit is contained in:
austin 2021-07-03 23:25:11 -04:00
parent ef6116646a
commit f4bcc35cbf
36 changed files with 1059 additions and 221 deletions

View File

@ -1 +1,121 @@
{"state":"TITLE_MENU","controlsMap":{"moveForward":87,"menuType9":57,"menuTypeBackspace":259,"moveBackward":83,"menuType0":48,"menuType.":46,"fall":341,"moveRight":68,"menuSelect":257,"menuType7":55,"menuDecrement":265,"menuBackout":256,"menuType8":56,"moveLeft":65,"menuType5":53,"menuType6":54,"menuType3":51,"menuType4":52,"menuIncrement":264,"menuType1":49,"jump":32,"menuType2":50},"controlsState":{"moveForward":false,"menuType9":false,"menuTypeBackspace":false,"moveBackward":false,"menuType0":false,"menuType.":false,"fall":false,"moveRight":false,"menuSelect":false,"menuType7":false,"menuDecrement":false,"menuBackout":false,"menuType8":false,"moveLeft":false,"menuType5":false,"menuType6":false,"menuType3":false,"menuType4":false,"menuIncrement":false,"menuType1":false,"jump":false,"menuType2":false}} {
"state": "TITLE_MENU",
"mouseIsVisible" : true,
"controls": {
"moveForward": {
"isKey": true,
"isMouse": false,
"keyValue": 87
},
"menuType9": {
"isKey": true,
"isMouse": false,
"keyValue": 57
},
"menuTypeBackspace": {
"isKey": true,
"isMouse": false,
"keyValue": 259
},
"moveBackward": {
"isKey": true,
"isMouse": false,
"keyValue": 83
},
"menuType0": {
"isKey": true,
"isMouse": false,
"keyValue": 48
},
"menuType.": {
"isKey": true,
"isMouse": false,
"keyValue": 46
},
"fall": {
"isKey": true,
"isMouse": false,
"keyValue": 341
},
"moveRight": {
"isKey": true,
"isMouse": false,
"keyValue": 68
},
"menuSelect": {
"isKey": true,
"isMouse": false,
"keyValue": 257
},
"menuType7": {
"isKey": true,
"isMouse": false,
"keyValue": 55
},
"menuDecrement": {
"isKey": true,
"isMouse": false,
"keyValue": 265
},
"menuBackout": {
"isKey": true,
"isMouse": false,
"keyValue": 256
},
"menuType8": {
"isKey": true,
"isMouse": false,
"keyValue": 56
},
"moveLeft": {
"isKey": true,
"isMouse": false,
"keyValue": 65
},
"menuType5": {
"isKey": true,
"isMouse": false,
"keyValue": 53
},
"menuType6": {
"isKey": true,
"isMouse": false,
"keyValue": 54
},
"menuType3": {
"isKey": true,
"isMouse": false,
"keyValue": 51
},
"menuType4": {
"isKey": true,
"isMouse": false,
"keyValue": 52
},
"menuIncrement": {
"isKey": true,
"isMouse": false,
"keyValue": 264
},
"menuType1": {
"isKey": true,
"isMouse": false,
"keyValue": 49
},
"jump": {
"isKey": true,
"isMouse": false,
"keyValue": 32
},
"menuType2": {
"isKey": true,
"isMouse": false,
"keyValue": 50
},
"attackPrimary" : {
"isKey": false,
"isMouse": true,
"keyValue": 0
}
}
}

View File

@ -0,0 +1,51 @@
{
"state": "TITLE_MENU",
"controlsMap": {
"moveForward": 87,
"menuType9": 57,
"menuTypeBackspace": 259,
"moveBackward": 83,
"menuType0": 48,
"menuType.": 46,
"fall": 341,
"moveRight": 68,
"menuSelect": 257,
"menuType7": 55,
"menuDecrement": 265,
"menuBackout": 256,
"menuType8": 56,
"moveLeft": 65,
"menuType5": 53,
"menuType6": 54,
"menuType3": 51,
"menuType4": 52,
"menuIncrement": 264,
"menuType1": 49,
"jump": 32,
"menuType2": 50
},
"controlsState": {
"moveForward": false,
"menuType9": false,
"menuTypeBackspace": false,
"moveBackward": false,
"menuType0": false,
"menuType.": false,
"fall": false,
"moveRight": false,
"menuSelect": false,
"menuType7": false,
"menuDecrement": false,
"menuBackout": false,
"menuType8": false,
"moveLeft": false,
"menuType5": false,
"menuType6": false,
"menuType3": false,
"menuType4": false,
"menuIncrement": false,
"menuType1": false,
"jump": false,
"menuType2": false
}
}

View File

@ -87,7 +87,7 @@
{ {
"type" : "GROUND", "type" : "GROUND",
"acceleration" : 0.001, "acceleration" : 0.001,
"maxVelocity" : 0.025 "maxVelocity" : 0.015
} }
], ],
"modelPath" : "/Models/person1walkanim.fbx" "modelPath" : "/Models/person1walkanim.fbx"
@ -176,7 +176,8 @@
], ],
"tokens" : [ "tokens" : [
"BLENDER_TRANSFORM", "BLENDER_TRANSFORM",
"SENTIENT" "SENTIENT",
"ATTACKER"
], ],
"movementSystems" : [ "movementSystems" : [
{ {

View File

@ -5,7 +5,7 @@
{ {
"name" : "Katana", "name" : "Katana",
"modelPath" : "/Models/katana1alt.fbx", "modelPath" : "Models/katana1alt.fbx",
"hitboxes" : [ "hitboxes" : [
{ {
"type": "hit", "type": "hit",

Binary file not shown.

Binary file not shown.

View File

@ -30,8 +30,14 @@
"/Textures/transparent_red.png" "/Textures/transparent_red.png"
] ]
}, },
"Models/unitsphere_grey.fbx": {
"Sphere": [
"/Textures/transparent_grey.png",
"/Textures/transparent_grey.png"
]
},
"Models/katana1alt.fbx": { "Models/katana1alt.fbx": {
"SwordMesh": [ "Cube.001": [
"/Textures/katana1.png", "/Textures/katana1.png",
"/Textures/katana1.png" "/Textures/katana1.png"
] ]

Binary file not shown.

After

Width:  |  Height:  |  Size: 194 B

View File

@ -0,0 +1,37 @@
package electrosphere.controls;
public class Control {
boolean isKey;
boolean isMouse;
boolean state;
int keyValue;
public boolean isIsKey() {
return isKey;
}
public boolean isIsMouse() {
return isMouse;
}
public boolean isState() {
return state;
}
public int getKeyValue() {
return keyValue;
}
public void setState(boolean state) {
this.state = state;
}
public Control(boolean isKey, boolean isMouse, int keyValue) {
this.isKey = isKey;
this.isMouse = isMouse;
this.keyValue = keyValue;
this.state = false;
}
}

View File

@ -3,6 +3,7 @@ package electrosphere.controls;
import electrosphere.entity.CameraEntityUtils; import electrosphere.entity.CameraEntityUtils;
import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.entity.EntityUtils; import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.AttackTree;
import electrosphere.entity.state.MovementTree; import electrosphere.entity.state.MovementTree;
import electrosphere.entity.state.MovementTree.MovementTreeState; import electrosphere.entity.state.MovementTree.MovementTreeState;
import electrosphere.main.Globals; import electrosphere.main.Globals;
@ -12,7 +13,12 @@ import electrosphere.net.parser.net.message.EntityMessage;
import electrosphere.util.Utilities; import electrosphere.util.Utilities;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import org.joml.Vector2f;
import org.joml.Vector3f; import org.joml.Vector3f;
import static org.lwjgl.glfw.GLFW.GLFW_CURSOR;
import static org.lwjgl.glfw.GLFW.GLFW_CURSOR_DISABLED;
import static org.lwjgl.glfw.GLFW.GLFW_CURSOR_HIDDEN;
import static org.lwjgl.glfw.GLFW.GLFW_CURSOR_NORMAL;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_0; import static org.lwjgl.glfw.GLFW.GLFW_KEY_0;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_1; import static org.lwjgl.glfw.GLFW.GLFW_KEY_1;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_2; import static org.lwjgl.glfw.GLFW.GLFW_KEY_2;
@ -35,8 +41,12 @@ import static org.lwjgl.glfw.GLFW.GLFW_KEY_S;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_SPACE; import static org.lwjgl.glfw.GLFW.GLFW_KEY_SPACE;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_UP; import static org.lwjgl.glfw.GLFW.GLFW_KEY_UP;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_W; import static org.lwjgl.glfw.GLFW.GLFW_KEY_W;
import static org.lwjgl.glfw.GLFW.GLFW_MOUSE_BUTTON_LEFT;
import static org.lwjgl.glfw.GLFW.GLFW_PRESS; import static org.lwjgl.glfw.GLFW.GLFW_PRESS;
import static org.lwjgl.glfw.GLFW.glfwGetCursorPos;
import static org.lwjgl.glfw.GLFW.glfwGetKey; import static org.lwjgl.glfw.GLFW.glfwGetKey;
import static org.lwjgl.glfw.GLFW.glfwGetMouseButton;
import static org.lwjgl.glfw.GLFW.glfwSetInputMode;
/** /**
* *
@ -50,6 +60,7 @@ public class ControlHandler {
public static final String DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT = "moveRight"; public static final String DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT = "moveRight";
public static final String DATA_STRING_INPUT_CODE_MOVEMENT_JUMP = "jump"; public static final String DATA_STRING_INPUT_CODE_MOVEMENT_JUMP = "jump";
public static final String DATA_STRING_INPUT_CODE_MOVEMENT_FALL = "fall"; public static final String DATA_STRING_INPUT_CODE_MOVEMENT_FALL = "fall";
public static final String DATA_STRING_INPUT_CODE_ATTACK_PRIMARY = "attackPrimary";
public static final String DATA_STRING_INPUT_CODE_MENU_INCREMENT = "menuIncrement"; public static final String DATA_STRING_INPUT_CODE_MENU_INCREMENT = "menuIncrement";
public static final String DATA_STRING_INPUT_CODE_MENU_DECREMENT = "menuDecrement"; public static final String DATA_STRING_INPUT_CODE_MENU_DECREMENT = "menuDecrement";
@ -80,13 +91,12 @@ public class ControlHandler {
ControlsState state = ControlsState.TITLE_MENU; ControlsState state = ControlsState.TITLE_MENU;
boolean mouseIsVisible = true;
HashMap<String, Integer> controlsMap; HashMap<String, Control> controls;
HashMap<String, Boolean> controlsState;
ControlHandler(){ ControlHandler(){
controlsMap = new HashMap(); controls = new HashMap();
controlsState = new HashMap();
} }
public static ControlHandler generateExampleControlsMap(){ public static ControlHandler generateExampleControlsMap(){
@ -98,71 +108,37 @@ public class ControlHandler {
/* /*
Map the controls Map the controls
*/ */
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD, GLFW_KEY_W); handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD, new Control(true,false,GLFW_KEY_W));
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD, GLFW_KEY_S); handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD, new Control(true,false,GLFW_KEY_S));
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT, GLFW_KEY_A); handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT, new Control(true,false,GLFW_KEY_A));
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT, GLFW_KEY_D); handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT, new Control(true,false,GLFW_KEY_D));
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP, GLFW_KEY_SPACE); handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP, new Control(true,false,GLFW_KEY_SPACE));
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_FALL, GLFW_KEY_LEFT_CONTROL); handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_FALL, new Control(true,false,GLFW_KEY_LEFT_CONTROL));
handler.addControl(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY, new Control(false,true,GLFW_MOUSE_BUTTON_LEFT));
/*
Set their states to false(not pressed)
*/
handler.addControlState(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MOVEMENT_FALL, false);
/* /*
Map the menu navigation controls Map the menu navigation controls
*/ */
handler.addControl(DATA_STRING_INPUT_CODE_MENU_INCREMENT, GLFW_KEY_DOWN); handler.addControl(DATA_STRING_INPUT_CODE_MENU_INCREMENT, new Control(true,false,GLFW_KEY_DOWN));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_DECREMENT, GLFW_KEY_UP); handler.addControl(DATA_STRING_INPUT_CODE_MENU_DECREMENT, new Control(true,false,GLFW_KEY_UP));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_SELECT, GLFW_KEY_ENTER); handler.addControl(DATA_STRING_INPUT_CODE_MENU_SELECT, new Control(true,false,GLFW_KEY_ENTER));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_BACKOUT, GLFW_KEY_ESCAPE); handler.addControl(DATA_STRING_INPUT_CODE_MENU_BACKOUT, new Control(true,false,GLFW_KEY_ESCAPE));
/*
Set their states to false(not pressed)
*/
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_INCREMENT, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_DECREMENT, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_SELECT, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_BACKOUT, false);
/* /*
Map the typing controls Map the typing controls
*/ */
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_BACKSPACE, GLFW_KEY_BACKSPACE); handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_BACKSPACE, new Control(true,false,GLFW_KEY_BACKSPACE));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_0, GLFW_KEY_0); handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_0, new Control(true,false,GLFW_KEY_0));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_1, GLFW_KEY_1); handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_1, new Control(true,false,GLFW_KEY_1));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_2, GLFW_KEY_2); handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_2, new Control(true,false,GLFW_KEY_2));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_3, GLFW_KEY_3); handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_3, new Control(true,false,GLFW_KEY_3));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_4, GLFW_KEY_4); handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_4, new Control(true,false,GLFW_KEY_4));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_5, GLFW_KEY_5); handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_5, new Control(true,false,GLFW_KEY_5));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_6, GLFW_KEY_6); handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_6, new Control(true,false,GLFW_KEY_6));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_7, GLFW_KEY_7); handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_7, new Control(true,false,GLFW_KEY_7));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_8, GLFW_KEY_8); handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_8, new Control(true,false,GLFW_KEY_8));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_9, GLFW_KEY_9); handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_9, new Control(true,false,GLFW_KEY_9));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_PERIOD, GLFW_KEY_PERIOD); handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_PERIOD, new Control(true,false,GLFW_KEY_PERIOD));
/*
Set their states to false
*/
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_TYPE_BACKSPACE, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_TYPE_0, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_TYPE_1, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_TYPE_2, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_TYPE_3, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_TYPE_4, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_TYPE_5, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_TYPE_6, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_TYPE_7, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_TYPE_8, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_TYPE_9, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_TYPE_PERIOD, false);
/* /*
set state set state
@ -209,17 +185,18 @@ public class ControlHandler {
public void pollMainGameControls(){ public void pollMainGameControls(){
if(Globals.playerCharacter != null){ if(Globals.playerCharacter != null){
MovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter); MovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter);
AttackTree attackTree = CreatureUtils.getAttackTree(Globals.playerCharacter);
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
/* /*
Move forward Move forward
*/ */
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD)){ if(controls.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD)){
if(glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD)) == GLFW_PRESS){ if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue()) == GLFW_PRESS){
CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3f(-cameraEyeVector.x,0,-cameraEyeVector.z).normalize()); CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3f(-cameraEyeVector.x,0,-cameraEyeVector.z).normalize());
if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){ if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){
movementTree.start(); movementTree.start();
} }
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD, true); controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).setState(true);
//send to server //send to server
// Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter); // Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter);
// EntityMessage outgoingMessage = EntityMessage.constructMoveMessage( // EntityMessage outgoingMessage = EntityMessage.constructMoveMessage(
@ -231,22 +208,22 @@ public class ControlHandler {
// ); // );
// Globals.clientConnection.queueOutgoingMessage(outgoingMessage); // Globals.clientConnection.queueOutgoingMessage(outgoingMessage);
} else { } else {
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD) == true){ if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isState() == true){
movementTree.slowdown(); movementTree.slowdown();
} }
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD, false); controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).setState(false);
} }
} }
/* /*
Move backward Move backward
*/ */
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD)){ if(controls.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD)){
if(glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD)) == GLFW_PRESS){ if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).getKeyValue()) == GLFW_PRESS){
CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3f(cameraEyeVector.x,0,cameraEyeVector.z).normalize()); CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3f(cameraEyeVector.x,0,cameraEyeVector.z).normalize());
if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){ if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){
movementTree.start(); movementTree.start();
} }
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD, true); controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).setState(true);
//send to server //send to server
// Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter); // Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter);
// EntityMessage outgoingMessage = EntityMessage.constructMoveMessage( // EntityMessage outgoingMessage = EntityMessage.constructMoveMessage(
@ -258,22 +235,22 @@ public class ControlHandler {
// ); // );
// Globals.clientConnection.queueOutgoingMessage(outgoingMessage); // Globals.clientConnection.queueOutgoingMessage(outgoingMessage);
} else { } else {
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD) == true){ if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isState() == true){
movementTree.slowdown(); movementTree.slowdown();
} }
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD, false); controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).setState(false);
} }
} }
/* /*
Move left Move left
*/ */
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT)){ if(controls.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT)){
if(glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT)) == GLFW_PRESS){ if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).isIsKey() && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).getKeyValue()) == GLFW_PRESS){
CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3f(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY((float)(90 * Math.PI / 180)).normalize()); CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3f(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY((float)(90 * Math.PI / 180)).normalize());
if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){ if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){
movementTree.start(); movementTree.start();
} }
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT, true); controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).setState(true);
//send to server //send to server
// Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter); // Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter);
// EntityMessage outgoingMessage = EntityMessage.constructMoveMessage( // EntityMessage outgoingMessage = EntityMessage.constructMoveMessage(
@ -285,22 +262,22 @@ public class ControlHandler {
// ); // );
// Globals.clientConnection.queueOutgoingMessage(outgoingMessage); // Globals.clientConnection.queueOutgoingMessage(outgoingMessage);
} else { } else {
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT) == true){ if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).isState() == true){
movementTree.slowdown(); movementTree.slowdown();
} }
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT, false); controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).setState(false);
} }
} }
/* /*
Move right Move right
*/ */
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT)){ if(controls.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT)){
if(glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT)) == GLFW_PRESS){ if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).isIsKey() && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).getKeyValue()) == GLFW_PRESS){
CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3f(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY((float)(-90 * Math.PI / 180)).normalize()); CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3f(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY((float)(-90 * Math.PI / 180)).normalize());
if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){ if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){
movementTree.start(); movementTree.start();
} }
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT, true); controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).setState(true);
//send to server //send to server
// Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter); // Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter);
// EntityMessage outgoingMessage = EntityMessage.constructMoveMessage( // EntityMessage outgoingMessage = EntityMessage.constructMoveMessage(
@ -312,66 +289,84 @@ public class ControlHandler {
// ); // );
// Globals.clientConnection.queueOutgoingMessage(outgoingMessage); // Globals.clientConnection.queueOutgoingMessage(outgoingMessage);
} else { } else {
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT) == true){ if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).isState() == true){
movementTree.slowdown(); movementTree.slowdown();
} }
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT, false); controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).setState(false);
} }
} }
/* /*
Move up Move up
*/ */
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP) && glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP)) == GLFW_PRESS){ if(controls.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP) && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP).getKeyValue()) == GLFW_PRESS){
EntityUtils.getPosition(Globals.playerCharacter).add(new Vector3f(0,0.6f,0).mul(1f)); EntityUtils.getPosition(Globals.playerCharacter).add(new Vector3f(0,0.6f,0).mul(1f));
} }
/* /*
Move down Move down
*/ */
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_FALL) && glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FALL)) == GLFW_PRESS){ if(controls.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_FALL) && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FALL).getKeyValue()) == GLFW_PRESS){
EntityUtils.getPosition(Globals.playerCharacter).add(new Vector3f(0,-0.6f,0).mul(1f)); EntityUtils.getPosition(Globals.playerCharacter).add(new Vector3f(0,-0.6f,0).mul(1f));
} }
/*
Attack
*/
if(controls.containsKey(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY)){
if(controls.get(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY).isIsMouse() && glfwGetMouseButton(Globals.window, controls.get(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY).getKeyValue()) == GLFW_PRESS){
if(controls.get(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY).isState() == false){
if(attackTree != null){
attackTree.start();
}
}
controls.get(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY).setState(true);
} else {
if(controls.get(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY).isState() == true){
}
controls.get(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY).setState(false);
}
}
} }
} }
public void pollMenuNavigationControls(){ public void pollMenuNavigationControls(){
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MENU_INCREMENT)){ if(controls.containsKey(DATA_STRING_INPUT_CODE_MENU_INCREMENT)){
if(glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT)) == GLFW_PRESS){ if(controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).isIsKey() && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).getKeyValue()) == GLFW_PRESS){
controlsState.put(DATA_STRING_INPUT_CODE_MENU_INCREMENT, true); controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).setState(true);
} else { } else {
if(controlsState.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT) == true){ if(controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).isState() == true){
Globals.currentMenu.incrementMenuOption(); Globals.currentMenu.incrementMenuOption();
} }
controlsState.put(DATA_STRING_INPUT_CODE_MENU_INCREMENT, false); controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).setState(false);
} }
} }
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MENU_DECREMENT)){ if(controls.containsKey(DATA_STRING_INPUT_CODE_MENU_DECREMENT)){
if(glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MENU_DECREMENT)) == GLFW_PRESS){ if(controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).isIsKey() && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_MENU_DECREMENT).getKeyValue()) == GLFW_PRESS){
controlsState.put(DATA_STRING_INPUT_CODE_MENU_DECREMENT, true); controls.get(DATA_STRING_INPUT_CODE_MENU_DECREMENT).setState(true);
} else { } else {
if(controlsState.get(DATA_STRING_INPUT_CODE_MENU_DECREMENT) == true){ if(controls.get(DATA_STRING_INPUT_CODE_MENU_DECREMENT).isState() == true){
Globals.currentMenu.decrementMenuOption(); Globals.currentMenu.decrementMenuOption();
} }
controlsState.put(DATA_STRING_INPUT_CODE_MENU_DECREMENT, false); controls.get(DATA_STRING_INPUT_CODE_MENU_DECREMENT).setState(false);
} }
} }
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MENU_SELECT)){ if(controls.containsKey(DATA_STRING_INPUT_CODE_MENU_SELECT)){
if(glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MENU_SELECT)) == GLFW_PRESS){ if(controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).isIsKey() && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_MENU_SELECT).getKeyValue()) == GLFW_PRESS){
controlsState.put(DATA_STRING_INPUT_CODE_MENU_SELECT, true); controls.get(DATA_STRING_INPUT_CODE_MENU_SELECT).setState(true);
} else { } else {
if(controlsState.get(DATA_STRING_INPUT_CODE_MENU_SELECT) == true){ if(controls.get(DATA_STRING_INPUT_CODE_MENU_SELECT).isState() == true){
MenuTransition.selectOption(Globals.currentMenu); MenuTransition.selectOption(Globals.currentMenu);
} }
controlsState.put(DATA_STRING_INPUT_CODE_MENU_SELECT, false); controls.get(DATA_STRING_INPUT_CODE_MENU_SELECT).setState(false);
} }
} }
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MENU_BACKOUT)){ if(controls.containsKey(DATA_STRING_INPUT_CODE_MENU_BACKOUT)){
if(glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT)) == GLFW_PRESS){ if(controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).isIsKey() && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT).getKeyValue()) == GLFW_PRESS){
controlsState.put(DATA_STRING_INPUT_CODE_MENU_BACKOUT, true); controls.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT).setState(true);
} else { } else {
if(controlsState.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT) == true){ if(controls.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT).isState() == true){
MenuTransition.backout(Globals.currentMenu); MenuTransition.backout(Globals.currentMenu);
} }
controlsState.put(DATA_STRING_INPUT_CODE_MENU_BACKOUT, false); controls.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT).setState(false);
} }
} }
} }
@ -393,35 +388,31 @@ public class ControlHandler {
DATA_STRING_INPUT_CODE_MENU_TYPE_PERIOD, DATA_STRING_INPUT_CODE_MENU_TYPE_PERIOD,
}; };
for(String currentKey : typeKeybinds){ for(String currentKey : typeKeybinds){
if(glfwGetKey(Globals.window, controlsMap.get(currentKey)) == GLFW_PRESS){ if(controls.get(currentKey).isIsKey() && glfwGetKey(Globals.window, controls.get(currentKey).getKeyValue()) == GLFW_PRESS){
controlsState.put(currentKey, true); controls.get(currentKey).setState(true);
} else { } else {
if(controlsState.get(currentKey) == true){ if(controls.get(currentKey).isState() == true){
MenuTransition.menuType(Globals.currentMenu,currentKey); MenuTransition.menuType(Globals.currentMenu,currentKey);
} }
controlsState.put(currentKey, false); controls.get(currentKey).setState(false);
} }
} }
} }
public Integer getControl(String controlName){ public Control getControl(String controlName){
return controlsMap.get(controlName); return controls.get(controlName);
} }
public boolean containsControl(String controlName){ public boolean containsControl(String controlName){
return controlsMap.containsKey(controlName); return controls.containsKey(controlName);
} }
public void removeControl(String controlName){ public void removeControl(String controlName){
controlsMap.remove(controlName); controls.remove(controlName);
} }
public void addControl(String controlName, int keyCode){ public void addControl(String controlName, Control c){
controlsMap.put(controlName, keyCode); controls.put(controlName, c);
}
public void addControlState(String controlName, boolean state){
controlsState.put(controlName,state);
} }
public void setHandlerState(ControlsState state){ public void setHandlerState(ControlsState state){
@ -432,4 +423,28 @@ public class ControlHandler {
return state; return state;
} }
public void hideMouse(){
glfwSetInputMode(Globals.window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
mouseIsVisible = false;
}
public void showMouse(){
glfwSetInputMode(Globals.window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
mouseIsVisible = true;
}
public boolean isMouseVisible(){
return mouseIsVisible;
}
public Vector2f getMousePosition(){
double posX[] = new double[1];
double posY[] = new double[1];
glfwGetCursorPos(Globals.window, posX, posY);
Vector2f rVal = new Vector2f((float)posX[0],(float)posY[0]);
return rVal;
}
} }

View File

@ -136,8 +136,13 @@ public class LoadingThread extends Thread {
//initialize the "real" objects simulation //initialize the "real" objects simulation
initMicroSimulation(); initMicroSimulation();
//hide cursor
Globals.controlHandler.hideMouse();
loadingBox.setDraw(false); loadingBox.setDraw(false);
RenderUtils.recaptureScreen();
Globals.RENDER_FLAG_RENDER_SHADOW_MAP = true; Globals.RENDER_FLAG_RENDER_SHADOW_MAP = true;
Globals.RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER_CONTENT = true; Globals.RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER_CONTENT = true;
Globals.RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER = true; Globals.RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER = true;
@ -205,6 +210,9 @@ public class LoadingThread extends Thread {
//initialize the "real" objects simulation //initialize the "real" objects simulation
initMicroSimulation(); initMicroSimulation();
//hide cursor
Globals.controlHandler.hideMouse();
loadingBox.setDraw(false); loadingBox.setDraw(false);
Globals.RENDER_FLAG_RENDER_SHADOW_MAP = true; Globals.RENDER_FLAG_RENDER_SHADOW_MAP = true;

View File

@ -76,17 +76,15 @@ public class EntityDataStrings {
public static final String DATA_STRING_COLLISION_ENTITY = "collisionEntity"; public static final String DATA_STRING_COLLISION_ENTITY = "collisionEntity";
public static final String DATA_STRING_COLLISION_ENTITY_TYPE_SPHERE = "collisionSphere"; public static final String DATA_STRING_COLLISION_ENTITY_TYPE_SPHERE = "collisionSphere";
public static final String COLLISION_ENTITY_DATA_TYPE = "collisionDataType";
public static final String COLLISION_ENTITY_DATA_TYPE_HIT = "collisionDataTypeHit"; public static final String COLLISION_ENTITY_DATA_TYPE_HIT = "collisionDataTypeHit";
public static final String COLLISION_ENTITY_DATA_TYPE_HURT = "collisionDataTypeHurt"; public static final String COLLISION_ENTITY_DATA_TYPE_HURT = "collisionDataTypeHurt";
public static final String COLLISION_ENTITY_DATA_PARENT = "collisionDataParent"; public static final String COLLISION_ENTITY_DATA_PARENT = "collisionDataParent";
public static final String COLLISION_ENTITY_DATA_BONE = "collisionDataBone";
public static final String COLLISION_ENTITY_DATA_RADIUS = "collisionSphereRadius";
public static final String COLLISION_ENTITY_BEHAVIOR_TREE = "collisionEntityBehaviorTree"; public static final String COLLISION_ENTITY_BEHAVIOR_TREE = "collisionEntityBehaviorTree";
public static final String HITBOX_DATA = "hitboxData";
/* /*
Attach Entity Attach Entity
@ -94,6 +92,7 @@ public class EntityDataStrings {
public static final String ATTACH_ENTITY_IS_ATTACHED = "attachIsAttached"; public static final String ATTACH_ENTITY_IS_ATTACHED = "attachIsAttached";
public static final String ATTACH_PARENT = "attachParent"; public static final String ATTACH_PARENT = "attachParent";
public static final String ATTACH_TARGET_BONE = "attachTargetBone"; public static final String ATTACH_TARGET_BONE = "attachTargetBone";
public static final String ATTACH_CHILDREN_LIST = "attachChildrenList";
/* /*
Item Entity Item Entity
@ -102,4 +101,14 @@ public class EntityDataStrings {
public static final String ITEM_TYPE = "itemType"; public static final String ITEM_TYPE = "itemType";
/*
Attack behavior tree
*/
public static final String ATTACK_TREE = "attackTree";
/*
idle behavior tree
*/
public static final String IDLE_TREE = "idleTree";
} }

View File

@ -20,6 +20,8 @@ public class EntityManager {
static CopyOnWriteArrayList<Entity> uiList = new CopyOnWriteArrayList(); static CopyOnWriteArrayList<Entity> uiList = new CopyOnWriteArrayList();
static CopyOnWriteArrayList<Entity> itemList = new CopyOnWriteArrayList(); static CopyOnWriteArrayList<Entity> itemList = new CopyOnWriteArrayList();
static CopyOnWriteArrayList<Entity> attachList = new CopyOnWriteArrayList(); static CopyOnWriteArrayList<Entity> attachList = new CopyOnWriteArrayList();
static CopyOnWriteArrayList<Entity> attackerList = new CopyOnWriteArrayList();
static CopyOnWriteArrayList<Entity> creatureList = new CopyOnWriteArrayList();
public EntityManager(){ public EntityManager(){
@ -78,6 +80,22 @@ public class EntityManager {
return attachList; return attachList;
} }
public void registerAttackerEntity(Entity e){
attackerList.add(e);
}
public CopyOnWriteArrayList<Entity> getAttackerEntities(){
return attackerList;
}
public void registerCreatureEntity(Entity e){
creatureList.add(e);
}
public CopyOnWriteArrayList<Entity> getCreatureEntities(){
return creatureList;
}
public void deregisterEntity(Entity e){ public void deregisterEntity(Entity e){
if(lightList.contains(e)){ if(lightList.contains(e)){
lightList.remove(e); lightList.remove(e);
@ -98,6 +116,12 @@ public class EntityManager {
if(itemList.contains(e)){ if(itemList.contains(e)){
itemList.remove(e); itemList.remove(e);
} }
if(attackerList.contains(e)){
attackerList.remove(e);
}
if(creatureList.contains(e)){
creatureList.remove(e);
}
} }
public void overrideEntityId(Entity e, int id){ public void overrideEntityId(Entity e, int id){

View File

@ -0,0 +1,162 @@
package electrosphere.entity.state;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.entity.types.hitbox.HitboxUtils;
import electrosphere.main.Globals;
import electrosphere.net.parser.net.message.EntityMessage;
import electrosphere.renderer.Actor;
import electrosphere.renderer.anim.Animation;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.joml.Vector3f;
public class AttackTree {
public static enum AttackTreeState {
WINDUP,
ATTACK,
COOLDOWN,
IDLE,
}
AttackTreeState state;
Entity parent;
CopyOnWriteArrayList<EntityMessage> networkMessageQueue = new CopyOnWriteArrayList();
int frameCurrent;
int maxFrame = 60;
public AttackTree(Entity e){
state = AttackTreeState.IDLE;
parent = e;
}
public AttackTreeState getState(){
return state;
}
public void start(){
//TODO: check if can start moving
state = AttackTreeState.WINDUP;
frameCurrent = 0;
}
public void interrupt(){
state = AttackTreeState.IDLE;
}
public void slowdown(){
state = AttackTreeState.COOLDOWN;
}
public void simulate(){
float velocity = CreatureUtils.getVelocity(parent);
float acceleration = CreatureUtils.getAcceleration(parent);
float maxNaturalVelocity = CreatureUtils.getMaxNaturalVelocity(parent);
Actor entityActor = EntityUtils.getActor(parent);
// Model entityModel = Globals.assetManager.fetchModel(EntityUtils.getEntityModelPath(parent));
Vector3f position = EntityUtils.getPosition(parent);
Vector3f movementVector = CreatureUtils.getMovementVector(parent);
Vector3f newPosition;
//parse attached network messages
for(EntityMessage message : networkMessageQueue){
networkMessageQueue.remove(message);
// System.out.println("MOVE to " + message.getX() + " " + message.getY() + " " + message.getZ());
switch(message.getMessageSubtype()){
case ATTACKUPDATE:
switch(message.gettreeState()){
case 0:
state = AttackTreeState.WINDUP;
frameCurrent = 0;
// System.out.println("Set state STARTUP");
break;
case 1:
frameCurrent = 16;
state = AttackTreeState.ATTACK;
// System.out.println("Set state MOVE");
break;
case 2:
frameCurrent = 31;
state = AttackTreeState.COOLDOWN;
// System.out.println("Set state SLOWDOWN");
break;
case 3:
frameCurrent = 46;
state = AttackTreeState.IDLE;
// System.out.println("Set state IDLE");
break;
}
EntityUtils.getPosition(parent).set(message.getpositionX(),message.getpositionY(),message.getpositionZ());
CreatureUtils.setMovementVector(parent, new Vector3f(message.getrotationX(),message.getrotationY(),message.getrotationZ()));
break;
}
}
//state machine
switch(state){
case WINDUP:
if(entityActor != null){
if(!entityActor.isPlayingAnimation() || !entityActor.getCurrentAnimation().equals(Animation.ANIMATION_SWING_PRIMARY)){
entityActor.playAnimation(Animation.ANIMATION_SWING_PRIMARY);
entityActor.incrementAnimationTime(0.01);
}
}
frameCurrent++;
if(frameCurrent > 7){
state = AttackTreeState.ATTACK;
}
break;
case ATTACK:
if(parent.getDataKeys().contains(EntityDataStrings.ATTACH_CHILDREN_LIST)){
List<Entity> attachedEntities = (List<Entity>)parent.getData(EntityDataStrings.ATTACH_CHILDREN_LIST);
for(Entity currentAttached : attachedEntities){
if(currentAttached.getDataKeys().contains(EntityDataStrings.ITEM_IS_ITEM)){
for(Entity hitbox : Globals.hitboxManager.getAllHitboxes()){
if(hitbox.getData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT) == currentAttached){
HitboxUtils.getHitboxData(hitbox).setActive(true);
}
}
}
}
}
frameCurrent++;
if(frameCurrent > 30){
state = AttackTreeState.COOLDOWN;
}
break;
case COOLDOWN:
if(parent.getDataKeys().contains(EntityDataStrings.ATTACH_CHILDREN_LIST)){
List<Entity> attachedEntities = (List<Entity>)parent.getData(EntityDataStrings.ATTACH_CHILDREN_LIST);
for(Entity currentAttached : attachedEntities){
if(currentAttached.getDataKeys().contains(EntityDataStrings.ITEM_IS_ITEM)){
for(Entity hitbox : Globals.hitboxManager.getAllHitboxes()){
if(hitbox.getData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT) == currentAttached){
HitboxUtils.getHitboxData(hitbox).setActive(false);
}
}
}
}
}
frameCurrent++;
if(frameCurrent > 45){
state = AttackTreeState.IDLE;
frameCurrent = 0;
}
break;
case IDLE:
break;
}
}
public void addNetworkMessage(EntityMessage networkMessage) {
networkMessageQueue.add(networkMessage);
}
}

View File

@ -0,0 +1,139 @@
package electrosphere.entity.state;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.AttackTree.AttackTreeState;
import electrosphere.entity.state.MovementTree.MovementTreeState;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.net.parser.net.message.EntityMessage;
import electrosphere.renderer.Actor;
import electrosphere.renderer.anim.Animation;
import java.util.concurrent.CopyOnWriteArrayList;
import org.joml.Vector3f;
public class IdleTree {
public static enum IdleTreeState {
IDLE,
NOT_IDLE,
}
IdleTreeState state;
Entity parent;
CopyOnWriteArrayList<EntityMessage> networkMessageQueue = new CopyOnWriteArrayList();
int frameCurrent;
int maxFrame = 60;
public IdleTree(Entity e){
state = IdleTreeState.IDLE;
parent = e;
}
public IdleTreeState getState(){
return state;
}
public void start(){
//TODO: check if can start moving
state = IdleTreeState.IDLE;
frameCurrent = 0;
}
public void interrupt(){
state = IdleTreeState.NOT_IDLE;
}
public void stop(){
state = IdleTreeState.NOT_IDLE;
}
public void simulate(){
float velocity = CreatureUtils.getVelocity(parent);
float acceleration = CreatureUtils.getAcceleration(parent);
float maxNaturalVelocity = CreatureUtils.getMaxNaturalVelocity(parent);
Actor entityActor = EntityUtils.getActor(parent);
Vector3f position = EntityUtils.getPosition(parent);
Vector3f movementVector = CreatureUtils.getMovementVector(parent);
Vector3f newPosition;
boolean hasMovementTree = parent.getDataKeys().contains(EntityDataStrings.DATA_STRING_MOVEMENT_BT);
MovementTree movementTree = CreatureUtils.getEntityMovementTree(parent);
boolean hasAttackTree = parent.getDataKeys().contains(EntityDataStrings.ATTACK_TREE);
AttackTree attackTree = CreatureUtils.getAttackTree(parent);
//parse attached network messages
for(EntityMessage message : networkMessageQueue){
networkMessageQueue.remove(message);
// System.out.println("MOVE to " + message.getX() + " " + message.getY() + " " + message.getZ());
switch(message.getMessageSubtype()){
case ATTACKUPDATE:
switch(message.gettreeState()){
case 0:
state = IdleTreeState.IDLE;
break;
case 1:
state = IdleTreeState.NOT_IDLE;
break;
}
EntityUtils.getPosition(parent).set(message.getpositionX(),message.getpositionY(),message.getpositionZ());
CreatureUtils.setMovementVector(parent, new Vector3f(message.getrotationX(),message.getrotationY(),message.getrotationZ()));
break;
}
}
boolean isIdle;
//state machine
switch(state){
case IDLE:
if(entityActor != null){
if(!entityActor.isPlayingAnimation() || !entityActor.getCurrentAnimation().equals(Animation.ANIMATION_IDLE_1)){
entityActor.playAnimation(Animation.ANIMATION_IDLE_1);
entityActor.incrementAnimationTime(0.01);
}
}
isIdle = true;
if(hasMovementTree){
if(movementTree.getState() != MovementTreeState.IDLE){
isIdle = false;
}
}
if(hasAttackTree){
if(attackTree.getState() != AttackTreeState.IDLE){
isIdle = false;
}
}
if(!isIdle){
state = IdleTreeState.NOT_IDLE;
}
break;
case NOT_IDLE:
isIdle = true;
if(hasMovementTree){
if(movementTree.getState() != MovementTreeState.IDLE){
isIdle = false;
}
}
if(hasAttackTree){
if(attackTree.getState() != AttackTreeState.IDLE){
isIdle = false;
}
}
if(isIdle){
state = IdleTreeState.IDLE;
}
break;
}
}
public void addNetworkMessage(EntityMessage networkMessage) {
networkMessageQueue.add(networkMessage);
}
}

View File

@ -14,10 +14,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
import org.joml.Quaternionf; import org.joml.Quaternionf;
import org.joml.Vector3f; import org.joml.Vector3f;
/**
*
* @author amaterasu
*/
/* /*
Behavior tree for movement in an entity Behavior tree for movement in an entity
*/ */
@ -94,7 +90,7 @@ public class MovementTree {
case SETFACING: case SETFACING:
break; break;
case MOVEUPDATE: case MOVEUPDATE:
switch(message.getmoveState()){ switch(message.gettreeState()){
case 0: case 0:
state = MovementTreeState.STARTUP; state = MovementTreeState.STARTUP;
// System.out.println("Set state STARTUP"); // System.out.println("Set state STARTUP");
@ -284,12 +280,12 @@ public class MovementTree {
} }
break; break;
case IDLE: case IDLE:
if(entityActor != null){ // if(entityActor != null){
if(!entityActor.isPlayingAnimation() || !entityActor.getCurrentAnimation().equals(Animation.ANIMATION_IDLE_1)){ // if(!entityActor.isPlayingAnimation() || !entityActor.getCurrentAnimation().equals(Animation.ANIMATION_IDLE_1)){
entityActor.playAnimation(Animation.ANIMATION_IDLE_1); // entityActor.playAnimation(Animation.ANIMATION_IDLE_1);
entityActor.incrementAnimationTime(0.01); // entityActor.incrementAnimationTime(0.01);
} // }
} // }
if(Globals.collisionEngine.gravityCheck(Globals.commonWorldData, parent)){ if(Globals.collisionEngine.gravityCheck(Globals.commonWorldData, parent)){
EntityUtils.getPosition(parent).set(Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData,parent,new Vector3f(position.x,position.y - 9.8f,position.z))); EntityUtils.getPosition(parent).set(Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData,parent,new Vector3f(position.x,position.y - 9.8f,position.z)));
} }

View File

@ -3,8 +3,11 @@ package electrosphere.entity.types.attach;
import electrosphere.entity.Entity; import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils; import electrosphere.entity.EntityUtils;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.main.Globals; import electrosphere.main.Globals;
import electrosphere.renderer.Actor; import electrosphere.renderer.Actor;
import electrosphere.renderer.Model;
import java.util.LinkedList;
import org.joml.Quaternionf; import org.joml.Quaternionf;
import org.joml.Vector3f; import org.joml.Vector3f;
@ -20,6 +23,13 @@ public class AttachUtils {
toAttach.putData(EntityDataStrings.ATTACH_ENTITY_IS_ATTACHED, true); toAttach.putData(EntityDataStrings.ATTACH_ENTITY_IS_ATTACHED, true);
toAttach.putData(EntityDataStrings.ATTACH_PARENT, parent); toAttach.putData(EntityDataStrings.ATTACH_PARENT, parent);
toAttach.putData(EntityDataStrings.ATTACH_TARGET_BONE, boneName); toAttach.putData(EntityDataStrings.ATTACH_TARGET_BONE, boneName);
if(parent.getDataKeys().contains(EntityDataStrings.ATTACH_CHILDREN_LIST)){
((LinkedList)parent.getData(EntityDataStrings.ATTACH_CHILDREN_LIST)).add(toAttach);
} else {
LinkedList<Entity> childrenEntities = new LinkedList();
childrenEntities.add(toAttach);
parent.putData(EntityDataStrings.ATTACH_CHILDREN_LIST, childrenEntities);
}
} }
public static void updateAttachedEntityPositions(){ public static void updateAttachedEntityPositions(){
@ -29,12 +39,19 @@ public class AttachUtils {
String targetBone; String targetBone;
if((targetBone = (String)currentEntity.getData(EntityDataStrings.ATTACH_TARGET_BONE))!=null){ if((targetBone = (String)currentEntity.getData(EntityDataStrings.ATTACH_TARGET_BONE))!=null){
Actor parentActor = EntityUtils.getActor(parent); Actor parentActor = EntityUtils.getActor(parent);
//transform bone space
Vector3f position = new Vector3f(parentActor.getBonePosition(targetBone)); Vector3f position = new Vector3f(parentActor.getBonePosition(targetBone));
position = position.mul(((Vector3f)EntityUtils.getScale(parent))); position = position.mul(((Vector3f)EntityUtils.getScale(parent)));
position = position.rotate(((Quaternionf)EntityUtils.getRotation(parent))); position = position.rotate(((Quaternionf)EntityUtils.getRotation(parent)));
//transform worldspace
position.add(new Vector3f(EntityUtils.getPosition(parent))); position.add(new Vector3f(EntityUtils.getPosition(parent)));
//set
EntityUtils.getPosition(currentEntity).set(position); EntityUtils.getPosition(currentEntity).set(position);
EntityUtils.getRotation(currentEntity).set(EntityUtils.getRotation(parent)).normalize(); //set rotation
// Quaternionf rotation = parentActor.getBoneRotation(targetBone);
// EntityUtils.getRotation(currentEntity).set(rotation).normalize();
Vector3f facingAngle = CreatureUtils.getMovementVector(parent);
EntityUtils.getRotation(currentEntity).rotationTo(new Vector3f(0,0,1), facingAngle).mul(parentActor.getBoneRotation(targetBone)).normalize();
} }
} }
} }

View File

@ -8,6 +8,8 @@ import electrosphere.entity.types.hitbox.HitboxData;
import electrosphere.entity.types.hitbox.HitboxUtils; import electrosphere.entity.types.hitbox.HitboxUtils;
import electrosphere.game.server.creature.type.CreatureType; import electrosphere.game.server.creature.type.CreatureType;
import electrosphere.game.server.creature.type.MovementSystem; import electrosphere.game.server.creature.type.MovementSystem;
import electrosphere.entity.state.AttackTree;
import electrosphere.entity.state.IdleTree;
import electrosphere.main.Globals; import electrosphere.main.Globals;
import electrosphere.main.Main; import electrosphere.main.Main;
import electrosphere.net.parser.net.message.EntityMessage; import electrosphere.net.parser.net.message.EntityMessage;
@ -68,14 +70,20 @@ public class CreatureUtils {
for(String token : rawType.getTokens()){ for(String token : rawType.getTokens()){
switch(token){ switch(token){
case "BLENDER_TRANSFORM": case "BLENDER_TRANSFORM":
Actor entityActor = EntityUtils.getActor(rVal); ActorUtils.applyBlenderTransformer(rVal);
entityActor.setAnimationScalar(0.4f); break;
EntityUtils.getScale(rVal).set(0.005f); case "ATTACKER":
AttackTree attackTree = new AttackTree(rVal);
rVal.putData(EntityDataStrings.ATTACK_TREE, attackTree);
Globals.entityManager.registerAttackerEntity(rVal);
break; break;
} }
} }
rVal.putData(EntityDataStrings.IDLE_TREE, new IdleTree(rVal));
Globals.entityManager.registerCreatureEntity(rVal);
rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_IS_CREATURE, true); rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_IS_CREATURE, true);
rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_TYPE, type); rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_TYPE, type);
rVal.putData(EntityDataStrings.DATA_STRING_MOVEMENT_VECTOR, new Vector3f(0,0,1));
return rVal; return rVal;
} }
@ -138,4 +146,12 @@ public class CreatureUtils {
public static boolean isCreature(Entity e){ public static boolean isCreature(Entity e){
return e.getDataKeys().contains(EntityDataStrings.DATA_STRING_CREATURE_IS_CREATURE); return e.getDataKeys().contains(EntityDataStrings.DATA_STRING_CREATURE_IS_CREATURE);
} }
public static AttackTree getAttackTree(Entity e){
return (AttackTree)e.getData(EntityDataStrings.ATTACK_TREE);
}
public static IdleTree getIdleTree(Entity e){
return (IdleTree)e.getData(EntityDataStrings.IDLE_TREE);
}
} }

View File

@ -5,6 +5,7 @@ public class HitboxData {
String type; String type;
String bone; String bone;
float radius; float radius;
boolean active = false;
public String getType() { public String getType() {
return type; return type;
@ -18,5 +19,25 @@ public class HitboxData {
return radius; return radius;
} }
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
public void setBone(String bone) {
this.bone = bone;
}
public void setType(String type) {
this.type = type;
}
public void setRadius(float radius) {
this.radius = radius;
}
} }

View File

@ -3,6 +3,8 @@ package electrosphere.entity.types.hitbox;
import electrosphere.entity.Entity; import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils; import electrosphere.entity.EntityUtils;
import electrosphere.entity.types.attach.AttachUtils;
import electrosphere.entity.types.item.ItemUtils;
import electrosphere.main.Globals; import electrosphere.main.Globals;
import org.joml.Matrix4f; import org.joml.Matrix4f;
import org.joml.Quaternionf; import org.joml.Quaternionf;
@ -18,10 +20,13 @@ public class HitboxUtils {
public static Entity spawnRegularHitbox(Entity parent, String bone, float size){ public static Entity spawnRegularHitbox(Entity parent, String bone, float size){
Entity rVal = new Entity(); Entity rVal = new Entity();
HitboxData data = new HitboxData();
data.setActive(false);
data.setBone(bone);
data.setRadius(size);
data.setType(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HIT);
rVal.putData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT, parent); rVal.putData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT, parent);
rVal.putData(EntityDataStrings.COLLISION_ENTITY_DATA_BONE, bone); rVal.putData(EntityDataStrings.HITBOX_DATA, data);
rVal.putData(EntityDataStrings.COLLISION_ENTITY_DATA_RADIUS,size);
rVal.putData(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE,EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HIT);
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3f(0,0,0)); rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3f(0,0,0));
Globals.hitboxManager.registerHitbox(rVal); Globals.hitboxManager.registerHitbox(rVal);
return rVal; return rVal;
@ -29,10 +34,14 @@ public class HitboxUtils {
public static Entity spawnRegularHurtbox(Entity parent, String bone, float size){ public static Entity spawnRegularHurtbox(Entity parent, String bone, float size){
Entity rVal = new Entity(); Entity rVal = new Entity();
HitboxData data = new HitboxData();
data.setActive(true);
data.setBone(bone);
data.setRadius(size);
data.setType(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HURT);
data.setType(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HURT);
rVal.putData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT, parent); rVal.putData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT, parent);
rVal.putData(EntityDataStrings.COLLISION_ENTITY_DATA_BONE, bone); rVal.putData(EntityDataStrings.HITBOX_DATA, data);
rVal.putData(EntityDataStrings.COLLISION_ENTITY_DATA_RADIUS,size);
rVal.putData(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE,EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HURT);
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3f(0,0,0)); rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3f(0,0,0));
Globals.hitboxManager.registerHitbox(rVal); Globals.hitboxManager.registerHitbox(rVal);
return rVal; return rVal;
@ -40,7 +49,8 @@ public class HitboxUtils {
public static void updatePosition(Entity hitbox){ public static void updatePosition(Entity hitbox){
Entity parent = ((Entity)hitbox.getData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT)); Entity parent = ((Entity)hitbox.getData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT));
String boneName = ((String)(hitbox.getData(EntityDataStrings.COLLISION_ENTITY_DATA_BONE))); HitboxData hitboxData = getHitboxData(hitbox);
String boneName = hitboxData.getBone();
Quaternionf parentRotation = ((Quaternionf)EntityUtils.getRotation(parent)); Quaternionf parentRotation = ((Quaternionf)EntityUtils.getRotation(parent));
Vector3f positionScale = ((Vector3f)EntityUtils.getScale(parent)); Vector3f positionScale = ((Vector3f)EntityUtils.getScale(parent));
Vector3f worldPosition = new Vector3f(); Vector3f worldPosition = new Vector3f();
@ -60,28 +70,62 @@ public class HitboxUtils {
public static void collideEntities(Entity generatorHitbox){ public static void collideEntities(Entity generatorHitbox){
// long generatorId = (Long)generatorHitbox.getData(EntityDataStrings.COLLISION_ENTITY_ID); // long generatorId = (Long)generatorHitbox.getData(EntityDataStrings.COLLISION_ENTITY_ID);
//This is the entity the hitbox is attached to
Entity generatorParent = (Entity)generatorHitbox.getData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT); Entity generatorParent = (Entity)generatorHitbox.getData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT);
for(Entity receiverHitbox : Globals.hitboxManager.getAllHitboxes()){ for(Entity receiverHitbox : Globals.hitboxManager.getAllHitboxes()){
Entity receiverParent = (Entity)receiverHitbox.getData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT); Entity receiverParent = (Entity)receiverHitbox.getData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT);
// long targetId = (Long)receiverHitbox.getData(EntityDataStrings.COLLISION_ENTITY_ID);
if(receiverParent != generatorParent && Globals.collisionEngine.collisionSphereCheck(generatorHitbox, receiverHitbox)){ HitboxData generatorData = getHitboxData(generatorHitbox);
String generatorType = (String)generatorHitbox.getData(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE); HitboxData receiverData = getHitboxData(receiverHitbox);
String receiverType = (String)receiverHitbox.getData(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE);
if( //if there is a collision
(generatorType.equals(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HIT) || generatorType.equals(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HURT)) && //and the collision isn't against itself
(receiverType.equals(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HIT) || receiverType.equals(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HURT)) && //and both hitboxes are active
generatorType != receiverType if(
){ receiverParent != generatorParent &&
if(generatorType.equals(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HURT)){ Globals.collisionEngine.collisionSphereCheck(generatorHitbox, generatorData, receiverHitbox, receiverData) &&
// Globals.microSimulation.freeze(); generatorData.isActive() &&
EntityUtils.getPosition(generatorParent).set(Globals.spawnPoint); receiverData.isActive()){
} else if(receiverParent.equals(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HURT)){ //if two spheres collide, grab their hitbox types (eg hurt, hit, fire, etc)
EntityUtils.getPosition(receiverParent).set(Globals.spawnPoint); String generatorType = generatorData.getType();
} String receiverType = receiverData.getType();
if(generatorType.equals(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HIT) && receiverType.equals(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HURT)){
damageHitboxColision(generatorHitbox, receiverHitbox);
}
if(generatorType.equals(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HURT) && receiverType.equals(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HIT)){
damageHitboxColision(receiverHitbox, generatorHitbox);
} }
} }
} }
} }
public static void damageHitboxColision(Entity hitbox, Entity hurtbox){
Entity hitboxParent = (Entity)hitbox.getData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT);
Entity hurtboxParent = (Entity)hurtbox.getData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT);
//if the entity is attached to is an item, we need to compare with the parent of the item
//to make sure you don't stab yourself for instance
boolean isItem = hitboxParent.getDataKeys().contains(EntityDataStrings.ITEM_IS_ITEM);
Entity hitboxAttachParent = AttachUtils.getParent(hitboxParent);
if(isItem){
if(hitboxAttachParent != hurtboxParent){
EntityUtils.getPosition(hurtboxParent).set(Globals.spawnPoint);
}
} else {
EntityUtils.getPosition(hurtboxParent).set(Globals.spawnPoint);
}
}
public static HitboxData getHitboxData(Entity e){
return (HitboxData)e.getData(EntityDataStrings.HITBOX_DATA);
}
} }

View File

@ -10,6 +10,7 @@ import electrosphere.game.server.creature.type.CreatureType;
import electrosphere.game.server.item.type.Item; import electrosphere.game.server.item.type.Item;
import electrosphere.main.Globals; import electrosphere.main.Globals;
import electrosphere.renderer.Actor; import electrosphere.renderer.Actor;
import electrosphere.renderer.ActorUtils;
import electrosphere.renderer.Model; import electrosphere.renderer.Model;
import org.joml.Quaternionf; import org.joml.Quaternionf;
import org.joml.Vector3f; import org.joml.Vector3f;
@ -28,9 +29,7 @@ public class ItemUtils {
for(String token : item.getTokens()){ for(String token : item.getTokens()){
switch(token){ switch(token){
case "BLENDER_TRANSFORM": case "BLENDER_TRANSFORM":
Actor entityActor = EntityUtils.getActor(rVal); ActorUtils.applyBlenderTransformer(rVal);
entityActor.setAnimationScalar(0.4f);
EntityUtils.getScale(rVal).set(0.005f);
break; break;
} }
} }

View File

@ -3,6 +3,7 @@ package electrosphere.game.collision;
import electrosphere.entity.Entity; import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils; import electrosphere.entity.EntityUtils;
import electrosphere.entity.types.hitbox.HitboxData;
import electrosphere.game.server.world.ServerWorldData; import electrosphere.game.server.world.ServerWorldData;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -30,12 +31,6 @@ public class CollisionEngine {
public boolean checkCanOccupyPosition(CommonWorldData w, Entity e, Vector3f positionToCheck){ public boolean checkCanOccupyPosition(CommonWorldData w, Entity e, Vector3f positionToCheck){
boolean rVal = true; boolean rVal = true;
// //
// are we below the terrain?
//
if(w.getElevationAtPoint(positionToCheck) > positionToCheck.y){
return false;
}
//
// check world bounds // check world bounds
// //
if( if(
@ -46,6 +41,12 @@ public class CollisionEngine {
){ ){
return false; return false;
} }
//
// are we below the terrain?
//
if(w.getElevationAtPoint(positionToCheck) > positionToCheck.y){
return false;
}
return rVal; return rVal;
} }
@ -94,11 +95,11 @@ public class CollisionEngine {
public boolean collisionSphereCheck(Entity hitbox1, Entity hitbox2){ public boolean collisionSphereCheck(Entity hitbox1, HitboxData hitbox1data, Entity hitbox2, HitboxData hitbox2data){
Vector3f position1 = EntityUtils.getPosition(hitbox1); Vector3f position1 = EntityUtils.getPosition(hitbox1);
Vector3f position2 = EntityUtils.getPosition(hitbox2); Vector3f position2 = EntityUtils.getPosition(hitbox2);
float radius1 = (float)hitbox1.getData(EntityDataStrings.COLLISION_ENTITY_DATA_RADIUS); float radius1 = hitbox1data.getRadius();
float radius2 = (float)hitbox2.getData(EntityDataStrings.COLLISION_ENTITY_DATA_RADIUS); float radius2 = hitbox2data.getRadius();
float distance = position1.distance(position2); float distance = position1.distance(position2);
if(distance < radius1 + radius2){ if(distance < radius1 + radius2){
return true; return true;

View File

@ -2,11 +2,16 @@ package electrosphere.game.state;
import electrosphere.entity.types.attach.AttachUtils; import electrosphere.entity.types.attach.AttachUtils;
import electrosphere.entity.Entity; import electrosphere.entity.Entity;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.AttackTree;
import electrosphere.entity.state.IdleTree;
import electrosphere.entity.state.MovementTree; import electrosphere.entity.state.MovementTree;
import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.entity.types.hitbox.HitboxUtils; import electrosphere.entity.types.hitbox.HitboxUtils;
import electrosphere.entity.types.item.ItemUtils; import electrosphere.entity.types.item.ItemUtils;
import electrosphere.main.Globals; import electrosphere.main.Globals;
import static electrosphere.main.Main.deltaTime;
import electrosphere.renderer.Actor;
/** /**
* *
@ -21,6 +26,14 @@ public class MicroSimulation {
} }
public void simulate(){ public void simulate(){
for(Entity currentEntity : Globals.entityManager.getDrawable()){
//fetch actor
Actor currentActor = EntityUtils.getActor(currentEntity);
//increment animations
if(currentActor.getCurrentAnimation() != null){
currentActor.incrementAnimationTime(deltaTime);
}
}
//make items play idle animation //make items play idle animation
for(Entity item : Globals.entityManager.getItemEntities()){ for(Entity item : Globals.entityManager.getItemEntities()){
ItemUtils.updateItemActorAnimation(item); ItemUtils.updateItemActorAnimation(item);
@ -30,6 +43,16 @@ public class MicroSimulation {
MovementTree behaviorTree = CreatureUtils.getEntityMovementTree(currentMoveable); MovementTree behaviorTree = CreatureUtils.getEntityMovementTree(currentMoveable);
behaviorTree.simulate(); behaviorTree.simulate();
} }
//attacker behavior tree
for(Entity currentAttacker : Globals.entityManager.getAttackerEntities()){
AttackTree attackTree = CreatureUtils.getAttackTree(currentAttacker);
attackTree.simulate();
}
//idle behavior tree
for(Entity currentIdler : Globals.entityManager.getCreatureEntities()){
IdleTree idleTree = CreatureUtils.getIdleTree(currentIdler);
idleTree.simulate();
}
//update attached entity positions //update attached entity positions
AttachUtils.updateAttachedEntityPositions(); AttachUtils.updateAttachedEntityPositions();
//update hitbox positions //update hitbox positions

View File

@ -284,6 +284,8 @@ public class Globals {
assetManager.addModelPathToQueue("Models/unitsphere.fbx"); assetManager.addModelPathToQueue("Models/unitsphere.fbx");
//init hitbox //init hitbox
assetManager.addModelPathToQueue("Models/unitsphere_1.fbx"); assetManager.addModelPathToQueue("Models/unitsphere_1.fbx");
//init disabled hitbox
assetManager.addModelPathToQueue("Models/unitsphere_grey.fbx");
//init smallcube //init smallcube
assetManager.addModelPathToQueue("Models/SmallCube.fbx"); assetManager.addModelPathToQueue("Models/SmallCube.fbx");

View File

@ -11,6 +11,7 @@ public class EntityMessage extends NetworkMessage {
SETPOSITION, SETPOSITION,
SETFACING, SETFACING,
MOVEUPDATE, MOVEUPDATE,
ATTACKUPDATE,
MOVE, MOVE,
DESTROY, DESTROY,
SETBEHAVIORTREE, SETBEHAVIORTREE,
@ -30,7 +31,7 @@ public class EntityMessage extends NetworkMessage {
float rotationY; float rotationY;
float rotationZ; float rotationZ;
float velocity; float velocity;
int moveState; int treeState;
int propertyType; int propertyType;
int propertyValue; int propertyValue;
int treeType; int treeType;
@ -136,12 +137,12 @@ public class EntityMessage extends NetworkMessage {
this.velocity = velocity; this.velocity = velocity;
} }
public int getmoveState() { public int gettreeState() {
return moveState; return treeState;
} }
public void setmoveState(int moveState) { public void settreeState(int treeState) {
this.moveState = moveState; this.treeState = treeState;
} }
public int getpropertyType() { public int getpropertyType() {
@ -227,6 +228,12 @@ public class EntityMessage extends NetworkMessage {
} else { } else {
return false; return false;
} }
case TypeBytes.ENTITY_MESSAGE_TYPE_ATTACKUPDATE:
if(byteStream.size() >= TypeBytes.ENTITY_MESSAGE_TYPE_ATTACKUPDATE_SIZE){
return true;
} else {
return false;
}
case TypeBytes.ENTITY_MESSAGE_TYPE_MOVE: case TypeBytes.ENTITY_MESSAGE_TYPE_MOVE:
if(byteStream.size() >= TypeBytes.ENTITY_MESSAGE_TYPE_MOVE_SIZE){ if(byteStream.size() >= TypeBytes.ENTITY_MESSAGE_TYPE_MOVE_SIZE){
return true; return true;
@ -371,11 +378,11 @@ public class EntityMessage extends NetworkMessage {
rVal.setrotationY(ByteStreamUtils.popFloatFromByteQueue(byteStream)); rVal.setrotationY(ByteStreamUtils.popFloatFromByteQueue(byteStream));
rVal.setrotationZ(ByteStreamUtils.popFloatFromByteQueue(byteStream)); rVal.setrotationZ(ByteStreamUtils.popFloatFromByteQueue(byteStream));
rVal.setvelocity(ByteStreamUtils.popFloatFromByteQueue(byteStream)); rVal.setvelocity(ByteStreamUtils.popFloatFromByteQueue(byteStream));
rVal.setmoveState(ByteStreamUtils.popIntFromByteQueue(byteStream)); rVal.settreeState(ByteStreamUtils.popIntFromByteQueue(byteStream));
return rVal; return rVal;
} }
public static EntityMessage constructmoveUpdateMessage(int entityID,long time,float positionX,float positionY,float positionZ,float rotationX,float rotationY,float rotationZ,float velocity,int moveState){ public static EntityMessage constructmoveUpdateMessage(int entityID,long time,float positionX,float positionY,float positionZ,float rotationX,float rotationY,float rotationZ,float velocity,int treeState){
EntityMessage rVal = new EntityMessage(EntityMessageType.MOVEUPDATE); EntityMessage rVal = new EntityMessage(EntityMessageType.MOVEUPDATE);
rVal.setentityID(entityID); rVal.setentityID(entityID);
rVal.settime(time); rVal.settime(time);
@ -386,7 +393,39 @@ public class EntityMessage extends NetworkMessage {
rVal.setrotationY(rotationY); rVal.setrotationY(rotationY);
rVal.setrotationZ(rotationZ); rVal.setrotationZ(rotationZ);
rVal.setvelocity(velocity); rVal.setvelocity(velocity);
rVal.setmoveState(moveState); rVal.settreeState(treeState);
rVal.serialize();
return rVal;
}
public static EntityMessage parseattackUpdateMessage(List<Byte> byteStream){
EntityMessage rVal = new EntityMessage(EntityMessageType.ATTACKUPDATE);
stripPacketHeader(byteStream);
rVal.setentityID(ByteStreamUtils.popIntFromByteQueue(byteStream));
rVal.settime(ByteStreamUtils.popLongFromByteQueue(byteStream));
rVal.setpositionX(ByteStreamUtils.popFloatFromByteQueue(byteStream));
rVal.setpositionY(ByteStreamUtils.popFloatFromByteQueue(byteStream));
rVal.setpositionZ(ByteStreamUtils.popFloatFromByteQueue(byteStream));
rVal.setrotationX(ByteStreamUtils.popFloatFromByteQueue(byteStream));
rVal.setrotationY(ByteStreamUtils.popFloatFromByteQueue(byteStream));
rVal.setrotationZ(ByteStreamUtils.popFloatFromByteQueue(byteStream));
rVal.setvelocity(ByteStreamUtils.popFloatFromByteQueue(byteStream));
rVal.settreeState(ByteStreamUtils.popIntFromByteQueue(byteStream));
return rVal;
}
public static EntityMessage constructattackUpdateMessage(int entityID,long time,float positionX,float positionY,float positionZ,float rotationX,float rotationY,float rotationZ,float velocity,int treeState){
EntityMessage rVal = new EntityMessage(EntityMessageType.ATTACKUPDATE);
rVal.setentityID(entityID);
rVal.settime(time);
rVal.setpositionX(positionX);
rVal.setpositionY(positionY);
rVal.setpositionZ(positionZ);
rVal.setrotationX(rotationX);
rVal.setrotationY(rotationY);
rVal.setrotationZ(rotationZ);
rVal.setvelocity(velocity);
rVal.settreeState(treeState);
rVal.serialize(); rVal.serialize();
return rVal; return rVal;
} }
@ -630,7 +669,47 @@ public class EntityMessage extends NetworkMessage {
} intValues = ByteStreamUtils.serializeFloatToBytes(velocity); } intValues = ByteStreamUtils.serializeFloatToBytes(velocity);
for(int i = 0; i < 4; i++){ for(int i = 0; i < 4; i++){
rawBytes[38+i] = intValues[i]; rawBytes[38+i] = intValues[i];
} intValues = ByteStreamUtils.serializeIntToBytes(moveState); } intValues = ByteStreamUtils.serializeIntToBytes(treeState);
for(int i = 0; i < 4; i++){
rawBytes[42+i] = intValues[i];
}
break;
case ATTACKUPDATE:
rawBytes = new byte[2+4+8+4+4+4+4+4+4+4+4];
//message header
rawBytes[0] = TypeBytes.MESSAGE_TYPE_ENTITY;
//entity messaage header
rawBytes[1] = TypeBytes.ENTITY_MESSAGE_TYPE_ATTACKUPDATE;
intValues = ByteStreamUtils.serializeIntToBytes(entityID);
for(int i = 0; i < 4; i++){
rawBytes[2+i] = intValues[i];
}
intValues = ByteStreamUtils.serializeLongToBytes(time);
for(int i = 0; i < 8; i++){
rawBytes[6+i] = intValues[i];
}
intValues = ByteStreamUtils.serializeFloatToBytes(positionX);
for(int i = 0; i < 4; i++){
rawBytes[14+i] = intValues[i];
} intValues = ByteStreamUtils.serializeFloatToBytes(positionY);
for(int i = 0; i < 4; i++){
rawBytes[18+i] = intValues[i];
} intValues = ByteStreamUtils.serializeFloatToBytes(positionZ);
for(int i = 0; i < 4; i++){
rawBytes[22+i] = intValues[i];
} intValues = ByteStreamUtils.serializeFloatToBytes(rotationX);
for(int i = 0; i < 4; i++){
rawBytes[26+i] = intValues[i];
} intValues = ByteStreamUtils.serializeFloatToBytes(rotationY);
for(int i = 0; i < 4; i++){
rawBytes[30+i] = intValues[i];
} intValues = ByteStreamUtils.serializeFloatToBytes(rotationZ);
for(int i = 0; i < 4; i++){
rawBytes[34+i] = intValues[i];
} intValues = ByteStreamUtils.serializeFloatToBytes(velocity);
for(int i = 0; i < 4; i++){
rawBytes[38+i] = intValues[i];
} intValues = ByteStreamUtils.serializeIntToBytes(treeState);
for(int i = 0; i < 4; i++){ for(int i = 0; i < 4; i++){
rawBytes[42+i] = intValues[i]; rawBytes[42+i] = intValues[i];
} }

View File

@ -109,6 +109,11 @@ ENTITY_MESSAGE,
rVal = EntityMessage.parsemoveUpdateMessage(byteStream); rVal = EntityMessage.parsemoveUpdateMessage(byteStream);
} }
break; break;
case TypeBytes.ENTITY_MESSAGE_TYPE_ATTACKUPDATE:
if(EntityMessage.canParseMessage(byteStream,secondByte)){
rVal = EntityMessage.parseattackUpdateMessage(byteStream);
}
break;
case TypeBytes.ENTITY_MESSAGE_TYPE_MOVE: case TypeBytes.ENTITY_MESSAGE_TYPE_MOVE:
if(EntityMessage.canParseMessage(byteStream,secondByte)){ if(EntityMessage.canParseMessage(byteStream,secondByte)){
rVal = EntityMessage.parseMoveMessage(byteStream); rVal = EntityMessage.parseMoveMessage(byteStream);

View File

@ -50,17 +50,19 @@ Message categories
public static final byte ENTITY_MESSAGE_TYPE_SETPOSITION = 1; public static final byte ENTITY_MESSAGE_TYPE_SETPOSITION = 1;
public static final byte ENTITY_MESSAGE_TYPE_SETFACING = 2; public static final byte ENTITY_MESSAGE_TYPE_SETFACING = 2;
public static final byte ENTITY_MESSAGE_TYPE_MOVEUPDATE = 3; public static final byte ENTITY_MESSAGE_TYPE_MOVEUPDATE = 3;
public static final byte ENTITY_MESSAGE_TYPE_MOVE = 4; public static final byte ENTITY_MESSAGE_TYPE_ATTACKUPDATE = 4;
public static final byte ENTITY_MESSAGE_TYPE_DESTROY = 5; public static final byte ENTITY_MESSAGE_TYPE_MOVE = 5;
public static final byte ENTITY_MESSAGE_TYPE_SETBEHAVIORTREE = 6; public static final byte ENTITY_MESSAGE_TYPE_DESTROY = 6;
public static final byte ENTITY_MESSAGE_TYPE_SETPROPERTY = 7; public static final byte ENTITY_MESSAGE_TYPE_SETBEHAVIORTREE = 7;
public static final byte ENTITY_MESSAGE_TYPE_ATTACHENTITYTOENTITY = 8; public static final byte ENTITY_MESSAGE_TYPE_SETPROPERTY = 8;
public static final byte ENTITY_MESSAGE_TYPE_ATTACHENTITYTOENTITY = 9;
/* /*
Entity packet sizes Entity packet sizes
*/ */
public static final byte ENTITY_MESSAGE_TYPE_SETPOSITION_SIZE = 26; public static final byte ENTITY_MESSAGE_TYPE_SETPOSITION_SIZE = 26;
public static final byte ENTITY_MESSAGE_TYPE_SETFACING_SIZE = 26; public static final byte ENTITY_MESSAGE_TYPE_SETFACING_SIZE = 26;
public static final byte ENTITY_MESSAGE_TYPE_MOVEUPDATE_SIZE = 46; public static final byte ENTITY_MESSAGE_TYPE_MOVEUPDATE_SIZE = 46;
public static final byte ENTITY_MESSAGE_TYPE_ATTACKUPDATE_SIZE = 46;
public static final byte ENTITY_MESSAGE_TYPE_MOVE_SIZE = 26; public static final byte ENTITY_MESSAGE_TYPE_MOVE_SIZE = 26;
public static final byte ENTITY_MESSAGE_TYPE_DESTROY_SIZE = 6; public static final byte ENTITY_MESSAGE_TYPE_DESTROY_SIZE = 6;
public static final byte ENTITY_MESSAGE_TYPE_SETBEHAVIORTREE_SIZE = 22; public static final byte ENTITY_MESSAGE_TYPE_SETBEHAVIORTREE_SIZE = 22;

View File

@ -97,8 +97,8 @@ public class ServerConnectionHandler implements Runnable {
playerCharacterID = newPlayerCharacter.getId(); playerCharacterID = newPlayerCharacter.getId();
EntityUtils.getPosition(newPlayerCharacter).set(Globals.spawnPoint.x,0,Globals.spawnPoint.z); EntityUtils.getPosition(newPlayerCharacter).set(Globals.spawnPoint.x,0,Globals.spawnPoint.z);
//spawn player sword //spawn player sword
// Entity sword = ItemUtils.spawnBasicItem("Katana"); Entity sword = ItemUtils.spawnBasicItem("Katana");
// AttachUtils.attachEntityToEntityAtBone(newPlayerCharacter, sword, "Bone.020"); AttachUtils.attachEntityToEntityAtBone(newPlayerCharacter, sword, "Bone.031");
//set controller id //set controller id
CreatureUtils.setControllerPlayerId(newPlayerCharacter, playerID); CreatureUtils.setControllerPlayerId(newPlayerCharacter, playerID);
if(Globals.RUN_SERVER && Main.playerId == -1){ if(Globals.RUN_SERVER && Main.playerId == -1){

View File

@ -2,7 +2,9 @@
import electrosphere.main.Globals; import electrosphere.main.Globals;
import electrosphere.renderer.anim.Animation; import electrosphere.renderer.anim.Animation;
import org.joml.AxisAngle4f;
import org.joml.Matrix4f; import org.joml.Matrix4f;
import org.joml.Quaternionf;
import org.joml.Vector3f; import org.joml.Vector3f;
import org.joml.Vector4f; import org.joml.Vector4f;
@ -129,6 +131,25 @@ public class Actor {
return rVal; return rVal;
} }
public Quaternionf getBoneRotation(String boneName){
Quaternionf rVal = new Quaternionf();
Model model = Globals.assetManager.fetchModel(modelPath);
if(model != null){
if(animation != null){
model.playAnimation(animation);
model.incrementTime(animationTime);
Bone currentBone = model.boneMap.get(boneName);
if(currentBone != null){
AxisAngle4f axisAngle = new AxisAngle4f();
currentBone.final_transform.getRotation(axisAngle);
Quaternionf rotation = new Quaternionf(axisAngle);
rVal.set(rotation);
}
}
}
return rVal;
}
public Matrix4f getBoneTransform(String boneName){ public Matrix4f getBoneTransform(String boneName){
Matrix4f rVal = new Matrix4f(); Matrix4f rVal = new Matrix4f();
Model model = Globals.assetManager.fetchModel(modelPath); Model model = Globals.assetManager.fetchModel(modelPath);

View File

@ -1,5 +1,7 @@
package electrosphere.renderer; package electrosphere.renderer;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityUtils;
import electrosphere.main.Globals; import electrosphere.main.Globals;
/** /**
@ -15,8 +17,10 @@ public class ActorUtils {
return rVal; return rVal;
} }
public static void applyBlenderTransformer(Actor a){ public static void applyBlenderTransformer(Entity actorEntity){
Actor entityActor = EntityUtils.getActor(actorEntity);
entityActor.setAnimationScalar(100f);
EntityUtils.getScale(actorEntity).set(0.005f);
} }

View File

@ -236,11 +236,11 @@ public class Model {
//First we push transformFromParent into deform so that later in the pipeline bones without a current animation take on transformFromParent as their transformation to the hierarchy //First we push transformFromParent into deform so that later in the pipeline bones without a current animation take on transformFromParent as their transformation to the hierarchy
//I BELIEVE this is so that control bones still apply their offset to the hierarchy even when they're not animated :tm: //I BELIEVE this is so that control bones still apply their offset to the hierarchy even when they're not animated :tm:
//4/5/20 //4/5/20
Iterator<Bone> boneIterator = bones.iterator(); // Iterator<Bone> boneIterator = bones.iterator();
while(boneIterator.hasNext()){ // while(boneIterator.hasNext()){
Bone currentBone = boneIterator.next(); // Bone currentBone = boneIterator.next();
// currentBone.deform = currentBone.transformFromParent; //// currentBone.deform = currentBone.transformFromParent;
} // }
//Once that's done, for every channel we set the corresponding bone's deform to the channels TRS //Once that's done, for every channel we set the corresponding bone's deform to the channels TRS
Iterator<AnimChannel> channelIterator = currentAnimation.channels.iterator(); Iterator<AnimChannel> channelIterator = currentAnimation.channels.iterator();
while(channelIterator.hasNext()){ while(channelIterator.hasNext()){

View File

@ -187,8 +187,12 @@ public class RenderUtils {
glfwMakeContextCurrent(Globals.window); glfwMakeContextCurrent(Globals.window);
//Maximize it //Maximize it
glfwMaximizeWindow(Globals.window); glfwMaximizeWindow(Globals.window);
//Hide the cursor and capture it //apply mouse controls state
glfwSetInputMode(Globals.window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); if(Globals.controlHandler.isMouseVisible()){
Globals.controlHandler.showMouse();
} else {
Globals.controlHandler.hideMouse();
}
} }

View File

@ -4,6 +4,8 @@ import electrosphere.entity.CameraEntityUtils;
import electrosphere.entity.Entity; import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils; import electrosphere.entity.EntityUtils;
import electrosphere.entity.types.hitbox.HitboxData;
import electrosphere.entity.types.hitbox.HitboxUtils;
import electrosphere.logger.LoggerInterface; import electrosphere.logger.LoggerInterface;
import electrosphere.main.Globals; import electrosphere.main.Globals;
import static electrosphere.main.Main.deltaTime; import static electrosphere.main.Main.deltaTime;
@ -114,8 +116,8 @@ public class RenderingEngine {
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//Hide the cursor and capture it // //Hide the cursor and capture it
glfwSetInputMode(Globals.window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); // glfwSetInputMode(Globals.window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
@ -239,10 +241,7 @@ public class RenderingEngine {
for(Entity currentEntity : Globals.entityManager.getDrawable()){ for(Entity currentEntity : Globals.entityManager.getDrawable()){
//fetch actor //fetch actor
Actor currentActor = EntityUtils.getActor(currentEntity); Actor currentActor = EntityUtils.getActor(currentEntity);
//increment animations currentActor.incrementAnimationTime(0.001);
if(currentActor.getCurrentAnimation() != null){
currentActor.incrementAnimationTime(deltaTime * 500);
}
//calculate and apply model transform //calculate and apply model transform
modelTransformMatrix.identity(); modelTransformMatrix.identity();
modelTransformMatrix.translate(new Vector3f(EntityUtils.getPosition(currentEntity)).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)).sub(new Vector3f(0,1,0))); modelTransformMatrix.translate(new Vector3f(EntityUtils.getPosition(currentEntity)).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)).sub(new Vector3f(0,1,0)));
@ -290,6 +289,7 @@ public class RenderingEngine {
for(Entity currentEntity : Globals.entityManager.getDrawable()){ for(Entity currentEntity : Globals.entityManager.getDrawable()){
//fetch actor //fetch actor
Actor currentActor = EntityUtils.getActor(currentEntity); Actor currentActor = EntityUtils.getActor(currentEntity);
currentActor.incrementAnimationTime(0.001);
//increment animations //increment animations
//this is incremented in the shadow calculations //this is incremented in the shadow calculations
// if(currentActor.getCurrentAnimation() != null){ // if(currentActor.getCurrentAnimation() != null){
@ -320,23 +320,36 @@ public class RenderingEngine {
if(renderHitboxes){ if(renderHitboxes){
for(Entity currentHitbox : Globals.hitboxManager.getAllHitboxes()){ for(Entity currentHitbox : Globals.hitboxManager.getAllHitboxes()){
Model hitboxModel; Model hitboxModel;
if(currentHitbox.getData(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE).equals(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HURT)){ HitboxData data = HitboxUtils.getHitboxData(currentHitbox);
if((hitboxModel = Globals.assetManager.fetchModel("Models/unitsphere.fbx")) != null){ if(data.isActive()){
Vector3f position = EntityUtils.getPosition(currentHitbox); if(data.getType().equals(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HURT)){
modelTransformMatrix.identity(); if((hitboxModel = Globals.assetManager.fetchModel("Models/unitsphere.fbx")) != null){
modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)).sub(new Vector3f(0,1,0))); Vector3f position = EntityUtils.getPosition(currentHitbox);
// modelTransformMatrix.translate(-0.25f, 0.0f, 0.5f); //center sphere modelTransformMatrix.identity();
modelTransformMatrix.scale((Float)currentHitbox.getData(EntityDataStrings.COLLISION_ENTITY_DATA_RADIUS) * 2); modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)).sub(new Vector3f(0,1,0)));
hitboxModel.modelMatrix = modelTransformMatrix; // modelTransformMatrix.translate(-0.25f, 0.0f, 0.5f); //center sphere
hitboxModel.draw(); modelTransformMatrix.scale(data.getRadius() * 2);
hitboxModel.modelMatrix = modelTransformMatrix;
hitboxModel.draw();
}
} else if(data.getType().equals(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HIT)){
if((hitboxModel = Globals.assetManager.fetchModel("Models/unitsphere_1.fbx")) != null){
Vector3f position = EntityUtils.getPosition(currentHitbox);
modelTransformMatrix.identity();
modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)).sub(new Vector3f(0,1,0)));
// modelTransformMatrix.translate(-0.25f, 0.0f, 0.5f); //center sphere
modelTransformMatrix.scale(data.getRadius() * 2);
hitboxModel.modelMatrix = modelTransformMatrix;
hitboxModel.draw();
}
} }
} else if(currentHitbox.getData(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE).equals(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HIT)){ } else {
if((hitboxModel = Globals.assetManager.fetchModel("Models/unitsphere_1.fbx")) != null){ if((hitboxModel = Globals.assetManager.fetchModel("Models/unitsphere_grey.fbx")) != null){
Vector3f position = EntityUtils.getPosition(currentHitbox); Vector3f position = EntityUtils.getPosition(currentHitbox);
modelTransformMatrix.identity(); modelTransformMatrix.identity();
modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)).sub(new Vector3f(0,1,0))); modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)).sub(new Vector3f(0,1,0)));
// modelTransformMatrix.translate(-0.25f, 0.0f, 0.5f); //center sphere // modelTransformMatrix.translate(-0.25f, 0.0f, 0.5f); //center sphere
modelTransformMatrix.scale((Float)currentHitbox.getData(EntityDataStrings.COLLISION_ENTITY_DATA_RADIUS) * 2); modelTransformMatrix.scale(data.getRadius() * 2);
hitboxModel.modelMatrix = modelTransformMatrix; hitboxModel.modelMatrix = modelTransformMatrix;
hitboxModel.draw(); hitboxModel.draw();
} }

View File

@ -23,6 +23,7 @@ public class Animation {
public static final String ANIMATION_MOVEMENT_STARTUP = "Armature|WalkStart"; public static final String ANIMATION_MOVEMENT_STARTUP = "Armature|WalkStart";
public static final String ANIMATION_MOVEMENT_MOVE = "Armature|Walk"; public static final String ANIMATION_MOVEMENT_MOVE = "Armature|Walk";
public static final String ANIMATION_IDLE_1 = "Armature|Idle1"; public static final String ANIMATION_IDLE_1 = "Armature|Idle1";
public static final String ANIMATION_SWING_PRIMARY = "Armature|SwingWeapon";

View File

@ -50,6 +50,7 @@ public class ModelLoader {
static void attemptAddTexturesFromPathname(String path, Model m){ static void attemptAddTexturesFromPathname(String path, Model m){
//first we get the default texture map that's global //first we get the default texture map that's global
TextureMap global_map = Globals.textureMapDefault; TextureMap global_map = Globals.textureMapDefault;
LoggerInterface.loggerRenderer.DEBUG(path);
//then we try to get the path of our model from the map //then we try to get the path of our model from the map
Map<String,ArrayList<String>> mesh_map = global_map.get_mesh_map(path); Map<String,ArrayList<String>> mesh_map = global_map.get_mesh_map(path);
//if it exists.. //if it exists..
@ -58,6 +59,7 @@ public class ModelLoader {
Iterator<Mesh> mesh_iterator = m.meshes.iterator(); Iterator<Mesh> mesh_iterator = m.meshes.iterator();
while(mesh_iterator.hasNext()){ while(mesh_iterator.hasNext()){
Mesh current_mesh = mesh_iterator.next(); Mesh current_mesh = mesh_iterator.next();
LoggerInterface.loggerRenderer.DEBUG(current_mesh.nodeID);
//if the current iteration is contained within the mesh map we procured from above //if the current iteration is contained within the mesh map we procured from above
if(mesh_map.containsKey(current_mesh.nodeID)){ if(mesh_map.containsKey(current_mesh.nodeID)){
//we create a new material, check if the diffuse or specular is not null, //we create a new material, check if the diffuse or specular is not null,
@ -65,6 +67,7 @@ public class ModelLoader {
Material final_material = new Material(); Material final_material = new Material();
ArrayList<String> texture_path_list = mesh_map.get(current_mesh.nodeID); ArrayList<String> texture_path_list = mesh_map.get(current_mesh.nodeID);
String diffuse_path = TextureMap.get_diffuse_path(texture_path_list); String diffuse_path = TextureMap.get_diffuse_path(texture_path_list);
LoggerInterface.loggerRenderer.DEBUG(current_mesh.nodeID + "->" + diffuse_path);
if(diffuse_path != null){ if(diffuse_path != null){
LoggerInterface.loggerRenderer.DEBUG(diffuse_path); LoggerInterface.loggerRenderer.DEBUG(diffuse_path);
// Texture diffuse = new Texture(diffuse_path); // Texture diffuse = new Texture(diffuse_path);

View File

@ -320,7 +320,7 @@
"type" : "FIXED_FLOAT" "type" : "FIXED_FLOAT"
}, },
{ {
"name" : "moveState", "name" : "treeState",
"type" : "FIXED_INT" "type" : "FIXED_INT"
}, },
{ {
@ -396,7 +396,22 @@
"rotationY", "rotationY",
"rotationZ", "rotationZ",
"velocity", "velocity",
"moveState" "treeState"
]
},
{
"messageName" : "attackUpdate",
"data" : [
"entityID",
"time",
"positionX",
"positionY",
"positionZ",
"rotationX",
"rotationY",
"rotationZ",
"velocity",
"treeState"
] ]
}, },
{ {