Skip to content

Instantly share code, notes, and snippets.

@fizz
Last active April 21, 2019 05:28
Show Gist options
  • Save fizz/1a8573a82a28f8a576bc709031283d8c to your computer and use it in GitHub Desktop.
Save fizz/1a8573a82a28f8a576bc709031283d8c to your computer and use it in GitHub Desktop.
gamedev
#include "com/example/_prototypes/ArrayPrototype.as"
#include "com/example/_prototypes/ObjectPrototype.as"
_global.GameEvent = {}
AsBroadcaster.initialize(GameEvent)
import com.example.PlayerState
_global.saveHere = PlayerState.saveGame
_global.fromStash = PlayerState.unstash
var respond_to_events = function() {
PlayerState.globalizeKeyValue('keychainListener', {})
keychainListener.keys = ['puzzles', 'seen_clues', 'used_clues', 'current_note']
keychainListener.onWillSaveGame = function(){
return PlayerState.stashValuesAtKeys(this.keys)
}
keychainListener.onWillRestoreSave = function(){
return PlayerState.awakenKeysFromStash(this.keys)
}
return _global.GameEvent.addListener(_global.keychainListener)
}
respond_to_events()
//TODO: attachInventoryChest and restoreSaveData when we receive the event onWillRestoreSave or onDidRestoreSave (Continue.as)
//TODO: also "fly by" frames with registering flotsam, while hiding behind a black square mc, to reregister them on onWill/DidRestoreSave
//TODO: saveInventory on event onWillSave.
var enableIfElseGoto = function(_$){
var ifElseGoto = function(cond, tLabel, fLabel){
if (_$.puzzles[cond]){return sendPlayerToFrame(tLabel)}
return sendPlayerToFrame(fLabel)
}
_$.maybeGoto = ifElseGoto
trace("INFO: maybeGoto is enabled. Use it on your puzzle buttons, like this: \n\ton(release){\n\t\tmaybeGoto('puzzleName', 'solvedLabel', 'unsolvedLabel')\n\t}\n-if puzzleName is solved, the button release will go to solvedLabel, otherwise, it will go to unsolvedLabel")
}
enableIfElseGoto(_global)
var enableAlwaysSucceedsGoto = function(_$){
var alwaysSucceedsGoto = function(cond, tLabel, fLabel){
sendPlayerToFrame(tLabel)
}
_$.maybeGoto = alwaysSucceedsGoto
trace('INFO: alwaysSucceedsGoto is enabled.')
}
enableAlwaysSucceedsGoto(_global) //uncomment to solve all puzzles.
config.set('LOGLEVEL', 'QUIET') //or chatty
import com.example.Peekaboo
import com.example.PlayerState
class com.example.Continue extends Peekaboo {
static var _$ = _global
function Continue(){
showWhen(PlayerState.saveExists())
}
function onRelease(){
_$.GameEvent.broadcastMessage('onWillRestoreSave')
_global.sendPlayerToFrame(PlayerState.unstash('frame'))
_$.GameEvent.broadcastMessage('onDidRestoreSave')
}
}
import com.example.Peekaboo
import com.example.RandomGate
class com.example.Flotsam extends Peekaboo {
var _originalDepth
var _inner
var _reelWidth
function Flotsam(){
_inner = inner()
_reelWidth = reelWidth()
_originalDepth = getDepth()
swapDepths(_root.getNextHighestDepth())
RandomGate.register(this)
if (_name.indexOf('instance') != -1) {
trace('WARN: Flotsam needs an instance name at frame ' + _root._currentframe)
}
}
function play(gate){
_x = (gate._x + gate._width) - 24 - _inner._x
_y = (gate._y + (gate._height/2)) - _inner._y - (_height/2)
showWhen(true)
super.play()
}
function stop(){
hideWhen(true)
rewind()
}
function inner(){
for ( var key in this ){
if (typeof this[key] == 'movieclip') {
return this[key]
}
}
}
function reelWidth(){
rewind()
var x1 = _inner._x
gotoAndStop(_totalframes-1)
var x2 = _inner._x
rewind()
return(x1-x2)
}
}
import com.visualcondition.twease.*; Twease.register(Easing);
_global.inventoryList = ["pizza", "antidote", "chaincutter", "marble", "pickle", "glasses", "cotton", "cottonoil", "key_director", "duck", "toetag", "bodysheet", "key_chapel"];
_global.shouldBeInInventory = [];
_global.isUsedUp = [];
_global.itemsInInventory = [];
_global.combinations = [];
_global.products = [];
_global.arrangements = [];
_global.originalDepths = [];
combinations["syringe"] = "laudanum";
combinations["matches"] = "lamp_unlit";
combinations["hook"] = "thread";
combinations["handle_bottom"] = "handle_top";
combinations["tile_blue"] = "tile_white";
combinations["tile_blue_white"] = "tile_red";
combinations["tile_blue_white_red"] = "tile_green";
products["syringe,laudanum"] = "shot";
products["matches,lamp_unlit"] = "lamp";
products["hook,thread"] = "thread_hook";
products["handle_bottom,handle_top"] = "handle";
products["tile_white,tile_blue"] = "tile_blue_white";
products["tile_blue_white,tile_red"] = "tile_blue_white_red";
products["tile_blue_white_red,tile_green"] = "tile";
arrangements["hook"] = ["book"];
arrangements["key_dead"] = ["dead_fist","coffin_top"];
_global.placement = [];
placement["topbar"] = new Object({w:85.45, h:49.40, x:5, y:487.9});
placement["pizza"] = new Object({w:230.60, h:71.20, x:11.75, y:257.75});
placement["marble"] = new Object({w:10.85, h:10.55, x:529.90, y:442.20});
placement["antidote"] = new Object({w:29.55, h:29.50, x:177.25, y:239.65});
placement["chaincutter"] = new Object({w:113.60, h:68.85, x:80.85, y:399.85});
placement["pickle"] = new Object({w:54.10, h:24.80, x:436.35, y:305.70});
placement["glasses"] = new Object({w:180.45, h:56.00, x:224.00, y:281.65});
placement["cotton"] = new Object({w:39.80, h:34.15, x:508.45, y:406.55});
placement["cottonoil"] = new Object({w:39.80, h:34.30, x:230.20, y:435.80});
placement["key_director"] = new Object({w:80.35, h:69.10, x:335.10, y:317.05});
placement["duck"] = new Object({w:134.80, h:99.95, x:35.30, y:362.25});
placement["toetag"] = new Object({w:77.25, h:32.25, x:362.25, y:445.55});
placement["bodysheet"] = new Object({w:240.10, h:70.35, x:270.25, y:225.95});
placement["key_dining"] = new Object({w:129.65, h:99.50, x:202.00, y:153.95});
placement["needle"] = new Object({w:185.40, h:214.70, x:209.60, y:86.70});
placement["star"] = new Object({w:48.75, h:34.75, x:337.00, y:354.05});
placement["key_chapel"] = new Object({w:106.15, h:44.85, x:240.45, y:211.55});
placement["key_yard"] = new Object({w:71.50, h:40.00, x:471.00, y:418.50});
placement["crowbar"] = new Object({w:286.05, h:64.85, x:192.00, y:132.95});
placement["key_liesl"] = new Object({w:40.85, h:98.40, x:488.70, y:321.65});
placement["key_basement"] = new Object({w:93.25, h:71.75, x:330.10, y:311.25});
placement["key_bedroom"] = new Object({w:98.60, h:43.10, x:355.70, y:395.45});
placement["key_library"] = new Object({w:99.70, h:40.60, x:283.90, y:340.45});
placement["sword"] = new Object({w:347.85, h:78.80, x:141.20, y:285.60});
placement["key_heart"] = new Object({w:46.50, h:118.60, x:222.55, y:238.05});
placement["sword_holy"] = new Object({w:78.20, h:345.85, x:293.55, y:57.90});
placement["key_crest"] = new Object({w:36.65, h:83.15, x:84.60, y:190.60});
placement["key_attic"] = new Object({w:53.15, h:132.65, x:283.00, y:242.05});
placement["key_doll"] = new Object({w:54.55, h:70.05, x:373.20, y:367.15});
var respond_to_events = function() {
PlayerState.globalizeKeyValue('inventoryListener', {})
inventoryListener.onWillSaveGame = function() {
PlayerState.stashValueForKey(_global.shouldBeInInventory, 'sbii')
PlayerState.stashValueForKey(_global.isUsedUp, 'iuu')
return PlayerState.stashValueForKey(_global.itemsInInventory, 'iii')
}
inventoryListener.onWillRestoreSave = function() {
PlayerState.awakenKeyFromStashWithAliasKey('shouldBeInInventory', 'sbii')
PlayerState.awakenKeyFromStashWithAliasKey('isUsedUp', 'iuu')
PlayerState.awakenKeyFromStashWithAliasKey('itemsInInventory', 'iii')
return attachInventoryChest()
}
return _global.GameEvent.addListener(_global.inventoryListener)
}
respond_to_events()
function set_up_combinations_and_products(){
for ( var i in combinations ){
combinations[combinations[i]] = i
}
for ( var i in products ){
k = i.split(",")
products[k[1] + "," + k[0]] = products[i]
}
}
set_up_combinations_and_products();
_global.attachInventoryChest = function() {
if (!_global.invchest_inst) {
item_name = "topbar";
instance_name = "_global.topbar_instance";
instance_name =_root.attachMovie(item_name, instance_name, _root.getNextHighestDepth(), {_x:placement["topbar"].x, _y:placement["topbar"].y, _width:placement["topbar"].w, _height:placement["topbar"].h});
_global.topbar_inst=instance_name;
item_name = "inventory_chest";
instance_name = "inventory_chest_instance";
_root.attachMovie(item_name, instance_name, _root.getNextHighestDepth(), {_width:(_global.topbar_inst._width-20), _height:(_global.topbar_inst._height-10), _x:(_global.topbar_inst._x + 10), _y:(_global.topbar_inst._y+5)});
instance = eval(instance_name);
_global.invchest_inst = instance;
instance.onRelease = showInventory;
}
};
_global.attachToThisFrame = function(item) {
if (!_global.shouldBeInInventory[item] & !_global.isUsedUp[item]) {
item_name = item+"_mc";
instance_name = item_name+"_instance";
_root.attachMovie(item_name, instance_name, _root.getNextHighestDepth(), {_x:placement[item].x, _y:placement[item].y, _width:placement[item].w, _height:placement[item].h});
instance = eval(instance_name);
instance.invname = item;
arrangement = arrangements[item];
originalDepths[item] = [];
for ( var i=0; i<arrangement.length; i++ ) {
arrangeItem = eval(arrangement[i]);
originalDepths[item][i]= arrangeItem.getDepth();
arrangeItem.swapDepths(_root.getNextHighestDepth());
}
instance.onRollOver = scrollOver;
instance.onRollOut = scrollOff;
instance.onRelease = moveFromStageToInventory;
}
};
_global.scrollOver = function() {
this.gotoAndStop(2);
};
_global.scrollOff = function() {
this.gotoAndStop(1);
};
_global.moveFromStageToInventory = function() {
var item = this;
shouldBeInInventory[item.invname] = true;
var beforeTween = magic_shelf.show;
var afterTween = function(){
item.removeMovieClip();
magic_shelf.hide();
saveHere();
};
Twease.tween({target:item, time:1, _x:invchest_inst._x + invchest_inst._width/2, _y:invchest_inst._y + invchest_inst._height/2, _alpha:40, _height:item._height/20, _width:item._width/20, func:afterTween, delay:.25, startfunc:beforeTween, ease:'easeInCubic'});
};
_global.showInventory = function() {
_global.curframe = _root._currentframe;
sendPlayerToFrame("inventoryChestFrame", true);
_global.invchest_inst._alpha = 0;
_global.invchest_inst._visible = false;
trace(_global.invchest_inst._alpha);
_global.itemsInInventory = [];
for (j=-1, l=inventoryList.length, i=0; i<l; i++) {
if (_global.shouldBeInInventory[inventoryList[i]] and not _global.isUsedUp[inventoryList[i]]) {
if(!_global.itemsInInventory.contains(inventoryList[i])){
_global.itemsInInventory[++j] = inventoryList[i];
}
}
}
inventoryRows = _global.itemsInInventory.chunk(Math.ceil(Math.sqrt(_global.itemsInInventory.length)));
for (w=inventoryBackground._width*0.8, margin_left=w/8, h=inventoryBackground._height*0.8, margin_top=h/8, l=inventoryRows.length, i=0; i<l; i++) {
//let's put inventoryRows[i] into a variable to avoid typing inventoryRows[i] all the time
inventoryRow = inventoryRows[i];
for (r=inventoryRow.length, j=0; j<r; j++) {
item = inventoryRow[j];
item_name = item+"_inv";
instance_name = item_name+"_instance";
_root.attachMovie(item_name, instance_name, _root.getNextHighestDepth());
instance = eval(instance_name);
instance._x = inventoryBackground._x + margin_left+(w*j/r);
instance._y = inventoryBackground._y + (margin_top+(h*i/l));
instance.startx = instance._x;
instance.starty = instance._y;
}
}
hookDragDrop();
};
_global.sendPlayerToFrame = function(frameName, hideShelf) {
GameEvent.broadcastMessage('onWillNavigate', _root._currentframe, frameName);
hideShelf = hideShelf || false;
for (i=0; i<inventoryList.length; i++) {
arrangement = arrangements[inventoryList[i]];
for ( var j=0; j<arrangement.length; j++ ) {
arrangeItem = eval(arrangement[j]);
arrangeItem.swapDepths(originalDepths[inventoryList[i]][j])
};
inventoryitem = eval(inventoryList[i]+"_mc_instance");
inventoryitem.removeMovieClip();
inventoryitem = eval(inventoryList[i]+"_inv_instance");
inventoryitem.removeMovieClip();
}
if (hideShelf) {
hideShelfItems();//just making sure because we can't count on them being reliably gone
}
gotoAndStop(frameName);
GameEvent.broadcastMessage('onDidNavigate', _root._currentframe);
enable_shelf();
if (_global.inDragMode) {
dragItem = _global.itemsInInventory[invDragIndex]+"_mc";
dragInstance = _global.itemsInInventory[invDragIndex]+"_mc_instance";
_root.attachMovie(dragItem, dragInstance, _root.getNextHighestDepth(), {_x:_root._xmouse, _y:_root._ymouse});
}
};
_global.hookDragDrop = function() {
_root.onMouseDown = dragDropMouseStartsDragging;
_root.onMouseMove = dragDropMouseIsDragging;
_root.onMouseUp = dragDropMouseLetGo;
};
_global.dragDropMouseStartsDragging = function() {
for (i=0; i<_global.itemsInInventory.length; i++) {
item = eval(_global.itemsInInventory[i]+"_inv_instance");
if (item.hitTest(_root._xmouse, _root._ymouse)) {
_global.inDragMode = true;
_global.invDragIndex = i;
}
}
};
_global.dragDropMouseIsDragging = function() {
if (_global.inDragMode) {
if (_global.stageDragMode) {
item = _global.itemsInInventory[_global.invDragIndex]+"_mc_instance";
} else {
item = _global.itemsInInventory[_global.invDragIndex]+"_inv_instance";
}
item = eval(item);
item.swapDepths(_root.getNextHighestDepth());
_root.setMask(_root.topmask);
item._x = _root._xmouse;
item._y = _root._ymouse;
updateAfterEvent();
if (item.hitTest(invbackbtn)) {
sendPlayerToFrame(_global.curframe, true);
_global.stageDragMode = true;
_global.invchest_inst._visible = true;
_global.invchest_inst._alpha = 100;
}
}
};
_global.dragDropMouseLetGo = function() {
if (_global.inDragMode) {
_global.inDragMode = false;
item = _global.itemsInInventory[invDragIndex];
item_inst = eval(item+"_inv_instance");
combiner = combinations[_global.itemsInInventory[invDragIndex]];
combiner_inst = eval(combiner+"_inv_instance");
if (item_inst.hitTest(combiner_inst)) {
combined = products[combiner + "," + item];
combined_name = combined+"_inv";
combined_inst = combined_name+"_instance";
_root.attachMovie(combined_name, combined_inst, _root.getNextHighestDepth(), {_x:combiner_inst._x, _y:combiner_inst._y});
_global.itemsInInventory[_global.itemsInInventory.length] = combined;
combined_inst = eval(combined_inst);
combined_inst.startx = combined_inst._x;
combined_inst.starty = combined_inst._y;
_global.itemsInInventory = _global.itemsInInventory.without(item, combiner);
_global.shouldBeInInventory[item] = false;
_global.shouldBeInInventory[combiner] = false;
_global.isUsedUp[item] = true;
_global.isUsedUp[combiner] = true;
item_inst.removeMovieClip();
combiner_inst.removeMovieClip();
_global.shouldBeInInventory[combined] = true;
saveInventory();
} else {
if (_global.stageDragMode) {
item_inst = eval(item+"_mc_instance");
combiner = eval(item+"_target");
if (item_inst.hitTest(combiner)) {
item_inst.removeMovieClip();
_global.shouldBeInInventory[item] = false;
_global.isUsedUp[item] = true;
_global.itemsInInventory = _global.itemsInInventory.without(item);
_global.puzzles[item] = "solved";
sendPlayerToFrame(item+"_solved", true);
} else {
bad_try = false;
for (i=0; i<inventoryList.length; i++) {
if (inventoryList[i] != item){
target = eval(inventoryList[i]+"_target");
if (item_inst.hitTest(target)){
bad_try = true;
}
}
}
if(bad_try){
var alert_message = "wrong_target_mc";
}else{
var alert_message = "no_target_mc";
}
var alert_message_inst = alert_message + "_instance";
alert_message_inst = _root.attachMovie(alert_message, alert_message_inst, _root.getNextHighestDepth(), {_x:(250), _y:(1)});
var removeMessage = function(){
alert_message_inst.removeMovieClip();
};
var beforeTween = function(){magic_shelf.show()};
var afterTween = function(){
item_inst.removeMovieClip();
magic_shelf.hide();
};
Twease.tween({target:alert_message_inst, time:1, _alpha:0, func:removeMessage, ease:'easeInOutBack'});
Twease.tween({target:item_inst, time:1, _x:invchest_inst._x + (invchest_inst._width/2), _y:invchest_inst._y + (invchest_inst._height/2), _alpha:40, _height:item_inst._height/20, _width:item_inst._width/20, ease:'easeInCubic', startfunc:beforeTween, func:afterTween, delay:1.25});
}
} else {
item_inst._x = item_inst.startx;
item_inst._y = item_inst.starty;
}
}
}
_global.inDragMode = false;
_global.stageDragMode = false;
};
import com.visualcondition.twease.*; Twease.register(Easing);
placement["notebook_shelf"] = new Object({w:112.6, h:49.2, x:0, y:0});
_global.clues = [];
_global.seen_clues = [];
_global.used_clues = [];
_global.current_note = 0;
clues["driscoll"] = "Room 311<br />Nick Driscoll<br />Deceased";
clues["asner"] = "Room 212<br />Old Man Asner<br />Deceased";
clues["dedd"] = "Room 211<br />A.M. Dedd<br />Feeling better, apparently...";
clues["roof"] = "Code for Roof - 3165";
clues["roof_note"] = "Note on hospital roof said something or someone is coming from the old asylum...";
clues["roof_key"] = "There's an old rusted key on the hospital roof but I can't get to it.";
clues["recreation"] = "Code for Recreation Room - 8674";
clues["goldfish"] = "The name of Old Man Asner's goldfish is FINCH";
clues["drachmids"] = "There's money hidden in the ducts?";
clues["records"] = "Code for Records - 9081";
clues["monastery"] = "Before the old asylum there was a monastery here. It was burned down along with everyone in it. All that remains now are the catacombs...";
clues["forgot"] = "Crooke and Kennedy forgot some patients in the old asylum and the patients died. And now the dead seek revenge. What is going on in this place?";
clues["missing"] = "Four patients are missing... Are they the ones who were forgotten?";
clues["records_oa"] = "Note with patient numbers from the director's office:<br />#244<br />#125<br />#405<br />#368";
clues["mendelson"] = "#125<br />James Mendelson<br />8 yrs old<br />Committed to the asylum on<br />July 10th, 1896<br />Diagnosis:<br />Feeblemindedness";
clues["marble"] = "James could read and write. On December 22, 1896 he was restrained and put in seclusion because he was crying about his marbles.";
clues["graves"] = "#244<br />Laurie Graves<br />12 yrs old<br />Committed to Haven on<br />December 13th, 1896<br />Diagnosis:<br />Epilepsy";
clues["pink"] = "A little servant girl. She stole a ribbon on December 23rd, 1896 and was put in seclusion as punishment.";
clues["connelly"] = "#368<br />Peter Connelly <br />72 yrs old<br />Committed to the asylum<br />on February 20th, 1893<br />Diagnosis:<br />Poverty";
clues["penny"] = "On December 21st, 1896 Mr Connelly was given a week in seclusion as discipline for begging.";
clues["brown"] = "#405<br />Mary Brown <br />30 yrs old<br />Committed to Haven on<br />April 20th, 1894<br />Diagnosis:<br />Grief" ;
clues["locket"] = "Mrs Brown couldn't stop grieving over the death of her baby son. On November 23rd, 1896 she was prescribed daily seclusion for her nerves." ;
clues["constellation"] = "Constellations: <br /><br />Andromeda<br />Columba<br />Cassiopeia<br />Lyra";
clues["seclusion"] = "I like the pretty lady<br />Here comes the scary lion!<br />I hate fish<br />The man walks in and throws water on everyone";
clues["justice"] = "Laurie Graves<br />Justitia<br />Justitia means Justice";
clues["kindness"] = "James Mendelson<br />Benevolentia<br />If I remember my Latin correctly, Benevolentia means Kindness";
clues["grace"] = "Peter Connelly<br />Gratia<br />I'm pretty sure Gratia means Grace";
clues["mercy"] = "Mary Brown<br />Clementia<br />I think Clementia means Mercy";
fontinfo = ["<p class=\"clue\">","</p>"];
clueStyleSheet = new TextField.StyleSheet();
clueStyleSheet.setStyle(".clue", {color:'black', fontSize:'18', fontFamily:'Clue Font'});
_global.attachNotebook = function() {
item_name = "notebook_shelf";
instance_name = "notebook_shelf_instance";
_root.attachMovie(item_name, instance_name, _root.getNextHighestDepth(), {_x:placement["notebook_shelf"].x, _y:placement["notebook_shelf"].y, _width:placement["notebook_shelf"].w, _height:placement["notebook_shelf"].h, _alpha:0});
notebook_shelf_inst=eval(instance_name);
item_name = "notebook_mc";
instance_name = "notebook_mc_instance";
_root.attachMovie(item_name, instance_name, _root.getNextHighestDepth(), {_width:(notebook_shelf_inst._width-20), _height:(notebook_shelf_inst._height-10), _x:(notebook_shelf_inst._x + 10), _y:(notebook_shelf_inst._y+5)});
instance = eval(instance_name);
_global.notebook_mc_inst = instance;
instance.frame = "NotebookFrame";
instance.onRelease = showNotebook;
item_name = "notebook_open_mc";
instance_name = "notebook_open_mc_instance";
_root.attachMovie(item_name, instance_name, _root.getNextHighestDepth(), {_x: notebook_mc_inst._x, _y: notebook_mc_inst._y, _alpha:0, _width: notebook_mc_inst._width*.75, _height: notebook_mc_inst._height});
_global.notebook_open_mc_inst = eval(instance_name);
};
_global.showNotebook = function() {
if (_root._currentframe != 11) {
_global.curframe = _root._currentframe;
}
sendPlayerToFrame("NotebookFrame", true);
i=0;
for ( var id=current_note; id<seen_clues.length; id++ )
{
clue_id = seen_clues[id];
if (current_note > 0) {
page = eval("open_notebook.left_page");
if (prev_button) {
prev_button.removeMovieClip();
}
prev_button = page.attachMovie("previous_page", "prev_button", page.getNextHighestDepth());
prev_button._x = 5;
prev_button._y = page._height - prev_button._height;
prev_button.onRelease = function() {
prev_button.removeMovieClip();
next_button.removeMovieClip();
eval("open_notebook.left_page.txtfield_inst_0").removeTextField();
eval("open_notebook.right_page.txtfield_inst_1").removeTextField();
eval("open_notebook.left_page.crossed_out_inst_0").removeMovieClip();
eval("open_notebook.right_page.crossed_out_inst_1").removeMovieClip();
current_note -= 2;
showNotebook();
}
}
if (i==2)
{
page = eval("open_notebook.right_page");
next_button = page.attachMovie("next_page", "next_button", page.getNextHighestDepth());
next_button._x = page._width - next_button._width - 5;
next_button._y = page._height - next_button._height;
next_button.onRelease = function() {
prev_button.removeMovieClip();
next_button.removeMovieClip();
eval("open_notebook.left_page.txtfield_inst_0").removeTextField();
eval("open_notebook.right_page.txtfield_inst_1").removeTextField();
eval("open_notebook.left_page.crossed_out_inst_0").removeMovieClip();
eval("open_notebook.right_page.crossed_out_inst_1").removeMovieClip();
current_note += 2;
showNotebook();
};
break;
}
if (!(i%2))
{
page = eval("open_notebook.left_page");
}
else
{
page = eval("open_notebook.right_page");
}
x = page._width * 0.15; w = page._width * 0.7;
y = page._height * 0.15; h = page._height * 0.7;
txtfield = page.createTextField("txtfield_inst_"+i, page.getNextHighestDepth(), x, y, w, h);
txtfield.multiline = true;
txtfield.wordWrap = true;
txtfield.html = true;
txtfield.selectable = false;
txtfield.styleSheet = clueStyleSheet;
txtfield.htmlText = fontinfo.join(clues[clue_id]);
txtfield.embedFonts = true;
if (used_clues[clue_id]) {
page.attachMovie("crossed_out", "crossed_out_inst_"+i, page.getNextHighestDepth(), {_x:5, _y:5});
}
i+=1;
};
}
_global.add_clue = function(clue_id) {
seen_clue = false;
for ( var id=0; id<seen_clues.length; id++ ) {
if (seen_clues[id] == clue_id) {
seen_clue = true;
}
};
if (!seen_clue) {
var stashInfo = {x:notebook_mc_inst._x, y:notebook_mc_inst._y, h:notebook_mc_inst._height, w:notebook_mc_inst._width};
var absMidPoint = {x:Stage.width/2, y:Stage.height/2};
var relMidPoint = {x:absMidPoint.x, y:absMidPoint.y};
relMidPoint.x -= notebook_open_mc_inst._width;
/* relMidPoint.y -= notebook_open_mc_inst._height;*/
var midSize = {h:notebook_open_mc_inst._height*2, w:notebook_open_mc_inst._width*2};
notebook_mc_inst.enabled = false;
var beforeTween = function() {magic_shelf.show()};
var afterTween = function() {
notebook_mc_inst.enabled = true;
magic_shelf.hide()
};
var doScribbling = function() {
_root.attachMovie("scribbling", "scribbling_inst", _root.getNextHighestDepth(), {_x: absMidPoint.x-midSize.w/2-10, _y: absMidPoint.y});
};
var delScribbling = function() {
scribbling_inst.removeMovieClip();
}
Twease.tween({target:notebook_mc_inst, time:1, _alpha:0, startfunc:beforeTween});
Twease.tween({target:notebook_open_mc_inst, time:1, delay:.25, _alpha:100, _x:relMidPoint.x, _y:relMidPoint.y, _height:midSize.h, _width:midSize.w, func:doScribbling});
//adds 2s delay because scribbling animation lasts 24 frames @ 12fps
Twease.tween({target:notebook_open_mc_inst, time:.5, delay:2.25, _alpha:0, _x:stashInfo.x, _y:stashInfo.y, _height:stashInfo.h, _width:stashInfo.w, startfunc:delScribbling, func:afterTween});
Twease.tween({target:notebook_mc_inst, time:.5, delay:2.75, _alpha:100});
seen_clues[seen_clues.length] = clue_id;
}
else
{
/*
var beforeTween = function() {magic_shelf.show()};
var afterTween = function() {
magic_shelf.hide()
};
Twease.tween({target: notebook_mc_inst, time:.25, _rotation:15, _alpha:20, startfunc:beforeTween, delay:.25});
Twease.tween({target: notebook_mc_inst, time:.25, _alpha:100, _rotation:0, delay:.5, func:afterTween});
*/
}
}
_global.add_two_clues = function(clue_1, clue2) {
seen_clue = false;
for ( var id=0; id<seen_clues.length; id++ ) {
if (seen_clues[id] == clue_1) {
seen_clue = true;
}
};
if (!seen_clue) {
add_clue(clue_1);
seen_clues[seen_clues.length] = clue2;
}
};
_global.used_up_clue = function(clue_id) {
used_clues[clue_id] = true;
}
class com.example.Peekaboo extends MovieClip {
static var _ge = _global.GameEvent
function Peekaboo(){
stopWhen(true)
}
function showWhen(P){
if (_visible && !Boolean(P)) {
_ge.broadcastMessage('onWillBecomeInvisibleMc', this)
_visible = false
_ge.broadcastMessage('onDidBecomeInvisibleMc', this)
}
if (!_visible && Boolean(P)) {
_ge.broadcastMessage('onWillBecomeVisibleMc', this)
_visible = true
_ge.broadcastMessage('onDidBecomeVisibleMc', this)
}
}
function hideWhen(P){
showWhen(!Boolean(P))
}
function playWhen(P){
showWhen(Boolean(P))
if (Boolean(P)) {return play()}
return stop()
}
function stopWhen(P){
return playWhen(!Boolean(P))
}
function rewind(){
_ge.broadcastMessage('onWillRewindMc', this)
gotoAndStop(1)
_ge.broadcastMessage('onDidRewindMc', this)
}
function play(){
_ge.broadcastMessage('onWillPlayMc', this)
super.play()
_ge.broadcastMessage('onDidPlayMc', this)
}
function stop(){
_ge.broadcastMessage('onWillStopMc', this)
super.stop()
_ge.broadcastMessage('onDidStopMc', this)
}
function gotoAndStop(frame){
_ge.broadcastMessage('onWillGotoFrameAndStopMc', frame, this)
super.gotoAndStop(frame)
_ge.broadcastMessage('onDidGotoFrameAndStopMc', frame, this)
}
}
class com.example.PlayerState {
static var _basename = unescape(_url.substr(_url.lastIndexOf("/") + 1).split('.swf').join(''))
static var _so = SharedObject.getLocal('example/' + _basename, '/')
static var _$ = _global
static function saveExists(){
var frame = unstash('frame')
return typeof frame != 'undefined' && frame !==null
}
static function saveFrame(){
var frame = _root._currentframe
_$.GameEvent.broadcastMessage('onWillSaveFrame', frame)
stashValueForKey(frame, 'frame')
_$.GameEvent.broadcastMessage('onDidSaveFrame', frame)
}
static function saveGame(){
_$.GameEvent.broadcastMessage('onWillSaveGame')
saveFrame()
_$.GameEvent.broadcastMessage('onDidSaveGame')
}
static function unstash(key) {
return _so.data[key];
}
static function globalizeKeyValue(key, value){
return _$[key] = value
}
static function stashValueAtKey(key){
var val = _$[key]
_so.data[key] = val
_so.flush()
}
static function stashValuesAtKeys(keys){
for (var i in keys) {
var key = keys[i]
stashValueAtKey(key)
}
}
static function stashValueForKey(value, key){
_so.data[key] = value
_so.flush()
}
static function awakenKeyFromStash(key){
return globalizeKeyValue(key, unstash(key))
}
static function awakenKeyFromStashWithAliasKey(key, aliasKey){
return globalizeKeyValue(key, unstash(aliasKey))
}
static function awakenKeysFromStash(keys) {
for (var i in keys) {
awakenKeyFromStash(keys[i])
}
}
}
class com.example.RandomGate extends MovieClip {
static var itemsRegisteredAtFrame = {}
static var itemsUsedAtFrame = {}
static var itemRecentlySpottedAtFrame = {}
static var itemMostRecentlyUsed
var _originalDepth
function RandomGate(){
_originalDepth = getDepth()
if (_name.indexOf('instance') !== -1) {
trace('WARN: RandomGate needs an instance name at frame ' + _root._currentframe)
}
_global.GameEvent.addListener(this)
}
static function register(){
var registree = arguments[0]
var frame = _root._currentframe
if (typeof itemsRegisteredAtFrame[frame] != 'undefined' && itemsRegisteredAtFrame[frame] !== null) {
if (!itemsRegisteredAtFrame[frame].contains(registree)) {
return itemsRegisteredAtFrame[frame].push(registree)
}
return false
}
return itemsRegisteredAtFrame[frame] = [registree]
}
function onWillNavigate(from, to){
var flotsam = itemMostRecentlyUsed
flotsam.stop()
swapDepths(_originalDepth)
}
function getNearestValidFrame(){
var frame = _root._currentframe
var choices = itemsRegisteredAtFrame[frame]
if (typeof choices != 'undefined' && choices !== null) {return frame}
trace('INFO: Nothing registered to play at frame ' + frame + '. Checking previous frames.')
var max_frame = 0
for ( var candidate_frame in itemsRegisteredAtFrame ){
if (candidate_frame>max_frame && candidate_frame<frame) {max_frame = candidate_frame}
}
if (max_frame > 0) {
trace('INFO: Using items found registered at frame ' + max_frame)
return max_frame
}
trace('WARN: ' + _name + ' has nothing to do.\n\tFix it by dragging some Flotsam instances onto the artboard at frame ' + frame)
return false
}
function selectItem(frame){
var choices = itemsRegisteredAtFrame[frame]
var excludedHere = itemRecentlySpottedAtFrame[frame]
var excludedNear = itemMostRecentlyUsed
var excludedFromGroup = itemsUsedAtFrame[frame]
choices = choices.without(itemsUsedAtFrame[frame])//.without(excludedHere).without(excludedNear)
choices = choices.without(excludedNear)
choices = choices.without(excludedHere)
if (!choices.length) {
trace('nothing to play! :-(')
}
var randomIndex = Math.round(Math.random() * (choices.length -1))
var flotsam = choices[randomIndex]
return flotsam
}
function markUsed(item, registrationPoint) {
itemRecentlySpottedAtFrame[_root._currentframe] = item
itemMostRecentlyUsed = item
if (typeof itemsUsedAtFrame[registrationPoint] == 'undefined' || itemsUsedAtFrame[registrationPoint] === null) {
itemsUsedAtFrame[registrationPoint] = [item]
}
if (!itemsUsedAtFrame[registrationPoint].contains(item)) {
itemsUsedAtFrame[registrationPoint].push(item)
}
return true
}
function onLoad(){
swapDepths(_root.getNextHighestDepth())
_root.setMask(_root.topmask)
var nearestIndex = getNearestValidFrame()
if (nearestIndex) {
var flotsam = selectItem(nearestIndex)
flotsam.play(this)
markUsed(flotsam, nearestIndex)
}
}
}
/*
//in decl section: var playNext
//in onWillNavigate: clearInterval(playNext)
//in onLoad:
var selectAnother = selectRegisteredItem
var currentGate = this
var playLaggard = function(){
clearInterval(intervalToClear)
var flotsam = itemMostRecentlyUsed
flotsam.stop()
flotsam = selectAnother()
markFlotsamDirty(flotsam)
flotsam.play(currentGate)
}
playNext = setInterval(playLaggard, (flotsam._totalframes+24)*1000/24)
var intervalToClear = playNext
*/
//two things onstage at once, at all times: one entering, one exiting. so the span between them is less than the play/stop wavelength of each.
//don't stop when all items for sewer have played: just go forever. but not in a loop because we don't store the sequence and go ^.*$ over and over. We just exclude the two latest n as ineligible to play next, and pick a random remaining one. So: 1UpGate, 2UpGate, 3UpGate control how many appear on stage at once. RandomGate is just a non-repeating 1UpGate.
/*
RandomGate: pick one item from nearest artboard instances. Play it. The end for this frame.
1UpGate: pick one item from nearest artboard. Play it, and start the next item when it ends. Continue.
2UpGate: pick two items from nearest artboard. One is exiting stage, one is entering stage, cue one up and play it every time one exits stage left
3UpGate: three items from nearest artboard, same as 2Up but with one in the middle between them.
*/
/* inside Flotsam.as:
var x1 = inner()._x
gotoAndStop(_totalframes-1)
var x2 = inner()._x
rewind()
trace([x1, x2, x2-x1])
//x1-x2 = true width of mc during its lifespan
*/
class com.example.Roach extends MovieClip{
function Roach(){
stop()
_visible = false
var placeOfBirth = _root._currentframe
var instanceWillPlay = Math.round(Math.random())
if (instanceWillPlay) {
var moi = this
var playMe = function(){
clearInterval(playMeInterval)
moi._visible = true
moi.play()
}
var killMe = function(){
moi.stop()
var restartMe = function(){
clearInterval(restartMeInterval)
moi.play()
}
if (_root._currentframe!==placeOfBirth) {
clearInterval(killMeInterval)
} else {
var restartMeInterval = setInterval(restartMe, (waitFor + movielength)* Math.round(Math.random()))
}
}
var movielength = _totalframes * 24 / 1000
var waitFor = Math.round(Math.random() * movielength)
var playMeInterval = setInterval(playMe, waitFor)
var killMeInterval = setInterval(killMe, (waitFor + movielength)* Math.round(Math.random()))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment