Skip to content

Commit

Permalink
Merge pull request #8 from DomenicDev/v.012
Browse files Browse the repository at this point in the history
V0.12
  • Loading branch information
DomenicDev authored Jun 12, 2017
2 parents 38df9fc + 9bb14a4 commit 847a15c
Show file tree
Hide file tree
Showing 55 changed files with 889 additions and 83 deletions.
11 changes: 11 additions & 0 deletions assets/Interface/Scripts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>

<entry key="testText">Das ist ein Beispieltext. Hier kommt noch mehr und noch mehr Text hin
Und hier kann man
viel mit machen weils cool ist.
</entry>


</properties>
4 changes: 4 additions & 0 deletions assets/Materials/Headlamp/Headlamp.j3m
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Material My Material : Common/MatDefs/Light/Lighting.j3md {
MaterialParameters {
}
}
Binary file added assets/Models/Flashlight/TestFlashLight.j3o
Binary file not shown.
3 changes: 3 additions & 0 deletions assets/Models/Flashlight/TestFlashLight.j3odata
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#
#Fri Jun 09 13:51:19 CEST 2017
ORIGINAL_PATH=Models/Flashlight/TestFlashLight.j3o
Binary file added assets/Models/Headlamp/Headlamp.j3o
Binary file not shown.
3 changes: 3 additions & 0 deletions assets/Models/Headlamp/Headlamp.j3odata
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#
#Mon Jun 12 11:49:29 CEST 2017
ORIGINAL_PATH=Models/Headlamp/blender2ogre-export.scene
Binary file added assets/Models/Paper/TestPaper.j3o
Binary file not shown.
3 changes: 3 additions & 0 deletions assets/Models/Paper/TestPaper.j3odata
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#
#Thu Jun 08 01:17:28 CEST 2017
ORIGINAL_PATH=Models/Paper/TestPaper.j3o
Binary file modified assets/Models/Player/Player.j3o
Binary file not shown.
Binary file modified assets/Scenes/BeachScene.j3o
Binary file not shown.
Binary file added assets/Sounds/Footsteps/sand_footstep.WAV
Binary file not shown.
Binary file removed assets/Sounds/Footsteps/sand_footstep.wav
Binary file not shown.
Binary file added assets/Sounds/Footsteps/stone_footstep.WAV
Binary file not shown.
Binary file removed assets/Sounds/Footsteps/stone_footstep.wav
Binary file not shown.
Binary file added assets/Sounds/Footsteps/wood_footstep.WAV
Binary file not shown.
Binary file removed assets/Sounds/Footsteps/wood_footstep.wav
Binary file not shown.
32 changes: 32 additions & 0 deletions src/de/gamedevbaden/crucified/appstates/GameCommanderHolder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package de.gamedevbaden.crucified.appstates;

import com.jme3.app.state.AbstractAppState;
import com.simsilica.es.EntityId;
import de.gamedevbaden.crucified.game.GameCommander;

import java.util.HashMap;

/**
* This state holds a map of {@link GameCommander}s with their playerId as key. This
* state is used for easier access.
* Created by Domenic on 08.06.2017.
*/
public class GameCommanderHolder extends AbstractAppState {

private HashMap<EntityId, GameCommander> map = new HashMap<>();

public void add(EntityId player, GameCommander commander) {
map.put(player, commander);
}

public GameCommander get(EntityId player) {
return map.get(player);
}

@Override
public void cleanup() {
this.map.clear();
this.map = null;
super.cleanup();
}
}
18 changes: 17 additions & 1 deletion src/de/gamedevbaden/crucified/appstates/InteractionAppState.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import de.gamedevbaden.crucified.enums.InteractionType;
import de.gamedevbaden.crucified.enums.Sound;
import de.gamedevbaden.crucified.es.components.InteractionComponent;
import de.gamedevbaden.crucified.es.components.ReadableScript;
import de.gamedevbaden.crucified.es.utils.EntityFactory;
import de.gamedevbaden.crucified.game.GameCommander;

