Skip to content

Instantly share code, notes, and snippets.

@eropple
Created February 20, 2014 07:25
Show Gist options
  • Save eropple/9108570 to your computer and use it in GitHub Desktop.
Save eropple/9108570 to your computer and use it in GitHub Desktop.
Another test script
var loadAssets = function(assets) {
return [
{
fileName: "Portraits/adam-normal.png",
type: Types["Texture"]
},
{
fileName: "Portraits/celt-normal.png",
type: Types["Texture"]
}
];
}
var start = function() {
var previousAnswer = GAMESTATE.getPersistent("test_target.dialogue.answer");
LOGGER.info("Dialogue: previousAnswer = " + previousAnswer);
if (previousAnswer == null || previousAnswer == undefined) {
return {
speaker: "adam",
emotion: "normal",
face: true,
monologue: false,
text: "dialogue.TestDialogue.start.notalk",
args: [ ACTOR.name ],
next: "step2"
};
} else {
return {
speaker: "adam",
emotion: "normal",
face: true,
monologue: false,
text: "dialogue.TestDialogue.start.didtalk",
args: [ ACTOR.name, previousAnswer ],
next: "step2"
};
}
}
var step2 = function() {
return {
speaker: "celt",
emotion: "normal",
face: true,
monologue: false,
choices: [
{
"next": "yes",
"text": "dialogue.TestDialogue.step2.yes"
},
{
"next": "no",
"text": "dialogue.TestDialogue.step2.no"
}
]
};
}
var yes = function() {
RESULTS.put("answer", "yes");
return {
speaker: "adam",
emotion: "normal",
face: true,
monologue: false,
text: "dialogue.TestDialogue.yes",
next: "end"
};
}
var no = function() {
RESULTS.put("answer", "no");
return {
speaker: "adam",
emotion: "normal",
face: true,
monologue: false,
text: "dialogue.TestDialogue.no",
next: "end"
};
}
var end = function() {
return END_DIALOGUE;
}
var onInit = function() {
LOGGER.info("Initialized TestTarget named '" + ME.name + "'.");
ME.sendMessage("ow!", { a: 5, b: 6 }, ME.name, "player");
};
var onThud = function(thuddedBy) {
LOGGER.info("TestTarget '" + ME.name + "' thudded by '" + thuddedBy.name + "'.");
};
var onUnthud = function(thuddedBy) {
LOGGER.info("TestTarget '" + ME.name + "' unthudded by '" + thuddedBy.name + "'.");
};
var onUse = function(player) {
LOGGER.info("TestTarget '" + ME.name + "' used by '" + player.name + "'.");
ME.startDialogue("TestDialogue");
};
var onMessage = function(message) {
if (message.sender != null) {
LOGGER.info("TestTarget '" + ME.name + "' received message from '" + message.sender.name + "': " + message.text);
} else {
LOGGER.info("TestTarget '" + ME.name + "' received anonymous message: " + message.text);
}
if (message.text == "TestDialogue") {
LOGGER.info("TestTarget '" + ME.name + "' got a reply from a dialogue.");
var answer = message.args.get("answer");
if (answer != undefined && answer != null) {
LOGGER.info("TestTarget '" + ME.name + "' received an answer: " + answer);
GAMESTATE.setPersistent("test_target.dialogue.answer", answer);
}
}
}
var buildCollisionFixtures = function(body) {
body.setType(com.badlogic.gdx.physics.box2d.BodyDef.BodyType.StaticBody);
var shape = new com.badlogic.gdx.physics.box2d.PolygonShape();
var vertices = JavaArrays.floatArray(8);
var side = 60.0 / 128.0;
vertices[0] = 0.0; vertices[1] = 0.0;
vertices[2] = 0.0; vertices[3] = side;
vertices[4] = side; vertices[5] = side;
vertices[6] = side; vertices[7] = 0.0;
shape.set(vertices);
var def = new com.badlogic.gdx.physics.box2d.FixtureDef();
def.shape = shape;
def.friction = 1000;
def.density = 1000;
var f = body.createFixture(def);
f.setUserData(ME.javaObject);
shape.dispose();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment