Giving orders
How do I make an giving orders?
Experiment testing the controls for a strategy game. What is a giving orders? How do you make a giving orders? This script and codes were developed by Kevin Giguere on 30 November 2022, Wednesday.
Giving orders - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Giving orders</title> <link rel='stylesheet prefetch' href='https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css'>
<link rel='stylesheet prefetch' href='css/lrpqxy.css'> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="game"> <div class="tiles" id="TileContainer"></div> <div class="controls"> <div class="hints"> <div class="hint step1">Click on a <span class="fa fa-male"></span> to select It</div> <div class="hint step2" style="display:none">Click on a <span class="tile floor"></span> to move the selected character. <br/>Try to move him next to a <span class="fa fa-lightbulb-o"></span></div> <div class="hint step3" style="display:none">Use the following menu to turn that light on</div> <div class="hint step4" style="display:none">Good Job!</div> </div> <div class="characterInfo" style="visibility:hidden"> <div class="name">Name</div> <div class="actions"> <div class="title">Actions</div> <ul class="actions"> <li class="action model"> <a class="name">Name</a> </li> </ul> </div> </div> <div class="legend"> <h3>Legend</h3> <dl> <dt><div class="tile floor"></div></dt> <dd>Floor</dd> <dt><div class="tile wall"></dt> <dd>Wall</dd> <dt><div class="character fa fa-male"></dt> <dd>Character</dd> <dt><div class="machine fa fa-lightbulb-o"></dt> <dd>Lightbulb</dd> </dl> </div> </div>
</div>
<div class="links"> <a href="https://codepen.io/kevthunder/pen/RRpNMe" class="prev" target="_top"> <span class="collection">Game Development Experiments</span> <span class="number">pt 11</span> : <span class="title">Fog of war</span> </a> <a href="https://codepen.io/kevthunder/pen/xLxzNY" class="next" target="_top"> <span class="collection">Game Development Experiments</span> <span class="number">pt 13</span> : <span class="title">Star cluster</span> </a>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='http://npmcdn.com/[email protected]/EventEmitter.min.js'></script>
<script src='https://cdn.rawgit.com/kevthunder/parallelio/ceb0f5a7/dist/parallelio.min.js'></script>
<script src='js/lrpqxy.js'></script> <script src="js/index.js"></script>
</body>
</html>
Giving orders - Script Codes CSS Codes
body { background: #000; color: #666; font-family: Verdana, Geneva, sans-serif; text-align: center; position: relative;
}
.game { text-align: left; display: inline-block; margin-bottom: 5em;
}
.tiles { width: 350px; height: 300px; float: left; position: relative;
}
.character { z-index: 10; position: absolute; font-size: 20px; width: 20px; text-align: center;
}
.character.selected { color: #eee;
}
.machine { z-index: 10; position: absolute; font-size: 20px; width: 20px; text-align: center;
}
.lighbulb.enabled { color: #eee;
}
.tile { position: absolute; background: #333; width: 19px; height: 19px;
}
.tile.wall { background: #222;
}
.tile.floor { background: #444;
}
.controls { float: left; padding: 10px; width: 300px;
}
.controls .model { display: none;
}
.controls .characterInfo { height: 5.5em;
}
.controls .characterInfo > .name { margin: 1em 0; font-weight: bold;
}
.controls .characterInfo .actions { list-style: none; padding: 0;
}
.controls .characterInfo .action { cursor: pointer;
}
.controls .characterInfo .action a { padding: 2px 0.5em; border: 1px solid;
}
.controls .hints { height: 4em;
}
.controls .hint .fa, .controls .hint .tile { position: relative; display: inline-block;
}
.legend dl dt { margin-top: 1px; clear: both; float: left;
}
.legend dl dt .tile, .legend dl dt .character, .legend dl dt .machine { position: relative;
}
.legend dl dd { float: left; margin-left: 1em;
}
Giving orders - Script Codes JS Codes
(function() { var $, Action, ActionInstance, Character, Element, Game, LightBulb, PathAnimation, Tile, TileContainer, character1, character2, character3, game, tileSize, tiles, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; $ = jQuery; Element = this.Parallelio.Element; TileContainer = this.Parallelio.TileContainer; tileSize = 20; Tile = (function(superClass) { extend(Tile, superClass); function Tile() { return Tile.__super__.constructor.apply(this, arguments); } Tile.prototype.init = function() { Tile.__super__.init.call(this); return this.containerDisplay = $('#TileContainer'); }; Tile.properties({ container: { change: function(old) { if (old != null) { this.display.remove(); } if (this._container != null) { return this.draw(); } } } }); Tile.prototype.draw = function() { var displayPos, newDiv; newDiv = document.createElement("div"); displayPos = this.getDisplayPos(); return this.display = jQuery(newDiv).addClass('tile').addClass(this.type).appendTo(this.containerDisplay).css({ top: displayPos.y, left: displayPos.x }).click((function(_this) { return function() { return game.onClickTile(_this); }; })(this)); }; Tile.prototype.getDisplayPos = function() { return this.tileToDisplayPos(this.x, this.y); }; Tile.prototype.tileToDisplayPos = function(x, y) { return { x: x * tileSize, y: y * tileSize }; }; Tile.prototype.getAvailableActionsFor = function(requester) { return this.children.reduce(function(prev, child) { if (child.getAvailableActionsFor != null) { prev = prev.concat(child.getAvailableActionsFor(requester)); } return prev; }, []); }; return Tile; })(this.Parallelio.Tile); Character = (function(superClass) { extend(Character, superClass); Character.include(EventEmitter.prototype); function Character(name) { this.name = name; } Character.properties({ tile: { change: function(old) { if (old != null) { old.removeChild(this); } if (this.tile) { this.tile.addChild(this); this.display.appendTo(this.tile.containerDisplay); this.display.click((function(_this) { return function() { return game.onClickCharacter(_this); }; })(this)); return this.updatePos(); } } }, selected: { change: function() { return this.display.toggleClass('selected', this.selected); } }, display: { init: function() { return $(document.createElement("div")).addClass('character fa fa-male'); } }, offsetX: { "default": 0.5, change: function(old) { return this.updatePos(); } }, offsetY: { "default": 0.5, change: function(old) { return this.updatePos(); } } }); Character.prototype.updatePos = function() { var displayPos; if (this.tile != null) { displayPos = this.tile.getDisplayPos(); return this.display.css({ top: displayPos.y + (this.offsetY - 0.5) * tileSize, left: displayPos.x + (this.offsetX - 0.5) * tileSize }); } }; Character.prototype.getAvailableActions = function() { return this.getInterractableTiles().reduce((function(_this) { return function(actions, tile) { return actions = actions.concat(tile.getAvailableActionsFor(_this)); }; })(this), []); }; Character.prototype.getInterractableTiles = function() { return [this.tile, this.tile.getRelativeTile(0, 1), this.tile.getRelativeTile(0, -1), this.tile.getRelativeTile(1, 0), this.tile.getRelativeTile(-1, 0)].filter(function(t) { return t != null; }); }; Character.prototype.walkTo = function(tile) { var path; if (this.walk != null) { this.walk.stop(); } path = new Parallelio.PathFinder(this.tile.container, this.tile, tile, { validTile: function(tile) { return tile.walkable; } }); path.calcul(); this.walk = new PathAnimation(this, path); return this.walk.start(); }; return Character; })(Element); PathAnimation = (function(superClass) { extend(PathAnimation, superClass); function PathAnimation(walker, path1, speed) { this.walker = walker; this.path = path1; this.speed = speed != null ? speed : 500; this.updateCallback = (function(_this) { return function() { return _this.update(); }; })(this); } PathAnimation.prototype.start = function() { if (this.path.solution) { this.startTime = performance.now(); window.requestAnimationFrame(this.updateCallback); return this.started = true; } }; PathAnimation.prototype.stop = function() { window.cancelAnimationFrame(this.updateCallback); return this.started = false; }; PathAnimation.prototype.update = function() { var length, pos, time, timePos; if (this.started) { time = performance.now(); timePos = (time - this.startTime) / this.speed; length = this.path.solution.getTotalLength(); pos = this.path.getPosAtTime(timePos); this.walker.tile = pos.tile; this.walker.offsetX = pos.offsetX; this.walker.offsetY = pos.offsetY; if (timePos < length) { return window.requestAnimationFrame(this.updateCallback); } } }; return PathAnimation; })(Element); Action = (function() { function Action(options1, type) { this.options = options1 != null ? options1 : {}; this.type = type != null ? type : ActionInstance; } Action.prototype.getInstance = function(options) { return new this.type(this, options); }; return Action; })(); ActionInstance = (function() { function ActionInstance(action1, options1) { var key, ref, val; this.action = action1; this.options = options1 != null ? options1 : {}; ref = this.options; for (key in ref) { val = ref[key]; this[key] = val; } } ActionInstance.prototype.isAvailable = function() { return (this.action.options.available == null) || this.action.options.available.call(this); }; ActionInstance.prototype.getTitle = function() { return this.action.options.title; }; ActionInstance.prototype.addAvailableListener = function(callback) { var event, ref, results, target; if (this.action.options.availableInvaliders != null) { ref = this.action.options.availableInvaliders.call(this); results = []; for (event in ref) { target = ref[event]; results.push(target.addListener(event, callback)); } return results; } }; ActionInstance.prototype.removeAvailableListener = function(callback) { var event, ref, results, target; if (this.action.options.availableInvaliders != null) { ref = this.action.options.availableInvaliders.call(this); results = []; for (event in ref) { target = ref[event]; results.push(target.removeListener(event, callback)); } return results; } }; ActionInstance.prototype.start = function() { if (this.action.options.action != null) { return this.action.options.action.call(this); } }; return ActionInstance; })(); LightBulb = (function(superClass) { extend(LightBulb, superClass); function LightBulb() { return LightBulb.__super__.constructor.apply(this, arguments); } LightBulb.include(EventEmitter.prototype); LightBulb.properties({ tile: { change: function(old) { if (old != null) { old.removeChild(this); } if (this.tile) { this.tile.addChild(this); this.display.appendTo(this.tile.containerDisplay); return this.updatePos(); } } }, display: { init: function() { return $(document.createElement("div")).addClass('machine lighbulb fa fa-lightbulb-o'); } }, enabled: { "default": false, change: function(old) { return this.display.toggleClass('enabled', this.enabled); } } }); LightBulb.prototype.updatePos = function() { var displayPos; if (this.tile != null) { displayPos = this.tile.getDisplayPos(); return this.display.css({ top: displayPos.y, left: displayPos.x }); } }; LightBulb.prototype.actions = [ new Action({ title: 'Turn light on', available: function() { return this.target.enabled === false; }, availableInvaliders: function() { return { changedEnabled: this.target }; }, action: function() { return this.target.enabled = true; } }), new Action({ title: 'Turn light off', available: function() { return this.target.enabled === true; }, toListen: function() { return { changedEnabled: this.target }; }, action: function() { return this.target.enabled = false; } }) ]; LightBulb.prototype.getAvailableActionsFor = function(requester) { return this.actions.map((function(_this) { return function(action) { return action.getInstance({ target: _this, actor: requester }); }; })(this)); }; return LightBulb; })(Element); Game = (function(superClass) { extend(Game, superClass); function Game() { this.selectedCharacterChangedTileCallback = (function(_this) { return function(old) { _this.onSelectedCharacterChangedTile(old); return null; }; })(this); } Game.properties({ selectedCharacter: { change: function(old) { if (old != null) { old.selected = false; this.selectedCharacter.removeListener('changedTile', this.selectedCharacterChangedTileCallback); } if (this.selectedCharacter != null) { this.step = 2; this.selectedCharacter.selected = true; this.selectedCharacter.addListener('changedTile', this.selectedCharacterChangedTileCallback); $('.characterInfo > .name').text(this.selectedCharacter.name); } $('.characterInfo').css('visibility', this.selectedCharacter ? 'visible' : 'hidden'); return this.updateActions(); } }, step: { "default": 1, ingest: function(val) { return Math.max(val, this.step); }, change: function(old) { $('.hint.step' + old).hide(); return $('.hint.step' + this.step).show(); } } }); Game.prototype.onSelectedCharacterChangedTile = function(oldTile) { return this.updateActions(); }; Game.prototype.updateActions = function() { var $actionsPanel, actions, ref; if (this.actionInContext != null) { this.actionInContext.forEach((function(_this) { return function(action) { return action.removeAvailableListener(_this.callback('updateActions')); }; })(this)); } this.actionInContext = ((ref = this.selectedCharacter) != null ? ref.getAvailableActions() : void 0) || []; actions = this.actionInContext.filter((function(_this) { return function(action) { action.addAvailableListener(_this.callback('updateActions')); return action.isAvailable(); }; })(this)); $actionsPanel = $('.characterInfo > .actions'); $actionsPanel.toggle(actions.length > 0); $('.action:not(.model)', $actionsPanel).remove(); if (actions.length > 0) { this.step = 3; return actions.forEach((function(_this) { return function(action) { var $actionDisplay; $actionDisplay = $('.model', $actionsPanel).clone(); $('.name', $actionDisplay).text(action.getTitle()); return $actionDisplay.on('click', function() { _this.step = 4; return action.start(); }).removeClass('model').appendTo($('.model', $actionsPanel).parent()); }; })(this)); } }; Game.prototype.onClickCharacter = function(char) { return this.selectedCharacter = char; }; Game.prototype.onClickTile = function(tile) { if (this.selectedCharacter != null) { return this.selectedCharacter.walkTo(tile); } }; return Game; })(Element); this.game = game = new Game(); this.tiles = tiles = new TileContainer(); tiles.tap(function() { var f, w; w = function(opt) { return (new Tile(opt.x, opt.y)).tap(function() { this.type = 'wall'; return this.walkable = false; }); }; f = function(opt) { return (new Tile(opt.x, opt.y)).tap(function() { this.type = 'floor'; return this.walkable = true; }); }; return this.loadMatrix([[w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w], [w, f, f, f, f, f, f, w, f, f, f, f, f, f, f, f, w], [w, f, f, f, f, f, f, w, f, f, f, f, f, f, f, f, w], [w, f, f, f, f, f, f, w, w, w, w, w, w, f, w, w, w], [w, w, f, w, w, f, f, f, f, f, f, f, f, f, f, f, w], [w, f, f, f, w, f, f, f, f, f, f, f, f, f, f, f, w], [w, f, f, f, w, f, f, f, f, f, f, f, w, w, w, f, w], [w, f, f, f, w, f, f, w, w, f, f, f, w, f, f, f, w], [w, f, f, f, w, f, f, w, w, f, f, f, w, f, f, f, w], [w, f, f, f, w, f, f, f, f, f, f, f, w, f, f, f, w], [w, f, f, f, w, f, f, f, f, f, f, f, w, f, f, f, w], [w, f, f, f, w, f, f, f, f, f, f, f, w, w, w, f, w], [w, f, f, f, w, f, f, f, f, f, f, f, f, f, f, f, w], [w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w]]); }); character1 = new Character('Character 1'); tiles.getTile(2, 2).addChild(character1); character2 = new Character('Character 2'); tiles.getTile(10, 10).addChild(character2); character3 = new Character('Character 3'); tiles.getTile(12, 2).addChild(character3); tiles.getTile(7, 9).addChild(new LightBulb()); tiles.getTile(13, 7).addChild(new LightBulb());
}).call(this);
Developer | Kevin Giguere |
Username | kevthunder |
Uploaded | November 30, 2022 |
Rating | 3.5 |
Size | 9,531 Kb |
Views | 10,120 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Keyboard capture | 6,779 Kb |
Wiring | 14,292 Kb |
Strategy | 12,037 Kb |
Brawl | 12,068 Kb |
BaseClass | 2,816 Kb |
Path finder | 8,661 Kb |
Approach | 11,157 Kb |
Fog of war | 9,808 Kb |
Tile-Base | 3,813 Kb |
Targeting | 12,056 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Subtle site navigation with description | Necks | 3,206 Kb |
LeMandinque | Aadesida | 9,046 Kb |
Bubble animation | Ftabor | 6,565 Kb |
HEXAGON | Aurumlux | 1,684 Kb |
Shop Talk logo made in CSS | Hugo | 19,368 Kb |
03 - CSS Variables | Run-time | 2,682 Kb |
SCSS Unit Conversion | Jakob-e | 8,210 Kb |
Hover Animation from UNIQLO | Insprd | 3,772 Kb |
Getting Started | Viblast | 1,500 Kb |
Profile box | Daniesy | 2,766 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!