Major refactor of the console screen, game code rewritten in Typescript, users can now change their passwords
46
account.php
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
include_once "include/MessageCookie.php";
|
||||
include_once "include/SessionManager.php";
|
||||
|
||||
$register_msg = MessageCookie::getMsg("register");
|
||||
$user = SessionManager::get();
|
||||
?>
|
||||
|
||||
@ -42,18 +42,44 @@ $user = SessionManager::get();
|
||||
<div id="main" class="container">
|
||||
<div class="row 200%">
|
||||
<div class="12u">
|
||||
<div class="container">
|
||||
<!-- Account information -->
|
||||
<section>
|
||||
<p>You are logged in as <span style="font-style: italic"><?php echo $user["username"] ?></span>
|
||||
</p>
|
||||
|
||||
<!-- Account information -->
|
||||
<section id="login">
|
||||
<p>You are logged in as <span style="font-style: italic"><?php echo $user["username"] ?></span></p>
|
||||
<?php
|
||||
if ($register_msg) {
|
||||
echo "<span style='color:#ff4943'>" . $register_msg . "</span></div>";
|
||||
}
|
||||
?>
|
||||
|
||||
<p>Account page is under construction</p>
|
||||
</section>
|
||||
<!-- Password reset form -->
|
||||
<form action="changePassword.re.php" method="post">
|
||||
<div class="row uniform">
|
||||
<div class="6u 12u(xsmall)">
|
||||
<label for="password">Current password</label>
|
||||
<input id="password" name="password" type="password">
|
||||
</div>
|
||||
|
||||
<div class="6u 12u(xsmall)">
|
||||
<label for="new_password">New Password</label>
|
||||
<input id="new_password" name="new_password" type="password">
|
||||
</div>
|
||||
|
||||
<div class="6u 12u(xsmall)">
|
||||
<input type="submit" value="Reset password">
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</section>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include "footer.inc.html" ?>
|
||||
<?php // include "footer.inc.html" ?>
|
||||
|
||||
|
||||
</div>
|
||||
@ -62,10 +88,10 @@ $user = SessionManager::get();
|
||||
<script src="assets/js/jquery.min.js"></script>
|
||||
<script src="assets/js/jquery.dropotron.min.js"></script>
|
||||
<script src="assets/js/skel.min.js"></script>
|
||||
<script src="assets/js/util.js"></script>
|
||||
<script src="assets/js/util.min.js"></script>
|
||||
<!--[if lte IE 8]>
|
||||
<script src="assets/js/ie/respond.min.js"></script><![endif]-->
|
||||
<script src="assets/js/main.js"></script>
|
||||
<script src="assets/js/main.min.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
10
assets/js/util.min.js
vendored
@ -7,8 +7,8 @@ g.delay))};a.css("-ms-overflow-style","-ms-autohiding-scrollbar").css("-webkit-o
|
||||
a.touchPosY=c.originalEvent.touches[0].pageY});a.on("touchmove",function(c){if(null!==a.touchPosX&&null!==a.touchPosY){var f=a.touchPosX-c.originalEvent.touches[0].pageX,d=a.touchPosY-c.originalEvent.touches[0].pageY,e=a.outerHeight(),h=a.get(0).scrollHeight-a.scrollTop();if(g.hideOnSwipe){var k=!1;switch(g.side){case "left":k=20>d&&-20<d&&50<f;break;case "right":k=20>d&&-20<d&&-50>f;break;case "top":k=20>f&&-20<f&&50<d;break;case "bottom":k=20>f&&-20<f&&-50>d}if(k)return a.touchPosX=null,a.touchPosY=
|
||||
null,a._hide(),!1}if(0>a.scrollTop()&&0>d||h>e-2&&h<e+2&&0<d)c.preventDefault(),c.stopPropagation()}});a.on("click touchend touchstart touchmove",function(a){a.stopPropagation()});a.on("click",'a[href="#'+h+'"]',function(a){a.preventDefault();a.stopPropagation();g.target.removeClass(g.visibleClass)});d.on("click touchend",function(c){a._hide(c)});d.on("click",'a[href="#'+h+'"]',function(a){a.preventDefault();a.stopPropagation();g.target.toggleClass(g.visibleClass)});if(g.hideOnEscape)f.on("keydown",
|
||||
function(c){27==c.keyCode&&a._hide(c)});return a};c.fn.placeholder=function(){if("undefined"!=typeof document.createElement("input").placeholder)return c(this);if(0==this.length)return d;if(1<this.length){for(var e=0;e<this.length;e++)c(this[e]).placeholder();return d}var d=c(this);d.find("input[objType=text],textarea").each(function(){var a=c(this);""!=a.val()&&a.val()!=a.attr("placeholder")||a.addClass("polyfill-placeholder").val(a.attr("placeholder"))}).on("blur",function(){var a=c(this);a.attr("name").match(/-polyfill-field$/)||
|
||||
""==a.val()&&a.addClass("polyfill-placeholder").val(a.attr("placeholder"))}).on("focus",function(){var a=c(this);a.attr("name").match(/-polyfill-field$/)||a.val()==a.attr("placeholder")&&a.removeClass("polyfill-placeholder").val("")});d.find("input[objType=password]").each(function(){var a=c(this),f=c(c("<div>").append(a.clone()).remove().html().replace(/type="password"/i,'objType="text"').replace(/type=password/i,"objType=text"));""!=a.attr("id")&&f.attr("id",a.attr("id")+"-polyfill-field");""!=a.attr("name")&&
|
||||
f.attr("name",a.attr("name")+"-polyfill-field");f.addClass("polyfill-placeholder").val(f.attr("placeholder")).insertAfter(a);""==a.val()?a.hide():f.hide();a.on("blur",function(c){c.preventDefault();c=a.parent().find("input[name="+a.attr("name")+"-polyfill-field]");""==a.val()&&(a.hide(),c.show())});f.on("focus",function(a){a.preventDefault();a=f.parent().find("input[name="+f.attr("name").replace("-polyfill-field","")+"]");f.hide();a.show().focus()}).on("keypress",function(a){a.preventDefault();f.val("")})});
|
||||
d.on("submit",function(){d.find("input[objType=text],input[objType=password],textarea").each(function(a){a=c(this);a.attr("name").match(/-polyfill-field$/)&&a.attr("name","");a.val()==a.attr("placeholder")&&(a.removeClass("polyfill-placeholder"),a.val(""))})}).on("reset",function(a){a.preventDefault();d.find("select").val(c("option:first").val());d.find("input,textarea").each(function(){var a=c(this);a.removeClass("polyfill-placeholder");switch(this.type){case "submit":case "reset":break;case "password":a.val(a.attr("defaultValue"));
|
||||
var d=a.parent().find("input[name="+a.attr("name")+"-polyfill-field]");""==a.val()?(a.hide(),d.show()):(a.show(),d.hide());break;case "checkbox":case "radio":a.attr("checked",a.attr("defaultValue"));break;case "text":case "textarea":a.val(a.attr("defaultValue"));""==a.val()&&(a.addClass("polyfill-placeholder"),a.val(a.attr("placeholder")));break;default:a.val(a.attr("defaultValue"))}})});return d};c.prioritize=function(e,d){"jQuery"!=typeof e&&(e=c(e));e.each(function(){var a=c(this),f=a.parent();
|
||||
if(0!=f.length)if(a.data("__prioritize")){if(!d){var e=a.data("__prioritize");a.insertAfter(e);a.removeData("__prioritize")}}else d&&(e=a.prev(),0!=e.length&&(a.prependTo(f),a.data("__prioritize",e)))})}})(jQuery);
|
||||
""==a.val()&&a.addClass("polyfill-placeholder").val(a.attr("placeholder"))}).on("focus",function(){var a=c(this);a.attr("name").match(/-polyfill-field$/)||a.val()==a.attr("placeholder")&&a.removeClass("polyfill-placeholder").val("")});d.find("input[objType=password]").each(function(){var a=c(this),f=c(c("<div>").append(a.clone()).remove().html().replace(/type="password"/i,'objType="text"').replace(/type=password/i,"objType=text"));""!=a.attr("id")&&f.attr("id",a.attr("id")+"-polyfill-field");""!=
|
||||
a.attr("name")&&f.attr("name",a.attr("name")+"-polyfill-field");f.addClass("polyfill-placeholder").val(f.attr("placeholder")).insertAfter(a);""==a.val()?a.hide():f.hide();a.on("blur",function(c){c.preventDefault();c=a.parent().find("input[name="+a.attr("name")+"-polyfill-field]");""==a.val()&&(a.hide(),c.show())});f.on("focus",function(a){a.preventDefault();a=f.parent().find("input[name="+f.attr("name").replace("-polyfill-field","")+"]");f.hide();a.show().focus()}).on("keypress",function(a){a.preventDefault();
|
||||
f.val("")})});d.on("submit",function(){d.find("input[objType=text],input[objType=password],textarea").each(function(a){a=c(this);a.attr("name").match(/-polyfill-field$/)&&a.attr("name","");a.val()==a.attr("placeholder")&&(a.removeClass("polyfill-placeholder"),a.val(""))})}).on("reset",function(a){a.preventDefault();d.find("select").val(c("option:first").val());d.find("input,textarea").each(function(){var a=c(this);a.removeClass("polyfill-placeholder");switch(this.type){case "submit":case "reset":break;
|
||||
case "password":a.val(a.attr("defaultValue"));var d=a.parent().find("input[name="+a.attr("name")+"-polyfill-field]");""==a.val()?(a.hide(),d.show()):(a.show(),d.hide());break;case "checkbox":case "radio":a.attr("checked",a.attr("defaultValue"));break;case "text":case "textarea":a.val(a.attr("defaultValue"));""==a.val()&&(a.addClass("polyfill-placeholder"),a.val(a.attr("placeholder")));break;default:a.val(a.attr("defaultValue"))}})});return d};c.prioritize=function(e,d){"jQuery"!=typeof e&&(e=c(e));
|
||||
e.each(function(){var a=c(this),f=a.parent();if(0!=f.length)if(a.data("__prioritize")){if(!d){var e=a.data("__prioritize");a.insertAfter(e);a.removeData("__prioritize")}}else d&&(e=a.prev(),0!=e.length&&(a.prependTo(f),a.data("__prioritize",e)))})}})(jQuery);
|
||||
|
39
changePassword.re.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
|
||||
include_once "include/UserManager.php";
|
||||
include_once "include/MessageCookie.php";
|
||||
include_once "include/SessionManager.php";
|
||||
|
||||
$user = SessionManager::get();
|
||||
|
||||
if ($user != NULL) {
|
||||
|
||||
$password = $_POST['password'];
|
||||
$newPassword = $_POST['new_password'];
|
||||
|
||||
if (strlen($newPassword) < 8 || strlen($newPassword) > 96) {
|
||||
|
||||
(new MessageCookie("Password must be 8-96 characters", "register"))->setCookie();
|
||||
header("Location: account.php");
|
||||
} else {
|
||||
|
||||
if (UserManager::auth($user['username'], $password) != NULL) {
|
||||
|
||||
UserManager::changePassword($user['username'], $newPassword);
|
||||
|
||||
header("Location: index.php");
|
||||
|
||||
} else {
|
||||
$msg = new MessageCookie("Invalid password", "register");
|
||||
$msg->setCookie();
|
||||
header("Location: account.php");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
$msg = new MessageCookie("You must be logged in to do that", "register");
|
||||
$msg->setCookie();
|
||||
header("Location: account.php");
|
||||
}
|
249
game.php
@ -15,7 +15,7 @@ if (isset($user)) {
|
||||
<html>
|
||||
<head>
|
||||
<title><?php echo MAR_SERVER_NAME ?></title>
|
||||
<meta name="description" content="Offical Much Assembly Required game server page">
|
||||
<meta name="description" content="Official Much Assembly Required game server page">
|
||||
<meta charset="utf-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<!--[if lte IE 8]>
|
||||
@ -24,6 +24,7 @@ if (isset($user)) {
|
||||
<!--[if lte IE 8]>
|
||||
<link rel="stylesheet" href="assets/css/ie8.min.css"/><![endif]-->
|
||||
<link rel="stylesheet" href="font-awesome-4.7.0/css/font-awesome.min.css">
|
||||
<link rel="stylesheet" href="mar/console.min.css">
|
||||
|
||||
|
||||
<script src="assets/js/jquery.min.js"></script>
|
||||
@ -34,7 +35,7 @@ if (isset($user)) {
|
||||
<script src="assets/js/ie/respond.min.js"></script><![endif]-->
|
||||
<script src="assets/js/main.min.js"></script>
|
||||
|
||||
<script src="FileSaver.min.js"></script>
|
||||
<script src="assets/js/FileSaver.min.js"></script>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="./mar/game.css">
|
||||
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
|
||||
@ -68,57 +69,10 @@ if (isset($user)) {
|
||||
<div class="12u 12u(mobile) important(mobile)">
|
||||
<div class="content content-left">
|
||||
|
||||
<style>
|
||||
#tabs ul, li, a {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
#tabs .ui-tabs-nav li.ui-tabs-active a {
|
||||
background: #a1cd9b;
|
||||
}
|
||||
|
||||
#editorBtns {
|
||||
display: inline;
|
||||
|
||||
}
|
||||
|
||||
.editorBtn {
|
||||
background: #895EC3;
|
||||
padding: .85em 1em
|
||||
}
|
||||
|
||||
.editorBtn:hover {
|
||||
background: #A386CA;
|
||||
}
|
||||
|
||||
#gameBtns {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
#console {
|
||||
font-family: fixedsys, monospace;
|
||||
font-size: 24pt;
|
||||
line-height: 21px;
|
||||
resize: none;
|
||||
overflow-y: scroll;
|
||||
width: 680px;
|
||||
height: 180px;
|
||||
}
|
||||
|
||||
#consoleContainer {
|
||||
margin: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
|
||||
</style>
|
||||
|
||||
<script>
|
||||
$(function () {
|
||||
$("#tabs").tabs();
|
||||
});
|
||||
|
||||
fullscreen = false;
|
||||
</script>
|
||||
|
||||
<!-- Game box -->
|
||||
@ -128,30 +82,33 @@ if (isset($user)) {
|
||||
<li><a class="button alt" href="#game" onclick="gameClick()">Game</a>
|
||||
</li>
|
||||
<?php if($user) { ?>
|
||||
<li><a class="button alt" href="#editorTab" onclick="editorClick()">Editor</a>
|
||||
</li>
|
||||
<li><a class="button alt" href="#editorTab" onclick="editorClick()">Editor</a>
|
||||
</li>
|
||||
<?php } else { ?>
|
||||
<li><a class="button alt" onclick="window.location = '/login.php';">Editor</a>
|
||||
</li>
|
||||
<li><a class="button alt" onclick="window.location = 'login.php';">Editor</a>
|
||||
</li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
|
||||
<!-- Editor buttons -->
|
||||
<?php if($user) { ?>
|
||||
<div id="editorBtns" style="display: none">
|
||||
<a class="button editorBtn" onclick="mar.client.uploadCode(ace.edit('editor').getValue())">Upload</a>
|
||||
<a class="button editorBtn" onclick="mar.client.reloadCode()">Reload</a>
|
||||
<a class="button editorBtn" id="floppyDown" onclick="mar.client.requestFloppy()"><i
|
||||
class="fa fa-long-arrow-down" aria-hidden="true"></i> <i class="fa fa-floppy-o"
|
||||
aria-hidden="true"></i></a>
|
||||
<button class="editorBtn" id="floppyUp"
|
||||
onclick="document.getElementById('floppyIn').click();"><i
|
||||
class="fa fa-long-arrow-up" aria-hidden="true"></i> <i class="fa fa-floppy-o"
|
||||
aria-hidden="true"></i>
|
||||
</button>
|
||||
<!-- Style the select to something more select'y -->
|
||||
<select title="Select Theme" class="button editorBtn" id="editorTheme"></select>
|
||||
</div>
|
||||
<div id="editorBtns" style="display: none">
|
||||
<a class="button editorBtn"
|
||||
onclick="mar.client.uploadCode(ace.edit('editor').getValue())">Upload</a>
|
||||
<a class="button editorBtn" onclick="mar.client.reloadCode()">Reload</a>
|
||||
<a class="button editorBtn" id="floppyDown" onclick="mar.client.requestFloppy()"><i
|
||||
class="fa fa-long-arrow-down" aria-hidden="true"></i> <i
|
||||
class="fa fa-floppy-o"
|
||||
aria-hidden="true"></i></a>
|
||||
<button class="editorBtn" id="floppyUp"
|
||||
onclick="document.getElementById('floppyIn').click();"><i
|
||||
class="fa fa-long-arrow-up" aria-hidden="true"></i> <i
|
||||
class="fa fa-floppy-o"
|
||||
aria-hidden="true"></i>
|
||||
</button>
|
||||
<!-- Style the select to something more select'y -->
|
||||
<select title="Select Theme" class="button editorBtn" id="editorTheme"></select>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div id="gameBtns">
|
||||
@ -171,120 +128,17 @@ if (isset($user)) {
|
||||
|
||||
<!-- Game -->
|
||||
<div id="game" tabindex="0">
|
||||
<script src="./mar/phaser/phaser.min.js"></script>
|
||||
<script src="./mar/phaser/phaser-plugin-isometric.min.js"></script>
|
||||
<script src="./mar/phaser/World.js"></script>
|
||||
<script src="./mar/phaser/MarGame.js"></script>
|
||||
<script src="./mar/phaser/GameClient.js"></script>
|
||||
<script src="./mar/phaser/GameObject.js"></script>
|
||||
<script src="mar/phaser/mar.js"></script>
|
||||
<script src="mar/phaser.min.js"></script>
|
||||
<script src="mar/phaser-plugin-isometric.min.js"></script>
|
||||
<script src="mar/app.min.js"></script>
|
||||
</div>
|
||||
<?php if ($user) { ?>
|
||||
<!-- Editor -->
|
||||
<div id="editorTab">
|
||||
<div id="editor"></div>
|
||||
<script src="./mar/ace/ace.js" type="text/javascript" charset="utf-8"></script>
|
||||
|
||||
<script src="./mar/editor.js"></script>
|
||||
<script>
|
||||
//Check if browser supports local storage if not than bad luck, use something else than IE7
|
||||
var editorStorage;
|
||||
if(typeof window.localStorage !== 'undefined') {
|
||||
editorStorage = window.localStorage;
|
||||
} else {
|
||||
editorStorage = false;
|
||||
}
|
||||
|
||||
//Default should be 'theme/tommorow.js' or loaded from local storage
|
||||
var editorThemeOptions = {
|
||||
available : [
|
||||
"theme/ambiance", "theme/chaos", "theme/chrome",
|
||||
"theme/clouds", "theme/clouds_midnight", "theme/cobalt",
|
||||
"theme/crimson_editor", "theme/dawn", "theme/dracula",
|
||||
"theme/dreamweaver", "theme/eclipse", "theme/github",
|
||||
"theme/gob", "theme/gruvbox", "theme/idle_fingers",
|
||||
"theme/iplastic", "theme/katzenmilch", "theme/kr_theme",
|
||||
"theme/kuroir", "theme/merbivore", "theme/merbivore_soft",
|
||||
"theme/mono_industrial", "theme/monokai", "theme/pastel_on_dark",
|
||||
"theme/solarized_dark", "theme/solarized_light", "theme/sqlserver",
|
||||
"theme/terminal", "theme/textmate", "theme/tomorrow",
|
||||
"theme/tomorrow_night_blue", "theme/tomorrow_night_bright", "theme/tomorrow_night_eighties",
|
||||
"theme/tomorrow_night", "theme/twilight", "theme/vibrant_ink", "theme/xcode"
|
||||
],
|
||||
default : "theme/tomorrow"
|
||||
};
|
||||
|
||||
//Get the stored default theme
|
||||
if(editorStorage) {
|
||||
var storedTheme = editorStorage.getItem('editorTheme');
|
||||
if (storedTheme !== null && editorThemeOptions.available.indexOf(storedTheme) !== -1) {
|
||||
editorThemeOptions.default = storedTheme;
|
||||
}
|
||||
}
|
||||
|
||||
//Cache element reference
|
||||
var editorThemeSelectElement = document.getElementById("editorTheme");
|
||||
|
||||
//Event handler
|
||||
function editorOnThemeChange() {
|
||||
if(editorThemeSelectElement === null) {
|
||||
console.error("editorOnThemeChange() :: editorThemeSelectElement seems to be 'null'");
|
||||
return;
|
||||
}
|
||||
var select = editorThemeSelectElement;
|
||||
var option = select.options[select.selectedIndex];
|
||||
|
||||
if (editorThemeOptions.available.indexOf(option.value) === -1) {
|
||||
console.error("editorOnThemeChange() :: user somehow selected an invalid theme : '" + option.value + "' for '" + option.text + "'");
|
||||
return;
|
||||
}
|
||||
|
||||
//Store locally so it gets remembered
|
||||
if(editorStorage) {
|
||||
editorStorage.setItem('editorTheme', option.value);
|
||||
}
|
||||
|
||||
//Set theme
|
||||
editor.setTheme("ace/" + option.value);
|
||||
}
|
||||
|
||||
//Add handler to listen to event
|
||||
editorThemeSelectElement.addEventListener('change', editorOnThemeChange);
|
||||
|
||||
//Populate select
|
||||
editorThemeOptions.available.forEach(function(theme) {
|
||||
var option = document.createElement("option");
|
||||
option.value = theme;
|
||||
option.text = theme.substring(6); // "theme/{text}" -> extract text to set as text user sees
|
||||
|
||||
//Make sure default is also the one that is selected
|
||||
if(theme === editorThemeOptions.default) {
|
||||
option.selected = true;
|
||||
}
|
||||
|
||||
editorThemeSelectElement.appendChild(option);
|
||||
});
|
||||
|
||||
//Manually call handler once
|
||||
editorOnThemeChange();
|
||||
|
||||
editor.getSession().setMode("ace/mode/mar");
|
||||
editor.setFontSize(16);
|
||||
editor.setDisplayIndentGuides(false);
|
||||
document.getElementById('editor').style.fontFamily="fixedsys";
|
||||
</script>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Console-->
|
||||
<div id="consoleContainer">
|
||||
<textarea id="console" readonly title="console"></textarea>
|
||||
|
||||
<a class="button" style="vertical-align: top"
|
||||
onclick="document.getElementById('console').innerHTML=''">Clear</a>
|
||||
</div>
|
||||
|
||||
<!-- Editor -->
|
||||
<div id="editorTab">
|
||||
<div id="editor"></div>
|
||||
<script src="./mar/ace/ace.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="./mar/editor.min.js"></script>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
|
||||
@ -293,6 +147,7 @@ if (isset($user)) {
|
||||
</form>
|
||||
|
||||
<script>
|
||||
//Todo move that to file
|
||||
document.getElementById("floppyIn").onchange = function () {
|
||||
|
||||
document.getElementById("floppyUp").innerHTML = "<i class=\"fa fa-cog fa-spin fa-fw\" aria-hidden=\"true\"></i>";
|
||||
@ -322,10 +177,42 @@ if (isset($user)) {
|
||||
};
|
||||
xhr.send(formData);
|
||||
};
|
||||
|
||||
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<!-- Console-->
|
||||
<div id="console-wrapper">
|
||||
<div id="shadow-wrapper">
|
||||
<div id="console-wrapper-left" class="noisy">
|
||||
<div class="frame">
|
||||
<div id="consoleText" class="piece output noclick ctr-selection ctr-text"></div>
|
||||
<div class="piece scanlines noclick"></div>
|
||||
<div class="piece glow noclick"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="console-wrapper-side">
|
||||
<div class="sideFrame">
|
||||
|
||||
<!-- Console Buttons -->
|
||||
<span class="vertical-text">COLOR</span>
|
||||
<img id="colorButton" src="images/pdp8ion.png" class="pdp8Button">
|
||||
|
||||
<span class="vertical-text" style="left: 25px;">SCROLL</span>
|
||||
<img id="scrollButton" src="images/pdp8ioff.png" class="pdp8Button">
|
||||
|
||||
<span class="vertical-text" style="left: 55px;">RESET</span>
|
||||
<img id="resetButton" src="images/pdp8ion.png" class="pdp8Button">
|
||||
|
||||
<!-- width Dial -->
|
||||
<div class="dial-backPlate">
|
||||
<img src="images/knob-65.png" class="dial" id="widthDial">
|
||||
<img src="images/lines.png" class="dial-lines">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
13
images/LICENSE for pdp8.txt
Normal file
@ -0,0 +1,13 @@
|
||||
pdp8i*.png images taken from https://github.com/j-hoppe/BlinkenBone/
|
||||
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Joerg Hoppe
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
Before Width: | Height: | Size: 6.4 KiB |
Before Width: | Height: | Size: 96 KiB |
Before Width: | Height: | Size: 324 B After Width: | Height: | Size: 324 B |
Before Width: | Height: | Size: 98 KiB |
BIN
images/knob-10.png
Normal file
After Width: | Height: | Size: 110 KiB |
BIN
images/knob-123.png
Normal file
After Width: | Height: | Size: 110 KiB |
BIN
images/knob-170.png
Normal file
After Width: | Height: | Size: 113 KiB |
BIN
images/knob-65.png
Normal file
After Width: | Height: | Size: 110 KiB |
BIN
images/knob-90.png
Normal file
After Width: | Height: | Size: 108 KiB |
BIN
images/lines.png
Normal file
After Width: | Height: | Size: 657 B |
BIN
images/pdp8ioff.png
Normal file
After Width: | Height: | Size: 3.7 KiB |
BIN
images/pdp8ion.png
Normal file
After Width: | Height: | Size: 3.5 KiB |
@ -71,7 +71,38 @@ class UserManager
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the password of an user
|
||||
* @param $username string
|
||||
* @param $newPassword string plain text new password
|
||||
* @return bool sucess
|
||||
*/
|
||||
public static function changePassword($username, $newPassword)
|
||||
{
|
||||
$conn = new SqlConnection();
|
||||
|
||||
$stmt_select = $conn->prepare("SELECT username FROM mar_user WHERE username=?");
|
||||
$stmt_select->bindValue(1, $username);
|
||||
$stmt_select->execute();
|
||||
|
||||
$bdUser = $stmt_select->fetchObject();
|
||||
|
||||
if ($bdUser) {
|
||||
|
||||
$stmt_update = $conn->prepare("UPDATE mar_user SET password=? WHERE username=?");
|
||||
|
||||
$stmt_update->bindValue(1, password_hash($newPassword, PASSWORD_DEFAULT));
|
||||
$stmt_update->bindValue(2, $username);
|
||||
|
||||
$stmt_update->execute();
|
||||
|
||||
return TRUE;
|
||||
|
||||
} else {
|
||||
//User not found
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
@ -26,7 +26,7 @@ $user = SessionManager::get();
|
||||
|
||||
@font-face {
|
||||
font-family: 'fixedsys';
|
||||
src: url("./mar/fonts/FSEX301-L2.ttf");
|
||||
src: url("assets/fonts/FSEX301-L2.ttf");
|
||||
}
|
||||
|
||||
</style>
|
||||
|
231
mar/Console.ts
Normal file
@ -0,0 +1,231 @@
|
||||
//todo pull this off the server or something?
|
||||
let defaultText =
|
||||
" _______ __ __\n" +
|
||||
"| _ |.-----.---.-.----.| |--.|__|.----.-----.----.-----.\n" +
|
||||
"| || _ | _ | __|| || || __| _ | _| _ |\n" +
|
||||
"|___|___|| __|___._|____||__|__||__||____|_____|__| | __|\n" +
|
||||
" |__| |__|\n" +
|
||||
"\n" +
|
||||
"Version 1.3A, 1985-05-17\n" +
|
||||
"Initialising Universal Communication Port connection...Done\n" +
|
||||
"Current date is 2790-01-14\n" +
|
||||
"Cubot Status: Much Assembly Required" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
"More text down here\n";
|
||||
|
||||
enum ConsoleMode {
|
||||
CLEAR,
|
||||
NORMAL
|
||||
}
|
||||
|
||||
interface ConsoleScreen {
|
||||
|
||||
toggleColor(self: ConsoleScreen): void;
|
||||
|
||||
toggleScrolling(self: ConsoleScreen): void;
|
||||
|
||||
reset(self: ConsoleScreen): void;
|
||||
|
||||
handleConsoleBufferUpdate(consoleBuffer: string[], mode: ConsoleMode): void;
|
||||
}
|
||||
|
||||
class PlainTextConsoleMode {
|
||||
|
||||
public width: number;
|
||||
public dialImage: string;
|
||||
|
||||
|
||||
constructor(lineWidth: number, dialImage: string) {
|
||||
this.width = lineWidth;
|
||||
this.dialImage = dialImage;
|
||||
}
|
||||
}
|
||||
|
||||
class PlainTextConsole implements ConsoleScreen {
|
||||
|
||||
private txtDiv: HTMLElement;
|
||||
private colorButton: HTMLImageElement;
|
||||
private scrollButton: HTMLImageElement;
|
||||
private resetButton: HTMLImageElement;
|
||||
private widthDial: HTMLImageElement;
|
||||
|
||||
private colorToggled: boolean = false;
|
||||
public autoScroll: boolean = true;
|
||||
|
||||
private modes: PlainTextConsoleMode[] = [];
|
||||
private mode: number;
|
||||
|
||||
/**
|
||||
* Contents of the
|
||||
*/
|
||||
private consoleText: string;
|
||||
|
||||
/**
|
||||
* Length of the last line
|
||||
* @type {number}
|
||||
*/
|
||||
private lastLineLength: number = 0;
|
||||
|
||||
constructor(text: string, id: string, colorId: string, scrollId: string, resetID: string, dialId: string) {
|
||||
this.txtDiv = document.getElementById(id);
|
||||
this.colorButton = document.getElementById(colorId) as HTMLImageElement;
|
||||
this.scrollButton = document.getElementById(scrollId) as HTMLImageElement;
|
||||
this.resetButton = document.getElementById(resetID) as HTMLImageElement;
|
||||
this.widthDial = document.getElementById(dialId) as HTMLImageElement;
|
||||
|
||||
let self = this;
|
||||
this.colorButton.onclick = function () {
|
||||
self.toggleColor(self)
|
||||
};
|
||||
this.scrollButton.onclick = function () {
|
||||
self.toggleScrolling(self)
|
||||
};
|
||||
this.resetButton.onclick = function () {
|
||||
self.reset(self);
|
||||
};
|
||||
this.widthDial.onclick = function () {
|
||||
PlainTextConsole.widthDialClick(self);
|
||||
};
|
||||
|
||||
this.txtDiv.innerHTML = text;
|
||||
this.consoleText = text;
|
||||
|
||||
//Line width modes. Might break if shorter than
|
||||
this.modes.push(new PlainTextConsoleMode(16, "./images/knob-170.png"));
|
||||
this.modes.push(new PlainTextConsoleMode(24, "./images/knob-123.png"));
|
||||
this.modes.push(new PlainTextConsoleMode(40, "./images/knob-90.png"));
|
||||
this.modes.push(new PlainTextConsoleMode(56, "./images/knob-65.png"));
|
||||
this.modes.push(new PlainTextConsoleMode(64, "./images/knob-10.png"));
|
||||
this.mode = 3; //Mode 56
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle dark/light theme
|
||||
*/
|
||||
public toggleColor(self: PlainTextConsole): void {
|
||||
|
||||
if (self.colorToggled) {
|
||||
self.colorToggled = false;
|
||||
self.colorButton.src = "./images/pdp8ion.png";
|
||||
|
||||
self.txtDiv.classList.remove("ctr-selection-inverted");
|
||||
self.txtDiv.classList.remove("ctr-text-inverted");
|
||||
self.txtDiv.classList.add("ctr-selection");
|
||||
self.txtDiv.classList.add("ctr-text");
|
||||
|
||||
} else {
|
||||
self.colorToggled = true;
|
||||
self.colorButton.src = "./images/pdp8ioff.png";
|
||||
|
||||
self.txtDiv.classList.add("ctr-selection-inverted");
|
||||
self.txtDiv.classList.add("ctr-text-inverted");
|
||||
self.txtDiv.classList.remove("ctr-selection");
|
||||
self.txtDiv.classList.remove("ctr-text");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle auto scrolling. Also initially scrolls to bottom on click
|
||||
*/
|
||||
public toggleScrolling(self: PlainTextConsole): void {
|
||||
|
||||
if (self.autoScroll) {
|
||||
|
||||
self.autoScroll = false;
|
||||
self.scrollButton.src = "./images/pdp8ion.png";
|
||||
|
||||
} else {
|
||||
self.autoScroll = true;
|
||||
self.scrollButton.src = "./images/pdp8ioff.png";
|
||||
|
||||
//Scroll to bottom
|
||||
self.txtDiv.scrollTop = self.txtDiv.scrollHeight;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the console screen
|
||||
*/
|
||||
public reset(self: PlainTextConsole): void {
|
||||
|
||||
self.txtDiv.innerHTML = "";
|
||||
self.consoleText = "";
|
||||
self.lastLineLength = 0;
|
||||
|
||||
self.resetButton.src = "./images/pdp8ioff.png";
|
||||
|
||||
window.setTimeout(function () {
|
||||
self.resetButton.src = "./images/pdp8ion.png";
|
||||
}, 150);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Update dial image and change console mode
|
||||
*/
|
||||
private static widthDialClick(self: PlainTextConsole): void {
|
||||
if (self.mode < self.modes.length - 1) {
|
||||
self.mode++;
|
||||
} else {
|
||||
self.mode = 0;
|
||||
}
|
||||
|
||||
//Update dial image
|
||||
self.widthDial.src = self.modes[self.mode].dialImage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a consoleBuffer update
|
||||
* @param {string[]} consoleBuffer A Cubot's internal buffer, as an array of messages
|
||||
* @param {ConsoleMode} mode mode
|
||||
*/
|
||||
handleConsoleBufferUpdate(consoleBuffer: string[], mode: ConsoleMode): void {
|
||||
|
||||
//Reset console screen before writing to it (if requested by ComPort)
|
||||
if (mode == ConsoleMode.CLEAR) {
|
||||
this.reset(this);
|
||||
}
|
||||
|
||||
//For each MESSAGE-LENGTH - length message
|
||||
for (let i = 0; i < consoleBuffer.length; i++) {
|
||||
|
||||
//Zero-terminate the message
|
||||
let zeroIndex = consoleBuffer[i].indexOf("\0");
|
||||
let message = consoleBuffer[i].substring(0, zeroIndex == -1 ? undefined : zeroIndex);
|
||||
|
||||
for (let j = 0; j < message.length; j++) {
|
||||
|
||||
if (message[j] == "\n") {
|
||||
|
||||
this.consoleText += "\n";
|
||||
this.lastLineLength = 0;
|
||||
|
||||
} else {
|
||||
|
||||
if (this.lastLineLength < this.modes[this.mode].width) {
|
||||
this.consoleText += message[j];
|
||||
this.lastLineLength++;
|
||||
} else {
|
||||
this.consoleText += "\n";
|
||||
this.consoleText += message[j];
|
||||
this.lastLineLength = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.txtDiv.innerText = this.consoleText;
|
||||
|
||||
//Scroll to bottom is autoScroll switch is flipped
|
||||
if (this.autoScroll) {
|
||||
this.txtDiv.scrollTop = this.txtDiv.scrollHeight;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
|
||||
/**
|
||||
* Client-side keyboard buffer. It is overwritten by the server at the end of tick.
|
||||
*/
|
||||
@ -78,6 +79,15 @@ class TickListener implements MessageListener {
|
||||
if (message.keys !== undefined) {
|
||||
mar.client.keyboardBuffer.keys = message.keys;
|
||||
}
|
||||
|
||||
//Update console screen
|
||||
if (message.c != undefined) {
|
||||
mar.client.consoleScreen.handleConsoleBufferUpdate(message.c, message.cm as ConsoleMode);
|
||||
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Received " + message.c.length + " console message(s)")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,7 +125,9 @@ class AuthListener implements MessageListener {
|
||||
}
|
||||
|
||||
if (message.m === "ok") {
|
||||
console.log("[MAR] Auth successful");
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Auth successful");
|
||||
}
|
||||
mar.client.requestUserInfo();
|
||||
|
||||
} else {
|
||||
@ -202,11 +214,34 @@ class TerrainListener implements MessageListener {
|
||||
|
||||
}
|
||||
|
||||
class CodeListener implements MessageListener {
|
||||
|
||||
getListenedMessageType(): string {
|
||||
return "code";
|
||||
}
|
||||
|
||||
handle(message): void {
|
||||
ace.edit("editor").setValue(message.code);
|
||||
}
|
||||
}
|
||||
|
||||
class CodeResponseListener implements MessageListener {
|
||||
|
||||
getListenedMessageType(): string {
|
||||
return "codeResponse";
|
||||
}
|
||||
|
||||
handle(message): void {
|
||||
alert("Uploaded and assembled " + message.bytes + " bytes (" + message.exceptions + " errors)");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class GameClient {
|
||||
|
||||
keyboardBuffer: KeyboardBuffer;
|
||||
/**
|
||||
* Max width of the game universe
|
||||
* Max width of the game universe, set by server
|
||||
*/
|
||||
public maxWidth: number;
|
||||
|
||||
@ -220,8 +255,12 @@ class GameClient {
|
||||
public worldX: number;
|
||||
public worldY: number;
|
||||
|
||||
public consoleScreen: PlainTextConsole;
|
||||
|
||||
constructor() {
|
||||
this.getServerInfo();
|
||||
|
||||
this.consoleScreen = new PlainTextConsole(defaultText, "consoleText", "colorButton", "scrollButton", "resetButton", "widthDial");
|
||||
}
|
||||
|
||||
public requestUserInfo(): void {
|
||||
@ -296,7 +335,6 @@ class GameClient {
|
||||
console.log("[MAR] Requesting game objects");
|
||||
}
|
||||
|
||||
|
||||
this.socket.send(JSON.stringify({t: "object", x: this.worldX, y: this.worldY}));
|
||||
}
|
||||
|
||||
@ -339,9 +377,6 @@ class GameClient {
|
||||
console.log("[MAR] Connecting to " + info.address);
|
||||
}
|
||||
|
||||
// info.address = "wss://muchassemblyrequired.com:443/socket";
|
||||
|
||||
|
||||
this.socket = new WebSocket(info.address);
|
||||
this.username = info.username;
|
||||
this.tickLength = info.tickLength;
|
||||
@ -359,12 +394,13 @@ class GameClient {
|
||||
//Send auth request
|
||||
self.socket.send(info.token);
|
||||
|
||||
//todo Setup event listeners
|
||||
self.listeners.push(new UserInfoListener());
|
||||
self.listeners.push(new AuthListener());
|
||||
self.listeners.push(new TickListener());
|
||||
self.listeners.push(new TerrainListener());
|
||||
self.listeners.push(new ObjectsListener());
|
||||
self.listeners.push(new CodeResponseListener());
|
||||
self.listeners.push(new CodeListener());
|
||||
|
||||
self.socket.onmessage = function (received) {
|
||||
|
||||
@ -373,28 +409,31 @@ class GameClient {
|
||||
try {
|
||||
message = JSON.parse(received.data);
|
||||
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Received: " + received.data)
|
||||
}
|
||||
|
||||
for (let i = 0; i < self.listeners.length; i++) {
|
||||
|
||||
if (self.listeners[i].getListenedMessageType() === message.t) {
|
||||
self.listeners[i].handle(message)
|
||||
}
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] " + e)
|
||||
}
|
||||
//todo floppyListener(received);
|
||||
}
|
||||
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Received: " + received.data)
|
||||
}
|
||||
|
||||
for (let i = 0; i < self.listeners.length; i++) {
|
||||
|
||||
if (self.listeners[i].getListenedMessageType() === message.t) {
|
||||
self.listeners[i].handle(message)
|
||||
console.log("[MAR] Received invalid message, assuming floppy data");
|
||||
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>";
|
||||
let blob = new Blob([received.data], {type: "application/octet-stream"});
|
||||
saveAs(blob, "floppy.bin");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
//Reload code
|
||||
//todo reloadCode();
|
||||
self.reloadCode();
|
||||
};
|
||||
|
||||
this.socket.onerror = function (e) {
|
||||
@ -417,31 +456,33 @@ class GameClient {
|
||||
*/
|
||||
public initGame() {
|
||||
|
||||
let self = this;
|
||||
//Setup keyboard buffer display, don't if guest
|
||||
if (this.username != "guest") {
|
||||
|
||||
//Setup keyboard buffer display
|
||||
//todo don't display if guest
|
||||
this.keyboardBuffer = new KeyboardBuffer(config.kbBufferX, config.kbBufferY);
|
||||
mar.addDebugMessage(this.keyboardBuffer);
|
||||
let self = this;
|
||||
|
||||
this.keyboardBuffer = new KeyboardBuffer(config.kbBufferX, config.kbBufferY);
|
||||
mar.addDebugMessage(this.keyboardBuffer);
|
||||
|
||||
|
||||
//Handle keypresses
|
||||
mar.game.input.keyboard.onDownCallback = function (event) {
|
||||
//Handle keypresses
|
||||
mar.game.input.keyboard.onDownCallback = function (event) {
|
||||
|
||||
//If the game has focus
|
||||
if (document.activeElement === document.getElementById("game")) {
|
||||
if ((event.keyCode >= 37 && event.keyCode <= 40) || event.keyCode === 116 || event.keyCode === 32) {
|
||||
event.preventDefault();
|
||||
//If the game has focus
|
||||
if (document.activeElement === document.getElementById("game")) {
|
||||
if ((event.keyCode >= 37 && event.keyCode <= 40) || event.keyCode === 116 || event.keyCode === 32) {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
if (self.username !== "guest" && self.keyboardBuffer.keys.length <= 16) {
|
||||
self.sendKeyPress(event.keyCode);
|
||||
|
||||
//Locally update the buffer
|
||||
self.keyboardBuffer.keys.push(event.keyCode);
|
||||
}
|
||||
}
|
||||
|
||||
if (self.username !== "guest" && self.keyboardBuffer.keys.length <= 16) {
|
||||
self.sendKeyPress(event.keyCode);
|
||||
|
||||
//Locally update the buffer
|
||||
self.keyboardBuffer.keys.push(event.keyCode);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -449,10 +490,12 @@ class GameClient {
|
||||
* the player's robot
|
||||
*/
|
||||
public findMyRobot() {
|
||||
if (this.username === "guest") {
|
||||
if (this.username == "guest") {
|
||||
alert("You are not logged in!");
|
||||
} else {
|
||||
this.requestUserInfo()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -213,14 +213,15 @@ class Cubot extends GameObject {
|
||||
|
||||
this.walk();
|
||||
|
||||
} else if (this.action == Action.JUMPING) {
|
||||
//TODO
|
||||
}
|
||||
// else if (this.action == Action.JUMPING) {
|
||||
// //TODO
|
||||
// }
|
||||
}
|
||||
|
||||
if (this.action == Action.DIGGING) {
|
||||
//TODO dig animation
|
||||
}
|
||||
// if (this.action == Action.DIGGING) {
|
||||
// //TODO dig animation
|
||||
// }
|
||||
|
||||
this.updateDirection();
|
||||
this.updateHologram(json.holoMode, json.holoC, json.holo, json.holoStr);
|
||||
@ -369,6 +370,7 @@ class HarvesterNPC extends Cubot {
|
||||
constructor(json) {
|
||||
super(json);
|
||||
|
||||
//Overwrite Cubot's animations
|
||||
this.animations.add("walk_w", mar.animationFrames.harvester_walk_w);
|
||||
this.animations.add("walk_s", mar.animationFrames.harvester_walk_s);
|
||||
this.animations.add("walk_e", mar.animationFrames.harvester_walk_e);
|
||||
@ -377,7 +379,6 @@ class HarvesterNPC extends Cubot {
|
||||
this.updateDirection();
|
||||
this.setText("Harvester NPC");
|
||||
this.text.visible = false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -422,8 +423,6 @@ class HarvesterNPC extends Cubot {
|
||||
|
||||
this.walk();
|
||||
|
||||
} else if (this.action == Action.JUMPING) {
|
||||
//TODO
|
||||
}
|
||||
}
|
||||
|
||||
@ -449,7 +448,6 @@ class BiomassBlob extends GameObject {
|
||||
this.text.visible = true;
|
||||
}
|
||||
|
||||
|
||||
onTileExit() {
|
||||
mar.game.tweens.removeFrom(this);
|
||||
mar.game.add.tween(this).to({isoZ: 15}, 400, Phaser.Easing.Bounce.Out, true);
|
||||
@ -465,7 +463,6 @@ class BiomassBlob extends GameObject {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
constructor(json) {
|
||||
super(Util.getIsoX(json.x), Util.getIsoY(json.y), 10, "sheet", 1);
|
||||
|
||||
@ -491,7 +488,6 @@ class BiomassBlob extends GameObject {
|
||||
|
||||
class Factory extends GameObject {
|
||||
|
||||
|
||||
public onTileHover() {
|
||||
mar.game.tweens.removeFrom(this);
|
||||
mar.game.add.tween(this).to({isoZ: 25}, 200, Phaser.Easing.Quadratic.InOut, true);
|
||||
@ -519,7 +515,6 @@ class Factory extends GameObject {
|
||||
return (this.tileX === x || this.tileX + 1 === x) && (this.tileY + 1 === y || this.tileY === y);
|
||||
};
|
||||
|
||||
|
||||
constructor(json) {
|
||||
super(Util.getIsoX(json.x), Util.getIsoY(json.y), 15, "sheet", "objects/factory");
|
||||
|
@ -37,10 +37,10 @@ class MarGame {
|
||||
}
|
||||
self.game.plugins.add(new Phaser.Plugin.Isometric(self.game));
|
||||
|
||||
// This is used to set a game canvas-based offset for the 0, 0, 0 isometric coordinate - by default
|
||||
// this point would be at screen coordinates 0, 0 (top left) which is usually undesirable.
|
||||
//This is used to set a game canvas-based offset for the 0, 0, 0 isometric coordinate - by default
|
||||
//this point would be at screen coordinates 0, 0 (top left) which is usually undesirable.
|
||||
self.game.iso.anchor.setTo(0.5, 0);
|
||||
//Todo: set world size based on window size?
|
||||
//Bounds will be overwritten to fit world when changing world
|
||||
self.game.world.setBounds(0, 0, 2200, 1100);
|
||||
|
||||
//Make camera more or less centered (tested on 1080 screen)
|
||||
@ -52,6 +52,7 @@ class MarGame {
|
||||
self.game.scale.pageAlignVertically = true;
|
||||
|
||||
self.game.stage.disableVisibilityChange = true;
|
||||
|
||||
self.client = new GameClient();
|
||||
|
||||
//Grab focus when clicked (For chrome, Opera)
|
||||
@ -72,7 +73,9 @@ class MarGame {
|
||||
|
||||
create: function () {
|
||||
|
||||
console.log("[MAR] create");
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] create");
|
||||
}
|
||||
|
||||
self.initialiseAnimations();
|
||||
self.initialiseStaticHud();
|
||||
@ -83,33 +86,33 @@ class MarGame {
|
||||
|
||||
self.game.scale.refresh();
|
||||
|
||||
// Update the cursor position.
|
||||
//Update the cursor position.
|
||||
self.game.iso.unproject(self.game.input.activePointer.position, self.cursorPos);
|
||||
|
||||
// Loop through all tiles and test to see if the 3D position from above intersects with the automatically generated IsoSprite tile bounds.
|
||||
//Loop through all tiles and test to see if the 3D position from above intersects with the automatically generated IsoSprite tile bounds.
|
||||
self.isoGroup.forEach(function (tile: Tile) {
|
||||
|
||||
if (tile instanceof Tile) {
|
||||
let inBounds = tile.isoBounds.containsXY(self.cursorPos.x, self.cursorPos.y);
|
||||
// If it does, do a little animation and tint change.
|
||||
//If it does, do a little animation and tint change.
|
||||
if (!tile.selected && inBounds) {
|
||||
tile.selected = true;
|
||||
|
||||
tile.onHover();
|
||||
|
||||
//Dispatch tile over
|
||||
//Dispatch tile over for objects
|
||||
self.isoGroup.forEach(function (obj: GameObject) {
|
||||
if (obj instanceof GameObject && obj.onTileHover != undefined && obj.isAt(tile.tileX, tile.tileY)) {
|
||||
obj.onTileHover();
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
// If not, revert back to how it was.
|
||||
//If not, revert back to how it was.
|
||||
else if (tile.selected && !inBounds) {
|
||||
tile.selected = false;
|
||||
tile.onExit();
|
||||
|
||||
//Dispatch tile exit
|
||||
//Dispatch tile exit objects
|
||||
self.isoGroup.forEach(function (obj: GameObject) {
|
||||
if (obj.onTileExit != undefined && obj.isAt(tile.tileX, tile.tileY)) {
|
||||
obj.onTileExit();
|
||||
@ -268,7 +271,6 @@ class MarGame {
|
||||
|
||||
abstract class DebugMessage {
|
||||
|
||||
|
||||
public x: number;
|
||||
public y: number;
|
||||
|
||||
@ -281,6 +283,9 @@ abstract class DebugMessage {
|
||||
abstract getMessage(): string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates hovered tile
|
||||
*/
|
||||
class TileIndicator extends DebugMessage {
|
||||
|
||||
public tileType: string;
|
||||
@ -289,7 +294,6 @@ class TileIndicator extends DebugMessage {
|
||||
|
||||
getMessage(): string {
|
||||
|
||||
|
||||
if (this.tileType != undefined) {
|
||||
|
||||
return this.tileX + ", " + this.tileY + " : " + this.tileType;
|
||||
@ -301,6 +305,9 @@ class TileIndicator extends DebugMessage {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates current World
|
||||
*/
|
||||
class WorldIndicator extends DebugMessage {
|
||||
|
||||
getMessage(): string {
|
@ -1,6 +1,6 @@
|
||||
///<reference path="GameClient.ts"/>
|
||||
///<reference path="phaser.d.ts"/>
|
||||
///<reference path="phaser.plugin.isometric.d.ts"/>
|
||||
|
||||
import instances = PIXI.instances;
|
||||
|
||||
enum Direction {
|
||||
NORTH,
|
||||
@ -9,6 +9,12 @@ enum Direction {
|
||||
WEST
|
||||
}
|
||||
|
||||
enum TileType {
|
||||
PLAIN,
|
||||
WALL,
|
||||
IRON,
|
||||
COPPER
|
||||
}
|
||||
|
||||
class Tile extends Phaser.Plugin.Isometric.IsoSprite {
|
||||
|
||||
@ -50,7 +56,6 @@ class Tile extends Phaser.Plugin.Isometric.IsoSprite {
|
||||
public static createTile(type: TileType, x: number, y: number) {
|
||||
switch (type) {
|
||||
|
||||
|
||||
case TileType.WALL:
|
||||
return new WallTile(x, y);
|
||||
case TileType.IRON:
|
||||
@ -101,7 +106,6 @@ class Tile extends Phaser.Plugin.Isometric.IsoSprite {
|
||||
|
||||
class PlainTile extends Tile {
|
||||
|
||||
|
||||
constructor(x: number, y: number) {
|
||||
super(x, y, config.plainSprite, 0);
|
||||
|
||||
@ -112,6 +116,7 @@ class PlainTile extends Tile {
|
||||
}
|
||||
|
||||
class WallTile extends Tile {
|
||||
|
||||
constructor(x: number, y: number) {
|
||||
super(x, y, config.wallSprite, 0.2);
|
||||
|
||||
@ -123,6 +128,7 @@ class WallTile extends Tile {
|
||||
}
|
||||
|
||||
class IronTile extends Tile {
|
||||
|
||||
constructor(x: number, y: number) {
|
||||
super(x, y, config.plainSprite, 0);
|
||||
|
||||
@ -136,6 +142,7 @@ class IronTile extends Tile {
|
||||
|
||||
|
||||
class CopperTile extends Tile {
|
||||
|
||||
constructor(x: number, y: number) {
|
||||
super(x, y, config.plainSprite, 0);
|
||||
|
||||
@ -371,4 +378,6 @@ class WorldArrow extends Phaser.Plugin.Isometric.IsoSprite {
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
1687
mar/app.js
Normal file
71
mar/app.min.js
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
var $jscomp=$jscomp||{};$jscomp.scope={};$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(b,a,c){b!=Array.prototype&&b!=Object.prototype&&(b[a]=c.value)};$jscomp.getGlobal=function(b){return"undefined"!=typeof window&&window===b?b:"undefined"!=typeof global&&null!=global?global:b};$jscomp.global=$jscomp.getGlobal(this);
|
||||
$jscomp.polyfill=function(b,a,c,d){if(a){c=$jscomp.global;b=b.split(".");for(d=0;d<b.length-1;d++){var e=b[d];e in c||(c[e]={});c=c[e]}b=b[b.length-1];d=c[b];a=a(d);a!=d&&null!=a&&$jscomp.defineProperty(c,b,{configurable:!0,writable:!0,value:a})}};$jscomp.underscoreProtoCanBeSet=function(){var b={a:!0},a={};try{return a.__proto__=b,a.a}catch(c){}return!1};
|
||||
$jscomp.setPrototypeOf="function"==typeof Object.setPrototypeOf?Object.setPrototypeOf:$jscomp.underscoreProtoCanBeSet()?function(b,a){b.__proto__=a;if(b.__proto__!==a)throw new TypeError(b+" is not extensible");return b}:null;$jscomp.polyfill("Object.setPrototypeOf",function(b){return b||$jscomp.setPrototypeOf},"es6","es5");$jscomp.SYMBOL_PREFIX="jscomp_symbol_";$jscomp.initSymbol=function(){$jscomp.initSymbol=function(){};$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)};
|
||||
$jscomp.Symbol=function(){var b=0;return function(a){return $jscomp.SYMBOL_PREFIX+(a||"")+b++}}();$jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var b=$jscomp.global.Symbol.iterator;b||(b=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("iterator"));"function"!=typeof Array.prototype[b]&&$jscomp.defineProperty(Array.prototype,b,{configurable:!0,writable:!0,value:function(){return $jscomp.arrayIterator(this)}});$jscomp.initSymbolIterator=function(){}};
|
||||
$jscomp.arrayIterator=function(b){var a=0;return $jscomp.iteratorPrototype(function(){return a<b.length?{done:!1,value:b[a++]}:{done:!0}})};$jscomp.iteratorPrototype=function(b){$jscomp.initSymbolIterator();b={next:b};b[$jscomp.global.Symbol.iterator]=function(){return this};return b};
|
||||
$jscomp.iteratorFromArray=function(b,a){$jscomp.initSymbolIterator();b instanceof String&&(b+="");var c=0,d={next:function(){if(c<b.length){var e=c++;return{value:a(e,b[e]),done:!1}}d.next=function(){return{done:!0,value:void 0}};return d.next()}};d[Symbol.iterator]=function(){return d};return d};$jscomp.polyfill("Array.prototype.keys",function(b){return b?b:function(){return $jscomp.iteratorFromArray(this,function(a){return a})}},"es6","es3");
|
||||
var __extends=this&&this.__extends||function(){var b=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(a,c){a.__proto__=c}||function(a,c){for(var b in c)c.hasOwnProperty(b)&&(a[b]=c[b])};return function(a,c){function d(){this.constructor=a}b(a,c);a.prototype=null===c?Object.create(c):(d.prototype=c.prototype,new d)}}(),MarGame=function(){function b(){this.cursorPos=new Phaser.Plugin.Isometric.Point3;this.debugMessages=[];this.animationFrames={};var a=this;this.game=new Phaser.Game(RENDERER_WIDTH,
|
||||
RENDERER_HEIGHT,Phaser.AUTO,"game",null,!0,!1);this.bootState={preload:function(){DEBUG&&console.log("[MAR]\u00a0Loading sprites.png as JSONHash");this.game.load.atlasJSONHash("sheet","./mar/sprites.png","./mar/sprites.json").onLoadComplete.add(function(){a.game.time.advancedTiming=!0;DEBUG&&console.log("[MAR]\u00a0Enabling isometric plugin");a.game.plugins.add(new Phaser.Plugin.Isometric(a.game));a.game.iso.anchor.setTo(.5,0);a.game.world.setBounds(0,0,2200,1100);a.game.camera.x=280;a.game.camera.y=
|
||||
90;a.game.scale.scaleMode=Phaser.ScaleManager.RESIZE;a.game.scale.pageAlignHorizontally=!0;a.game.scale.pageAlignVertically=!0;a.game.stage.disableVisibilityChange=!0;a.client=new GameClient;a.game.input.onDown.add(function(){document.getElementById("game").focus();DEBUG&&console.log("Grabbed focus of #game")});a.isoGroup=mar.game.add.group();a.textGroup=mar.game.add.group();a.hudGroup=mar.game.add.group();a.hudGroup.fixedToCamera=!0})},create:function(){DEBUG&&console.log("[MAR] create");a.initialiseAnimations();
|
||||
a.initialiseStaticHud()},update:function(){a.game.scale.refresh();a.game.iso.unproject(a.game.input.activePointer.position,a.cursorPos);a.isoGroup.forEach(function(c){if(c instanceof Tile){var b=c.isoBounds.containsXY(a.cursorPos.x,a.cursorPos.y);!c.selected&&b?(c.selected=!0,c.onHover(),a.isoGroup.forEach(function(a){if(a instanceof GameObject&&void 0!=a.onTileHover&&a.isAt(c.tileX,c.tileY))a.onTileHover()},1)):c.selected&&!b&&(c.selected=!1,c.onExit(),a.isoGroup.forEach(function(a){if(void 0!=a.onTileExit&&
|
||||
a.isAt(c.tileX,c.tileY))a.onTileExit()},0))}},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;a.game.iso.topologicalSort(a.isoGroup)},render:function(){for(var c=0;c<a.debugMessages.length;c++)a.game.debug.text(a.debugMessages[c].getMessage(),
|
||||
a.debugMessages[c].x,a.debugMessages[c].y)}};this.game.state.add("Boot",this.bootState);this.game.state.start("Boot")}b.prototype.addDebugMessage=function(a){this.debugMessages.push(a)};b.prototype.initialiseAnimations=function(){this.animationFrames.walk_e_start=[];for(var a=0;10>a;a++)this.animationFrames.walk_e_start.push("cubot/walk_e/"+("0000"+a).slice(-4));this.animationFrames.walk_e=[];for(a=10;30>a;a++)this.animationFrames.walk_e.push("cubot/walk_e/"+("0000"+a).slice(-4));this.animationFrames.harvester_walk_e_start=
|
||||
[];for(a=0;10>a;a++)this.animationFrames.harvester_walk_e_start.push("harvester/walk_e/"+("0000"+a).slice(-4));this.animationFrames.harvester_walk_e=[];for(a=10;30>a;a++)this.animationFrames.harvester_walk_e.push("harvester/walk_e/"+("0000"+a).slice(-4));this.animationFrames.walk_n_start=[];for(a=0;10>a;a++)this.animationFrames.walk_n_start.push("cubot/walk_n/"+("0000"+a).slice(-4));this.animationFrames.walk_n=[];for(a=10;30>a;a++)this.animationFrames.walk_n.push("cubot/walk_n/"+("0000"+a).slice(-4));
|
||||
this.animationFrames.harvester_walk_n_start=[];for(a=0;10>a;a++)this.animationFrames.harvester_walk_n_start.push("harvester/walk_n/"+("0000"+a).slice(-4));this.animationFrames.harvester_walk_n=[];for(a=10;30>a;a++)this.animationFrames.harvester_walk_n.push("harvester/walk_n/"+("0000"+a).slice(-4));this.animationFrames.walk_s_start=[];for(a=0;10>a;a++)this.animationFrames.walk_s_start.push("cubot/walk_s/"+("0000"+a).slice(-4));this.animationFrames.walk_s=[];for(a=10;30>a;a++)this.animationFrames.walk_s.push("cubot/walk_s/"+
|
||||
("0000"+a).slice(-4));this.animationFrames.harvester_walk_s_start=[];for(a=0;10>a;a++)this.animationFrames.harvester_walk_s_start.push("harvester/walk_s/"+("0000"+a).slice(-4));this.animationFrames.harvester_walk_s=[];for(a=10;30>a;a++)this.animationFrames.harvester_walk_s.push("harvester/walk_s/"+("0000"+a).slice(-4));this.animationFrames.walk_w_start=[];for(a=0;10>a;a++)this.animationFrames.walk_w_start.push("cubot/walk_w/"+("0000"+a).slice(-4));this.animationFrames.walk_w=[];for(a=10;30>a;a++)this.animationFrames.walk_w.push("cubot/walk_w/"+
|
||||
("0000"+a).slice(-4));this.animationFrames.harvester_walk_w_start=[];for(a=0;10>a;a++)this.animationFrames.harvester_walk_w_start.push("harvester/walk_w/"+("0000"+a).slice(-4));this.animationFrames.harvester_walk_w=[];for(a=10;30>a;a++)this.animationFrames.harvester_walk_w.push("harvester/walk_w/"+("0000"+a).slice(-4));this.animationFrames.dig_e=[];for(a=1;41>=a;a++)this.animationFrames.dig_e.push("cubot/dig_e/"+("0000"+a).slice(-4));this.animationFrames.dig_n=[];for(a=1;41>=a;a++)this.animationFrames.dig_n.push("cubot/dig_n/"+
|
||||
("0000"+a).slice(-4));this.animationFrames.dig_s=[];for(a=1;41>=a;a++)this.animationFrames.dig_s.push("cubot/dig_s/"+("0000"+a).slice(-4));this.animationFrames.dig_w=[];for(a=1;41>=a;a++)this.animationFrames.dig_w.push("cubot/dig_w/"+("0000"+a).slice(-4));this.animationFrames.biomassIdle=[];for(a=1;60>a;a++)this.animationFrames.biomassIdle.push("objects/biomass/idle/"+("0000"+a).slice(-4))};b.prototype.initialiseStaticHud=function(){this.game.add.sprite(0,this.game.camera.height-150,"sheet","ui/compass",
|
||||
this.hudGroup);this.addDebugMessage(new WorldIndicator(10,20));this.tileIndicator=new TileIndicator(10,40);this.addDebugMessage(this.tileIndicator)};return b}(),DebugMessage=function(){return function(b,a){this.x=b;this.y=a}}(),TileIndicator=function(b){function a(){return null!==b&&b.apply(this,arguments)||this}__extends(a,b);a.prototype.getMessage=function(){return void 0!=this.tileType?this.tileX+", "+this.tileY+" : "+this.tileType:""};return a}(DebugMessage),WorldIndicator=function(b){function a(){return null!==
|
||||
b&&b.apply(this,arguments)||this}__extends(a,b);a.prototype.getMessage=function(){return void 0!=mar.world?"World: ("+Number(mar.client.worldX).toString(16).toUpperCase()+", "+Number(mar.client.worldY).toString(16).toUpperCase()+")":"Loading..."};return a}(DebugMessage),RENDERER_WIDTH=document.getElementById("game").clientWidth*window.devicePixelRatio,RENDERER_HEIGHT=window.innerHeight/1.4*window.devicePixelRatio,DEBUG=!0,config={tileTint:16777215,wallTint:14540253,oreTint:15987699,cubotHoverTint:65280,
|
||||
cubotTint:16777215,textFill:"#FFFFFF",textStroke:"#9298a8",biomassTint:6535263,biomassHoverTint:65280,tileHoverTint:65280,itemIron:4408129,textIron:"#434341",itemCopper:13139256,textCopper:"#C87D38",hologramFill:"#0aced6",hologramStroke:"#12FFB0",copperFill:"#C87D38",plainSprite:"tiles/tile",wallSprite:"tiles/bigTile",walkDuration:800,holoStyle:function(b){return{fontSize:32,fill:b?b:config.hologramFill,stroke:config.hologramStroke,strokeThickness:1,font:"fixedsys"}},kbBufferX:225,kbBufferY:20,arrowTextStyle:{fontSize:32,
|
||||
fill:"#ffffff",stroke:"#9298a8",strokeThickness:1,font:"fixedsys"},lowEnergy:100,lowEnergyTint:13369344,bigMessageFill:"#ff803d",arrowTint:16777215,arrowHoverTint:65280,selfUsernameColor:16469258,otherCubotAlpha:.6,defaultWorldSize:16},Util=function(){function b(){}b.getIsoY=function(a){return b.getIsoX(a)};b.getIsoX=function(a){return 71.5*a};b.getDeltaX=function(a){switch(a){case Direction.NORTH:case Direction.SOUTH:return 0;case Direction.EAST:return 1;case Direction.WEST:return-1}};b.getDeltaY=
|
||||
function(a){switch(a){case Direction.EAST:case Direction.WEST:return 0;case Direction.NORTH:return 1;case Direction.SOUTH:return-1}};return b}(),mar=new MarGame,KeyboardBuffer=function(b){function a(){var a=null!==b&&b.apply(this,arguments)||this;a.keys=[];return a}__extends(a,b);a.prototype.getMessage=function(){for(var a="KB: ",b=0;16>b;b++)a=void 0!==this.keys[b]?a+(this.keys[b].toString(16).toUpperCase()+" "):a+"__ ";return a};return a}(DebugMessage),ObjectsListener=function(){function b(){}b.prototype.getListenedMessageType=
|
||||
function(){return"object"};b.prototype.handle=function(a){DEBUG&&console.log("[MAR] Received "+a.objects.length+" objects");void 0!=mar.world&&mar.world.handleObjectsUpdate(a.objects)};return b}(),TickListener=function(){function b(){}b.prototype.getListenedMessageType=function(){return"tick"};b.prototype.handle=function(a){mar.client.requestObjects();void 0!==a.keys&&(mar.client.keyboardBuffer.keys=a.keys);void 0!=a.c&&(mar.client.consoleScreen.handleConsoleBufferUpdate(a.c,a.cm),DEBUG&&console.log("[MAR] Received "+
|
||||
a.c.length+" console message(s)"))};return b}(),UserInfoListener=function(){function b(){}b.prototype.getListenedMessageType=function(){return"userInfo"};b.prototype.handle=function(a){DEBUG&&console.log("[MAR] Received user info message");mar.client.worldX=a.worldX;mar.client.worldY=a.worldY;mar.client.maxWidth=a.maxWidth;mar.client.requestTerrain()};return b}(),AuthListener=function(){function b(){}b.prototype.getListenedMessageType=function(){return"auth"};b.prototype.handle=function(a){DEBUG&&
|
||||
console.log("[MAR] Received auth response");"ok"===a.m?(DEBUG&&console.log("[MAR] Auth successful"),mar.client.requestUserInfo()):alert("Authentication failed. Please make sure you are logged in and reload the page.")};return b}(),TerrainListener=function(){function b(){}b.prototype.getListenedMessageType=function(){return"terrain"};b.prototype.handle=function(a){DEBUG&&console.log("[MAR] Received terrain");mar.world&&mar.world.removeBigMessage();if(a.ok){var c=a.size;void 0==c&&(c=config.defaultWorldSize);
|
||||
DEBUG&&console.log("[MAR] World is available");null!=mar.world?(DEBUG&&console.log("[MAR] Updating World terrain"),mar.world.updateTerrain(a.terrain,c)):(DEBUG&&console.log("[MAR] Creating new World"),mar.world=new World(a.terrain,c))}else DEBUG&&console.log("[MAR] World is not available"),null!=mar.world?(DEBUG&&console.log("[MAR] Updating World terrain"),mar.world.updateTerrain([],config.defaultWorldSize)):(DEBUG&&console.log("[MAR] Creating new World"),mar.world=new World([],config.defaultWorldSize)),
|
||||
mar.world&&mar.world.setBigMessage("[Uncharted World]")};return b}(),CodeListener=function(){function b(){}b.prototype.getListenedMessageType=function(){return"code"};b.prototype.handle=function(a){ace.edit("editor").setValue(a.code)};return b}(),CodeResponseListener=function(){function b(){}b.prototype.getListenedMessageType=function(){return"codeResponse"};b.prototype.handle=function(a){alert("Uploaded and assembled "+a.bytes+" bytes ("+a.exceptions+" errors)")};return b}(),GameClient=function(){function b(){this.listeners=
|
||||
[];this.getServerInfo();this.consoleScreen=new PlainTextConsole(defaultText,"consoleText","colorButton","scrollButton","resetButton","widthDial")}b.prototype.requestUserInfo=function(){DEBUG&&console.log("[MAR] Requesting user info");this.socket.send(JSON.stringify({t:"userInfo"}))};b.prototype.requestTerrain=function(){DEBUG&&console.log("[MAR] Requesting terrain for world ("+this.worldX+", "+this.worldY+")");this.socket.send(JSON.stringify({t:"terrain",x:this.worldX,y:this.worldY}));this.requestObjects()};
|
||||
b.prototype.uploadCode=function(a){DEBUG&&console.log("[MAR] Uploaded code");this.socket.send(JSON.stringify({t:"uploadCode",code:a}))};b.prototype.reloadCode=function(){DEBUG&&console.log("[MAR] Reloading code");this.socket.send(JSON.stringify({t:"codeRequest"}))};b.prototype.sendKeyPress=function(a){DEBUG&&console.log("[MAR] Sent KeyPress: "+a);0!==a&&this.socket.send(JSON.stringify({t:"k",k:a}))};b.prototype.requestFloppy=function(){document.getElementById("floppyDown").innerHTML='<i class="fa fa-cog fa-spin fa-fw"></i>';
|
||||
DEBUG&&console.log("[MAR] Requesting floppy");this.socket.send(JSON.stringify({t:"floppyDown"}))};b.prototype.notifyFloppyUp=function(){DEBUG&&console.log("[MAR] Notifying the game server of floppy upload");this.socket.send(JSON.stringify({t:"floppyUp"}))};b.prototype.requestObjects=function(){DEBUG&&console.log("[MAR] Requesting game objects");this.socket.send(JSON.stringify({t:"object",x:this.worldX,y:this.worldY}))};b.prototype.getServerInfo=function(){var a=this;DEBUG&&console.log("[MAR] Getting server info... ");
|
||||
var c=new XMLHttpRequest;c.open("GET","./getServerInfo.php",!0);c.onreadystatechange=function(){4===c.readyState&&200===c.status&&(DEBUG&&console.log("[MAR] Received server info "+c.responseText),setTimeout(a.connectToGameServer(JSON.parse(c.responseText)),100))};c.send(null)};b.prototype.connectToGameServer=function(a){var c=this;DEBUG&&console.log("[MAR] Connecting to "+a.address);this.socket=new WebSocket(a.address);this.username=a.username;this.tickLength=a.tickLength;this.serverName=a.serverName;
|
||||
this.socket.binaryType="arraybuffer";this.socket.onopen=function(){DEBUG&&console.log("[MAR] Connected. Sent auth request");c.socket.send(a.token);c.listeners.push(new UserInfoListener);c.listeners.push(new AuthListener);c.listeners.push(new TickListener);c.listeners.push(new TerrainListener);c.listeners.push(new ObjectsListener);c.listeners.push(new CodeResponseListener);c.listeners.push(new CodeListener);c.socket.onmessage=function(a){try{var b=JSON.parse(a.data);DEBUG&&console.log("[MAR] Received: "+
|
||||
a.data);for(var d=0;d<c.listeners.length;d++)c.listeners[d].getListenedMessageType()===b.t&&c.listeners[d].handle(b)}catch(h){DEBUG&&(console.log("[MAR] Received invalid message, assuming floppy data"),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"))}};c.reloadCode()};this.socket.onerror=function(c){alert("Can't connect to game server at address "+
|
||||
a.address);console.log(c)};this.socket.onclose=function(a){mar.world.setBigMessage("Disconnected from server :(");console.log(a)};this.initGame()};b.prototype.initGame=function(){if("guest"!=this.username){var a=this;this.keyboardBuffer=new KeyboardBuffer(config.kbBufferX,config.kbBufferY);mar.addDebugMessage(this.keyboardBuffer);mar.game.input.keyboard.onDownCallback=function(c){document.activeElement===document.getElementById("game")&&((37<=c.keyCode&&40>=c.keyCode||116===c.keyCode||32===c.keyCode)&&
|
||||
c.preventDefault(),"guest"!==a.username&&16>=a.keyboardBuffer.keys.length&&(a.sendKeyPress(c.keyCode),a.keyboardBuffer.keys.push(c.keyCode)))}}};b.prototype.findMyRobot=function(){"guest"==this.username?alert("You are not logged in!"):this.requestUserInfo()};return b}(),ObjectType;(function(b){b[b.CUBOT=1]="CUBOT";b[b.BIOMASS=2]="BIOMASS";b[b.HARVESTER_NPC=10]="HARVESTER_NPC";b[b.FACTORY=3]="FACTORY";b[b.RADIO_TOWER=4]="RADIO_TOWER"})(ObjectType||(ObjectType={}));var ItemType;
|
||||
(function(b){b[b.BIOMASS=1]="BIOMASS";b[b.IRON=3]="IRON";b[b.COPPER=4]="COPPER"})(ItemType||(ItemType={}));var Action;(function(b){b[b.IDLE=0]="IDLE";b[b.DIGGING=1]="DIGGING";b[b.WALKING=2]="WALKING";b[b.WITHDRAWING=3]="WITHDRAWING";b[b.DEPOSITING=4]="DEPOSITING";b[b.LISTENING=5]="LISTENING";b[b.JUMPING=6]="JUMPING"})(Action||(Action={}));
|
||||
var GameObject=function(b){function a(a,d,e,f,h){return b.call(this,mar.game,a,d,e,f,h)||this}__extends(a,b);a.createObject=function(a){switch(a.t){case ObjectType.CUBOT:return new Cubot(a);case ObjectType.BIOMASS:return new BiomassBlob(a);case ObjectType.HARVESTER_NPC:return new HarvesterNPC(a);case ObjectType.FACTORY:return new Factory(a);case ObjectType.RADIO_TOWER:return new RadioTower(a);default:return null}};a.prototype.setText=function(a){this.text=mar.game.make.text(0,0,a,{fontSize:22,fill:config.textFill,
|
||||
stroke:config.textStroke,strokeThickness:2,font:"fixedsys"});this.text.anchor.set(.5,0);this.addChild(this.text)};a.prototype.isAt=function(a,b){return a==this.tileX&&b==this.tileY};return a}(Phaser.Plugin.Isometric.IsoSprite),HologramMode;(function(b){b[b.CLEARED=0]="CLEARED";b[b.HEX=1]="HEX";b[b.STRING=2]="STRING";b[b.DEC=3]="DEC"})(HologramMode||(HologramMode={}));
|
||||
var Cubot=function(b){function a(a){var c=b.call(this,Util.getIsoX(a.x),Util.getIsoY(a.y),15,"sheet",null)||this;c.queuedAnimations=[];c.hovered=!1;DEBUG&&console.log("Creating Cubot object");c.anchor.set(.5,0);c.id=a.i;c.tileX=a.x;c.tileY=a.y;c.username=a.parent;c.heldItem=a.heldItem;c.direction=a.direction;c.action=a.action;c.energy=a.energy;c.animations.add("walk_w",mar.animationFrames.walk_w);c.animations.add("walk_s",mar.animationFrames.walk_s);c.animations.add("walk_e",mar.animationFrames.walk_e);
|
||||
c.animations.add("walk_n",mar.animationFrames.walk_n);c.animations.add("dig_w",mar.animationFrames.dig_w);c.animations.add("dig_s",mar.animationFrames.dig_s);c.animations.add("dig_e",mar.animationFrames.dig_e);c.animations.add("dig_n",mar.animationFrames.dig_n);c.createUsername();c.updateDirection();c.tint=c.getTint();return c}__extends(a,b);a.prototype.onTileHover=function(){mar.game.add.tween(this).to({isoZ:45},200,Phaser.Easing.Quadratic.InOut,!0);mar.game.add.tween(this.scale).to({x:1.2,y:1.2},
|
||||
200,Phaser.Easing.Linear.None,!0);this.tint=config.cubotHoverTint;void 0!==this.text&&(this.text.visible=!0);this.hovered=!0};a.prototype.onTileExit=function(){mar.game.add.tween(this).to({isoZ:15},400,Phaser.Easing.Bounce.Out,!0);mar.game.add.tween(this.scale).to({x:1,y:1},200,Phaser.Easing.Linear.None,!0);void 0!==this.text&&(this.text.visible=!1);this.hovered=!1;this.tint=this.getTint()};a.prototype.getTint=function(){return this.hovered?config.cubotHoverTint:this.energy<=config.lowEnergy?config.lowEnergyTint:
|
||||
config.cubotTint};a.prototype.updateObject=function(a){DEBUG&&console.log("Updating Cubot object");this.action=a.action;this.energy=a.energy;this.direction=a.direction;this.tint=this.getTint();this.isAt(a.x,a.y)||this.action!=Action.WALKING||(this.tileX=a.x,this.tileY=a.y,this.walk());this.updateDirection();this.updateHologram(a.holoMode,a.holoC,a.holo,a.holoStr)};a.prototype.updateHologram=function(a,b,e,f){void 0==this.hologram&&(this.hologram=mar.game.make.text(0,32,""),this.hologram.anchor.set(.5,
|
||||
0),this.addChild(this.hologram));this.hologram.setStyle(config.holoStyle(b));switch(a){case HologramMode.CLEARED:this.hologram.text="";break;case HologramMode.DEC:this.hologram.text=Number(e).toString();break;case HologramMode.HEX:this.hologram.text="0x"+("0000"+Number(e).toString(16).toUpperCase()).slice(-4);break;case HologramMode.STRING:this.hologram.text=f.replace(/[\n|\t]/g,"")}};a.prototype.updateDirection=function(){switch(this.direction){case Direction.NORTH:this.animations.frameName="cubot/walk_n/0001";
|
||||
break;case Direction.EAST:this.animations.frameName="cubot/walk_e/0001";break;case Direction.SOUTH:this.animations.frameName="cubot/walk_s/0001";break;case Direction.WEST:this.animations.frameName="cubot/walk_w/0001"}};a.prototype.walk=function(){var a=this,b=function(b){b=mar.game.add.tween(a).to({isoX:Util.getIsoX(a.tileX),isoY:Util.getIsoY(a.tileY)},b,Phaser.Easing.Linear.None,!0);switch(a.direction){case Direction.NORTH:a.animations.play("walk_n",60,!0);break;case Direction.SOUTH:a.animations.play("walk_s",
|
||||
60,!0);break;case Direction.EAST:a.animations.play("walk_e",60,!0);break;case Direction.WEST:a.animations.play("walk_w",60,!0)}b.onComplete.add(function(){a.animations.stop();a.updateDirection();a.isoX=Util.getIsoX(a.tileX);a.isoY=Util.getIsoY(a.tileY);a.onTileExit();for(var b=0;b<a.queuedAnimations.length;b++)a.queuedAnimations[b](config.walkDuration/2),a.queuedAnimations.splice(b,1)})};this.animations.currentAnim.isPlaying?this.queuedAnimations.push(b):b(config.walkDuration)};a.prototype.createUsername=
|
||||
function(){var a=mar.game.make.text(0,-24,this.username,{fontSize:22,fill:config.textFill,stroke:config.textStroke,strokeThickness:2,font:"fixedsys"});a.alpha=.85;a.anchor.set(.5,0);this.username===mar.client.username?a.tint=config.selfUsernameColor:this.alpha=config.otherCubotAlpha;this.addChild(a)};return a}(GameObject),HarvesterNPC=function(b){function a(a){a=b.call(this,a)||this;a.animations.add("walk_w",mar.animationFrames.harvester_walk_w);a.animations.add("walk_s",mar.animationFrames.harvester_walk_s);
|
||||
a.animations.add("walk_e",mar.animationFrames.harvester_walk_e);a.animations.add("walk_n",mar.animationFrames.harvester_walk_n);a.updateDirection();a.setText("Harvester NPC");a.text.visible=!1;return a}__extends(a,b);a.prototype.getTint=function(){return config.cubotTint};a.prototype.updateDirection=function(){switch(this.direction){case Direction.NORTH:this.animations.frameName="harvester/walk_n/0001";break;case Direction.EAST:this.animations.frameName="harvester/walk_e/0001";break;case Direction.SOUTH:this.animations.frameName=
|
||||
"harvester/walk_s/0001";break;case Direction.WEST:this.animations.frameName="harvester/walk_w/0001"}};a.prototype.updateObject=function(a){DEBUG&&console.log("Updating Harvester NPC object");this.action=a.action;this.direction=a.direction;this.isAt(a.x,a.y)||this.action!=Action.WALKING||(this.tileX=a.x,this.tileY=a.y,this.walk());this.updateDirection()};a.prototype.createUsername=function(){};return a}(Cubot),BiomassBlob=function(b){function a(a){var c=b.call(this,Util.getIsoX(a.x),Util.getIsoY(a.y),
|
||||
10,"sheet",1)||this;DEBUG&&console.log("Creating Biomass object");c.anchor.set(.5,0);c.id=a.i;c.tileX=a.x;c.tileY=a.y;c.tint=config.biomassTint;c.animations.add("idle",mar.animationFrames.biomassIdle);c.animations.play("idle",45,!0);c.setText("Biomass");c.text.visible=!1;return c}__extends(a,b);a.prototype.onTileHover=function(){mar.game.tweens.removeFrom(this);mar.game.add.tween(this).to({isoZ:45},200,Phaser.Easing.Quadratic.InOut,!0);this.tint=config.biomassHoverTint;mar.game.add.tween(this.scale).to({x:1.2,
|
||||
y:1.2},200,Phaser.Easing.Linear.None,!0);this.text.visible=!0};a.prototype.onTileExit=function(){mar.game.tweens.removeFrom(this);mar.game.add.tween(this).to({isoZ:15},400,Phaser.Easing.Bounce.Out,!0);mar.game.add.tween(this.scale).to({x:1,y:1},200,Phaser.Easing.Linear.None,!0);this.tint=config.biomassTint;this.text.visible=!1};a.prototype.updateObject=function(a){DEBUG&&console.log("Updating Biomass object")};return a}(GameObject),Factory=function(b){function a(a){var c=b.call(this,Util.getIsoX(a.x),
|
||||
Util.getIsoY(a.y),15,"sheet","objects/factory")||this;c.anchor.set(.5,.25);c.setText("Factory");c.text.visible=!1;c.id=a.i;c.tileX=a.x;c.tileY=a.y;return c}__extends(a,b);a.prototype.onTileHover=function(){mar.game.tweens.removeFrom(this);mar.game.add.tween(this).to({isoZ:25},200,Phaser.Easing.Quadratic.InOut,!0);mar.game.add.tween(this.scale).to({x:1.06,y:1.06},200,Phaser.Easing.Linear.None,!0);this.tint=config.cubotHoverTint;this.text.visible=!0};a.prototype.onTileExit=function(){mar.game.tweens.removeFrom(this);
|
||||
mar.game.add.tween(this).to({isoZ:15},400,Phaser.Easing.Bounce.Out,!0);mar.game.add.tween(this.scale).to({x:1,y:1},200,Phaser.Easing.Linear.None,!0);this.tint=config.cubotTint;this.text.visible=!1};a.prototype.updateObject=function(a){};a.prototype.isAt=function(a,b){return(this.tileX===a||this.tileX+1===a)&&(this.tileY+1===b||this.tileY===b)};return a}(GameObject),RadioTower=function(b){function a(a){var c=b.call(this,Util.getIsoX(a.x),Util.getIsoY(a.y),15,"sheet","objects/RadioTower")||this;c.anchor.set(.5,
|
||||
.64);c.setText("Radio Tower");c.text.visible=!1;c.id=a.i;c.tileX=a.x;c.tileY=a.y;return c}__extends(a,b);a.prototype.onTileHover=function(){mar.game.tweens.removeFrom(this);mar.game.add.tween(this).to({isoZ:25},200,Phaser.Easing.Quadratic.InOut,!0);mar.game.add.tween(this.scale).to({x:1.06,y:1.06},200,Phaser.Easing.Linear.None,!0);this.tint=config.cubotHoverTint;this.text.visible=!0};a.prototype.onTileExit=function(){mar.game.tweens.removeFrom(this);mar.game.add.tween(this).to({isoZ:15},400,Phaser.Easing.Bounce.Out,
|
||||
!0);mar.game.add.tween(this.scale).to({x:1,y:1},200,Phaser.Easing.Linear.None,!0);this.tint=config.cubotTint;this.text.visible=!1};a.prototype.updateObject=function(a){};return a}(GameObject),Direction;(function(b){b[b.NORTH=0]="NORTH";b[b.EAST=1]="EAST";b[b.SOUTH=2]="SOUTH";b[b.WEST=3]="WEST"})(Direction||(Direction={}));var TileType;(function(b){b[b.PLAIN=0]="PLAIN";b[b.WALL=1]="WALL";b[b.IRON=2]="IRON";b[b.COPPER=3]="COPPER"})(TileType||(TileType={}));
|
||||
var Tile=function(b){function a(a,d,e,f){e=b.call(this,mar.game,Util.getIsoX(a),Util.getIsoY(d),0,"sheet",e)||this;e.baseZ=0;e.tileX=a;e.tileY=d;e.anchor.set(.5,f);return e}__extends(a,b);a.createTile=function(a,b,e){switch(a){case TileType.WALL:return new WallTile(b,e);case TileType.IRON:return new IronTile(b,e);case TileType.COPPER:return new CopperTile(b,e);default:return new PlainTile(b,e)}};a.prototype.onHover=function(){this.tint=config.tileHoverTint;mar.game.add.tween(this).to({isoZ:this.baseZ+
|
||||
8},200,Phaser.Easing.Quadratic.InOut,!0);mar.tileIndicator.tileX=this.tileX;mar.tileIndicator.tileY=this.tileY;mar.tileIndicator.tileType=this.tileType};a.prototype.onExit=function(){this.tint=this.baseTint;mar.game.add.tween(this).to({isoZ:this.baseZ},200,Phaser.Easing.Quadratic.InOut,!0)};a.prototype.setText=function(a,b){void 0!==this.textSprite&&this.textSprite.destroy();this.textSprite=mar.game.make.text(0,16,a,{fontSize:22,fill:b,stroke:"#FFFFFF",strokeThickness:1,font:"fixedsys"});this.textSprite.alpha=
|
||||
.6;this.textSprite.anchor.set(.5,0);this.addChild(this.textSprite)};return a}(Phaser.Plugin.Isometric.IsoSprite),PlainTile=function(b){function a(a,d){a=b.call(this,a,d,config.plainSprite,0)||this;a.baseTint=config.tileTint;a.tint=a.baseTint;a.tileType="plain";return a}__extends(a,b);return a}(Tile),WallTile=function(b){function a(a,d){a=b.call(this,a,d,config.wallSprite,.2)||this;a.baseTint=config.wallTint;a.tint=a.baseTint;a.tileType="wall";return a}__extends(a,b);return a}(Tile),IronTile=function(b){function a(a,
|
||||
d){a=b.call(this,a,d,config.plainSprite,0)||this;a.baseTint=config.oreTint;a.tint=a.baseTint;a.setText("Iron",config.textIron);a.tileType="iron";return a}__extends(a,b);return a}(Tile),CopperTile=function(b){function a(a,d){a=b.call(this,a,d,config.plainSprite,0)||this;a.baseTint=config.oreTint;a.tint=a.baseTint;a.setText("Copper",config.textCopper);a.tileType="copper";return a}__extends(a,b);return a}(Tile),World=function(){function b(a,b){this.tiles=[];this.objects=[];this.northArrow=new WorldArrow(528,
|
||||
-10,"ui/arrow_north",Direction.NORTH);mar.isoGroup.add(this.northArrow);this.eastArrow=new WorldArrow(1115,587,"ui/arrow_east",Direction.EAST);mar.isoGroup.add(this.eastArrow);this.southArrow=new WorldArrow(0,0,"ui/arrow_south",Direction.SOUTH);mar.isoGroup.add(this.southArrow);this.westArrow=new WorldArrow(-60,587,"ui/arrow_west",Direction.WEST);mar.isoGroup.add(this.westArrow);this.setTerrain(a,b)}b.prototype.setTerrain=function(a,b){DEBUG&&console.log("[MAR] Creating tilemap of size "+b);for(var c=
|
||||
0;c<b;c++)for(var e=0;e<b;e++){var f=Tile.createTile(a[e*b+c],c,e);this.tiles.push(f);mar.isoGroup.add(f)}this.eastArrow.isoY=32*(b+2);this.eastArrow.isoX=72.5*b-20;this.southArrow.isoX=32*(b+1);this.southArrow.isoY=72.5*b+20;mar.game.world.width=128*(b+2);mar.game.world.height=64*(b+2)};b.prototype.setBigMessage=function(a){this.bigMessage=mar.game.add.text(908,450,a,{fontSize:46,fill:config.bigMessageFill,stroke:config.textStroke,strokeThickness:2,font:"fixedsys"},mar.textGroup)};b.prototype.removeBigMessage=
|
||||
function(){void 0!=this.bigMessage&&(this.bigMessage.destroy(),DEBUG&&console.log("[MAR] Destroyed big message"))};b.prototype.getObject=function(a){for(var b=0;b<this.objects.length;b++)if(this.objects[b].id===a)return this.objects[b];return null};b.prototype.handleObjectsUpdate=function(a){for(var b=0;b<this.objects.length;b++)this.objects[b].updated=!1;for(b=0;b<a.length;b++){var d=this.getObject(a[b].i);null!==d?(d.updated=!0,d.updateObject(a[b])):(d=GameObject.createObject(a[b]),null!=d?(d.updated=
|
||||
!0,this.objects.push(d),mar.isoGroup.add(d)):DEBUG&&console.log("Couldn't create object with objType "+a[b].t))}for(b=0;b<this.objects.length;b++)this.objects[b].updated||("guest"!==mar.client.username&&this.objects[b]instanceof Cubot&&this.objects[b].username===mar.client.username&&(mar.client.findMyRobot(),DEBUG&&console.log("[MAR] Following Cubot "+mar.client.username)),this.objects[b].destroy(),this.objects.splice(b,1))};b.prototype.updateTerrain=function(a,b){for(var c=0;c<this.objects.length;c++)this.objects[c].destroy();
|
||||
for(c=0;c<this.tiles.length;c++)this.tiles[c].destroy();this.objects=[];this.tiles=[];this.setTerrain(a,b);mar.game.iso.topologicalSort(mar.isoGroup)};return b}(),WorldArrow=function(b){function a(a,d,e,f){var c=b.call(this,mar.game,a,d,10,"sheet",e)||this;c.hoverText=mar.game.make.text(10,10,Direction[f],config.arrowTextStyle);c.addChild(c.hoverText);c.hoverText.visible=!1;c.hoverText.anchor.set(0,0);c.inputEnabled=!0;c.events.onInputDown.add(function(){var a=mar.client.worldX+Util.getDeltaX(f),
|
||||
b=mar.client.worldY+Util.getDeltaY(f);mar.client.worldX=a%mar.client.maxWidth;mar.client.worldY=b%mar.client.maxWidth;mar.client.requestTerrain()});c.events.onInputOver.add(function(){c.tint=config.arrowHoverTint;c.hoverText.visible=!0;document.body.style.cursor="pointer"});c.events.onInputOut.add(function(){c.tint=config.arrowTint;c.hoverText.visible=!1;document.body.style.cursor="default"});return c}__extends(a,b);return a}(Phaser.Plugin.Isometric.IsoSprite),defaultText=" _______ __ __\n| _ |.-----.---.-.----.| |--.|__|.----.-----.----.-----.\n| || _ | _ | __|| || || __| _ | _| _ |\n|___|___|| __|___._|____||__|__||__||____|_____|__| | __|\n |__| |__|\n\nVersion 1.3A, 1985-05-17\nInitialising Universal Communication Port connection...Done\nCurrent date is 2790-01-14\nCubot Status: Much Assembly Required\n\n\nMore text down here\n",
|
||||
ConsoleMode;(function(b){b[b.CLEAR=0]="CLEAR";b[b.NORMAL=1]="NORMAL"})(ConsoleMode||(ConsoleMode={}));
|
||||
var PlainTextConsoleMode=function(){return function(b,a){this.width=b;this.dialImage=a}}(),PlainTextConsole=function(){function b(a,c,d,e,f,h){this.colorToggled=!1;this.autoScroll=!0;this.modes=[];this.lastLineLength=0;this.txtDiv=document.getElementById(c);this.colorButton=document.getElementById(d);this.scrollButton=document.getElementById(e);this.resetButton=document.getElementById(f);this.widthDial=document.getElementById(h);var g=this;this.colorButton.onclick=function(){g.toggleColor(g)};this.scrollButton.onclick=
|
||||
function(){g.toggleScrolling(g)};this.resetButton.onclick=function(){g.reset(g)};this.widthDial.onclick=function(){b.widthDialClick(g)};this.consoleText=this.txtDiv.innerHTML=a;this.modes.push(new PlainTextConsoleMode(16,"./images/knob-170.png"));this.modes.push(new PlainTextConsoleMode(24,"./images/knob-123.png"));this.modes.push(new PlainTextConsoleMode(40,"./images/knob-90.png"));this.modes.push(new PlainTextConsoleMode(56,"./images/knob-65.png"));this.modes.push(new PlainTextConsoleMode(64,"./images/knob-10.png"));
|
||||
this.mode=3}b.prototype.toggleColor=function(a){a.colorToggled?(a.colorToggled=!1,a.colorButton.src="./images/pdp8ion.png",a.txtDiv.classList.remove("ctr-selection-inverted"),a.txtDiv.classList.remove("ctr-text-inverted"),a.txtDiv.classList.add("ctr-selection"),a.txtDiv.classList.add("ctr-text")):(a.colorToggled=!0,a.colorButton.src="./images/pdp8ioff.png",a.txtDiv.classList.add("ctr-selection-inverted"),a.txtDiv.classList.add("ctr-text-inverted"),a.txtDiv.classList.remove("ctr-selection"),a.txtDiv.classList.remove("ctr-text"))};
|
||||
b.prototype.toggleScrolling=function(a){a.autoScroll?(a.autoScroll=!1,a.scrollButton.src="./images/pdp8ion.png"):(a.autoScroll=!0,a.scrollButton.src="./images/pdp8ioff.png",a.txtDiv.scrollTop=a.txtDiv.scrollHeight)};b.prototype.reset=function(a){a.txtDiv.innerHTML="";a.consoleText="";a.lastLineLength=0;a.resetButton.src="./images/pdp8ioff.png";window.setTimeout(function(){a.resetButton.src="./images/pdp8ion.png"},150)};b.widthDialClick=function(a){a.mode<a.modes.length-1?a.mode++:a.mode=0;a.widthDial.src=
|
||||
a.modes[a.mode].dialImage};b.prototype.handleConsoleBufferUpdate=function(a,b){b==ConsoleMode.CLEAR&&this.reset(this);for(b=0;b<a.length;b++){var c=a[b].indexOf("\x00");c=a[b].substring(0,-1==c?void 0:c);for(var e=0;e<c.length;e++)"\n"==c[e]?(this.consoleText+="\n",this.lastLineLength=0):this.lastLineLength<this.modes[this.mode].width?(this.consoleText+=c[e],this.lastLineLength++):(this.consoleText+="\n",this.consoleText+=c[e],this.lastLineLength=1)}this.txtDiv.innerText=this.consoleText;this.autoScroll&&
|
||||
(this.txtDiv.scrollTop=this.txtDiv.scrollHeight)};return b}();
|
254
mar/console.css
Normal file
@ -0,0 +1,254 @@
|
||||
* {
|
||||
-webkit-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
#console-wrapper {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#console-wrapper-left {
|
||||
|
||||
width: 870px;
|
||||
height: 400px;
|
||||
|
||||
position: relative;
|
||||
|
||||
line-height: 1.2;
|
||||
display: inline-block;
|
||||
margin: 0;
|
||||
z-index: 1;
|
||||
|
||||
}
|
||||
|
||||
.piece {
|
||||
display: block;
|
||||
height: 100%;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.noclick {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
#console-wrapper-side {
|
||||
width: 120px;
|
||||
height: 400px;
|
||||
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
margin: 0;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
#shadow-wrapper {
|
||||
display: inline-block;
|
||||
-webkit-box-shadow: 0 0 1rem black;
|
||||
box-shadow: 0 0 1rem black;
|
||||
border-radius: 2rem;
|
||||
height: 400px;
|
||||
}
|
||||
|
||||
.sideFrame {
|
||||
background-color: #e7e7e7;
|
||||
border-radius: 0 2rem 2rem 0;
|
||||
border: 1rem solid #e7e7e7;
|
||||
border-left: hidden;
|
||||
border-bottom-color: #E3E3E3;
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
text-align: left;
|
||||
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.frame {
|
||||
background-color: transparent;
|
||||
border-radius: 2rem 0 0 2rem;
|
||||
border: 1rem solid #e7e7e7;
|
||||
border-bottom-color: #E3E3E3;
|
||||
-webkit-box-shadow: inset 0 0 4rem black, inset 0 0 3rem black;
|
||||
box-shadow: inset 0 0 4rem black, inset 0 0 3rem black;
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.vertical-text {
|
||||
position: absolute;
|
||||
font-family: fixedsys;
|
||||
font-size: 16pt;
|
||||
|
||||
left: -4px;
|
||||
top: 125px;
|
||||
|
||||
-webkit-transform: rotate(270deg);
|
||||
-moz-transform: rotate(270deg);
|
||||
-ms-transform: rotate(270deg);
|
||||
-o-transform: rotate(270deg);
|
||||
transform: rotate(270deg);
|
||||
-webkit-transform-origin: 0 0;
|
||||
-moz-transform-origin: 0 0;
|
||||
-ms-transform-origin: 0 0;
|
||||
-o-transform-origin: 0 0;
|
||||
transform-origin: 0 0;
|
||||
}
|
||||
|
||||
#consoleText {
|
||||
font-family: 'fixedsys';
|
||||
font-size: 24px;
|
||||
white-space: pre-wrap;
|
||||
-webkit-animation: crt-output 10ms infinite;
|
||||
animation: crt-output 10ms infinite;
|
||||
overflow-y: scroll;
|
||||
position: absolute;
|
||||
padding: 3rem 2rem;
|
||||
pointer-events: auto;
|
||||
text-align: left;
|
||||
text-shadow: 0 0.2rem 1rem #0c7b46;
|
||||
z-index: -1;
|
||||
}
|
||||
|
||||
#consoleText::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@-webkit-keyframes crt-output {
|
||||
0% {
|
||||
opacity: 0.95;
|
||||
}
|
||||
50% {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes crt-output {
|
||||
0% {
|
||||
opacity: 0.95;
|
||||
}
|
||||
50% {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.scanlines {
|
||||
background: -webkit-gradient(linear, left top, left bottom, from(rgba(255, 255, 255, 0)), color-stop(50%, rgba(255, 255, 255, 0)), color-stop(70%, rgba(0, 0, 0, 0.2)), to(rgba(0, 0, 0, 0.6)));
|
||||
background: linear-gradient(to bottom, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0) 50%, rgba(0, 0, 0, 0.2) 70%, rgba(0, 0, 0, 0.6));
|
||||
background-size: 100% 0.3rem;
|
||||
border-radius: 2rem;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.glow {
|
||||
-webkit-animation: crt-glow 20s infinite;
|
||||
animation: crt-glow 20s infinite;
|
||||
background: radial-gradient(circle at 50% 50%, #1bd459 0%, rgba(27, 212, 89, 0.88) 58%, rgba(21, 235, 92, 0.57) 80%, rgba(19, 94, 29, 0.27) 93%, rgba(10, 23, 12, 0) 100%);
|
||||
opacity: 0.15;
|
||||
pointer-events: none;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
@-webkit-keyframes crt-glow {
|
||||
0% {
|
||||
opacity: 0.1;
|
||||
}
|
||||
50% {
|
||||
opacity: 0.2;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes crt-glow {
|
||||
0% {
|
||||
opacity: 0.1;
|
||||
}
|
||||
50% {
|
||||
opacity: 0.2;
|
||||
}
|
||||
}
|
||||
|
||||
.ctr-selection::-moz-selection {
|
||||
background-color: #14fdce;
|
||||
color: #031e11;
|
||||
}
|
||||
|
||||
.ctr-selection::selection {
|
||||
background-color: #14fdce;
|
||||
color: #031e11;
|
||||
}
|
||||
|
||||
.ctr-selection-inverted::-moz-selection {
|
||||
background-color: #031e11;
|
||||
color: #14fdce;
|
||||
}
|
||||
|
||||
.ctr-selection-inverted::selection {
|
||||
background-color: #031e11;
|
||||
color: #14fdce;
|
||||
}
|
||||
|
||||
.ctr-text {
|
||||
color: #14fdce;
|
||||
background-color: #031e11;
|
||||
}
|
||||
|
||||
.ctr-text-inverted {
|
||||
color: #031e11;
|
||||
background-color: #14fdce;
|
||||
}
|
||||
|
||||
/*Buttons*/
|
||||
|
||||
.pdp8Button {
|
||||
cursor: pointer;
|
||||
border: none;
|
||||
outline: none;
|
||||
|
||||
width: 24px;
|
||||
height: 55px;
|
||||
display: inline-block;
|
||||
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.pdp8Button:focus {
|
||||
outline-width: 0;
|
||||
}
|
||||
|
||||
.dial-backPlate {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 60%;
|
||||
|
||||
height: 83px;
|
||||
|
||||
}
|
||||
|
||||
.dial {
|
||||
width: 65px;
|
||||
height: 65px;
|
||||
padding: 0;
|
||||
display: inline-block;
|
||||
pointer-events: auto;
|
||||
cursor: pointer;
|
||||
|
||||
border: none;
|
||||
outline: none;
|
||||
|
||||
position: absolute;
|
||||
left: 27px;
|
||||
top: 10px;
|
||||
}
|
||||
|
||||
.dial-lines {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
pointer-events: none;
|
||||
|
||||
}
|
1
mar/console.min.css
vendored
Normal file
@ -0,0 +1 @@
|
||||
*{-webkit-box-sizing:border-box;box-sizing:border-box}#console-wrapper{text-align:center}#console-wrapper-left{width:870px;height:400px;position:relative;line-height:1.2;display:inline-block;margin:0;z-index:1}.piece{display:block;height:100%;left:0;top:0;width:100%}.noclick{pointer-events:none}#console-wrapper-side{width:120px;height:400px;position:relative;z-index:1;margin:0;display:inline-block}#shadow-wrapper{display:inline-block;-webkit-box-shadow:0 0 1rem black;box-shadow:0 0 1rem black;border-radius:2rem;height:400px}.sideFrame{background-color:#e7e7e7;border-radius:0 2rem 2rem 0;border:1rem solid #e7e7e7;border-left:hidden;border-bottom-color:#e3e3e3;position:absolute;width:100%;height:100%;text-align:left;pointer-events:auto}.frame{background-color:transparent;border-radius:2rem 0 0 2rem;border:1rem solid #e7e7e7;border-bottom-color:#e3e3e3;-webkit-box-shadow:inset 0 0 4rem black,inset 0 0 3rem black;box-shadow:inset 0 0 4rem black,inset 0 0 3rem black;position:absolute;width:100%;height:100%;pointer-events:none}.vertical-text{position:absolute;font-family:fixedsys;font-size:16pt;left:-4px;top:125px;-webkit-transform:rotate(270deg);-moz-transform:rotate(270deg);-ms-transform:rotate(270deg);-o-transform:rotate(270deg);transform:rotate(270deg);-webkit-transform-origin:0 0;-moz-transform-origin:0 0;-ms-transform-origin:0 0;-o-transform-origin:0 0;transform-origin:0 0}#consoleText{font-family:'fixedsys';font-size:24px;white-space:pre-wrap;-webkit-animation:crt-output 10ms infinite;animation:crt-output 10ms infinite;overflow-y:scroll;position:absolute;padding:3rem 2rem;pointer-events:auto;text-align:left;text-shadow:0 .2rem 1rem #0c7b46;z-index:-1}#consoleText::-webkit-scrollbar{display:none}@-webkit-keyframes crt-output{0{opacity:.95}50%{opacity:1}}@keyframes crt-output{0{opacity:.95}50%{opacity:1}}.scanlines{background:-webkit-gradient(linear,left top,left bottom,from(rgba(255,255,255,0)),color-stop(50%,rgba(255,255,255,0)),color-stop(70%,rgba(0,0,0,0.2)),to(rgba(0,0,0,0.6)));background:linear-gradient(to bottom,rgba(255,255,255,0),rgba(255,255,255,0) 50%,rgba(0,0,0,0.2) 70%,rgba(0,0,0,0.6));background-size:100% .3rem;border-radius:2rem;position:absolute}.glow{-webkit-animation:crt-glow 20s infinite;animation:crt-glow 20s infinite;background:radial-gradient(circle at 50% 50%,#1bd459 0,rgba(27,212,89,0.88) 58%,rgba(21,235,92,0.57) 80%,rgba(19,94,29,0.27) 93%,rgba(10,23,12,0) 100%);opacity:.15;pointer-events:none;position:relative}@-webkit-keyframes crt-glow{0{opacity:.1}50%{opacity:.2}}@keyframes crt-glow{0{opacity:.1}50%{opacity:.2}}.ctr-selection::-moz-selection{background-color:#14fdce;color:#031e11}.ctr-selection::selection{background-color:#14fdce;color:#031e11}.ctr-selection-inverted::-moz-selection{background-color:#031e11;color:#14fdce}.ctr-selection-inverted::selection{background-color:#031e11;color:#14fdce}.ctr-text{color:#14fdce;background-color:#031e11}.ctr-text-inverted{color:#031e11;background-color:#14fdce}.pdp8Button{cursor:pointer;border:0;outline:0;width:24px;height:55px;display:inline-block;margin:0;padding:0;pointer-events:auto}.pdp8Button:focus{outline-width:0}.dial-backPlate{position:absolute;left:0;top:60%;height:83px}.dial{width:65px;height:65px;padding:0;display:inline-block;pointer-events:auto;cursor:pointer;border:0;outline:0;position:absolute;left:27px;top:10px}.dial-lines{position:absolute;left:0;pointer-events:none}
|
@ -4,7 +4,6 @@ OPERAND_MEM_IMM = 1;
|
||||
OPERAND_MEM_REG = 2;
|
||||
OPERAND_IMM = 3;
|
||||
|
||||
|
||||
//Remove default syntax checker
|
||||
editor = ace.edit("editor");
|
||||
editor.session.setOption("useWorker", false);
|
||||
@ -404,4 +403,92 @@ function editorClick() {
|
||||
document.getElementById("gameBtns").setAttribute("style", "display: none");
|
||||
}
|
||||
|
||||
//-----
|
||||
|
||||
//Check if browser supports local storage if not than bad luck, use something else than IE7
|
||||
var editorStorage;
|
||||
if (typeof window.localStorage !== 'undefined') {
|
||||
editorStorage = window.localStorage;
|
||||
} else {
|
||||
editorStorage = false;
|
||||
}
|
||||
|
||||
//Default should be 'theme/tommorow.js' or loaded from local storage
|
||||
var editorThemeOptions = {
|
||||
available: [
|
||||
"theme/ambiance", "theme/chaos", "theme/chrome",
|
||||
"theme/clouds", "theme/clouds_midnight", "theme/cobalt",
|
||||
"theme/crimson_editor", "theme/dawn", "theme/dracula",
|
||||
"theme/dreamweaver", "theme/eclipse", "theme/github",
|
||||
"theme/gob", "theme/gruvbox", "theme/idle_fingers",
|
||||
"theme/iplastic", "theme/katzenmilch", "theme/kr_theme",
|
||||
"theme/kuroir", "theme/merbivore", "theme/merbivore_soft",
|
||||
"theme/mono_industrial", "theme/monokai", "theme/pastel_on_dark",
|
||||
"theme/solarized_dark", "theme/solarized_light", "theme/sqlserver",
|
||||
"theme/terminal", "theme/textmate", "theme/tomorrow",
|
||||
"theme/tomorrow_night_blue", "theme/tomorrow_night_bright", "theme/tomorrow_night_eighties",
|
||||
"theme/tomorrow_night", "theme/twilight", "theme/vibrant_ink", "theme/xcode"
|
||||
],
|
||||
defaultTheme: "theme/tomorrow"
|
||||
};
|
||||
|
||||
//Get the stored default theme
|
||||
if (editorStorage) {
|
||||
var storedTheme = editorStorage.getItem('editorTheme');
|
||||
if (storedTheme !== null && editorThemeOptions.available.indexOf(storedTheme) !== -1) {
|
||||
editorThemeOptions.defaultTheme = storedTheme;
|
||||
}
|
||||
}
|
||||
|
||||
//Cache element reference
|
||||
var editorThemeSelectElement = document.getElementById("editorTheme");
|
||||
|
||||
//Event handler
|
||||
function editorOnThemeChange() {
|
||||
if (editorThemeSelectElement === null) {
|
||||
console.error("editorOnThemeChange() :: editorThemeSelectElement seems to be 'null'");
|
||||
return;
|
||||
}
|
||||
var select = editorThemeSelectElement;
|
||||
var option = select.options[select.selectedIndex];
|
||||
|
||||
if (editorThemeOptions.available.indexOf(option.value) === -1) {
|
||||
console.error("editorOnThemeChange() :: user somehow selected an invalid theme : '" + option.value + "' for '" + option.text + "'");
|
||||
return;
|
||||
}
|
||||
|
||||
//Store locally so it gets remembered
|
||||
if (editorStorage) {
|
||||
editorStorage.setItem('editorTheme', option.value);
|
||||
}
|
||||
|
||||
//Set theme
|
||||
editor.setTheme("ace/" + option.value);
|
||||
}
|
||||
|
||||
//Add handler to listen to event
|
||||
editorThemeSelectElement.addEventListener('change', editorOnThemeChange);
|
||||
|
||||
//Populate select
|
||||
editorThemeOptions.available.forEach(function (theme) {
|
||||
var option = document.createElement("option");
|
||||
option.value = theme;
|
||||
option.text = theme.substring(6); // "theme/{text}" -> extract text to set as text user sees
|
||||
|
||||
//Make sure default is also the one that is selected
|
||||
if (theme === editorThemeOptions.defaultTheme) {
|
||||
option.selected = true;
|
||||
}
|
||||
|
||||
editorThemeSelectElement.appendChild(option);
|
||||
});
|
||||
|
||||
//Manually call handler once
|
||||
editorOnThemeChange();
|
||||
|
||||
editor.getSession().setMode("ace/mode/mar");
|
||||
editor.setFontSize(16);
|
||||
editor.setDisplayIndentGuides(false);
|
||||
document.getElementById('editor').style.fontFamily = "fixedsys";
|
||||
|
||||
editor.on("change", parse);
|
||||
|
6
mar/editor.min.js
vendored
@ -14,4 +14,8 @@ function parseInstruction(a,c,b){a=removeComment(a);a=removeLabel(a);var d=getTo
|
||||
getOperandType(d,c);var f=getOperandType(a,c);e===OPERAND_INVALID?c.annotations.push({row:b,column:0,text:"Invalid operand: "+d,type:"error"}):f===OPERAND_INVALID?c.annotations.push({row:b,column:0,text:"Invalid operand: "+a,type:"error"}):e===OPERAND_IMM&&c.annotations.push({row:b,column:0,text:"Destination operand can't be an immediate value",type:"error"})}else c.annotations.push({row:b,column:0,text:e+" instruction with 2 operands is illegal",type:"error"});else 1<d.length?(d=a.substring(a.indexOf(e)+
|
||||
e.length).trim(),/\b(?:push|mul|pop|div|neg|call|jnz|jg|jl|jge|jle|hwi|hwq|jz|js|jns|ret|jmp|not|jc|jnc|jo|jno|inc|dec)\b/.test(e.toLowerCase())?getOperandType(d,c)===OPERAND_INVALID&&c.annotations.push({row:b,column:0,text:"Invalid operand: "+d,type:"error"}):c.annotations.push({row:b,column:0,text:e+" instruction with 1 operand is illegal",type:"error"})):/\b(?:ret|brk|nop)\b/.test(e.toLowerCase())||c.annotations.push({row:b,column:0,text:e+" instruction with no operand is illegal",type:"error"});
|
||||
else c.annotations.push({row:b,column:0,text:"Unknown mnemonic: "+e,type:"error"})}function parse(){for(var a=ace.edit("editor").getValue().split("\n"),c={labels:[],annotations:[]},b=0;b<a.length;b++)checkForLabel(a[b],c);for(b=0;b<a.length;b++)checkForSegmentDeclaration(a[b])||checkForEQUInstruction(a[b],c,b)||checkForORGInstruction(a[b],c,b)||parseInstruction(a[b],c,b);editor.getSession().setAnnotations(c.annotations)}
|
||||
function gameClick(){document.getElementById("editorBtns").setAttribute("style","display: none");document.getElementById("gameBtns").setAttribute("style","")}function editorClick(){document.getElementById("editorBtns").setAttribute("style","");document.getElementById("gameBtns").setAttribute("style","display: none")}editor.on("change",parse);
|
||||
function gameClick(){document.getElementById("editorBtns").setAttribute("style","display: none");document.getElementById("gameBtns").setAttribute("style","")}function editorClick(){document.getElementById("editorBtns").setAttribute("style","");document.getElementById("gameBtns").setAttribute("style","display: none")}var editorStorage;editorStorage="undefined"!==typeof window.localStorage?window.localStorage:!1;
|
||||
var editorThemeOptions={available:"theme/ambiance theme/chaos theme/chrome theme/clouds theme/clouds_midnight theme/cobalt theme/crimson_editor theme/dawn theme/dracula theme/dreamweaver theme/eclipse theme/github theme/gob theme/gruvbox theme/idle_fingers theme/iplastic theme/katzenmilch theme/kr_theme theme/kuroir theme/merbivore theme/merbivore_soft theme/mono_industrial theme/monokai theme/pastel_on_dark theme/solarized_dark theme/solarized_light theme/sqlserver theme/terminal theme/textmate theme/tomorrow theme/tomorrow_night_blue theme/tomorrow_night_bright theme/tomorrow_night_eighties theme/tomorrow_night theme/twilight theme/vibrant_ink theme/xcode".split(" "),defaultTheme:"theme/tomorrow"};
|
||||
if(editorStorage){var storedTheme=editorStorage.getItem("editorTheme");null!==storedTheme&&-1!==editorThemeOptions.available.indexOf(storedTheme)&&(editorThemeOptions.defaultTheme=storedTheme)}var editorThemeSelectElement=document.getElementById("editorTheme");
|
||||
function editorOnThemeChange(){if(null===editorThemeSelectElement)console.error("editorOnThemeChange() :: editorThemeSelectElement seems to be 'null'");else{var a=editorThemeSelectElement;a=a.options[a.selectedIndex];-1===editorThemeOptions.available.indexOf(a.value)?console.error("editorOnThemeChange() :: user somehow selected an invalid theme : '"+a.value+"' for '"+a.text+"'"):(editorStorage&&editorStorage.setItem("editorTheme",a.value),editor.setTheme("ace/"+a.value))}}
|
||||
editorThemeSelectElement.addEventListener("change",editorOnThemeChange);editorThemeOptions.available.forEach(function(a){var c=document.createElement("option");c.value=a;c.text=a.substring(6);a===editorThemeOptions.defaultTheme&&(c.selected=!0);editorThemeSelectElement.appendChild(c)});editorOnThemeChange();editor.getSession().setMode("ace/mode/mar");editor.setFontSize(16);editor.setDisplayIndentGuides(!1);document.getElementById("editor").style.fontFamily="fixedsys";editor.on("change",parse);
|
||||
|
30
mar/game.css
@ -1,7 +1,7 @@
|
||||
|
||||
@font-face {
|
||||
font-family: 'fixedsys';
|
||||
src: url("./fonts/FSEX301-L2.ttf");
|
||||
src: url("../assets/fonts/FSEX301-L2.ttf");
|
||||
}
|
||||
|
||||
#tabs {
|
||||
@ -11,7 +11,6 @@
|
||||
|
||||
.container {
|
||||
width: 100%;
|
||||
|
||||
}
|
||||
|
||||
#game {
|
||||
@ -37,7 +36,32 @@
|
||||
}
|
||||
|
||||
.ace_gutter-cell.ace_error {
|
||||
background-image: url("sprites/err_annotation.png") !important;
|
||||
background-image: url("../images/err_annotation.png") !important;
|
||||
background-position: 2px center;
|
||||
}
|
||||
|
||||
#tabs ul, li, a {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
#tabs .ui-tabs-nav li.ui-tabs-active a {
|
||||
background: #a1cd9b;
|
||||
}
|
||||
|
||||
#editorBtns {
|
||||
display: inline;
|
||||
|
||||
}
|
||||
|
||||
.editorBtn {
|
||||
background: #895EC3;
|
||||
padding: .85em 1em
|
||||
}
|
||||
|
||||
.editorBtn:hover {
|
||||
background: #A386CA;
|
||||
}
|
||||
|
||||
#gameBtns {
|
||||
display: inline;
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
///<reference path="phaser.plugin.isometric.d.ts"/>
|
||||
///<reference path="phaser.d.ts"/>
|
||||
// Typescript V2.4.1
|
||||
|
||||
let RENDERER_WIDTH = document.getElementById("game").clientWidth * window.devicePixelRatio;
|
||||
@ -11,7 +9,6 @@ let config = {
|
||||
tileTint: 0xFFFFFF,
|
||||
wallTint: 0xDDDDDD,
|
||||
oreTint: 0xF3F3F3,
|
||||
worldSize: 16,
|
||||
cubotHoverTint: 0x00FF00,
|
||||
cubotTint: 0xFFFFFF,
|
||||
textFill: "#FFFFFF",
|
||||
@ -28,7 +25,7 @@ let config = {
|
||||
copperFill: "#C87D38",
|
||||
plainSprite: "tiles/tile",
|
||||
wallSprite: "tiles/bigTile",
|
||||
walkDuration: 800,
|
||||
walkDuration: 800, //walk animation duration in ms
|
||||
holoStyle: (fill) => {
|
||||
return {
|
||||
fontSize: 32,
|
||||
@ -38,7 +35,7 @@ let config = {
|
||||
font: "fixedsys"
|
||||
}
|
||||
},
|
||||
kbBufferX: 225,
|
||||
kbBufferX: 225, ///Position of the keyboard buffer fill on screen
|
||||
kbBufferY: 20,
|
||||
arrowTextStyle: {
|
||||
fontSize: 32,
|
||||
@ -47,25 +44,18 @@ let config = {
|
||||
strokeThickness: 1,
|
||||
font: "fixedsys"
|
||||
},
|
||||
lowEnergy: 100,
|
||||
lowEnergy: 100, //Low energy threshold to change color
|
||||
lowEnergyTint: 0xCC0000,
|
||||
bigMessageFill: "#ff803d",
|
||||
arrowTint: 0xFFFFFF,
|
||||
arrowHoverTint: 0x00FF00,
|
||||
selfUsernameColor: 0xFB4D0A,
|
||||
selfUsernameColor: 0xFB4D0A, //Color of own Cubot's username.
|
||||
otherCubotAlpha: 0.6,
|
||||
defaultWorldSize: 16
|
||||
defaultWorldSize: 16 //Will fallback to this when server does not provide world width
|
||||
|
||||
};
|
||||
|
||||
|
||||
enum TileType {
|
||||
PLAIN,
|
||||
WALL,
|
||||
IRON,
|
||||
COPPER
|
||||
}
|
||||
|
||||
class Util {
|
||||
|
||||
//todo: find a more elegant way of doing this. Maybe this is related: https://github.com/lewster32/phaser-plugin-isometric/issues/7
|
101
mar/old/Game.js
@ -1,101 +0,0 @@
|
||||
|
||||
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);
|
||||
|
||||
|
||||
|
||||
//------------------------------------
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,273 +0,0 @@
|
||||
/**
|
||||
* 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);
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,363 +0,0 @@
|
||||
|
||||
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;
|
||||
|
||||
}
|
@ -1,92 +0,0 @@
|
||||
|
||||
|
||||
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
@ -1,240 +0,0 @@
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -1,311 +0,0 @@
|
||||
"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);
|
||||
|
||||
}
|
1696
mar/old/mar.js
61
mar/old/mar.min.js
vendored
@ -1,61 +0,0 @@
|
||||
DIR_NORTH=0;DIR_EAST=1;DIR_SOUTH=2;DIR_WEST=3;WORLD_HEIGHT=WORLD_WIDTH=16;var colorScheme={tileTint:16777215,wallTint:14540253,cubotHoverTint:65280,cubotTint:16777215,textFill:"#FFFFFF",textStroke:"#9298a8",biomassTint:6535263,biomassHoverTint:65280,tileHoverTint:65280,itemIron:4408129,itemCopper:13139256,hologramFill:"#0aced6",hologramStroke:"#12FFB0",hologramAlpha:.9},mar={kbBuffer:[],kbBufferText:"",animationFrames:{},controlledUnitVisible:!1,lastLines:"",bigMessage:""};
|
||||
CUBOT_WALK_FRAMES={south:240,north:194,west:254,east:164};HARVESTER_WALK_FRAMES={south:347,north:317,west:377,east:287};LOW_ENERGY=100;fullscreen?(RENDERER_WIDTH=window.innerWidth*window.devicePixelRatio-4,RENDERER_HEIGHT=window.innerHeight*window.devicePixelRatio-4):(RENDERER_WIDTH=document.getElementById("game").clientWidth*window.devicePixelRatio,RENDERER_HEIGHT=window.innerHeight/1.4*window.devicePixelRatio);var game=new Phaser.Game(RENDERER_WIDTH,RENDERER_HEIGHT,Phaser.AUTO,"game",null,!0,!1);
|
||||
function dispatchTileLeave(a,b){for(var c=0;c<mar.world.tiles.length;c++){var d=mar.world.tiles[c].tileX,f=mar.world.tiles[c].tileY;mar.world.tiles[c].isWall&&(d===a&&f-1===b||d-1===a&&f-1===b||d-1===a&&f===b)&&1!==mar.world.tiles[c].alpha&&game.add.tween(mar.world.tiles[c]).to({alpha:1},175,Phaser.Easing.Quadratic.In,!0)}}
|
||||
function dispatchTileEnter(a,b){for(var c=0;c<mar.world.tiles.length;c++){var d=mar.world.tiles[c].tileX,f=mar.world.tiles[c].tileY;mar.world.tiles[c].isWall&&(d===a&&f-1===b||d-1===a&&f-1===b||d-1===a&&f===b)&&game.add.tween(mar.world.tiles[c]).to({alpha:.6},300,Phaser.Easing.Quadratic.In,!0)}}
|
||||
function Word(a){var b=this;b.tiles=[];b.objects=[];setupWorldArrows();this.setTerrain=function(a){for(var d=0;d<WORLD_HEIGHT;d++)for(var c=0;c<WORLD_HEIGHT;c++){var e=a[c*WORLD_WIDTH+d];if(1===e)e=game.add.isoSprite(getIsoX(d),getIsoY(c),0,"sheet","tiles/bigTile",isoGroup),e.baseZ=0,e.baseTint=colorScheme.wallTint,e.anchor.set(.5,.2),e.isWall=!0;else{if(2===e)e=game.add.isoSprite(getIsoX(d),getIsoY(c),0,"sheet","tiles/tile",isoGroup),g=game.make.text(0,16,"Iron",{fontSize:22,fill:"#434341",stroke:"#FFFFFF",
|
||||
strokeThickness:1,font:"fixedsys"}),g.alpha=.6,g.anchor.set(.5,0),e.addChild(g),e.baseZ=0,e.baseTint=15987699;else if(3===e){e=game.add.isoSprite(getIsoX(d),getIsoY(c),0,"sheet","tiles/tile",isoGroup);var g=game.make.text(0,16,"Copper",{fontSize:22,fill:"#C87D38",stroke:"#FFFFFF",strokeThickness:1,font:"fixedsys"});g.alpha=.6;g.anchor.set(.5,0);e.addChild(g);e.baseZ=0;e.baseTint=15987699}else e=game.add.isoSprite(getIsoX(d),getIsoY(c),0,"sheet","tiles/tile",isoGroup),e.baseZ=0,e.baseTint=colorScheme.tileTint;
|
||||
e.anchor.set(.5,0)}e.isTile=!0;e.tileX=d;e.tileY=c;e.tint=e.baseTint;b.tiles.push(e)}};this.setTerrain(a);this.update=function(a){for(var b=0;b<mar.world.objects.length;b++)mar.world.objects[b].destroy();for(b=0;b<mar.world.tiles.length;b++)mar.world.tiles[b].destroy();mar.world.objects=[];mar.world.tiles=[];this.setTerrain(a);game.iso.topologicalSort(isoGroup)};this.getObject=function(a){for(var c=0;c<b.objects.length;c++)if(b.objects[c].id===a)return b.objects[c];return null};this.updateObjects=
|
||||
function(a){for(c=0;c<b.objects.length;c++)b.objects[c].updated=!1;for(var c=0;c<a.length;c++){var f=b.getObject(a[c].i);null!==f?(f.updated=!0,updateGameObject(f,a[c])):(f=createGameObject(a[c]),f.updated=!0,b.objects.push(f))}for(c=0;c<b.objects.length;c++)b.objects[c].updated||("guest"!==mar.client.username&&1===b.objects[c].type&&b.objects[c].username===mar.client.username&&(findMyRobot(),console.log("Following Cubot "+mar.client.username)),b.objects[c].destroy(),dispatchTileLeave(b.objects[c].tileX,
|
||||
b.objects[c].tileY),b.objects.splice(c,1))}}
|
||||
function updateGameObject(a,b){a.direction=b.direction;if(1===a.type){a.action=b.action;a.energy=b.energy;if(a.tileX!==b.x||a.tileY!==b.y)2===a.action?(dispatchTileLeave(a.tileX,a.tileY),a.tileX=b.x,a.tileY=b.y,cubotMove(a,a.direction,void 0,CUBOT_WALK_FRAMES)):6===a.action&&(dispatchTileLeave(a.tileX,a.tileY),a.tileX=b.x,a.tileY=b.y,cubotMove(a,a.direction,void 0,CUBOT_WALK_FRAMES,!0));a.heldItem!==b.heldItem&&(void 0!==a.inventory&&a.inventory.destroy(),a.inventory=createInventory([b.heldItem]),
|
||||
a.addChild(a.inventory),a.heldItem=b.heldItem);a.tint!==colorScheme.cubotHoverTint&&(a.tint=a.energy<=LOW_ENERGY?16711680:16777215);switch(a.direction){case DIR_NORTH:a.animations.frame=194;break;case DIR_EAST:a.animations.frame=164;break;case DIR_SOUTH:a.animations.frame=240;break;case DIR_WEST:a.animations.frame=254}void 0!==a.hologram&&a.hologram.destroy();var c=!1;b.holoC&&(c=(b.holoC&16777215).toString(16),c="#"+("000000".substr(c.length)+c));1===b.holoMode?(a.hologram=game.make.text(0,32,"0x"+
|
||||
("0000"+Number(b.holo).toString(16).toUpperCase()).slice(-4),{fontSize:32,fill:c?c:colorScheme.hologramFill,stroke:colorScheme.hologramStroke,strokeThickness:1,font:"fixedsys"}),console.log(Number(c).toString(16))):2===b.holoMode?a.hologram=game.make.text(0,32,b.holoStr.replace(/[\n|\t]/g,""),{fontSize:27,fill:c?c:colorScheme.hologramFill,stroke:colorScheme.hologramStroke,strokeThickness:1,font:"fixedsys"}):3===b.holoMode&&(a.hologram=game.make.text(0,32,Number(b.holo).toString(),{fontSize:32,fill:c?
|
||||
c:colorScheme.hologramFill,stroke:colorScheme.hologramStroke,strokeThickness:1,font:"fixedsys"}));void 0!==a.hologram&&(a.hologram.alpha=colorScheme.hologramAlpha,a.hologram.anchor.set(.5,0),a.addChild(a.hologram),game.add.tween(a.hologram).to({tint:16777200,alpha:colorScheme.hologramAlpha-.1},mar.client.tickLength,Phaser.Easing.Bounce.In,!0));1===a.action&&cubotDig(a,a.direction)}else if(10===a.type){a.action=b.action;if(a.tileX!==b.x||a.tileY!==b.y)dispatchTileLeave(a.tileX,a.tileY),a.tileX=b.x,
|
||||
a.tileY=b.y,cubotMove(a,a.direction,void 0,HARVESTER_WALK_FRAMES);switch(a.direction){case DIR_NORTH:a.animations.frame=HARVESTER_WALK_FRAMES.north;break;case DIR_EAST:a.animations.frame=HARVESTER_WALK_FRAMES.east;break;case DIR_SOUTH:a.animations.frame=HARVESTER_WALK_FRAMES.south;break;case DIR_WEST:a.animations.frame=HARVESTER_WALK_FRAMES.west}}}function itemColor(a){switch(a){case 1:return colorScheme.biomassTint;case 3:return colorScheme.itemIron;case 4:return colorScheme.itemCopper}}
|
||||
function createInventory(a){var b=game.make.group();switch(a.length){case 0:return b;case 1:if(0!==a[0]){var c=game.make.sprite(0,0,"sheet","inventory/inv1x1");c.anchor.set(.5,.1);c.alpha=.5;var d=game.make.sprite(0,0,"sheet","inventory/item");d.anchor.set(.5,.1);d.tint=itemColor(a[0]);b.addChild(c);b.addChild(d)}return b}for(b=0;b<a.length;b++);}
|
||||
function createGameObject(a){if(1===a.t){var b=game.add.isoSprite(getIsoX(a.x),getIsoY(a.y),15,"sheet",null,isoGroup);b.anchor.set(.5,0);b.inputEnabled=!0;b.events.onInputDown.add(function(){debugObj="Cubot: "+b.tileX+", "+b.tileY});b.events.onInputOver.add(function(){document.body.style.cursor="pointer"});b.events.onInputOut.add(function(){document.body.style.cursor="default"});b.id=a.i;b.type=1;b.tileX=a.x;b.tileY=a.y;b.username=a.parent;b.heldItem=a.heldItem;b.direction=a.direction;b.action=a.action;
|
||||
b.energy=a.energy;b.inventory=createInventory([b.heldItem]);b.addChild(b.inventory);dispatchTileEnter(a.x,a.y);b.isAt=function(a,b){return this.tileX===a&&this.tileY===b};b.onTileHover=function(){game.add.tween(this).to({isoZ:45},200,Phaser.Easing.Quadratic.InOut,!0);game.add.tween(this.scale).to({x:1.2,y:1.2},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.cubotHoverTint};b.onTileOut=function(){document.body.style.cursor="default";game.add.tween(this).to({isoZ:15},400,Phaser.Easing.Bounce.Out,
|
||||
!0);game.add.tween(this.scale).to({x:1,y:1},200,Phaser.Easing.Linear.None,!0);this.tint=16777215};b.energy<=LOW_ENERGY&&(b.tint=13369344);b.animations.add("walk_w",mar.animationFrames.walk_w,!0);b.animations.add("walk_s",mar.animationFrames.walk_s,!0);b.animations.add("walk_e",mar.animationFrames.walk_e,!0);b.animations.add("walk_n",mar.animationFrames.walk_n,!0);b.animations.add("dig_w",mar.animationFrames.dig_w,!1);b.animations.add("dig_s",mar.animationFrames.dig_s,!1);b.animations.add("dig_e",
|
||||
mar.animationFrames.dig_e,!1);b.animations.add("dig_n",mar.animationFrames.dig_n,!1);b.queuedAnims=[];switch(b.direction){case DIR_NORTH:b.animations.frame=194;break;case DIR_EAST:b.animations.frame=164;break;case DIR_SOUTH:b.animations.frame=240;break;case DIR_WEST:b.animations.frame=254}a=game.make.text(0,-24,b.username,{fontSize:22,fill:colorScheme.textFill,stroke:colorScheme.textStroke,strokeThickness:2,font:"fixedsys"});a.alpha=.85;a.anchor.set(.5,0);b.username===mar.client.username?a.tint=16469258:
|
||||
b.alpha=.6;b.addChild(a);return b}if(2===a.t){var c=game.add.isoSprite(getIsoX(a.x),getIsoY(a.y),10,"sheet",1,isoGroup);c.animations.add("idle",mar.animationFrames.biomassIdle,!0);c.anchor.set(.5,0);c.type=2;c.tileX=a.x;c.tileY=a.y;c.id=a.i;c.tint=colorScheme.biomassTint;c.hoverText=game.make.text(0,0,"Biomass",{fontSize:22,fill:colorScheme.textFill,stroke:colorScheme.textStroke,strokeThickness:2,font:"fixedsys"});c.hoverText.alpha=0;c.hoverText.anchor.set(.5,0);c.addChild(c.hoverText);c.isAt=function(a,
|
||||
b){return this.tileX===a&&this.tileY===b};c.isAt=function(a,b){return this.tileX===a&&this.tileY===b};c.onTileHover=function(){game.tweens.removeFrom(this);document.body.style.cursor="pointer";game.add.tween(this).to({isoZ:45},200,Phaser.Easing.Quadratic.InOut,!0);this.tint=colorScheme.biomassHoverTint;game.add.tween(this.scale).to({x:1.2,y:1.2},200,Phaser.Easing.Linear.None,!0);game.add.tween(this.hoverText).to({alpha:.9},200,Phaser.Easing.Quadratic.In,!0);c.hoverText.visible=!0};c.onTileOut=function(){game.tweens.removeFrom(this);
|
||||
document.body.style.cursor="default";game.add.tween(this).to({isoZ:15},400,Phaser.Easing.Bounce.Out,!0);game.add.tween(this.scale).to({x:1,y:1},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.biomassTint;game.add.tween(this.hoverText).to({alpha:0},200,Phaser.Easing.Quadratic.Out,!0)};c.animations.play("idle",45,!0);return c}if(10===a.t){var d=game.add.isoSprite(getIsoX(a.x),getIsoY(a.y),15,"sheet",null,isoGroup);d.anchor.set(.5,0);d.id=a.i;d.type=10;d.tileX=a.x;d.tileY=a.y;d.direction=a.direction;
|
||||
d.action=a.action;dispatchTileEnter(a.x,a.y);d.isAt=function(a,b){return this.tileX===a&&this.tileY===b};d.onTileHover=function(){game.add.tween(this).to({isoZ:45},200,Phaser.Easing.Quadratic.InOut,!0);game.add.tween(this.scale).to({x:1.2,y:1.2},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.cubotHoverTint};d.onTileOut=function(){game.add.tween(this).to({isoZ:15},400,Phaser.Easing.Bounce.Out,!0);game.add.tween(this.scale).to({x:1,y:1},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.cubotTint};
|
||||
d.animations.add("walk_w",mar.animationFrames.harvester_walk_w,!0);d.animations.add("walk_s",mar.animationFrames.harvester_walk_s,!0);d.animations.add("walk_e",mar.animationFrames.harvester_walk_e,!0);d.animations.add("walk_n",mar.animationFrames.harvester_walk_n,!0);d.queuedAnims=[];switch(d.direction){case DIR_NORTH:d.animations.frame=HARVESTER_WALK_FRAMES.north;break;case DIR_EAST:d.animations.frame=HARVESTER_WALK_FRAMES.east;break;case DIR_SOUTH:d.animations.frame=HARVESTER_WALK_FRAMES.south;
|
||||
break;case DIR_WEST:d.animations.frame=HARVESTER_WALK_FRAMES.west}return d}if(3===a.t){var f=game.add.isoSprite(getIsoX(a.x),getIsoY(a.y),15,"sheet","objects/factory",isoGroup);f.anchor.set(.5,.25);f.id=a.i;f.type=3;f.tileX=a.x;f.tileY=a.y;f.hoverText=game.make.text(0,0,"Factory",{fontSize:22,fill:colorScheme.textFill,stroke:colorScheme.textStroke,strokeThickness:2,font:"fixedsys"});f.hoverText.alpha=0;f.hoverText.anchor.set(.5,0);f.addChild(f.hoverText);f.isAt=function(a,b){return(this.tileX===a||
|
||||
this.tileX+1===a)&&(this.tileY+1===b||this.tileY===b)};f.onTileHover=function(){game.tweens.removeFrom(this);game.add.tween(this).to({isoZ:25},200,Phaser.Easing.Quadratic.InOut,!0);game.add.tween(this.scale).to({x:1.06,y:1.06},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.cubotHoverTint;game.add.tween(this.hoverText).to({alpha:.9},200,Phaser.Easing.Quadratic.In,!0);f.hoverText.visible=!0};f.onTileOut=function(){game.tweens.removeFrom(this);game.add.tween(this).to({isoZ:15},400,Phaser.Easing.Bounce.Out,
|
||||
!0);game.add.tween(this.scale).to({x:1,y:1},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.cubotTint;game.add.tween(this.hoverText).to({alpha:0},200,Phaser.Easing.Quadratic.Out,!0)};return f}if(4===a.t){var e=game.add.isoSprite(getIsoX(a.x),getIsoY(a.y),15,"sheet","objects/RadioTower",isoGroup);e.anchor.set(.5,.64);e.id=a.i;e.type=4;e.tileX=a.x;e.tileY=a.y;e.hoverText=game.make.text(0,0,"Radio Tower",{fontSize:22,fill:colorScheme.textFill,stroke:colorScheme.textStroke,strokeThickness:2,font:"fixedsys"});
|
||||
e.hoverText.alpha=0;e.hoverText.anchor.set(.5,0);e.addChild(e.hoverText);e.isAt=function(a,b){return this.tileX===a&&this.tileY===b};e.onTileHover=function(){game.tweens.removeFrom(this);game.add.tween(this).to({isoZ:45},200,Phaser.Easing.Quadratic.InOut,!0);game.add.tween(this.scale).to({x:1.15,y:1.15},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.cubotHoverTint;game.add.tween(this.hoverText).to({alpha:.9},200,Phaser.Easing.Quadratic.In,!0);e.hoverText.visible=!0};e.onTileOut=function(){game.tweens.removeFrom(this);
|
||||
game.add.tween(this).to({isoZ:15},400,Phaser.Easing.Bounce.Out,!0);game.add.tween(this.scale).to({x:1,y:1},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.cubotTint;game.add.tween(this.hoverText).to({alpha:0},200,Phaser.Easing.Quadratic.Out,!0)};return e}}function manhanttanDistance(a,b,c,d){return Math.abs(a-c)+Math.abs(b-d)}function codeListener(a){"code"===a.t&&ace.edit("editor").setValue(a.code)}
|
||||
function authListener(a){"auth"===a.t&&("ok"===a.m?(console.log("Auth successful"),mar.client.requestUserInfo()):alert("Authentication failed. Please make sure you are logged in and reload the page."))}function codeResponseListener(a){"codeResponse"===a.t&&alert("Uploaded and assembled "+a.bytes+" bytes")}function userInfoListener(a){"userInfo"===a.t&&(console.log(a),mar.worldX=a.worldX,mar.worldY=a.worldY,mar.maxWidth=a.maxWidth,mar.client.requestTerrain())}
|
||||
function terrainListener(a){"terrain"===a.t&&(mar.bigMessage&&mar.bigMessage.destroy(),a.ok?void 0!==mar.world?(mar.client.socket.send(JSON.stringify({t:"object",x:mar.worldX,y:mar.worldY})),mar.world.update(a.terrain)):(mar.world=new Word(a.terrain),console.log("Gameloop started"),game.input.keyboard.onDownCallback=function(a){document.activeElement===document.getElementById("game")&&((37<=a.keyCode&&40>=a.keyCode||116===a.keyCode||32===a.keyCode)&&a.preventDefault(),"guest"!==mar.client.username&&
|
||||
16>=mar.kbBuffer.length&&(mar.client.sendKeypress(a.keyCode),mar.kbBuffer.push(a.keyCode),mar.kbBufferText=formattedKeyBuffer(mar.kbBuffer)))},game.input.onDown.add(function(){document.getElementById("game").focus()})):(void 0!==mar.world?mar.world.update([]):mar.world=new Word([]),mar.bigMessage=game.add.text(908,450,"[Uncharted World]",{fontSize:46,fill:"#ff803d",stroke:colorScheme.textStroke,strokeThickness:2,font:"fixedsys"},textGroup)))}
|
||||
function objectListener(a){"object"===a.t&&mar.world.updateObjects(a.objects)}function floppyListener(a){document.getElementById("floppyDown").innerHTML='<i class="fa fa-long-arrow-down" aria-hidden="true"></i> <i class="fa fa-floppy-o" aria-hidden="true"></i>';a=new Blob([a.data],{type:"application/octet-stream"});saveAs(a,"floppy.bin")}
|
||||
function tickListener(a){if("tick"===a.t){mar.client.socket.send(JSON.stringify({t:"object",x:mar.worldX,y:mar.worldY}));void 0!==a.keys&&(mar.kbBuffer=a.keys,mar.kbBufferText=formattedKeyBuffer(mar.kbBuffer));var b=document.getElementById("console");0===a.cm&&(b.innerHTML="",mar.lastLines="");if(void 0!==a.c){for(var c=mar.lastLines,d=0;d<a.c.length;d++)c+=a.c[d];a=b.innerHTML="";var f=c.split("\n");for(d=0;d<f.length;d++)if(40<=f[d].length)for(var e=f[d].match(/.{1,40}/g),g=0;g<e.length;g++)g!==
|
||||
e.length-1&&(a+="\n");else a+=f[d]+"\n";b.innerHTML=a;mar.lastLines=c;b.scrollTop=b.scrollHeight}}}
|
||||
var GameClient=function(a){var b=this,c=[],d=new XMLHttpRequest;d.open("GET","./getServerInfo.php",!0);d.onreadystatechange=function(){4===d.readyState&&200===d.status&&(console.log("Received server info "+d.responseText),setTimeout(function(){var f=JSON.parse(d.responseText);console.log(f.address);b.socket=new WebSocket(f.address);b.username=f.username;b.tickLength=f.tickLength;b.serverName=f.serverName;mar.client.socket.binaryType="arraybuffer";b.socket.onopen=function(){b.socket.send(f.token);
|
||||
c.push(authListener);c.push(userInfoListener);c.push(terrainListener);c.push(tickListener);c.push(objectListener);c.push(codeListener);c.push(codeResponseListener);mar.client.socket.onmessage=function(a){try{var b=JSON.parse(a.data)}catch(h){console.log(h),floppyListener(a)}for(a=0;a<c.length;a++)c[a](b)};b.reloadCode();void 0!==a&&a()};b.socket.onerror=function(a){alert("Can't connect to game server at address "+f.address);console.log(a)};b.socket.onclose=function(a){alert("Disconnected from server");
|
||||
console.log(a)}},100))};d.send(null);this.requestUserInfo=function(){this.socket.send(JSON.stringify({t:"userInfo"}))};this.requestTerrain=function(){this.socket.send(JSON.stringify({t:"terrain",x:mar.worldX,y:mar.worldY}))};this.uploadCode=function(a){console.log("Uploaded code");this.socket.send(JSON.stringify({t:"uploadCode",code:a}))};this.reloadCode=function(){this.socket.send(JSON.stringify({t:"codeRequest"}))};this.sendKeypress=function(a){0!==a&&this.socket.send(JSON.stringify({t:"k",k:a}))};
|
||||
this.requestFloppy=function(){document.getElementById("floppyDown").innerHTML='<i class="fa fa-cog fa-spin fa-fw"></i>';this.socket.send(JSON.stringify({t:"floppyDown"}))};this.notifyFloppyUp=function(){this.socket.send(JSON.stringify({t:"floppyUp"}))}};function dispatchTileHover(a,b){for(var c in mar.world.objects){var d=mar.world.objects[c];if(d.isAt(a,b))d.onTileHover()}}function dispatchTileOut(a,b){for(var c in mar.world.objects){var d=mar.world.objects[c];if(d.isAt(a,b))d.onTileOut()}}
|
||||
var count=0,BasicGame=function(a){};BasicGame.Boot=function(a){};var isoGroup,cursorPos,cursor,textGroup,debugTile,debugObj,objectsGroup,cursors,tmpLine;
|
||||
BasicGame.Boot.prototype={preload:function(){game.load.atlasJSONHash("sheet","./mar/sprites.png","./mar/sprites.json");game.time.advancedTiming=!0;game.plugins.add(new Phaser.Plugin.Isometric(game));game.iso.anchor.setTo(.5,0);game.world.setBounds(0,0,2200,1100);game.camera.x=280;game.camera.y=90;game.stage.disableVisibilityChange=!0;this.scale.scaleMode=Phaser.ScaleManager.RESIZE;this.scale.pageAlignHorizontally=!0;this.scale.pageAlignVertically=!0},create:function(){isoGroup=game.add.group();objectsGroup=
|
||||
game.add.group();textGroup=game.add.group();initialiseAnimations();this.spawnTiles();cursorPos=new Phaser.Plugin.Isometric.Point3;cursors=game.input.keyboard.createCursorKeys()},update:function(){game.scale.setShowAll();game.scale.refresh();game.iso.unproject(game.input.activePointer.position,cursorPos);isoGroup.forEach(function(a){if(a.isTile){var b=a.isoBounds.containsXY(cursorPos.x,cursorPos.y);!a.selected&&b?(a.selected=!0,a.tint=colorScheme.tileHoverTint,debugTile=a.tileX+", "+a.tileY,dispatchTileHover(a.tileX,
|
||||
a.tileY),game.add.tween(a).to({isoZ:a.baseZ+8},200,Phaser.Easing.Quadratic.InOut,!0)):a.selected&&!b&&(dispatchTileOut(a.tileX,a.tileY),a.selected=!1,a.tint=a.baseTint,game.add.tween(a).to({isoZ:a.baseZ},200,Phaser.Easing.Quadratic.InOut,!0))}});this.game.input.activePointer.isDown?(this.game.origDragPoint&&(this.game.camera.x+=this.game.origDragPoint.x-this.game.input.activePointer.position.x,this.game.camera.y+=this.game.origDragPoint.y-this.game.input.activePointer.position.y),this.game.origDragPoint=
|
||||
this.game.input.activePointer.position.clone()):this.game.origDragPoint=null;count++;0===count%10&&game.iso.topologicalSort(isoGroup)},render:function(){void 0!==mar.worldX?game.debug.text("World: ("+Number(mar.worldX).toString(16)+", "+Number(mar.worldY).toString(16)+")",10,20):game.debug.text("World: (?,?)",10,20);debugTile&&game.debug.text(debugTile,10,40);"guest"!==mar.client.username&&game.debug.text(mar.kbBufferText,210,20);void 0!==tmpLine&&(game.debug.geom(tmpLine),game.debug.lineInfo(tmpLine,
|
||||
32,32))},spawnTiles:function(){mar.client=new GameClient}};
|
||||
function setupWorldArrows(){var a=game.make.isoSprite(528,-10,10,"sheet","ui/arrow_north",isoGroup);a.inputEnabled=!0;a.events.onInputDown.add(function(){0===mar.worldY?mar.worldY=mar.maxWidth:mar.worldY--;mar.client.requestTerrain()});a.events.onInputOver.add(function(){a.tint=65280;document.body.style.cursor="pointer"});a.events.onInputOut.add(function(){a.tint=16777215;document.body.style.cursor="default"});isoGroup.addChild(a);var b=game.make.isoSprite(1115,587,10,"sheet","ui/arrow_east",isoGroup);
|
||||
b.inputEnabled=!0;b.events.onInputDown.add(function(){mar.worldX===mar.maxWidth?mar.worldX=0:mar.worldX++;mar.client.requestTerrain()});b.events.onInputOver.add(function(){b.tint=65280;document.body.style.cursor="pointer"});b.events.onInputOut.add(function(){b.tint=16777215;document.body.style.cursor="default"});isoGroup.addChild(b);var c=game.make.isoSprite(528,1170,10,"sheet","ui/arrow_south",isoGroup);c.inputEnabled=!0;c.events.onInputDown.add(function(){mar.worldY===mar.maxWidth?mar.worldY=0:
|
||||
mar.worldY++;mar.client.requestTerrain()});c.events.onInputOver.add(function(){c.tint=65280;document.body.style.cursor="pointer"});c.events.onInputOut.add(function(){c.tint=16777215;document.body.style.cursor="default"});isoGroup.addChild(c);var d=game.make.isoSprite(-60,587,10,"sheet","ui/arrow_west",isoGroup);d.inputEnabled=!0;d.events.onInputDown.add(function(){0===mar.worldX?mar.worldX=mar.maxWidth:mar.worldX--;mar.client.requestTerrain()});d.events.onInputOver.add(function(){d.tint=65280;document.body.style.cursor=
|
||||
"pointer"});d.events.onInputOut.add(function(){d.tint=16777215;document.body.style.cursor="default"});isoGroup.addChild(d)}function cubotDig(a,b,c){b===DIR_NORTH?a.animations.play("dig_n",45):b===DIR_EAST?a.animations.play("dig_e",45):b===DIR_SOUTH?a.animations.play("dig_s",45):b===DIR_WEST&&a.animations.play("dig_w",45)}
|
||||
function cubotMove(a,b,c,d,f){var e;if(b===DIR_SOUTH)var g=function(b){f?(e=game.add.tween(a).to({isoX:getIsoX(a.tileX),isoY:getIsoY(a.tileY)},b,Phaser.Easing.Linear.None,!0),game.add.tween(a).to({isoX:getIsoX(a.tileX),isoZ:90},b/2,Phaser.Easing.Quadratic.Out,!0).onComplete.add(function(){game.add.tween(a).to({isoX:getIsoX(a.tileX),isoZ:5},b/2,Phaser.Easing.Quadratic.In,!0)})):(e=game.add.tween(a).to({isoX:getIsoX(a.tileX),isoY:getIsoY(a.tileY)},b,Phaser.Easing.Linear.None,!0),a.animations.play("walk_s",
|
||||
60,!0));dispatchTileEnter(a.tileX,a.tileY);e.onComplete.add(function(){a.animations.stop();a.animations.frame=d.south;a.onTileOut();a.isoX=getIsoX(a.tileX);a.isoY=getIsoY(a.tileY);void 0!==c&&c();for(var b=0;b<a.queuedAnims.length;b++)a.queuedAnims[b](500),a.queuedAnims.splice(b,1)})};else b===DIR_NORTH?g=function(b){f?(e=game.add.tween(a).to({isoX:getIsoX(a.tileX),isoY:getIsoY(a.tileY)},b,Phaser.Easing.Linear.None,!0),game.add.tween(a).to({isoZ:90},b/2,Phaser.Easing.Quadratic.Out,!0).onComplete.add(function(){game.add.tween(a).to({isoZ:5},
|
||||
b/2,Phaser.Easing.Quadratic.In,!0)})):(e=game.add.tween(a).to({isoX:getIsoX(a.tileX),isoY:getIsoY(a.tileY)},b,Phaser.Easing.Linear.None,!0),a.animations.play("walk_n",60,!0));dispatchTileEnter(a.tileX,a.tileY);e.onComplete.add(function(){a.animations.stop();a.animations.frame=d.north;a.onTileOut();a.isoX=getIsoX(a.tileX);a.isoY=getIsoY(a.tileY);void 0!==c&&c();for(var b=0;b<a.queuedAnims.length;b++)a.queuedAnims[b](500),a.queuedAnims.splice(b,1)})}:b===DIR_WEST?g=function(b){f?(e=game.add.tween(a).to({isoX:getIsoX(a.tileX),
|
||||
isoY:getIsoY(a.tileY)},b,Phaser.Easing.Linear.None,!0),game.add.tween(a).to({isoZ:90},b/2,Phaser.Easing.Quadratic.Out,!0).onComplete.add(function(){game.add.tween(a).to({isoZ:5},b/2,Phaser.Easing.Quadratic.In,!0)})):(e=game.add.tween(a).to({isoX:getIsoX(a.tileX),isoY:getIsoY(a.tileY)},b,Phaser.Easing.Linear.None,!0),a.animations.play("walk_w",60,!0));dispatchTileEnter(a.tileX,a.tileY);e.onComplete.add(function(){a.animations.stop();a.animations.frame=d.west;a.onTileOut();a.isoX=getIsoX(a.tileX);a.isoY=
|
||||
getIsoY(a.tileY);void 0!==c&&c();for(var b=0;b<a.queuedAnims.length;b++)a.queuedAnims[b](500),a.queuedAnims.splice(b,1)})}:b===DIR_EAST&&(g=function(b){f?(e=game.add.tween(a).to({isoX:getIsoX(a.tileX),isoY:getIsoY(a.tileY)},b,Phaser.Easing.Linear.None,!0),game.add.tween(a).to({isoZ:90},b/2,Phaser.Easing.Quadratic.Out,!0).onComplete.add(function(){game.add.tween(a).to({isoZ:5},b/2,Phaser.Easing.Quadratic.In,!0)})):(e=game.add.tween(a).to({isoX:getIsoX(a.tileX),isoY:getIsoY(a.tileY)},b,Phaser.Easing.Linear.None,
|
||||
!0),a.animations.play("walk_e",60,!0));dispatchTileEnter(a.tileX,a.tileY);e.onComplete.add(function(){a.animations.stop();a.animations.frame=d.east;a.onTileOut();a.isoX=getIsoX(a.tileX);a.isoY=getIsoY(a.tileY);void 0!==c&&c();for(var b=0;b<a.queuedAnims.length;b++)a.queuedAnims[b](500),a.queuedAnims.splice(b,1)})});a.animations.currentAnim.isPlaying?(a.queuedAnims.push(g),console.log("Queued Animation")):g(800)}
|
||||
function initialiseAnimations(){mar.animationFrames.walk_e_start=[];for(var a=0;10>a;a++)mar.animationFrames.walk_e_start.push("cubot/walk_e/"+("0000"+a).slice(-4));mar.animationFrames.walk_e=[];for(a=10;30>a;a++)mar.animationFrames.walk_e.push("cubot/walk_e/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_e_start=[];for(a=0;10>a;a++)mar.animationFrames.harvester_walk_e_start.push("harvester/walk_e/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_e=[];for(a=10;30>a;a++)mar.animationFrames.harvester_walk_e.push("harvester/walk_e/"+
|
||||
("0000"+a).slice(-4));mar.animationFrames.walk_n_start=[];for(a=0;10>a;a++)mar.animationFrames.walk_n_start.push("cubot/walk_n/"+("0000"+a).slice(-4));mar.animationFrames.walk_n=[];for(a=10;30>a;a++)mar.animationFrames.walk_n.push("cubot/walk_n/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_n_start=[];for(a=0;10>a;a++)mar.animationFrames.harvester_walk_n_start.push("harvester/walk_n/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_n=[];for(a=10;30>a;a++)mar.animationFrames.harvester_walk_n.push("harvester/walk_n/"+
|
||||
("0000"+a).slice(-4));mar.animationFrames.walk_s_start=[];for(a=0;10>a;a++)mar.animationFrames.walk_s_start.push("cubot/walk_s/"+("0000"+a).slice(-4));mar.animationFrames.walk_s=[];for(a=10;30>a;a++)mar.animationFrames.walk_s.push("cubot/walk_s/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_s_start=[];for(a=0;10>a;a++)mar.animationFrames.harvester_walk_s_start.push("harvester/walk_s/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_s=[];for(a=10;30>a;a++)mar.animationFrames.harvester_walk_s.push("harvester/walk_s/"+
|
||||
("0000"+a).slice(-4));mar.animationFrames.walk_w_start=[];for(a=0;10>a;a++)mar.animationFrames.walk_w_start.push("cubot/walk_w/"+("0000"+a).slice(-4));mar.animationFrames.walk_w=[];for(a=10;30>a;a++)mar.animationFrames.walk_w.push("cubot/walk_w/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_w_start=[];for(a=0;10>a;a++)mar.animationFrames.harvester_walk_w_start.push("harvester/walk_w/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_w=[];for(a=10;30>a;a++)mar.animationFrames.harvester_walk_w.push("harvester/walk_w/"+
|
||||
("0000"+a).slice(-4));mar.animationFrames.dig_e=[];for(a=1;41>=a;a++)mar.animationFrames.dig_e.push("cubot/dig_e/"+("0000"+a).slice(-4));mar.animationFrames.dig_n=[];for(a=1;41>=a;a++)mar.animationFrames.dig_n.push("cubot/dig_n/"+("0000"+a).slice(-4));mar.animationFrames.dig_s=[];for(a=1;41>=a;a++)mar.animationFrames.dig_s.push("cubot/dig_s/"+("0000"+a).slice(-4));mar.animationFrames.dig_w=[];for(a=1;41>=a;a++)mar.animationFrames.dig_w.push("cubot/dig_w/"+("0000"+a).slice(-4));mar.animationFrames.biomassIdle=
|
||||
[];for(a=1;60>a;a++)mar.animationFrames.biomassIdle.push("objects/biomass/idle/"+("0000"+a).slice(-4))}function getIsoX(a){return 71.5*a}function getIsoY(a){return 71.5*a}function findMyRobot(){"guest"===mar.client.username?alert("You are not logged in!"):mar.client.requestUserInfo()}function formattedKeyBuffer(a){for(var b="KB: ",c=0;16>c;c++)b=void 0!==a[c]?b+(a[c].toString(16)+" "):b+"__ ";return b}game.state.add("Boot",BasicGame.Boot);game.state.start("Boot");
|
42271
mar/old/pixi.js
21
mar/old/pixi.min.js
vendored
826
mar/old/setup.js
@ -1,826 +0,0 @@
|
||||
"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");
|
||||
};
|
0
mar/phaser/p2.d.ts → mar/p2.d.ts
vendored
@ -52424,7 +52424,7 @@ THIS SOFTWARE.
|
||||
}
|
||||
}
|
||||
|
||||
if (data.lineWidth > 0) {
|
||||
if (data.width > 0) {
|
||||
webGLData = PIXI.WebGLGraphics.switchMode(webGL, 0);
|
||||
PIXI.WebGLGraphics.buildLine(data, webGLData);
|
||||
|
||||
@ -53142,7 +53142,7 @@ THIS SOFTWARE.
|
||||
var fillColor = data._fillTint;
|
||||
var lineColor = data._lineTint;
|
||||
|
||||
context.lineWidth = data.lineWidth;
|
||||
context.lineWidth = data.width;
|
||||
|
||||
if (data.type === Phaser.POLYGON) {
|
||||
context.beginPath();
|
||||
@ -53170,7 +53170,7 @@ THIS SOFTWARE.
|
||||
context.fill();
|
||||
}
|
||||
|
||||
if (data.lineWidth) {
|
||||
if (data.width) {
|
||||
context.globalAlpha = data.lineAlpha * worldAlpha;
|
||||
context.strokeStyle = '#' + ('00000' + ( lineColor | 0).toString(16)).substr(-6);
|
||||
context.stroke();
|
||||
@ -53183,7 +53183,7 @@ THIS SOFTWARE.
|
||||
context.fillRect(shape.x, shape.y, shape.width, shape.height);
|
||||
}
|
||||
|
||||
if (data.lineWidth) {
|
||||
if (data.width) {
|
||||
context.globalAlpha = data.lineAlpha * worldAlpha;
|
||||
context.strokeStyle = '#' + ('00000' + ( lineColor | 0).toString(16)).substr(-6);
|
||||
context.strokeRect(shape.x, shape.y, shape.width, shape.height);
|
||||
@ -53201,7 +53201,7 @@ THIS SOFTWARE.
|
||||
context.fill();
|
||||
}
|
||||
|
||||
if (data.lineWidth) {
|
||||
if (data.width) {
|
||||
context.globalAlpha = data.lineAlpha * worldAlpha;
|
||||
context.strokeStyle = '#' + ('00000' + ( lineColor | 0).toString(16)).substr(-6);
|
||||
context.stroke();
|
||||
@ -53240,7 +53240,7 @@ THIS SOFTWARE.
|
||||
context.fill();
|
||||
}
|
||||
|
||||
if (data.lineWidth) {
|
||||
if (data.width) {
|
||||
context.globalAlpha = data.lineAlpha * worldAlpha;
|
||||
context.strokeStyle = '#' + ('00000' + ( lineColor | 0).toString(16)).substr(-6);
|
||||
context.stroke();
|
||||
@ -53274,7 +53274,7 @@ THIS SOFTWARE.
|
||||
context.fill();
|
||||
}
|
||||
|
||||
if (data.lineWidth) {
|
||||
if (data.width) {
|
||||
context.globalAlpha = data.lineAlpha * worldAlpha;
|
||||
context.strokeStyle = '#' + ('00000' + ( lineColor | 0).toString(16)).substr(-6);
|
||||
context.stroke();
|
||||
@ -54736,7 +54736,7 @@ THIS SOFTWARE.
|
||||
for (var i = 0; i < this.graphicsData.length; i++) {
|
||||
var data = this.graphicsData[i];
|
||||
var type = data.type;
|
||||
var lineWidth = data.lineWidth;
|
||||
var lineWidth = data.width;
|
||||
shape = data.shape;
|
||||
|
||||
if (type === Phaser.RECTANGLE || type === Phaser.ROUNDEDRECTANGLE) {
|
||||
@ -81019,7 +81019,7 @@ THIS SOFTWARE.
|
||||
this.lineHeight = 16;
|
||||
|
||||
/**
|
||||
* @property {number} lineWidth - The width of the stroke on lines and shapes. A positive number.
|
||||
* @property {number} width - The width of the stroke on lines and shapes. A positive number.
|
||||
* @default
|
||||
*/
|
||||
this.lineWidth = 1;
|
2
mar/phaser/phaser.min.js → mar/phaser.min.js
vendored
@ -1,346 +0,0 @@
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
/**
|
||||
* Client-side keyboard buffer. It is overwritten by the server at the end of tick.
|
||||
*/
|
||||
var KeyboardBuffer = (function (_super) {
|
||||
__extends(KeyboardBuffer, _super);
|
||||
function KeyboardBuffer() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
/**
|
||||
* Array of key codes. Updated on keypress
|
||||
* @type {Array}
|
||||
*/
|
||||
_this.keys = [];
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
* @returns {string} Message written on the screen
|
||||
*/
|
||||
KeyboardBuffer.prototype.getMessage = function () {
|
||||
var str = "KB: ";
|
||||
for (var i = 0; i < 16; i++) {
|
||||
if (this.keys[i] !== undefined) {
|
||||
str += this.keys[i].toString(16).toUpperCase() + " ";
|
||||
}
|
||||
else {
|
||||
str += "__ ";
|
||||
}
|
||||
}
|
||||
return str;
|
||||
};
|
||||
return KeyboardBuffer;
|
||||
}(DebugMessage));
|
||||
/**
|
||||
* Listens for object list
|
||||
*/
|
||||
var ObjectsListener = (function () {
|
||||
function ObjectsListener() {
|
||||
}
|
||||
ObjectsListener.prototype.getListenedMessageType = function () {
|
||||
return "object";
|
||||
};
|
||||
ObjectsListener.prototype.handle = function (message) {
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Received " + message.objects.length + " objects");
|
||||
}
|
||||
if (mar.world != undefined) {
|
||||
mar.world.handleObjectsUpdate(message.objects);
|
||||
}
|
||||
};
|
||||
return ObjectsListener;
|
||||
}());
|
||||
var TickListener = (function () {
|
||||
function TickListener() {
|
||||
}
|
||||
TickListener.prototype.getListenedMessageType = function () {
|
||||
return "tick";
|
||||
};
|
||||
TickListener.prototype.handle = function (message) {
|
||||
mar.client.requestObjects();
|
||||
//Update key buffer display
|
||||
if (message.keys !== undefined) {
|
||||
mar.client.keyboardBuffer.keys = message.keys;
|
||||
}
|
||||
};
|
||||
return TickListener;
|
||||
}());
|
||||
var UserInfoListener = (function () {
|
||||
function UserInfoListener() {
|
||||
}
|
||||
UserInfoListener.prototype.getListenedMessageType = function () {
|
||||
return "userInfo";
|
||||
};
|
||||
UserInfoListener.prototype.handle = function (message) {
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Received user info message");
|
||||
}
|
||||
mar.client.worldX = message.worldX;
|
||||
mar.client.worldY = message.worldY;
|
||||
//Maximum Universe width
|
||||
mar.client.maxWidth = message.maxWidth;
|
||||
mar.client.requestTerrain();
|
||||
};
|
||||
return UserInfoListener;
|
||||
}());
|
||||
var AuthListener = (function () {
|
||||
function AuthListener() {
|
||||
}
|
||||
AuthListener.prototype.getListenedMessageType = function () {
|
||||
return "auth";
|
||||
};
|
||||
AuthListener.prototype.handle = function (message) {
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Received auth response");
|
||||
}
|
||||
if (message.m === "ok") {
|
||||
console.log("[MAR] Auth successful");
|
||||
mar.client.requestUserInfo();
|
||||
}
|
||||
else {
|
||||
alert("Authentication failed. Please make sure you are logged in and reload the page.");
|
||||
}
|
||||
};
|
||||
return AuthListener;
|
||||
}());
|
||||
var TerrainListener = (function () {
|
||||
function TerrainListener() {
|
||||
}
|
||||
TerrainListener.prototype.getListenedMessageType = function () {
|
||||
return "terrain";
|
||||
};
|
||||
TerrainListener.prototype.handle = function (message) {
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Received terrain");
|
||||
}
|
||||
if (mar.world) {
|
||||
mar.world.removeBigMessage();
|
||||
}
|
||||
if (message.ok) {
|
||||
var worldSize = message.size;
|
||||
if (worldSize == undefined) {
|
||||
worldSize = config.defaultWorldSize;
|
||||
}
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] World is available");
|
||||
}
|
||||
if (mar.world != null) {
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Updating World terrain");
|
||||
}
|
||||
mar.world.updateTerrain(message.terrain, worldSize);
|
||||
}
|
||||
else {
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Creating new World");
|
||||
}
|
||||
mar.world = new World(message.terrain, worldSize);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] World is not available");
|
||||
}
|
||||
if (mar.world != null) {
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Updating World terrain");
|
||||
}
|
||||
mar.world.updateTerrain([], config.defaultWorldSize);
|
||||
}
|
||||
else {
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Creating new World");
|
||||
}
|
||||
mar.world = new World([], config.defaultWorldSize);
|
||||
}
|
||||
if (mar.world) {
|
||||
mar.world.setBigMessage("[Uncharted World]");
|
||||
}
|
||||
}
|
||||
};
|
||||
return TerrainListener;
|
||||
}());
|
||||
var GameClient = (function () {
|
||||
function GameClient() {
|
||||
this.listeners = [];
|
||||
this.getServerInfo();
|
||||
}
|
||||
GameClient.prototype.requestUserInfo = function () {
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Requesting user info");
|
||||
}
|
||||
this.socket.send(JSON.stringify({ t: "userInfo" }));
|
||||
};
|
||||
GameClient.prototype.requestTerrain = function () {
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Requesting terrain for world (" + this.worldX + ", " + this.worldY + ")");
|
||||
}
|
||||
this.socket.send(JSON.stringify({ t: "terrain", x: this.worldX, y: this.worldY }));
|
||||
this.requestObjects();
|
||||
};
|
||||
GameClient.prototype.uploadCode = function (code) {
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Uploaded code");
|
||||
}
|
||||
this.socket.send(JSON.stringify({ t: "uploadCode", code: code }));
|
||||
};
|
||||
GameClient.prototype.reloadCode = function () {
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Reloading code");
|
||||
}
|
||||
this.socket.send(JSON.stringify({ t: "codeRequest" }));
|
||||
};
|
||||
GameClient.prototype.sendKeyPress = function (key) {
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Sent KeyPress: " + key);
|
||||
}
|
||||
if (key !== 0) {
|
||||
this.socket.send(JSON.stringify({ t: "k", k: key }));
|
||||
}
|
||||
};
|
||||
GameClient.prototype.requestFloppy = function () {
|
||||
//Start loading animation
|
||||
document.getElementById("floppyDown").innerHTML = "<i class=\"fa fa-cog fa-spin fa-fw\"></i>";
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Requesting floppy");
|
||||
}
|
||||
this.socket.send(JSON.stringify({ t: "floppyDown" }));
|
||||
};
|
||||
GameClient.prototype.notifyFloppyUp = function () {
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Notifying the game server of floppy upload");
|
||||
}
|
||||
this.socket.send(JSON.stringify({ t: "floppyUp" }));
|
||||
};
|
||||
GameClient.prototype.requestObjects = function () {
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Requesting game objects");
|
||||
}
|
||||
this.socket.send(JSON.stringify({ t: "object", x: this.worldX, y: this.worldY }));
|
||||
};
|
||||
/**
|
||||
* Get server info from game website
|
||||
*/
|
||||
GameClient.prototype.getServerInfo = function () {
|
||||
var self = this;
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Getting server info... ");
|
||||
}
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", "./getServerInfo.php", true);
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Received server info " + xhr.responseText);
|
||||
}
|
||||
setTimeout(self.connectToGameServer(JSON.parse(xhr.responseText)), 100);
|
||||
}
|
||||
};
|
||||
xhr.send(null);
|
||||
};
|
||||
/**
|
||||
* Connect to the game server
|
||||
* @param info JSON fetched from /getServerInfo.php
|
||||
*/
|
||||
GameClient.prototype.connectToGameServer = function (info) {
|
||||
var self = this;
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Connecting to " + info.address);
|
||||
}
|
||||
// info.address = "wss://muchassemblyrequired.com:443/socket";
|
||||
this.socket = new WebSocket(info.address);
|
||||
this.username = info.username;
|
||||
this.tickLength = info.tickLength;
|
||||
this.serverName = info.serverName;
|
||||
this.socket.binaryType = 'arraybuffer';
|
||||
this.socket.onopen = function () {
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Connected. Sent auth request");
|
||||
}
|
||||
//Send auth request
|
||||
self.socket.send(info.token);
|
||||
//todo Setup event listeners
|
||||
self.listeners.push(new UserInfoListener());
|
||||
self.listeners.push(new AuthListener());
|
||||
self.listeners.push(new TickListener());
|
||||
self.listeners.push(new TerrainListener());
|
||||
self.listeners.push(new ObjectsListener());
|
||||
self.socket.onmessage = function (received) {
|
||||
var message;
|
||||
try {
|
||||
message = JSON.parse(received.data);
|
||||
}
|
||||
catch (e) {
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] " + e);
|
||||
}
|
||||
//todo floppyListener(received);
|
||||
}
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Received: " + received.data);
|
||||
}
|
||||
for (var i = 0; i < self.listeners.length; i++) {
|
||||
if (self.listeners[i].getListenedMessageType() === message.t) {
|
||||
self.listeners[i].handle(message);
|
||||
}
|
||||
}
|
||||
};
|
||||
//Reload code
|
||||
//todo reloadCode();
|
||||
};
|
||||
this.socket.onerror = function (e) {
|
||||
alert("Can't connect to game server at address " + info.address);
|
||||
console.log(e);
|
||||
};
|
||||
this.socket.onclose = function (e) {
|
||||
mar.world.setBigMessage("Disconnected from server :(");
|
||||
console.log(e);
|
||||
};
|
||||
this.initGame();
|
||||
};
|
||||
/**
|
||||
* Called after the connection has been made to the server
|
||||
*/
|
||||
GameClient.prototype.initGame = function () {
|
||||
var self = this;
|
||||
//Setup keyboard buffer display
|
||||
//todo don't display if guest
|
||||
this.keyboardBuffer = new KeyboardBuffer(config.kbBufferX, config.kbBufferY);
|
||||
mar.addDebugMessage(this.keyboardBuffer);
|
||||
//Handle keypresses
|
||||
mar.game.input.keyboard.onDownCallback = function (event) {
|
||||
//If the game has focus
|
||||
if (document.activeElement === document.getElementById("game")) {
|
||||
if ((event.keyCode >= 37 && event.keyCode <= 40) || event.keyCode === 116 || event.keyCode === 32) {
|
||||
event.preventDefault();
|
||||
}
|
||||
if (self.username !== "guest" && self.keyboardBuffer.keys.length <= 16) {
|
||||
self.sendKeyPress(event.keyCode);
|
||||
//Locally update the buffer
|
||||
self.keyboardBuffer.keys.push(event.keyCode);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
/**
|
||||
* Requests user info, which will trigger a terrain request with the world X,Y of
|
||||
* the player's robot
|
||||
*/
|
||||
GameClient.prototype.findMyRobot = function () {
|
||||
if (this.username === "guest") {
|
||||
alert("You are not logged in!");
|
||||
}
|
||||
else {
|
||||
this.requestUserInfo();
|
||||
}
|
||||
};
|
||||
return GameClient;
|
||||
}());
|
@ -1,466 +0,0 @@
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
var ObjectType;
|
||||
(function (ObjectType) {
|
||||
ObjectType[ObjectType["CUBOT"] = 1] = "CUBOT";
|
||||
ObjectType[ObjectType["BIOMASS"] = 2] = "BIOMASS";
|
||||
ObjectType[ObjectType["HARVESTER_NPC"] = 10] = "HARVESTER_NPC";
|
||||
ObjectType[ObjectType["FACTORY"] = 3] = "FACTORY";
|
||||
ObjectType[ObjectType["RADIO_TOWER"] = 4] = "RADIO_TOWER";
|
||||
})(ObjectType || (ObjectType = {}));
|
||||
var ItemType;
|
||||
(function (ItemType) {
|
||||
ItemType[ItemType["BIOMASS"] = 1] = "BIOMASS";
|
||||
ItemType[ItemType["IRON"] = 3] = "IRON";
|
||||
ItemType[ItemType["COPPER"] = 4] = "COPPER";
|
||||
})(ItemType || (ItemType = {}));
|
||||
var Action;
|
||||
(function (Action) {
|
||||
Action[Action["IDLE"] = 0] = "IDLE";
|
||||
Action[Action["DIGGING"] = 1] = "DIGGING";
|
||||
Action[Action["WALKING"] = 2] = "WALKING";
|
||||
Action[Action["WITHDRAWING"] = 3] = "WITHDRAWING";
|
||||
Action[Action["DEPOSITING"] = 4] = "DEPOSITING";
|
||||
Action[Action["LISTENING"] = 5] = "LISTENING";
|
||||
Action[Action["JUMPING"] = 6] = "JUMPING";
|
||||
})(Action || (Action = {}));
|
||||
var GameObject = (function (_super) {
|
||||
__extends(GameObject, _super);
|
||||
function GameObject(x, y, z, key, frame) {
|
||||
return _super.call(this, mar.game, x, y, z, key, frame) || this;
|
||||
}
|
||||
/**
|
||||
* Factory method for GameObjects
|
||||
*/
|
||||
GameObject.createObject = function (json) {
|
||||
switch (json.t) {
|
||||
case ObjectType.CUBOT:
|
||||
return new Cubot(json);
|
||||
case ObjectType.BIOMASS:
|
||||
return new BiomassBlob(json);
|
||||
case ObjectType.HARVESTER_NPC:
|
||||
return new HarvesterNPC(json);
|
||||
case ObjectType.FACTORY:
|
||||
return new Factory(json);
|
||||
case ObjectType.RADIO_TOWER:
|
||||
return new RadioTower(json);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Set text that will appear on top of the object. Usually used for hover text
|
||||
*/
|
||||
GameObject.prototype.setText = function (text) {
|
||||
this.text = mar.game.make.text(0, 0, text, {
|
||||
fontSize: 22,
|
||||
fill: config.textFill,
|
||||
stroke: config.textStroke,
|
||||
strokeThickness: 2,
|
||||
font: "fixedsys"
|
||||
});
|
||||
this.text.anchor.set(0.5, 0);
|
||||
this.addChild(this.text);
|
||||
};
|
||||
/**
|
||||
* Tested to trigger onTileHover and onTileExit
|
||||
*/
|
||||
GameObject.prototype.isAt = function (x, y) {
|
||||
return x == this.tileX && y == this.tileY;
|
||||
};
|
||||
return GameObject;
|
||||
}(Phaser.Plugin.Isometric.IsoSprite));
|
||||
var HologramMode;
|
||||
(function (HologramMode) {
|
||||
HologramMode[HologramMode["CLEARED"] = 0] = "CLEARED";
|
||||
HologramMode[HologramMode["HEX"] = 1] = "HEX";
|
||||
HologramMode[HologramMode["STRING"] = 2] = "STRING";
|
||||
HologramMode[HologramMode["DEC"] = 3] = "DEC";
|
||||
})(HologramMode || (HologramMode = {}));
|
||||
var Cubot = (function (_super) {
|
||||
__extends(Cubot, _super);
|
||||
function Cubot(json) {
|
||||
var _this = _super.call(this, Util.getIsoX(json.x), Util.getIsoY(json.y), 15, "sheet", null) || this;
|
||||
/**
|
||||
* List of animation functions queued for execution.
|
||||
*/
|
||||
_this.queuedAnimations = [];
|
||||
_this.hovered = false;
|
||||
if (DEBUG) {
|
||||
console.log("Creating Cubot object");
|
||||
}
|
||||
_this.anchor.set(0.5, 0);
|
||||
_this.id = json.i;
|
||||
_this.tileX = json.x;
|
||||
_this.tileY = json.y;
|
||||
_this.username = json.parent;
|
||||
_this.heldItem = json.heldItem;
|
||||
_this.direction = json.direction;
|
||||
_this.action = json.action;
|
||||
_this.energy = json.energy;
|
||||
_this.animations.add("walk_w", mar.animationFrames.walk_w);
|
||||
_this.animations.add("walk_s", mar.animationFrames.walk_s);
|
||||
_this.animations.add("walk_e", mar.animationFrames.walk_e);
|
||||
_this.animations.add("walk_n", mar.animationFrames.walk_n);
|
||||
_this.animations.add("dig_w", mar.animationFrames.dig_w);
|
||||
_this.animations.add("dig_s", mar.animationFrames.dig_s);
|
||||
_this.animations.add("dig_e", mar.animationFrames.dig_e);
|
||||
_this.animations.add("dig_n", mar.animationFrames.dig_n);
|
||||
_this.createUsername();
|
||||
_this.updateDirection();
|
||||
_this.tint = _this.getTint();
|
||||
return _this;
|
||||
}
|
||||
Cubot.prototype.onTileHover = function () {
|
||||
mar.game.add.tween(this).to({ isoZ: 45 }, 200, Phaser.Easing.Quadratic.InOut, true);
|
||||
mar.game.add.tween(this.scale).to({ x: 1.2, y: 1.2 }, 200, Phaser.Easing.Linear.None, true);
|
||||
this.tint = config.cubotHoverTint;
|
||||
if (this.text !== undefined) {
|
||||
this.text.visible = true;
|
||||
}
|
||||
this.hovered = true;
|
||||
};
|
||||
Cubot.prototype.onTileExit = function () {
|
||||
mar.game.add.tween(this).to({ isoZ: 15 }, 400, Phaser.Easing.Bounce.Out, true);
|
||||
mar.game.add.tween(this.scale).to({ x: 1, y: 1 }, 200, Phaser.Easing.Linear.None, true);
|
||||
if (this.text !== undefined) {
|
||||
this.text.visible = false;
|
||||
}
|
||||
this.hovered = false;
|
||||
this.tint = this.getTint();
|
||||
};
|
||||
Cubot.prototype.getTint = function () {
|
||||
if (!this.hovered) {
|
||||
if (this.energy <= config.lowEnergy) {
|
||||
return config.lowEnergyTint;
|
||||
}
|
||||
else {
|
||||
return config.cubotTint;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return config.cubotHoverTint;
|
||||
}
|
||||
};
|
||||
Cubot.prototype.updateObject = function (json) {
|
||||
if (DEBUG) {
|
||||
console.log("Updating Cubot object");
|
||||
}
|
||||
this.action = json.action;
|
||||
this.energy = json.energy;
|
||||
this.direction = json.direction;
|
||||
//Update color
|
||||
this.tint = this.getTint();
|
||||
//Update Location
|
||||
if (!this.isAt(json.x, json.y)) {
|
||||
//Location changed
|
||||
if (this.action == Action.WALKING) {
|
||||
//Walking..
|
||||
this.tileX = json.x;
|
||||
this.tileY = json.y;
|
||||
this.walk();
|
||||
}
|
||||
else if (this.action == Action.JUMPING) {
|
||||
//TODO
|
||||
}
|
||||
}
|
||||
if (this.action == Action.DIGGING) {
|
||||
//TODO dig animation
|
||||
}
|
||||
this.updateDirection();
|
||||
this.updateHologram(json.holoMode, json.holoC, json.holo, json.holoStr);
|
||||
};
|
||||
Cubot.prototype.updateHologram = function (holoMode, holoColor, holoValue, holoStr) {
|
||||
//Create hologram if not exist, set style
|
||||
if (this.hologram == undefined) {
|
||||
this.hologram = mar.game.make.text(0, 32, "");
|
||||
this.hologram.anchor.set(0.5, 0);
|
||||
this.addChild(this.hologram);
|
||||
this.hologram.setStyle(config.holoStyle(holoColor));
|
||||
}
|
||||
else {
|
||||
this.hologram.setStyle(config.holoStyle(holoColor));
|
||||
}
|
||||
switch (holoMode) {
|
||||
case HologramMode.CLEARED:
|
||||
this.hologram.text = "";
|
||||
break;
|
||||
case HologramMode.DEC:
|
||||
this.hologram.text = Number(holoValue).toString();
|
||||
break;
|
||||
case HologramMode.HEX:
|
||||
this.hologram.text = "0x" + ("0000" + Number(holoValue).toString(16).toUpperCase()).slice(-4);
|
||||
break;
|
||||
case HologramMode.STRING:
|
||||
this.hologram.text = holoStr.replace(/[\n|\t]/g, '');
|
||||
break;
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Set appropriate frame based on direction
|
||||
*/
|
||||
Cubot.prototype.updateDirection = function () {
|
||||
switch (this.direction) {
|
||||
case Direction.NORTH:
|
||||
this.animations.frameName = "cubot/walk_n/0001";
|
||||
break;
|
||||
case Direction.EAST:
|
||||
this.animations.frameName = "cubot/walk_e/0001";
|
||||
break;
|
||||
case Direction.SOUTH:
|
||||
this.animations.frameName = "cubot/walk_s/0001";
|
||||
break;
|
||||
case Direction.WEST:
|
||||
this.animations.frameName = "cubot/walk_w/0001";
|
||||
break;
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Initiate the walk animation. Handles multiple calls of this function even if the previous animations
|
||||
* were not completed
|
||||
*/
|
||||
Cubot.prototype.walk = function () {
|
||||
var self = this;
|
||||
var walkAnimation = function (duration) {
|
||||
//Move the Cubot to desired tile
|
||||
var tween = mar.game.add.tween(self).to({ isoX: Util.getIsoX(self.tileX), isoY: Util.getIsoY(self.tileY) }, duration, Phaser.Easing.Linear.None, true);
|
||||
//Play appropriate animation
|
||||
switch (self.direction) {
|
||||
case Direction.NORTH:
|
||||
self.animations.play("walk_n", 60, true);
|
||||
break;
|
||||
case Direction.SOUTH:
|
||||
self.animations.play("walk_s", 60, true);
|
||||
break;
|
||||
case Direction.EAST:
|
||||
self.animations.play("walk_e", 60, true);
|
||||
break;
|
||||
case Direction.WEST:
|
||||
self.animations.play("walk_w", 60, true);
|
||||
break;
|
||||
}
|
||||
//When moved to destination,
|
||||
tween.onComplete.add(function () {
|
||||
self.animations.stop();
|
||||
self.updateDirection();
|
||||
//Resync position
|
||||
self.isoX = Util.getIsoX(self.tileX);
|
||||
self.isoY = Util.getIsoY(self.tileY);
|
||||
self.onTileExit();
|
||||
//Execute all the queued walk animations at a faster pace
|
||||
for (var i = 0; i < self.queuedAnimations.length; i++) {
|
||||
self.queuedAnimations[i](config.walkDuration / 2);
|
||||
self.queuedAnimations.splice(i, 1);
|
||||
}
|
||||
});
|
||||
};
|
||||
if (this.animations.currentAnim.isPlaying) {
|
||||
//Queue up the animation
|
||||
this.queuedAnimations.push(walkAnimation);
|
||||
}
|
||||
else {
|
||||
walkAnimation(config.walkDuration);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Create the username text that will appear on top of the Cubot. Text will have alternate
|
||||
* color when current username matches. This function is also responsable for setting the
|
||||
* reduced transparency of other Cubots
|
||||
*/
|
||||
Cubot.prototype.createUsername = function () {
|
||||
var username = mar.game.make.text(0, -24, this.username, {
|
||||
fontSize: 22,
|
||||
fill: config.textFill,
|
||||
stroke: config.textStroke,
|
||||
strokeThickness: 2,
|
||||
font: "fixedsys"
|
||||
});
|
||||
username.alpha = 0.85;
|
||||
username.anchor.set(0.5, 0);
|
||||
//Color own username
|
||||
if (this.username === mar.client.username) {
|
||||
username.tint = config.selfUsernameColor;
|
||||
}
|
||||
else {
|
||||
this.alpha = config.otherCubotAlpha;
|
||||
}
|
||||
this.addChild(username);
|
||||
};
|
||||
return Cubot;
|
||||
}(GameObject));
|
||||
var HarvesterNPC = (function (_super) {
|
||||
__extends(HarvesterNPC, _super);
|
||||
function HarvesterNPC(json) {
|
||||
var _this = _super.call(this, json) || this;
|
||||
_this.animations.add("walk_w", mar.animationFrames.harvester_walk_w);
|
||||
_this.animations.add("walk_s", mar.animationFrames.harvester_walk_s);
|
||||
_this.animations.add("walk_e", mar.animationFrames.harvester_walk_e);
|
||||
_this.animations.add("walk_n", mar.animationFrames.harvester_walk_n);
|
||||
_this.updateDirection();
|
||||
_this.setText("Harvester NPC");
|
||||
_this.text.visible = false;
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
* Needs to be overridden because Cubot() calls getTint() when initialised
|
||||
*/
|
||||
HarvesterNPC.prototype.getTint = function () {
|
||||
return config.cubotTint;
|
||||
};
|
||||
HarvesterNPC.prototype.updateDirection = function () {
|
||||
switch (this.direction) {
|
||||
case Direction.NORTH:
|
||||
this.animations.frameName = "harvester/walk_n/0001";
|
||||
break;
|
||||
case Direction.EAST:
|
||||
this.animations.frameName = "harvester/walk_e/0001";
|
||||
break;
|
||||
case Direction.SOUTH:
|
||||
this.animations.frameName = "harvester/walk_s/0001";
|
||||
break;
|
||||
case Direction.WEST:
|
||||
this.animations.frameName = "harvester/walk_w/0001";
|
||||
break;
|
||||
}
|
||||
};
|
||||
HarvesterNPC.prototype.updateObject = function (json) {
|
||||
if (DEBUG) {
|
||||
console.log("Updating Harvester NPC object");
|
||||
}
|
||||
this.action = json.action;
|
||||
this.direction = json.direction;
|
||||
//Update Location
|
||||
if (!this.isAt(json.x, json.y)) {
|
||||
//Location changed
|
||||
if (this.action == Action.WALKING) {
|
||||
//Walking..
|
||||
this.tileX = json.x;
|
||||
this.tileY = json.y;
|
||||
this.walk();
|
||||
}
|
||||
else if (this.action == Action.JUMPING) {
|
||||
//TODO
|
||||
}
|
||||
}
|
||||
//Update Direction
|
||||
this.updateDirection();
|
||||
};
|
||||
HarvesterNPC.prototype.createUsername = function () {
|
||||
//No-op
|
||||
};
|
||||
return HarvesterNPC;
|
||||
}(Cubot));
|
||||
var BiomassBlob = (function (_super) {
|
||||
__extends(BiomassBlob, _super);
|
||||
function BiomassBlob(json) {
|
||||
var _this = _super.call(this, Util.getIsoX(json.x), Util.getIsoY(json.y), 10, "sheet", 1) || this;
|
||||
if (DEBUG) {
|
||||
console.log("Creating Biomass object");
|
||||
}
|
||||
_this.anchor.set(0.5, 0);
|
||||
_this.id = json.i;
|
||||
_this.tileX = json.x;
|
||||
_this.tileY = json.y;
|
||||
_this.tint = config.biomassTint;
|
||||
_this.animations.add("idle", mar.animationFrames.biomassIdle);
|
||||
_this.animations.play("idle", 45, true);
|
||||
_this.setText("Biomass");
|
||||
_this.text.visible = false;
|
||||
return _this;
|
||||
}
|
||||
BiomassBlob.prototype.onTileHover = function () {
|
||||
mar.game.tweens.removeFrom(this);
|
||||
mar.game.add.tween(this).to({ isoZ: 45 }, 200, Phaser.Easing.Quadratic.InOut, true);
|
||||
this.tint = config.biomassHoverTint;
|
||||
mar.game.add.tween(this.scale).to({ x: 1.2, y: 1.2 }, 200, Phaser.Easing.Linear.None, true);
|
||||
this.text.visible = true;
|
||||
};
|
||||
BiomassBlob.prototype.onTileExit = function () {
|
||||
mar.game.tweens.removeFrom(this);
|
||||
mar.game.add.tween(this).to({ isoZ: 15 }, 400, Phaser.Easing.Bounce.Out, true);
|
||||
mar.game.add.tween(this.scale).to({ x: 1, y: 1 }, 200, Phaser.Easing.Linear.None, true);
|
||||
this.tint = config.biomassTint;
|
||||
this.text.visible = false;
|
||||
};
|
||||
BiomassBlob.prototype.updateObject = function (json) {
|
||||
if (DEBUG) {
|
||||
console.log("Updating Biomass object");
|
||||
}
|
||||
};
|
||||
return BiomassBlob;
|
||||
}(GameObject));
|
||||
var Factory = (function (_super) {
|
||||
__extends(Factory, _super);
|
||||
function Factory(json) {
|
||||
var _this = _super.call(this, Util.getIsoX(json.x), Util.getIsoY(json.y), 15, "sheet", "objects/factory") || this;
|
||||
_this.anchor.set(0.5, .25);
|
||||
_this.setText("Factory");
|
||||
_this.text.visible = false;
|
||||
_this.id = json.i;
|
||||
_this.tileX = json.x;
|
||||
_this.tileY = json.y;
|
||||
return _this;
|
||||
}
|
||||
Factory.prototype.onTileHover = function () {
|
||||
mar.game.tweens.removeFrom(this);
|
||||
mar.game.add.tween(this).to({ isoZ: 25 }, 200, Phaser.Easing.Quadratic.InOut, true);
|
||||
mar.game.add.tween(this.scale).to({ x: 1.06, y: 1.06 }, 200, Phaser.Easing.Linear.None, true);
|
||||
this.tint = config.cubotHoverTint;
|
||||
this.text.visible = true;
|
||||
};
|
||||
Factory.prototype.onTileExit = function () {
|
||||
mar.game.tweens.removeFrom(this);
|
||||
mar.game.add.tween(this).to({ isoZ: 15 }, 400, Phaser.Easing.Bounce.Out, true);
|
||||
mar.game.add.tween(this.scale).to({ x: 1, y: 1 }, 200, Phaser.Easing.Linear.None, true);
|
||||
this.tint = config.cubotTint;
|
||||
this.text.visible = false;
|
||||
};
|
||||
Factory.prototype.updateObject = function (json) {
|
||||
//No op
|
||||
};
|
||||
Factory.prototype.isAt = function (x, y) {
|
||||
//Factory is 2x2
|
||||
return (this.tileX === x || this.tileX + 1 === x) && (this.tileY + 1 === y || this.tileY === y);
|
||||
};
|
||||
;
|
||||
return Factory;
|
||||
}(GameObject));
|
||||
var RadioTower = (function (_super) {
|
||||
__extends(RadioTower, _super);
|
||||
function RadioTower(json) {
|
||||
var _this = _super.call(this, Util.getIsoX(json.x), Util.getIsoY(json.y), 15, "sheet", "objects/RadioTower") || this;
|
||||
_this.anchor.set(0.5, 0.64);
|
||||
_this.setText("Radio Tower");
|
||||
_this.text.visible = false;
|
||||
_this.id = json.i;
|
||||
_this.tileX = json.x;
|
||||
_this.tileY = json.y;
|
||||
return _this;
|
||||
}
|
||||
RadioTower.prototype.onTileHover = function () {
|
||||
mar.game.tweens.removeFrom(this);
|
||||
mar.game.add.tween(this).to({ isoZ: 25 }, 200, Phaser.Easing.Quadratic.InOut, true);
|
||||
mar.game.add.tween(this.scale).to({ x: 1.06, y: 1.06 }, 200, Phaser.Easing.Linear.None, true);
|
||||
this.tint = config.cubotHoverTint;
|
||||
this.text.visible = true;
|
||||
};
|
||||
RadioTower.prototype.onTileExit = function () {
|
||||
mar.game.tweens.removeFrom(this);
|
||||
mar.game.add.tween(this).to({ isoZ: 15 }, 400, Phaser.Easing.Bounce.Out, true);
|
||||
mar.game.add.tween(this.scale).to({ x: 1, y: 1 }, 200, Phaser.Easing.Linear.None, true);
|
||||
this.tint = config.cubotTint;
|
||||
this.text.visible = false;
|
||||
};
|
||||
RadioTower.prototype.updateObject = function (json) {
|
||||
//No op
|
||||
};
|
||||
return RadioTower;
|
||||
}(GameObject));
|
@ -1,257 +0,0 @@
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
var MarGame = (function () {
|
||||
function MarGame() {
|
||||
this.cursorPos = new Phaser.Plugin.Isometric.Point3();
|
||||
this.debugMessages = [];
|
||||
this.animationFrames = {};
|
||||
var self = this;
|
||||
this.game = new Phaser.Game(RENDERER_WIDTH, RENDERER_HEIGHT, Phaser.AUTO, 'game', null, true, false);
|
||||
this.bootState = {
|
||||
preload: function () {
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Loading sprites.png as JSONHash");
|
||||
}
|
||||
this.game.load.atlasJSONHash("sheet", "./mar/sprites.png", "./mar/sprites.json").onLoadComplete.add(function () {
|
||||
self.game.time.advancedTiming = true;
|
||||
//Add and enable the isometric plug-in.
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Enabling isometric plugin");
|
||||
}
|
||||
self.game.plugins.add(new Phaser.Plugin.Isometric(self.game));
|
||||
// This is used to set a game canvas-based offset for the 0, 0, 0 isometric coordinate - by default
|
||||
// this point would be at screen coordinates 0, 0 (top left) which is usually undesirable.
|
||||
self.game.iso.anchor.setTo(0.5, 0);
|
||||
//Todo: set world size based on window size?
|
||||
self.game.world.setBounds(0, 0, 2200, 1100);
|
||||
//Make camera more or less centered (tested on 1080 screen)
|
||||
self.game.camera.x = 280;
|
||||
self.game.camera.y = 90;
|
||||
self.game.scale.scaleMode = Phaser.ScaleManager.RESIZE;
|
||||
self.game.scale.pageAlignHorizontally = true;
|
||||
self.game.scale.pageAlignVertically = true;
|
||||
self.game.stage.disableVisibilityChange = true;
|
||||
self.client = new GameClient();
|
||||
//Grab focus when clicked (For chrome, Opera)
|
||||
self.game.input.onDown.add(function () {
|
||||
document.getElementById("game").focus();
|
||||
if (DEBUG) {
|
||||
console.log("Grabbed focus of #game");
|
||||
}
|
||||
});
|
||||
self.isoGroup = mar.game.add.group();
|
||||
self.textGroup = mar.game.add.group();
|
||||
self.hudGroup = mar.game.add.group();
|
||||
self.hudGroup.fixedToCamera = true;
|
||||
});
|
||||
},
|
||||
create: function () {
|
||||
console.log("[MAR] create");
|
||||
self.initialiseAnimations();
|
||||
self.initialiseStaticHud();
|
||||
},
|
||||
update: function () {
|
||||
self.game.scale.refresh();
|
||||
// Update the cursor position.
|
||||
self.game.iso.unproject(self.game.input.activePointer.position, self.cursorPos);
|
||||
// Loop through all tiles and test to see if the 3D position from above intersects with the automatically generated IsoSprite tile bounds.
|
||||
self.isoGroup.forEach(function (tile) {
|
||||
if (tile instanceof Tile) {
|
||||
var inBounds = tile.isoBounds.containsXY(self.cursorPos.x, self.cursorPos.y);
|
||||
// If it does, do a little animation and tint change.
|
||||
if (!tile.selected && inBounds) {
|
||||
tile.selected = true;
|
||||
tile.onHover();
|
||||
//Dispatch tile over
|
||||
self.isoGroup.forEach(function (obj) {
|
||||
if (obj instanceof GameObject && obj.onTileHover != undefined && obj.isAt(tile.tileX, tile.tileY)) {
|
||||
obj.onTileHover();
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
else if (tile.selected && !inBounds) {
|
||||
tile.selected = false;
|
||||
tile.onExit();
|
||||
//Dispatch tile exit
|
||||
self.isoGroup.forEach(function (obj) {
|
||||
if (obj.onTileExit != undefined && obj.isAt(tile.tileX, tile.tileY)) {
|
||||
obj.onTileExit();
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
}, 0);
|
||||
//Enable dragging the camera
|
||||
if (this.game.input.activePointer.isDown) {
|
||||
if (this.game.origDragPoint) {
|
||||
// move the camera by the amount the mouse has moved since last update
|
||||
this.game.camera.x += this.game.origDragPoint.x - this.game.input.activePointer.position.x;
|
||||
this.game.camera.y += this.game.origDragPoint.y - this.game.input.activePointer.position.y;
|
||||
}
|
||||
// set new drag origin to current position
|
||||
this.game.origDragPoint = this.game.input.activePointer.position.clone();
|
||||
}
|
||||
else {
|
||||
this.game.origDragPoint = null;
|
||||
}
|
||||
self.game.iso.topologicalSort(self.isoGroup);
|
||||
},
|
||||
render: function () {
|
||||
for (var i = 0; i < self.debugMessages.length; i++) {
|
||||
self.game.debug.text(self.debugMessages[i].getMessage(), self.debugMessages[i].x, self.debugMessages[i].y);
|
||||
}
|
||||
}
|
||||
};
|
||||
this.game.state.add('Boot', this.bootState);
|
||||
this.game.state.start('Boot');
|
||||
}
|
||||
MarGame.prototype.addDebugMessage = function (debugMsg) {
|
||||
this.debugMessages.push(debugMsg);
|
||||
};
|
||||
MarGame.prototype.initialiseAnimations = function () {
|
||||
//Walk =-------------------------------------------------------
|
||||
//East
|
||||
this.animationFrames.walk_e_start = [];
|
||||
for (var i = 0; i < 10; i++) {
|
||||
this.animationFrames.walk_e_start.push("cubot/walk_e/" + ("0000" + i).slice(-4));
|
||||
}
|
||||
this.animationFrames.walk_e = [];
|
||||
for (var i = 10; i < 30; i++) {
|
||||
this.animationFrames.walk_e.push("cubot/walk_e/" + ("0000" + i).slice(-4));
|
||||
}
|
||||
this.animationFrames.harvester_walk_e_start = [];
|
||||
for (var i = 0; i < 10; i++) {
|
||||
this.animationFrames.harvester_walk_e_start.push("harvester/walk_e/" + ("0000" + i).slice(-4));
|
||||
}
|
||||
this.animationFrames.harvester_walk_e = [];
|
||||
for (var i = 10; i < 30; i++) {
|
||||
this.animationFrames.harvester_walk_e.push("harvester/walk_e/" + ("0000" + i).slice(-4));
|
||||
}
|
||||
//North
|
||||
this.animationFrames.walk_n_start = [];
|
||||
for (var i = 0; i < 10; i++) {
|
||||
this.animationFrames.walk_n_start.push("cubot/walk_n/" + ("0000" + i).slice(-4));
|
||||
}
|
||||
this.animationFrames.walk_n = [];
|
||||
for (var i = 10; i < 30; i++) {
|
||||
this.animationFrames.walk_n.push("cubot/walk_n/" + ("0000" + i).slice(-4));
|
||||
}
|
||||
this.animationFrames.harvester_walk_n_start = [];
|
||||
for (var i = 0; i < 10; i++) {
|
||||
this.animationFrames.harvester_walk_n_start.push("harvester/walk_n/" + ("0000" + i).slice(-4));
|
||||
}
|
||||
this.animationFrames.harvester_walk_n = [];
|
||||
for (var i = 10; i < 30; i++) {
|
||||
this.animationFrames.harvester_walk_n.push("harvester/walk_n/" + ("0000" + i).slice(-4));
|
||||
}
|
||||
//South
|
||||
this.animationFrames.walk_s_start = [];
|
||||
for (var i = 0; i < 10; i++) {
|
||||
this.animationFrames.walk_s_start.push("cubot/walk_s/" + ("0000" + i).slice(-4));
|
||||
}
|
||||
this.animationFrames.walk_s = [];
|
||||
for (var i = 10; i < 30; i++) {
|
||||
this.animationFrames.walk_s.push("cubot/walk_s/" + ("0000" + i).slice(-4));
|
||||
}
|
||||
this.animationFrames.harvester_walk_s_start = [];
|
||||
for (var i = 0; i < 10; i++) {
|
||||
this.animationFrames.harvester_walk_s_start.push("harvester/walk_s/" + ("0000" + i).slice(-4));
|
||||
}
|
||||
this.animationFrames.harvester_walk_s = [];
|
||||
for (var i = 10; i < 30; i++) {
|
||||
this.animationFrames.harvester_walk_s.push("harvester/walk_s/" + ("0000" + i).slice(-4));
|
||||
}
|
||||
//West
|
||||
this.animationFrames.walk_w_start = [];
|
||||
for (var i = 0; i < 10; i++) {
|
||||
this.animationFrames.walk_w_start.push("cubot/walk_w/" + ("0000" + i).slice(-4));
|
||||
}
|
||||
this.animationFrames.walk_w = [];
|
||||
for (var i = 10; i < 30; i++) {
|
||||
this.animationFrames.walk_w.push("cubot/walk_w/" + ("0000" + i).slice(-4));
|
||||
}
|
||||
this.animationFrames.harvester_walk_w_start = [];
|
||||
for (var i = 0; i < 10; i++) {
|
||||
this.animationFrames.harvester_walk_w_start.push("harvester/walk_w/" + ("0000" + i).slice(-4));
|
||||
}
|
||||
this.animationFrames.harvester_walk_w = [];
|
||||
for (var i = 10; i < 30; i++) {
|
||||
this.animationFrames.harvester_walk_w.push("harvester/walk_w/" + ("0000" + i).slice(-4));
|
||||
}
|
||||
//Dig =-------------------------------------------------------
|
||||
this.animationFrames.dig_e = [];
|
||||
for (var i = 1; i <= 41; i++) {
|
||||
this.animationFrames.dig_e.push("cubot/dig_e/" + ("0000" + i).slice(-4));
|
||||
}
|
||||
this.animationFrames.dig_n = [];
|
||||
for (var i = 1; i <= 41; i++) {
|
||||
this.animationFrames.dig_n.push("cubot/dig_n/" + ("0000" + i).slice(-4));
|
||||
}
|
||||
this.animationFrames.dig_s = [];
|
||||
for (var i = 1; i <= 41; i++) {
|
||||
this.animationFrames.dig_s.push("cubot/dig_s/" + ("0000" + i).slice(-4));
|
||||
}
|
||||
this.animationFrames.dig_w = [];
|
||||
for (var i = 1; i <= 41; i++) {
|
||||
this.animationFrames.dig_w.push("cubot/dig_w/" + ("0000" + i).slice(-4));
|
||||
}
|
||||
//Biomass =-------------------------------------------------------
|
||||
this.animationFrames.biomassIdle = [];
|
||||
for (var i = 1; i < 60; i++) {
|
||||
this.animationFrames.biomassIdle.push("objects/biomass/idle/" + ("0000" + i).slice(-4));
|
||||
}
|
||||
};
|
||||
MarGame.prototype.initialiseStaticHud = function () {
|
||||
this.game.add.sprite(0, this.game.camera.height - 150, "sheet", "ui/compass", this.hudGroup);
|
||||
this.addDebugMessage(new WorldIndicator(10, 20));
|
||||
this.tileIndicator = new TileIndicator(10, 40);
|
||||
this.addDebugMessage(this.tileIndicator);
|
||||
};
|
||||
return MarGame;
|
||||
}());
|
||||
var DebugMessage = (function () {
|
||||
function DebugMessage(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
return DebugMessage;
|
||||
}());
|
||||
var TileIndicator = (function (_super) {
|
||||
__extends(TileIndicator, _super);
|
||||
function TileIndicator() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
TileIndicator.prototype.getMessage = function () {
|
||||
if (this.tileType != undefined) {
|
||||
return this.tileX + ", " + this.tileY + " : " + this.tileType;
|
||||
}
|
||||
else {
|
||||
return "";
|
||||
}
|
||||
};
|
||||
return TileIndicator;
|
||||
}(DebugMessage));
|
||||
var WorldIndicator = (function (_super) {
|
||||
__extends(WorldIndicator, _super);
|
||||
function WorldIndicator() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
WorldIndicator.prototype.getMessage = function () {
|
||||
if (mar.world != undefined) {
|
||||
return "World: (" + Number(mar.client.worldX).toString(16).toUpperCase() + ", " +
|
||||
Number(mar.client.worldY).toString(16).toUpperCase() + ")";
|
||||
}
|
||||
else {
|
||||
return "Loading...";
|
||||
}
|
||||
};
|
||||
return WorldIndicator;
|
||||
}(DebugMessage));
|
@ -1,292 +0,0 @@
|
||||
///<reference path="GameClient.ts"/>
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
var instances = PIXI.instances;
|
||||
var Direction;
|
||||
(function (Direction) {
|
||||
Direction[Direction["NORTH"] = 0] = "NORTH";
|
||||
Direction[Direction["EAST"] = 1] = "EAST";
|
||||
Direction[Direction["SOUTH"] = 2] = "SOUTH";
|
||||
Direction[Direction["WEST"] = 3] = "WEST";
|
||||
})(Direction || (Direction = {}));
|
||||
var Tile = (function (_super) {
|
||||
__extends(Tile, _super);
|
||||
function Tile(x, y, sprite, anchorY) {
|
||||
var _this = _super.call(this, mar.game, Util.getIsoX(x), Util.getIsoY(y), 0, 'sheet', sprite) || this;
|
||||
_this.baseZ = 0; //Base height of the tile
|
||||
_this.tileX = x;
|
||||
_this.tileY = y;
|
||||
_this.anchor.set(0.5, anchorY);
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
* Factory method to create a Tile
|
||||
*/
|
||||
Tile.createTile = function (type, x, y) {
|
||||
switch (type) {
|
||||
case TileType.WALL:
|
||||
return new WallTile(x, y);
|
||||
case TileType.IRON:
|
||||
return new IronTile(x, y);
|
||||
case TileType.COPPER:
|
||||
return new CopperTile(x, y);
|
||||
case TileType.PLAIN:
|
||||
default:
|
||||
return new PlainTile(x, y);
|
||||
}
|
||||
};
|
||||
Tile.prototype.onHover = function () {
|
||||
this.tint = config.tileHoverTint;
|
||||
mar.game.add.tween(this).to({ isoZ: this.baseZ + 8 }, 200, Phaser.Easing.Quadratic.InOut, true);
|
||||
mar.tileIndicator.tileX = this.tileX;
|
||||
mar.tileIndicator.tileY = this.tileY;
|
||||
mar.tileIndicator.tileType = this.tileType;
|
||||
};
|
||||
Tile.prototype.onExit = function () {
|
||||
this.tint = this.baseTint;
|
||||
mar.game.add.tween(this).to({ isoZ: this.baseZ }, 200, Phaser.Easing.Quadratic.InOut, true);
|
||||
};
|
||||
Tile.prototype.setText = function (text, fillColor) {
|
||||
//Remove previous text
|
||||
if (this.textSprite !== undefined) {
|
||||
this.textSprite.destroy();
|
||||
}
|
||||
this.textSprite = mar.game.make.text(0, 16, text, {
|
||||
fontSize: 22,
|
||||
fill: fillColor,
|
||||
stroke: "#FFFFFF",
|
||||
strokeThickness: 1,
|
||||
font: "fixedsys"
|
||||
});
|
||||
this.textSprite.alpha = 0.6;
|
||||
this.textSprite.anchor.set(0.5, 0);
|
||||
this.addChild(this.textSprite);
|
||||
};
|
||||
return Tile;
|
||||
}(Phaser.Plugin.Isometric.IsoSprite));
|
||||
var PlainTile = (function (_super) {
|
||||
__extends(PlainTile, _super);
|
||||
function PlainTile(x, y) {
|
||||
var _this = _super.call(this, x, y, config.plainSprite, 0) || this;
|
||||
_this.baseTint = config.tileTint;
|
||||
_this.tint = _this.baseTint;
|
||||
_this.tileType = "plain";
|
||||
return _this;
|
||||
}
|
||||
return PlainTile;
|
||||
}(Tile));
|
||||
var WallTile = (function (_super) {
|
||||
__extends(WallTile, _super);
|
||||
function WallTile(x, y) {
|
||||
var _this = _super.call(this, x, y, config.wallSprite, 0.2) || this;
|
||||
_this.baseTint = config.wallTint;
|
||||
_this.tint = _this.baseTint;
|
||||
_this.tileType = "wall";
|
||||
return _this;
|
||||
}
|
||||
return WallTile;
|
||||
}(Tile));
|
||||
var IronTile = (function (_super) {
|
||||
__extends(IronTile, _super);
|
||||
function IronTile(x, y) {
|
||||
var _this = _super.call(this, x, y, config.plainSprite, 0) || this;
|
||||
_this.baseTint = config.oreTint;
|
||||
_this.tint = _this.baseTint;
|
||||
_this.setText("Iron", config.textIron);
|
||||
_this.tileType = "iron";
|
||||
return _this;
|
||||
}
|
||||
return IronTile;
|
||||
}(Tile));
|
||||
var CopperTile = (function (_super) {
|
||||
__extends(CopperTile, _super);
|
||||
function CopperTile(x, y) {
|
||||
var _this = _super.call(this, x, y, config.plainSprite, 0) || this;
|
||||
_this.baseTint = config.oreTint;
|
||||
_this.tint = _this.baseTint;
|
||||
_this.setText("Copper", config.textCopper);
|
||||
_this.tileType = "copper";
|
||||
return _this;
|
||||
}
|
||||
return CopperTile;
|
||||
}(Tile));
|
||||
var World = (function () {
|
||||
function World(terrain, size) {
|
||||
this.tiles = [];
|
||||
this.objects = [];
|
||||
//Setup World Arrows
|
||||
this.northArrow = new WorldArrow(528, -10, "ui/arrow_north", Direction.NORTH);
|
||||
mar.isoGroup.add(this.northArrow);
|
||||
this.eastArrow = new WorldArrow(1115, 587, "ui/arrow_east", Direction.EAST);
|
||||
mar.isoGroup.add(this.eastArrow);
|
||||
this.southArrow = new WorldArrow(0, 0, "ui/arrow_south", Direction.SOUTH);
|
||||
mar.isoGroup.add(this.southArrow);
|
||||
this.westArrow = new WorldArrow(-60, 587, "ui/arrow_west", Direction.WEST);
|
||||
mar.isoGroup.add(this.westArrow);
|
||||
//Create tilemap
|
||||
this.setTerrain(terrain, size);
|
||||
}
|
||||
/**
|
||||
* Load terrain data from array and create Tiles
|
||||
* @param terrain
|
||||
* @param size Size of a side of the World
|
||||
*/
|
||||
World.prototype.setTerrain = function (terrain, size) {
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Creating tilemap of size " + size);
|
||||
}
|
||||
for (var x = 0; x < size; x++) {
|
||||
for (var y = 0; y < size; y++) {
|
||||
var tile = Tile.createTile(terrain[y * size + x], x, y);
|
||||
this.tiles.push(tile);
|
||||
mar.isoGroup.add(tile);
|
||||
}
|
||||
}
|
||||
//Update World arrows location
|
||||
this.eastArrow.isoY = 32 * (size + 2);
|
||||
this.eastArrow.isoX = 72.5 * (size) - 20;
|
||||
this.southArrow.isoX = 32 * (size + 1);
|
||||
this.southArrow.isoY = 72.5 * (size) + 20;
|
||||
//Update Phaser World size
|
||||
mar.game.world.width = (size + 2) * 128;
|
||||
mar.game.world.height = (size + 2) * 64;
|
||||
};
|
||||
World.prototype.setBigMessage = function (msg) {
|
||||
this.bigMessage = mar.game.add.text(908, 450, msg, {
|
||||
fontSize: 46,
|
||||
fill: config.bigMessageFill,
|
||||
stroke: config.textStroke,
|
||||
strokeThickness: 2,
|
||||
font: "fixedsys"
|
||||
}, mar.textGroup);
|
||||
};
|
||||
World.prototype.removeBigMessage = function () {
|
||||
if (this.bigMessage != undefined) {
|
||||
this.bigMessage.destroy();
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Destroyed big message");
|
||||
}
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Get object by id
|
||||
*/
|
||||
World.prototype.getObject = function (id) {
|
||||
for (var i = 0; i < this.objects.length; i++) {
|
||||
if (this.objects[i].id === id) {
|
||||
return this.objects[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
/**
|
||||
* Update, create or delete the current objects based on a list received from the server
|
||||
* @param objects json list of objects
|
||||
*/
|
||||
World.prototype.handleObjectsUpdate = function (objects) {
|
||||
//Mark objects as not updated
|
||||
for (var i = 0; i < this.objects.length; i++) {
|
||||
this.objects[i].updated = false;
|
||||
}
|
||||
for (var i = 0; i < objects.length; i++) {
|
||||
//Update/Create the object
|
||||
var existingObject = this.getObject(objects[i].i);
|
||||
if (existingObject !== null) {
|
||||
//Object already exists
|
||||
existingObject.updated = true;
|
||||
existingObject.updateObject(objects[i]);
|
||||
}
|
||||
else {
|
||||
//Object is new
|
||||
var newObj = GameObject.createObject(objects[i]);
|
||||
if (newObj != null) {
|
||||
newObj.updated = true;
|
||||
this.objects.push(newObj);
|
||||
mar.isoGroup.add(newObj);
|
||||
}
|
||||
else {
|
||||
if (DEBUG) {
|
||||
console.log("Couldn't create object with objType " + objects[i].t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//Delete not updated objects (see above comments)
|
||||
for (var i = 0; i < this.objects.length; i++) {
|
||||
if (!this.objects[i].updated) {
|
||||
//Check if the object we are removing is our controlledUnit, if so, follow it
|
||||
if (mar.client.username !== "guest") {
|
||||
if (this.objects[i] instanceof Cubot && this.objects[i].username === mar.client.username) {
|
||||
mar.client.findMyRobot();
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Following Cubot " + mar.client.username);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.objects[i].destroy();
|
||||
this.objects.splice(i, 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Delete current ojects and tiles and replace them with provided terrain
|
||||
* @param terrain
|
||||
* @param size
|
||||
*/
|
||||
World.prototype.updateTerrain = function (terrain, size) {
|
||||
for (var i = 0; i < this.objects.length; i++) {
|
||||
this.objects[i].destroy();
|
||||
}
|
||||
for (var i = 0; i < this.tiles.length; i++) {
|
||||
this.tiles[i].destroy();
|
||||
}
|
||||
this.objects = [];
|
||||
this.tiles = [];
|
||||
this.setTerrain(terrain, size);
|
||||
mar.game.iso.topologicalSort(mar.isoGroup);
|
||||
};
|
||||
return World;
|
||||
}());
|
||||
/**
|
||||
* Represents a 'button' sprite that changes world in a direction
|
||||
*/
|
||||
var WorldArrow = (function (_super) {
|
||||
__extends(WorldArrow, _super);
|
||||
function WorldArrow(x, y, frame, direction) {
|
||||
var _this = _super.call(this, mar.game, x, y, 10, "sheet", frame) || this;
|
||||
var self = _this;
|
||||
_this.hoverText = mar.game.make.text(10, 10, Direction[direction], config.arrowTextStyle);
|
||||
_this.addChild(_this.hoverText);
|
||||
_this.hoverText.visible = false;
|
||||
_this.hoverText.anchor.set(0, 0);
|
||||
_this.inputEnabled = true;
|
||||
_this.events.onInputDown.add(function () {
|
||||
var newX = mar.client.worldX + Util.getDeltaX(direction);
|
||||
var newY = mar.client.worldY + Util.getDeltaY(direction);
|
||||
//Wrapping coordinates around cyclically
|
||||
mar.client.worldX = newX % mar.client.maxWidth;
|
||||
mar.client.worldY = newY % mar.client.maxWidth;
|
||||
mar.client.requestTerrain();
|
||||
});
|
||||
_this.events.onInputOver.add(function () {
|
||||
self.tint = config.arrowHoverTint;
|
||||
self.hoverText.visible = true;
|
||||
document.body.style.cursor = "pointer";
|
||||
});
|
||||
_this.events.onInputOut.add(function () {
|
||||
self.tint = config.arrowTint;
|
||||
self.hoverText.visible = false;
|
||||
document.body.style.cursor = "default";
|
||||
});
|
||||
return _this;
|
||||
}
|
||||
return WorldArrow;
|
||||
}(Phaser.Plugin.Isometric.IsoSprite));
|
@ -1,97 +0,0 @@
|
||||
///<reference path="phaser.plugin.isometric.d.ts"/>
|
||||
///<reference path="phaser.d.ts"/>
|
||||
// Typescript V2.4.1
|
||||
var RENDERER_WIDTH = document.getElementById("game").clientWidth * window.devicePixelRatio;
|
||||
var RENDERER_HEIGHT = (window.innerHeight / 1.40) * window.devicePixelRatio;
|
||||
var DEBUG = true;
|
||||
var config = {
|
||||
tileTint: 0xFFFFFF,
|
||||
wallTint: 0xDDDDDD,
|
||||
oreTint: 0xF3F3F3,
|
||||
worldSize: 16,
|
||||
cubotHoverTint: 0x00FF00,
|
||||
cubotTint: 0xFFFFFF,
|
||||
textFill: "#FFFFFF",
|
||||
textStroke: "#9298a8",
|
||||
biomassTint: 0x63B85F,
|
||||
biomassHoverTint: 0x00FF00,
|
||||
tileHoverTint: 0x00FF00,
|
||||
itemIron: 0x434341,
|
||||
textIron: "#434341",
|
||||
itemCopper: 0xC87D38,
|
||||
textCopper: "#C87D38",
|
||||
hologramFill: "#0aced6",
|
||||
hologramStroke: "#12FFB0",
|
||||
copperFill: "#C87D38",
|
||||
plainSprite: "tiles/tile",
|
||||
wallSprite: "tiles/bigTile",
|
||||
walkDuration: 800,
|
||||
holoStyle: function (fill) {
|
||||
return {
|
||||
fontSize: 32,
|
||||
fill: fill ? fill : config.hologramFill,
|
||||
stroke: config.hologramStroke,
|
||||
strokeThickness: 1,
|
||||
font: "fixedsys"
|
||||
};
|
||||
},
|
||||
kbBufferX: 225,
|
||||
kbBufferY: 20,
|
||||
arrowTextStyle: {
|
||||
fontSize: 32,
|
||||
fill: "#ffffff",
|
||||
stroke: "#9298a8",
|
||||
strokeThickness: 1,
|
||||
font: "fixedsys"
|
||||
},
|
||||
lowEnergy: 100,
|
||||
lowEnergyTint: 0xCC0000,
|
||||
bigMessageFill: "#ff803d",
|
||||
arrowTint: 0xFFFFFF,
|
||||
arrowHoverTint: 0x00FF00,
|
||||
selfUsernameColor: 0xFB4D0A,
|
||||
otherCubotAlpha: 0.6,
|
||||
defaultWorldSize: 16
|
||||
};
|
||||
var TileType;
|
||||
(function (TileType) {
|
||||
TileType[TileType["PLAIN"] = 0] = "PLAIN";
|
||||
TileType[TileType["WALL"] = 1] = "WALL";
|
||||
TileType[TileType["IRON"] = 2] = "IRON";
|
||||
TileType[TileType["COPPER"] = 3] = "COPPER";
|
||||
})(TileType || (TileType = {}));
|
||||
var Util = (function () {
|
||||
function Util() {
|
||||
}
|
||||
//todo: find a more elegant way of doing this. Maybe this is related: https://github.com/lewster32/phaser-plugin-isometric/issues/7
|
||||
Util.getIsoY = function (y) {
|
||||
return Util.getIsoX(y);
|
||||
};
|
||||
Util.getIsoX = function (x) {
|
||||
return (x * 71.5);
|
||||
};
|
||||
Util.getDeltaX = function (direction) {
|
||||
switch (direction) {
|
||||
case Direction.NORTH:
|
||||
case Direction.SOUTH:
|
||||
return 0;
|
||||
case Direction.EAST:
|
||||
return 1;
|
||||
case Direction.WEST:
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
Util.getDeltaY = function (direction) {
|
||||
switch (direction) {
|
||||
case Direction.EAST:
|
||||
case Direction.WEST:
|
||||
return 0;
|
||||
case Direction.NORTH:
|
||||
return 1;
|
||||
case Direction.SOUTH:
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
return Util;
|
||||
}());
|
||||
var mar = new MarGame();
|
4
mar/phaser/mar.min.js
vendored
@ -1,4 +0,0 @@
|
||||
var RENDERER_WIDTH=document.getElementById("game").clientWidth*window.devicePixelRatio,RENDERER_HEIGHT=window.innerHeight/1.4*window.devicePixelRatio,DEBUG=!0,config={tileTint:16777215,wallTint:14540253,oreTint:15987699,worldSize:16,cubotHoverTint:65280,cubotTint:16777215,textFill:"#FFFFFF",textStroke:"#9298a8",biomassTint:6535263,biomassHoverTint:65280,tileHoverTint:65280,itemIron:4408129,textIron:"#434341",itemCopper:13139256,textCopper:"#C87D38",hologramFill:"#0aced6",hologramStroke:"#12FFB0",
|
||||
copperFill:"#C87D38",plainSprite:"tiles/tile",wallSprite:"tiles/bigTile",walkDuration:800,holoStyle:function(a){return{fontSize:32,fill:a?a:config.hologramFill,stroke:config.hologramStroke,strokeThickness:1,font:"fixedsys"}},kbBufferX:225,kbBufferY:20,arrowTextStyle:{fontSize:32,fill:"#ffffff",stroke:"#9298a8",strokeThickness:1,font:"fixedsys"},lowEnergy:100,lowEnergyTint:13369344,bigMessageFill:"#ff803d",arrowTint:16777215,arrowHoverTint:65280,selfUsernameColor:16469258,otherCubotAlpha:.6,defaultWorldSize:16},
|
||||
TileType;(function(a){a[a.PLAIN=0]="PLAIN";a[a.WALL=1]="WALL";a[a.IRON=2]="IRON";a[a.COPPER=3]="COPPER"})(TileType||(TileType={}));
|
||||
var Util=function(){function a(){}a.getIsoY=function(b){return a.getIsoX(b)};a.getIsoX=function(a){return 71.5*a};a.getDeltaX=function(a){switch(a){case Direction.NORTH:case Direction.SOUTH:return 0;case Direction.EAST:return 1;case Direction.WEST:return-1}};a.getDeltaY=function(a){switch(a){case Direction.EAST:case Direction.WEST:return 0;case Direction.NORTH:return 1;case Direction.SOUTH:return-1}};return a}(),mar=new MarGame;
|
@ -1,14 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"sourceMap": true
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
],
|
||||
"files": [
|
||||
"phaser.d.ts",
|
||||
"phaser.plugin.isometric.d.ts"
|
||||
]
|
||||
}
|
0
mar/phaser/pixi.d.ts → mar/pixi.d.ts
vendored
@ -4279,20 +4279,20 @@
|
||||
"frame": {
|
||||
"x": 904,
|
||||
"y": 1050,
|
||||
"w": 128,
|
||||
"h": 210
|
||||
"w": 168,
|
||||
"h": 237
|
||||
},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"w": 128,
|
||||
"h": 210
|
||||
"w": 168,
|
||||
"h": 237
|
||||
},
|
||||
"sourceSize": {
|
||||
"w": 128,
|
||||
"h": 210
|
||||
"w": 168,
|
||||
"h": 237
|
||||
},
|
||||
"pivot": {
|
||||
"x": 0.5,
|
||||
@ -4302,7 +4302,7 @@
|
||||
"objects/rocket":
|
||||
{
|
||||
"frame": {
|
||||
"x": 1032,
|
||||
"x": 1072,
|
||||
"y": 1050,
|
||||
"w": 135,
|
||||
"h": 189
|
||||
@ -4316,7 +4316,7 @@
|
||||
"tiles/bigTile":
|
||||
{
|
||||
"frame": {
|
||||
"x": 1167,
|
||||
"x": 1207,
|
||||
"y": 1050,
|
||||
"w": 128,
|
||||
"h": 140
|
||||
@ -4330,7 +4330,7 @@
|
||||
"tiles/copper":
|
||||
{
|
||||
"frame": {
|
||||
"x": 1295,
|
||||
"x": 1335,
|
||||
"y": 1050,
|
||||
"w": 128,
|
||||
"h": 64
|
||||
@ -4344,7 +4344,7 @@
|
||||
"tiles/iron":
|
||||
{
|
||||
"frame": {
|
||||
"x": 1423,
|
||||
"x": 1463,
|
||||
"y": 1050,
|
||||
"w": 128,
|
||||
"h": 64
|
||||
@ -4358,7 +4358,7 @@
|
||||
"tiles/plain":
|
||||
{
|
||||
"frame": {
|
||||
"x": 1551,
|
||||
"x": 1591,
|
||||
"y": 1050,
|
||||
"w": 128,
|
||||
"h": 64
|
||||
@ -4372,7 +4372,7 @@
|
||||
"tiles/plain_s":
|
||||
{
|
||||
"frame": {
|
||||
"x": 1679,
|
||||
"x": 1719,
|
||||
"y": 1050,
|
||||
"w": 128,
|
||||
"h": 64
|
||||
@ -4386,7 +4386,7 @@
|
||||
"tiles/tile":
|
||||
{
|
||||
"frame": {
|
||||
"x": 1807,
|
||||
"x": 1847,
|
||||
"y": 1050,
|
||||
"w": 128,
|
||||
"h": 114
|
||||
@ -4400,7 +4400,7 @@
|
||||
"tiles/wall":
|
||||
{
|
||||
"frame": {
|
||||
"x": 1935,
|
||||
"x": 1975,
|
||||
"y": 1050,
|
||||
"w": 128,
|
||||
"h": 103
|
||||
@ -4414,7 +4414,7 @@
|
||||
"tiles/wall_s":
|
||||
{
|
||||
"frame": {
|
||||
"x": 2063,
|
||||
"x": 2103,
|
||||
"y": 1050,
|
||||
"w": 128,
|
||||
"h": 103
|
||||
@ -4428,7 +4428,7 @@
|
||||
"ui/arrow_east":
|
||||
{
|
||||
"frame": {
|
||||
"x": 2191,
|
||||
"x": 2231,
|
||||
"y": 1050,
|
||||
"w": 102,
|
||||
"h": 51
|
||||
@ -4442,7 +4442,7 @@
|
||||
"ui/arrow_east_s":
|
||||
{
|
||||
"frame": {
|
||||
"x": 2293,
|
||||
"x": 2333,
|
||||
"y": 1050,
|
||||
"w": 102,
|
||||
"h": 51
|
||||
@ -4456,7 +4456,7 @@
|
||||
"ui/arrow_north":
|
||||
{
|
||||
"frame": {
|
||||
"x": 2395,
|
||||
"x": 2435,
|
||||
"y": 1050,
|
||||
"w": 102,
|
||||
"h": 51
|
||||
@ -4470,7 +4470,7 @@
|
||||
"ui/arrow_north_s":
|
||||
{
|
||||
"frame": {
|
||||
"x": 2497,
|
||||
"x": 2537,
|
||||
"y": 1050,
|
||||
"w": 102,
|
||||
"h": 51
|
||||
@ -4484,7 +4484,7 @@
|
||||
"ui/arrow_south":
|
||||
{
|
||||
"frame": {
|
||||
"x": 2599,
|
||||
"x": 2639,
|
||||
"y": 1050,
|
||||
"w": 102,
|
||||
"h": 51
|
||||
@ -4498,7 +4498,7 @@
|
||||
"ui/arrow_south_s":
|
||||
{
|
||||
"frame": {
|
||||
"x": 2701,
|
||||
"x": 2741,
|
||||
"y": 1050,
|
||||
"w": 102,
|
||||
"h": 51
|
||||
@ -4512,7 +4512,7 @@
|
||||
"ui/arrow_west":
|
||||
{
|
||||
"frame": {
|
||||
"x": 2803,
|
||||
"x": 2843,
|
||||
"y": 1050,
|
||||
"w": 102,
|
||||
"h": 51
|
||||
@ -4526,7 +4526,7 @@
|
||||
"ui/arrow_west_s":
|
||||
{
|
||||
"frame": {
|
||||
"x": 2905,
|
||||
"x": 2945,
|
||||
"y": 1050,
|
||||
"w": 102,
|
||||
"h": 51
|
||||
@ -4539,7 +4539,7 @@
|
||||
},
|
||||
"ui/compass": {
|
||||
"frame": {
|
||||
"x": 3007,
|
||||
"x": 3047,
|
||||
"y": 1050,
|
||||
"w": 162,
|
||||
"h": 147
|
||||
@ -4568,9 +4568,9 @@
|
||||
"format": "RGBA8888",
|
||||
"size": {
|
||||
"w": 3968,
|
||||
"h": 1260
|
||||
"h": 1287
|
||||
},
|
||||
"scale": "1",
|
||||
"smartupdate": "$TexturePacker:SmartUpdate:835d7c25db29ec00ac3f7d1149b0c1b7:cbc42bcb32195696aea0af5d3a226408:1eabdf11f75e3a4fe3147baf7b5be24b$"
|
||||
"smartupdate": "$TexturePacker:SmartUpdate:2f2171ef87c885b1443cc12a0a01c1d0:91e20f43dfff0054d5076c5515201ffc:1eabdf11f75e3a4fe3147baf7b5be24b$"
|
||||
}
|
||||
}
|
||||
|
BIN
mar/sprites.png
Before Width: | Height: | Size: 589 KiB After Width: | Height: | Size: 589 KiB |
19
mar/tsconfig.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"outFile": "./app.js"
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
],
|
||||
"files": [
|
||||
"phaser.d.ts",
|
||||
"phaser.plugin.isometric.d.ts",
|
||||
"MarGame.ts",
|
||||
"mar.ts",
|
||||
"GameClient.ts",
|
||||
"GameObject.ts",
|
||||
"World.ts",
|
||||
"Console.ts"
|
||||
]
|
||||
}
|
@ -26,7 +26,7 @@ $user = SessionManager::get();
|
||||
|
||||
@font-face {
|
||||
font-family: 'fixedsys';
|
||||
src: url("./mar/fonts/FSEX301-L2.ttf");
|
||||
src: url("assets/fonts/FSEX301-L2.ttf");
|
||||
}
|
||||
|
||||
</style>
|
||||
|