Mine Upgrade (#15)

This commit is contained in:
gavin
2018-08-24 02:42:33 +00:00
committed by Gitea
parent 90cf1723a8
commit a2d7402cfa
5 changed files with 171 additions and 108 deletions

View File

@@ -39,7 +39,7 @@ class Demo {
this.map = {};
this.taps = [];
this.flags = {};
this.mines = {};
this.ripples = [];
this.setOriginTile();
@@ -60,10 +60,13 @@ class Demo {
drawStyle: Tessellate.DRAW_STYLES.FILL,
tileStyle: this.settings.tile,
orientation: this.settings.orientation,
red: 255,
green: 255,
blue: 0,
alpha: 1,
color: {
red: 255,
green: 255,
blue: 0,
alpha: 1,
}
});
Tessellate.utils.rangeInclusive(0, 5)
@@ -76,28 +79,29 @@ class Demo {
drawStyle: Tessellate.DRAW_STYLES.OUTLINE,
tileStyle: this.settings.tile,
orientation: this.settings.orientation,
red: 0,
green: 0,
blue: 0,
alpha: 1,
color: {
red: 0,
green: 0,
blue: 0,
alpha: 1,
},
}));
});
}
tap(tap) {
const {x, y, z} = tap.tile.getPoint();
console.log(x, y, z);
const key = `${ x },${ z != null ? z : y }`;
const pipMax = this.settings.tile === Tessellate.TILE_STYLES.HEX ? 7 : 9;
this.map[key].pips = Tessellate.utils.random(1, pipMax);
console.log(this.map[key].pips);
}
pressStart(tap) {
this.ripples.push({
timestamp: tap.event.timeStamp,
timestamp: tap.event.timeStampUTC,
cell: this.createTile({
x: tap.tile.x,
@@ -109,43 +113,47 @@ class Demo {
tileStyle: Tessellate.TILE_STYLES.CIRCLE,
orientation: Tessellate.ORIENTATION_STYLES.FLAT,
red: 255,
green: 127,
blue: 127,
alpha: 0.5,
color: {
red: 128,
green: 128,
blue: 128,
alpha: 0.5,
},
})
});
if (tap.event.mobile) {
this.toggleFlag(tap.tile)
this.togglemine(tap.tile)
}
}
press(tap) {
if (!tap.event.mobile) {
this.toggleFlag(tap.tile)
this.togglemine(tap.tile)
}
}
toggleFlag(tile) {
togglemine(tile) {
const {x, y, z} = tile.getPoint();
const key = `${ x },${ z != null ? z : y }`;
if (this.flags[key]) {
delete this.flags[key];
if (this.mines[key]) {
delete this.mines[key];
}
else {
this.flags[key] = tile;
this.mines[key] = tile;
}
}
createTile({x, y,
drawStyle, tileStyle, orientation,
scale = Tessellate.utils.random(7, 9) / 10,
red = Tessellate.utils.random(255),
green = Tessellate.utils.random(255),
blue = Tessellate.utils.random(255),
alpha = Tessellate.utils.random(25, 75) / 100,
color = {
red: Tessellate.utils.random(255),
green: Tessellate.utils.random(255),
blue: Tessellate.utils.random(255),
alpha: Tessellate.utils.random(25, 75) / 100,
}
}) {
return new Tessellate.Cell({
@@ -157,10 +165,7 @@ class Demo {
tileStyle,
orientation,
red,
green,
blue,
alpha,
color,
});
}
@@ -186,13 +191,10 @@ class Demo {
const now = Date.now();
this.ripples.forEach(({timestamp, cell}) => {
let pressFactor = (now - timestamp) / PRESS_RIPPLE;
pressFactor = pressFactor > 1 ? 1 : pressFactor;
const pressFactor = Math.min((now - timestamp) / PRESS_RIPPLE, 1);
Object.assign(cell, {
scale: pressRipple(pressFactor),
alpha: pressFade(pressFactor),
});
Object.assign(cell, {scale: pressRipple(pressFactor)});
Object.assign(cell.color, {alpha: pressFade(pressFactor)});
const pixelPoint = this.tessellate.tileToPixel(cell.x, cell.y);
Tessellate.TILES[cell.tileStyle][cell.drawStyle](context, scale, pixelPoint.getX(), pixelPoint.getY(), cell);
@@ -204,15 +206,15 @@ class Demo {
Tessellate.TILES[cell.tileStyle][cell.drawStyle](context, scale, pixelPoint.getX(), pixelPoint.getY(), cell);
});
Tessellate.funky.forEach(this.flags, cell => {
Tessellate.funky.forEach(this.mines, cell => {
const pixelPoint = this.tessellate.tileToPixel(cell.x, cell.y);
Tessellate.Shapes.flag(context, scale, pixelPoint.getX(), pixelPoint.getY());
Tessellate.Shapes.mine(context, scale, pixelPoint.getX(), pixelPoint.getY());
});
if (!this.notFirstTime) {
this.notFirstTime = true;
console.log(tilePoints);
}
// if (!this.notFirstTime) {
// this.notFirstTime = true;
// console.log(tilePoints);
// }
}
}