/**
* This app state defines what shall happen if players interact with various types of game objects.
Expand All @@ -21,9 +23,11 @@ public class InteractionAppState extends AbstractAppState {

private EntitySet interactables;
private EntityData entityData;
private GameCommanderHolder commanderHolder;

@Override
public void initialize(AppStateManager stateManager, Application app) {
this.commanderHolder = stateManager.getState(GameCommanderHolder.class);
this.entityData = stateManager.getState(EntityDataState.class).getEntityData();
this.interactables = entityData.getEntities(InteractionComponent.class);
super.initialize(stateManager, app);
Expand All @@ -34,7 +38,7 @@ public void update(float tpf) {
interactables.applyChanges();
}

public void interactWith(EntityId interactableEntityId) {
public void interactWith(EntityId playerId, EntityId interactableEntityId) {
if (interactables.containsId(interactableEntityId)) {
Entity entity = interactables.getEntity(interactableEntityId);
InteractionComponent interactionComponent = entity.get(InteractionComponent.class);
Expand All @@ -50,6 +54,18 @@ public void interactWith(EntityId interactableEntityId) {
EntityFactory.createSoundEffect(entityData, Sound.Miss, false, null);
break;

case ReadText:
// look whether this entity has an script component
ReadableScript readableScript = entityData.getComponent(interactableEntityId, ReadableScript.class);
if (readableScript != null && readableScript.getScript() != null) {
GameCommander commander = commanderHolder.get(playerId);
System.out.println(commander);
if (commander != null) {
commander.readNote(readableScript.getScript());
}
}
break;

default:
break;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package de.gamedevbaden.crucified.appstates;

import com.jme3.app.Application;
import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import com.simsilica.es.EntityData;
import com.simsilica.es.EntityId;
import com.simsilica.es.EntitySet;
import de.gamedevbaden.crucified.es.components.FlashLight;

/**
* This state handles the functionality of items the player can interact with.
* For example: Turning a FlashLight on or off
* <p>
* Created by Domenic on 09.06.2017.
*/
public class ItemFunctionalityAppState extends AbstractAppState {

private EntityData entityData;
private EntitySet flashLights;

@Override
public void initialize(AppStateManager stateManager, Application app) {
this.entityData = stateManager.getState(EntityDataState.class).getEntityData();
this.flashLights = entityData.getEntities(FlashLight.class);
super.initialize(stateManager, app);
}

@Override
public void update(float tpf) {
flashLights.applyChanges();
}

public void toggleFlashLight(EntityId flashLight) {
if (flashLights.containsId(flashLight)) {
FlashLight lightComponent = flashLights.getEntity(flashLight).get(FlashLight.class);
boolean enabled = lightComponent.isEnabled();
enabled = !enabled; // we switch on / off state
entityData.setComponent(flashLight, new FlashLight(enabled));
}
}

@Override
public void cleanup() {
this.flashLights.release();
this.flashLights.clear();
this.flashLights = null;
super.cleanup();
}
}
4 changes: 3 additions & 1 deletion src/de/gamedevbaden/crucified/appstates/PhysicAppState.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,10 @@ private void removeTerrain(Entity entity) {
}

