Browse Source

movement and basic spellcasts

tags/v0.3.1
Big Bad Waffle 5 years ago
parent
commit
b6d46d5114
13 changed files with 94 additions and 17 deletions
  1. +4
    -0
      src/client/css/main.less
  2. +2
    -0
      src/client/index.html
  3. +1
    -0
      src/client/js/components/components.js
  4. +6
    -4
      src/client/js/components/pather.js
  5. +1
    -1
      src/client/js/components/spellbook.js
  6. +36
    -7
      src/client/js/components/touchMover.js
  7. +4
    -4
      src/client/js/input.js
  8. +3
    -0
      src/client/js/main.js
  9. +14
    -0
      src/client/js/misc/helpers.js
  10. +3
    -0
      src/client/js/rendering/renderer.js
  11. +1
    -1
      src/client/ui/templates/login/login.js
  12. +14
    -0
      src/client/ui/templates/spells/spells.js
  13. +5
    -0
      src/client/ui/templates/target/styles.less

+ 4
- 0
src/client/css/main.less View File

@@ -22,6 +22,10 @@ body {
right: 10px;
top: 100px;
}

.uiMenu, .uiQuests, .uiEvents, .uiTooltipInfo {
display: none;
}
}

* {


+ 2
- 0
src/client/index.html View File

@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta name="mobile-web-app-capable" content="yes">
<title>Isleward</title>
<link rel="stylesheet" href="css/loader.css">
<link rel="stylesheet" href="css/main.css">
@@ -9,6 +10,7 @@
<script src="plugins/require.min.js" data-main="js/app"></script>
<script>if (window.module) module = window.module;</script>
<link rel="icon" href="images/favicon.ico">
<link rel="manifest" href="/manifest.json">
</head>
<body>
<div class="canvas-container"></div>


+ 1
- 0
src/client/js/components/components.js View File

@@ -1,6 +1,7 @@
let components = [
'keyboardMover',
'mouseMover',
'touchMover',
'player',
'pather',
'attackAnimation',


+ 6
- 4
src/client/js/components/pather.js View File

@@ -1,9 +1,11 @@
define([
'js/rendering/renderer',
'js/system/events'
'js/system/events',
'js/system/client'
], function (
renderer,
events
events,
client
) {
let round = Math.round.bind(Math);
let maxPathLength = 50;
@@ -54,8 +56,8 @@ define([
if (this.path.length >= maxPathLength || this.obj.moveAnimation)
return;

pather.pathPos.x = x;
pather.pathPos.y = y;
this.pathPos.x = x;
this.pathPos.y = y;

this.path.push({
x: x,


+ 1
- 1
src/client/js/components/spellbook.js View File

@@ -142,7 +142,7 @@ define([
if (!spell.aura && !spell.targetGround && !spell.autoTargetFollower && !this.target)
return;

let hoverTile = this.obj.mouseMover.hoverTile;
let hoverTile = (this.obj.mouseMover || this.obj.touchMover).hoverTile;
let target = hoverTile;
if (spell.autoTargetFollower && !this.target)
target = null;


+ 36
- 7
src/client/js/components/touchMover.js View File

@@ -13,14 +13,29 @@ define([
lastNode: null,
nodes: [],

minSqrDistance: 9,
hoverTile: null,

minSqrDistance: 1200,
diagonalThreshold: 35,

init: function () {
['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'].forEach(e => this[e].bind(this));
['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'].forEach(e => {
events.on(e, this[e].bind(this));
});
},

onTouchStart: function (e) {
this.lastNode = e;

let tileX = ~~(e.worldX / scale);
let tileY = ~~(e.worldY / scale);

this.hoverTile = {
x: tileX,
y: tileY
};

events.emit('onChangeHoverTile', tileX, tileY);
},

onTouchMove: function (e) {
@@ -30,8 +45,22 @@ define([
if (sqrDistance < this.minSqrDistance)
return;

let dx = 1;
let dy = 0;
let dx = e.x - lastNode.x;
let dy = e.y - lastNode.y;

let diff = Math.abs(dx - dy);
if (diff < this.diagonalThreshold) {
dx = ~~(dx / Math.abs(dx));
dy = ~~(dy / Math.abs(dy));
} else if (Math.abs(dx) > Math.abs(dy)) {
dx = ~~(dx / Math.abs(dx));
dy = 0;
} else {
dx = 0;
dy = ~~(dy / Math.abs(dy));
}

this.lastNode = e;

let newX = this.obj.pather.pathPos.x + dx;
let newY = this.obj.pather.pathPos.y + dy;
@@ -41,10 +70,10 @@ define([
return;
}

this.obj.pather.addQueue(newX, newY);
this.obj.pather.add(newX, newY);
},

onTouchEnd: function () {
onTouchEnd: function (e) {
this.lastNode = null;
},

@@ -52,7 +81,7 @@ define([
this.lastNode = null;
},

ump: function (dx, dy) {
bump: function (dx, dy) {
if (this.obj.pather.path.length > 0)
return;



+ 4
- 4
src/client/js/input.js View File

@@ -60,9 +60,7 @@ define([
$('.ui-container')
.on('mousedown', this.events.mouse.mouseDown.bind(this))
.on('mouseup', this.events.mouse.mouseUp.bind(this))
.on('mousemove', this.events.mouse.mouseMove.bind(this));

$('.canvas-container');
.on('mousemove', this.events.mouse.mouseMove.bind(this))
.on('touchstart', this.events.touch.touchStart.bind(this))
.on('touchmove', this.events.touch.touchMove.bind(this))
.on('touchend', this.events.touch.touchEnd.bind(this))
@@ -221,7 +219,9 @@ define([
let touch = e.touches[0];
events.emit('onTouchStart', {
x: touch.clientX,
y: touch.clientY
y: touch.clientY,
worldX: touch.clientX + renderer.pos.x,
worldY: touch.clientY + renderer.pos.y
});
},



+ 3
- 0
src/client/js/main.js View File

@@ -25,6 +25,9 @@ define([
hasFocus: true,

init: function () {
if (isMobile)
$('.ui-container').addClass('mobile');

client.init(this.onClientReady.bind(this));
},



+ 14
- 0
src/client/js/misc/helpers.js View File

@@ -100,6 +100,20 @@ window._ = {
}

return result;
},

toggleFullScreen: function () {
let doc = window.document;
let docEl = doc.documentElement;

let requestFullScreen = docEl.requestFullscreen || docEl.mozRequestFullScreen || docEl.webkitRequestFullScreen || docEl.msRequestFullscreen;
let cancelFullScreen = doc.exitFullscreen || doc.mozCancelFullScreen || doc.webkitExitFullscreen || doc.msExitFullscreen;

if (!doc.fullscreenElement && !doc.mozFullScreenElement && !doc.webkitFullscreenElement && !doc.msFullscreenElement)
requestFullScreen.call(docEl);

else
cancelFullScreen.call(doc);
}
};



+ 3
- 0
src/client/js/rendering/renderer.js View File

@@ -221,6 +221,9 @@ define([
},

onResize: function () {
if (isMobile)
return;
let zoom = window.devicePixelRatio;

this.width = $('body').width() * zoom;


+ 1
- 1
src/client/ui/templates/login/login.js View File

@@ -50,7 +50,7 @@ define([
this.show();
},

onLoginClick: function () {
onLoginClick: function () {
if (this.el.hasClass('disabled'))
return;



+ 14
- 0
src/client/ui/templates/spells/spells.js View File

@@ -44,6 +44,7 @@ define([
let el = $(html)
.appendTo(this.el);
el
.on('click', this.onClickSpell.bind(this, hotkey))
.on('mouseover', this.onShowTooltip.bind(this, el, spell))
.on('mouseleave', this.onHideTooltip.bind(this, el));

@@ -66,7 +67,20 @@ define([
}
},

onClickSpell: function (hotkey, e) {
e.preventDefault();

let key = (hotkey === 'space') ? ' ' : hotkey;

window.player.spellbook.onKeyDown(key);

return false;
},

onShowTooltip: function (el, spell) {
if (isMobile)
return false;

let pos = el.offset();
pos = {
x: pos.left + 56,


+ 5
- 0
src/client/ui/templates/target/styles.less View File

@@ -124,3 +124,8 @@
}
}
}

.mobile .uiTarget {
left: 10px;
top: 100px;
}

Loading…
Cancel
Save