Skip to content

Instantly share code, notes, and snippets.

describe("Geometry", function() {
beforeEach(function() {
var $canvasContainer = $('<div><canvas width="400", height="400" style="border: 1px solid gray"></canvas></div>').appendTo('body');
jasmine.getEnv().currentSpec.canvasContainer = $canvasContainer;
jasmine.getEnv().currentSpec.renderCanvas = true;
$canvas = $canvasContainer.find('canvas');
g = Geometry;
g.ctx = $canvas[0].getContext('2d');
});
/**
* checks if 2 lines intersect TESTED
* coincidentReturn: what to return if lines are coincident (exactly overlaping)
* parallelReturn: what to return if lines are exactly parallel
*/
linesIntersect = function (a1, a2, b1, b2, coincidentReturn, parallelReturn){
var result,
coincidentReturn = coincidentReturn || false,
parallelReturn = parallelReturn || false,
/**
* all values in percentages
*/
Attack = ig.Class.extend({
/**
* unit this attack belongs to
*/
unit: null,
init: function(unit){
this.unit = unit;
ig.module(
'game.entities.container'
)
.requires(
'impact.entity',
'game.helpers.geometry'
)
.defines(function(){
EntityObstacle = ig.Entity.extend({
function pointInPolygon (point, polygon){
var i,
j,
c = 0,
pointX = point.x,
pointY = point.y;
for (i = 0, j = polygon.length - 1, len = polygon.length; i < len; j = i++){
if (((polygon[i].y > pointY) != (polygon[j].y > pointY)) && (pointX < (polygon[j].x - polygon[i].x) * (pointY - polygon[i].y) / (polygon[j].y - polygon[i].y) + polygon[i].x)){
search: function(unit, grid, start, end, heuristic) {
astar.init(grid);
heuristic = heuristic || astar.manhattan;
var openHeap = astar.heap();
start.hexes = 0;
openHeap.push(start);
while(openHeap.size() > 0) {
ig.module(
'game.entities.character'
)
.requires(
'game.entities.clickable',
'game.entities.difference',
'plugins.entityExtensions'
)
FeatureButton = ig.Entity.extend({
size: {
x: 100,
y: 50
},
r: 0,
b: 0,
init: function(x, y, settings) {
ig.module(
'plugins.gui'
)
.requires(
'impact.game',
'impact.system'
)
.defines(function () {
// Create GUI container
ig.module (
'game.entities.Player'
)
.requires(
'impact.entity',
'impact.game',
'impact.font'
)
.defines(function(){