private void addCharacterControl(Entity entity) {
// PhysicsCharacterControl pcc = entity.get(PhysicsCharacterControl.class);
PhysicsCharacterControl pcc = entity.get(PhysicsCharacterControl.class);
CustomCharacterControl characterControl = new CustomCharacterControl(PhysicConstants.HUMAN_RADIUS, PhysicConstants.HUMAN_HEIGHT, PhysicConstants.HUMAN_WEIGHT);
characterControl.setWalkDirection(pcc.getWalkDirection());
characterControl.setViewDirection(pcc.getViewDirection());
addPhysicsControl(characterControl);
characterControls.put(entity.getId(), characterControl);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void initialize(AppStateManager stateManager, Application app) {
this.listeners = new ArrayList<>();

this.ray = new Ray();
this.ray.setLimit(2f);
this.ray.setLimit(4f);

this.results = new CollisionResults();

Expand Down
21 changes: 21 additions & 0 deletions src/de/gamedevbaden/crucified/appstates/SceneEntityLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
import de.gamedevbaden.crucified.es.triggersystem.TriggerType;
import de.gamedevbaden.crucified.es.utils.physics.CollisionShapeType;
import de.gamedevbaden.crucified.userdata.EntityType;
import de.gamedevbaden.crucified.userdata.ReadablePaperScriptUserData;
import de.gamedevbaden.crucified.userdata.eventgroup.EventGroupData;
import de.gamedevbaden.crucified.userdata.events.OpenCloseEventUserData;
import de.gamedevbaden.crucified.userdata.events.SoundEvent;
import de.gamedevbaden.crucified.userdata.triggers.TriggerTypeData;
import de.gamedevbaden.crucified.utils.GameConstants;

import java.util.HashMap;
import java.util.logging.Logger;
Expand Down Expand Up @@ -179,6 +181,25 @@ private void initEntities(Node rootNode, HashMap<Spatial, EntityId> entities) {
entityData.setComponents(entityId,
new PhysicsRigidBody(0, false, CollisionShapeType.MESH_COLLISION_SHAPE));
break;

case ReadablePaper:
// get script
ReadablePaperScriptUserData script = spatial.getUserData(GameConstants.USER_DATA_READABLE_SCRIPT);
if (script != null) {
entityData.setComponents(entityId,
new InteractionComponent(InteractionType.ReadText),
new ReadableScript(script.getScript())
);
}
break;

case FlashLight:
entityData.setComponents(entityId,
new Pickable(),
new Equipable(),
new FlashLight(true));
break;

default:
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@
import com.jme3.terrain.geomipmap.TerrainLodControl;
import com.jme3.terrain.geomipmap.TerrainQuad;
import de.gamedevbaden.crucified.appstates.view.ShadowRendererAppState;
import de.gamedevbaden.crucified.enums.PaperScript;
import de.gamedevbaden.crucified.enums.Scene;
import de.gamedevbaden.crucified.game.GameCommander;
import de.gamedevbaden.crucified.userdata.EntityType;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.InvalidPropertiesFormatException;
import java.util.Properties;

/**
* Created by Domenic on 27.05.2017.
*/
Expand All @@ -30,6 +38,9 @@ public class GameCommanderAppState extends AbstractAppState implements GameComma
private SimpleApplication app;
private ShadowRendererAppState shadowRendererAppState;

// scripts
private Properties scripts;

public GameCommanderAppState() {
}

Expand All @@ -52,6 +63,20 @@ public void initialize(AppStateManager stateManager, Application app) {

this.rootNode.attachChild(mainWorldNode);

// load script file
try {
FileInputStream stringFileInput = new FileInputStream(new File("assets/Interface/Scripts.xml"));
this.scripts = new Properties();
this.scripts.loadFromXML(stringFileInput);
stringFileInput.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (InvalidPropertiesFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

super.initialize(stateManager, app);
}

Expand Down Expand Up @@ -117,6 +142,14 @@ public void loadScene(Scene scene) {

}

@Override
public void readNote(PaperScript script) {
if (scripts != null) {
String text = scripts.getProperty(script.getKey());
System.out.println(text);
}
}

public Node getMainWorldNode() {
return mainWorldNode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ public class GameEventAppState extends AbstractAppState implements ActionListene
private InputManager inputManager;
private Camera cam;

private Vector3f lastCamDirection;
private Vector3f lastCamDirection = new Vector3f();
private float camUpdateTime;

@Override
public void initialize(AppStateManager stateManager, Application app) {
this.gameSession = stateManager.getState(GameSessionAppState.class).getGameSession();
this.inputManager = app.getInputManager();
this.cam = app.getCamera();
this.lastCamDirection = cam.getDirection(new Vector3f());

// init listener for input events
for (InputCommand input : InputCommand.values()) {
Expand All @@ -46,7 +45,6 @@ public void initialize(AppStateManager stateManager, Application app) {
PlayerInteractionState playerInteractionState = stateManager.getState(PlayerInteractionState.class);
playerInteractionState.addInteractionListener(this);


super.initialize(stateManager, app);
}

Expand All @@ -55,7 +53,7 @@ public void initialize(AppStateManager stateManager, Application app) {
public void update(float tpf) {
// check for camera change

if ((camUpdateTime += tpf) >= 0.1f || !lastCamDirection.equals(cam.getDirection())) { // we send 50 updates per second
if ((camUpdateTime += tpf) >= 0.05f && !lastCamDirection.equals(cam.getDirection())) { // we send 50 updates per second

lastCamDirection.set(cam.getDirection());
// when the camera has rotated we call the update method
Expand All @@ -64,7 +62,6 @@ public void update(float tpf) {
// this case isn't handled yet...

gameSession.applyViewDirection(cam.getDirection());

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class GameEventHandler extends AbstractAppState implements GameEventListe
private ItemStoreAppState itemStoreAppState;
private EquipmentAppState equipmentAppState;
private GameSessionManager gameSession;
private ItemFunctionalityAppState itemFunctionalityAppState;

public GameEventHandler(GameSessionManager gameSession) {
this.gameSession = gameSession;
Expand All @@ -38,6 +39,7 @@ public void initialize(AppStateManager stateManager, Application app) {
this.interactionAppState = stateManager.getState(InteractionAppState.class);
this.itemStoreAppState = stateManager.getState(ItemStoreAppState.class);
this.equipmentAppState = stateManager.getState(EquipmentAppState.class);
this.itemFunctionalityAppState = stateManager.getState(ItemFunctionalityAppState.class);
super.initialize(stateManager, app);
}

Expand Down Expand Up @@ -79,6 +81,11 @@ public void onViewDirectionChange(EntityId entityId, Vector3f newViewDirection)
@Override
public void onInteraction(EntityId playerId, EntityId interactedEntity) {
// triggerAppState.onInteraction(playerId, interactedEntity);
interactionAppState.interactWith(interactedEntity);
interactionAppState.interactWith(playerId, interactedEntity);
}

@Override
public void onFlashLightToggled(EntityId playerId, EntityId flashLightId) {
itemFunctionalityAppState.toggleFlashLight(flashLightId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,12 @@ public void interactWithEntity(EntityId interactedEntity) {
}
}

@Override
public void toggleFlashLight(EntityId flashLightId) {
for (GameEventListener listener : listeners) {
listener.onFlashLightToggled(playerId, flashLightId);
}
}

}
}
Loading

0 comments on commit 847a15c

Please sign in to comment.