mirror of
https://github.com/simon987/Much-Assembly-Required-Frontend.git
synced 2025-12-14 07:09:06 +00:00
Initial commit
This commit is contained in:
19384
mar/ace/ace.js
Executable file
19384
mar/ace/ace.js
Executable file
File diff suppressed because it is too large
Load Diff
118
mar/ace/mode-mar.js
Executable file
118
mar/ace/mode-mar.js
Executable file
@@ -0,0 +1,118 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Distributed under the BSD license:
|
||||
*
|
||||
* Copyright (c) 2012, Ajax.org B.V.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Ajax.org B.V. nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/* This file was autogenerated from Assembly x86.tmLanguage (uuid: ) */
|
||||
/****************************************************************************************
|
||||
* IT MIGHT NOT BE PERFECT ...But it's a good start from an existing *.tmlanguage file. *
|
||||
* fileTypes *
|
||||
****************************************************************************************/
|
||||
define("ace/mode/mar_rules", ["require", "exports", "module", "ace/lib/oop", "ace/mode/text_highlight_rules"], function (require, exports, module) {
|
||||
"use strict";
|
||||
|
||||
var oop = require("../lib/oop");
|
||||
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
|
||||
|
||||
var MarHighlightRules = function () {
|
||||
// regexp must not have capturing parentheses. Use (?:) instead.
|
||||
// regexps are ordered -> the first match is used
|
||||
|
||||
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: true
|
||||
},
|
||||
{
|
||||
token: 'keyword.operator.assembly',
|
||||
regex: '\\b(?:call|ret|jmp|jnz|jg|jl|jge|jle|hwi|jz|js|jns|jc|jnc)\\b',
|
||||
caseInsensitive: true
|
||||
},
|
||||
{
|
||||
token: 'variable.predefined.ahk',
|
||||
regex: '\\b(?:brk|dup)\\b',
|
||||
caseInsensitive: true
|
||||
},
|
||||
{
|
||||
token: 'variable.parameter.register.assembly',
|
||||
regex: '\\b(?:A|B|C|D|X|Y|bp|sp)\\b',
|
||||
caseInsensitive: true
|
||||
},
|
||||
{
|
||||
token: 'constant.character.decimal.assembly',
|
||||
regex: '\\b[0-9]+\\b'
|
||||
},
|
||||
{
|
||||
token: 'constant.character.hexadecimal.assembly',
|
||||
regex: '\\b0x[A-F0-9]+\\b',
|
||||
caseInsensitive: true
|
||||
},
|
||||
{token: 'string.assembly', regex: /'([^\\']|\\.)*'/},
|
||||
{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();
|
||||
};
|
||||
|
||||
MarHighlightRules.metaData = {
|
||||
fileTypes: ['asm'],
|
||||
name: 'Much Assembly Required',
|
||||
scopeName: 'source.assembly'
|
||||
};
|
||||
|
||||
|
||||
oop.inherits(MarHighlightRules, TextHighlightRules);
|
||||
|
||||
exports.MarHighlightRules = MarHighlightRules;
|
||||
});
|
||||
|
||||
define("ace/mode/mar", ["require", "exports", "module", "ace/lib/oop", "ace/mode/text", "ace/mode/mar_rules"], function (require, exports, module) {
|
||||
"use strict";
|
||||
|
||||
var oop = require("../lib/oop");
|
||||
var TextMode = require("./text").Mode;
|
||||
var MarHighlightRules = require("./mar_rules").MarHighlightRules;
|
||||
|
||||
var Mode = function () {
|
||||
this.HighlightRules = MarHighlightRules;
|
||||
this.$behaviour = this.$defaultBehaviour;
|
||||
};
|
||||
oop.inherits(Mode, TextMode);
|
||||
|
||||
(function () {
|
||||
this.lineCommentStart = ";";
|
||||
this.$id = "ace/mode/mar";
|
||||
}).call(Mode.prototype);
|
||||
|
||||
exports.Mode = Mode;
|
||||
});
|
||||
4
mar/ace/mode-mar.min.js
vendored
Normal file
4
mar/ace/mode-mar.min.js
vendored
Normal file
@@ -0,0 +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:"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});
|
||||
108
mar/ace/theme-tomorrow.js
Executable file
108
mar/ace/theme-tomorrow.js
Executable file
@@ -0,0 +1,108 @@
|
||||
define("ace/theme/tomorrow", ["require", "exports", "module", "ace/lib/dom"], function (require, exports, module) {
|
||||
|
||||
exports.isDark = false;
|
||||
exports.cssClass = "ace-tomorrow";
|
||||
exports.cssText = ".ace-tomorrow .ace_gutter {\
|
||||
background: #f6f6f6;\
|
||||
color: #4D4D4C\
|
||||
}\
|
||||
.ace-tomorrow .ace_print-margin {\
|
||||
width: 1px;\
|
||||
background: #f6f6f6\
|
||||
}\
|
||||
.ace-tomorrow {\
|
||||
background-color: #FFFFFF;\
|
||||
color: #4D4D4C\
|
||||
}\
|
||||
.ace-tomorrow .ace_cursor {\
|
||||
color: #AEAFAD\
|
||||
}\
|
||||
.ace-tomorrow .ace_marker-layer .ace_selection {\
|
||||
background: #D6D6D6\
|
||||
}\
|
||||
.ace-tomorrow.ace_multiselect .ace_selection.ace_start {\
|
||||
box-shadow: 0 0 3px 0px #FFFFFF;\
|
||||
}\
|
||||
.ace-tomorrow .ace_marker-layer .ace_step {\
|
||||
background: rgb(255, 255, 0)\
|
||||
}\
|
||||
.ace-tomorrow .ace_marker-layer .ace_bracket {\
|
||||
margin: -1px 0 0 -1px;\
|
||||
border: 1px solid #D1D1D1\
|
||||
}\
|
||||
.ace-tomorrow .ace_marker-layer .ace_active-line {\
|
||||
background: #EFEFEF\
|
||||
}\
|
||||
.ace-tomorrow .ace_gutter-active-line {\
|
||||
background-color : #dcdcdc\
|
||||
}\
|
||||
.ace-tomorrow .ace_marker-layer .ace_selected-word {\
|
||||
border: 1px solid #D6D6D6\
|
||||
}\
|
||||
.ace-tomorrow .ace_invisible {\
|
||||
color: #D1D1D1\
|
||||
}\
|
||||
.ace-tomorrow .ace_keyword,\
|
||||
.ace-tomorrow .ace_meta,\
|
||||
.ace-tomorrow .ace_storage,\
|
||||
.ace-tomorrow .ace_storage.ace_type,\
|
||||
.ace-tomorrow .ace_support.ace_type {\
|
||||
color: #8959A8\
|
||||
}\
|
||||
.ace-tomorrow .ace_keyword.ace_operator {\
|
||||
color: #3E999F\
|
||||
}\
|
||||
.ace-tomorrow .ace_constant.ace_character,\
|
||||
.ace-tomorrow .ace_constant.ace_language,\
|
||||
.ace-tomorrow .ace_constant.ace_numeric,\
|
||||
.ace-tomorrow .ace_keyword.ace_other.ace_unit,\
|
||||
.ace-tomorrow .ace_support.ace_constant,\
|
||||
.ace-tomorrow .ace_variable.ace_parameter {\
|
||||
color: #F5871F\
|
||||
}\
|
||||
.ace-tomorrow .ace_constant.ace_other {\
|
||||
color: #666969\
|
||||
}\
|
||||
.ace-tomorrow .ace_invalid {\
|
||||
color: #FFFFFF;\
|
||||
background-color: #C82829\
|
||||
}\
|
||||
.ace-tomorrow .ace_invalid.ace_deprecated {\
|
||||
color: #FFFFFF;\
|
||||
background-color: #8959A8\
|
||||
}\
|
||||
.ace-tomorrow .ace_fold {\
|
||||
background-color: #4271AE;\
|
||||
border-color: #4D4D4C\
|
||||
}\
|
||||
.ace-tomorrow .ace_entity.ace_name.ace_function,\
|
||||
.ace-tomorrow .ace_support.ace_function,\
|
||||
.ace-tomorrow .ace_variable {\
|
||||
color: #4271AE\
|
||||
}\
|
||||
.ace-tomorrow .ace_support.ace_class,\
|
||||
.ace-tomorrow .ace_support.ace_type {\
|
||||
color: #C99E00\
|
||||
}\
|
||||
.ace-tomorrow .ace_heading,\
|
||||
.ace-tomorrow .ace_markup.ace_heading,\
|
||||
.ace-tomorrow .ace_string {\
|
||||
color: #718C00\
|
||||
}\
|
||||
.ace-tomorrow .ace_entity.ace_name.ace_tag,\
|
||||
.ace-tomorrow .ace_entity.ace_other.ace_attribute-name,\
|
||||
.ace-tomorrow .ace_meta.ace_tag,\
|
||||
.ace-tomorrow .ace_string.ace_regexp,\
|
||||
.ace-tomorrow .ace_variable {\
|
||||
color: #C82829\
|
||||
}\
|
||||
.ace-tomorrow .ace_comment {\
|
||||
color: #8E908C\
|
||||
}\
|
||||
.ace-tomorrow .ace_indent-guide {\
|
||||
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAE0lEQVQImWP4////f4bdu3f/BwAlfgctduB85QAAAABJRU5ErkJggg==) right repeat-y\
|
||||
}";
|
||||
|
||||
var dom = require("../lib/dom");
|
||||
dom.importCssString(exports.cssText, exports.cssClass);
|
||||
});
|
||||
406
mar/editor.js
Normal file
406
mar/editor.js
Normal file
@@ -0,0 +1,406 @@
|
||||
OPERAND_INVALID = -1;
|
||||
OPERAND_REG = 0;
|
||||
OPERAND_MEM_IMM = 1;
|
||||
OPERAND_MEM_REG = 2;
|
||||
OPERAND_IMM = 3;
|
||||
|
||||
|
||||
//Remove default syntax checker
|
||||
editor = ace.edit("editor");
|
||||
editor.session.setOption("useWorker", false);
|
||||
|
||||
//Remove message
|
||||
editor.$blockScrolling = Infinity;
|
||||
|
||||
|
||||
function removeComment(line) {
|
||||
if (line.indexOf(";") !== -1) {
|
||||
|
||||
return line.substring(0, line.indexOf(";"));
|
||||
|
||||
} else {
|
||||
return line;
|
||||
}
|
||||
}
|
||||
|
||||
function checkForLabel(line, result) {
|
||||
line = removeComment(line);
|
||||
|
||||
if (line.indexOf(":") !== -1) {
|
||||
|
||||
line = line.substring(0, line.indexOf(":"));
|
||||
|
||||
result.labels.push(line.trim());
|
||||
}
|
||||
}
|
||||
|
||||
function checkForSegmentDeclaration(line) {
|
||||
|
||||
var tokens = getTokens(line);
|
||||
|
||||
return tokens[0] !== undefined && (tokens[0].toLowerCase() === ".data" || tokens[0].toLowerCase() === ".text");
|
||||
|
||||
}
|
||||
|
||||
function checkForEQUInstruction(line, result, currentLine) {
|
||||
|
||||
var tokens = getTokens(line);
|
||||
|
||||
|
||||
if (line.toLowerCase().indexOf(" equ ") !== -1 || tokens[1] !== undefined && tokens[1].toLowerCase() === "equ") {
|
||||
//Save as a label
|
||||
var num = Number(tokens[2]);
|
||||
if (!isNaN(num) && num === Math.floor(num)) {
|
||||
result.labels.push(tokens[0]);
|
||||
return true;
|
||||
} else {
|
||||
result.annotations.push({
|
||||
row: currentLine,
|
||||
column: 0,
|
||||
text: "Usage: constant_name EQU immediate_value",
|
||||
type: "error"
|
||||
});
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function getTokens(line) {
|
||||
|
||||
var tokens = line.split(/\s+/);
|
||||
|
||||
for (var i = 0; i < tokens.length; i++) {
|
||||
if (tokens[i] === "") {
|
||||
tokens.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return tokens;
|
||||
}
|
||||
|
||||
function removeLabel(line) {
|
||||
if (line.indexOf(':') !== -1) {
|
||||
return line.substring(line.indexOf(':') + 1);
|
||||
} else {
|
||||
return line;
|
||||
}
|
||||
}
|
||||
|
||||
function checkForORGInstruction(line, result, currentLine) {
|
||||
line = removeComment(line);
|
||||
line = removeLabel(line);
|
||||
|
||||
//Split string
|
||||
var tokens = getTokens(line);
|
||||
var mnemonic = tokens[0];
|
||||
|
||||
if (mnemonic !== undefined && mnemonic.toLowerCase() === "org") {
|
||||
|
||||
console.log(tokens);
|
||||
|
||||
if (tokens.length > 1) {
|
||||
|
||||
var num = Number(tokens[1]);
|
||||
if (!isNaN(num) && num === Math.floor(num)) {
|
||||
return true;
|
||||
} else {
|
||||
result.annotations.push({
|
||||
row: currentLine,
|
||||
column: 0,
|
||||
text: "Invalid operand: " + tokens[1],
|
||||
type: "error"
|
||||
});
|
||||
return true
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function parseDWInstruction(line, result, currentLine) {
|
||||
line = line.trim();
|
||||
|
||||
|
||||
if (line.substr(0, 2).toLowerCase() === "dw") {
|
||||
|
||||
|
||||
var values = line.substr(2, line.length).split(",");
|
||||
|
||||
|
||||
for (var i = 0; i < values.length; i++) {
|
||||
|
||||
values[i] = values[i].trim();
|
||||
var tokens = getTokens(values[i]);
|
||||
|
||||
if (tokens.length === 2 && getOperandType(tokens[0], result) === OPERAND_IMM &&
|
||||
tokens[1].toLowerCase().startsWith("dup(") && tokens[1].endsWith(")") &&
|
||||
getOperandType(tokens[1].substring(4, tokens[1].indexOf(")")), result) === OPERAND_IMM) {
|
||||
|
||||
// console.log("DUp");
|
||||
|
||||
} else if (getOperandType(values[i], result) === OPERAND_IMM) {
|
||||
|
||||
// console.log("is Imm " + values[i]);
|
||||
|
||||
} else {
|
||||
|
||||
result.annotations.push({
|
||||
row: currentLine,
|
||||
column: 0,
|
||||
text: "Usage: DW IMM, IMM ...",
|
||||
type: "error"
|
||||
});
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function getOperandType(text, result) {
|
||||
|
||||
text = text.trim();
|
||||
if (text === "") {
|
||||
return OPERAND_INVALID;
|
||||
}
|
||||
|
||||
//Check IMM
|
||||
if (!isNaN(Number(text)) && Number(text) === Math.floor(Number(text))) {
|
||||
return OPERAND_IMM;
|
||||
}
|
||||
|
||||
//Check REG
|
||||
if (new RegExp('^(a|b|c|d|x|y|bp|sp)$').test(text.toLowerCase())) {
|
||||
return OPERAND_REG;
|
||||
}
|
||||
|
||||
//Check Label
|
||||
for (i = 0; i < result.labels.length; i++) {
|
||||
if (text === result.labels[i]) {
|
||||
return OPERAND_IMM;
|
||||
}
|
||||
}
|
||||
|
||||
//Check MEM_*
|
||||
if (text.startsWith("[") && text.endsWith("]")) {
|
||||
text = text.replace("[", "").replace("]", "");
|
||||
|
||||
//Check MEM_IMM
|
||||
if (!isNaN(Number(text)) && Number(text) === Math.floor(Number(text))) {
|
||||
return OPERAND_MEM_IMM;
|
||||
}
|
||||
//Check MEM_Label
|
||||
for (var i = 0; i < result.labels.length; i++) {
|
||||
if (text === result.labels[i]) {
|
||||
return OPERAND_MEM_IMM;
|
||||
}
|
||||
}
|
||||
|
||||
//Check for MEM_REG (+ x)
|
||||
var expr = "";
|
||||
if (new RegExp('^(bp|sp)$').test(text.toLowerCase().substring(0, 2).toLowerCase())) {
|
||||
//Starts with 2-char register
|
||||
expr = text.substring(2);
|
||||
} else if (new RegExp('^(a|b|c|d|x|y)$').test(text.toLowerCase().substring(0, 1).toLowerCase())) {
|
||||
//Starts with 1-char register
|
||||
expr = text.substring(1);
|
||||
} else {
|
||||
return OPERAND_INVALID;
|
||||
}
|
||||
|
||||
|
||||
if (expr.replace(/\s+/g, '') === "") {
|
||||
//No displacement specified
|
||||
return OPERAND_MEM_REG;
|
||||
}
|
||||
|
||||
//Remove white space
|
||||
expr = expr.replace(/\s+/g, '');
|
||||
//expr should now look like this: '+1' '-3' '+0x02' '+myLabel'
|
||||
|
||||
//Check for label
|
||||
for (i = 0; i < result.labels.length; i++) {
|
||||
if (expr.substring(1) === result.labels[i]) {
|
||||
return OPERAND_MEM_REG;
|
||||
}
|
||||
}
|
||||
//Check for number
|
||||
if (!isNaN(Number(expr)) && Number(expr) === Math.floor(Number(expr))) {
|
||||
return OPERAND_MEM_REG;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return OPERAND_INVALID;
|
||||
|
||||
}
|
||||
|
||||
function parseInstruction(line, result, currentLine) {
|
||||
line = removeComment(line);
|
||||
line = removeLabel(line);
|
||||
|
||||
var tokens = getTokens(line);
|
||||
var mnemonic = tokens[0];
|
||||
|
||||
if (mnemonic === undefined || mnemonic === "") {
|
||||
return; //Line is empty
|
||||
}
|
||||
|
||||
|
||||
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)\\b').test(mnemonic.toLowerCase())) {
|
||||
|
||||
|
||||
if (line.indexOf(",") !== -1) {
|
||||
//2 Operands
|
||||
var strO1 = line.substring(line.indexOf(mnemonic) + mnemonic.length, line.indexOf(','));
|
||||
var strO2 = line.substring(line.indexOf(',') + 1).trim();
|
||||
|
||||
|
||||
//Validate operand number
|
||||
if (!new RegExp('\\b(?:mov|add|sub|and|or|test|cmp|shl|shr|xor|rol|ror|sal|sar)\\b').test(mnemonic.toLowerCase())) {
|
||||
result.annotations.push({
|
||||
row: currentLine,
|
||||
column: 0,
|
||||
text: mnemonic + " instruction with 2 operands is illegal",
|
||||
type: "error"
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
//Validate operand type
|
||||
var o1Type = getOperandType(strO1, result);
|
||||
var o2Type = getOperandType(strO2, result);
|
||||
if (o1Type === OPERAND_INVALID) {
|
||||
result.annotations.push({
|
||||
row: currentLine,
|
||||
column: 0,
|
||||
text: "Invalid operand: " + strO1,
|
||||
type: "error"
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (o2Type === OPERAND_INVALID) {
|
||||
result.annotations.push({
|
||||
row: currentLine,
|
||||
column: 0,
|
||||
text: "Invalid operand: " + strO2,
|
||||
type: "error"
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
//Check for illegal operand combos:
|
||||
if (o1Type === OPERAND_IMM) {
|
||||
result.annotations.push({
|
||||
row: currentLine,
|
||||
column: 0,
|
||||
text: "Destination operand can't be an immediate value",
|
||||
type: "error"
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
} else if (tokens.length > 1) {
|
||||
//1 Operand
|
||||
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)\\b').test(mnemonic.toLowerCase())) {
|
||||
result.annotations.push({
|
||||
row: currentLine,
|
||||
column: 0,
|
||||
text: mnemonic + " instruction with 1 operand is illegal",
|
||||
type: "error"
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
//Validate operand type
|
||||
if (getOperandType(strO1, result) === OPERAND_INVALID) {
|
||||
result.annotations.push({
|
||||
row: currentLine,
|
||||
column: 0,
|
||||
text: "Invalid operand: " + strO1,
|
||||
type: "error"
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
//No operand
|
||||
if (!new RegExp('\\b(?:ret|brk|nop)\\b').test(mnemonic.toLowerCase())) {
|
||||
|
||||
//Validate operand number
|
||||
result.annotations.push({
|
||||
row: currentLine,
|
||||
column: 0,
|
||||
text: mnemonic + " instruction with no operand is illegal",
|
||||
type: "error"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
result.annotations.push({
|
||||
row: currentLine,
|
||||
column: 0,
|
||||
text: "Unknown mnemonic: " + mnemonic,
|
||||
type: "error"
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function parse() {
|
||||
|
||||
var text = ace.edit("editor").getValue();
|
||||
var lines = text.split("\n");
|
||||
var result = {
|
||||
labels: [],
|
||||
annotations: []
|
||||
};
|
||||
|
||||
//Pass 1 of 2: Save label names
|
||||
for (var currentLine = 0; currentLine < lines.length; currentLine++) {
|
||||
checkForLabel(lines[currentLine], result);
|
||||
}
|
||||
|
||||
|
||||
//Pass 2 of 2: Check instructions
|
||||
for (currentLine = 0; currentLine < lines.length; currentLine++) {
|
||||
|
||||
if (!checkForSegmentDeclaration(lines[currentLine]) &&
|
||||
!checkForEQUInstruction(lines[currentLine], result, currentLine) &&
|
||||
!checkForORGInstruction(lines[currentLine], result, currentLine)) {
|
||||
|
||||
parseInstruction(lines[currentLine], result, currentLine);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Set icons
|
||||
editor.getSession().setAnnotations(result.annotations);
|
||||
}
|
||||
|
||||
function gameClick() {
|
||||
document.getElementById("editorBtns").setAttribute("style", "display: none")
|
||||
}
|
||||
|
||||
function editorClick() {
|
||||
document.getElementById("editorBtns").setAttribute("style", "")
|
||||
}
|
||||
|
||||
editor.on("change", parse);
|
||||
16
mar/editor.min.js
vendored
Normal file
16
mar/editor.min.js
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.checkStringArgs=function(a,c,b){if(null==a)throw new TypeError("The 'this' value for String.prototype."+b+" must not be null or undefined");if(c instanceof RegExp)throw new TypeError("First argument to String.prototype."+b+" must not be a regular expression");return a+""};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;
|
||||
$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(a,c,b){a!=Array.prototype&&a!=Object.prototype&&(a[c]=b.value)};$jscomp.getGlobal=function(a){return"undefined"!=typeof window&&window===a?a:"undefined"!=typeof global&&null!=global?global:a};$jscomp.global=$jscomp.getGlobal(this);
|
||||
$jscomp.polyfill=function(a,c,b,d){if(c){b=$jscomp.global;a=a.split(".");for(d=0;d<a.length-1;d++){var e=a[d];e in b||(b[e]={});b=b[e]}a=a[a.length-1];d=b[a];c=c(d);c!=d&&null!=c&&$jscomp.defineProperty(b,a,{configurable:!0,writable:!0,value:c})}};
|
||||
$jscomp.polyfill("String.prototype.startsWith",function(a){return a?a:function(a,b){var c=$jscomp.checkStringArgs(this,a,"startsWith");a+="";var e=c.length,f=a.length;b=Math.max(0,Math.min(b|0,c.length));for(var g=0;g<f&&b<e;)if(c[b++]!=a[g++])return!1;return g>=f}},"es6","es3");
|
||||
$jscomp.polyfill("String.prototype.endsWith",function(a){return a?a:function(a,b){var c=$jscomp.checkStringArgs(this,a,"endsWith");a+="";void 0===b&&(b=c.length);b=Math.max(0,Math.min(b|0,c.length));for(var e=a.length;0<e&&0<b;)if(c[--b]!=a[--e])return!1;return 0>=e}},"es6","es3");OPERAND_INVALID=-1;OPERAND_REG=0;OPERAND_MEM_IMM=1;OPERAND_MEM_REG=2;OPERAND_IMM=3;editor=ace.edit("editor");editor.session.setOption("useWorker",!1);editor.$blockScrolling=Infinity;
|
||||
function removeComment(a){return-1!==a.indexOf(";")?a.substring(0,a.indexOf(";")):a}function checkForLabel(a,c){a=removeComment(a);-1!==a.indexOf(":")&&(a=a.substring(0,a.indexOf(":")),c.labels.push(a.trim()))}function checkForSegmentDeclaration(a){a=getTokens(a);return void 0!==a[0]&&(".data"===a[0].toLowerCase()||".text"===a[0].toLowerCase())}
|
||||
function checkForEQUInstruction(a,c,b){var d=getTokens(a);return-1!==a.toLowerCase().indexOf(" equ ")||void 0!==d[1]&&"equ"===d[1].toLowerCase()?(a=Number(d[2]),isNaN(a)||a!==Math.floor(a)?c.annotations.push({row:b,column:0,text:"Usage: constant_name EQU immediate_value",type:"error"}):c.labels.push(d[0]),!0):!1}function getTokens(a){a=a.split(/\s+/);for(var c=0;c<a.length;c++)""===a[c]&&a.splice(c,1);return a}function removeLabel(a){return-1!==a.indexOf(":")?a.substring(a.indexOf(":")+1):a}
|
||||
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(",");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||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)))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)\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)\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")}
|
||||
function editorClick(){document.getElementById("editorBtns").setAttribute("style","")}editor.on("change",parse);
|
||||
BIN
mar/fonts/C64_Pro_Mono-STYLE.ttf
Normal file
BIN
mar/fonts/C64_Pro_Mono-STYLE.ttf
Normal file
Binary file not shown.
BIN
mar/fonts/FSEX301-L2.ttf
Executable file
BIN
mar/fonts/FSEX301-L2.ttf
Executable file
Binary file not shown.
34
mar/game.css
Executable file
34
mar/game.css
Executable file
@@ -0,0 +1,34 @@
|
||||
|
||||
@font-face {
|
||||
font-family: 'fixedsys';
|
||||
src: url("./fonts/FSEX301-L2.ttf");
|
||||
}
|
||||
|
||||
.container {
|
||||
width: 1600px;
|
||||
}
|
||||
|
||||
#game {
|
||||
box-shadow: rgba(46, 94, 134, 0.45) 10px 10px 3px;
|
||||
margin-top: 1em;
|
||||
outline: none;
|
||||
/*background: #282828;*/
|
||||
}
|
||||
|
||||
#editor {
|
||||
margin-top: 1em;
|
||||
height: 650px;
|
||||
box-shadow: rgba(46, 94, 134, 0.45) 10px 10px 3px;
|
||||
|
||||
}
|
||||
|
||||
#graphContainer {
|
||||
height: 500px;
|
||||
width: 500px;
|
||||
}
|
||||
|
||||
.ace_gutter-cell.ace_error {
|
||||
background-image: url("sprites/err_annotation.png") !important;
|
||||
background-position: 2px center;
|
||||
}
|
||||
|
||||
101
mar/old/Game.js
Normal file
101
mar/old/Game.js
Normal file
@@ -0,0 +1,101 @@
|
||||
|
||||
fullscreen = false;
|
||||
|
||||
|
||||
function gameLoop() {
|
||||
requestAnimationFrame(gameLoop);
|
||||
|
||||
for(var i in game.world.objects){
|
||||
|
||||
if(game.world.objects[i]){
|
||||
game.world.objects[i].update();
|
||||
}
|
||||
}
|
||||
|
||||
game.worldLayer.children.sort(depthCompare);
|
||||
|
||||
game.renderer.render(game.rootContainer);
|
||||
|
||||
}
|
||||
|
||||
function Game(){
|
||||
|
||||
var world;
|
||||
var worldX;
|
||||
var worldY;
|
||||
var self = this;
|
||||
|
||||
this.calculateBounds = function(){
|
||||
|
||||
if (fullscreen) {
|
||||
self.RENDERER_WIDTH = window.innerWidth - 4;
|
||||
self.RENDERER_HEIGHT = window.innerHeight - 4;
|
||||
} else {
|
||||
self.RENDERER_WIDTH = document.getElementById("game").clientWidth;
|
||||
self.RENDERER_HEIGHT = (window.innerHeight / 1.25);
|
||||
}
|
||||
};
|
||||
|
||||
//Setup renderer
|
||||
this.calculateBounds();
|
||||
|
||||
this.renderer = PIXI.autoDetectRenderer(256, 256);
|
||||
document.getElementById("game").appendChild(this.renderer.view);
|
||||
|
||||
this.rootContainer = new PIXI.Container();
|
||||
this.renderer.backgroundColor = 0x282828;
|
||||
this.renderer.resize(this.RENDERER_WIDTH, this.RENDERER_HEIGHT);
|
||||
|
||||
window.onresize = function () {
|
||||
|
||||
self.calculateBounds();
|
||||
self.renderer.resize(self.RENDERER_WIDTH, self.RENDERER_HEIGHT);
|
||||
};
|
||||
|
||||
//SETUP BACKGROUND LAYER & PANNING
|
||||
this.bgLayer = new PIXI.Container();
|
||||
this.rootContainer.addChildAt(this.bgLayer, 0);
|
||||
this.bg = new PIXI.Sprite();
|
||||
this.bg.interactive = true;
|
||||
this.bg.hitArea = new PIXI.Rectangle(0, 0, this.RENDERER_WIDTH, this.RENDERER_HEIGHT);
|
||||
this.bg.on("pointerdown", function (e) {
|
||||
self.pointerdown = true;
|
||||
self.pointerFirstClick = e.data.getLocalPosition(self.rootContainer);
|
||||
});
|
||||
this.bg.on("pointerup", function () {
|
||||
self.pointerdown = false;
|
||||
self.pointerLastDrag = null;
|
||||
});
|
||||
this.bg.on("pointerupoutside", function () {
|
||||
self.pointerdown = false;
|
||||
self.pointerLastDrag = null;
|
||||
});
|
||||
this.bg.on("pointermove", function (e) {
|
||||
if (self.pointerdown === true) {
|
||||
//Dragging
|
||||
|
||||
var currentMouse = e.data.getLocalPosition(self.rootContainer);
|
||||
|
||||
if (self.pointerLastDrag !== null) {
|
||||
self.worldLayer.position.x += currentMouse.x - self.pointerLastDrag.x;
|
||||
self.worldLayer.position.y += currentMouse.y - self.pointerLastDrag.y;
|
||||
} else {
|
||||
self.worldLayer.position.x += currentMouse.x - self.pointerFirstClick.x;
|
||||
self.worldLayer.position.y += currentMouse.y - self.pointerFirstClick.y;
|
||||
}
|
||||
|
||||
self.pointerLastDrag = currentMouse;
|
||||
}
|
||||
});
|
||||
this.bgLayer.addChild(this.bg);
|
||||
|
||||
|
||||
|
||||
//------------------------------------
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
274
mar/old/GameClient.js
Normal file
274
mar/old/GameClient.js
Normal file
@@ -0,0 +1,274 @@
|
||||
/**
|
||||
* Listens for authentications responses from the server
|
||||
*/
|
||||
function authListener(message){
|
||||
|
||||
if(message.t === "auth"){
|
||||
|
||||
if(message.m === "ok"){
|
||||
console.log("Auth successful");
|
||||
client.requestUserInfo();
|
||||
|
||||
} else {
|
||||
console.log("Auth failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Listens for user info responses from the server
|
||||
*/
|
||||
function userInfoListener(message){
|
||||
if(message.t === "userInfo"){
|
||||
|
||||
game = new Game();
|
||||
game.worldX = message.worldX;
|
||||
game.worldY = message.worldY;
|
||||
|
||||
client.requestTerrain();
|
||||
}
|
||||
}
|
||||
|
||||
function formattedKeyBuffer(kbBuffer) {
|
||||
|
||||
var str = "Keyboard: ";
|
||||
|
||||
for(var i = 0; i < 16; i++){
|
||||
|
||||
if(kbBuffer[i] !== undefined) {
|
||||
|
||||
str += "0x" + kbBuffer[i].toString(16) + " ";
|
||||
|
||||
} else {
|
||||
|
||||
str += "____ ";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return str;
|
||||
|
||||
}
|
||||
|
||||
function terrainListener(message){
|
||||
if(message.t === "terrain"){
|
||||
|
||||
if(game.world !== undefined){
|
||||
|
||||
game.world.update(message.terrain);
|
||||
|
||||
} else {
|
||||
game.world = new Word(message.terrain);
|
||||
|
||||
//Setup keyboard buffer display
|
||||
game.textLayer = new PIXI.Container();
|
||||
game.rootContainer.addChild(game.textLayer);
|
||||
game.kbBuffer = [];
|
||||
|
||||
game.keyboardBuffer = new PIXI.Text(formattedKeyBuffer([]), {fontSize: 16, fontFamily: "fixedsys", fill: "white"});
|
||||
game.textLayer.addChild(game.keyboardBuffer);
|
||||
|
||||
|
||||
//Handle keypresses
|
||||
window.addEventListener('keydown', function(event) {
|
||||
|
||||
if(game.kbBuffer.length <= 16) {
|
||||
|
||||
client.sendKeypress(event.keyCode);
|
||||
|
||||
//Locally update the buffer
|
||||
game.kbBuffer.push(event.keyCode);
|
||||
game.keyboardBuffer.text = formattedKeyBuffer(game.kbBuffer);
|
||||
|
||||
if(event.keyCode >= 37 && event.keyCode <= 40){
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
console.log("Gameloop started");
|
||||
gameLoop();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function tickListener(message){
|
||||
if(message.t === "tick"){
|
||||
//Request objects
|
||||
client.socket.send(JSON.stringify({t: "object", x: game.worldX, y: game.worldY}));
|
||||
|
||||
//Update key buffer display
|
||||
if(game.textLayer){
|
||||
if(message.keys !== undefined){
|
||||
console.log(message.keys);
|
||||
|
||||
game.kbBuffer = message.keys;
|
||||
game.keyboardBuffer.text = formattedKeyBuffer(game.kbBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function objectListener(message){
|
||||
|
||||
if(message.t === "object"){
|
||||
|
||||
game.world.updateObjects(message.objects);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function codeListener(message){
|
||||
|
||||
if(message.t === "code"){
|
||||
|
||||
ace.edit("editor").setValue(message.code);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function GameClient(callback) {
|
||||
|
||||
var self = this;
|
||||
|
||||
var listeners = [];
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.open("GET", "./getServerInfo.php", true);
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||
|
||||
console.log("Received server info " + xhr.responseText);
|
||||
|
||||
setTimeout(function(){
|
||||
var info = JSON.parse(xhr.responseText);
|
||||
|
||||
self.socket = new WebSocket(info.address);
|
||||
self.username = info.username;
|
||||
self.tickLength = info.tickLength;
|
||||
self.serverName = info.serverName;
|
||||
|
||||
|
||||
self.socket.onopen = function () {
|
||||
|
||||
//Send auth request
|
||||
self.socket.send(info.token);
|
||||
|
||||
|
||||
//Setup event managers
|
||||
listeners.push(authListener);
|
||||
listeners.push(userInfoListener);
|
||||
listeners.push(terrainListener);
|
||||
listeners.push(tickListener);
|
||||
listeners.push(objectListener);
|
||||
listeners.push(codeListener);
|
||||
|
||||
client.socket.onmessage = function(e){
|
||||
|
||||
//console.log("Received " + e.data);
|
||||
var message = JSON.parse(e.data);
|
||||
|
||||
for(var i = 0; i < listeners.length ; i++){
|
||||
listeners[i](message);
|
||||
}
|
||||
};
|
||||
|
||||
self.reloadCode();
|
||||
|
||||
|
||||
if(callback !== undefined){
|
||||
callback();
|
||||
}
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
};
|
||||
xhr.send(null);
|
||||
|
||||
|
||||
this.requestUserInfo = function(){
|
||||
this.socket.send(JSON.stringify({t: "userInfo"}));
|
||||
};
|
||||
|
||||
this.requestTerrain = function(){
|
||||
this.socket.send(JSON.stringify({t: "terrain", x: game.worldX, y: game.worldY}));
|
||||
};
|
||||
|
||||
this.uploadCode = function(code){
|
||||
console.log("Uploaded code");
|
||||
this.socket.send(JSON.stringify({t: "uploadCode", code: code}))
|
||||
};
|
||||
|
||||
this.reloadCode = function(){
|
||||
this.socket.send(JSON.stringify({t: "codeRequest"}))
|
||||
};
|
||||
|
||||
this.sendKeypress = function(key){
|
||||
if(key !== 0){
|
||||
this.socket.send(JSON.stringify({t:"k", k:key}));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Change an object's location and initialise the move animation
|
||||
function moveObject(newX, newY, gameObject) {
|
||||
|
||||
//Resync object
|
||||
|
||||
for(clip in gameObject.clips){
|
||||
gameObject.clips[clip].x = (gameObject.x - gameObject.y) * 64;
|
||||
gameObject.clips[clip].y = ((gameObject.x + gameObject.y) * 32) - 16;
|
||||
}
|
||||
|
||||
var tiledx = newX - gameObject.x;
|
||||
var tiledy = newY - gameObject.y;
|
||||
|
||||
gameObject.dx = 0;
|
||||
gameObject.dy = 0;
|
||||
|
||||
//Recalculate position
|
||||
gameObject.x = newX;
|
||||
gameObject.y = newY;
|
||||
|
||||
if (tiledx === 1) {
|
||||
//We need to move 128px to the right and the minimum tick length is 1s.
|
||||
//This means that we have maximum 60 frames to do the animation
|
||||
gameObject.dx = 64 / 58;
|
||||
gameObject.dy = 32 / 58;
|
||||
gameObject.walking = 58;
|
||||
//Recalculate Z order immediately
|
||||
gameObject.sprite.z = gameObject.y + gameObject.x + 0.1;
|
||||
} else if (tiledx === -1) {
|
||||
gameObject.dx = -64 / 58;
|
||||
gameObject.dy = -32 / 58;
|
||||
gameObject.walking = 58;
|
||||
|
||||
//The Z order needs to be recalculated when the movement ends
|
||||
gameObject.recalculateZAfter = true;
|
||||
} else if (tiledy === 1) {
|
||||
gameObject.dx = -64 / 58;
|
||||
gameObject.dy = 32 / 58;
|
||||
gameObject.walking = 58;
|
||||
//Recalculate Z order immediately
|
||||
gameObject.sprite.z = gameObject.y + gameObject.x + 0.1;
|
||||
} else if (tiledy === -1) {
|
||||
gameObject.dx = 64 / 58;
|
||||
gameObject.dy = -32 / 58;
|
||||
gameObject.walking = 58;
|
||||
//The Z order needs to be recalculated when the movement ends
|
||||
gameObject.recalculateZAfter = true;
|
||||
}
|
||||
|
||||
game.worldLayer.children.sort(depthCompare);
|
||||
|
||||
}
|
||||
|
||||
|
||||
363
mar/old/GameObject.js
Normal file
363
mar/old/GameObject.js
Normal file
@@ -0,0 +1,363 @@
|
||||
|
||||
OBJ_CUBOT = 1;
|
||||
OBJ_PLANT = 2;
|
||||
OBJ_KILN = 3;
|
||||
OBJ_DIGESTER = 4;
|
||||
OBJ_ROCKET = 5;
|
||||
|
||||
DIR_NORTH = 0;
|
||||
DIR_EAST = 1;
|
||||
DIR_SOUTH = 2;
|
||||
DIR_WEST = 3;
|
||||
|
||||
ACTION_WALK =2;
|
||||
|
||||
|
||||
|
||||
function getItemTexture(item){
|
||||
|
||||
return PIXI.Texture.fromFrame("objects/plant1_s");
|
||||
|
||||
}
|
||||
|
||||
function getCubotAnimatedSprites(){
|
||||
|
||||
var walk_e = [];
|
||||
var walk_n = [];
|
||||
var walk_s = [];
|
||||
var walk_w = [];
|
||||
var i;
|
||||
|
||||
for(i = 1; i <= 30; i++){
|
||||
walk_e.push(PIXI.Texture.fromFrame("cubot/walk_e/" + ("0000" + i).slice(-4)))
|
||||
}
|
||||
for(i = 1; i <= 30; i++){
|
||||
walk_n.push(PIXI.Texture.fromFrame("cubot/walk_n/" + ("0000" + i).slice(-4)))
|
||||
}
|
||||
for(i = 1; i <= 30; i++){
|
||||
walk_s.push(PIXI.Texture.fromFrame("cubot/walk_s/" + ("0000" + i).slice(-4)))
|
||||
}
|
||||
for(i = 1; i <= 30; i++){
|
||||
walk_w.push(PIXI.Texture.fromFrame("cubot/walk_w/" + ("0000" + i).slice(-4)))
|
||||
}
|
||||
|
||||
var clip_wal_e = new PIXI.extras.AnimatedSprite(walk_e);
|
||||
clip_wal_e.animationSpeed = 0.5;
|
||||
clip_wal_e.onFrameChange = function(){
|
||||
if(this.currentFrame === 29){
|
||||
this.gotoAndPlay(10);
|
||||
}
|
||||
};
|
||||
|
||||
var clip_wal_n = new PIXI.extras.AnimatedSprite(walk_n);
|
||||
clip_wal_n.animationSpeed = 0.5;
|
||||
clip_wal_n.onFrameChange = function(){
|
||||
if(this.currentFrame === 29){
|
||||
this.gotoAndPlay(10);
|
||||
}
|
||||
};
|
||||
var clip_wal_s = new PIXI.extras.AnimatedSprite(walk_s);
|
||||
clip_wal_s.animationSpeed = 0.5;
|
||||
clip_wal_s.onFrameChange = function(){
|
||||
if(this.currentFrame === 29){
|
||||
this.gotoAndPlay(10);
|
||||
}
|
||||
};
|
||||
var clip_wal_w = new PIXI.extras.AnimatedSprite(walk_w);
|
||||
clip_wal_w.animationSpeed = 0.5;
|
||||
clip_wal_w.onFrameChange = function(){
|
||||
if(this.currentFrame === 29){
|
||||
this.gotoAndPlay(10);
|
||||
}
|
||||
};
|
||||
|
||||
var clips = {"walk_e": clip_wal_e,
|
||||
"walk_n":clip_wal_n,
|
||||
"walk_s":clip_wal_s,
|
||||
"walk_w":clip_wal_w};
|
||||
|
||||
return clips;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
function getObjectTexture(obj, selected){
|
||||
|
||||
switch(obj.type){
|
||||
|
||||
case OBJ_CUBOT:
|
||||
//Tortoise
|
||||
if(selected){
|
||||
|
||||
return PIXI.Texture.fromFrame("cubot/walk_w/0001");
|
||||
|
||||
} else {
|
||||
|
||||
switch (obj.direction){
|
||||
case DIR_NORTH:
|
||||
return PIXI.Texture.fromFrame("cubot/walk_n/0001");
|
||||
case DIR_EAST:
|
||||
return PIXI.Texture.fromFrame("cubot/walk_e/0001");
|
||||
case DIR_SOUTH:
|
||||
return PIXI.Texture.fromFrame("cubot/walk_s/0001");
|
||||
case DIR_WEST:
|
||||
return PIXI.Texture.fromFrame("cubot/walk_w/0001");
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case OBJ_PLANT:
|
||||
//Plant
|
||||
if(selected){
|
||||
return PIXI.Texture.fromFrame("objects/plant1_s");
|
||||
} else {
|
||||
return PIXI.Texture.fromFrame("objects/plant1");
|
||||
}
|
||||
case OBJ_KILN:
|
||||
//Kiln
|
||||
if(selected){
|
||||
return PIXI.Texture.fromFrame("objects/kiln_s");
|
||||
} else {
|
||||
return PIXI.Texture.fromFrame("objects/kiln");
|
||||
}
|
||||
case OBJ_DIGESTER:
|
||||
//Digester
|
||||
return PIXI.Texture.fromFrame("objects/digester");
|
||||
case OBJ_ROCKET:
|
||||
//Rocket
|
||||
return PIXI.Texture.fromFrame("objects/rocket");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function getZPosition(type, x, y) {
|
||||
|
||||
switch (type){
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
return x + y + 0.1;
|
||||
case 5:
|
||||
return x + y + + 11.1;
|
||||
}
|
||||
}
|
||||
|
||||
function getXPosition(type, x, y) {
|
||||
|
||||
switch (type){
|
||||
case OBJ_CUBOT:
|
||||
return (x - y) * 64;
|
||||
case OBJ_PLANT:
|
||||
return (x - y) * 64 + 32;
|
||||
case OBJ_KILN:
|
||||
return (x - y) * 64;
|
||||
case OBJ_DIGESTER:
|
||||
return ((x - y) * 64) - 64;
|
||||
case OBJ_ROCKET:
|
||||
return (x - y) * 64;
|
||||
}
|
||||
}
|
||||
|
||||
function getYPosition(type, x, y) {
|
||||
|
||||
switch (type){
|
||||
case OBJ_CUBOT:
|
||||
return ((x + y) * 32) - 8;
|
||||
case OBJ_PLANT:
|
||||
return ((x + y) * 32) - 26;
|
||||
case OBJ_KILN:
|
||||
return ((x + y) * 32) - 58;
|
||||
case OBJ_DIGESTER:
|
||||
return ((x + y) * 32) - 64;
|
||||
case OBJ_ROCKET:
|
||||
return ((x + y) * 32) - 128;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Object an object with the new instance from the server
|
||||
* @param object
|
||||
* @param responseObj
|
||||
*/
|
||||
function updateGameObject(object, responseObj){
|
||||
|
||||
//Update location
|
||||
if (object.x !== responseObj.x || object.y !== responseObj.y) {
|
||||
//location changed
|
||||
moveObject(responseObj.x, responseObj.y, object);
|
||||
}
|
||||
|
||||
//Overwrite object fields
|
||||
for(var key in responseObj){
|
||||
object[key] = responseObj[key];
|
||||
}
|
||||
|
||||
if(object.type === OBJ_CUBOT){
|
||||
|
||||
// object.sprite.x = getXPosition(object.type, object.x, object.y);
|
||||
// object.sprite.y = getYPosition(object.type, object.x, object.y);
|
||||
// object.sprite.z = getZPosition(object.type, object.x, object.y);
|
||||
|
||||
if(object.action === ACTION_WALK){
|
||||
|
||||
//Walking
|
||||
switch (object.direction){
|
||||
case DIR_NORTH:
|
||||
|
||||
object.clips.walk_n.x = object.sprite.x;
|
||||
object.clips.walk_n.y = object.sprite.y;
|
||||
object.clips.walk_n.z = object.sprite.z;
|
||||
|
||||
if(!object.clips.walk_n.visible) {
|
||||
|
||||
object.clips.walk_n.visible = true;
|
||||
object.clips.walk_n.play();
|
||||
object.clips.walk_e.visible = false;
|
||||
object.clips.walk_s.visible = false;
|
||||
object.clips.walk_w.visible = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case DIR_EAST:
|
||||
|
||||
object.clips.walk_e.x = object.sprite.x;
|
||||
object.clips.walk_e.y = object.sprite.y;
|
||||
object.clips.walk_e.z = object.sprite.z;
|
||||
|
||||
if(!object.clips.walk_e.visible){
|
||||
|
||||
object.clips.walk_n.visible = false;
|
||||
object.clips.walk_e.visible = true;
|
||||
object.clips.walk_e.play();
|
||||
object.clips.walk_s.visible = false;
|
||||
object.clips.walk_w.visible = false;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case DIR_SOUTH:
|
||||
|
||||
object.clips.walk_s.x = object.sprite.x;
|
||||
object.clips.walk_s.y = object.sprite.y;
|
||||
object.clips.walk_s.z = object.sprite.z;
|
||||
|
||||
if(!object.clips.walk_s.visible){
|
||||
|
||||
object.clips.walk_n.visible = false;
|
||||
object.clips.walk_e.visible = false;
|
||||
object.clips.walk_s.visible = true;
|
||||
object.clips.walk_s.play();
|
||||
object.clips.walk_w.visible = false;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case DIR_WEST:
|
||||
object.clips.walk_w.x = object.sprite.x;
|
||||
object.clips.walk_w.y = object.sprite.y;
|
||||
object.clips.walk_w.z = object.sprite.z;
|
||||
|
||||
if(!object.clips.walk_s.visible){
|
||||
|
||||
object.clips.walk_n.visible = false;
|
||||
object.clips.walk_e.visible = false;
|
||||
object.clips.walk_s.visible = false;
|
||||
object.clips.walk_w.visible = true;
|
||||
object.clips.walk_w.play();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called each frame
|
||||
*/
|
||||
function update(){
|
||||
|
||||
if (this.walking === undefined) {
|
||||
|
||||
this.walking = 0;
|
||||
} else if (this.walking > 0) {
|
||||
//The object has more walking frames to do
|
||||
for(clip in this.clips){
|
||||
this.clips[clip].x += this.dx;
|
||||
this.clips[clip].y += this.dy;
|
||||
}
|
||||
|
||||
this.walking--;
|
||||
|
||||
if (this.walking === 0 && this.recalculateZAfter) {
|
||||
//Finished walking cycle
|
||||
for(clip in this.clips){
|
||||
this.clips[clip].z = this.y + this.x + 0.1;
|
||||
}
|
||||
this.recalculateZAfter = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
function createGameObject(objData){
|
||||
|
||||
console.log(objData);
|
||||
|
||||
objData.sprite = new PIXI.Sprite(getObjectTexture(objData));
|
||||
objData.sprite.x = getXPosition(objData.type, objData.x, objData.y);
|
||||
objData.sprite.y = getYPosition(objData.type, objData.x, objData.y);
|
||||
objData.sprite.z = getZPosition(objData.type, objData.x, objData.y);
|
||||
|
||||
objData.sprite.interactive = true;
|
||||
objData.sprite.buttonMode = true;
|
||||
|
||||
objData.sprite.on("click", function(){
|
||||
console.log(objData);
|
||||
});
|
||||
|
||||
objData.sprite.on("pointerover", function(){
|
||||
objData.sprite.texture = getObjectTexture(objData, true);
|
||||
});
|
||||
|
||||
objData.sprite.on("pointerout", function(){
|
||||
objData.sprite.texture = getObjectTexture(objData, false);
|
||||
});
|
||||
|
||||
//Setup Inventory
|
||||
// createInventory(objData);
|
||||
|
||||
objData.update = update;
|
||||
|
||||
if(objData.type === OBJ_CUBOT){
|
||||
objData.clips = getCubotAnimatedSprites();
|
||||
objData.clips.walk_e.visible = false;
|
||||
objData.clips.walk_n.visible = false;
|
||||
objData.clips.walk_s.visible = false;
|
||||
objData.clips.walk_w.visible = false;
|
||||
game.worldLayer.addChild(objData.clips.walk_e);
|
||||
game.worldLayer.addChild(objData.clips.walk_n);
|
||||
game.worldLayer.addChild(objData.clips.walk_s);
|
||||
game.worldLayer.addChild(objData.clips.walk_w);
|
||||
|
||||
} else {
|
||||
game.worldLayer.addChild(objData.sprite);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return objData;
|
||||
|
||||
}
|
||||
92
mar/old/Tile.js
Normal file
92
mar/old/Tile.js
Normal file
@@ -0,0 +1,92 @@
|
||||
|
||||
|
||||
TILE_PLAIN = 0;
|
||||
TILE_WALL = 1;
|
||||
TILE_IRON = 2;
|
||||
TILE_COPPER = 3;
|
||||
|
||||
getTileYOffset = function(terrainType) {
|
||||
|
||||
if (terrainType === TILE_WALL) {
|
||||
return -40;
|
||||
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
};
|
||||
getTileXOffset = function(terrainType) {
|
||||
return 0;
|
||||
};
|
||||
|
||||
getTileHitBox = function(terrainType) {
|
||||
if (terrainType === TILE_PLAIN) {
|
||||
return new PIXI.Polygon(
|
||||
new PIXI.Point(64, 0),
|
||||
new PIXI.Point(128, 32),
|
||||
new PIXI.Point(64, 64),
|
||||
new PIXI.Point(0, 32)
|
||||
)
|
||||
} else if(terrainType === TILE_WALL) {
|
||||
return new PIXI.Polygon(
|
||||
new PIXI.Point(64, 0),
|
||||
new PIXI.Point(128, 32),
|
||||
new PIXI.Point(128, 72),
|
||||
new PIXI.Point(64, 103),
|
||||
new PIXI.Point(0, 72),
|
||||
new PIXI.Point(0, 32)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
TILE_TEXTURE = function(terrainType, selected) {
|
||||
|
||||
switch (terrainType){
|
||||
case TILE_PLAIN:
|
||||
return selected ? PIXI.Texture.fromFrame("tiles/plain_s") : PIXI.Texture.fromFrame("tiles/plain");
|
||||
case TILE_WALL:
|
||||
return selected ? PIXI.Texture.fromFrame("tiles/wall_s") : PIXI.Texture.fromFrame("tiles/wall");
|
||||
case TILE_IRON:
|
||||
return selected ? PIXI.Texture.fromFrame("tiles/iron") : PIXI.Texture.fromFrame("tiles/iron");
|
||||
case TILE_COPPER:
|
||||
return selected ? PIXI.Texture.fromFrame("tiles/copper") : PIXI.Texture.fromFrame("tiles/copper");
|
||||
}
|
||||
};
|
||||
|
||||
function Tile(terrainType) {
|
||||
|
||||
|
||||
this.sprite = new PIXI.Sprite(TILE_TEXTURE(terrainType, false));
|
||||
this.sprite.hitArea = getTileHitBox(terrainType);
|
||||
this.sprite.terrainType = terrainType;
|
||||
|
||||
//Setup Events
|
||||
//todo: We are assigning an event to each tile (256), is it efficient?
|
||||
this.sprite.interactive = true;
|
||||
|
||||
this.sprite.on("pointerover", function() {
|
||||
this.texture = TILE_TEXTURE(this.terrainType, true);
|
||||
|
||||
//TODO Show tooltip / debug info here
|
||||
});
|
||||
|
||||
this.sprite.on("pointerout", function() {
|
||||
this.texture = TILE_TEXTURE(this.terrainType, false);
|
||||
});
|
||||
|
||||
//Behave like background when clicked
|
||||
this.sprite.on("pointerdown", pointerDown);
|
||||
this.sprite.on("pointerup", bgPointerUp);
|
||||
this.sprite.on("pointerupoutside", bgPointerUp);
|
||||
|
||||
}
|
||||
|
||||
function pointerDown(e) {
|
||||
game.pointerdown = true;
|
||||
game.pointerFirstClick = e.data.getLocalPosition(game.rootContainer);
|
||||
}
|
||||
|
||||
function bgPointerUp() {
|
||||
game.pointerdown = false;
|
||||
game.pointerLastDrag = null;
|
||||
}
|
||||
240
mar/old/World.js
Normal file
240
mar/old/World.js
Normal file
@@ -0,0 +1,240 @@
|
||||
|
||||
|
||||
WORLD_WIDTH = 16;
|
||||
WORLD_HEIGHT = 16;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param terrain
|
||||
* @constructor
|
||||
*/
|
||||
function Word(terrain) {
|
||||
|
||||
setupWorldLayer(this);
|
||||
// game.worldLayer = new PIXI.Container();
|
||||
|
||||
this.tiles = {};
|
||||
this.objects = [];
|
||||
|
||||
var self = this;
|
||||
|
||||
for (var x = 0; x < WORLD_HEIGHT; x++) {
|
||||
for (var y = 0; y < WORLD_HEIGHT; y++) {
|
||||
|
||||
var terrainType = terrain[y * WORLD_WIDTH + x];
|
||||
|
||||
var tile = new Tile(terrainType);
|
||||
|
||||
tile.sprite.x = (x - y) * 64 + getTileXOffset(terrainType);
|
||||
tile.sprite.y = (x + y) * 32 + getTileYOffset(terrainType);
|
||||
tile.sprite.z = y + x;
|
||||
|
||||
this.tiles[x + ',' + y] = tile;
|
||||
|
||||
game.worldLayer.addChild(tile.sprite);
|
||||
game.rootContainer.addChild(game.worldLayer);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
game.worldLayer.children.sort(depthCompare);
|
||||
|
||||
/**
|
||||
* Update object from parsed JSON string sent from the server
|
||||
* @param response parsed JSON string sent from the server
|
||||
*/
|
||||
this.updateObjects = function(response) {
|
||||
|
||||
|
||||
//Mark objects as not updated
|
||||
for(var i = 0; i < self.objects.length ; i++){
|
||||
self.objects[i].updated = false;
|
||||
}
|
||||
|
||||
|
||||
for(var i = 0; i < response.length ; i++){
|
||||
|
||||
response[i].updated = true;
|
||||
|
||||
//Update/Create the object
|
||||
|
||||
var existingObject = self.getObject(response[i].id);
|
||||
if(existingObject !== null){
|
||||
//Object already exists
|
||||
existingObject = updateGameObject(existingObject, response[i]);
|
||||
|
||||
} else {
|
||||
|
||||
//Object is new
|
||||
var newObj = createGameObject(response[i]);
|
||||
self.addObject(newObj);
|
||||
}
|
||||
}
|
||||
|
||||
//Delete not updated objects (see above comments)
|
||||
for (var i = 0; i < self.objects.length; i++) {
|
||||
if (!self.objects[i].updated) {
|
||||
console.log("DEBUG: removed " + self.objects[i].id);
|
||||
game.worldLayer.removeChild(self.objects[i].sprite);
|
||||
self.objects.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
game.worldLayer.children.sort(depthCompare);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Add an object the the 'current' objects
|
||||
* @param object
|
||||
*/
|
||||
this.addObject = function(object) {
|
||||
|
||||
self.objects.push(object);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get object from the list of 'current' objects (Objects shown on the screen)
|
||||
* @param id objectId of the object
|
||||
*/
|
||||
this.getObject = function(id) {
|
||||
|
||||
for(var i = 0; i < self.objects.length; i++) {
|
||||
if (self.objects[i].id === id) {
|
||||
return self.objects[i];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
this.update = function(terrain){
|
||||
|
||||
for (key in this.tiles) {
|
||||
game.worldLayer.removeChild(this.tiles[key].sprite);
|
||||
}
|
||||
|
||||
for (var j = 0; j < this.objects.length; j++) {
|
||||
game.worldLayer.removeChild(this.objects[j].sprite);
|
||||
}
|
||||
|
||||
this.tiles = {};
|
||||
this.objects = [];
|
||||
|
||||
for (var x = 0; x < WORLD_HEIGHT; x++) {
|
||||
for (var y = 0; y < WORLD_HEIGHT; y++) {
|
||||
|
||||
var terrainType = terrain[y * WORLD_WIDTH + x];
|
||||
|
||||
var tile = new Tile(terrainType);
|
||||
|
||||
tile.sprite.x = (x - y) * 64 + getTileXOffset(terrainType);
|
||||
tile.sprite.y = (x + y) * 32 + getTileYOffset(terrainType);
|
||||
tile.sprite.z = y + x;
|
||||
|
||||
this.tiles[x + ',' + y] = tile;
|
||||
|
||||
game.worldLayer.addChild(tile.sprite);
|
||||
game.rootContainer.addChild(game.worldLayer);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
game.worldLayer.children.sort(depthCompare);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function setupWorldLayer(world) {
|
||||
game.worldLayer = new PIXI.Container();
|
||||
game.worldLayer.x = 736;
|
||||
game.worldLayer.y = -32;
|
||||
game.rootContainer.addChild(game.worldLayer);
|
||||
|
||||
//NORTH
|
||||
var arrow_north = new PIXI.Sprite(PIXI.Texture.fromFrame("ui/arrow_north"));
|
||||
arrow_north.x = 528;
|
||||
arrow_north.y = 224;
|
||||
arrow_north.interactive = true;
|
||||
arrow_north.buttonMode = true;
|
||||
arrow_north.on("pointerover", function () {
|
||||
arrow_north.texture = PIXI.Texture.fromFrame("ui/arrow_north_s");
|
||||
});
|
||||
arrow_north.on("pointerout", function () {
|
||||
arrow_north.texture = PIXI.Texture.fromFrame("ui/arrow_north");
|
||||
});
|
||||
arrow_north.on("pointerdown", function () {
|
||||
game.worldY--;
|
||||
client.requestTerrain()
|
||||
});
|
||||
game.worldLayer.addChild(arrow_north);
|
||||
|
||||
//EAST
|
||||
var arrow_east = new PIXI.Sprite(PIXI.Texture.fromFrame("ui/arrow_east"));
|
||||
arrow_east.x = 528;
|
||||
arrow_east.y = 750;
|
||||
arrow_east.interactive = true;
|
||||
arrow_east.buttonMode = true;
|
||||
arrow_east.on("pointerover", function () {
|
||||
arrow_east.texture = PIXI.Texture.fromFrame("ui/arrow_east_s");
|
||||
});
|
||||
arrow_east.on("pointerout", function () {
|
||||
arrow_east.texture = PIXI.Texture.fromFrame("ui/arrow_east");
|
||||
});
|
||||
arrow_east.on("pointerdown", function () {
|
||||
game.worldX++;
|
||||
client.requestTerrain();
|
||||
});
|
||||
game.worldLayer.addChild(arrow_east);
|
||||
|
||||
//SOUTH
|
||||
var arrow_south = new PIXI.Sprite(PIXI.Texture.fromFrame("ui/arrow_south"));
|
||||
arrow_south.x = -496;
|
||||
arrow_south.y = 750;
|
||||
arrow_south.interactive = true;
|
||||
arrow_south.buttonMode = true;
|
||||
arrow_south.on("pointerover", function () {
|
||||
arrow_south.texture = PIXI.Texture.fromFrame("ui/arrow_south_s");
|
||||
});
|
||||
arrow_south.on("pointerout", function () {
|
||||
arrow_south.texture = PIXI.Texture.fromFrame("ui/arrow_south");
|
||||
});
|
||||
arrow_south.on("pointerdown", function () {
|
||||
game.worldY++;
|
||||
client.requestTerrain();
|
||||
});
|
||||
game.worldLayer.addChild(arrow_south);
|
||||
|
||||
//WEST
|
||||
var arrow_west = new PIXI.Sprite(PIXI.Texture.fromFrame("ui/arrow_west"));
|
||||
arrow_west.x = -496;
|
||||
arrow_west.y = 224;
|
||||
arrow_west.interactive = true;
|
||||
arrow_west.buttonMode = true;
|
||||
arrow_west.on("pointerover", function () {
|
||||
arrow_west.texture = PIXI.Texture.fromFrame("ui/arrow_west_s");
|
||||
});
|
||||
arrow_west.on("pointerout", function () {
|
||||
arrow_west.texture = PIXI.Texture.fromFrame("ui/arrow_west");
|
||||
});
|
||||
arrow_west.on("pointerdown", function () {
|
||||
game.worldX--;
|
||||
client.requestTerrain();
|
||||
});
|
||||
game.worldLayer.addChild(arrow_west)
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare depth of two sprites based on their z property
|
||||
*/
|
||||
function depthCompare(a, b) {
|
||||
if (a.z < b.z) {
|
||||
return -1;
|
||||
}
|
||||
if (a.z > b.z) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
311
mar/old/game-olf.js
Normal file
311
mar/old/game-olf.js
Normal file
@@ -0,0 +1,311 @@
|
||||
"use strict";
|
||||
console.log("hello")
|
||||
// --------------------------
|
||||
// MAR loop
|
||||
function gameLoop() {
|
||||
requestAnimationFrame(gameLoop);
|
||||
|
||||
//UPDATE EFFECTS
|
||||
for (var i = 0; i < MAR.effects.length; i++) {
|
||||
MAR.effects[i].update();
|
||||
}
|
||||
//Update objects
|
||||
for (var j = 0; j < MAR.objects.length; j++) {
|
||||
|
||||
if (MAR.objects[j].objectType === 1) {-
|
||||
MAR.objects[j].update();
|
||||
}
|
||||
}
|
||||
|
||||
MAR.renderer.render(MAR.rootContainer);
|
||||
}
|
||||
|
||||
var setupCallback = function () {
|
||||
getWorldTerrain();
|
||||
gameLoop();
|
||||
};
|
||||
|
||||
function tick() {
|
||||
getGameEffects();
|
||||
getGameObjects();
|
||||
|
||||
//Update indicators
|
||||
for (var i = 0; i < MAR.objects.length; i++) {
|
||||
if (MAR.objects[i].indicator !== undefined) {
|
||||
MAR.objects[i].indicator.updateIcon();
|
||||
}
|
||||
}
|
||||
|
||||
//Update debug text
|
||||
MAR.timeText.text = "gameTime: " + MAR.time;
|
||||
}
|
||||
|
||||
function getGameObjects() {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", "./mar/objects.php?x=" + MAR.currentLocX + "&y=" + MAR.currentLocY, true);
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||
var jsonResponse = JSON.parse(xhr.responseText);
|
||||
|
||||
for (var i = 0; i < MAR.objects.length; i++) {
|
||||
MAR.objects[i].updated = false;
|
||||
}
|
||||
|
||||
for (var i = 0; i < jsonResponse.length; i++) {
|
||||
var obj = getObject(jsonResponse[i].i);
|
||||
|
||||
if (obj !== null) {
|
||||
//OBJECT already exist, update
|
||||
obj.updated = true;
|
||||
|
||||
if (obj.objectType === 1) {
|
||||
//Update direction
|
||||
obj.direction = jsonResponse[i].d;
|
||||
|
||||
//Update location
|
||||
if (obj.x !== jsonResponse[i].x || obj.y !== jsonResponse[i].y) {
|
||||
//location changed
|
||||
moveObject(jsonResponse[i].x, jsonResponse[i].y, obj);
|
||||
}
|
||||
|
||||
//update held item
|
||||
obj.heldItem = jsonResponse[i].h;
|
||||
//Update action
|
||||
obj.action = jsonResponse[i].a;
|
||||
} else if (obj.objectType === 3) {
|
||||
//Kiln object already exists, update
|
||||
obj.qi = jsonResponse[i].qi; //Queued Iron
|
||||
obj.qc = jsonResponse[i].qc; //Queued Copper
|
||||
obj.ci = jsonResponse[i].ci; //Cooked Iron
|
||||
obj.cc = jsonResponse[i].cc; //Cooked Copper
|
||||
obj.f = jsonResponse[i].f; //Fuel
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
var newObj = new GameObject(jsonResponse[i]);
|
||||
newObj.updated = true;
|
||||
MAR.worldLayer.addChild(newObj.sprite);
|
||||
MAR.objects.push(newObj);
|
||||
|
||||
console.log("DEBUG: added " + newObj.id);
|
||||
}
|
||||
}
|
||||
|
||||
//Delete not updated objects (see above comments)
|
||||
for (var i = 0; i < MAR.objects.length; i++) {
|
||||
if (!MAR.objects[i].updated) {
|
||||
console.log("DEBUG: removed " + MAR.objects[i].id);
|
||||
MAR.worldLayer.removeChild(MAR.objects[i].sprite);
|
||||
MAR.objects.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
MAR.worldLayer.children.sort(depthCompare);
|
||||
}
|
||||
};
|
||||
xhr.send(null);
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
// Display a single effect
|
||||
function displayEffect(effect) {
|
||||
if (effect.t === "ERROR") {
|
||||
var newEffect = new IconEffect(effect.x, effect.y, "err_icon");
|
||||
MAR.effects.push(newEffect);
|
||||
addToWorldLayer(newEffect.sprite);
|
||||
}
|
||||
if (effect.t === "WARNING") {
|
||||
var newEffect = new IconEffect(effect.x, effect.y, "warn_icon");
|
||||
MAR.effects.push(newEffect);
|
||||
addToWorldLayer(newEffect.sprite);
|
||||
}
|
||||
if (effect.t === "A_EMOTE") {
|
||||
var newEffect = new IconEffect(effect.x, effect.y, "A_icon");
|
||||
MAR.effects.push(newEffect);
|
||||
addToWorldLayer(newEffect.sprite);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
// Query the MAR API to get the MAR effects
|
||||
function getGameEffects() {
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", "./mar/effects.php?x=" + MAR.currentLocX + "&y=" + MAR.currentLocY, true);
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||
var effects = JSON.parse(xhr.responseText);
|
||||
|
||||
for (var i = 0; i < effects.length; i++) {
|
||||
displayEffect(effects[i]);
|
||||
}
|
||||
MAR.worldLayer.children.sort(depthCompare);
|
||||
}
|
||||
};
|
||||
xhr.send(null);
|
||||
}
|
||||
|
||||
function getWorldTerrain() {
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", "./mar/terrain.php?x=" + MAR.currentLocX + "&y=" + MAR.currentLocY, true);
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||
var currentTerrain = JSON.parse(xhr.responseText);
|
||||
|
||||
//Calculate wall height
|
||||
//First pass, set wall height to 2 for each wall tile with 3+ adjacent wall tile (diagonals don't count)
|
||||
for (var y = 0; y < 16; y++) {
|
||||
for (var x = 0; x < 16; x++) {
|
||||
var tile = new Tile(currentTerrain[x * 16 + y]);
|
||||
|
||||
|
||||
//Calculate neighbors
|
||||
var neighbors = 0;
|
||||
if (currentTerrain[x * 16 + y] === 1) {
|
||||
if (currentTerrain[x * 16 + y - 16] === 1 ||
|
||||
(currentTerrain[x * 16 + y - 16] !== undefined && currentTerrain[x * 16 + y - 16].wallHeight >= 1)) {
|
||||
neighbors++;
|
||||
} else {
|
||||
|
||||
}
|
||||
if (currentTerrain[x * 16 + y + 16] === 1 ||
|
||||
(currentTerrain[x * 16 + y + 16] !== undefined && currentTerrain[x * 16 + y + 16].wallHeight >= 1)) {
|
||||
neighbors++;
|
||||
}
|
||||
if (currentTerrain[x * 16 + y + 1] === 1 ||
|
||||
(currentTerrain[x * 16 + y + 1] !== undefined && currentTerrain[x * 16 + y + 1].wallHeight >= 1)) {
|
||||
neighbors++;
|
||||
}
|
||||
if (currentTerrain[x * 16 + y - 1] === 1 ||
|
||||
(currentTerrain[x * 16 + y - 1] !== undefined && currentTerrain[x * 16 + y - 1].wallHeight >= 1)) {
|
||||
neighbors++;
|
||||
}
|
||||
|
||||
if (neighbors >= 4) {
|
||||
tile.wallHeight++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
tile.sprite.tileX = x;
|
||||
tile.sprite.tileY = y;
|
||||
|
||||
tile.sprite.x += (x - y) * 64;
|
||||
tile.sprite.y += (x + y) * 32;
|
||||
tile.sprite.z += y + x;
|
||||
|
||||
//A bit hacky but it'll work for now...
|
||||
currentTerrain[x * 16 + y] = tile;
|
||||
}
|
||||
}
|
||||
//currentTerrain is no longer an array of ints but an array of Tile objects
|
||||
//Add tiles to world layer
|
||||
for (var i = 0; i < currentTerrain.length; i++) {
|
||||
|
||||
|
||||
if (currentTerrain[i].sprite.tileId === 1) {
|
||||
if (currentTerrain[i].wallHeight === 1) {
|
||||
MAR.worldLayer.addChild(currentTerrain[i].sprite);
|
||||
} else if (currentTerrain[i].wallHeight === 2) {
|
||||
|
||||
MAR.worldLayer.addChild(currentTerrain[i].sprite);
|
||||
//Add duplicate sprite on top (63 px up)
|
||||
var topTile = new Tile(1);
|
||||
topTile.sprite.tileX = currentTerrain[i].sprite.tileX;
|
||||
topTile.sprite.tileY = currentTerrain[i].sprite.tileY;
|
||||
topTile.sprite.tileId = 1;
|
||||
|
||||
topTile.sprite.x = currentTerrain[i].sprite.x;
|
||||
topTile.sprite.y = currentTerrain[i].sprite.y - 40;
|
||||
topTile.sprite.z = currentTerrain[i].sprite.z + 1.1;
|
||||
MAR.worldLayer.addChild(topTile.sprite);
|
||||
MAR.tiles.push(topTile);
|
||||
}
|
||||
|
||||
} else {
|
||||
MAR.worldLayer.addChild(currentTerrain[i].sprite);
|
||||
}
|
||||
|
||||
MAR.tiles.push(currentTerrain[i]);
|
||||
}
|
||||
|
||||
|
||||
MAR.worldLayer.children.sort(depthCompare);
|
||||
}
|
||||
|
||||
};
|
||||
xhr.send(null);
|
||||
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
// Query the MAR API to get MAR time
|
||||
function getGameTime() {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", "./mar/time.php", true);
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||
|
||||
if (MAR.time !== xhr.responseText) {
|
||||
MAR.timeChanged = true;
|
||||
MAR.time = xhr.responseText;
|
||||
} else {
|
||||
MAR.timeChanged = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
xhr.send(null);
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
// Change an object's location and initialise the move animation
|
||||
function moveObject(newX, newY, gameObject) {
|
||||
|
||||
//Resync object
|
||||
gameObject.sprite.x = (gameObject.x - gameObject.y) * 64;
|
||||
gameObject.sprite.y = ((gameObject.x + gameObject.y) * 32) - 16;
|
||||
|
||||
var tiledx = newX - gameObject.x;
|
||||
var tiledy = newY - gameObject.y;
|
||||
|
||||
gameObject.dx = 0;
|
||||
gameObject.dy = 0;
|
||||
|
||||
//Recalculate position
|
||||
gameObject.x = newX;
|
||||
gameObject.y = newY;
|
||||
|
||||
if (tiledx === 1) {
|
||||
//We need to move 128px to the right and the minimum tick length is 1s.
|
||||
//This means that we have maximum 60 frames to do the animation
|
||||
gameObject.dx = 64 / 58;
|
||||
gameObject.dy = 32 / 58;
|
||||
gameObject.walking = 58;
|
||||
//Recalculate Z order immediately
|
||||
gameObject.sprite.z = gameObject.y + gameObject.x + 0.1;
|
||||
} else if (tiledx === -1) {
|
||||
gameObject.dx = -64 / 58;
|
||||
gameObject.dy = -32 / 58;
|
||||
gameObject.walking = 58;
|
||||
|
||||
//The Z order needs to be recalculated when the movement ends
|
||||
gameObject.recalculateZAfter = true;
|
||||
} else if (tiledy === 1) {
|
||||
gameObject.dx = -64 / 58;
|
||||
gameObject.dy = 32 / 58;
|
||||
gameObject.walking = 58;
|
||||
//Recalculate Z order immediately
|
||||
gameObject.sprite.z = gameObject.y + gameObject.x + 0.1;
|
||||
} else if (tiledy === -1) {
|
||||
gameObject.dx = 64 / 58;
|
||||
gameObject.dy = -32 / 58;
|
||||
gameObject.walking = 58;
|
||||
//The Z order needs to be recalculated when the movement ends
|
||||
gameObject.recalculateZAfter = true;
|
||||
}
|
||||
|
||||
MAR.worldLayer.children.sort(depthCompare);
|
||||
|
||||
}
|
||||
42271
mar/old/pixi.js
Executable file
42271
mar/old/pixi.js
Executable file
File diff suppressed because it is too large
Load Diff
21
mar/old/pixi.min.js
vendored
Executable file
21
mar/old/pixi.min.js
vendored
Executable file
File diff suppressed because one or more lines are too long
826
mar/old/setup.js
Normal file
826
mar/old/setup.js
Normal file
@@ -0,0 +1,826 @@
|
||||
"use strict";
|
||||
|
||||
|
||||
var MAR = {
|
||||
|
||||
RENDERER_BG: 0x282828,
|
||||
currentLocX: 0,
|
||||
currentLocY: 0,
|
||||
effects: [],
|
||||
tiles: [],
|
||||
objects: []
|
||||
};
|
||||
|
||||
if (fullscreen) {
|
||||
MAR.RENDERER_WIDTH = window.innerWidth - 4;
|
||||
MAR.RENDERER_HEIGHT = window.innerHeight - 4;
|
||||
} else {
|
||||
MAR.RENDERER_WIDTH = document.getElementById("game").clientWidth;
|
||||
MAR.RENDERER_HEIGHT = (window.innerHeight / 1.25);
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
// Load Sprites
|
||||
PIXI.loader
|
||||
.add("./mar/sprites/cubot.json")
|
||||
.add("biomass", "./mar/sprites/biomass.png")
|
||||
.add("rocket", "./mar/sprites/rocket.png")
|
||||
.add("kiln", "./mar/sprites/kiln.png")
|
||||
.add("digester", "./mar/sprites/digester.png")
|
||||
.add("arrow_north", "./mar/sprites/arrow_north.png")
|
||||
.add("arrow_north_s", "./mar/sprites/arrow_north_s.png")
|
||||
.add("arrow_west", "./mar/sprites/arrow_west.png")
|
||||
.add("arrow_west_s", "./mar/sprites/arrow_west_s.png")
|
||||
.add("arrow_south", "./mar/sprites/arrow_south.png")
|
||||
.add("arrow_south_s", "./mar/sprites/arrow_south_s.png")
|
||||
.add("arrow_east", "./mar/sprites/arrow_east.png")
|
||||
.add("arrow_east_s", "./mar/sprites/arrow_east_s.png")
|
||||
.add("plain", "./mar/sprites/sample.png")
|
||||
.add("tile_iron", "./mar/sprites/tile_iron.png")
|
||||
.add("tile_copper", "./mar/sprites/tile_copper.png")
|
||||
.add("plain_s", "./mar/sprites/Tile_iso_selected.png")
|
||||
.add("wall", "./mar/sprites/Tile_iso _wall.png")
|
||||
.add("wall_s", "./mar/sprites/Tile_iso _wall_s.png")
|
||||
|
||||
.add("GOURD_PLANT", "./mar/sprites/GOURD_PLANT.png")
|
||||
.add("GOURD_PLANT_s", "./mar/sprites/GOURD_PLANT_s.png")
|
||||
.add("LETTUCE_PLANT", "./mar/sprites/LETTUCE_PLANT.png")
|
||||
.add("LETTUCE_PLANT_s", "./mar/sprites/LETTUCE_PLANT_s.png")
|
||||
.add("OAK_TREE", "./mar/sprites/OAK_TREE.png")
|
||||
.add("egg", "./mar/sprites/egg.png")
|
||||
|
||||
.add("plant1", "./mar/sprites/plant1.png")
|
||||
|
||||
.add("err_icon", "./mar/sprites/err_icon.png")
|
||||
.add("warn_icon", "./mar/sprites/warn_icon.png")
|
||||
.add("A_icon", "./mar/sprites/A_icon.png");
|
||||
|
||||
PIXI.loader
|
||||
.on("progress", progressHandler)
|
||||
.load(loaderCallback);
|
||||
|
||||
|
||||
// --------------------------
|
||||
// Handle progress change event
|
||||
function progressHandler(loader, resource) {
|
||||
//TODO - implement loading bar
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
// Loader callback (Setup)
|
||||
function loaderCallback() {
|
||||
setupRenderer();
|
||||
setupBackground();
|
||||
// setupKeyBoard();
|
||||
setupWorldLayer();
|
||||
setupAutoUpdate();
|
||||
setupDebugText();
|
||||
|
||||
|
||||
setupCallback();
|
||||
}
|
||||
|
||||
function addToWorldLayer(sprite) {
|
||||
MAR.worldLayer.addChild(sprite);
|
||||
MAR.worldLayer.children.sort(depthCompare);
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
// Compare depth of two sprites based on their z property
|
||||
function depthCompare(a, b) {
|
||||
if (a.z < b.z) {
|
||||
return -1;
|
||||
}
|
||||
if (a.z > b.z) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function setupDebugText() {
|
||||
MAR.textLayer = new PIXI.Container();
|
||||
MAR.rootContainer.addChild(MAR.textLayer);
|
||||
|
||||
//Debug text
|
||||
MAR.currentTileText = new PIXI.Text("", {fontSize: 12, fontFamily: "c64_mono", fill: "white"});
|
||||
MAR.currentTileText.position.x = MAR.RENDERER_WIDTH - 100;
|
||||
MAR.currentTileText.position.y = 10;
|
||||
MAR.textLayer.addChild(MAR.currentTileText);
|
||||
|
||||
MAR.currentWorldText = new PIXI.Text("World 0,0", {fontSize: 12, fontFamily: "c64_mono", fill: "white"});
|
||||
MAR.currentWorldText.position.x = MAR.RENDERER_WIDTH - 150;
|
||||
MAR.currentWorldText.position.y = 100;
|
||||
MAR.textLayer.addChild(MAR.currentWorldText);
|
||||
|
||||
MAR.timeText = new PIXI.Text("gameTime: 0", {fontSize: 12, fontFamily: "c64_mono", fill: "white"});
|
||||
MAR.timeText.position.x = MAR.RENDERER_WIDTH - 200;
|
||||
MAR.timeText.position.y = 70;
|
||||
MAR.textLayer.addChild(MAR.timeText);
|
||||
|
||||
// Watermark
|
||||
MAR.watermark = new PIXI.Text("Much Assembly Required V3.0", {fontSize: 20, fontFamily: "c64_mono", fill: "grey"});
|
||||
MAR.watermark.position.x = MAR.RENDERER_WIDTH - 450;
|
||||
MAR.watermark.position.y = MAR.RENDERER_HEIGHT - 30;
|
||||
MAR.textLayer.addChild(MAR.watermark)
|
||||
}
|
||||
|
||||
function setupAutoUpdate() {
|
||||
window.setInterval(function () {
|
||||
getGameTime();
|
||||
|
||||
if (MAR.timeChanged) {
|
||||
tick();
|
||||
}
|
||||
}, 334);
|
||||
}
|
||||
|
||||
function setupWorldLayer() {
|
||||
MAR.worldLayer = new PIXI.Container();
|
||||
MAR.worldLayer.x = 736;
|
||||
MAR.worldLayer.y = -32;
|
||||
MAR.rootContainer.addChild(MAR.worldLayer);
|
||||
|
||||
//NORTH
|
||||
var arrow_north = new PIXI.Sprite(PIXI.loader.resources["arrow_north"].texture);
|
||||
arrow_north.x = 528;
|
||||
arrow_north.y = 224;
|
||||
arrow_north.interactive = true;
|
||||
arrow_north.buttonMode = true;
|
||||
arrow_north.on("pointerover", function () {
|
||||
arrow_north.texture = PIXI.loader.resources["arrow_north_s"].texture;
|
||||
});
|
||||
arrow_north.on("pointerout", function () {
|
||||
arrow_north.texture = PIXI.loader.resources["arrow_north"].texture;
|
||||
});
|
||||
arrow_north.on("pointerdown", function () {
|
||||
clearWorldLayer();
|
||||
MAR.currentLocY--;
|
||||
getWorldTerrain();
|
||||
getGameObjects();
|
||||
updateCurrentWorldText();
|
||||
});
|
||||
MAR.worldLayer.addChild(arrow_north);
|
||||
|
||||
//EAST
|
||||
var arrow_east = new PIXI.Sprite(PIXI.loader.resources["arrow_east"].texture);
|
||||
arrow_east.x = 528;
|
||||
arrow_east.y = 750;
|
||||
arrow_east.interactive = true;
|
||||
arrow_east.buttonMode = true;
|
||||
arrow_east.on("pointerover", function () {
|
||||
arrow_east.texture = PIXI.loader.resources["arrow_east_s"].texture;
|
||||
});
|
||||
arrow_east.on("pointerout", function () {
|
||||
arrow_east.texture = PIXI.loader.resources["arrow_east"].texture;
|
||||
});
|
||||
arrow_east.on("pointerdown", function () {
|
||||
clearWorldLayer();
|
||||
MAR.currentLocX++;
|
||||
getWorldTerrain();
|
||||
getGameObjects();
|
||||
updateCurrentWorldText();
|
||||
});
|
||||
MAR.worldLayer.addChild(arrow_east);
|
||||
|
||||
//SOUTH
|
||||
var arrow_south = new PIXI.Sprite(PIXI.loader.resources["arrow_south"].texture);
|
||||
arrow_south.x = -496;
|
||||
arrow_south.y = 750;
|
||||
arrow_south.interactive = true;
|
||||
arrow_south.buttonMode = true;
|
||||
arrow_south.on("pointerover", function () {
|
||||
arrow_south.texture = PIXI.loader.resources["arrow_south_s"].texture;
|
||||
});
|
||||
arrow_south.on("pointerout", function () {
|
||||
arrow_south.texture = PIXI.loader.resources["arrow_south"].texture;
|
||||
});
|
||||
arrow_south.on("pointerdown", function () {
|
||||
clearWorldLayer();
|
||||
MAR.currentLocY++;
|
||||
getWorldTerrain();
|
||||
getGameObjects();
|
||||
updateCurrentWorldText();
|
||||
});
|
||||
MAR.worldLayer.addChild(arrow_south);
|
||||
|
||||
//WEST
|
||||
var arrow_west = new PIXI.Sprite(PIXI.loader.resources["arrow_west"].texture);
|
||||
arrow_west.x = -496;
|
||||
arrow_west.y = 224;
|
||||
arrow_west.interactive = true;
|
||||
arrow_west.buttonMode = true;
|
||||
arrow_west.on("pointerover", function () {
|
||||
arrow_west.texture = PIXI.loader.resources["arrow_west_s"].texture;
|
||||
});
|
||||
arrow_west.on("pointerout", function () {
|
||||
arrow_west.texture = PIXI.loader.resources["arrow_west"].texture;
|
||||
});
|
||||
arrow_west.on("pointerdown", function () {
|
||||
clearWorldLayer();
|
||||
MAR.currentLocX--;
|
||||
getWorldTerrain();
|
||||
getGameObjects();
|
||||
updateCurrentWorldText();
|
||||
});
|
||||
MAR.worldLayer.addChild(arrow_west)
|
||||
}
|
||||
|
||||
function clearWorldLayer() {
|
||||
for (var i = 0; i < MAR.tiles.length; i++) {
|
||||
MAR.worldLayer.removeChild(MAR.tiles[i].sprite);
|
||||
}
|
||||
|
||||
for (var j = 0; j < MAR.objects.length; j++) {
|
||||
MAR.worldLayer.removeChild(MAR.objects[j].sprite);
|
||||
|
||||
if (MAR.objects[j].indicator !== undefined) {
|
||||
MAR.worldLayer.removeChild(MAR.objects[j].indicator.sprite);
|
||||
}
|
||||
//todo Remove inv indicator as well
|
||||
}
|
||||
|
||||
MAR.objects = [];
|
||||
MAR.tiles = [];
|
||||
}
|
||||
|
||||
function updateCurrentWorldText() {
|
||||
MAR.currentWorldText.text = MAR.currentLocX + "," + MAR.currentLocY;
|
||||
}
|
||||
|
||||
function setupKeyBoard() {
|
||||
//SETUP KEYBOARD LISTENERS
|
||||
// var leftArrow = keyboard(37);
|
||||
// var rightArrow = keyboard(39);
|
||||
var downArrow = keyboard(40);
|
||||
var upArrow = keyboard(38);
|
||||
|
||||
downArrow.press = function () {
|
||||
|
||||
MAR.worldLayer.scale.x -= 0.1;
|
||||
MAR.worldLayer.scale.y -= 0.1;
|
||||
|
||||
};
|
||||
|
||||
upArrow.press = function () {
|
||||
|
||||
MAR.worldLayer.scale.x += 0.1;
|
||||
MAR.worldLayer.scale.y += 0.1;
|
||||
}
|
||||
}
|
||||
|
||||
function setupBackground() {
|
||||
//SETUP BACKGROUND LAYER & PANNING
|
||||
MAR.bgLayer = new PIXI.Container();
|
||||
MAR.rootContainer.addChild(MAR.bgLayer);
|
||||
MAR.bg = new PIXI.Sprite();
|
||||
MAR.bg.interactive = true;
|
||||
MAR.bg.hitArea = new PIXI.Rectangle(0, 0, MAR.RENDERER_WIDTH, MAR.RENDERER_HEIGHT);
|
||||
MAR.bg.on("pointerover", function () {
|
||||
MAR.currentTileText.text = "-";
|
||||
});
|
||||
MAR.bg.on("pointerdown", function (e) {
|
||||
MAR.pointerdown = true;
|
||||
MAR.pointerFirstClick = e.data.getLocalPosition(MAR.rootContainer);
|
||||
});
|
||||
MAR.bg.on("pointerup", function () {
|
||||
MAR.pointerdown = false;
|
||||
MAR.pointerLastDrag = null;
|
||||
});
|
||||
MAR.bg.on("pointerupoutside", function () {
|
||||
MAR.pointerdown = false;
|
||||
MAR.pointerLastDrag = null;
|
||||
});
|
||||
MAR.bg.on("pointermove", function (e) {
|
||||
if (MAR.pointerdown === true) {
|
||||
|
||||
var currentMouse = e.data.getLocalPosition(MAR.rootContainer);
|
||||
|
||||
if (MAR.pointerLastDrag != null) {
|
||||
MAR.worldLayer.position.x += currentMouse.x - MAR.pointerLastDrag.x;
|
||||
MAR.worldLayer.position.y += currentMouse.y - MAR.pointerLastDrag.y;
|
||||
} else {
|
||||
MAR.worldLayer.position.x += currentMouse.x - MAR.pointerFirstClick.x;
|
||||
MAR.worldLayer.position.y += currentMouse.y - MAR.pointerFirstClick.y;
|
||||
}
|
||||
|
||||
MAR.pointerLastDrag = currentMouse;
|
||||
}
|
||||
});
|
||||
MAR.bgLayer.addChild(MAR.bg);
|
||||
}
|
||||
|
||||
function setupRenderer() {
|
||||
MAR.renderer = PIXI.autoDetectRenderer(256, 256);
|
||||
document.getElementById("game").appendChild(MAR.renderer.view);
|
||||
MAR.rootContainer = new PIXI.Container();
|
||||
MAR.renderer.backgroundColor = MAR.RENDERER_BG;
|
||||
MAR.renderer.resize(MAR.RENDERER_WIDTH, MAR.RENDERER_HEIGHT);
|
||||
|
||||
|
||||
window.onresize = function (event) {
|
||||
if (fullscreen) {
|
||||
MAR.RENDERER_WIDTH = window.innerWidth - 4;
|
||||
MAR.RENDERER_HEIGHT = window.innerHeight - 4;
|
||||
} else {
|
||||
MAR.RENDERER_WIDTH = document.getElementById("game").clientWidth;
|
||||
MAR.RENDERER_HEIGHT = (window.innerHeight / 1.25);
|
||||
}
|
||||
|
||||
MAR.renderer.resize(MAR.RENDERER_WIDTH, MAR.RENDERER_HEIGHT);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
//From https://github.com/kittykatattack/learningPixi#keyboard
|
||||
function keyboard(keyCode) {
|
||||
var key = {};
|
||||
key.code = keyCode;
|
||||
key.isDown = false;
|
||||
key.isUp = true;
|
||||
key.press = undefined;
|
||||
key.release = undefined;
|
||||
|
||||
//The downHandler
|
||||
key.downHandler = function (event) {
|
||||
if (event.keyCode === key.code) {
|
||||
if (key.isUp && key.press) key.press();
|
||||
key.isDown = true;
|
||||
key.isUp = false;
|
||||
}
|
||||
event.preventDefault();
|
||||
};
|
||||
|
||||
//The upHandler
|
||||
key.upHandler = function (event) {
|
||||
if (event.keyCode === key.code) {
|
||||
if (key.isDown && key.release) key.release();
|
||||
key.isDown = false;
|
||||
key.isUp = true;
|
||||
}
|
||||
event.preventDefault();
|
||||
};
|
||||
|
||||
//Attach event listeners
|
||||
window.addEventListener(
|
||||
"keydown", key.downHandler.bind(key), false
|
||||
);
|
||||
window.addEventListener(
|
||||
"keyup", key.upHandler.bind(key), false
|
||||
);
|
||||
return key;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------
|
||||
// Classes
|
||||
|
||||
// Particle effect
|
||||
function ParticleEffect(x, y, bp) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.bluePrint = bp;
|
||||
this.framesLeft = bp.framesCount;
|
||||
|
||||
}
|
||||
|
||||
ParticleEffect.prototype.graphics = new PIXI.Graphics();
|
||||
ParticleEffect.prototype.particles = [];
|
||||
ParticleEffect.prototype.update = function () {
|
||||
|
||||
this.graphics.clear();
|
||||
this.framesLeft--;
|
||||
|
||||
//Add new particles
|
||||
while (this.particles.length < this.bluePrint.particleCount && this.framesLeft > 0) {
|
||||
this.particles.push(this.bluePrint.createParticle(this.x, this.y));
|
||||
}
|
||||
|
||||
//Draw & update particles
|
||||
for (var i = 0; i < this.particles.length; i++) {
|
||||
|
||||
var p = this.particles[i];
|
||||
|
||||
var g = this.graphics;
|
||||
|
||||
g.beginFill(p.color);
|
||||
g.drawRect(p.x, p.y, p.size, p.size);
|
||||
g.endFill();
|
||||
|
||||
p.y += p.dy;
|
||||
p.x += p.dx;
|
||||
p.ttl--;
|
||||
}
|
||||
//Delete dead particles
|
||||
var particles_ = this.particles.slice(); //Copy array
|
||||
for (var j = 0; j < particles_.length; j++) {
|
||||
|
||||
if (particles_[j].ttl <= 0) {
|
||||
this.particles.splice(j, 1);
|
||||
}
|
||||
}
|
||||
//Delete effect
|
||||
if (this.particles.length <= 0) {
|
||||
MAR.rootContainer.removeChild(this.graphics);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//Icon effect
|
||||
function IconEffect(x, y, resourceName) {
|
||||
this.framesLeft = 55;
|
||||
this.sprite = new PIXI.Sprite(PIXI.loader.resources[resourceName].texture);
|
||||
|
||||
this.sprite.alpha = 0.9;
|
||||
|
||||
this.sprite.x = ((x - y) * 64) + 40;
|
||||
this.sprite.y = ((x + y) * 32) - 45;
|
||||
this.sprite.z = y + x + 0.2;
|
||||
|
||||
}
|
||||
|
||||
IconEffect.prototype.update = function () {
|
||||
|
||||
if (this.framesLeft < 30) {
|
||||
this.sprite.alpha = (this.framesLeft / 40);
|
||||
|
||||
//Remove itself
|
||||
if (this.framesLeft === 0) {
|
||||
MAR.rootContainer.removeChild(this.sprite);
|
||||
}
|
||||
}
|
||||
|
||||
this.framesLeft--;
|
||||
};
|
||||
|
||||
//Game object
|
||||
function GameObject(objData) {
|
||||
|
||||
this.objectType = objData.t;
|
||||
this.x = objData.x;
|
||||
this.y = objData.y;
|
||||
this.direction = objData.d;
|
||||
this.id = objData.i;
|
||||
this.animSpeed = 1;
|
||||
this.waitTicks = this.animSpeed;
|
||||
|
||||
|
||||
//Create sprite
|
||||
if (this.objectType === 1) {
|
||||
|
||||
this.heldItem = objData.h;
|
||||
this.action = objData.a;
|
||||
|
||||
//Tortoise
|
||||
var sprite = null;
|
||||
if (this.direction === 0) {
|
||||
//North
|
||||
sprite = new PIXI.Sprite(PIXI.Texture.fromFrame("walk_n/0001"));
|
||||
} else if (this.direction === 1) {
|
||||
//East
|
||||
sprite = new PIXI.Sprite(PIXI.Texture.fromFrame("walk_n/0001"));
|
||||
} else if (this.direction === 2) {
|
||||
//South
|
||||
sprite = new PIXI.Sprite(PIXI.Texture.fromFrame("walk_n/0001"));
|
||||
} else if (this.direction === 3) {
|
||||
//West
|
||||
sprite = new PIXI.Sprite(PIXI.Texture.fromFrame("walk_n/0001"));
|
||||
}
|
||||
sprite.y = ((this.x + this.y) * 32) - 8;
|
||||
sprite.x = (this.x - this.y) * 64;
|
||||
sprite.z = this.y + this.x + 0.1;
|
||||
this.sprite = sprite;
|
||||
|
||||
//Add inventory indicator
|
||||
this.indicator = new InventoryIndicator(this);
|
||||
this.indicator.sprite = new PIXI.Text("", {fontSize: 12, fontFamily: "c64_mono", fill: "white"});//Will be replace by a texture
|
||||
this.indicator.updateIcon = function () {
|
||||
if (this.parentObj.heldItem === 1) {
|
||||
this.sprite.text = "Biomass";
|
||||
} else if (this.parentObj.heldItem === 2) {
|
||||
this.sprite.text = "CH3OH";
|
||||
} else if (this.parentObj.heldItem === 3) {
|
||||
this.sprite.text = "Fe";
|
||||
} else if (this.parentObj.heldItem === 4) {
|
||||
this.sprite.text = "Cu";
|
||||
} else if (this.parentObj.heldItem === 5) {
|
||||
this.sprite.text = "Fe pl8";
|
||||
} else if (this.parentObj.heldItem === 6) {
|
||||
this.sprite.text = "Cu pl8";
|
||||
} else {
|
||||
this.sprite.text = "";
|
||||
}
|
||||
|
||||
};
|
||||
this.indicator.updateIcon();
|
||||
this.indicator.updatePos();
|
||||
addToWorldLayer(this.indicator.sprite);
|
||||
|
||||
} else if (this.objectType === 2) {
|
||||
//Plant
|
||||
var sprite = new PIXI.Sprite(PIXI.loader.resources["plant1"].texture); //Todo handle different plant styles
|
||||
sprite.x = (this.x - this.y) * 64 + 32;
|
||||
sprite.y = ((this.x + this.y) * 32) - 26;
|
||||
sprite.z = this.y + this.x + 0.1;
|
||||
this.sprite = sprite;
|
||||
|
||||
//todo life bar thingy indicator
|
||||
} else if (this.objectType === 3) {
|
||||
//Kiln
|
||||
this.qi = objData.qi; //Queued Iron
|
||||
this.qc = objData.qc; //Queued Copper
|
||||
this.ci = objData.ci; //Cooked Iron
|
||||
this.cc = objData.cc; //Cooked Copper
|
||||
this.f = objData.f; //fuel
|
||||
|
||||
var sprite = new PIXI.Sprite(PIXI.loader.resources["kiln"].texture);
|
||||
sprite.x = ((this.x - this.y) * 64);
|
||||
sprite.y = ((this.x + this.y) * 32) - 58;
|
||||
sprite.z = this.y + this.x + 0.1;
|
||||
this.sprite = sprite;
|
||||
|
||||
//Add inventory indicator
|
||||
this.indicator = new InventoryIndicator(this);
|
||||
this.indicator.sprite = new PIXI.Text("", {fontSize: 12, fontFamily: "c64_mono", fill: "white"});//Will be replace by a texture
|
||||
this.indicator.updateIcon = function () {
|
||||
this.sprite.text = this.parentObj.qc + ":" + this.parentObj.qi + "\n" +
|
||||
this.parentObj.cc + ":" + this.parentObj.ci + "\nf:" + this.parentObj.f;
|
||||
};
|
||||
this.indicator.updateIcon();
|
||||
this.indicator.updatePos();
|
||||
addToWorldLayer(this.indicator.sprite);
|
||||
|
||||
//todo life bar thingy indicator
|
||||
} else if (this.objectType === 4) {
|
||||
//Digester
|
||||
var sprite = new PIXI.Sprite(PIXI.loader.resources["digester"].texture);
|
||||
sprite.x = ((this.x - this.y) * 64) - 64;
|
||||
sprite.y = ((this.x + this.y) * 32) - 64;
|
||||
sprite.z = this.y + this.x + 11.1;
|
||||
this.sprite = sprite;
|
||||
|
||||
//todo life bar thingy indicator
|
||||
//todo inventory indicator
|
||||
} else if (this.objectType === 5) {
|
||||
//Rocket
|
||||
var sprite = new PIXI.Sprite(PIXI.loader.resources["rocket"].texture);
|
||||
sprite.x = (this.x - this.y) * 64;
|
||||
sprite.y = ((this.x + this.y) * 32) - 128;
|
||||
sprite.z = this.y + this.x + 0.1;
|
||||
this.sprite = sprite;
|
||||
|
||||
//todo life bar thingy indicator
|
||||
//todo progress indicator
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
GameObject.prototype.update = function () {
|
||||
|
||||
|
||||
if (this.walking === undefined) {
|
||||
|
||||
this.walking = 0;
|
||||
} else if (this.walking > 0) {
|
||||
//The object has more walking frames to do
|
||||
this.sprite.x += this.dx;
|
||||
this.sprite.y += this.dy;
|
||||
|
||||
this.walking--;
|
||||
|
||||
if (this.walking === 0) {
|
||||
//Finished walking cycle
|
||||
if (this.recalculateZAfter) {
|
||||
this.sprite.z = this.y + this.x + 0.1;
|
||||
this.recalculateZAfter = false;
|
||||
}
|
||||
} else {
|
||||
//Play 10 first frames then loop frames 10-30
|
||||
if (this.frame === undefined) {
|
||||
this.frame = 1;
|
||||
} else if (this.frame === 30) {
|
||||
this.frame = 10;
|
||||
} else {
|
||||
if (this.waitTicks === 0) {
|
||||
this.frame++;
|
||||
this.waitTicks = this.animSpeed;
|
||||
} else {
|
||||
this.waitTicks--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ((this.digging === undefined || isNaN(this.digging)) && this.action === 1) {
|
||||
//Just started digging animation
|
||||
console.log("started digging");
|
||||
this.digging = 1;
|
||||
this.action = 0;
|
||||
} else {
|
||||
//Continue digging animation
|
||||
this.digging++;
|
||||
|
||||
if (this.digging === 41) {
|
||||
//Reached end of animation
|
||||
this.digging = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.direction === 0) {
|
||||
//North
|
||||
if (this.walking !== 0) {
|
||||
this.sprite.texture = PIXI.Texture.fromFrame("walk_n/" + ("0000" + this.frame).slice(-4));
|
||||
} else if (this.digging > 0) {
|
||||
//Digging
|
||||
this.sprite.texture = PIXI.Texture.fromFrame("dig_n/" + ("0000" + this.digging).slice(-4));
|
||||
|
||||
} else {
|
||||
this.sprite.texture = PIXI.Texture.fromFrame("walk_n/0001");
|
||||
}
|
||||
|
||||
} else if (this.direction === 1) {
|
||||
//East
|
||||
if (this.walking !== 0) {
|
||||
this.sprite.texture = PIXI.Texture.fromFrame("walk_e/" + ("0000" + this.frame).slice(-4));
|
||||
} else if (this.digging > 0) {
|
||||
//Digging
|
||||
this.sprite.texture = PIXI.Texture.fromFrame("dig_e/" + ("0000" + this.digging).slice(-4));
|
||||
|
||||
} else {
|
||||
this.sprite.texture = PIXI.Texture.fromFrame("walk_e/0001");
|
||||
}
|
||||
} else if (this.direction === 2) {
|
||||
//South
|
||||
if (this.walking !== 0) {
|
||||
this.sprite.texture = PIXI.Texture.fromFrame("walk_s/" + ("0000" + this.frame).slice(-4));
|
||||
} else if (this.digging > 0) {
|
||||
//Digging
|
||||
this.sprite.texture = PIXI.Texture.fromFrame("dig_s/" + ("0000" + this.digging).slice(-4));
|
||||
|
||||
} else {
|
||||
this.sprite.texture = PIXI.Texture.fromFrame("walk_s/0001");
|
||||
}
|
||||
|
||||
} else if (this.direction === 3) {
|
||||
//West
|
||||
if (this.walking !== 0) {
|
||||
this.sprite.texture = PIXI.Texture.fromFrame("walk_w/" + ("0000" + this.frame).slice(-4));
|
||||
} else if (this.digging > 0) {
|
||||
//Digging
|
||||
this.sprite.texture = PIXI.Texture.fromFrame("dig_w/" + ("0000" + this.digging).slice(-4));
|
||||
|
||||
} else {
|
||||
this.sprite.texture = PIXI.Texture.fromFrame("walk_w/0001");
|
||||
}
|
||||
}
|
||||
|
||||
//Sync indicator icon location and z order
|
||||
this.indicator.sprite.x = this.sprite.x;
|
||||
this.indicator.sprite.y = this.sprite.y;
|
||||
this.indicator.sprite.z = this.sprite.z + 0.1;
|
||||
|
||||
MAR.worldLayer.children.sort(depthCompare);
|
||||
};
|
||||
|
||||
|
||||
//Tile
|
||||
function Tile(terrainType) {
|
||||
|
||||
if (terrainType === 0) {
|
||||
this.sprite = new PIXI.Sprite(PIXI.loader.resources["plain"].texture);
|
||||
this.sprite.x = 0;
|
||||
this.sprite.y = 0;
|
||||
this.sprite.z = 0;
|
||||
|
||||
this.sprite.hitArea = new PIXI.Polygon(
|
||||
new PIXI.Point(64, 0),
|
||||
new PIXI.Point(128, 32),
|
||||
new PIXI.Point(64, 64),
|
||||
new PIXI.Point(0, 32)
|
||||
);
|
||||
|
||||
} else if (terrainType === 1) {
|
||||
this.sprite = new PIXI.Sprite(PIXI.loader.resources["wall"].texture);
|
||||
this.sprite.x = 0;
|
||||
this.sprite.y = -40;
|
||||
this.sprite.z = 0;
|
||||
|
||||
this.sprite.hitArea = new PIXI.Polygon(
|
||||
new PIXI.Point(64, 0),
|
||||
new PIXI.Point(128, 32),
|
||||
new PIXI.Point(128, 72),
|
||||
new PIXI.Point(64, 103),
|
||||
new PIXI.Point(0, 72),
|
||||
new PIXI.Point(0, 32)
|
||||
);
|
||||
|
||||
this.wallHeight = 1;
|
||||
} else if (terrainType === 2) {
|
||||
|
||||
this.sprite = new PIXI.Sprite(PIXI.loader.resources["tile_iron"].texture);
|
||||
this.sprite.x = 0;
|
||||
this.sprite.y = 0;
|
||||
this.sprite.z = 0;
|
||||
|
||||
this.sprite.hitArea = new PIXI.Polygon(
|
||||
new PIXI.Point(64, 0),
|
||||
new PIXI.Point(128, 32),
|
||||
new PIXI.Point(64, 64),
|
||||
new PIXI.Point(0, 32)
|
||||
);
|
||||
} else if (terrainType === 3) {
|
||||
this.sprite = new PIXI.Sprite(PIXI.loader.resources["tile_copper"].texture);
|
||||
this.sprite.x = 0;
|
||||
this.sprite.y = 0;
|
||||
this.sprite.z = 0;
|
||||
|
||||
this.sprite.hitArea = new PIXI.Polygon(
|
||||
new PIXI.Point(64, 0),
|
||||
new PIXI.Point(128, 32),
|
||||
new PIXI.Point(64, 64),
|
||||
new PIXI.Point(0, 32)
|
||||
);
|
||||
}
|
||||
this.sprite.tileId = terrainType;
|
||||
|
||||
//Assigning event to each tile inefficient?
|
||||
this.sprite.interactive = true;
|
||||
|
||||
this.sprite.on("pointerover", function () {
|
||||
var tileName = "null";
|
||||
//Change tile texture to indicate hover state
|
||||
if (this.tileId === 0) {
|
||||
this.texture = PIXI.loader.resources["plain_s"].texture;
|
||||
tileName = "plain";
|
||||
} else if (this.tileId === 1) {
|
||||
this.texture = PIXI.loader.resources["wall_s"].texture;
|
||||
tileName = "wall";
|
||||
}//todo add other tiles
|
||||
|
||||
//Change info text
|
||||
//todo make this better
|
||||
MAR.currentTileText.text = "(" + this.tileX + "," + this.tileY + "," + this.z + ")\n" + tileName;
|
||||
});
|
||||
|
||||
this.sprite.on("pointerout", function () {
|
||||
//Change tile texture to indicate hover state
|
||||
if (this.tileId === 0) {
|
||||
this.texture = PIXI.loader.resources["plain"].texture;
|
||||
} else if (this.tileId === 1) {
|
||||
this.texture = PIXI.loader.resources["wall"].texture;
|
||||
}
|
||||
});
|
||||
//Behave like background when clicked
|
||||
this.sprite.on("pointerdown", pointerDown);
|
||||
this.sprite.on("pointerup", bgPointerUp);
|
||||
this.sprite.on("pointerupoutside", bgPointerUp);
|
||||
|
||||
}
|
||||
|
||||
function pointerDown(e) {
|
||||
MAR.pointerdown = true;
|
||||
MAR.pointerFirstClick = e.data.getLocalPosition(MAR.rootContainer);
|
||||
}
|
||||
|
||||
function bgPointerUp() {
|
||||
MAR.pointerdown = false;
|
||||
MAR.pointerLastDrag = null;
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
// Get an object from the current World's object list
|
||||
function getObject(id) {
|
||||
|
||||
for (var i = 0; i < MAR.objects.length; i++) {
|
||||
if (MAR.objects[i].id === id) {
|
||||
return MAR.objects[i];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
//Integer distance between 2 tiles
|
||||
function distance(x1, y1, x2, y2) {
|
||||
return Math.abs(x1 - x2) + Math.abs(y1 - y2)
|
||||
}
|
||||
|
||||
//Inventory indicator
|
||||
function InventoryIndicator(parentObj, sprite) {
|
||||
this.parentObj = parentObj;
|
||||
this.sprite = sprite;
|
||||
}
|
||||
|
||||
InventoryIndicator.prototype.updatePos = function () {
|
||||
this.sprite.x = this.parentObj.sprite.x; //todo add offSetX property
|
||||
this.sprite.y = this.parentObj.sprite.y;
|
||||
this.sprite.z = this.parentObj.sprite.z + 0.1;
|
||||
};
|
||||
|
||||
InventoryIndicator.prototype.updateIcon = function () {
|
||||
console.log("FIXME: forgot to define updateIcon");
|
||||
};
|
||||
1207
mar/phaser/mar.js
Normal file
1207
mar/phaser/mar.js
Normal file
File diff suppressed because it is too large
Load Diff
43
mar/phaser/mar.min.js
vendored
Normal file
43
mar/phaser/mar.min.js
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
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:"#FFFFFF",hologramStroke:"#9298a8",hologramAlpha:.9},mar={objects:[],animationFrames:{}};
|
||||
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 d=0;d<mar.world.tiles.length;d++){var c=mar.world.tiles[d].tileX,f=mar.world.tiles[d].tileY;mar.world.tiles[d].isWall&&(c===a&&f-1===b||c-1===a&&f-1===b||c-1===a&&f===b)&&1!==mar.world.tiles[d].alpha&&game.add.tween(mar.world.tiles[d]).to({alpha:1},175,Phaser.Easing.Quadratic.In,!0)}}
|
||||
function dispatchTileEnter(a,b){console.log("enter "+a+", "+b);for(var d=0;d<mar.world.tiles.length;d++){var c=mar.world.tiles[d].tileX,f=mar.world.tiles[d].tileY;mar.world.tiles[d].isWall&&(c===a&&f-1===b||c-1===a&&f-1===b||c-1===a&&f===b)&&game.add.tween(mar.world.tiles[d]).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 c=0;c<WORLD_HEIGHT;c++)for(var d=0;d<WORLD_HEIGHT;d++){var e=a[d*WORLD_WIDTH+c];if(1===e)e=game.add.isoSprite(getIsoX(c),getIsoY(d),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(c),getIsoY(d),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(c),getIsoY(d),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(c),getIsoY(d),0,"sheet","tiles/tile",isoGroup),e.baseZ=0,e.baseTint=colorScheme.tileTint;
|
||||
e.anchor.set(.5,0)}e.isTile=!0;e.tileX=c;e.tileY=d;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 d=b.getObject(a[c].id);null!==d?(d.updated=!0,updateGameObject(d,a[c])):(d=createGameObject(a[c]),d.updated=!0,b.objects.push(d))}for(c=0;c<b.objects.length;c++)b.objects[c].updated||(b.objects[c].destroy(),b.objects.splice(c,1))}}
|
||||
function updateGameObject(a,b){a.direction=b.direction;if(1===a.type||10===a.type){console.log(b.holo);a.action=b.action;if(a.tileX!==b.x||a.tileY!==b.y)console.log("walk"),dispatchTileLeave(a.tileX,a.tileY),a.tileX=b.x,a.tileY=b.y,cubotWalk(a,a.direction);a.heldItem!==b.heldItem&&(console.log("Update held item"+b.heldItem),void 0!==a.inventory&&a.inventory.destroy(),a.inventory=createInventory([b.heldItem]),a.addChild(a.inventory),a.heldItem=b.heldItem);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();0!==b.holo&&(a.hologram=game.make.text(0,32,"0x"+("0000"+Number(b.holo).toString(16).toUpperCase()).slice(-4),{fontSize:32,fill:colorScheme.hologramFill,stroke:colorScheme.hologramStroke,strokeThickness:1,font:"fixedsys"}),a.hologram.alpha=colorScheme.hologramAlpha,a.hologram.anchor.set(.5,0),a.addChild(a.hologram));1===a.action&&
|
||||
cubotDig(a,a.direction)}}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 d=game.make.sprite(0,0,"sheet","inventory/inv1x1");d.anchor.set(.5,.1);d.alpha=.5;var c=game.make.sprite(0,0,"sheet","inventory/item");c.anchor.set(.5,.1);c.tint=itemColor(a[0]);b.addChild(d);b.addChild(c)}return b}for(b=0;b<a.length;b++);}
|
||||
function createGameObject(a){console.log("Added "+a.type);if(1===a.type||10===a.type){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.id;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.inventory=createInventory([b.heldItem]);b.addChild(b.inventory);dispatchTileEnter(a.x,a.y);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=colorScheme.cubotTint};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}var d=game.make.text(0,-24,b.username,{fontSize:22,fill:colorScheme.textFill,stroke:colorScheme.textStroke,strokeThickness:2,font:"fixedsys"});d.alpha=.85;d.anchor.set(.5,0);b.addChild(d);0!==a.holo&&(b.hologram=game.make.text(0,32,"0x"+("0000"+Number(a.holo).toString(16).toUpperCase()).slice(-4),
|
||||
{fontSize:32,fill:colorScheme.hologramFill,stroke:colorScheme.hologramStroke,strokeThickness:1,font:"fixedsys"}),b.hologram.alpha=colorScheme.hologramAlpha,b.hologram.anchor.set(.5,0),b.addChild(b.hologram));return b}if(2===a.type){console.log("biomass");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.id;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.onTileHover=function(){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(){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}}function manhanttanDistance(a,b,d,c){return Math.abs(a-d)+Math.abs(b-c)}
|
||||
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")))}function objectListener(a){"object"===a.t&&(mar.world.updateObjects(a.objects),console.log(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){"tick"===a.t&&mar.client.socket.send(JSON.stringify({t:"object",x:mar.worldX,y:mar.worldY}))}
|
||||
var GameClient=function(a){var b=this,d=[],c=new XMLHttpRequest;c.open("GET","./getServerInfo.php",!0);c.onreadystatechange=function(){4===c.readyState&&200===c.status&&(console.log("Received server info "+c.responseText),setTimeout(function(){var f=JSON.parse(c.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);
|
||||
d.push(authListener);d.push(userInfoListener);d.push(terrainListener);d.push(tickListener);d.push(objectListener);d.push(codeListener);d.push(codeResponseListener);mar.client.socket.onmessage=function(a){try{var b=JSON.parse(a.data)}catch(h){floppyListener(a)}for(a=0;a<d.length;a++)d[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))};c.send(null);this.requestUserInfo=function(){this.socket.send(JSON.stringify({t:"userInfo"}))};this.requestTerrain=function(){console.log("request terrain");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.request=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 d in mar.world.objects){var c=mar.world.objects[d];if(c.tileX===a&&c.tileY===b)c.onTileHover()}}
|
||||
function dispatchTileOut(a,b){for(var d in mar.world.objects){var c=mar.world.objects[d];if(c.tileX===a&&c.tileY===b)c.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);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 d=game.make.isoSprite(528,1170,10,"sheet","ui/arrow_south",isoGroup);d.inputEnabled=!0;d.events.onInputDown.add(function(){mar.worldY===mar.maxWidth?mar.worldY=0:
|
||||
mar.worldY++;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);var c=game.make.isoSprite(-60,587,10,"sheet","ui/arrow_west",isoGroup);c.inputEnabled=!0;c.events.onInputDown.add(function(){0===mar.worldX?mar.worldX=mar.maxWidth:mar.worldX--;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)}function cubotDig(a,b,d){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,d){var c;if(b===DIR_SOUTH)var f=function(b){a.animations.play("walk_s",60,!0);c=game.add.tween(a).to({isoX:getIsoX(a.tileX),isoY:getIsoY(a.tileY)},b,Phaser.Easing.Linear.None,!0);dispatchTileEnter(a.tileX,a.tileY);c.onComplete.add(function(){a.animations.stop();a.animations.frame=240;a.onTileOut();a.isoX=getIsoX(a.tileX);a.isoY=getIsoY(a.tileY);void 0!==d&&d();for(var b=0;b<a.queuedAnims.length;b++)a.queuedAnims[b](500),a.queuedAnims.splice(b,1)})};else b===DIR_NORTH?f=function(b){a.animations.play("walk_n",
|
||||
60,!0);c=game.add.tween(a).to({isoX:getIsoX(a.tileX),isoY:getIsoY(a.tileY)},b,Phaser.Easing.Linear.None,!0);dispatchTileEnter(a.tileX,a.tileY);c.onComplete.add(function(){a.animations.stop();a.animations.frame=194;a.onTileOut();a.isoX=getIsoX(a.tileX);a.isoY=getIsoY(a.tileY);void 0!==d&&d();for(var b=0;b<a.queuedAnims.length;b++)a.queuedAnims[b](500),a.queuedAnims.splice(b,1)})}:b===DIR_WEST?f=function(b){a.animations.play("walk_w",60,!0);c=game.add.tween(a).to({isoX:getIsoX(a.tileX),isoY:getIsoY(a.tileY)},
|
||||
b,Phaser.Easing.Linear.None,!0);dispatchTileEnter(a.tileX,a.tileY);c.onComplete.add(function(){a.animations.stop();a.animations.frame=254;a.onTileOut();a.isoX=getIsoX(a.tileX);a.isoY=getIsoY(a.tileY);void 0!==d&&d();for(var b=0;b<a.queuedAnims.length;b++)a.queuedAnims[b](500),a.queuedAnims.splice(b,1)})}:b===DIR_EAST&&(f=function(b){a.animations.play("walk_e",60,!0);c=game.add.tween(a).to({isoX:getIsoX(a.tileX),isoY:getIsoY(a.tileY)},b,Phaser.Easing.Linear.None,!0);dispatchTileEnter(a.tileX,a.tileY);
|
||||
c.onComplete.add(function(){a.animations.stop();a.animations.frame=164;a.onTileOut();a.isoX=getIsoX(a.tileX);a.isoY=getIsoY(a.tileY);void 0!==d&&d();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(f),console.log("Queued Animation")):f(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.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.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.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.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}game.state.add("Boot",BasicGame.Boot);game.state.start("Boot");
|
||||
4446
mar/phaser/phaser-plugin-isometric.js
Normal file
4446
mar/phaser/phaser-plugin-isometric.js
Normal file
File diff suppressed because it is too large
Load Diff
3
mar/phaser/phaser-plugin-isometric.min.js
vendored
Normal file
3
mar/phaser/phaser-plugin-isometric.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
104323
mar/phaser/phaser.js
Normal file
104323
mar/phaser/phaser.js
Normal file
File diff suppressed because it is too large
Load Diff
4
mar/phaser/phaser.min.js
vendored
Normal file
4
mar/phaser/phaser.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
4440
mar/sprites.json
Normal file
4440
mar/sprites.json
Normal file
File diff suppressed because it is too large
Load Diff
BIN
mar/sprites.png
Normal file
BIN
mar/sprites.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 574 KiB |
BIN
mar/sprites/err_annotation.png
Executable file
BIN
mar/sprites/err_annotation.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 324 B |
Reference in New Issue
Block a user