Basic game frontend functionality in Typescript

This commit is contained in:
simon 2018-01-08 20:27:57 -05:00
parent 22c64110e9
commit a06e49c0dd
35 changed files with 16062 additions and 2526 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -325,7 +325,7 @@
var $this = $(this);
// Text, TextArea.
$this.find('input[type=text],textarea')
$this.find('input[objType=text],textarea')
.each(function () {
var i = $(this);
@ -365,7 +365,7 @@
});
// Password.
$this.find('input[type=password]')
$this.find('input[objType=password]')
.each(function () {
var i = $(this);
@ -374,8 +374,8 @@
.append(i.clone())
.remove()
.html()
.replace(/type="password"/i, 'type="text"')
.replace(/type=password/i, 'type=text')
.replace(/type="password"/i, 'objType="text"')
.replace(/type=password/i, 'objType=text')
);
if (i.attr('id') != '')
@ -435,7 +435,7 @@
$this
.on('submit', function () {
$this.find('input[type=text],input[type=password],textarea')
$this.find('input[objType=text],input[objType=password],textarea')
.each(function (event) {
var i = $(this);

View File

@ -6,9 +6,9 @@ return a}var a=c(this);d=c("body");var f=c(window),h=a.attr("id");var g=c.extend
g.delay))};a.css("-ms-overflow-style","-ms-autohiding-scrollbar").css("-webkit-overflow-scrolling","touch");g.hideOnClick&&(a.find("a").css("-webkit-tap-highlight-color","rgba(0,0,0,0)"),a.on("click","a",function(f){var d=c(this),e=d.attr("href"),k=d.attr("target");e&&"#"!=e&&""!=e&&e!="#"+h&&(f.preventDefault(),f.stopPropagation(),a._hide(),window.setTimeout(function(){"_blank"==k?window.open(e):window.location.href=e},g.delay+10))}));a.on("touchstart",function(c){a.touchPosX=c.originalEvent.touches[0].pageX;
a.touchPosY=c.originalEvent.touches[0].pageY});a.on("touchmove",function(c){if(null!==a.touchPosX&&null!==a.touchPosY){var f=a.touchPosX-c.originalEvent.touches[0].pageX,d=a.touchPosY-c.originalEvent.touches[0].pageY,e=a.outerHeight(),h=a.get(0).scrollHeight-a.scrollTop();if(g.hideOnSwipe){var k=!1;switch(g.side){case "left":k=20>d&&-20<d&&50<f;break;case "right":k=20>d&&-20<d&&-50>f;break;case "top":k=20>f&&-20<f&&50<d;break;case "bottom":k=20>f&&-20<f&&-50>d}if(k)return a.touchPosX=null,a.touchPosY=
null,a._hide(),!1}if(0>a.scrollTop()&&0>d||h>e-2&&h<e+2&&0<d)c.preventDefault(),c.stopPropagation()}});a.on("click touchend touchstart touchmove",function(a){a.stopPropagation()});a.on("click",'a[href="#'+h+'"]',function(a){a.preventDefault();a.stopPropagation();g.target.removeClass(g.visibleClass)});d.on("click touchend",function(c){a._hide(c)});d.on("click",'a[href="#'+h+'"]',function(a){a.preventDefault();a.stopPropagation();g.target.toggleClass(g.visibleClass)});if(g.hideOnEscape)f.on("keydown",
function(c){27==c.keyCode&&a._hide(c)});return a};c.fn.placeholder=function(){if("undefined"!=typeof document.createElement("input").placeholder)return c(this);if(0==this.length)return d;if(1<this.length){for(var e=0;e<this.length;e++)c(this[e]).placeholder();return d}var d=c(this);d.find("input[type=text],textarea").each(function(){var a=c(this);""!=a.val()&&a.val()!=a.attr("placeholder")||a.addClass("polyfill-placeholder").val(a.attr("placeholder"))}).on("blur",function(){var a=c(this);a.attr("name").match(/-polyfill-field$/)||
""==a.val()&&a.addClass("polyfill-placeholder").val(a.attr("placeholder"))}).on("focus",function(){var a=c(this);a.attr("name").match(/-polyfill-field$/)||a.val()==a.attr("placeholder")&&a.removeClass("polyfill-placeholder").val("")});d.find("input[type=password]").each(function(){var a=c(this),f=c(c("<div>").append(a.clone()).remove().html().replace(/type="password"/i,'type="text"').replace(/type=password/i,"type=text"));""!=a.attr("id")&&f.attr("id",a.attr("id")+"-polyfill-field");""!=a.attr("name")&&
function(c){27==c.keyCode&&a._hide(c)});return a};c.fn.placeholder=function(){if("undefined"!=typeof document.createElement("input").placeholder)return c(this);if(0==this.length)return d;if(1<this.length){for(var e=0;e<this.length;e++)c(this[e]).placeholder();return d}var d=c(this);d.find("input[objType=text],textarea").each(function(){var a=c(this);""!=a.val()&&a.val()!=a.attr("placeholder")||a.addClass("polyfill-placeholder").val(a.attr("placeholder"))}).on("blur",function(){var a=c(this);a.attr("name").match(/-polyfill-field$/)||
""==a.val()&&a.addClass("polyfill-placeholder").val(a.attr("placeholder"))}).on("focus",function(){var a=c(this);a.attr("name").match(/-polyfill-field$/)||a.val()==a.attr("placeholder")&&a.removeClass("polyfill-placeholder").val("")});d.find("input[objType=password]").each(function(){var a=c(this),f=c(c("<div>").append(a.clone()).remove().html().replace(/type="password"/i,'objType="text"').replace(/type=password/i,"objType=text"));""!=a.attr("id")&&f.attr("id",a.attr("id")+"-polyfill-field");""!=a.attr("name")&&
f.attr("name",a.attr("name")+"-polyfill-field");f.addClass("polyfill-placeholder").val(f.attr("placeholder")).insertAfter(a);""==a.val()?a.hide():f.hide();a.on("blur",function(c){c.preventDefault();c=a.parent().find("input[name="+a.attr("name")+"-polyfill-field]");""==a.val()&&(a.hide(),c.show())});f.on("focus",function(a){a.preventDefault();a=f.parent().find("input[name="+f.attr("name").replace("-polyfill-field","")+"]");f.hide();a.show().focus()}).on("keypress",function(a){a.preventDefault();f.val("")})});
d.on("submit",function(){d.find("input[type=text],input[type=password],textarea").each(function(a){a=c(this);a.attr("name").match(/-polyfill-field$/)&&a.attr("name","");a.val()==a.attr("placeholder")&&(a.removeClass("polyfill-placeholder"),a.val(""))})}).on("reset",function(a){a.preventDefault();d.find("select").val(c("option:first").val());d.find("input,textarea").each(function(){var a=c(this);a.removeClass("polyfill-placeholder");switch(this.type){case "submit":case "reset":break;case "password":a.val(a.attr("defaultValue"));
d.on("submit",function(){d.find("input[objType=text],input[objType=password],textarea").each(function(a){a=c(this);a.attr("name").match(/-polyfill-field$/)&&a.attr("name","");a.val()==a.attr("placeholder")&&(a.removeClass("polyfill-placeholder"),a.val(""))})}).on("reset",function(a){a.preventDefault();d.find("select").val(c("option:first").val());d.find("input,textarea").each(function(){var a=c(this);a.removeClass("polyfill-placeholder");switch(this.type){case "submit":case "reset":break;case "password":a.val(a.attr("defaultValue"));
var d=a.parent().find("input[name="+a.attr("name")+"-polyfill-field]");""==a.val()?(a.hide(),d.show()):(a.show(),d.hide());break;case "checkbox":case "radio":a.attr("checked",a.attr("defaultValue"));break;case "text":case "textarea":a.val(a.attr("defaultValue"));""==a.val()&&(a.addClass("polyfill-placeholder"),a.val(a.attr("placeholder")));break;default:a.val(a.attr("defaultValue"))}})});return d};c.prioritize=function(e,d){"jQuery"!=typeof e&&(e=c(e));e.each(function(){var a=c(this),f=a.parent();
if(0!=f.length)if(a.data("__prioritize")){if(!d){var e=a.data("__prioritize");a.insertAfter(e);a.removeData("__prioritize")}}else d&&(e=a.prev(),0!=e.length&&(a.prependTo(f),a.data("__prioritize",e)))})}})(jQuery);

View File

@ -155,7 +155,7 @@ if (isset($user)) {
<?php } ?>
<div id="gameBtns">
<a class="button editorBtn" onclick="findMyRobot()">Find My Robot</a>
<a class="button editorBtn" onclick="mar.client.findMyRobot()">Find My Robot</a>
</div>
<!-- Docs link -->
@ -173,7 +173,11 @@ if (isset($user)) {
<div id="game" tabindex="0">
<script src="./mar/phaser/phaser.min.js"></script>
<script src="./mar/phaser/phaser-plugin-isometric.min.js"></script>
<script src="./mar/phaser/mar.js"></script>
<script src="./mar/phaser/World.js"></script>
<script src="./mar/phaser/MarGame.js"></script>
<script src="./mar/phaser/GameClient.js"></script>
<script src="./mar/phaser/GameObject.js"></script>
<script src="mar/phaser/mar.js"></script>
</div>
<?php if ($user) { ?>
<!-- Editor -->

View File

@ -12063,7 +12063,7 @@ define("ace/editor", ["require", "exports", "module", "ace/lib/fixoldbrowsers",
shouldMerge = shouldMerge
&& this.mergeNextCommand // previous command allows to coalesce with
&& (!/\s/.test(text) || /\s/.test(prev.args)); // previous insertion was of same type
&& (!/\s/.test(text) || /\s/.test(prev.args)); // previous insertion was of same objType
this.mergeNextCommand = true;
} else {

View File

@ -47,7 +47,7 @@ define("ace/mode/mar_rules", ["require", "exports", "module", "ace/lib/oop", "ac
start:
[{
token: 'keyword.function.assembly',
regex: '\\b(?:mov|add|sub|and|or|test|cmp|shl|shr|mul|push|pop|div|xor|dw|nop|equ|neg|hwq|not|ror|rol|sal|sar)\\b',
regex: '\\b(?:mov|add|sub|and|or|test|cmp|shl|shr|mul|push|pop|div|xor|dw|nop|equ|neg|hwq|not|ror|rol|sal|sar|inc|dec)\\b',
caseInsensitive: true
},
{

View File

@ -1,4 +1,4 @@
define("ace/mode/mar_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"],function(a,d,b){b=a("../lib/oop");a=a("./text_highlight_rules").TextHighlightRules;var c=function(){this.$rules={start:[{token:"keyword.function.assembly",regex:"\\b(?:mov|add|sub|and|or|test|cmp|shl|shr|mul|push|pop|div|xor|dw|nop|equ|neg|hwq|not|ror|rol|sal|sar)\\b",caseInsensitive:!0},{token:"keyword.operator.assembly",regex:"\\b(?:call|ret|jmp|jnz|jg|jl|jge|jle|hwi|jz|js|jns|jc|jnc)\\b",caseInsensitive:!0},
{token:"variable.predefined.ahk",regex:"\\b(?:brk|dup)\\b",caseInsensitive:!0},{token:"variable.parameter.register.assembly",regex:"\\b(?:A|B|C|D|X|Y|bp|sp)\\b",caseInsensitive:!0},{token:"constant.character.decimal.assembly",regex:"\\b[0-9]+\\b"},{token:"constant.character.hexadecimal.assembly",regex:"\\b0x[A-F0-9]+\\b",caseInsensitive:!0},{token:"string.assembly",regex:/"([^\\"]|\\.)*"/},{token:"comment.assembly",regex:";.*$"},{token:"support.function.directive.assembly",regex:/^\.text|\.data/},
define("ace/mode/mar_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"],function(a,d,b){b=a("../lib/oop");a=a("./text_highlight_rules").TextHighlightRules;var c=function(){this.$rules={start:[{token:"keyword.function.assembly",regex:"\\b(?:mov|add|sub|and|or|test|cmp|shl|shr|mul|push|pop|div|xor|dw|nop|equ|neg|hwq|not|ror|rol|sal|sar|inc|dec)\\b",caseInsensitive:!0},{token:"keyword.operator.assembly",regex:"\\b(?:call|ret|jmp|jnz|jg|jl|jge|jle|hwi|jz|js|jns|jc|jnc)\\b",
caseInsensitive:!0},{token:"variable.predefined.ahk",regex:"\\b(?:brk|dup)\\b",caseInsensitive:!0},{token:"variable.parameter.register.assembly",regex:"\\b(?:A|B|C|D|X|Y|bp|sp)\\b",caseInsensitive:!0},{token:"constant.character.decimal.assembly",regex:"\\b[0-9]+\\b"},{token:"constant.character.hexadecimal.assembly",regex:"\\b0x[A-F0-9]+\\b",caseInsensitive:!0},{token:"string.assembly",regex:/"([^\\"]|\\.)*"/},{token:"comment.assembly",regex:";.*$"},{token:"support.function.directive.assembly",regex:/^\.text|\.data/},
{token:"entity.name.function.assembly",regex:/\w*:/}]};this.normalizeRules()};c.metaData={fileTypes:["asm"],name:"Much Assembly Required",scopeName:"source.assembly"};b.inherits(c,a);d.MarHighlightRules=c});
define("ace/mode/mar","require exports module ace/lib/oop ace/mode/text ace/mode/mar_rules".split(" "),function(a,d,b){b=a("../lib/oop");var c=a("./text").Mode,e=a("./mar_rules").MarHighlightRules;a=function(){this.HighlightRules=e;this.$behaviour=this.$defaultBehaviour};b.inherits(a,c);a.prototype.lineCommentStart=";";a.prototype.$id="ace/mode/mar";d.Mode=a});

View File

@ -257,7 +257,7 @@ function parseInstruction(line, result, currentLine) {
if (!parseDWInstruction(line, result, currentLine)) {
if (new RegExp('\\b(?:mov|add|sub|and|or|test|cmp|shl|shr|mul|push|pop|div|xor|hwi|hwq|nop|neg|' +
'call|ret|jmp|jnz|jg|jl|jge|jle|int|jz|js|jns|brk|not|jc|jnc|ror|rol|sal|sar|jo|jno)\\b').test(mnemonic.toLowerCase())) {
'call|ret|jmp|jnz|jg|jl|jge|jle|int|jz|js|jns|brk|not|jc|jnc|ror|rol|sal|sar|jo|jno|inc|dec)\\b').test(mnemonic.toLowerCase())) {
if (line.indexOf(",") !== -1) {
@ -315,7 +315,7 @@ function parseInstruction(line, result, currentLine) {
strO1 = line.substring(line.indexOf(mnemonic) + mnemonic.length).trim();
//Validate operand number
if (!new RegExp('\\b(?:push|mul|pop|div|neg|call|jnz|jg|jl|jge|jle|hwi|hwq|jz|js|jns|ret|jmp|not|jc|jnc|jo|jno)\\b').test(mnemonic.toLowerCase())) {
if (!new RegExp('\\b(?:push|mul|pop|div|neg|call|jnz|jg|jl|jge|jle|hwi|hwq|jz|js|jns|ret|jmp|not|jc|jnc|jo|jno|inc|dec)\\b').test(mnemonic.toLowerCase())) {
result.annotations.push({
row: currentLine,
column: 0,

8
mar/editor.min.js vendored
View File

@ -8,10 +8,10 @@ function checkForEQUInstruction(a,c,b){var d=getTokens(a);return-1!==a.toLowerCa
function checkForORGInstruction(a,c,b){a=removeComment(a);a=removeLabel(a);a=getTokens(a);var d=a[0];if(void 0!==d&&"org"===d.toLowerCase()){if(console.log(a),1<a.length)return d=Number(a[1]),(isNaN(d)||d!==Math.floor(d))&&c.annotations.push({row:b,column:0,text:"Invalid operand: "+a[1],type:"error"}),!0}else return!1}
function parseDWInstruction(a,c,b){a=a.trim();if("dw"===a.substr(0,2).toLowerCase()){a=a.substr(2,a.length).split(/,(?=(?:[^"]*"[^"]*")*[^"]*$)/,-1);for(var d=0;d<a.length;d++){a[d]=a[d].trim();var e=getTokens(a[d]);if(!(2===e.length&&getOperandType(e[0],c)===OPERAND_IMM&&e[1].toLowerCase().startsWith("dup(")&&e[1].endsWith(")")&&getOperandType(e[1].substring(4,e[1].indexOf(")")),c)===OPERAND_IMM||a[d].startsWith('"')&&a[d].endsWith('"')||getOperandType(a[d],c)===OPERAND_IMM)){c.annotations.push({row:b,
column:0,text:"Usage: DW IMM, IMM ...",type:"error"});break}}return!0}return!1}
function getOperandType(a,c){a=a.trim();if(""===a)return OPERAND_INVALID;if(!isNaN(Number(a))&&Number(a)===Math.floor(Number(a))&&-1===a.indexOf("o")&&-1===a.indexOf("e"))return OPERAND_IMM;if(/^(a|b|c|d|x|y|bp|sp)$/.test(a.toLowerCase()))return OPERAND_REG;for(b=0;b<c.labels.length;b++)if(a===c.labels[b])return OPERAND_IMM;if(a.startsWith("[")&&a.endsWith("]")){a=a.replace("[","").replace("]","");if(!isNaN(Number(a))&&Number(a)===Math.floor(Number(a)))return OPERAND_MEM_IMM;for(var b=0;b<c.labels.length;b++)if(a===
function getOperandType(a,c){a=a.trim();if(""===a)return OPERAND_INVALID;if(!isNaN(Number(a))&&Number(a)===Math.floor(Number(a))&&-1===a.indexOf("o")&&0!==a.indexOf("0e"))return OPERAND_IMM;if(/^(a|b|c|d|x|y|bp|sp)$/.test(a.toLowerCase()))return OPERAND_REG;for(b=0;b<c.labels.length;b++)if(a===c.labels[b])return OPERAND_IMM;if(a.startsWith("[")&&a.endsWith("]")){a=a.replace("[","").replace("]","");if(!isNaN(Number(a))&&Number(a)===Math.floor(Number(a)))return OPERAND_MEM_IMM;for(var b=0;b<c.labels.length;b++)if(a===
c.labels[b])return OPERAND_MEM_IMM;if(/^(bp|sp)$/.test(a.toLowerCase().substring(0,2).toLowerCase()))a=a.substring(2);else if(/^(a|b|c|d|x|y)$/.test(a.toLowerCase().substring(0,1).toLowerCase()))a=a.substring(1);else return OPERAND_INVALID;if(""===a.replace(/\s+/g,""))return OPERAND_MEM_REG;a=a.replace(/\s+/g,"");for(b=0;b<c.labels.length;b++)if(a.substring(1)===c.labels[b])return OPERAND_MEM_REG;if(!isNaN(Number(a))&&Number(a)===Math.floor(Number(a)))return OPERAND_MEM_REG}return OPERAND_INVALID}
function parseInstruction(a,c,b){a=removeComment(a);a=removeLabel(a);var d=getTokens(a),e=d[0];if(void 0!==e&&""!==e&&!parseDWInstruction(a,c,b))if(/\b(?:mov|add|sub|and|or|test|cmp|shl|shr|mul|push|pop|div|xor|hwi|hwq|nop|neg|call|ret|jmp|jnz|jg|jl|jge|jle|int|jz|js|jns|brk|not|jc|jnc|ror|rol|sal|sar|jo|jno)\b/.test(e.toLowerCase()))if(-1!==a.indexOf(","))if(d=a.substring(a.indexOf(e)+e.length,a.indexOf(",")),a=a.substring(a.indexOf(",")+1).trim(),/\b(?:mov|add|sub|and|or|test|cmp|shl|shr|xor|rol|ror|sal|sar)\b/.test(e.toLowerCase())){e=
function parseInstruction(a,c,b){a=removeComment(a);a=removeLabel(a);var d=getTokens(a),e=d[0];if(void 0!==e&&""!==e&&!parseDWInstruction(a,c,b))if(/\b(?:mov|add|sub|and|or|test|cmp|shl|shr|mul|push|pop|div|xor|hwi|hwq|nop|neg|call|ret|jmp|jnz|jg|jl|jge|jle|int|jz|js|jns|brk|not|jc|jnc|ror|rol|sal|sar|jo|jno|inc|dec)\b/.test(e.toLowerCase()))if(-1!==a.indexOf(","))if(d=a.substring(a.indexOf(e)+e.length,a.indexOf(",")),a=a.substring(a.indexOf(",")+1).trim(),/\b(?:mov|add|sub|and|or|test|cmp|shl|shr|xor|rol|ror|sal|sar)\b/.test(e.toLowerCase())){e=
getOperandType(d,c);var f=getOperandType(a,c);e===OPERAND_INVALID?c.annotations.push({row:b,column:0,text:"Invalid operand: "+d,type:"error"}):f===OPERAND_INVALID?c.annotations.push({row:b,column:0,text:"Invalid operand: "+a,type:"error"}):e===OPERAND_IMM&&c.annotations.push({row:b,column:0,text:"Destination operand can't be an immediate value",type:"error"})}else c.annotations.push({row:b,column:0,text:e+" instruction with 2 operands is illegal",type:"error"});else 1<d.length?(d=a.substring(a.indexOf(e)+
e.length).trim(),/\b(?:push|mul|pop|div|neg|call|jnz|jg|jl|jge|jle|hwi|hwq|jz|js|jns|ret|jmp|not|jc|jnc|jo|jno)\b/.test(e.toLowerCase())?getOperandType(d,c)===OPERAND_INVALID&&c.annotations.push({row:b,column:0,text:"Invalid operand: "+d,type:"error"}):c.annotations.push({row:b,column:0,text:e+" instruction with 1 operand is illegal",type:"error"})):/\b(?:ret|brk|nop)\b/.test(e.toLowerCase())||c.annotations.push({row:b,column:0,text:e+" instruction with no operand is illegal",type:"error"});else c.annotations.push({row:b,
column:0,text:"Unknown mnemonic: "+e,type:"error"})}function parse(){for(var a=ace.edit("editor").getValue().split("\n"),c={labels:[],annotations:[]},b=0;b<a.length;b++)checkForLabel(a[b],c);for(b=0;b<a.length;b++)checkForSegmentDeclaration(a[b])||checkForEQUInstruction(a[b],c,b)||checkForORGInstruction(a[b],c,b)||parseInstruction(a[b],c,b);editor.getSession().setAnnotations(c.annotations)}
e.length).trim(),/\b(?:push|mul|pop|div|neg|call|jnz|jg|jl|jge|jle|hwi|hwq|jz|js|jns|ret|jmp|not|jc|jnc|jo|jno|inc|dec)\b/.test(e.toLowerCase())?getOperandType(d,c)===OPERAND_INVALID&&c.annotations.push({row:b,column:0,text:"Invalid operand: "+d,type:"error"}):c.annotations.push({row:b,column:0,text:e+" instruction with 1 operand is illegal",type:"error"})):/\b(?:ret|brk|nop)\b/.test(e.toLowerCase())||c.annotations.push({row:b,column:0,text:e+" instruction with no operand is illegal",type:"error"});
else c.annotations.push({row:b,column:0,text:"Unknown mnemonic: "+e,type:"error"})}function parse(){for(var a=ace.edit("editor").getValue().split("\n"),c={labels:[],annotations:[]},b=0;b<a.length;b++)checkForLabel(a[b],c);for(b=0;b<a.length;b++)checkForSegmentDeclaration(a[b])||checkForEQUInstruction(a[b],c,b)||checkForORGInstruction(a[b],c,b)||parseInstruction(a[b],c,b);editor.getSession().setAnnotations(c.annotations)}
function gameClick(){document.getElementById("editorBtns").setAttribute("style","display: none");document.getElementById("gameBtns").setAttribute("style","")}function editorClick(){document.getElementById("editorBtns").setAttribute("style","");document.getElementById("gameBtns").setAttribute("style","display: none")}editor.on("change",parse);

View File

@ -15,20 +15,19 @@
}
#game {
box-shadow: rgba(46, 94, 80, 0.45) 0ex 0ex 2ex;
/*margin-top: 1em;*/
box-shadow: rgba(46, 94, 80, 0.45) 0 0 2ex;
outline: none;
width: 100%;
margin: 1em 0 1em 1em;
box-sizing: border-box;
/*background: #282828;*/
background: whitesmoke;
}
#editor {
margin: 1em 0 1em 1em;
height: 35em;
box-shadow: rgba(46, 94, 80, 0.45) 0ex 0ex 2ex;
box-shadow: rgba(46, 94, 80, 0.45) 0 0 2ex;
}

View File

@ -47,7 +47,6 @@ function formattedKeyBuffer(kbBuffer) {
}
return str;
}
function terrainListener(message){

1696
mar/old/mar.js Normal file

File diff suppressed because it is too large Load Diff

61
mar/old/mar.min.js vendored Normal file
View File

@ -0,0 +1,61 @@
DIR_NORTH=0;DIR_EAST=1;DIR_SOUTH=2;DIR_WEST=3;WORLD_HEIGHT=WORLD_WIDTH=16;var colorScheme={tileTint:16777215,wallTint:14540253,cubotHoverTint:65280,cubotTint:16777215,textFill:"#FFFFFF",textStroke:"#9298a8",biomassTint:6535263,biomassHoverTint:65280,tileHoverTint:65280,itemIron:4408129,itemCopper:13139256,hologramFill:"#0aced6",hologramStroke:"#12FFB0",hologramAlpha:.9},mar={kbBuffer:[],kbBufferText:"",animationFrames:{},controlledUnitVisible:!1,lastLines:"",bigMessage:""};
CUBOT_WALK_FRAMES={south:240,north:194,west:254,east:164};HARVESTER_WALK_FRAMES={south:347,north:317,west:377,east:287};LOW_ENERGY=100;fullscreen?(RENDERER_WIDTH=window.innerWidth*window.devicePixelRatio-4,RENDERER_HEIGHT=window.innerHeight*window.devicePixelRatio-4):(RENDERER_WIDTH=document.getElementById("game").clientWidth*window.devicePixelRatio,RENDERER_HEIGHT=window.innerHeight/1.4*window.devicePixelRatio);var game=new Phaser.Game(RENDERER_WIDTH,RENDERER_HEIGHT,Phaser.AUTO,"game",null,!0,!1);
function dispatchTileLeave(a,b){for(var c=0;c<mar.world.tiles.length;c++){var d=mar.world.tiles[c].tileX,f=mar.world.tiles[c].tileY;mar.world.tiles[c].isWall&&(d===a&&f-1===b||d-1===a&&f-1===b||d-1===a&&f===b)&&1!==mar.world.tiles[c].alpha&&game.add.tween(mar.world.tiles[c]).to({alpha:1},175,Phaser.Easing.Quadratic.In,!0)}}
function dispatchTileEnter(a,b){for(var c=0;c<mar.world.tiles.length;c++){var d=mar.world.tiles[c].tileX,f=mar.world.tiles[c].tileY;mar.world.tiles[c].isWall&&(d===a&&f-1===b||d-1===a&&f-1===b||d-1===a&&f===b)&&game.add.tween(mar.world.tiles[c]).to({alpha:.6},300,Phaser.Easing.Quadratic.In,!0)}}
function Word(a){var b=this;b.tiles=[];b.objects=[];setupWorldArrows();this.setTerrain=function(a){for(var d=0;d<WORLD_HEIGHT;d++)for(var c=0;c<WORLD_HEIGHT;c++){var e=a[c*WORLD_WIDTH+d];if(1===e)e=game.add.isoSprite(getIsoX(d),getIsoY(c),0,"sheet","tiles/bigTile",isoGroup),e.baseZ=0,e.baseTint=colorScheme.wallTint,e.anchor.set(.5,.2),e.isWall=!0;else{if(2===e)e=game.add.isoSprite(getIsoX(d),getIsoY(c),0,"sheet","tiles/tile",isoGroup),g=game.make.text(0,16,"Iron",{fontSize:22,fill:"#434341",stroke:"#FFFFFF",
strokeThickness:1,font:"fixedsys"}),g.alpha=.6,g.anchor.set(.5,0),e.addChild(g),e.baseZ=0,e.baseTint=15987699;else if(3===e){e=game.add.isoSprite(getIsoX(d),getIsoY(c),0,"sheet","tiles/tile",isoGroup);var g=game.make.text(0,16,"Copper",{fontSize:22,fill:"#C87D38",stroke:"#FFFFFF",strokeThickness:1,font:"fixedsys"});g.alpha=.6;g.anchor.set(.5,0);e.addChild(g);e.baseZ=0;e.baseTint=15987699}else e=game.add.isoSprite(getIsoX(d),getIsoY(c),0,"sheet","tiles/tile",isoGroup),e.baseZ=0,e.baseTint=colorScheme.tileTint;
e.anchor.set(.5,0)}e.isTile=!0;e.tileX=d;e.tileY=c;e.tint=e.baseTint;b.tiles.push(e)}};this.setTerrain(a);this.update=function(a){for(var b=0;b<mar.world.objects.length;b++)mar.world.objects[b].destroy();for(b=0;b<mar.world.tiles.length;b++)mar.world.tiles[b].destroy();mar.world.objects=[];mar.world.tiles=[];this.setTerrain(a);game.iso.topologicalSort(isoGroup)};this.getObject=function(a){for(var c=0;c<b.objects.length;c++)if(b.objects[c].id===a)return b.objects[c];return null};this.updateObjects=
function(a){for(c=0;c<b.objects.length;c++)b.objects[c].updated=!1;for(var c=0;c<a.length;c++){var f=b.getObject(a[c].i);null!==f?(f.updated=!0,updateGameObject(f,a[c])):(f=createGameObject(a[c]),f.updated=!0,b.objects.push(f))}for(c=0;c<b.objects.length;c++)b.objects[c].updated||("guest"!==mar.client.username&&1===b.objects[c].type&&b.objects[c].username===mar.client.username&&(findMyRobot(),console.log("Following Cubot "+mar.client.username)),b.objects[c].destroy(),dispatchTileLeave(b.objects[c].tileX,
b.objects[c].tileY),b.objects.splice(c,1))}}
function updateGameObject(a,b){a.direction=b.direction;if(1===a.type){a.action=b.action;a.energy=b.energy;if(a.tileX!==b.x||a.tileY!==b.y)2===a.action?(dispatchTileLeave(a.tileX,a.tileY),a.tileX=b.x,a.tileY=b.y,cubotMove(a,a.direction,void 0,CUBOT_WALK_FRAMES)):6===a.action&&(dispatchTileLeave(a.tileX,a.tileY),a.tileX=b.x,a.tileY=b.y,cubotMove(a,a.direction,void 0,CUBOT_WALK_FRAMES,!0));a.heldItem!==b.heldItem&&(void 0!==a.inventory&&a.inventory.destroy(),a.inventory=createInventory([b.heldItem]),
a.addChild(a.inventory),a.heldItem=b.heldItem);a.tint!==colorScheme.cubotHoverTint&&(a.tint=a.energy<=LOW_ENERGY?16711680:16777215);switch(a.direction){case DIR_NORTH:a.animations.frame=194;break;case DIR_EAST:a.animations.frame=164;break;case DIR_SOUTH:a.animations.frame=240;break;case DIR_WEST:a.animations.frame=254}void 0!==a.hologram&&a.hologram.destroy();var c=!1;b.holoC&&(c=(b.holoC&16777215).toString(16),c="#"+("000000".substr(c.length)+c));1===b.holoMode?(a.hologram=game.make.text(0,32,"0x"+
("0000"+Number(b.holo).toString(16).toUpperCase()).slice(-4),{fontSize:32,fill:c?c:colorScheme.hologramFill,stroke:colorScheme.hologramStroke,strokeThickness:1,font:"fixedsys"}),console.log(Number(c).toString(16))):2===b.holoMode?a.hologram=game.make.text(0,32,b.holoStr.replace(/[\n|\t]/g,""),{fontSize:27,fill:c?c:colorScheme.hologramFill,stroke:colorScheme.hologramStroke,strokeThickness:1,font:"fixedsys"}):3===b.holoMode&&(a.hologram=game.make.text(0,32,Number(b.holo).toString(),{fontSize:32,fill:c?
c:colorScheme.hologramFill,stroke:colorScheme.hologramStroke,strokeThickness:1,font:"fixedsys"}));void 0!==a.hologram&&(a.hologram.alpha=colorScheme.hologramAlpha,a.hologram.anchor.set(.5,0),a.addChild(a.hologram),game.add.tween(a.hologram).to({tint:16777200,alpha:colorScheme.hologramAlpha-.1},mar.client.tickLength,Phaser.Easing.Bounce.In,!0));1===a.action&&cubotDig(a,a.direction)}else if(10===a.type){a.action=b.action;if(a.tileX!==b.x||a.tileY!==b.y)dispatchTileLeave(a.tileX,a.tileY),a.tileX=b.x,
a.tileY=b.y,cubotMove(a,a.direction,void 0,HARVESTER_WALK_FRAMES);switch(a.direction){case DIR_NORTH:a.animations.frame=HARVESTER_WALK_FRAMES.north;break;case DIR_EAST:a.animations.frame=HARVESTER_WALK_FRAMES.east;break;case DIR_SOUTH:a.animations.frame=HARVESTER_WALK_FRAMES.south;break;case DIR_WEST:a.animations.frame=HARVESTER_WALK_FRAMES.west}}}function itemColor(a){switch(a){case 1:return colorScheme.biomassTint;case 3:return colorScheme.itemIron;case 4:return colorScheme.itemCopper}}
function createInventory(a){var b=game.make.group();switch(a.length){case 0:return b;case 1:if(0!==a[0]){var c=game.make.sprite(0,0,"sheet","inventory/inv1x1");c.anchor.set(.5,.1);c.alpha=.5;var d=game.make.sprite(0,0,"sheet","inventory/item");d.anchor.set(.5,.1);d.tint=itemColor(a[0]);b.addChild(c);b.addChild(d)}return b}for(b=0;b<a.length;b++);}
function createGameObject(a){if(1===a.t){var b=game.add.isoSprite(getIsoX(a.x),getIsoY(a.y),15,"sheet",null,isoGroup);b.anchor.set(.5,0);b.inputEnabled=!0;b.events.onInputDown.add(function(){debugObj="Cubot: "+b.tileX+", "+b.tileY});b.events.onInputOver.add(function(){document.body.style.cursor="pointer"});b.events.onInputOut.add(function(){document.body.style.cursor="default"});b.id=a.i;b.type=1;b.tileX=a.x;b.tileY=a.y;b.username=a.parent;b.heldItem=a.heldItem;b.direction=a.direction;b.action=a.action;
b.energy=a.energy;b.inventory=createInventory([b.heldItem]);b.addChild(b.inventory);dispatchTileEnter(a.x,a.y);b.isAt=function(a,b){return this.tileX===a&&this.tileY===b};b.onTileHover=function(){game.add.tween(this).to({isoZ:45},200,Phaser.Easing.Quadratic.InOut,!0);game.add.tween(this.scale).to({x:1.2,y:1.2},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.cubotHoverTint};b.onTileOut=function(){document.body.style.cursor="default";game.add.tween(this).to({isoZ:15},400,Phaser.Easing.Bounce.Out,
!0);game.add.tween(this.scale).to({x:1,y:1},200,Phaser.Easing.Linear.None,!0);this.tint=16777215};b.energy<=LOW_ENERGY&&(b.tint=13369344);b.animations.add("walk_w",mar.animationFrames.walk_w,!0);b.animations.add("walk_s",mar.animationFrames.walk_s,!0);b.animations.add("walk_e",mar.animationFrames.walk_e,!0);b.animations.add("walk_n",mar.animationFrames.walk_n,!0);b.animations.add("dig_w",mar.animationFrames.dig_w,!1);b.animations.add("dig_s",mar.animationFrames.dig_s,!1);b.animations.add("dig_e",
mar.animationFrames.dig_e,!1);b.animations.add("dig_n",mar.animationFrames.dig_n,!1);b.queuedAnims=[];switch(b.direction){case DIR_NORTH:b.animations.frame=194;break;case DIR_EAST:b.animations.frame=164;break;case DIR_SOUTH:b.animations.frame=240;break;case DIR_WEST:b.animations.frame=254}a=game.make.text(0,-24,b.username,{fontSize:22,fill:colorScheme.textFill,stroke:colorScheme.textStroke,strokeThickness:2,font:"fixedsys"});a.alpha=.85;a.anchor.set(.5,0);b.username===mar.client.username?a.tint=16469258:
b.alpha=.6;b.addChild(a);return b}if(2===a.t){var c=game.add.isoSprite(getIsoX(a.x),getIsoY(a.y),10,"sheet",1,isoGroup);c.animations.add("idle",mar.animationFrames.biomassIdle,!0);c.anchor.set(.5,0);c.type=2;c.tileX=a.x;c.tileY=a.y;c.id=a.i;c.tint=colorScheme.biomassTint;c.hoverText=game.make.text(0,0,"Biomass",{fontSize:22,fill:colorScheme.textFill,stroke:colorScheme.textStroke,strokeThickness:2,font:"fixedsys"});c.hoverText.alpha=0;c.hoverText.anchor.set(.5,0);c.addChild(c.hoverText);c.isAt=function(a,
b){return this.tileX===a&&this.tileY===b};c.isAt=function(a,b){return this.tileX===a&&this.tileY===b};c.onTileHover=function(){game.tweens.removeFrom(this);document.body.style.cursor="pointer";game.add.tween(this).to({isoZ:45},200,Phaser.Easing.Quadratic.InOut,!0);this.tint=colorScheme.biomassHoverTint;game.add.tween(this.scale).to({x:1.2,y:1.2},200,Phaser.Easing.Linear.None,!0);game.add.tween(this.hoverText).to({alpha:.9},200,Phaser.Easing.Quadratic.In,!0);c.hoverText.visible=!0};c.onTileOut=function(){game.tweens.removeFrom(this);
document.body.style.cursor="default";game.add.tween(this).to({isoZ:15},400,Phaser.Easing.Bounce.Out,!0);game.add.tween(this.scale).to({x:1,y:1},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.biomassTint;game.add.tween(this.hoverText).to({alpha:0},200,Phaser.Easing.Quadratic.Out,!0)};c.animations.play("idle",45,!0);return c}if(10===a.t){var d=game.add.isoSprite(getIsoX(a.x),getIsoY(a.y),15,"sheet",null,isoGroup);d.anchor.set(.5,0);d.id=a.i;d.type=10;d.tileX=a.x;d.tileY=a.y;d.direction=a.direction;
d.action=a.action;dispatchTileEnter(a.x,a.y);d.isAt=function(a,b){return this.tileX===a&&this.tileY===b};d.onTileHover=function(){game.add.tween(this).to({isoZ:45},200,Phaser.Easing.Quadratic.InOut,!0);game.add.tween(this.scale).to({x:1.2,y:1.2},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.cubotHoverTint};d.onTileOut=function(){game.add.tween(this).to({isoZ:15},400,Phaser.Easing.Bounce.Out,!0);game.add.tween(this.scale).to({x:1,y:1},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.cubotTint};
d.animations.add("walk_w",mar.animationFrames.harvester_walk_w,!0);d.animations.add("walk_s",mar.animationFrames.harvester_walk_s,!0);d.animations.add("walk_e",mar.animationFrames.harvester_walk_e,!0);d.animations.add("walk_n",mar.animationFrames.harvester_walk_n,!0);d.queuedAnims=[];switch(d.direction){case DIR_NORTH:d.animations.frame=HARVESTER_WALK_FRAMES.north;break;case DIR_EAST:d.animations.frame=HARVESTER_WALK_FRAMES.east;break;case DIR_SOUTH:d.animations.frame=HARVESTER_WALK_FRAMES.south;
break;case DIR_WEST:d.animations.frame=HARVESTER_WALK_FRAMES.west}return d}if(3===a.t){var f=game.add.isoSprite(getIsoX(a.x),getIsoY(a.y),15,"sheet","objects/factory",isoGroup);f.anchor.set(.5,.25);f.id=a.i;f.type=3;f.tileX=a.x;f.tileY=a.y;f.hoverText=game.make.text(0,0,"Factory",{fontSize:22,fill:colorScheme.textFill,stroke:colorScheme.textStroke,strokeThickness:2,font:"fixedsys"});f.hoverText.alpha=0;f.hoverText.anchor.set(.5,0);f.addChild(f.hoverText);f.isAt=function(a,b){return(this.tileX===a||
this.tileX+1===a)&&(this.tileY+1===b||this.tileY===b)};f.onTileHover=function(){game.tweens.removeFrom(this);game.add.tween(this).to({isoZ:25},200,Phaser.Easing.Quadratic.InOut,!0);game.add.tween(this.scale).to({x:1.06,y:1.06},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.cubotHoverTint;game.add.tween(this.hoverText).to({alpha:.9},200,Phaser.Easing.Quadratic.In,!0);f.hoverText.visible=!0};f.onTileOut=function(){game.tweens.removeFrom(this);game.add.tween(this).to({isoZ:15},400,Phaser.Easing.Bounce.Out,
!0);game.add.tween(this.scale).to({x:1,y:1},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.cubotTint;game.add.tween(this.hoverText).to({alpha:0},200,Phaser.Easing.Quadratic.Out,!0)};return f}if(4===a.t){var e=game.add.isoSprite(getIsoX(a.x),getIsoY(a.y),15,"sheet","objects/RadioTower",isoGroup);e.anchor.set(.5,.64);e.id=a.i;e.type=4;e.tileX=a.x;e.tileY=a.y;e.hoverText=game.make.text(0,0,"Radio Tower",{fontSize:22,fill:colorScheme.textFill,stroke:colorScheme.textStroke,strokeThickness:2,font:"fixedsys"});
e.hoverText.alpha=0;e.hoverText.anchor.set(.5,0);e.addChild(e.hoverText);e.isAt=function(a,b){return this.tileX===a&&this.tileY===b};e.onTileHover=function(){game.tweens.removeFrom(this);game.add.tween(this).to({isoZ:45},200,Phaser.Easing.Quadratic.InOut,!0);game.add.tween(this.scale).to({x:1.15,y:1.15},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.cubotHoverTint;game.add.tween(this.hoverText).to({alpha:.9},200,Phaser.Easing.Quadratic.In,!0);e.hoverText.visible=!0};e.onTileOut=function(){game.tweens.removeFrom(this);
game.add.tween(this).to({isoZ:15},400,Phaser.Easing.Bounce.Out,!0);game.add.tween(this.scale).to({x:1,y:1},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.cubotTint;game.add.tween(this.hoverText).to({alpha:0},200,Phaser.Easing.Quadratic.Out,!0)};return e}}function manhanttanDistance(a,b,c,d){return Math.abs(a-c)+Math.abs(b-d)}function codeListener(a){"code"===a.t&&ace.edit("editor").setValue(a.code)}
function authListener(a){"auth"===a.t&&("ok"===a.m?(console.log("Auth successful"),mar.client.requestUserInfo()):alert("Authentication failed. Please make sure you are logged in and reload the page."))}function codeResponseListener(a){"codeResponse"===a.t&&alert("Uploaded and assembled "+a.bytes+" bytes")}function userInfoListener(a){"userInfo"===a.t&&(console.log(a),mar.worldX=a.worldX,mar.worldY=a.worldY,mar.maxWidth=a.maxWidth,mar.client.requestTerrain())}
function terrainListener(a){"terrain"===a.t&&(mar.bigMessage&&mar.bigMessage.destroy(),a.ok?void 0!==mar.world?(mar.client.socket.send(JSON.stringify({t:"object",x:mar.worldX,y:mar.worldY})),mar.world.update(a.terrain)):(mar.world=new Word(a.terrain),console.log("Gameloop started"),game.input.keyboard.onDownCallback=function(a){document.activeElement===document.getElementById("game")&&((37<=a.keyCode&&40>=a.keyCode||116===a.keyCode||32===a.keyCode)&&a.preventDefault(),"guest"!==mar.client.username&&
16>=mar.kbBuffer.length&&(mar.client.sendKeypress(a.keyCode),mar.kbBuffer.push(a.keyCode),mar.kbBufferText=formattedKeyBuffer(mar.kbBuffer)))},game.input.onDown.add(function(){document.getElementById("game").focus()})):(void 0!==mar.world?mar.world.update([]):mar.world=new Word([]),mar.bigMessage=game.add.text(908,450,"[Uncharted World]",{fontSize:46,fill:"#ff803d",stroke:colorScheme.textStroke,strokeThickness:2,font:"fixedsys"},textGroup)))}
function objectListener(a){"object"===a.t&&mar.world.updateObjects(a.objects)}function floppyListener(a){document.getElementById("floppyDown").innerHTML='<i class="fa fa-long-arrow-down" aria-hidden="true"></i> <i class="fa fa-floppy-o" aria-hidden="true"></i>';a=new Blob([a.data],{type:"application/octet-stream"});saveAs(a,"floppy.bin")}
function tickListener(a){if("tick"===a.t){mar.client.socket.send(JSON.stringify({t:"object",x:mar.worldX,y:mar.worldY}));void 0!==a.keys&&(mar.kbBuffer=a.keys,mar.kbBufferText=formattedKeyBuffer(mar.kbBuffer));var b=document.getElementById("console");0===a.cm&&(b.innerHTML="",mar.lastLines="");if(void 0!==a.c){for(var c=mar.lastLines,d=0;d<a.c.length;d++)c+=a.c[d];a=b.innerHTML="";var f=c.split("\n");for(d=0;d<f.length;d++)if(40<=f[d].length)for(var e=f[d].match(/.{1,40}/g),g=0;g<e.length;g++)g!==
e.length-1&&(a+="\n");else a+=f[d]+"\n";b.innerHTML=a;mar.lastLines=c;b.scrollTop=b.scrollHeight}}}
var GameClient=function(a){var b=this,c=[],d=new XMLHttpRequest;d.open("GET","./getServerInfo.php",!0);d.onreadystatechange=function(){4===d.readyState&&200===d.status&&(console.log("Received server info "+d.responseText),setTimeout(function(){var f=JSON.parse(d.responseText);console.log(f.address);b.socket=new WebSocket(f.address);b.username=f.username;b.tickLength=f.tickLength;b.serverName=f.serverName;mar.client.socket.binaryType="arraybuffer";b.socket.onopen=function(){b.socket.send(f.token);
c.push(authListener);c.push(userInfoListener);c.push(terrainListener);c.push(tickListener);c.push(objectListener);c.push(codeListener);c.push(codeResponseListener);mar.client.socket.onmessage=function(a){try{var b=JSON.parse(a.data)}catch(h){console.log(h),floppyListener(a)}for(a=0;a<c.length;a++)c[a](b)};b.reloadCode();void 0!==a&&a()};b.socket.onerror=function(a){alert("Can't connect to game server at address "+f.address);console.log(a)};b.socket.onclose=function(a){alert("Disconnected from server");
console.log(a)}},100))};d.send(null);this.requestUserInfo=function(){this.socket.send(JSON.stringify({t:"userInfo"}))};this.requestTerrain=function(){this.socket.send(JSON.stringify({t:"terrain",x:mar.worldX,y:mar.worldY}))};this.uploadCode=function(a){console.log("Uploaded code");this.socket.send(JSON.stringify({t:"uploadCode",code:a}))};this.reloadCode=function(){this.socket.send(JSON.stringify({t:"codeRequest"}))};this.sendKeypress=function(a){0!==a&&this.socket.send(JSON.stringify({t:"k",k:a}))};
this.requestFloppy=function(){document.getElementById("floppyDown").innerHTML='<i class="fa fa-cog fa-spin fa-fw"></i>';this.socket.send(JSON.stringify({t:"floppyDown"}))};this.notifyFloppyUp=function(){this.socket.send(JSON.stringify({t:"floppyUp"}))}};function dispatchTileHover(a,b){for(var c in mar.world.objects){var d=mar.world.objects[c];if(d.isAt(a,b))d.onTileHover()}}function dispatchTileOut(a,b){for(var c in mar.world.objects){var d=mar.world.objects[c];if(d.isAt(a,b))d.onTileOut()}}
var count=0,BasicGame=function(a){};BasicGame.Boot=function(a){};var isoGroup,cursorPos,cursor,textGroup,debugTile,debugObj,objectsGroup,cursors,tmpLine;
BasicGame.Boot.prototype={preload:function(){game.load.atlasJSONHash("sheet","./mar/sprites.png","./mar/sprites.json");game.time.advancedTiming=!0;game.plugins.add(new Phaser.Plugin.Isometric(game));game.iso.anchor.setTo(.5,0);game.world.setBounds(0,0,2200,1100);game.camera.x=280;game.camera.y=90;game.stage.disableVisibilityChange=!0;this.scale.scaleMode=Phaser.ScaleManager.RESIZE;this.scale.pageAlignHorizontally=!0;this.scale.pageAlignVertically=!0},create:function(){isoGroup=game.add.group();objectsGroup=
game.add.group();textGroup=game.add.group();initialiseAnimations();this.spawnTiles();cursorPos=new Phaser.Plugin.Isometric.Point3;cursors=game.input.keyboard.createCursorKeys()},update:function(){game.scale.setShowAll();game.scale.refresh();game.iso.unproject(game.input.activePointer.position,cursorPos);isoGroup.forEach(function(a){if(a.isTile){var b=a.isoBounds.containsXY(cursorPos.x,cursorPos.y);!a.selected&&b?(a.selected=!0,a.tint=colorScheme.tileHoverTint,debugTile=a.tileX+", "+a.tileY,dispatchTileHover(a.tileX,
a.tileY),game.add.tween(a).to({isoZ:a.baseZ+8},200,Phaser.Easing.Quadratic.InOut,!0)):a.selected&&!b&&(dispatchTileOut(a.tileX,a.tileY),a.selected=!1,a.tint=a.baseTint,game.add.tween(a).to({isoZ:a.baseZ},200,Phaser.Easing.Quadratic.InOut,!0))}});this.game.input.activePointer.isDown?(this.game.origDragPoint&&(this.game.camera.x+=this.game.origDragPoint.x-this.game.input.activePointer.position.x,this.game.camera.y+=this.game.origDragPoint.y-this.game.input.activePointer.position.y),this.game.origDragPoint=
this.game.input.activePointer.position.clone()):this.game.origDragPoint=null;count++;0===count%10&&game.iso.topologicalSort(isoGroup)},render:function(){void 0!==mar.worldX?game.debug.text("World: ("+Number(mar.worldX).toString(16)+", "+Number(mar.worldY).toString(16)+")",10,20):game.debug.text("World: (?,?)",10,20);debugTile&&game.debug.text(debugTile,10,40);"guest"!==mar.client.username&&game.debug.text(mar.kbBufferText,210,20);void 0!==tmpLine&&(game.debug.geom(tmpLine),game.debug.lineInfo(tmpLine,
32,32))},spawnTiles:function(){mar.client=new GameClient}};
function setupWorldArrows(){var a=game.make.isoSprite(528,-10,10,"sheet","ui/arrow_north",isoGroup);a.inputEnabled=!0;a.events.onInputDown.add(function(){0===mar.worldY?mar.worldY=mar.maxWidth:mar.worldY--;mar.client.requestTerrain()});a.events.onInputOver.add(function(){a.tint=65280;document.body.style.cursor="pointer"});a.events.onInputOut.add(function(){a.tint=16777215;document.body.style.cursor="default"});isoGroup.addChild(a);var b=game.make.isoSprite(1115,587,10,"sheet","ui/arrow_east",isoGroup);
b.inputEnabled=!0;b.events.onInputDown.add(function(){mar.worldX===mar.maxWidth?mar.worldX=0:mar.worldX++;mar.client.requestTerrain()});b.events.onInputOver.add(function(){b.tint=65280;document.body.style.cursor="pointer"});b.events.onInputOut.add(function(){b.tint=16777215;document.body.style.cursor="default"});isoGroup.addChild(b);var c=game.make.isoSprite(528,1170,10,"sheet","ui/arrow_south",isoGroup);c.inputEnabled=!0;c.events.onInputDown.add(function(){mar.worldY===mar.maxWidth?mar.worldY=0:
mar.worldY++;mar.client.requestTerrain()});c.events.onInputOver.add(function(){c.tint=65280;document.body.style.cursor="pointer"});c.events.onInputOut.add(function(){c.tint=16777215;document.body.style.cursor="default"});isoGroup.addChild(c);var d=game.make.isoSprite(-60,587,10,"sheet","ui/arrow_west",isoGroup);d.inputEnabled=!0;d.events.onInputDown.add(function(){0===mar.worldX?mar.worldX=mar.maxWidth:mar.worldX--;mar.client.requestTerrain()});d.events.onInputOver.add(function(){d.tint=65280;document.body.style.cursor=
"pointer"});d.events.onInputOut.add(function(){d.tint=16777215;document.body.style.cursor="default"});isoGroup.addChild(d)}function cubotDig(a,b,c){b===DIR_NORTH?a.animations.play("dig_n",45):b===DIR_EAST?a.animations.play("dig_e",45):b===DIR_SOUTH?a.animations.play("dig_s",45):b===DIR_WEST&&a.animations.play("dig_w",45)}
function cubotMove(a,b,c,d,f){var e;if(b===DIR_SOUTH)var g=function(b){f?(e=game.add.tween(a).to({isoX:getIsoX(a.tileX),isoY:getIsoY(a.tileY)},b,Phaser.Easing.Linear.None,!0),game.add.tween(a).to({isoX:getIsoX(a.tileX),isoZ:90},b/2,Phaser.Easing.Quadratic.Out,!0).onComplete.add(function(){game.add.tween(a).to({isoX:getIsoX(a.tileX),isoZ:5},b/2,Phaser.Easing.Quadratic.In,!0)})):(e=game.add.tween(a).to({isoX:getIsoX(a.tileX),isoY:getIsoY(a.tileY)},b,Phaser.Easing.Linear.None,!0),a.animations.play("walk_s",
60,!0));dispatchTileEnter(a.tileX,a.tileY);e.onComplete.add(function(){a.animations.stop();a.animations.frame=d.south;a.onTileOut();a.isoX=getIsoX(a.tileX);a.isoY=getIsoY(a.tileY);void 0!==c&&c();for(var b=0;b<a.queuedAnims.length;b++)a.queuedAnims[b](500),a.queuedAnims.splice(b,1)})};else b===DIR_NORTH?g=function(b){f?(e=game.add.tween(a).to({isoX:getIsoX(a.tileX),isoY:getIsoY(a.tileY)},b,Phaser.Easing.Linear.None,!0),game.add.tween(a).to({isoZ:90},b/2,Phaser.Easing.Quadratic.Out,!0).onComplete.add(function(){game.add.tween(a).to({isoZ:5},
b/2,Phaser.Easing.Quadratic.In,!0)})):(e=game.add.tween(a).to({isoX:getIsoX(a.tileX),isoY:getIsoY(a.tileY)},b,Phaser.Easing.Linear.None,!0),a.animations.play("walk_n",60,!0));dispatchTileEnter(a.tileX,a.tileY);e.onComplete.add(function(){a.animations.stop();a.animations.frame=d.north;a.onTileOut();a.isoX=getIsoX(a.tileX);a.isoY=getIsoY(a.tileY);void 0!==c&&c();for(var b=0;b<a.queuedAnims.length;b++)a.queuedAnims[b](500),a.queuedAnims.splice(b,1)})}:b===DIR_WEST?g=function(b){f?(e=game.add.tween(a).to({isoX:getIsoX(a.tileX),
isoY:getIsoY(a.tileY)},b,Phaser.Easing.Linear.None,!0),game.add.tween(a).to({isoZ:90},b/2,Phaser.Easing.Quadratic.Out,!0).onComplete.add(function(){game.add.tween(a).to({isoZ:5},b/2,Phaser.Easing.Quadratic.In,!0)})):(e=game.add.tween(a).to({isoX:getIsoX(a.tileX),isoY:getIsoY(a.tileY)},b,Phaser.Easing.Linear.None,!0),a.animations.play("walk_w",60,!0));dispatchTileEnter(a.tileX,a.tileY);e.onComplete.add(function(){a.animations.stop();a.animations.frame=d.west;a.onTileOut();a.isoX=getIsoX(a.tileX);a.isoY=
getIsoY(a.tileY);void 0!==c&&c();for(var b=0;b<a.queuedAnims.length;b++)a.queuedAnims[b](500),a.queuedAnims.splice(b,1)})}:b===DIR_EAST&&(g=function(b){f?(e=game.add.tween(a).to({isoX:getIsoX(a.tileX),isoY:getIsoY(a.tileY)},b,Phaser.Easing.Linear.None,!0),game.add.tween(a).to({isoZ:90},b/2,Phaser.Easing.Quadratic.Out,!0).onComplete.add(function(){game.add.tween(a).to({isoZ:5},b/2,Phaser.Easing.Quadratic.In,!0)})):(e=game.add.tween(a).to({isoX:getIsoX(a.tileX),isoY:getIsoY(a.tileY)},b,Phaser.Easing.Linear.None,
!0),a.animations.play("walk_e",60,!0));dispatchTileEnter(a.tileX,a.tileY);e.onComplete.add(function(){a.animations.stop();a.animations.frame=d.east;a.onTileOut();a.isoX=getIsoX(a.tileX);a.isoY=getIsoY(a.tileY);void 0!==c&&c();for(var b=0;b<a.queuedAnims.length;b++)a.queuedAnims[b](500),a.queuedAnims.splice(b,1)})});a.animations.currentAnim.isPlaying?(a.queuedAnims.push(g),console.log("Queued Animation")):g(800)}
function initialiseAnimations(){mar.animationFrames.walk_e_start=[];for(var a=0;10>a;a++)mar.animationFrames.walk_e_start.push("cubot/walk_e/"+("0000"+a).slice(-4));mar.animationFrames.walk_e=[];for(a=10;30>a;a++)mar.animationFrames.walk_e.push("cubot/walk_e/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_e_start=[];for(a=0;10>a;a++)mar.animationFrames.harvester_walk_e_start.push("harvester/walk_e/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_e=[];for(a=10;30>a;a++)mar.animationFrames.harvester_walk_e.push("harvester/walk_e/"+
("0000"+a).slice(-4));mar.animationFrames.walk_n_start=[];for(a=0;10>a;a++)mar.animationFrames.walk_n_start.push("cubot/walk_n/"+("0000"+a).slice(-4));mar.animationFrames.walk_n=[];for(a=10;30>a;a++)mar.animationFrames.walk_n.push("cubot/walk_n/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_n_start=[];for(a=0;10>a;a++)mar.animationFrames.harvester_walk_n_start.push("harvester/walk_n/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_n=[];for(a=10;30>a;a++)mar.animationFrames.harvester_walk_n.push("harvester/walk_n/"+
("0000"+a).slice(-4));mar.animationFrames.walk_s_start=[];for(a=0;10>a;a++)mar.animationFrames.walk_s_start.push("cubot/walk_s/"+("0000"+a).slice(-4));mar.animationFrames.walk_s=[];for(a=10;30>a;a++)mar.animationFrames.walk_s.push("cubot/walk_s/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_s_start=[];for(a=0;10>a;a++)mar.animationFrames.harvester_walk_s_start.push("harvester/walk_s/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_s=[];for(a=10;30>a;a++)mar.animationFrames.harvester_walk_s.push("harvester/walk_s/"+
("0000"+a).slice(-4));mar.animationFrames.walk_w_start=[];for(a=0;10>a;a++)mar.animationFrames.walk_w_start.push("cubot/walk_w/"+("0000"+a).slice(-4));mar.animationFrames.walk_w=[];for(a=10;30>a;a++)mar.animationFrames.walk_w.push("cubot/walk_w/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_w_start=[];for(a=0;10>a;a++)mar.animationFrames.harvester_walk_w_start.push("harvester/walk_w/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_w=[];for(a=10;30>a;a++)mar.animationFrames.harvester_walk_w.push("harvester/walk_w/"+
("0000"+a).slice(-4));mar.animationFrames.dig_e=[];for(a=1;41>=a;a++)mar.animationFrames.dig_e.push("cubot/dig_e/"+("0000"+a).slice(-4));mar.animationFrames.dig_n=[];for(a=1;41>=a;a++)mar.animationFrames.dig_n.push("cubot/dig_n/"+("0000"+a).slice(-4));mar.animationFrames.dig_s=[];for(a=1;41>=a;a++)mar.animationFrames.dig_s.push("cubot/dig_s/"+("0000"+a).slice(-4));mar.animationFrames.dig_w=[];for(a=1;41>=a;a++)mar.animationFrames.dig_w.push("cubot/dig_w/"+("0000"+a).slice(-4));mar.animationFrames.biomassIdle=
[];for(a=1;60>a;a++)mar.animationFrames.biomassIdle.push("objects/biomass/idle/"+("0000"+a).slice(-4))}function getIsoX(a){return 71.5*a}function getIsoY(a){return 71.5*a}function findMyRobot(){"guest"===mar.client.username?alert("You are not logged in!"):mar.client.requestUserInfo()}function formattedKeyBuffer(a){for(var b="KB: ",c=0;16>c;c++)b=void 0!==a[c]?b+(a[c].toString(16)+" "):b+"__ ";return b}game.state.add("Boot",BasicGame.Boot);game.state.start("Boot");

343
mar/phaser/GameClient.js Normal file
View File

@ -0,0 +1,343 @@
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
/**
* Client-side keyboard buffer. It is overwritten by the server at the end of tick.
*/
var KeyboardBuffer = (function (_super) {
__extends(KeyboardBuffer, _super);
function KeyboardBuffer() {
var _this = _super !== null && _super.apply(this, arguments) || this;
/**
* Array of key codes. Updated on keypress
* @type {Array}
*/
_this.keys = [];
return _this;
}
/**
* @returns {string} Message written on the screen
*/
KeyboardBuffer.prototype.getMessage = function () {
var str = "KB: ";
for (var i = 0; i < 16; i++) {
if (this.keys[i] !== undefined) {
str += this.keys[i].toString(16).toUpperCase() + " ";
}
else {
str += "__ ";
}
}
return str;
};
return KeyboardBuffer;
}(DebugMessage));
/**
* Listens for object list
*/
var ObjectsListener = (function () {
function ObjectsListener() {
}
ObjectsListener.prototype.getListenedMessageType = function () {
return "object";
};
ObjectsListener.prototype.handle = function (message) {
if (DEBUG) {
console.log("[MAR] Received " + message.objects.length + " objects");
}
if (mar.world != undefined) {
mar.world.handleObjectsUpdate(message.objects);
}
};
return ObjectsListener;
}());
var TickListener = (function () {
function TickListener() {
}
TickListener.prototype.getListenedMessageType = function () {
return "tick";
};
TickListener.prototype.handle = function (message) {
mar.client.requestObjects();
//Update key buffer display
if (message.keys !== undefined) {
mar.client.keyboardBuffer.keys = message.keys;
}
};
return TickListener;
}());
var UserInfoListener = (function () {
function UserInfoListener() {
}
UserInfoListener.prototype.getListenedMessageType = function () {
return "userInfo";
};
UserInfoListener.prototype.handle = function (message) {
if (DEBUG) {
console.log("[MAR] Received user info message");
}
mar.client.worldX = message.worldX;
mar.client.worldY = message.worldY;
//Maximum Universe width
mar.client.maxWidth = message.maxWidth;
mar.client.requestTerrain();
};
return UserInfoListener;
}());
var AuthListener = (function () {
function AuthListener() {
}
AuthListener.prototype.getListenedMessageType = function () {
return "auth";
};
AuthListener.prototype.handle = function (message) {
if (DEBUG) {
console.log("[MAR] Received auth response");
}
if (message.m === "ok") {
console.log("[MAR] Auth successful");
mar.client.requestUserInfo();
}
else {
alert("Authentication failed. Please make sure you are logged in and reload the page.");
}
};
return AuthListener;
}());
var TerrainListener = (function () {
function TerrainListener() {
}
TerrainListener.prototype.getListenedMessageType = function () {
return "terrain";
};
TerrainListener.prototype.handle = function (message) {
if (DEBUG) {
console.log("[MAR] Received terrain");
}
if (mar.world) {
mar.world.removeBigMessage();
}
if (message.ok) {
//todo handle vault worlds here
if (DEBUG) {
console.log("[MAR] World is available");
}
if (mar.world != null) {
if (DEBUG) {
console.log("[MAR] Updating World terrain");
}
mar.world.updateTerrain(message.terrain);
}
else {
if (DEBUG) {
console.log("[MAR] Creating new World");
}
mar.world = new World(message.terrain);
}
}
else {
if (DEBUG) {
console.log("[MAR] World is not available");
}
if (mar.world != null) {
if (DEBUG) {
console.log("[MAR] Updating World terrain");
}
mar.world.updateTerrain([]);
}
else {
if (DEBUG) {
console.log("[MAR] Creating new World");
}
mar.world = new World([]);
}
if (mar.world) {
mar.world.setBigMessage("[Uncharted World]");
}
}
};
return TerrainListener;
}());
var GameClient = (function () {
function GameClient() {
this.listeners = [];
this.getServerInfo();
}
GameClient.prototype.requestUserInfo = function () {
if (DEBUG) {
console.log("[MAR] Requesting user info");
}
this.socket.send(JSON.stringify({ t: "userInfo" }));
};
GameClient.prototype.requestTerrain = function () {
if (DEBUG) {
console.log("[MAR] Requesting terrain for world (" + this.worldX + ", " + this.worldY + ")");
}
this.socket.send(JSON.stringify({ t: "terrain", x: this.worldX, y: this.worldY }));
this.requestObjects();
};
GameClient.prototype.uploadCode = function (code) {
if (DEBUG) {
console.log("[MAR] Uploaded code");
}
this.socket.send(JSON.stringify({ t: "uploadCode", code: code }));
};
GameClient.prototype.reloadCode = function () {
if (DEBUG) {
console.log("[MAR] Reloading code");
}
this.socket.send(JSON.stringify({ t: "codeRequest" }));
};
GameClient.prototype.sendKeyPress = function (key) {
if (DEBUG) {
console.log("[MAR] Sent KeyPress: " + key);
}
if (key !== 0) {
this.socket.send(JSON.stringify({ t: "k", k: key }));
}
};
GameClient.prototype.requestFloppy = function () {
//Start loading animation
document.getElementById("floppyDown").innerHTML = "<i class=\"fa fa-cog fa-spin fa-fw\"></i>";
if (DEBUG) {
console.log("[MAR] Requesting floppy");
}
this.socket.send(JSON.stringify({ t: "floppyDown" }));
};
GameClient.prototype.notifyFloppyUp = function () {
if (DEBUG) {
console.log("[MAR] Notifying the game server of floppy upload");
}
this.socket.send(JSON.stringify({ t: "floppyUp" }));
};
GameClient.prototype.requestObjects = function () {
if (DEBUG) {
console.log("[MAR] Requesting game objects");
}
this.socket.send(JSON.stringify({ t: "object", x: this.worldX, y: this.worldY }));
};
/**
* Get server info from game website
*/
GameClient.prototype.getServerInfo = function () {
var self = this;
if (DEBUG) {
console.log("[MAR] Getting server info... ");
}
var xhr = new XMLHttpRequest();
xhr.open("GET", "./getServerInfo.php", true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
if (DEBUG) {
console.log("[MAR] Received server info " + xhr.responseText);
}
setTimeout(self.connectToGameServer(JSON.parse(xhr.responseText)), 100);
}
};
xhr.send(null);
};
/**
* Connect to the game server
* @param info JSON fetched from /getServerInfo.php
*/
GameClient.prototype.connectToGameServer = function (info) {
var self = this;
if (DEBUG) {
console.log("[MAR] Connecting to " + info.address);
}
// info.address = "wss://muchassemblyrequired.com:443/socket";
this.socket = new WebSocket(info.address);
this.username = info.username;
this.tickLength = info.tickLength;
this.serverName = info.serverName;
this.socket.binaryType = 'arraybuffer';
this.socket.onopen = function () {
if (DEBUG) {
console.log("[MAR] Connected. Sent auth request");
}
//Send auth request
self.socket.send(info.token);
//todo Setup event listeners
self.listeners.push(new UserInfoListener());
self.listeners.push(new AuthListener());
self.listeners.push(new TickListener());
self.listeners.push(new TerrainListener());
self.listeners.push(new ObjectsListener());
self.socket.onmessage = function (received) {
var message;
try {
message = JSON.parse(received.data);
}
catch (e) {
if (DEBUG) {
console.log("[MAR] " + e);
}
//todo floppyListener(received);
}
if (DEBUG) {
console.log("[MAR] Received: " + received.data);
}
for (var i = 0; i < self.listeners.length; i++) {
if (self.listeners[i].getListenedMessageType() === message.t) {
self.listeners[i].handle(message);
}
}
};
//Reload code
//todo reloadCode();
};
this.socket.onerror = function (e) {
alert("Can't connect to game server at address " + info.address);
console.log(e);
};
this.socket.onclose = function (e) {
mar.world.setBigMessage("Disconnected from server :(");
console.log(e);
};
this.initGame();
};
/**
* Called after the connection has been made to the server
*/
GameClient.prototype.initGame = function () {
var self = this;
//Setup keyboard buffer display
//todo don't display if guest
this.keyboardBuffer = new KeyboardBuffer(config.kbBufferX, config.kbBufferY);
mar.addDebugMessage(this.keyboardBuffer);
//Handle keypresses
mar.game.input.keyboard.onDownCallback = function (event) {
//If the game has focus
if (document.activeElement === document.getElementById("game")) {
if ((event.keyCode >= 37 && event.keyCode <= 40) || event.keyCode === 116 || event.keyCode === 32) {
event.preventDefault();
}
if (self.username !== "guest" && self.keyboardBuffer.keys.length <= 16) {
self.sendKeyPress(event.keyCode);
//Locally update the buffer
self.keyboardBuffer.keys.push(event.keyCode);
}
}
};
};
/**
* Requests user info, which will trigger a terrain request with the world X,Y of
* the player's robot
*/
GameClient.prototype.findMyRobot = function () {
if (this.username === "guest") {
alert("You are not logged in!");
}
else {
this.requestUserInfo();
}
};
return GameClient;
}());

455
mar/phaser/GameClient.ts Normal file
View File

@ -0,0 +1,455 @@
/**
* Client-side keyboard buffer. It is overwritten by the server at the end of tick.
*/
class KeyboardBuffer extends DebugMessage {
/**
* Array of key codes. Updated on keypress
* @type {Array}
*/
public keys: number[] = [];
/**
* @returns {string} Message written on the screen
*/
public getMessage(): string {
let str = "KB: ";
for (let i = 0; i < 16; i++) {
if (this.keys[i] !== undefined) {
str += this.keys[i].toString(16).toUpperCase() + " ";
} else {
str += "__ ";
}
}
return str;
}
}
/**
* Listens for server messages
*/
interface MessageListener {
handle (message): void;
getListenedMessageType(): string
}
/**
* Listens for object list
*/
class ObjectsListener implements MessageListener {
getListenedMessageType(): string {
return "object";
}
handle(message): void {
if (DEBUG) {
console.log("[MAR] Received " + message.objects.length + " objects")
}
if (mar.world != undefined) {
mar.world.handleObjectsUpdate(message.objects)
}
}
}
class TickListener implements MessageListener {
getListenedMessageType() {
return "tick";
}
handle(message): void {
mar.client.requestObjects();
//Update key buffer display
if (message.keys !== undefined) {
mar.client.keyboardBuffer.keys = message.keys;
}
}
}
class UserInfoListener implements MessageListener {
getListenedMessageType() {
return "userInfo";
}
handle(message) {
if (DEBUG) {
console.log("[MAR] Received user info message")
}
mar.client.worldX = message.worldX;
mar.client.worldY = message.worldY;
//Maximum Universe width
mar.client.maxWidth = message.maxWidth;
mar.client.requestTerrain();
}
}
class AuthListener implements MessageListener {
getListenedMessageType() {
return "auth";
}
handle(message) {
if (DEBUG) {
console.log("[MAR] Received auth response")
}
if (message.m === "ok") {
console.log("[MAR] Auth successful");
mar.client.requestUserInfo();
} else {
alert("Authentication failed. Please make sure you are logged in and reload the page.");
}
}
}
class TerrainListener implements MessageListener {
getListenedMessageType() {
return "terrain";
}
handle(message) {
if (DEBUG) {
console.log("[MAR] Received terrain");
}
if (mar.world) {
mar.world.removeBigMessage();
}
if (message.ok) {
//todo handle vault worlds here
if (DEBUG) {
console.log("[MAR] World is available");
}
if (mar.world != null) {
if (DEBUG) {
console.log("[MAR] Updating World terrain");
}
mar.world.updateTerrain(message.terrain);
} else {
if (DEBUG) {
console.log("[MAR] Creating new World");
}
mar.world = new World(message.terrain);
}
} else {
if (DEBUG) {
console.log("[MAR] World is not available");
}
if (mar.world != null) {
if (DEBUG) {
console.log("[MAR] Updating World terrain");
}
mar.world.updateTerrain([]);
} else {
if (DEBUG) {
console.log("[MAR] Creating new World");
}
mar.world = new World([]);
}
if (mar.world) {
mar.world.setBigMessage("[Uncharted World]")
}
}
}
}
class GameClient {
keyboardBuffer: KeyboardBuffer;
/**
* Max width of the game universe
*/
public maxWidth: number;
private listeners: MessageListener[] = [];
private socket: WebSocket;
public username: string;
private tickLength: number;
private serverName: string;
public worldX: number;
public worldY: number;
constructor() {
this.getServerInfo();
}
public requestUserInfo(): void {
if (DEBUG) {
console.log("[MAR] Requesting user info");
}
this.socket.send(JSON.stringify({t: "userInfo"}));
}
public requestTerrain() {
if (DEBUG) {
console.log("[MAR] Requesting terrain for world (" + this.worldX + ", " + this.worldY + ")");
}
this.socket.send(JSON.stringify({t: "terrain", x: this.worldX, y: this.worldY}));
this.requestObjects();
}
public uploadCode(code: string): void {
if (DEBUG) {
console.log("[MAR] Uploaded code");
}
this.socket.send(JSON.stringify({t: "uploadCode", code: code}))
}
public reloadCode(): void {
if (DEBUG) {
console.log("[MAR] Reloading code");
}
this.socket.send(JSON.stringify({t: "codeRequest"}))
}
public sendKeyPress(key: number): void {
if (DEBUG) {
console.log("[MAR] Sent KeyPress: " + key);
}
if (key !== 0) {
this.socket.send(JSON.stringify({t: "k", k: key}));
}
}
public requestFloppy(): void {
//Start loading animation
document.getElementById("floppyDown").innerHTML = "<i class=\"fa fa-cog fa-spin fa-fw\"></i>";
if (DEBUG) {
console.log("[MAR] Requesting floppy");
}
this.socket.send(JSON.stringify({t: "floppyDown"}));
}
public notifyFloppyUp(): void {
if (DEBUG) {
console.log("[MAR] Notifying the game server of floppy upload");
}
this.socket.send(JSON.stringify({t: "floppyUp"}));
}
public requestObjects(): void {
if (DEBUG) {
console.log("[MAR] Requesting game objects");
}
this.socket.send(JSON.stringify({t: "object", x: this.worldX, y: this.worldY}));
}
/**
* Get server info from game website
*/
private getServerInfo() {
let self = this;
if (DEBUG) {
console.log("[MAR] Getting server info... ");
}
let xhr = new XMLHttpRequest();
xhr.open("GET", "./getServerInfo.php", true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
if (DEBUG) {
console.log("[MAR] Received server info " + xhr.responseText);
}
setTimeout(self.connectToGameServer(JSON.parse(xhr.responseText)), 100);
}
};
xhr.send(null);
}
/**
* Connect to the game server
* @param info JSON fetched from /getServerInfo.php
*/
private connectToGameServer(info: any) {
let self = this;
if (DEBUG) {
console.log("[MAR] Connecting to " + info.address);
}
// info.address = "wss://muchassemblyrequired.com:443/socket";
this.socket = new WebSocket(info.address);
this.username = info.username;
this.tickLength = info.tickLength;
this.serverName = info.serverName;
this.socket.binaryType = 'arraybuffer';
this.socket.onopen = function () {
if (DEBUG) {
console.log("[MAR] Connected. Sent auth request");
}
//Send auth request
self.socket.send(info.token);
//todo Setup event listeners
self.listeners.push(new UserInfoListener());
self.listeners.push(new AuthListener());
self.listeners.push(new TickListener());
self.listeners.push(new TerrainListener());
self.listeners.push(new ObjectsListener());
self.socket.onmessage = function (received) {
let message;
try {
message = JSON.parse(received.data);
} catch (e) {
if (DEBUG) {
console.log("[MAR] " + e)
}
//todo floppyListener(received);
}
if (DEBUG) {
console.log("[MAR] Received: " + received.data)
}
for (let i = 0; i < self.listeners.length; i++) {
if (self.listeners[i].getListenedMessageType() === message.t) {
self.listeners[i].handle(message)
}
}
};
//Reload code
//todo reloadCode();
};
this.socket.onerror = function (e) {
alert("Can't connect to game server at address " + info.address);
console.log(e);
};
this.socket.onclose = function (e) {
mar.world.setBigMessage("Disconnected from server :(");
console.log(e);
};
this.initGame();
}
/**
* Called after the connection has been made to the server
*/
public initGame() {
let self = this;
//Setup keyboard buffer display
//todo don't display if guest
this.keyboardBuffer = new KeyboardBuffer(config.kbBufferX, config.kbBufferY);
mar.addDebugMessage(this.keyboardBuffer);
//Handle keypresses
mar.game.input.keyboard.onDownCallback = function (event) {
//If the game has focus
if (document.activeElement === document.getElementById("game")) {
if ((event.keyCode >= 37 && event.keyCode <= 40) || event.keyCode === 116 || event.keyCode === 32) {
event.preventDefault();
}
if (self.username !== "guest" && self.keyboardBuffer.keys.length <= 16) {
self.sendKeyPress(event.keyCode);
//Locally update the buffer
self.keyboardBuffer.keys.push(event.keyCode);
}
}
};
}
/**
* Requests user info, which will trigger a terrain request with the world X,Y of
* the player's robot
*/
public findMyRobot() {
if (this.username === "guest") {
alert("You are not logged in!");
} else {
this.requestUserInfo()
}
}
}

466
mar/phaser/GameObject.js Normal file
View File

@ -0,0 +1,466 @@
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var ObjectType;
(function (ObjectType) {
ObjectType[ObjectType["CUBOT"] = 1] = "CUBOT";
ObjectType[ObjectType["BIOMASS"] = 2] = "BIOMASS";
ObjectType[ObjectType["HARVESTER_NPC"] = 10] = "HARVESTER_NPC";
ObjectType[ObjectType["FACTORY"] = 3] = "FACTORY";
ObjectType[ObjectType["RADIO_TOWER"] = 4] = "RADIO_TOWER";
})(ObjectType || (ObjectType = {}));
var ItemType;
(function (ItemType) {
ItemType[ItemType["BIOMASS"] = 1] = "BIOMASS";
ItemType[ItemType["IRON"] = 3] = "IRON";
ItemType[ItemType["COPPER"] = 4] = "COPPER";
})(ItemType || (ItemType = {}));
var Action;
(function (Action) {
Action[Action["IDLE"] = 0] = "IDLE";
Action[Action["DIGGING"] = 1] = "DIGGING";
Action[Action["WALKING"] = 2] = "WALKING";
Action[Action["WITHDRAWING"] = 3] = "WITHDRAWING";
Action[Action["DEPOSITING"] = 4] = "DEPOSITING";
Action[Action["LISTENING"] = 5] = "LISTENING";
Action[Action["JUMPING"] = 6] = "JUMPING";
})(Action || (Action = {}));
var GameObject = (function (_super) {
__extends(GameObject, _super);
function GameObject(x, y, z, key, frame) {
return _super.call(this, mar.game, x, y, z, key, frame) || this;
}
/**
* Factory method for GameObjects
*/
GameObject.createObject = function (json) {
switch (json.t) {
case ObjectType.CUBOT:
return new Cubot(json);
case ObjectType.BIOMASS:
return new BiomassBlob(json);
case ObjectType.HARVESTER_NPC:
return new HarvesterNPC(json);
case ObjectType.FACTORY:
return new Factory(json);
case ObjectType.RADIO_TOWER:
return new RadioTower(json);
default:
return null;
}
};
/**
* Set text that will appear on top of the object. Usually used for hover text
*/
GameObject.prototype.setText = function (text) {
this.text = mar.game.make.text(0, 0, text, {
fontSize: 22,
fill: config.textFill,
stroke: config.textStroke,
strokeThickness: 2,
font: "fixedsys"
});
this.text.anchor.set(0.5, 0);
this.addChild(this.text);
};
/**
* Tested to trigger onTileHover and onTileExit
*/
GameObject.prototype.isAt = function (x, y) {
return x == this.tileX && y == this.tileY;
};
return GameObject;
}(Phaser.Plugin.Isometric.IsoSprite));
var HologramMode;
(function (HologramMode) {
HologramMode[HologramMode["CLEARED"] = 0] = "CLEARED";
HologramMode[HologramMode["HEX"] = 1] = "HEX";
HologramMode[HologramMode["STRING"] = 2] = "STRING";
HologramMode[HologramMode["DEC"] = 3] = "DEC";
})(HologramMode || (HologramMode = {}));
var Cubot = (function (_super) {
__extends(Cubot, _super);
function Cubot(json) {
var _this = _super.call(this, Util.getIsoX(json.x), Util.getIsoY(json.y), 15, "sheet", null) || this;
/**
* List of animation functions queued for execution.
*/
_this.queuedAnimations = [];
_this.hovered = false;
if (DEBUG) {
console.log("Creating Cubot object");
}
_this.anchor.set(0.5, 0);
_this.id = json.i;
_this.tileX = json.x;
_this.tileY = json.y;
_this.username = json.parent;
_this.heldItem = json.heldItem;
_this.direction = json.direction;
_this.action = json.action;
_this.energy = json.energy;
_this.animations.add("walk_w", mar.animationFrames.walk_w);
_this.animations.add("walk_s", mar.animationFrames.walk_s);
_this.animations.add("walk_e", mar.animationFrames.walk_e);
_this.animations.add("walk_n", mar.animationFrames.walk_n);
_this.animations.add("dig_w", mar.animationFrames.dig_w);
_this.animations.add("dig_s", mar.animationFrames.dig_s);
_this.animations.add("dig_e", mar.animationFrames.dig_e);
_this.animations.add("dig_n", mar.animationFrames.dig_n);
_this.createUsername();
_this.updateDirection();
_this.tint = _this.getTint();
return _this;
}
Cubot.prototype.onTileHover = function () {
mar.game.add.tween(this).to({ isoZ: 45 }, 200, Phaser.Easing.Quadratic.InOut, true);
mar.game.add.tween(this.scale).to({ x: 1.2, y: 1.2 }, 200, Phaser.Easing.Linear.None, true);
this.tint = config.cubotHoverTint;
if (this.text !== undefined) {
this.text.visible = true;
}
this.hovered = true;
};
Cubot.prototype.onTileExit = function () {
mar.game.add.tween(this).to({ isoZ: 15 }, 400, Phaser.Easing.Bounce.Out, true);
mar.game.add.tween(this.scale).to({ x: 1, y: 1 }, 200, Phaser.Easing.Linear.None, true);
if (this.text !== undefined) {
this.text.visible = false;
}
this.hovered = false;
this.tint = this.getTint();
};
Cubot.prototype.getTint = function () {
if (!this.hovered) {
if (this.energy <= config.lowEnergy) {
return config.lowEnergyTint;
}
else {
return config.cubotTint;
}
}
else {
return config.cubotHoverTint;
}
};
Cubot.prototype.updateObject = function (json) {
if (DEBUG) {
console.log("Updating Cubot object");
}
this.action = json.action;
this.energy = json.energy;
this.direction = json.direction;
//Update color
this.tint = this.getTint();
//Update Location
if (!this.isAt(json.x, json.y)) {
//Location changed
if (this.action == Action.WALKING) {
//Walking..
this.tileX = json.x;
this.tileY = json.y;
this.walk();
}
else if (this.action == Action.JUMPING) {
//TODO
}
}
if (this.action == Action.DIGGING) {
//TODO dig animation
}
this.updateDirection();
this.updateHologram(json.holoMode, json.holoC, json.holo, json.holoStr);
};
Cubot.prototype.updateHologram = function (holoMode, holoColor, holoValue, holoStr) {
//Create hologram if not exist, set style
if (this.hologram == undefined) {
this.hologram = mar.game.make.text(0, 32, "");
this.hologram.anchor.set(0.5, 0);
this.addChild(this.hologram);
this.hologram.setStyle(config.holoStyle(holoColor));
}
else {
this.hologram.setStyle(config.holoStyle(holoColor));
}
switch (holoMode) {
case HologramMode.CLEARED:
this.hologram.text = "";
break;
case HologramMode.DEC:
this.hologram.text = Number(holoValue).toString();
break;
case HologramMode.HEX:
this.hologram.text = "0x" + ("0000" + Number(holoValue).toString(16).toUpperCase()).slice(-4);
break;
case HologramMode.STRING:
this.hologram.text = holoStr.replace(/[\n|\t]/g, '');
break;
}
};
/**
* Set appropriate frame based on direction
*/
Cubot.prototype.updateDirection = function () {
switch (this.direction) {
case Direction.NORTH:
this.animations.frameName = "cubot/walk_n/0001";
break;
case Direction.EAST:
this.animations.frameName = "cubot/walk_e/0001";
break;
case Direction.SOUTH:
this.animations.frameName = "cubot/walk_s/0001";
break;
case Direction.WEST:
this.animations.frameName = "cubot/walk_w/0001";
break;
}
};
/**
* Initiate the walk animation. Handles multiple calls of this function even if the previous animations
* were not completed
*/
Cubot.prototype.walk = function () {
var self = this;
var walkAnimation = function (duration) {
//Move the Cubot to desired tile
var tween = mar.game.add.tween(self).to({ isoX: Util.getIsoX(self.tileX), isoY: Util.getIsoY(self.tileY) }, duration, Phaser.Easing.Linear.None, true);
//Play appropriate animation
switch (self.direction) {
case Direction.NORTH:
self.animations.play("walk_n", 60, true);
break;
case Direction.SOUTH:
self.animations.play("walk_s", 60, true);
break;
case Direction.EAST:
self.animations.play("walk_e", 60, true);
break;
case Direction.WEST:
self.animations.play("walk_w", 60, true);
break;
}
//When moved to destination,
tween.onComplete.add(function () {
self.animations.stop();
self.updateDirection();
//Resync position
self.isoX = Util.getIsoX(self.tileX);
self.isoY = Util.getIsoY(self.tileY);
self.onTileExit();
//Execute all the queued walk animations at a faster pace
for (var i = 0; i < self.queuedAnimations.length; i++) {
self.queuedAnimations[i](config.walkDuration / 2);
self.queuedAnimations.splice(i, 1);
}
});
};
if (this.animations.currentAnim.isPlaying) {
//Queue up the animation
this.queuedAnimations.push(walkAnimation);
}
else {
walkAnimation(config.walkDuration);
}
};
/**
* Create the username text that will appear on top of the Cubot. Text will have alternate
* color when current username matches. This function is also responsable for setting the
* reduced transparency of other Cubots
*/
Cubot.prototype.createUsername = function () {
var username = mar.game.make.text(0, -24, this.username, {
fontSize: 22,
fill: config.textFill,
stroke: config.textStroke,
strokeThickness: 2,
font: "fixedsys"
});
username.alpha = 0.85;
username.anchor.set(0.5, 0);
//Color own username
if (this.username === mar.client.username) {
username.tint = config.selfUsernameColor;
}
else {
this.alpha = config.otherCubotAlpha;
}
this.addChild(username);
};
return Cubot;
}(GameObject));
var HarvesterNPC = (function (_super) {
__extends(HarvesterNPC, _super);
function HarvesterNPC(json) {
var _this = _super.call(this, json) || this;
_this.animations.add("walk_w", mar.animationFrames.harvester_walk_w);
_this.animations.add("walk_s", mar.animationFrames.harvester_walk_s);
_this.animations.add("walk_e", mar.animationFrames.harvester_walk_e);
_this.animations.add("walk_n", mar.animationFrames.harvester_walk_n);
_this.updateDirection();
_this.setText("Harvester NPC");
_this.text.visible = false;
return _this;
}
/**
* Needs to be overridden because Cubot() calls getTint() when initialised
*/
HarvesterNPC.prototype.getTint = function () {
return config.cubotTint;
};
HarvesterNPC.prototype.updateDirection = function () {
switch (this.direction) {
case Direction.NORTH:
this.animations.frameName = "harvester/walk_n/0001";
break;
case Direction.EAST:
this.animations.frameName = "harvester/walk_e/0001";
break;
case Direction.SOUTH:
this.animations.frameName = "harvester/walk_s/0001";
break;
case Direction.WEST:
this.animations.frameName = "harvester/walk_w/0001";
break;
}
};
HarvesterNPC.prototype.updateObject = function (json) {
if (DEBUG) {
console.log("Updating Harvester NPC object");
}
this.action = json.action;
this.direction = json.direction;
//Update Location
if (!this.isAt(json.x, json.y)) {
//Location changed
if (this.action == Action.WALKING) {
//Walking..
this.tileX = json.x;
this.tileY = json.y;
this.walk();
}
else if (this.action == Action.JUMPING) {
//TODO
}
}
//Update Direction
this.updateDirection();
};
HarvesterNPC.prototype.createUsername = function () {
//No-op
};
return HarvesterNPC;
}(Cubot));
var BiomassBlob = (function (_super) {
__extends(BiomassBlob, _super);
function BiomassBlob(json) {
var _this = _super.call(this, Util.getIsoX(json.x), Util.getIsoY(json.y), 10, "sheet", 1) || this;
if (DEBUG) {
console.log("Creating Biomass object");
}
_this.anchor.set(0.5, 0);
_this.id = json.i;
_this.tileX = json.x;
_this.tileY = json.y;
_this.tint = config.biomassTint;
_this.animations.add("idle", mar.animationFrames.biomassIdle);
_this.animations.play("idle", 45, true);
_this.setText("Biomass");
_this.text.visible = false;
return _this;
}
BiomassBlob.prototype.onTileHover = function () {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({ isoZ: 45 }, 200, Phaser.Easing.Quadratic.InOut, true);
this.tint = config.biomassHoverTint;
mar.game.add.tween(this.scale).to({ x: 1.2, y: 1.2 }, 200, Phaser.Easing.Linear.None, true);
this.text.visible = true;
};
BiomassBlob.prototype.onTileExit = function () {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({ isoZ: 15 }, 400, Phaser.Easing.Bounce.Out, true);
mar.game.add.tween(this.scale).to({ x: 1, y: 1 }, 200, Phaser.Easing.Linear.None, true);
this.tint = config.biomassTint;
this.text.visible = false;
};
BiomassBlob.prototype.updateObject = function (json) {
if (DEBUG) {
console.log("Updating Biomass object");
}
};
return BiomassBlob;
}(GameObject));
var Factory = (function (_super) {
__extends(Factory, _super);
function Factory(json) {
var _this = _super.call(this, Util.getIsoX(json.x), Util.getIsoY(json.y), 15, "sheet", "objects/factory") || this;
_this.anchor.set(0.5, .25);
_this.setText("Factory");
_this.text.visible = false;
_this.id = json.i;
_this.tileX = json.x;
_this.tileY = json.y;
return _this;
}
Factory.prototype.onTileHover = function () {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({ isoZ: 25 }, 200, Phaser.Easing.Quadratic.InOut, true);
mar.game.add.tween(this.scale).to({ x: 1.06, y: 1.06 }, 200, Phaser.Easing.Linear.None, true);
this.tint = config.cubotHoverTint;
this.text.visible = true;
};
Factory.prototype.onTileExit = function () {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({ isoZ: 15 }, 400, Phaser.Easing.Bounce.Out, true);
mar.game.add.tween(this.scale).to({ x: 1, y: 1 }, 200, Phaser.Easing.Linear.None, true);
this.tint = config.cubotTint;
this.text.visible = false;
};
Factory.prototype.updateObject = function (json) {
//No op
};
Factory.prototype.isAt = function (x, y) {
//Factory is 2x2
return (this.tileX === x || this.tileX + 1 === x) && (this.tileY + 1 === y || this.tileY === y);
};
;
return Factory;
}(GameObject));
var RadioTower = (function (_super) {
__extends(RadioTower, _super);
function RadioTower(json) {
var _this = _super.call(this, Util.getIsoX(json.x), Util.getIsoY(json.y), 15, "sheet", "objects/RadioTower") || this;
_this.anchor.set(0.5, 0.64);
_this.setText("Radio Tower");
_this.text.visible = false;
_this.id = json.i;
_this.tileX = json.x;
_this.tileY = json.y;
return _this;
}
RadioTower.prototype.onTileHover = function () {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({ isoZ: 25 }, 200, Phaser.Easing.Quadratic.InOut, true);
mar.game.add.tween(this.scale).to({ x: 1.06, y: 1.06 }, 200, Phaser.Easing.Linear.None, true);
this.tint = config.cubotHoverTint;
this.text.visible = true;
};
RadioTower.prototype.onTileExit = function () {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({ isoZ: 15 }, 400, Phaser.Easing.Bounce.Out, true);
mar.game.add.tween(this.scale).to({ x: 1, y: 1 }, 200, Phaser.Easing.Linear.None, true);
this.tint = config.cubotTint;
this.text.visible = false;
};
RadioTower.prototype.updateObject = function (json) {
//No op
};
return RadioTower;
}(GameObject));

572
mar/phaser/GameObject.ts Normal file
View File

@ -0,0 +1,572 @@
enum ObjectType {
CUBOT = 1,
BIOMASS = 2,
HARVESTER_NPC = 10,
FACTORY = 3,
RADIO_TOWER = 4
}
enum ItemType {
BIOMASS = 1,
IRON = 3,
COPPER = 4
}
enum Action {
IDLE,
DIGGING,
WALKING,
WITHDRAWING,
DEPOSITING,
LISTENING,
JUMPING
}
abstract class GameObject extends Phaser.Plugin.Isometric.IsoSprite {
public tileX: number;
public tileY: number;
id: number;
protected direction: Direction;
protected action: Action;
public updated: boolean;
protected text: Phaser.Text;
constructor(x: number, y: number, z: number, key: any, frame: any) {
super(mar.game, x, y, z, key, frame);
}
public abstract updateObject(json): void;
public abstract onTileHover(): void;
public abstract onTileExit(): void;
/**
* Factory method for GameObjects
*/
public static createObject(json): GameObject {
switch (json.t) {
case ObjectType.CUBOT:
return new Cubot(json);
case ObjectType.BIOMASS:
return new BiomassBlob(json);
case ObjectType.HARVESTER_NPC:
return new HarvesterNPC(json);
case ObjectType.FACTORY:
return new Factory(json);
case ObjectType.RADIO_TOWER:
return new RadioTower(json);
default:
return null;
}
}
/**
* Set text that will appear on top of the object. Usually used for hover text
*/
protected setText(text: string): void {
this.text = mar.game.make.text(0, 0, text, {
fontSize: 22,
fill: config.textFill,
stroke: config.textStroke,
strokeThickness: 2,
font: "fixedsys"
});
this.text.anchor.set(0.5, 0);
this.addChild(this.text);
}
/**
* Tested to trigger onTileHover and onTileExit
*/
public isAt(x: number, y: number): boolean {
return x == this.tileX && y == this.tileY;
}
}
enum HologramMode {
CLEARED,
HEX,
STRING,
DEC
}
class Cubot extends GameObject {
username: string;
heldItem: ItemType;
energy: number;
private hologram: Phaser.Text;
/**
* List of animation functions queued for execution.
*/
queuedAnimations = [];
private hovered: boolean = false;
constructor(json) {
super(Util.getIsoX(json.x), Util.getIsoY(json.y), 15, "sheet", null);
if (DEBUG) {
console.log("Creating Cubot object");
}
this.anchor.set(0.5, 0);
this.id = json.i;
this.tileX = json.x;
this.tileY = json.y;
this.username = json.parent;
this.heldItem = json.heldItem;
this.direction = json.direction;
this.action = json.action;
this.energy = json.energy;
this.animations.add("walk_w", mar.animationFrames.walk_w);
this.animations.add("walk_s", mar.animationFrames.walk_s,);
this.animations.add("walk_e", mar.animationFrames.walk_e);
this.animations.add("walk_n", mar.animationFrames.walk_n);
this.animations.add("dig_w", mar.animationFrames.dig_w);
this.animations.add("dig_s", mar.animationFrames.dig_s);
this.animations.add("dig_e", mar.animationFrames.dig_e);
this.animations.add("dig_n", mar.animationFrames.dig_n);
this.createUsername();
this.updateDirection();
this.tint = this.getTint();
}
onTileHover(): void {
mar.game.add.tween(this).to({isoZ: 45}, 200, Phaser.Easing.Quadratic.InOut, true);
mar.game.add.tween(this.scale).to({x: 1.2, y: 1.2}, 200, Phaser.Easing.Linear.None, true);
this.tint = config.cubotHoverTint;
if (this.text !== undefined) {
this.text.visible = true;
}
this.hovered = true;
}
onTileExit(): void {
mar.game.add.tween(this).to({isoZ: 15}, 400, Phaser.Easing.Bounce.Out, true);
mar.game.add.tween(this.scale).to({x: 1, y: 1}, 200, Phaser.Easing.Linear.None, true);
if (this.text !== undefined) {
this.text.visible = false;
}
this.hovered = false;
this.tint = this.getTint();
}
public getTint(): number {
if (!this.hovered) {
if (this.energy <= config.lowEnergy) {
return config.lowEnergyTint;
} else {
return config.cubotTint;
}
} else {
return config.cubotHoverTint;
}
}
updateObject(json): void {
if (DEBUG) {
console.log("Updating Cubot object")
}
this.action = json.action;
this.energy = json.energy;
this.direction = json.direction;
//Update color
this.tint = this.getTint();
//Update Location
if (!this.isAt(json.x, json.y)) {
//Location changed
if (this.action == Action.WALKING) {
//Walking..
this.tileX = json.x;
this.tileY = json.y;
this.walk();
} else if (this.action == Action.JUMPING) {
//TODO
}
}
if (this.action == Action.DIGGING) {
//TODO dig animation
}
this.updateDirection();
this.updateHologram(json.holoMode, json.holoC, json.holo, json.holoStr);
}
private updateHologram(holoMode: HologramMode, holoColor: number, holoValue: number, holoStr: string): void {
//Create hologram if not exist, set style
if (this.hologram == undefined) {
this.hologram = mar.game.make.text(0, 32, "");
this.hologram.anchor.set(0.5, 0);
this.addChild(this.hologram);
this.hologram.setStyle(config.holoStyle(holoColor));
} else {
this.hologram.setStyle(config.holoStyle(holoColor));
}
switch (holoMode) {
case HologramMode.CLEARED:
this.hologram.text = "";
break;
case HologramMode.DEC:
this.hologram.text = Number(holoValue).toString();
break;
case HologramMode.HEX:
this.hologram.text = "0x" + ("0000" + Number(holoValue).toString(16).toUpperCase()).slice(-4);
break;
case HologramMode.STRING:
this.hologram.text = holoStr.replace(/[\n|\t]/g, '');
break;
}
}
/**
* Set appropriate frame based on direction
*/
public updateDirection() {
switch (this.direction) {
case Direction.NORTH:
this.animations.frameName = "cubot/walk_n/0001";
break;
case Direction.EAST:
this.animations.frameName = "cubot/walk_e/0001";
break;
case Direction.SOUTH:
this.animations.frameName = "cubot/walk_s/0001";
break;
case Direction.WEST:
this.animations.frameName = "cubot/walk_w/0001";
break;
}
}
/**
* Initiate the walk animation. Handles multiple calls of this function even if the previous animations
* were not completed
*/
public walk() {
let self = this;
let walkAnimation = function (duration) {
//Move the Cubot to desired tile
let tween = mar.game.add.tween(self).to({isoX: Util.getIsoX(self.tileX), isoY: Util.getIsoY(self.tileY)},
duration, Phaser.Easing.Linear.None, true);
//Play appropriate animation
switch (self.direction) {
case Direction.NORTH:
self.animations.play("walk_n", 60, true);
break;
case Direction.SOUTH:
self.animations.play("walk_s", 60, true);
break;
case Direction.EAST:
self.animations.play("walk_e", 60, true);
break;
case Direction.WEST:
self.animations.play("walk_w", 60, true);
break;
}
//When moved to destination,
tween.onComplete.add(function () {
self.animations.stop();
self.updateDirection();
//Resync position
self.isoX = Util.getIsoX(self.tileX);
self.isoY = Util.getIsoY(self.tileY);
self.onTileExit();
//Execute all the queued walk animations at a faster pace
for (let i = 0; i < self.queuedAnimations.length; i++) {
self.queuedAnimations[i](config.walkDuration / 2);
self.queuedAnimations.splice(i, 1)
}
});
};
if (this.animations.currentAnim.isPlaying) {
//Queue up the animation
this.queuedAnimations.push(walkAnimation);
} else {
walkAnimation(config.walkDuration);
}
}
/**
* Create the username text that will appear on top of the Cubot. Text will have alternate
* color when current username matches. This function is also responsable for setting the
* reduced transparency of other Cubots
*/
public createUsername() {
let username = mar.game.make.text(0, -24, this.username, {
fontSize: 22,
fill: config.textFill,
stroke: config.textStroke,
strokeThickness: 2,
font: "fixedsys"
});
username.alpha = 0.85;
username.anchor.set(0.5, 0);
//Color own username
if (this.username === mar.client.username) {
username.tint = config.selfUsernameColor;
} else {
this.alpha = config.otherCubotAlpha;
}
this.addChild(username);
}
}
class HarvesterNPC extends Cubot {
constructor(json) {
super(json);
this.animations.add("walk_w", mar.animationFrames.harvester_walk_w);
this.animations.add("walk_s", mar.animationFrames.harvester_walk_s);
this.animations.add("walk_e", mar.animationFrames.harvester_walk_e);
this.animations.add("walk_n", mar.animationFrames.harvester_walk_n);
this.updateDirection();
this.setText("Harvester NPC");
this.text.visible = false;
}
/**
* Needs to be overridden because Cubot() calls getTint() when initialised
*/
public getTint() {
return config.cubotTint;
}
public updateDirection() {
switch (this.direction) {
case Direction.NORTH:
this.animations.frameName = "harvester/walk_n/0001";
break;
case Direction.EAST:
this.animations.frameName = "harvester/walk_e/0001";
break;
case Direction.SOUTH:
this.animations.frameName = "harvester/walk_s/0001";
break;
case Direction.WEST:
this.animations.frameName = "harvester/walk_w/0001";
break;
}
}
updateObject(json) {
if (DEBUG) {
console.log("Updating Harvester NPC object")
}
this.action = json.action;
this.direction = json.direction;
//Update Location
if (!this.isAt(json.x, json.y)) {
//Location changed
if (this.action == Action.WALKING) {
//Walking..
this.tileX = json.x;
this.tileY = json.y;
this.walk();
} else if (this.action == Action.JUMPING) {
//TODO
}
}
//Update Direction
this.updateDirection();
}
public createUsername() {
//No-op
}
}
class BiomassBlob extends GameObject {
onTileHover() {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({isoZ: 45}, 200, Phaser.Easing.Quadratic.InOut, true);
this.tint = config.biomassHoverTint;
mar.game.add.tween(this.scale).to({x: 1.2, y: 1.2}, 200, Phaser.Easing.Linear.None, true);
this.text.visible = true;
}
onTileExit() {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({isoZ: 15}, 400, Phaser.Easing.Bounce.Out, true);
mar.game.add.tween(this.scale).to({x: 1, y: 1}, 200, Phaser.Easing.Linear.None, true);
this.tint = config.biomassTint;
this.text.visible = false;
}
updateObject(json) {
if (DEBUG) {
console.log("Updating Biomass object")
}
}
constructor(json) {
super(Util.getIsoX(json.x), Util.getIsoY(json.y), 10, "sheet", 1);
if (DEBUG) {
console.log("Creating Biomass object")
}
this.anchor.set(0.5, 0);
this.id = json.i;
this.tileX = json.x;
this.tileY = json.y;
this.tint = config.biomassTint;
this.animations.add("idle", mar.animationFrames.biomassIdle);
this.animations.play("idle", 45, true);
this.setText("Biomass");
this.text.visible = false;
}
}
class Factory extends GameObject {
public onTileHover() {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({isoZ: 25}, 200, Phaser.Easing.Quadratic.InOut, true);
mar.game.add.tween(this.scale).to({x: 1.06, y: 1.06}, 200, Phaser.Easing.Linear.None, true);
this.tint = config.cubotHoverTint;
this.text.visible = true;
}
public onTileExit() {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({isoZ: 15}, 400, Phaser.Easing.Bounce.Out, true);
mar.game.add.tween(this.scale).to({x: 1, y: 1}, 200, Phaser.Easing.Linear.None, true);
this.tint = config.cubotTint;
this.text.visible = false;
}
public updateObject(json) {
//No op
}
public isAt(x: number, y: number) {
//Factory is 2x2
return (this.tileX === x || this.tileX + 1 === x) && (this.tileY + 1 === y || this.tileY === y);
};
constructor(json) {
super(Util.getIsoX(json.x), Util.getIsoY(json.y), 15, "sheet", "objects/factory");
this.anchor.set(0.5, .25);
this.setText("Factory");
this.text.visible = false;
this.id = json.i;
this.tileX = json.x;
this.tileY = json.y;
}
}
class RadioTower extends GameObject {
public onTileHover() {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({isoZ: 25}, 200, Phaser.Easing.Quadratic.InOut, true);
mar.game.add.tween(this.scale).to({x: 1.06, y: 1.06}, 200, Phaser.Easing.Linear.None, true);
this.tint = config.cubotHoverTint;
this.text.visible = true;
}
public onTileExit() {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({isoZ: 15}, 400, Phaser.Easing.Bounce.Out, true);
mar.game.add.tween(this.scale).to({x: 1, y: 1}, 200, Phaser.Easing.Linear.None, true);
this.tint = config.cubotTint;
this.text.visible = false;
}
public updateObject(json) {
//No op
}
constructor(json) {
super(Util.getIsoX(json.x), Util.getIsoY(json.y), 15, "sheet", "objects/RadioTower");
this.anchor.set(0.5, 0.64);
this.setText("Radio Tower");
this.text.visible = false;
this.id = json.i;
this.tileX = json.x;
this.tileY = json.y;
}
}

257
mar/phaser/MarGame.js Normal file
View File

@ -0,0 +1,257 @@
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var MarGame = (function () {
function MarGame() {
this.cursorPos = new Phaser.Plugin.Isometric.Point3();
this.debugMessages = [];
this.animationFrames = {};
var self = this;
this.game = new Phaser.Game(RENDERER_WIDTH, RENDERER_HEIGHT, Phaser.AUTO, 'game', null, true, false);
this.bootState = {
preload: function () {
if (DEBUG) {
console.log("[MAR] Loading sprites.png as JSONHash");
}
this.game.load.atlasJSONHash("sheet", "./mar/sprites.png", "./mar/sprites.json").onLoadComplete.add(function () {
self.game.time.advancedTiming = true;
//Add and enable the isometric plug-in.
if (DEBUG) {
console.log("[MAR] Enabling isometric plugin");
}
self.game.plugins.add(new Phaser.Plugin.Isometric(self.game));
// This is used to set a game canvas-based offset for the 0, 0, 0 isometric coordinate - by default
// this point would be at screen coordinates 0, 0 (top left) which is usually undesirable.
self.game.iso.anchor.setTo(0.5, 0);
//Todo: set world size based on window size?
self.game.world.setBounds(0, 0, 2200, 1100);
//Make camera more or less centered (tested on 1080 screen)
self.game.camera.x = 280;
self.game.camera.y = 90;
self.game.scale.scaleMode = Phaser.ScaleManager.RESIZE;
self.game.scale.pageAlignHorizontally = true;
self.game.scale.pageAlignVertically = true;
self.game.stage.disableVisibilityChange = true;
self.client = new GameClient();
//Grab focus when clicked (For chrome, Opera)
self.game.input.onDown.add(function () {
document.getElementById("game").focus();
if (DEBUG) {
console.log("Grabbed focus of #game");
}
});
self.isoGroup = mar.game.add.group();
self.textGroup = mar.game.add.group();
self.hudGroup = mar.game.add.group();
self.hudGroup.fixedToCamera = true;
});
},
create: function () {
console.log("[MAR] create");
self.initialiseAnimations();
self.initialiseStaticHud();
},
update: function () {
self.game.scale.refresh();
// Update the cursor position.
self.game.iso.unproject(self.game.input.activePointer.position, self.cursorPos);
// Loop through all tiles and test to see if the 3D position from above intersects with the automatically generated IsoSprite tile bounds.
self.isoGroup.forEach(function (tile) {
if (tile instanceof Tile) {
var inBounds = tile.isoBounds.containsXY(self.cursorPos.x, self.cursorPos.y);
// If it does, do a little animation and tint change.
if (!tile.selected && inBounds) {
tile.selected = true;
tile.onHover();
//Dispatch tile over
self.isoGroup.forEach(function (obj) {
if (obj instanceof GameObject && obj.onTileHover != undefined && obj.isAt(tile.tileX, tile.tileY)) {
obj.onTileHover();
}
}, 1);
}
else if (tile.selected && !inBounds) {
tile.selected = false;
tile.onExit();
//Dispatch tile exit
self.isoGroup.forEach(function (obj) {
if (obj.onTileExit != undefined && obj.isAt(tile.tileX, tile.tileY)) {
obj.onTileExit();
}
}, 0);
}
}
}, 0);
//Enable dragging the camera
if (this.game.input.activePointer.isDown) {
if (this.game.origDragPoint) {
// move the camera by the amount the mouse has moved since last update
this.game.camera.x += this.game.origDragPoint.x - this.game.input.activePointer.position.x;
this.game.camera.y += this.game.origDragPoint.y - this.game.input.activePointer.position.y;
}
// set new drag origin to current position
this.game.origDragPoint = this.game.input.activePointer.position.clone();
}
else {
this.game.origDragPoint = null;
}
self.game.iso.topologicalSort(self.isoGroup);
},
render: function () {
for (var i = 0; i < self.debugMessages.length; i++) {
self.game.debug.text(self.debugMessages[i].getMessage(), self.debugMessages[i].x, self.debugMessages[i].y);
}
}
};
this.game.state.add('Boot', this.bootState);
this.game.state.start('Boot');
}
MarGame.prototype.addDebugMessage = function (debugMsg) {
this.debugMessages.push(debugMsg);
};
MarGame.prototype.initialiseAnimations = function () {
//Walk =-------------------------------------------------------
//East
this.animationFrames.walk_e_start = [];
for (var i = 0; i < 10; i++) {
this.animationFrames.walk_e_start.push("cubot/walk_e/" + ("0000" + i).slice(-4));
}
this.animationFrames.walk_e = [];
for (var i = 10; i < 30; i++) {
this.animationFrames.walk_e.push("cubot/walk_e/" + ("0000" + i).slice(-4));
}
this.animationFrames.harvester_walk_e_start = [];
for (var i = 0; i < 10; i++) {
this.animationFrames.harvester_walk_e_start.push("harvester/walk_e/" + ("0000" + i).slice(-4));
}
this.animationFrames.harvester_walk_e = [];
for (var i = 10; i < 30; i++) {
this.animationFrames.harvester_walk_e.push("harvester/walk_e/" + ("0000" + i).slice(-4));
}
//North
this.animationFrames.walk_n_start = [];
for (var i = 0; i < 10; i++) {
this.animationFrames.walk_n_start.push("cubot/walk_n/" + ("0000" + i).slice(-4));
}
this.animationFrames.walk_n = [];
for (var i = 10; i < 30; i++) {
this.animationFrames.walk_n.push("cubot/walk_n/" + ("0000" + i).slice(-4));
}
this.animationFrames.harvester_walk_n_start = [];
for (var i = 0; i < 10; i++) {
this.animationFrames.harvester_walk_n_start.push("harvester/walk_n/" + ("0000" + i).slice(-4));
}
this.animationFrames.harvester_walk_n = [];
for (var i = 10; i < 30; i++) {
this.animationFrames.harvester_walk_n.push("harvester/walk_n/" + ("0000" + i).slice(-4));
}
//South
this.animationFrames.walk_s_start = [];
for (var i = 0; i < 10; i++) {
this.animationFrames.walk_s_start.push("cubot/walk_s/" + ("0000" + i).slice(-4));
}
this.animationFrames.walk_s = [];
for (var i = 10; i < 30; i++) {
this.animationFrames.walk_s.push("cubot/walk_s/" + ("0000" + i).slice(-4));
}
this.animationFrames.harvester_walk_s_start = [];
for (var i = 0; i < 10; i++) {
this.animationFrames.harvester_walk_s_start.push("harvester/walk_s/" + ("0000" + i).slice(-4));
}
this.animationFrames.harvester_walk_s = [];
for (var i = 10; i < 30; i++) {
this.animationFrames.harvester_walk_s.push("harvester/walk_s/" + ("0000" + i).slice(-4));
}
//West
this.animationFrames.walk_w_start = [];
for (var i = 0; i < 10; i++) {
this.animationFrames.walk_w_start.push("cubot/walk_w/" + ("0000" + i).slice(-4));
}
this.animationFrames.walk_w = [];
for (var i = 10; i < 30; i++) {
this.animationFrames.walk_w.push("cubot/walk_w/" + ("0000" + i).slice(-4));
}
this.animationFrames.harvester_walk_w_start = [];
for (var i = 0; i < 10; i++) {
this.animationFrames.harvester_walk_w_start.push("harvester/walk_w/" + ("0000" + i).slice(-4));
}
this.animationFrames.harvester_walk_w = [];
for (var i = 10; i < 30; i++) {
this.animationFrames.harvester_walk_w.push("harvester/walk_w/" + ("0000" + i).slice(-4));
}
//Dig =-------------------------------------------------------
this.animationFrames.dig_e = [];
for (var i = 1; i <= 41; i++) {
this.animationFrames.dig_e.push("cubot/dig_e/" + ("0000" + i).slice(-4));
}
this.animationFrames.dig_n = [];
for (var i = 1; i <= 41; i++) {
this.animationFrames.dig_n.push("cubot/dig_n/" + ("0000" + i).slice(-4));
}
this.animationFrames.dig_s = [];
for (var i = 1; i <= 41; i++) {
this.animationFrames.dig_s.push("cubot/dig_s/" + ("0000" + i).slice(-4));
}
this.animationFrames.dig_w = [];
for (var i = 1; i <= 41; i++) {
this.animationFrames.dig_w.push("cubot/dig_w/" + ("0000" + i).slice(-4));
}
//Biomass =-------------------------------------------------------
this.animationFrames.biomassIdle = [];
for (var i = 1; i < 60; i++) {
this.animationFrames.biomassIdle.push("objects/biomass/idle/" + ("0000" + i).slice(-4));
}
};
MarGame.prototype.initialiseStaticHud = function () {
this.game.add.sprite(0, this.game.camera.height - 150, "sheet", "ui/compass", this.hudGroup);
this.addDebugMessage(new WorldIndicator(10, 20));
this.tileIndicator = new TileIndicator(10, 40);
this.addDebugMessage(this.tileIndicator);
};
return MarGame;
}());
var DebugMessage = (function () {
function DebugMessage(x, y) {
this.x = x;
this.y = y;
}
return DebugMessage;
}());
var TileIndicator = (function (_super) {
__extends(TileIndicator, _super);
function TileIndicator() {
return _super !== null && _super.apply(this, arguments) || this;
}
TileIndicator.prototype.getMessage = function () {
if (this.tileType != undefined) {
return this.tileX + ", " + this.tileY + " : " + this.tileType;
}
else {
return "";
}
};
return TileIndicator;
}(DebugMessage));
var WorldIndicator = (function (_super) {
__extends(WorldIndicator, _super);
function WorldIndicator() {
return _super !== null && _super.apply(this, arguments) || this;
}
WorldIndicator.prototype.getMessage = function () {
if (mar.world != undefined) {
return "World: (" + Number(mar.client.worldX).toString(16).toUpperCase() + ", " +
Number(mar.client.worldY).toString(16).toUpperCase() + ")";
}
else {
return "Loading...";
}
};
return WorldIndicator;
}(DebugMessage));

318
mar/phaser/MarGame.ts Normal file
View File

@ -0,0 +1,318 @@
class MarGame {
isoGroup: Phaser.Group;
textGroup: Phaser.Group;
hudGroup: Phaser.Group;
game: Phaser.Game;
cursorPos: Phaser.Plugin.Isometric.Point3 = new Phaser.Plugin.Isometric.Point3();
bootState;
client: GameClient;
debugMessages: DebugMessage[] = [];
world: World;
animationFrames: any = {};
tileIndicator: TileIndicator;
constructor() {
let self = this;
this.game = new Phaser.Game(RENDERER_WIDTH, RENDERER_HEIGHT, Phaser.AUTO, 'game', null, true, false);
this.bootState = {
preload: function () {
if (DEBUG) {
console.log("[MAR] Loading sprites.png as JSONHash");
}
this.game.load.atlasJSONHash("sheet", "./mar/sprites.png", "./mar/sprites.json").onLoadComplete.add(function () {
self.game.time.advancedTiming = true;
//Add and enable the isometric plug-in.
if (DEBUG) {
console.log("[MAR] Enabling isometric plugin");
}
self.game.plugins.add(new Phaser.Plugin.Isometric(self.game));
// This is used to set a game canvas-based offset for the 0, 0, 0 isometric coordinate - by default
// this point would be at screen coordinates 0, 0 (top left) which is usually undesirable.
self.game.iso.anchor.setTo(0.5, 0);
//Todo: set world size based on window size?
self.game.world.setBounds(0, 0, 2200, 1100);
//Make camera more or less centered (tested on 1080 screen)
self.game.camera.x = 280;
self.game.camera.y = 90;
self.game.scale.scaleMode = Phaser.ScaleManager.RESIZE;
self.game.scale.pageAlignHorizontally = true;
self.game.scale.pageAlignVertically = true;
self.game.stage.disableVisibilityChange = true;
self.client = new GameClient();
//Grab focus when clicked (For chrome, Opera)
self.game.input.onDown.add(function () {
document.getElementById("game").focus();
if (DEBUG) {
console.log("Grabbed focus of #game");
}
});
self.isoGroup = mar.game.add.group();
self.textGroup = mar.game.add.group();
self.hudGroup = mar.game.add.group();
self.hudGroup.fixedToCamera = true;
});
},
create: function () {
console.log("[MAR] create");
self.initialiseAnimations();
self.initialiseStaticHud();
},
update: function () {
self.game.scale.refresh();
// Update the cursor position.
self.game.iso.unproject(self.game.input.activePointer.position, self.cursorPos);
// Loop through all tiles and test to see if the 3D position from above intersects with the automatically generated IsoSprite tile bounds.
self.isoGroup.forEach(function (tile: Tile) {
if (tile instanceof Tile) {
let inBounds = tile.isoBounds.containsXY(self.cursorPos.x, self.cursorPos.y);
// If it does, do a little animation and tint change.
if (!tile.selected && inBounds) {
tile.selected = true;
tile.onHover();
//Dispatch tile over
self.isoGroup.forEach(function (obj: GameObject) {
if (obj instanceof GameObject && obj.onTileHover != undefined && obj.isAt(tile.tileX, tile.tileY)) {
obj.onTileHover();
}
}, 1);
}
// If not, revert back to how it was.
else if (tile.selected && !inBounds) {
tile.selected = false;
tile.onExit();
//Dispatch tile exit
self.isoGroup.forEach(function (obj: GameObject) {
if (obj.onTileExit != undefined && obj.isAt(tile.tileX, tile.tileY)) {
obj.onTileExit();
}
}, 0);
}
}
}, 0);
//Enable dragging the camera
if (this.game.input.activePointer.isDown) {
if (this.game.origDragPoint) {
// move the camera by the amount the mouse has moved since last update
this.game.camera.x += this.game.origDragPoint.x - this.game.input.activePointer.position.x;
this.game.camera.y += this.game.origDragPoint.y - this.game.input.activePointer.position.y;
}
// set new drag origin to current position
this.game.origDragPoint = this.game.input.activePointer.position.clone();
} else {
this.game.origDragPoint = null;
}
self.game.iso.topologicalSort(self.isoGroup);
},
render: function () {
for (let i = 0; i < self.debugMessages.length; i++) {
self.game.debug.text(self.debugMessages[i].getMessage(), self.debugMessages[i].x,
self.debugMessages[i].y)
}
}
};
this.game.state.add('Boot', this.bootState);
this.game.state.start('Boot');
}
public addDebugMessage(debugMsg: DebugMessage) {
this.debugMessages.push(debugMsg)
}
private initialiseAnimations() {
//Walk =-------------------------------------------------------
//East
this.animationFrames.walk_e_start = [];
for (let i = 0; i < 10; i++) {
this.animationFrames.walk_e_start.push("cubot/walk_e/" + ("0000" + i).slice(-4));
}
this.animationFrames.walk_e = [];
for (let i = 10; i < 30; i++) {
this.animationFrames.walk_e.push("cubot/walk_e/" + ("0000" + i).slice(-4));
}
this.animationFrames.harvester_walk_e_start = [];
for (let i = 0; i < 10; i++) {
this.animationFrames.harvester_walk_e_start.push("harvester/walk_e/" + ("0000" + i).slice(-4));
}
this.animationFrames.harvester_walk_e = [];
for (let i = 10; i < 30; i++) {
this.animationFrames.harvester_walk_e.push("harvester/walk_e/" + ("0000" + i).slice(-4));
}
//North
this.animationFrames.walk_n_start = [];
for (let i = 0; i < 10; i++) {
this.animationFrames.walk_n_start.push("cubot/walk_n/" + ("0000" + i).slice(-4));
}
this.animationFrames.walk_n = [];
for (let i = 10; i < 30; i++) {
this.animationFrames.walk_n.push("cubot/walk_n/" + ("0000" + i).slice(-4));
}
this.animationFrames.harvester_walk_n_start = [];
for (let i = 0; i < 10; i++) {
this.animationFrames.harvester_walk_n_start.push("harvester/walk_n/" + ("0000" + i).slice(-4));
}
this.animationFrames.harvester_walk_n = [];
for (let i = 10; i < 30; i++) {
this.animationFrames.harvester_walk_n.push("harvester/walk_n/" + ("0000" + i).slice(-4));
}
//South
this.animationFrames.walk_s_start = [];
for (let i = 0; i < 10; i++) {
this.animationFrames.walk_s_start.push("cubot/walk_s/" + ("0000" + i).slice(-4));
}
this.animationFrames.walk_s = [];
for (let i = 10; i < 30; i++) {
this.animationFrames.walk_s.push("cubot/walk_s/" + ("0000" + i).slice(-4));
}
this.animationFrames.harvester_walk_s_start = [];
for (let i = 0; i < 10; i++) {
this.animationFrames.harvester_walk_s_start.push("harvester/walk_s/" + ("0000" + i).slice(-4));
}
this.animationFrames.harvester_walk_s = [];
for (let i = 10; i < 30; i++) {
this.animationFrames.harvester_walk_s.push("harvester/walk_s/" + ("0000" + i).slice(-4));
}
//West
this.animationFrames.walk_w_start = [];
for (let i = 0; i < 10; i++) {
this.animationFrames.walk_w_start.push("cubot/walk_w/" + ("0000" + i).slice(-4));
}
this.animationFrames.walk_w = [];
for (let i = 10; i < 30; i++) {
this.animationFrames.walk_w.push("cubot/walk_w/" + ("0000" + i).slice(-4));
}
this.animationFrames.harvester_walk_w_start = [];
for (let i = 0; i < 10; i++) {
this.animationFrames.harvester_walk_w_start.push("harvester/walk_w/" + ("0000" + i).slice(-4));
}
this.animationFrames.harvester_walk_w = [];
for (let i = 10; i < 30; i++) {
this.animationFrames.harvester_walk_w.push("harvester/walk_w/" + ("0000" + i).slice(-4));
}
//Dig =-------------------------------------------------------
this.animationFrames.dig_e = [];
for (let i = 1; i <= 41; i++) {
this.animationFrames.dig_e.push("cubot/dig_e/" + ("0000" + i).slice(-4));
}
this.animationFrames.dig_n = [];
for (let i = 1; i <= 41; i++) {
this.animationFrames.dig_n.push("cubot/dig_n/" + ("0000" + i).slice(-4));
}
this.animationFrames.dig_s = [];
for (let i = 1; i <= 41; i++) {
this.animationFrames.dig_s.push("cubot/dig_s/" + ("0000" + i).slice(-4));
}
this.animationFrames.dig_w = [];
for (let i = 1; i <= 41; i++) {
this.animationFrames.dig_w.push("cubot/dig_w/" + ("0000" + i).slice(-4));
}
//Biomass =-------------------------------------------------------
this.animationFrames.biomassIdle = [];
for (let i = 1; i < 60; i++) {
this.animationFrames.biomassIdle.push("objects/biomass/idle/" + ("0000" + i).slice(-4));
}
}
private initialiseStaticHud() {
this.game.add.sprite(0, this.game.camera.height - 150, "sheet", "ui/compass", this.hudGroup);
this.addDebugMessage(new WorldIndicator(10, 20));
this.tileIndicator = new TileIndicator(10, 40);
this.addDebugMessage(this.tileIndicator);
}
}
abstract class DebugMessage {
public x: number;
public y: number;
constructor(x: number, y: number) {
this.x = x;
this.y = y;
}
abstract getMessage(): string;
}
class TileIndicator extends DebugMessage {
public tileType: string;
public tileX: number;
public tileY: number;
getMessage(): string {
if (this.tileType != undefined) {
return this.tileX + ", " + this.tileY + " : " + this.tileType;
} else {
return "";
}
}
}
class WorldIndicator extends DebugMessage {
getMessage(): string {
if (mar.world != undefined) {
return "World: (" + Number(mar.client.worldX).toString(16).toUpperCase() + ", " +
Number(mar.client.worldY).toString(16).toUpperCase() + ")";
} else {
return "Loading..."
}
}
}

278
mar/phaser/World.js Normal file
View File

@ -0,0 +1,278 @@
///<reference path="GameClient.ts"/>
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var instances = PIXI.instances;
var Direction;
(function (Direction) {
Direction[Direction["NORTH"] = 0] = "NORTH";
Direction[Direction["EAST"] = 1] = "EAST";
Direction[Direction["SOUTH"] = 2] = "SOUTH";
Direction[Direction["WEST"] = 3] = "WEST";
})(Direction || (Direction = {}));
var Tile = (function (_super) {
__extends(Tile, _super);
function Tile(x, y, sprite, anchorY) {
var _this = _super.call(this, mar.game, Util.getIsoX(x), Util.getIsoY(y), 0, 'sheet', sprite) || this;
_this.baseZ = 0; //Base height of the tile
_this.tileX = x;
_this.tileY = y;
_this.anchor.set(0.5, anchorY);
return _this;
}
/**
* Factory method to create a Tile
*/
Tile.createTile = function (type, x, y) {
switch (type) {
case TileType.WALL:
return new WallTile(x, y);
case TileType.IRON:
return new IronTile(x, y);
case TileType.COPPER:
return new CopperTile(x, y);
case TileType.PLAIN:
default:
return new PlainTile(x, y);
}
};
Tile.prototype.onHover = function () {
this.tint = config.tileHoverTint;
mar.game.add.tween(this).to({ isoZ: this.baseZ + 8 }, 200, Phaser.Easing.Quadratic.InOut, true);
mar.tileIndicator.tileX = this.tileX;
mar.tileIndicator.tileY = this.tileY;
mar.tileIndicator.tileType = this.tileType;
};
Tile.prototype.onExit = function () {
this.tint = this.baseTint;
mar.game.add.tween(this).to({ isoZ: this.baseZ }, 200, Phaser.Easing.Quadratic.InOut, true);
};
Tile.prototype.setText = function (text, fillColor) {
//Remove previous text
if (this.textSprite !== undefined) {
this.textSprite.destroy();
}
this.textSprite = mar.game.make.text(0, 16, text, {
fontSize: 22,
fill: fillColor,
stroke: "#FFFFFF",
strokeThickness: 1,
font: "fixedsys"
});
this.textSprite.alpha = 0.6;
this.textSprite.anchor.set(0.5, 0);
this.addChild(this.textSprite);
};
return Tile;
}(Phaser.Plugin.Isometric.IsoSprite));
var PlainTile = (function (_super) {
__extends(PlainTile, _super);
function PlainTile(x, y) {
var _this = _super.call(this, x, y, config.plainSprite, 0) || this;
_this.baseTint = config.tileTint;
_this.tint = _this.baseTint;
_this.tileType = "plain";
return _this;
}
return PlainTile;
}(Tile));
var WallTile = (function (_super) {
__extends(WallTile, _super);
function WallTile(x, y) {
var _this = _super.call(this, x, y, config.wallSprite, 0.2) || this;
_this.baseTint = config.wallTint;
_this.tint = _this.baseTint;
_this.tileType = "wall";
return _this;
}
return WallTile;
}(Tile));
var IronTile = (function (_super) {
__extends(IronTile, _super);
function IronTile(x, y) {
var _this = _super.call(this, x, y, config.plainSprite, 0) || this;
_this.baseTint = config.oreTint;
_this.tint = _this.baseTint;
_this.setText("Iron", config.textIron);
_this.tileType = "iron";
return _this;
}
return IronTile;
}(Tile));
var CopperTile = (function (_super) {
__extends(CopperTile, _super);
function CopperTile(x, y) {
var _this = _super.call(this, x, y, config.plainSprite, 0) || this;
_this.baseTint = config.oreTint;
_this.tint = _this.baseTint;
_this.setText("Copper", config.textCopper);
_this.tileType = "copper";
return _this;
}
return CopperTile;
}(Tile));
var World = (function () {
function World(terrain) {
this.tiles = [];
this.objects = [];
//Create tilemap
this.setTerrain(terrain);
//Setup World Arrows
mar.isoGroup.add(new WorldArrow(528, -10, "ui/arrow_north", Direction.NORTH));
mar.isoGroup.add(new WorldArrow(1115, 587, "ui/arrow_east", Direction.EAST));
mar.isoGroup.add(new WorldArrow(528, 1170, "ui/arrow_south", Direction.SOUTH));
mar.isoGroup.add(new WorldArrow(-60, 587, "ui/arrow_west", Direction.WEST));
}
/**
* Load terrain data from array and create Tiles
* @param terrain
*/
World.prototype.setTerrain = function (terrain) {
if (DEBUG) {
console.log("[MAR] Creating tilemap");
}
for (var x = 0; x < config.worldSize; x++) {
for (var y = 0; y < config.worldSize; y++) {
var tile = Tile.createTile(terrain[y * config.worldSize + x], x, y);
this.tiles.push(tile);
mar.isoGroup.add(tile);
}
}
};
World.prototype.setBigMessage = function (msg) {
this.bigMessage = mar.game.add.text(908, 450, msg, {
fontSize: 46,
fill: config.bigMessageFill,
stroke: config.textStroke,
strokeThickness: 2,
font: "fixedsys"
}, mar.textGroup);
};
World.prototype.removeBigMessage = function () {
if (this.bigMessage != undefined) {
this.bigMessage.destroy();
if (DEBUG) {
console.log("[MAR] Destroyed big message");
}
}
};
/**
* Get object by id
*/
World.prototype.getObject = function (id) {
for (var i = 0; i < this.objects.length; i++) {
if (this.objects[i].id === id) {
return this.objects[i];
}
}
return null;
};
/**
* Update, create or delete the current objects based on a list received from the server
* @param objects json list of objects
*/
World.prototype.handleObjectsUpdate = function (objects) {
//Mark objects as not updated
for (var i = 0; i < this.objects.length; i++) {
this.objects[i].updated = false;
}
for (var i = 0; i < objects.length; i++) {
//Update/Create the object
var existingObject = this.getObject(objects[i].i);
if (existingObject !== null) {
//Object already exists
existingObject.updated = true;
existingObject.updateObject(objects[i]);
}
else {
//Object is new
var newObj = GameObject.createObject(objects[i]);
if (newObj != null) {
newObj.updated = true;
this.objects.push(newObj);
mar.isoGroup.add(newObj);
}
else {
if (DEBUG) {
console.log("Couldn't create object with objType " + objects[i].t);
}
}
}
}
//Delete not updated objects (see above comments)
for (var i = 0; i < this.objects.length; i++) {
if (!this.objects[i].updated) {
//Check if the object we are removing is our controlledUnit, if so, follow it
if (mar.client.username !== "guest") {
if (this.objects[i] instanceof Cubot && this.objects[i].username === mar.client.username) {
mar.client.findMyRobot();
if (DEBUG) {
console.log("[MAR] Following Cubot " + mar.client.username);
}
}
}
this.objects[i].destroy();
this.objects.splice(i, 1);
}
}
};
/**
* Delete current ojects and tiles and replace them with provided terrain
* @param terrain
*/
World.prototype.updateTerrain = function (terrain) {
for (var i = 0; i < this.objects.length; i++) {
this.objects[i].destroy();
}
for (var i = 0; i < this.tiles.length; i++) {
this.tiles[i].destroy();
}
this.objects = [];
this.tiles = [];
this.setTerrain(terrain);
mar.game.iso.topologicalSort(mar.isoGroup);
};
return World;
}());
/**
* Represents a 'button' sprite that changes world in a direction
*/
var WorldArrow = (function (_super) {
__extends(WorldArrow, _super);
function WorldArrow(x, y, frame, direction) {
var _this = _super.call(this, mar.game, x, y, 10, "sheet", frame) || this;
var self = _this;
_this.hoverText = mar.game.make.text(10, 10, Direction[direction], config.arrowTextStyle);
_this.addChild(_this.hoverText);
_this.hoverText.visible = false;
_this.hoverText.anchor.set(0, 0);
_this.inputEnabled = true;
_this.events.onInputDown.add(function () {
var newX = mar.client.worldX + Util.getDeltaX(direction);
var newY = mar.client.worldY + Util.getDeltaY(direction);
//Wrapping coordinates around cyclically
mar.client.worldX = newX % mar.client.maxWidth;
mar.client.worldY = newY % mar.client.maxWidth;
mar.client.requestTerrain();
});
_this.events.onInputOver.add(function () {
self.tint = config.arrowHoverTint;
self.hoverText.visible = true;
document.body.style.cursor = "pointer";
});
_this.events.onInputOut.add(function () {
self.tint = config.arrowTint;
self.hoverText.visible = false;
document.body.style.cursor = "default";
});
return _this;
}
return WorldArrow;
}(Phaser.Plugin.Isometric.IsoSprite));

351
mar/phaser/World.ts Normal file
View File

@ -0,0 +1,351 @@
///<reference path="GameClient.ts"/>
import instances = PIXI.instances;
enum Direction {
NORTH,
EAST,
SOUTH,
WEST
}
class Tile extends Phaser.Plugin.Isometric.IsoSprite {
/**
* Text displayed on the tile
*/
textSprite: Phaser.Text;
baseTint: number;
tileX: number;
tileY: number;
/**
* Displayed on the screen
*/
tileType: string;
/**
* Based z coordinate of the tile
*/
private baseZ: number;
public selected: boolean;
protected constructor(x: number, y: number, sprite: string, anchorY: number) {
super(mar.game, Util.getIsoX(x), Util.getIsoY(y), 0, 'sheet', sprite);
this.baseZ = 0; //Base height of the tile
this.tileX = x;
this.tileY = y;
this.anchor.set(0.5, anchorY);
}
/**
* Factory method to create a Tile
*/
public static createTile(type: TileType, x: number, y: number) {
switch (type) {
case TileType.WALL:
return new WallTile(x, y);
case TileType.IRON:
return new IronTile(x, y);
case TileType.COPPER:
return new CopperTile(x, y);
case TileType.PLAIN:
default:
return new PlainTile(x, y);
}
}
public onHover() {
this.tint = config.tileHoverTint;
mar.game.add.tween(this).to({isoZ: this.baseZ + 8}, 200, Phaser.Easing.Quadratic.InOut, true);
mar.tileIndicator.tileX = this.tileX;
mar.tileIndicator.tileY = this.tileY;
mar.tileIndicator.tileType = this.tileType;
}
public onExit() {
this.tint = this.baseTint;
mar.game.add.tween(this).to({isoZ: this.baseZ}, 200, Phaser.Easing.Quadratic.InOut, true);
}
public setText(text: string, fillColor: string): void {
//Remove previous text
if (this.textSprite !== undefined) {
this.textSprite.destroy();
}
this.textSprite = mar.game.make.text(0, 16, text, {
fontSize: 22,
fill: fillColor,
stroke: "#FFFFFF",
strokeThickness: 1,
font: "fixedsys"
});
this.textSprite.alpha = 0.6;
this.textSprite.anchor.set(0.5, 0);
this.addChild(this.textSprite);
}
}
class PlainTile extends Tile {
constructor(x: number, y: number) {
super(x, y, config.plainSprite, 0);
this.baseTint = config.tileTint;
this.tint = this.baseTint;
this.tileType = "plain";
}
}
class WallTile extends Tile {
constructor(x: number, y: number) {
super(x, y, config.wallSprite, 0.2);
this.baseTint = config.wallTint;
this.tint = this.baseTint;
this.tileType = "wall";
}
}
class IronTile extends Tile {
constructor(x: number, y: number) {
super(x, y, config.plainSprite, 0);
this.baseTint = config.oreTint;
this.tint = this.baseTint;
this.setText("Iron", config.textIron);
this.tileType = "iron";
}
}
class CopperTile extends Tile {
constructor(x: number, y: number) {
super(x, y, config.plainSprite, 0);
this.baseTint = config.oreTint;
this.tint = this.baseTint;
this.setText("Copper", config.textCopper);
this.tileType = "copper";
}
}
class World {
private tiles: Tile[] = [];
private objects: GameObject[] = [];
/**
* Message displayed in the middle of the World
*/
private bigMessage: Phaser.Text;
constructor(terrain) {
//Create tilemap
this.setTerrain(terrain);
//Setup World Arrows
mar.isoGroup.add(new WorldArrow(528, -10, "ui/arrow_north", Direction.NORTH));
mar.isoGroup.add(new WorldArrow(1115, 587, "ui/arrow_east", Direction.EAST));
mar.isoGroup.add(new WorldArrow(528, 1170, "ui/arrow_south", Direction.SOUTH));
mar.isoGroup.add(new WorldArrow(-60, 587, "ui/arrow_west", Direction.WEST));
}
/**
* Load terrain data from array and create Tiles
* @param terrain
*/
private setTerrain(terrain: number[]) {
if (DEBUG) {
console.log("[MAR] Creating tilemap");
}
for (let x = 0; x < config.worldSize; x++) {
for (let y = 0; y < config.worldSize; y++) {
let tile: Tile = Tile.createTile(terrain[y * config.worldSize + x], x, y);
this.tiles.push(tile);
mar.isoGroup.add(tile);
}
}
}
public setBigMessage(msg: string) {
this.bigMessage = mar.game.add.text(908, 450, msg, {
fontSize: 46,
fill: config.bigMessageFill,
stroke: config.textStroke,
strokeThickness: 2,
font: "fixedsys"
}, mar.textGroup);
}
public removeBigMessage() {
if (this.bigMessage != undefined) {
this.bigMessage.destroy();
if (DEBUG) {
console.log("[MAR] Destroyed big message")
}
}
}
/**
* Get object by id
*/
private getObject(id: number): GameObject {
for (let i = 0; i < this.objects.length; i++) {
if (this.objects[i].id === id) {
return this.objects[i];
}
}
return null;
}
/**
* Update, create or delete the current objects based on a list received from the server
* @param objects json list of objects
*/
public handleObjectsUpdate(objects: any) {
//Mark objects as not updated
for (let i = 0; i < this.objects.length; i++) {
this.objects[i].updated = false;
}
for (let i = 0; i < objects.length; i++) {
//Update/Create the object
let existingObject = this.getObject(objects[i].i);
if (existingObject !== null) {
//Object already exists
existingObject.updated = true;
existingObject.updateObject(objects[i]);
} else {
//Object is new
let newObj = GameObject.createObject(objects[i]);
if (newObj != null) {
newObj.updated = true;
this.objects.push(newObj);
mar.isoGroup.add(newObj);
} else {
if (DEBUG) {
console.log("Couldn't create object with objType " + objects[i].t)
}
}
}
}
//Delete not updated objects (see above comments)
for (let i = 0; i < this.objects.length; i++) {
if (!this.objects[i].updated) {
//Check if the object we are removing is our controlledUnit, if so, follow it
if (mar.client.username !== "guest") {
if (this.objects[i] instanceof Cubot && (this.objects[i] as Cubot).username === mar.client.username) {
mar.client.findMyRobot();
if (DEBUG) {
console.log("[MAR] Following Cubot " + mar.client.username)
}
}
}
this.objects[i].destroy();
this.objects.splice(i, 1);
}
}
}
/**
* Delete current ojects and tiles and replace them with provided terrain
* @param terrain
*/
public updateTerrain(terrain: number[]) {
for (let i = 0; i < this.objects.length; i++) {
this.objects[i].destroy();
}
for (let i = 0; i < this.tiles.length; i++) {
this.tiles[i].destroy();
}
this.objects = [];
this.tiles = [];
this.setTerrain(terrain);
mar.game.iso.topologicalSort(mar.isoGroup);
}
}
/**
* Represents a 'button' sprite that changes world in a direction
*/
class WorldArrow extends Phaser.Plugin.Isometric.IsoSprite {
private hoverText: Phaser.Text;
constructor(x: number, y: number, frame: string, direction: Direction) {
super(mar.game, x, y, 10, "sheet", frame);
let self = this;
this.hoverText = mar.game.make.text(10, 10, Direction[direction], config.arrowTextStyle);
this.addChild(this.hoverText);
this.hoverText.visible = false;
this.hoverText.anchor.set(0, 0);
this.inputEnabled = true;
this.events.onInputDown.add(function () {
let newX = mar.client.worldX + Util.getDeltaX(direction);
let newY = mar.client.worldY + Util.getDeltaY(direction);
//Wrapping coordinates around cyclically
mar.client.worldX = newX % mar.client.maxWidth;
mar.client.worldY = newY % mar.client.maxWidth;
mar.client.requestTerrain();
});
this.events.onInputOver.add(function () {
self.tint = config.arrowHoverTint;
self.hoverText.visible = true;
document.body.style.cursor = "pointer";
});
this.events.onInputOut.add(function () {
self.tint = config.arrowTint;
self.hoverText.visible = false;
document.body.style.cursor = "default";
});
}
}

File diff suppressed because it is too large Load Diff

61
mar/phaser/mar.min.js vendored
View File

@ -1,57 +1,4 @@
DIR_NORTH=0;DIR_EAST=1;DIR_SOUTH=2;DIR_WEST=3;WORLD_HEIGHT=WORLD_WIDTH=16;var colorScheme={tileTint:16777215,wallTint:14540253,cubotHoverTint:65280,cubotTint:16777215,textFill:"#FFFFFF",textStroke:"#9298a8",biomassTint:6535263,biomassHoverTint:65280,tileHoverTint:65280,itemIron:4408129,itemCopper:13139256,hologramFill:"#0aced6",hologramStroke:"#12FFB0",hologramAlpha:.9},mar={kbBuffer:[],kbBufferText:"",animationFrames:{},controlledUnitVisible:!1,lastLines:""};
CUBOT_WALK_FRAMES={south:240,north:194,west:254,east:164};HARVESTER_WALK_FRAMES={south:347,north:317,west:377,east:287};LOW_ENERGY=100;fullscreen?(RENDERER_WIDTH=window.innerWidth-4,RENDERER_HEIGHT=window.innerHeight-4):(RENDERER_WIDTH=document.getElementById("game").clientWidth,RENDERER_HEIGHT=window.innerHeight/1.25);var game=new Phaser.Game(RENDERER_WIDTH,RENDERER_HEIGHT,Phaser.AUTO,"game",null,!0,!1);
function dispatchTileLeave(a,b){for(var c=0;c<mar.world.tiles.length;c++){var d=mar.world.tiles[c].tileX,f=mar.world.tiles[c].tileY;mar.world.tiles[c].isWall&&(d===a&&f-1===b||d-1===a&&f-1===b||d-1===a&&f===b)&&1!==mar.world.tiles[c].alpha&&game.add.tween(mar.world.tiles[c]).to({alpha:1},175,Phaser.Easing.Quadratic.In,!0)}}
function dispatchTileEnter(a,b){for(var c=0;c<mar.world.tiles.length;c++){var d=mar.world.tiles[c].tileX,f=mar.world.tiles[c].tileY;mar.world.tiles[c].isWall&&(d===a&&f-1===b||d-1===a&&f-1===b||d-1===a&&f===b)&&game.add.tween(mar.world.tiles[c]).to({alpha:.6},300,Phaser.Easing.Quadratic.In,!0)}}
function Word(a){var b=this;b.tiles=[];b.objects=[];setupWorldArrows();this.setTerrain=function(a){for(var d=0;d<WORLD_HEIGHT;d++)for(var c=0;c<WORLD_HEIGHT;c++){var e=a[c*WORLD_WIDTH+d];if(1===e)e=game.add.isoSprite(getIsoX(d),getIsoY(c),0,"sheet","tiles/bigTile",isoGroup),e.baseZ=0,e.baseTint=colorScheme.wallTint,e.anchor.set(.5,.2),e.isWall=!0;else{if(2===e)e=game.add.isoSprite(getIsoX(d),getIsoY(c),0,"sheet","tiles/tile",isoGroup),g=game.make.text(0,16,"Iron",{fontSize:22,fill:"#434341",stroke:"#FFFFFF",
strokeThickness:1,font:"fixedsys"}),g.alpha=.6,g.anchor.set(.5,0),e.addChild(g),e.baseZ=0,e.baseTint=15987699;else if(3===e){e=game.add.isoSprite(getIsoX(d),getIsoY(c),0,"sheet","tiles/tile",isoGroup);var g=game.make.text(0,16,"Copper",{fontSize:22,fill:"#C87D38",stroke:"#FFFFFF",strokeThickness:1,font:"fixedsys"});g.alpha=.6;g.anchor.set(.5,0);e.addChild(g);e.baseZ=0;e.baseTint=15987699}else e=game.add.isoSprite(getIsoX(d),getIsoY(c),0,"sheet","tiles/tile",isoGroup),e.baseZ=0,e.baseTint=colorScheme.tileTint;
e.anchor.set(.5,0)}e.isTile=!0;e.tileX=d;e.tileY=c;e.tint=e.baseTint;b.tiles.push(e)}};this.setTerrain(a);this.update=function(a){for(var b=0;b<mar.world.objects.length;b++)mar.world.objects[b].destroy();for(b=0;b<mar.world.tiles.length;b++)mar.world.tiles[b].destroy();mar.world.objects=[];mar.world.tiles=[];this.setTerrain(a);game.iso.topologicalSort(isoGroup)};this.getObject=function(a){for(var d=0;d<b.objects.length;d++)if(b.objects[d].id===a)return b.objects[d];return null};this.updateObjects=
function(a){for(d=0;d<b.objects.length;d++)b.objects[d].updated=!1;for(var d=0;d<a.length;d++){var c=b.getObject(a[d].i);null!==c?(c.updated=!0,updateGameObject(c,a[d])):(c=createGameObject(a[d]),c.updated=!0,b.objects.push(c))}for(d=0;d<b.objects.length;d++)b.objects[d].updated||("guest"!==mar.client.username&&1===b.objects[d].type&&b.objects[d].username===mar.client.username&&(findMyRobot(),console.log("Following Cubot "+mar.client.username)),b.objects[d].destroy(),dispatchTileLeave(b.objects[d].tileX,
b.objects[d].tileY),b.objects.splice(d,1))}}
function updateGameObject(a,b){a.direction=b.direction;if(1===a.type){a.action=b.action;a.energy=b.energy;if(a.tileX!==b.x||a.tileY!==b.y)dispatchTileLeave(a.tileX,a.tileY),a.tileX=b.x,a.tileY=b.y,cubotWalk(a,a.direction,void 0,CUBOT_WALK_FRAMES);a.heldItem!==b.heldItem&&(void 0!==a.inventory&&a.inventory.destroy(),a.inventory=createInventory([b.heldItem]),a.addChild(a.inventory),a.heldItem=b.heldItem);a.tint!==colorScheme.cubotHoverTint&&(a.tint=a.energy<=LOW_ENERGY?16711680:16777215);switch(a.direction){case DIR_NORTH:a.animations.frame=
194;break;case DIR_EAST:a.animations.frame=164;break;case DIR_SOUTH:a.animations.frame=240;break;case DIR_WEST:a.animations.frame=254}void 0!==a.hologram&&a.hologram.destroy();var c=!1;b.holoC&&(c="#"+Number(b.holoC&16777215).toString(16));1===b.holoMode?(a.hologram=game.make.text(0,32,"0x"+("0000"+Number(b.holo).toString(16).toUpperCase()).slice(-4),{fontSize:32,fill:c?c:colorScheme.hologramFill,stroke:colorScheme.hologramStroke,strokeThickness:1,font:"fixedsys"}),console.log(Number(c).toString(16))):
2===b.holoMode?a.hologram=game.make.text(0,32,b.holoStr,{fontSize:27,fill:c?c:colorScheme.hologramFill,stroke:colorScheme.hologramStroke,strokeThickness:1,font:"fixedsys"}):3===b.holoMode&&(a.hologram=game.make.text(0,32,Number(b.holo).toString(),{fontSize:32,fill:c?c:colorScheme.hologramFill,stroke:colorScheme.hologramStroke,strokeThickness:1,font:"fixedsys"}));void 0!==a.hologram&&(a.hologram.alpha=colorScheme.hologramAlpha,a.hologram.anchor.set(.5,0),a.addChild(a.hologram),game.add.tween(a.hologram).to({tint:16777200,
alpha:colorScheme.hologramAlpha-.1},mar.client.tickLength,Phaser.Easing.Bounce.In,!0));1===a.action&&cubotDig(a,a.direction)}else if(10===a.type){a.action=b.action;if(a.tileX!==b.x||a.tileY!==b.y)dispatchTileLeave(a.tileX,a.tileY),a.tileX=b.x,a.tileY=b.y,cubotWalk(a,a.direction,void 0,HARVESTER_WALK_FRAMES);switch(a.direction){case DIR_NORTH:a.animations.frame=HARVESTER_WALK_FRAMES.north;break;case DIR_EAST:a.animations.frame=HARVESTER_WALK_FRAMES.east;break;case DIR_SOUTH:a.animations.frame=HARVESTER_WALK_FRAMES.south;
break;case DIR_WEST:a.animations.frame=HARVESTER_WALK_FRAMES.west}}}function itemColor(a){switch(a){case 1:return colorScheme.biomassTint;case 3:return colorScheme.itemIron;case 4:return colorScheme.itemCopper}}
function createInventory(a){var b=game.make.group();switch(a.length){case 0:return b;case 1:if(0!==a[0]){var c=game.make.sprite(0,0,"sheet","inventory/inv1x1");c.anchor.set(.5,.1);c.alpha=.5;var d=game.make.sprite(0,0,"sheet","inventory/item");d.anchor.set(.5,.1);d.tint=itemColor(a[0]);b.addChild(c);b.addChild(d)}return b}for(b=0;b<a.length;b++);}
function createGameObject(a){if(1===a.t){var b=game.add.isoSprite(getIsoX(a.x),getIsoY(a.y),15,"sheet",null,isoGroup);b.anchor.set(.5,0);b.inputEnabled=!0;b.events.onInputDown.add(function(){debugObj="Cubot: "+b.tileX+", "+b.tileY});b.events.onInputOver.add(function(){document.body.style.cursor="pointer"});b.events.onInputOut.add(function(){document.body.style.cursor="default"});b.id=a.i;b.type=1;b.tileX=a.x;b.tileY=a.y;b.username=a.parent;b.heldItem=a.heldItem;b.direction=a.direction;b.action=a.action;
b.energy=a.energy;b.inventory=createInventory([b.heldItem]);b.addChild(b.inventory);dispatchTileEnter(a.x,a.y);b.isAt=function(a,b){return this.tileX===a&&this.tileY===b};b.onTileHover=function(){game.add.tween(this).to({isoZ:45},200,Phaser.Easing.Quadratic.InOut,!0);game.add.tween(this.scale).to({x:1.2,y:1.2},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.cubotHoverTint};b.onTileOut=function(){document.body.style.cursor="default";game.add.tween(this).to({isoZ:15},400,Phaser.Easing.Bounce.Out,
!0);game.add.tween(this.scale).to({x:1,y:1},200,Phaser.Easing.Linear.None,!0);this.tint=16777215};b.energy<=LOW_ENERGY&&(b.tint=13369344);b.animations.add("walk_w",mar.animationFrames.walk_w,!0);b.animations.add("walk_s",mar.animationFrames.walk_s,!0);b.animations.add("walk_e",mar.animationFrames.walk_e,!0);b.animations.add("walk_n",mar.animationFrames.walk_n,!0);b.animations.add("dig_w",mar.animationFrames.dig_w,!1);b.animations.add("dig_s",mar.animationFrames.dig_s,!1);b.animations.add("dig_e",
mar.animationFrames.dig_e,!1);b.animations.add("dig_n",mar.animationFrames.dig_n,!1);b.queuedAnims=[];switch(b.direction){case DIR_NORTH:b.animations.frame=194;break;case DIR_EAST:b.animations.frame=164;break;case DIR_SOUTH:b.animations.frame=240;break;case DIR_WEST:b.animations.frame=254}a=game.make.text(0,-24,b.username,{fontSize:22,fill:colorScheme.textFill,stroke:colorScheme.textStroke,strokeThickness:2,font:"fixedsys"});a.alpha=.85;a.anchor.set(.5,0);b.username===mar.client.username?a.tint=16469258:
b.alpha=.6;b.addChild(a);return b}if(2===a.t){var c=game.add.isoSprite(getIsoX(a.x),getIsoY(a.y),10,"sheet",1,isoGroup);c.animations.add("idle",mar.animationFrames.biomassIdle,!0);c.anchor.set(.5,0);c.type=2;c.tileX=a.x;c.tileY=a.y;c.id=a.i;c.tint=colorScheme.biomassTint;c.hoverText=game.make.text(0,0,"Biomass",{fontSize:22,fill:colorScheme.textFill,stroke:colorScheme.textStroke,strokeThickness:2,font:"fixedsys"});c.hoverText.alpha=0;c.hoverText.anchor.set(.5,0);c.addChild(c.hoverText);c.isAt=function(a,
b){return this.tileX===a&&this.tileY===b};c.isAt=function(a,b){return this.tileX===a&&this.tileY===b};c.onTileHover=function(){game.tweens.removeFrom(this);document.body.style.cursor="pointer";game.add.tween(this).to({isoZ:45},200,Phaser.Easing.Quadratic.InOut,!0);this.tint=colorScheme.biomassHoverTint;game.add.tween(this.scale).to({x:1.2,y:1.2},200,Phaser.Easing.Linear.None,!0);game.add.tween(this.hoverText).to({alpha:.9},200,Phaser.Easing.Quadratic.In,!0);c.hoverText.visible=!0};c.onTileOut=function(){game.tweens.removeFrom(this);
document.body.style.cursor="default";game.add.tween(this).to({isoZ:15},400,Phaser.Easing.Bounce.Out,!0);game.add.tween(this.scale).to({x:1,y:1},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.biomassTint;game.add.tween(this.hoverText).to({alpha:0},200,Phaser.Easing.Quadratic.Out,!0)};c.animations.play("idle",45,!0);return c}if(10===a.t){var d=game.add.isoSprite(getIsoX(a.x),getIsoY(a.y),15,"sheet",null,isoGroup);d.anchor.set(.5,0);d.id=a.i;d.type=10;d.tileX=a.x;d.tileY=a.y;d.direction=a.direction;
d.action=a.action;dispatchTileEnter(a.x,a.y);d.isAt=function(a,b){return this.tileX===a&&this.tileY===b};d.onTileHover=function(){game.add.tween(this).to({isoZ:45},200,Phaser.Easing.Quadratic.InOut,!0);game.add.tween(this.scale).to({x:1.2,y:1.2},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.cubotHoverTint};d.onTileOut=function(){game.add.tween(this).to({isoZ:15},400,Phaser.Easing.Bounce.Out,!0);game.add.tween(this.scale).to({x:1,y:1},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.cubotTint};
d.animations.add("walk_w",mar.animationFrames.harvester_walk_w,!0);d.animations.add("walk_s",mar.animationFrames.harvester_walk_s,!0);d.animations.add("walk_e",mar.animationFrames.harvester_walk_e,!0);d.animations.add("walk_n",mar.animationFrames.harvester_walk_n,!0);d.queuedAnims=[];switch(d.direction){case DIR_NORTH:d.animations.frame=HARVESTER_WALK_FRAMES.north;break;case DIR_EAST:d.animations.frame=HARVESTER_WALK_FRAMES.east;break;case DIR_SOUTH:d.animations.frame=HARVESTER_WALK_FRAMES.south;
break;case DIR_WEST:d.animations.frame=HARVESTER_WALK_FRAMES.west}return d}if(3===a.t){var f=game.add.isoSprite(getIsoX(a.x),getIsoY(a.y),15,"sheet","objects/factory",isoGroup);f.anchor.set(.5,.25);f.id=a.i;f.type=3;f.tileX=a.x;f.tileY=a.y;f.hoverText=game.make.text(0,0,"Factory",{fontSize:22,fill:colorScheme.textFill,stroke:colorScheme.textStroke,strokeThickness:2,font:"fixedsys"});f.hoverText.alpha=0;f.hoverText.anchor.set(.5,0);f.addChild(f.hoverText);f.isAt=function(a,b){return(this.tileX===a||
this.tileX+1===a)&&(this.tileY+1===b||this.tileY===b)};f.onTileHover=function(){game.tweens.removeFrom(this);game.add.tween(this).to({isoZ:25},200,Phaser.Easing.Quadratic.InOut,!0);game.add.tween(this.scale).to({x:1.06,y:1.06},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.cubotHoverTint;game.add.tween(this.hoverText).to({alpha:.9},200,Phaser.Easing.Quadratic.In,!0);f.hoverText.visible=!0};f.onTileOut=function(){game.tweens.removeFrom(this);game.add.tween(this).to({isoZ:15},400,Phaser.Easing.Bounce.Out,
!0);game.add.tween(this.scale).to({x:1,y:1},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.cubotTint;game.add.tween(this.hoverText).to({alpha:0},200,Phaser.Easing.Quadratic.Out,!0)};return f}if(4===a.t){var e=game.add.isoSprite(getIsoX(a.x),getIsoY(a.y),15,"sheet","objects/RadioTower",isoGroup);e.anchor.set(.5,.64);e.id=a.i;e.type=4;e.tileX=a.x;e.tileY=a.y;e.hoverText=game.make.text(0,0,"Radio Tower",{fontSize:22,fill:colorScheme.textFill,stroke:colorScheme.textStroke,strokeThickness:2,font:"fixedsys"});
e.hoverText.alpha=0;e.hoverText.anchor.set(.5,0);e.addChild(e.hoverText);e.isAt=function(a,b){return this.tileX===a&&this.tileY===b};e.onTileHover=function(){game.tweens.removeFrom(this);game.add.tween(this).to({isoZ:45},200,Phaser.Easing.Quadratic.InOut,!0);game.add.tween(this.scale).to({x:1.15,y:1.15},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.cubotHoverTint;game.add.tween(this.hoverText).to({alpha:.9},200,Phaser.Easing.Quadratic.In,!0);e.hoverText.visible=!0};e.onTileOut=function(){game.tweens.removeFrom(this);
game.add.tween(this).to({isoZ:15},400,Phaser.Easing.Bounce.Out,!0);game.add.tween(this.scale).to({x:1,y:1},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.cubotTint;game.add.tween(this.hoverText).to({alpha:0},200,Phaser.Easing.Quadratic.Out,!0)};return e}}function manhanttanDistance(a,b,c,d){return Math.abs(a-c)+Math.abs(b-d)}function codeListener(a){"code"===a.t&&ace.edit("editor").setValue(a.code)}
function authListener(a){"auth"===a.t&&("ok"===a.m?(console.log("Auth successful"),mar.client.requestUserInfo()):alert("Authentication failed. Please make sure you are logged in and reload the page."))}function codeResponseListener(a){"codeResponse"===a.t&&alert("Uploaded and assembled "+a.bytes+" bytes")}function userInfoListener(a){"userInfo"===a.t&&(console.log(a),mar.worldX=a.worldX,mar.worldY=a.worldY,mar.maxWidth=a.maxWidth,mar.client.requestTerrain())}
function terrainListener(a){"terrain"===a.t&&(void 0!==mar.world?(mar.client.socket.send(JSON.stringify({t:"object",x:mar.worldX,y:mar.worldY})),mar.world.update(a.terrain)):(mar.world=new Word(a.terrain),console.log("Gameloop started"),game.input.keyboard.onDownCallback=function(a){document.activeElement===document.getElementById("game")&&((37<=a.keyCode&&40>=a.keyCode||116===a.keyCode||32===a.keyCode)&&a.preventDefault(),"guest"!==mar.client.username&&16>=mar.kbBuffer.length&&(mar.client.sendKeypress(a.keyCode),
mar.kbBuffer.push(a.keyCode),mar.kbBufferText=formattedKeyBuffer(mar.kbBuffer)))},game.input.onDown.add(function(){document.getElementById("game").focus()})))}function objectListener(a){"object"===a.t&&mar.world.updateObjects(a.objects)}function floppyListener(a){document.getElementById("floppyDown").innerHTML='<i class="fa fa-long-arrow-down" aria-hidden="true"></i> <i class="fa fa-floppy-o" aria-hidden="true"></i>';a=new Blob([a.data],{type:"application/octet-stream"});saveAs(a,"floppy.bin")}
function tickListener(a){if("tick"===a.t){mar.client.socket.send(JSON.stringify({t:"object",x:mar.worldX,y:mar.worldY}));void 0!==a.keys&&(mar.kbBuffer=a.keys,mar.kbBufferText=formattedKeyBuffer(mar.kbBuffer));var b=document.getElementById("console");0===a.cm&&(b.innerHTML="",mar.lastLines="");if(void 0!==a.c){for(var c=mar.lastLines,d=0;d<a.c.length;d++)c+=a.c[d];a=b.innerHTML="";var f=c.split("\n");for(d=0;d<f.length;d++)if(40<=f[d].length)for(var e=f[d].match(/.{1,40}/g),g=0;g<e.length;g++)g!==
e.length-1&&(a+="\n");else a+=f[d]+"\n";b.innerHTML=a;mar.lastLines=c;b.scrollTop=b.scrollHeight}}}
var GameClient=function(a){var b=this,c=[],d=new XMLHttpRequest;d.open("GET","./getServerInfo.php",!0);d.onreadystatechange=function(){4===d.readyState&&200===d.status&&(console.log("Received server info "+d.responseText),setTimeout(function(){var f=JSON.parse(d.responseText);console.log(f.address);b.socket=new WebSocket(f.address);b.username=f.username;b.tickLength=f.tickLength;b.serverName=f.serverName;mar.client.socket.binaryType="arraybuffer";b.socket.onopen=function(){b.socket.send(f.token);
c.push(authListener);c.push(userInfoListener);c.push(terrainListener);c.push(tickListener);c.push(objectListener);c.push(codeListener);c.push(codeResponseListener);mar.client.socket.onmessage=function(a){try{var b=JSON.parse(a.data)}catch(h){console.log(h),floppyListener(a)}for(a=0;a<c.length;a++)c[a](b)};b.reloadCode();void 0!==a&&a()};b.socket.onerror=function(a){alert("Can't connect to game server at address "+f.address);console.log(a)};b.socket.onclose=function(a){alert("Disconnected from server");
console.log(a)}},100))};d.send(null);this.requestUserInfo=function(){this.socket.send(JSON.stringify({t:"userInfo"}))};this.requestTerrain=function(){this.socket.send(JSON.stringify({t:"terrain",x:mar.worldX,y:mar.worldY}))};this.uploadCode=function(a){console.log("Uploaded code");this.socket.send(JSON.stringify({t:"uploadCode",code:a}))};this.reloadCode=function(){this.socket.send(JSON.stringify({t:"codeRequest"}))};this.sendKeypress=function(a){0!==a&&this.socket.send(JSON.stringify({t:"k",k:a}))};
this.requestFloppy=function(){document.getElementById("floppyDown").innerHTML='<i class="fa fa-cog fa-spin fa-fw"></i>';this.socket.send(JSON.stringify({t:"floppyDown"}))};this.notifyFloppyUp=function(){this.socket.send(JSON.stringify({t:"floppyUp"}))}};function dispatchTileHover(a,b){for(var c in mar.world.objects){var d=mar.world.objects[c];if(d.isAt(a,b))d.onTileHover()}}function dispatchTileOut(a,b){for(var c in mar.world.objects){var d=mar.world.objects[c];if(d.isAt(a,b))d.onTileOut()}}
var count=0,BasicGame=function(a){};BasicGame.Boot=function(a){};var isoGroup,cursorPos,cursor,debugTile,debugObj,objectsGroup,cursors,tmpLine;
BasicGame.Boot.prototype={preload:function(){game.load.atlasJSONHash("sheet","./mar/sprites.png","./mar/sprites.json");game.time.advancedTiming=!0;game.plugins.add(new Phaser.Plugin.Isometric(game));game.iso.anchor.setTo(.5,0);game.world.setBounds(0,0,2200,1100);game.camera.x=280;game.camera.y=90;game.stage.disableVisibilityChange=!0},create:function(){isoGroup=game.add.group();objectsGroup=game.add.group();initialiseAnimations();this.spawnTiles();cursorPos=new Phaser.Plugin.Isometric.Point3;cursors=
game.input.keyboard.createCursorKeys()},update:function(){game.iso.unproject(game.input.activePointer.position,cursorPos);isoGroup.forEach(function(a){if(a.isTile){var b=a.isoBounds.containsXY(cursorPos.x,cursorPos.y);!a.selected&&b?(a.selected=!0,a.tint=colorScheme.tileHoverTint,debugTile=a.tileX+", "+a.tileY,dispatchTileHover(a.tileX,a.tileY),game.add.tween(a).to({isoZ:a.baseZ+8},200,Phaser.Easing.Quadratic.InOut,!0)):a.selected&&!b&&(dispatchTileOut(a.tileX,a.tileY),a.selected=!1,a.tint=a.baseTint,
game.add.tween(a).to({isoZ:a.baseZ},200,Phaser.Easing.Quadratic.InOut,!0))}});this.game.input.activePointer.isDown?(this.game.origDragPoint&&(this.game.camera.x+=this.game.origDragPoint.x-this.game.input.activePointer.position.x,this.game.camera.y+=this.game.origDragPoint.y-this.game.input.activePointer.position.y),this.game.origDragPoint=this.game.input.activePointer.position.clone()):this.game.origDragPoint=null;count++;0===count%10&&game.iso.topologicalSort(isoGroup)},render:function(){void 0!==
mar.worldX?game.debug.text("World: ("+Number(mar.worldX).toString(16)+", "+Number(mar.worldY).toString(16)+")",10,20):game.debug.text("World: (?,?)",10,20);debugTile&&game.debug.text(debugTile,10,40);"guest"!==mar.client.username&&game.debug.text(mar.kbBufferText,210,20);void 0!==tmpLine&&(game.debug.geom(tmpLine),game.debug.lineInfo(tmpLine,32,32))},spawnTiles:function(){mar.client=new GameClient}};
function setupWorldArrows(){var a=game.make.isoSprite(528,-10,10,"sheet","ui/arrow_north",isoGroup);a.inputEnabled=!0;a.events.onInputDown.add(function(){0===mar.worldY?mar.worldY=mar.maxWidth:mar.worldY--;mar.client.requestTerrain()});a.events.onInputOver.add(function(){a.tint=65280;document.body.style.cursor="pointer"});a.events.onInputOut.add(function(){a.tint=16777215;document.body.style.cursor="default"});isoGroup.addChild(a);var b=game.make.isoSprite(1115,587,10,"sheet","ui/arrow_east",isoGroup);
b.inputEnabled=!0;b.events.onInputDown.add(function(){mar.worldX===mar.maxWidth?mar.worldX=0:mar.worldX++;mar.client.requestTerrain()});b.events.onInputOver.add(function(){b.tint=65280;document.body.style.cursor="pointer"});b.events.onInputOut.add(function(){b.tint=16777215;document.body.style.cursor="default"});isoGroup.addChild(b);var c=game.make.isoSprite(528,1170,10,"sheet","ui/arrow_south",isoGroup);c.inputEnabled=!0;c.events.onInputDown.add(function(){mar.worldY===mar.maxWidth?mar.worldY=0:
mar.worldY++;mar.client.requestTerrain()});c.events.onInputOver.add(function(){c.tint=65280;document.body.style.cursor="pointer"});c.events.onInputOut.add(function(){c.tint=16777215;document.body.style.cursor="default"});isoGroup.addChild(c);var d=game.make.isoSprite(-60,587,10,"sheet","ui/arrow_west",isoGroup);d.inputEnabled=!0;d.events.onInputDown.add(function(){0===mar.worldX?mar.worldX=mar.maxWidth:mar.worldX--;mar.client.requestTerrain()});d.events.onInputOver.add(function(){d.tint=65280;document.body.style.cursor=
"pointer"});d.events.onInputOut.add(function(){d.tint=16777215;document.body.style.cursor="default"});isoGroup.addChild(d)}function cubotDig(a,b,c){b===DIR_NORTH?a.animations.play("dig_n",45):b===DIR_EAST?a.animations.play("dig_e",45):b===DIR_SOUTH?a.animations.play("dig_s",45):b===DIR_WEST&&a.animations.play("dig_w",45)}
function cubotWalk(a,b,c,d){var f;if(b===DIR_SOUTH)var e=function(b){a.animations.play("walk_s",60,!0);f=game.add.tween(a).to({isoX:getIsoX(a.tileX),isoY:getIsoY(a.tileY)},b,Phaser.Easing.Linear.None,!0);dispatchTileEnter(a.tileX,a.tileY);f.onComplete.add(function(){a.animations.stop();a.animations.frame=d.south;a.onTileOut();a.isoX=getIsoX(a.tileX);a.isoY=getIsoY(a.tileY);void 0!==c&&c();for(var b=0;b<a.queuedAnims.length;b++)a.queuedAnims[b](500),a.queuedAnims.splice(b,1)})};else b===DIR_NORTH?
e=function(b){a.animations.play("walk_n",60,!0);f=game.add.tween(a).to({isoX:getIsoX(a.tileX),isoY:getIsoY(a.tileY)},b,Phaser.Easing.Linear.None,!0);dispatchTileEnter(a.tileX,a.tileY);f.onComplete.add(function(){a.animations.stop();a.animations.frame=d.north;a.onTileOut();a.isoX=getIsoX(a.tileX);a.isoY=getIsoY(a.tileY);void 0!==c&&c();for(var b=0;b<a.queuedAnims.length;b++)a.queuedAnims[b](500),a.queuedAnims.splice(b,1)})}:b===DIR_WEST?e=function(b){a.animations.play("walk_w",60,!0);f=game.add.tween(a).to({isoX:getIsoX(a.tileX),
isoY:getIsoY(a.tileY)},b,Phaser.Easing.Linear.None,!0);dispatchTileEnter(a.tileX,a.tileY);f.onComplete.add(function(){a.animations.stop();a.animations.frame=d.west;a.onTileOut();a.isoX=getIsoX(a.tileX);a.isoY=getIsoY(a.tileY);void 0!==c&&c();for(var b=0;b<a.queuedAnims.length;b++)a.queuedAnims[b](500),a.queuedAnims.splice(b,1)})}:b===DIR_EAST&&(e=function(b){a.animations.play("walk_e",60,!0);f=game.add.tween(a).to({isoX:getIsoX(a.tileX),isoY:getIsoY(a.tileY)},b,Phaser.Easing.Linear.None,!0);dispatchTileEnter(a.tileX,
a.tileY);f.onComplete.add(function(){a.animations.stop();a.animations.frame=d.east;a.onTileOut();a.isoX=getIsoX(a.tileX);a.isoY=getIsoY(a.tileY);void 0!==c&&c();for(var b=0;b<a.queuedAnims.length;b++)a.queuedAnims[b](500),a.queuedAnims.splice(b,1)})});a.animations.currentAnim.isPlaying?(a.queuedAnims.push(e),console.log("Queued Animation")):e(800)}
function initialiseAnimations(){mar.animationFrames.walk_e_start=[];for(var a=0;10>a;a++)mar.animationFrames.walk_e_start.push("cubot/walk_e/"+("0000"+a).slice(-4));mar.animationFrames.walk_e=[];for(a=10;30>a;a++)mar.animationFrames.walk_e.push("cubot/walk_e/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_e_start=[];for(a=0;10>a;a++)mar.animationFrames.harvester_walk_e_start.push("harvester/walk_e/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_e=[];for(a=10;30>a;a++)mar.animationFrames.harvester_walk_e.push("harvester/walk_e/"+
("0000"+a).slice(-4));mar.animationFrames.walk_n_start=[];for(a=0;10>a;a++)mar.animationFrames.walk_n_start.push("cubot/walk_n/"+("0000"+a).slice(-4));mar.animationFrames.walk_n=[];for(a=10;30>a;a++)mar.animationFrames.walk_n.push("cubot/walk_n/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_n_start=[];for(a=0;10>a;a++)mar.animationFrames.harvester_walk_n_start.push("harvester/walk_n/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_n=[];for(a=10;30>a;a++)mar.animationFrames.harvester_walk_n.push("harvester/walk_n/"+
("0000"+a).slice(-4));mar.animationFrames.walk_s_start=[];for(a=0;10>a;a++)mar.animationFrames.walk_s_start.push("cubot/walk_s/"+("0000"+a).slice(-4));mar.animationFrames.walk_s=[];for(a=10;30>a;a++)mar.animationFrames.walk_s.push("cubot/walk_s/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_s_start=[];for(a=0;10>a;a++)mar.animationFrames.harvester_walk_s_start.push("harvester/walk_s/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_s=[];for(a=10;30>a;a++)mar.animationFrames.harvester_walk_s.push("harvester/walk_s/"+
("0000"+a).slice(-4));mar.animationFrames.walk_w_start=[];for(a=0;10>a;a++)mar.animationFrames.walk_w_start.push("cubot/walk_w/"+("0000"+a).slice(-4));mar.animationFrames.walk_w=[];for(a=10;30>a;a++)mar.animationFrames.walk_w.push("cubot/walk_w/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_w_start=[];for(a=0;10>a;a++)mar.animationFrames.harvester_walk_w_start.push("harvester/walk_w/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_w=[];for(a=10;30>a;a++)mar.animationFrames.harvester_walk_w.push("harvester/walk_w/"+
("0000"+a).slice(-4));mar.animationFrames.dig_e=[];for(a=1;41>=a;a++)mar.animationFrames.dig_e.push("cubot/dig_e/"+("0000"+a).slice(-4));mar.animationFrames.dig_n=[];for(a=1;41>=a;a++)mar.animationFrames.dig_n.push("cubot/dig_n/"+("0000"+a).slice(-4));mar.animationFrames.dig_s=[];for(a=1;41>=a;a++)mar.animationFrames.dig_s.push("cubot/dig_s/"+("0000"+a).slice(-4));mar.animationFrames.dig_w=[];for(a=1;41>=a;a++)mar.animationFrames.dig_w.push("cubot/dig_w/"+("0000"+a).slice(-4));mar.animationFrames.biomassIdle=
[];for(a=1;60>a;a++)mar.animationFrames.biomassIdle.push("objects/biomass/idle/"+("0000"+a).slice(-4))}function getIsoX(a){return 71.5*a}function getIsoY(a){return 71.5*a}function findMyRobot(){"guest"===mar.client.username?alert("You are not logged in!"):mar.client.requestUserInfo()}function formattedKeyBuffer(a){for(var b="KB: ",c=0;16>c;c++)b=void 0!==a[c]?b+(a[c].toString(16)+" "):b+"__ ";return b}game.state.add("Boot",BasicGame.Boot);game.state.start("Boot");
var RENDERER_WIDTH=document.getElementById("game").clientWidth*window.devicePixelRatio,RENDERER_HEIGHT=window.innerHeight/1.4*window.devicePixelRatio,DEBUG=!0,config={tileTint:16777215,wallTint:14540253,oreTint:15987699,worldSize:16,cubotHoverTint:65280,cubotTint:16777215,textFill:"#FFFFFF",textStroke:"#9298a8",biomassTint:6535263,biomassHoverTint:65280,tileHoverTint:65280,itemIron:4408129,textIron:"#434341",itemCopper:13139256,textCopper:"#C87D38",hologramFill:"#0aced6",hologramStroke:"#12FFB0",
copperFill:"#C87D38",plainSprite:"tiles/tile",wallSprite:"tiles/bigTile",walkDuration:800,holoStyle:function(a){return{fontSize:32,fill:a?a:config.hologramFill,stroke:config.hologramStroke,strokeThickness:1,font:"fixedsys"}},kbBufferX:225,kbBufferY:20,arrowTextStyle:{fontSize:32,fill:"#ffffff",stroke:"#9298a8",strokeThickness:1,font:"fixedsys"},lowEnergy:100,lowEnergyTint:13369344,bigMessageFill:"#ff803d",arrowTint:16777215,arrowHoverTint:65280,selfUsernameColor:16469258,otherCubotAlpha:.6},TileType;
(function(a){a[a.PLAIN=0]="PLAIN";a[a.WALL=1]="WALL";a[a.IRON=2]="IRON";a[a.COPPER=3]="COPPER"})(TileType||(TileType={}));
var Util=function(){function a(){}a.getIsoY=function(b){return a.getIsoX(b)};a.getIsoX=function(a){return 71.5*a};a.getDeltaX=function(a){switch(a){case Direction.NORTH:case Direction.SOUTH:return 0;case Direction.EAST:return 1;case Direction.WEST:return-1}};a.getDeltaY=function(a){switch(a){case Direction.EAST:case Direction.WEST:return 0;case Direction.NORTH:return 1;case Direction.SOUTH:return-1}};return a}(),mar=new MarGame;

107
mar/phaser/mar.ts Normal file
View File

@ -0,0 +1,107 @@
///<reference path="phaser.plugin.isometric.d.ts"/>
///<reference path="phaser.d.ts"/>
// Typescript V2.4.1
let RENDERER_WIDTH = document.getElementById("game").clientWidth * window.devicePixelRatio;
let RENDERER_HEIGHT = (window.innerHeight / 1.40) * window.devicePixelRatio;
let DEBUG: boolean = true;
let config = {
tileTint: 0xFFFFFF,
wallTint: 0xDDDDDD,
oreTint: 0xF3F3F3,
worldSize: 16,
cubotHoverTint: 0x00FF00,
cubotTint: 0xFFFFFF,
textFill: "#FFFFFF",
textStroke: "#9298a8",
biomassTint: 0x63B85F,
biomassHoverTint: 0x00FF00,
tileHoverTint: 0x00FF00,
itemIron: 0x434341,
textIron: "#434341",
itemCopper: 0xC87D38,
textCopper: "#C87D38",
hologramFill: "#0aced6",
hologramStroke: "#12FFB0",
copperFill: "#C87D38",
plainSprite: "tiles/tile",
wallSprite: "tiles/bigTile",
walkDuration: 800,
holoStyle: (fill) => {
return {
fontSize: 32,
fill: fill ? fill : config.hologramFill,
stroke: config.hologramStroke,
strokeThickness: 1,
font: "fixedsys"
}
},
kbBufferX: 225,
kbBufferY: 20,
arrowTextStyle: {
fontSize: 32,
fill: "#ffffff",
stroke: "#9298a8",
strokeThickness: 1,
font: "fixedsys"
},
lowEnergy: 100,
lowEnergyTint: 0xCC0000,
bigMessageFill: "#ff803d",
arrowTint: 0xFFFFFF,
arrowHoverTint: 0x00FF00,
selfUsernameColor: 0xFB4D0A,
otherCubotAlpha: 0.6
};
enum TileType {
PLAIN,
WALL,
IRON,
COPPER
}
class Util {
//todo: find a more elegant way of doing this. Maybe this is related: https://github.com/lewster32/phaser-plugin-isometric/issues/7
static getIsoY(y: number) {
return Util.getIsoX(y);
}
static getIsoX(x: number) {
return (x * 71.5)
}
static getDeltaX(direction: Direction) {
switch (direction) {
case Direction.NORTH:
case Direction.SOUTH:
return 0;
case Direction.EAST:
return 1;
case Direction.WEST:
return -1;
}
}
static getDeltaY(direction: Direction) {
switch (direction) {
case Direction.EAST:
case Direction.WEST:
return 0;
case Direction.NORTH:
return 1;
case Direction.SOUTH:
return -1;
}
}
}
let mar = new MarGame();

1108
mar/phaser/p2.d.ts vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -725,7 +725,7 @@ Phaser.Plugin.Isometric.IsoSprite = function (game, x, y, z, key, frame) {
Phaser.Sprite.call(this, game, x, y, key, frame);
/**
* @property {number} type - The const type of this object.
* @property {number} objType - The const objType of this object.
* @readonly
*/
this.type = Phaser.Plugin.Isometric.ISOSPRITE;
@ -2009,7 +2009,7 @@ Phaser.Plugin.Isometric.Body = function (sprite) {
this.game = sprite.game;
/**
* @property {number} type - The type of physics system this body belongs to.
* @property {number} objType - The objType of physics system this body belongs to.
*/
this.type = Phaser.Plugin.Isometric.ISOARCADE;
@ -2219,7 +2219,7 @@ Phaser.Plugin.Isometric.Body = function (sprite) {
/**
* This flag allows you to disable the custom x separation that takes place by Physics.IsoArcade.separate.
* Used in combination with your own collision processHandler you can create whatever type of collision response you need.
* Used in combination with your own collision processHandler you can create whatever objType of collision response you need.
* @property {boolean} customSeparateX - Use a custom separation system or the built-in one?
* @default
*/
@ -2227,7 +2227,7 @@ Phaser.Plugin.Isometric.Body = function (sprite) {
/**
* This flag allows you to disable the custom y separation that takes place by Physics.IsoArcade.separate.
* Used in combination with your own collision processHandler you can create whatever type of collision response you need.
* Used in combination with your own collision processHandler you can create whatever objType of collision response you need.
* @property {boolean} customSeparateY - Use a custom separation system or the built-in one?
* @default
*/
@ -2235,7 +2235,7 @@ Phaser.Plugin.Isometric.Body = function (sprite) {
/**
* This flag allows you to disable the custom z separation that takes place by Physics.IsoArcade.separate.
* Used in combination with your own collision processHandler you can create whatever type of collision response you need.
* Used in combination with your own collision processHandler you can create whatever objType of collision response you need.
* @property {boolean} customSeparateZ - Use a custom separation system or the built-in one?
* @default
*/

7685
mar/phaser/phaser.d.ts vendored Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

398
mar/phaser/phaser.plugin.isometric.d.ts vendored Normal file
View File

@ -0,0 +1,398 @@
//debug octreee is missing - Octree
//debug isoSprite is missing - IsoSprite
//gameobjectcreator isoSprite missing - IsoSprite
//gameobjectfactory isoSprite missing - IsoSprite
//debug body missing - Body
//debug bodyInfo missing -Body
declare module Phaser {
interface Physics {
isoArcade: Phaser.Plugin.Isometric.Arcade;
}
}
declare module Phaser.Plugin {
class Isometric extends Phaser.Plugin {
static CLASSIC: number;
static ISOMETRIC: number;
static MILITARY: number;
static VERSION: string;
static UP: number;
static DOWN: number;
static FORWARDX: number;
static FORWARDY: number;
static BACKWARDX: number;
static BACKWARDY: number;
static ISOSPRITE: number;
static ISOARCADE: number;
projector: Phaser.Plugin.Isometric.Projector;
constructor(game: Phaser.Game, parent?: any);
addIsoSprite(x: number, y: number, z: number, key?: any, frame?: any, group?: Phaser.Group): Phaser.Plugin.Isometric.IsoSprite;
}
module Isometric {
class Projector {
game: Phaser.Game;
anchor: Phaser.Point;
projectionAngle: number;
project(point3: Phaser.Plugin.Isometric.Point3, out?: Phaser.Point): Phaser.Point;
projectXY(point3: Phaser.Plugin.Isometric.Point3, out?: Phaser.Point): Phaser.Point;
unproject(point: Phaser.Point, out?: Phaser.Plugin.Isometric.Point3, z?: number): Phaser.Plugin.Isometric.Point3;
simpleSort(group: Phaser.Group): void;
topologicalSort(group: Phaser.Group, padding?: number, prop?: string): void;
}
class Point3 {
static add(a: Phaser.Plugin.Isometric.Point3, b: Phaser.Plugin.Isometric.Point3, out?: Phaser.Plugin.Isometric.Point3): Phaser.Plugin.Isometric.Point3;
static subtract(a: Phaser.Plugin.Isometric.Point3, b: Phaser.Plugin.Isometric.Point3, out?: Phaser.Plugin.Isometric.Point3): Phaser.Plugin.Isometric.Point3;
static multiply(a: Phaser.Plugin.Isometric.Point3, b: Phaser.Plugin.Isometric.Point3, out?: Phaser.Plugin.Isometric.Point3): Phaser.Plugin.Isometric.Point3;
static divide(a: Phaser.Plugin.Isometric.Point3, b: Phaser.Plugin.Isometric.Point3, out?: Phaser.Plugin.Isometric.Point3): Phaser.Plugin.Isometric.Point3;
static equals(a: Phaser.Plugin.Isometric.Point3, b: Phaser.Plugin.Isometric.Point3): boolean;
x: number;
y: number;
z: number;
constructor(x?: number, y?: number, z?: number);
copyFrom(source: any): Phaser.Plugin.Isometric.Point3;
copyto(dest: any): any;
equals(a: any): boolean;
set(x?: number, y?: number, z?: number): Phaser.Plugin.Isometric.Point3;
setTo(x?: number, y?: number, z?: number): Phaser.Plugin.Isometric.Point3;
add(x?: number, y?: number): Phaser.Plugin.Isometric.Point3;
subtract(x?: number, y?: number, z?: number): Phaser.Plugin.Isometric.Point3;
multiply(x?: number, y?: number, z?: number): Phaser.Plugin.Isometric.Point3;
divide(x?: number, y?: number, z?: number): Phaser.Plugin.Isometric.Point3;
containsXY(x?: number, y?: number);
}
class Octree {
maxObjects: number;
maxLevels: number;
level: number;
bounds: any;
objects: any[];
nodes: any[];
constructor(x: number, y: number, z: number, widthX: number, widthY: number, height: number, maxObject?: number, maxLevels?: number, level?: number);
reset(x: number, y: number, z: number, widthX: number, widthY: number, height: number, maxObject?: number, maxLevels?: number, level?: number): void;
populate(group: Phaser.Group): void;
populateHandler(sprite: Phaser.Plugin.Isometric.IsoSprite): void;
populateHandler(sprite: any): void;
split(): void;
insert(body: Phaser.Plugin.Isometric.Body): void;
insert(body: Phaser.Plugin.Isometric.Cube): void;
insert(body: any): void;
getIndex(cube: Phaser.Plugin.Isometric.Cube): number;
getIndex(cube: any): number;
retrieve(source: Phaser.Plugin.Isometric.IsoSprite): any[];
retrieve(source: Phaser.Plugin.Isometric.Cube): any[];
clear(): void;
}
class IsoSprite extends Phaser.Sprite {
snap: number;
isoX: number;
isoY: number;
isoZ: number;
isoPosition: Phaser.Plugin.Isometric.Point3;
isoBounds: Phaser.Plugin.Isometric.Point3;
depth: number;
constructor(game: Phaser.Game, x: number, y: number, z: number, key?: any, frame?: any);
resetIsoBounds(): void;
}
class Cube {
static size(a: Phaser.Plugin.Isometric.Cube, output?: Phaser.Plugin.Isometric.Point3): Phaser.Plugin.Isometric.Point3;
static clone(a: Phaser.Plugin.Isometric.Cube, output?: Phaser.Plugin.Isometric.Cube): Phaser.Plugin.Isometric.Cube;
static contains(a: Phaser.Plugin.Isometric.Cube, x: number, y: number, z: number): boolean;
static containsXY(a: Phaser.Plugin.Isometric.Cube, x: number, y: number): boolean;
static containsPoint3(a: Phaser.Plugin.Isometric.Cube, point3: Phaser.Plugin.Isometric.Point3): boolean;
static containsCube(a: Phaser.Plugin.Isometric.Cube, b: Phaser.Plugin.Isometric.Cube): boolean;
static intersects(a: Phaser.Plugin.Isometric.Cube, b: Phaser.Plugin.Isometric.Cube): boolean;
x: number;
y: number;
z: number;
widthX: number;
widthY: number;
height: number;
halfWidthX: number;
halfWidthY: number;
halfHeight: number;
bottom: number;
top: number;
backX: number;
backY: number;
frontX: number;
frontY: number;
volume: number;
centerX: number;
centerY: number;
centerZ: number;
randomX: number;
randomY: number;
randomZ: number;
empty: boolean;
constructor(x?: number, y?: number, z?: number, widthX?: number, widthY?: number, height?: number);
setTo(x?: number, y?: number, z?: number, widthX?: number, widthY?: number, height?: number): Phaser.Plugin.Isometric.Cube;
copyFrom(source: any): Phaser.Plugin.Isometric.Cube;
copyTo(dest: any): Phaser.Plugin.Isometric.Cube;
size(output?: Phaser.Plugin.Isometric.Point3): Phaser.Plugin.Isometric.Point3;
contains(x: number, y: number, z: number): boolean;
containsXY(x: number, y: number): boolean;
clone(output?: Phaser.Plugin.Isometric.Cube): Phaser.Plugin.Isometric.Cube;
intersects(b: Phaser.Plugin.Isometric.Cube): boolean;
getCorners(): Phaser.Plugin.Isometric.Point3[];
toString(): string;
}
class Body {
static render(context: any, body: Phaser.Plugin.Isometric.Body, color?: string, filled?: boolean): void;
static renderBodyInfo(debug: any, body: Phaser.Plugin.Isometric.Body): void; //togo debug?
sprite: Phaser.Plugin.Isometric.IsoSprite;
game: Phaser.Game;
type: number;
enable: boolean;
offset: Phaser.Plugin.Isometric.Point3;
position: Phaser.Plugin.Isometric.Point3;
prev: Phaser.Plugin.Isometric.Point3;
allowRotation: boolean;
rotation: number;
preRotation: number;
sourceWidthX: number;
sourceWidthY: number;
sourceHeight: number;
widthX: number;
widthY: number;
height: number;
halfWidthX: number;
halfWidthY: number;
halfHeight: number;
center: Phaser.Plugin.Isometric.Point3;
velocity: Phaser.Plugin.Isometric.Point3;
newVelocity: Phaser.Plugin.Isometric.Point3;
deltaMax: Phaser.Plugin.Isometric.Point3;
acceleration: Phaser.Plugin.Isometric.Point3;
drag: Phaser.Plugin.Isometric.Point3;
allowGravity: boolean;
gravity: Phaser.Plugin.Isometric.Point3;
bounce: Phaser.Plugin.Isometric.Point3;
maxVelocity: Phaser.Plugin.Isometric.Point3;
angularVelocity: number;
angularAcceleration: number;
angularDrag: number;
maxAngular: number;
mass: number;
angle: number;
speed: number;
facing: number;
immovable: boolean;
moves: boolean;
customSeparateX: boolean;
customSeparateY: boolean;
customSeparateZ: boolean;
overlapX: number;
overlapY: number;
overlayZ: number;
embedded: boolean;
collideWorldBounds: boolean;
checkCollision: {
none: boolean;
any: boolean;
up: boolean;
down: boolean;
frontX: number;
frontY: number;
backX: number;
backY: number;
};
touching: {
none: boolean;
up: boolean;
down: boolean;
frontX: number;
frontY: number;
backX: number;
backY: number;
};
wasTouching: {
none: boolean;
up: boolean;
down: boolean;
frontX: number;
frontY: number;
backX: number;
backY: number;
};
blocked: {
up: boolean;
down: boolean;
frontX: number;
frontY: number;
backX: number;
backY: number;
};
phase: number;
skipTree: boolean;
top: number;
frontX: number;
right: number;
frontY: number;
bottom: number;
x: number;
y: number;
z: number;
constructor(sprite: Phaser.Plugin.Isometric.IsoSprite);
destroy(): void;
setSize(widthX: number, widthY: number, height: number, offsetX?: number, offsetY?: number, offsetZ?: number): void;
reset(x: number, y: number, z: number): void;
hitText(x: number, y: number, z: number): boolean;
onFloor(): boolean;
onWall(): boolean;
deltaAbsX(): number;
deltaAbsY(): number;
deltaAbsZ(): number;
deltaX(): number;
deltaY(): number;
deltaZ(): number;
deltaR(): number;
getCorners(): Phaser.Plugin.Isometric.Point3[];
}
class Arcade {
game: Phaser.Game;
gravity: Phaser.Plugin.Isometric.Point3;
bounds: Phaser.Plugin.Isometric.Cube;
checkCollision: {
up: boolean;
down: boolean;
frontX: boolean;
frontY: boolean;
backX: boolean;
backY: boolean;
};
maxObjects: number;
maxLevels: number;
OVERLAP_BIAS: number;
forceXY: boolean;
skipTree: boolean;
useQuadTree: boolean;
quadTree: Phaser.QuadTree;
octree: Phaser.Plugin.Isometric.Octree;
constructor(game: Phaser.Game);
setBounds(x: number, y: number, z: number, widthX: number, widthY: number, height: number): void;
setBoundsToWorld(): void;
enable(object: any, children?: boolean): void;
enableBody(object: any): void;
updateMotion(body: Phaser.Plugin.Isometric.Body): void;
computeVelocity(axis: number, body: Phaser.Plugin.Isometric.Body, velocity: number, acceleration: number, drag: number, max?: number): number;
overlap(object1: any, object2: any, overlapCallback?: Function, processCallback?: Function, callbackContext?: any): boolean;
collide(object1: any, object2: any, overlapCallback?: Function, processCallback?: Function, callbackContext?: any): boolean;
intersects(body1: Phaser.Plugin.Isometric.Body): boolean;
distanceBetween(source: any, target: any): number;
distanceToXY(displayObject: any, x: number, y: number): number;
distanceToXYZ(displayObject: any, x: number, y: number, z: number): number;
}
}
}

1060
mar/phaser/pixi.d.ts vendored Normal file

File diff suppressed because it is too large Load Diff

14
mar/phaser/tsconfig.json Normal file
View File

@ -0,0 +1,14 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"sourceMap": true
},
"exclude": [
"node_modules"
],
"files": [
"phaser.d.ts",
"phaser.plugin.isometric.d.ts"
]
}

View File

@ -4536,6 +4536,30 @@
"spriteSourceSize": {"x":0,"y":0,"w":102,"h":51},
"sourceSize": {"w":102,"h":51},
"pivot": {"x":0.5,"y":0.5}
},
"ui/compass": {
"frame": {
"x": 3007,
"y": 1050,
"w": 162,
"h": 147
},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 162,
"h": 147
},
"sourceSize": {
"w": 162,
"h": 147
},
"pivot": {
"x": 0.5,
"y": 0.5
}
}},
"meta": {
"app": "http://www.codeandweb.com/texturepacker",
@ -4547,6 +4571,6 @@
"h": 1260
},
"scale": "1",
"smartupdate": "$TexturePacker:SmartUpdate:9033aea0c9a897c0ef813d508f6a34d4:37c604a593bacba7edbc1e4826db2c6e:1eabdf11f75e3a4fe3147baf7b5be24b$"
"smartupdate": "$TexturePacker:SmartUpdate:835d7c25db29ec00ac3f7d1149b0c1b7:cbc42bcb32195696aea0af5d3a226408:1eabdf11f75e3a4fe3147baf7b5be24b$"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 589 KiB

After

Width:  |  Height:  |  Size: 589 KiB