Skip to content
Snippets Groups Projects
Commit b6504841 authored by Tim Repke's avatar Tim Repke
Browse files
parents 4625d614 331386c6
No related branches found
No related tags found
No related merge requests found
*.idea/*
*/.idea*
*/view/signups/game1/tiles
*.swp
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
......@@ -7,18 +7,23 @@ function Char(svg, options) {
this.moveTarget = [];
this.maxSpeed = 2;
this.rect = this.svg.append("rect");
this.rect.attr("backgroundColor", "#f0f")
.attr("width", "20")
.attr("height", "20");
this.updatePosition();
var self = this;
d3.xml('chars/bernd.svg', 'image/svg+xml', function(xml) {
self.image = self.svg.append('g').attr('id', 'player');
var layers = d3.select(xml.documentElement).selectAll('g').filter(function() {
return this.getAttribute('inkscape:groupmode') == 'layer';
}).each(function() {
self.image[0][0].appendChild(this);
});
self.updatePosition();
});
}
Char.prototype.findSpawn = function() {
// [1320, svgFlipY(svg[0][0], 500)]
var spawn = this.svg.select("#player_spawn");
var b = spawn[0][0].getBBox();
return [b.x, b.y];
var bbox = spawn[0][0].getBBox();
return Vec.add(getTranslation(this.svg[0][0], spawn[0][0]), [bbox.x, bbox.y]);
}
Char.prototype.animate = function() {
}
......@@ -47,14 +52,13 @@ Char.prototype.physics = function() {
this.updatePosition();
}
Char.prototype.updatePosition = function() {
if (!this.image) return;
var self = this;
this.rect.attr("transform", function() {
this.image.attr("transform", function() {
return translate.apply(null, self.translation);
});
}
Char.prototype.setMoveTarget = function(newX, newY) {
if (!this.rect) return;
var matrix = this.svg[0][0].getScreenCTM();
var x = newX-matrix.e;
var y = newY-matrix.f;
......
......@@ -5,7 +5,7 @@ function Game(config) {
Game.instance = this;
}
Game.prototype.run = function() {
d3.xml('maps/map_castle.svg', 'image/svg+xml', function(xml) {
d3.xml('maps/'+Game.config.startMap, 'image/svg+xml', function(xml) {
var gameCanvas = document.getElementById("gameCanvas");
var gameRoot = document.getElementById("gameRoot");
gameCanvas.style.width = Game.config.size[0]+'px';
......
......@@ -18,11 +18,13 @@ PathFinder.prototype.scanWalkables = function() {
if (!self.noWalkNode && label == "NOWALK")
self.noWalkNode = this;
});
var walkTranslation = getTranslation(this.svg[0][0], this.walkNode);
d3.select(self.walkNode).selectAll('path').each(function() {
self.walkNodes.push(new Path(this.getAttribute("d")));
self.walkNodes.push(new Path(this.getAttribute("d"), walkTranslation));
});
var noWalkTranslation = getTranslation(this.svg[0][0], this.noWalkNode);
d3.select(self.noWalkNode).selectAll('path').each(function() {
self.noWalkNodes.push(new Path(this.getAttribute("d")));
self.noWalkNodes.push(new Path(this.getAttribute("d"), noWalkTranslation));
});
}
PathFinder.prototype.generateRaster = function() {
......
......@@ -7,12 +7,17 @@ function showCoords(x, y) {
function svgFlipY(svg, y) {
return svg.getBBox().height - y;
}
function getTranslation(svg, node) {
var matrix = svg.getTransformToElement(node);
return [matrix.e, matrix.f];
}
function Path(svgPathData) {
function Path(svgPathData, offset) {
this.edges = [];
var currentPosition = [0,0];
if (!offset) offset = [0,0];
var relativeCommand = true;
var currentCommand = 'm';
......@@ -32,7 +37,7 @@ function Path(svgPathData) {
if (isNumber) {
currentPosition = part.split(",");
for (var i = 0; i < currentPosition.length; ++i)
currentPosition[i] = (relativeCommand ? lastPosition[i] : 0) + Number(currentPosition[i]);
currentPosition[i] = offset[i]+(relativeCommand ? lastPosition[i] : 0) + Number(currentPosition[i]);
if (currentCommand == 'l')
this.edges.push([lastPosition, currentPosition]);
......
......@@ -22,6 +22,7 @@
g_smallValue = 0.000001; // fun with floats
var game = new Game({
startMap: 'map_landing.svg',
pathFindingGridSize: 5,
usePathFinding: true,
size: [800, 600]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment