Skip to content

Instantly share code, notes, and snippets.

@Akjosch
Akjosch / event_setup.js
Created October 29, 2019 14:55
Setting up events from event-tagged passages in SugarCube, simple version
class GameEvent {
/**
* @param {string} target
* @param {string} trigger
* @param {string} weight
* @param {string} priority
*/
constructor(target, trigger, weight, priority) {
this.target = String(target);
this.trigger = trigger;
@Akjosch
Akjosch / dialogue2.tw
Last active November 5, 2019 10:30
Another SugarCube one-passage dialogue example
/* The dialogue setup - typically at the start of the passage */
<<set _dialogue = {
"": {
text: "<div>Before you stands a wizard, clad in heavy robes, scarves, and a pointed hat. He gives a cheerful but heavily muffled greeting. <q>Ownt fon?</q> the wizard inquires as he holds out a handful of rings which radiate magical energy.</div><div>Take one?</div>",
choices: [
{ text: "One with a shiny jewel on top!", next: "death" },
{ text: "A band with runes glowing around it!", next: "runes" },
{ text: "Mom told me not to accept strange items from people I don't know&hellip;", next: "death"},
{ text: "Go away.", next: "death", filter: "$day != 7" }
]},
@Akjosch
Akjosch / Sprite.js
Last active November 6, 2019 04:43
Example class for SugarCube
/**
* @param {string} tex
* @param {number[]} rect
*/
var Sprite = function Sprite(tex, rect) {
var sp = this;
sp.tex = String(tex);
if (Array.isArray(rect)) {
if (rect.length != 4) {
throw new Error("new Sprite(): rect parameter needs to be exactly four numbers long - [x, y, width, height]");