Skip to content

Instantly share code, notes, and snippets.

@mordof mordof/create land tiles.js Secret
Created Feb 21, 2016

Embed
What would you like to do?
var uvs = [];
var vertices = [];
var indices = [];
var index = 0;
var graphics = []
for(var mapY = 0; mapY < this.landTileData.length; ++mapY){
for(var mapX = 0; mapX < this.landTileData[mapY].length; ++mapX){
if( (mapY + mapX) %2 == 0){
// gr = new PIXI.Graphics()
// xy = Map.mapXYtoScreenXY(mapX, mapY)
// gr.beginFill(0x0000FF);
// gr.drawCircle(xy[0],xy[1],2)
// gr.endFill();
// this.landTiles.addChild(gr)
continue
}
// gr = new PIXI.Graphics()
// xy = Map.mapXYtoScreenXY(mapX, mapY)
// gr.beginFill(0xFF0000);
// gr.drawCircle(xy[0],xy[1],2)
// gr.endFill();
// this.landTiles.addChild(gr)
// console.log(mapX, mapY)
pointHeights = this.gatherPointHeightsFromXY(mapX, mapY)
tileForm = Map.pointHeightsToTileForm(pointHeights, this.getBaseHeightFromXY(mapX, mapY))
origGraphics = this.landTileGraphicsObjects[tileForm]
var pTop = Map.mapXYtoScreenXY(mapX + 1, mapY)
var pLeft = Map.mapXYtoScreenXY(mapX, mapY + 1)
var pBottom = Map.mapXYtoScreenXY(mapX + 1, mapY + 2)
var pRight = Map.mapXYtoScreenXY(mapX + 2, mapY + 1)
elevation = Map.tileFormToPointHeights(tileForm)
pTop[1] = pTop[1] - elevation[0] * Map.tileElevationHeight
pLeft[1] = pLeft[1] - elevation[1] * Map.tileElevationHeight
pBottom[1] = pBottom[1] - elevation[2] * Map.tileElevationHeight
pRight[1] = pRight[1] - elevation[3] * Map.tileElevationHeight
console.log(pTop,pRight,pBottom,pLeft)
var g1 = new PIXI.Graphics()
var g2 = new PIXI.Graphics()
var g3 = new PIXI.Graphics()
var g4 = new PIXI.Graphics()
g1.beginFill(0xFF0000)
g1.drawCircle(pTop[0], pTop[1], 5)
g1.endFill()
g2.beginFill(0x00FF00)
g2.drawCircle(pRight[0], pRight[1] + 4, 5)
g2.endFill()
g3.beginFill(0x0000FF)
g3.drawCircle(pBottom[0], pBottom[1] + 8, 5)
g3.endFill()
g4.beginFill(0xFFFFFF)
g4.drawCircle(pLeft[0], pLeft[1] + 16, 5)
g4.endFill()
graphics.push(g1)
graphics.push(g2)
graphics.push(g3)
graphics.push(g4)
vertices.push(pTop[0])
vertices.push(pTop[1])
vertices.push(pRight[0])
vertices.push(pRight[1])
vertices.push(pBottom[0])
vertices.push(pBottom[1])
vertices.push(pLeft[0])
vertices.push(pLeft[1])
console.log(vertices.toString())
uvs.push(0)
uvs.push(0)
uvs.push(1)
uvs.push(0)
uvs.push(1)
uvs.push(1)
uvs.push(0)
uvs.push(1)
console.log([0,0],[1,0],[1,1],[0,1])
console.log(uvs.toString())
indices.push(index++)
indices.push(index++)
indices.push(index++)
indices.push(index++)
console.log(indices.toString())
// var vertices = new Float32Array([pTop[0], pTop[1], pRight[0], pRight[1], pBottom[0], pBottom[1], pLeft[0], pLeft[1]])
// sprite = new PIXI.mesh.Mesh(this.landTileTextures[tileForm], vertices)
square = origGraphics.clone();
square.type = "map"
square.mapX = mapX
square.mapY = mapY
square.tileForm = tileForm
square.baseHeight = this.getBaseHeightFromXY(square.mapX, square.mapY)
xy = Map.mapXYtoScreenXY(mapX, mapY)
// sprite.x = xy[0]
// sprite.y = xy[1] - square.baseHeight * Map.tileElevationHeight
// square.sprite = sprite;
index_bounds = {
x: xy[0], //sprite.x,
y: xy[1] - square.baseHeight * Map.tileElevationHeight, //sprite.y,
w: square.width,
h: Map.tileSize * 2
}
square.index_bounds = index_bounds
this.tileIndexBounds.push(index_bounds)
this.index.insert(index_bounds, square)
this.landTileData[mapY][mapX][1] = square;
// this.landTiles.addChild(sprite);
}
}
this.landTiles.addChild(new PIXI.mesh.Mesh(this.landTileTextures[0], new Float32Array(vertices), new Float32Array(uvs), new Uint16Array(indices)))
for(var q=0,len=graphics.length;q<len;q++){
this.landTiles.addChild(graphics[q])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.