Add piece mirror; fix move hints on rotate.

This commit is contained in:
yukirij 2024-08-18 13:40:09 -07:00
parent 6b596cc766
commit c9df933bfb
2 changed files with 17 additions and 3 deletions

View File

@ -394,6 +394,9 @@ const INTERFACE = {
if(!is_hover) { draw.hints(piece); } if(!is_hover) { draw.hints(piece); }
// Draw piece icon // Draw piece icon
if(INTERFACE_DATA.mirror && (piece.player ^ (INTERFACE_DATA.player & 1) ^ INTERFACE_DATA.rotate) != 0) {
ctx.rotate(Math.PI);
}
if(piece.promoted) { ctx.drawImage(GAME_ASSET.Image.Promote, -icon_radius, -icon_radius, icon_radius * 2., icon_radius * 2.); } if(piece.promoted) { ctx.drawImage(GAME_ASSET.Image.Promote, -icon_radius, -icon_radius, icon_radius * 2., icon_radius * 2.); }
ctx.drawImage(GAME_ASSET.Image.Piece[piece.piece][piece.player], -icon_radius, -icon_radius, icon_radius * 2., icon_radius * 2.); ctx.drawImage(GAME_ASSET.Image.Piece[piece.piece][piece.player], -icon_radius, -icon_radius, icon_radius * 2., icon_radius * 2.);
@ -558,7 +561,7 @@ const INTERFACE = {
ctx.fillText(GAME_DATA.turn, width - gui_margin, gui_margin); ctx.fillText(GAME_DATA.turn, width - gui_margin, gui_margin);
// Game state message // Game state message
let message = null; let message = "Info";
ctx.fillStyle = INTERFACE.Color.Text; ctx.fillStyle = INTERFACE.Color.Text;
if(GAME_DATA.state.check) { if(GAME_DATA.state.check) {
@ -593,6 +596,9 @@ const INTERFACE = {
hints(piece) { hints(piece) {
let movement = piece.moves(); let movement = piece.moves();
if((INTERFACE_DATA.player & 1) ^ INTERFACE_DATA.rotate) {
movement = movement.rotate();
}
let moves = movement.direction; let moves = movement.direction;
for(let mask = BITWISE.lsb(moves); moves > 0; mask = BITWISE.lsb(moves)) { for(let mask = BITWISE.lsb(moves); moves > 0; mask = BITWISE.lsb(moves)) {
@ -703,6 +709,7 @@ const INTERFACE = {
player: player, player: player,
rotate: 0, rotate: 0,
mirror: false,
hover: null, hover: null,
select: null, select: null,
@ -805,9 +812,14 @@ const INTERFACE = {
}, },
rotate() { rotate() {
INTERFACE_DATA.rotate = +(!INTERFACE_DATA.rotate); INTERFACE_DATA.rotate ^= 1;
INTERFACE.draw(); INTERFACE.draw();
} },
mirror() {
INTERFACE_DATA.mirror = !INTERFACE_DATA.mirror;
INTERFACE.draw();
},
}; };
INTERFACE.Radius = 2.0 / Math.sqrt(3.0); INTERFACE.Radius = 2.0 / Math.sqrt(3.0);

View File

@ -506,6 +506,7 @@ const SCENES = {
UI.nav([ UI.nav([
UI.button("Rotate", () => { INTERFACE.rotate(); }), UI.button("Rotate", () => { INTERFACE.rotate(); }),
UI.button("Mirror", () => { INTERFACE.mirror(); }),
], buttons_bottom); ], buttons_bottom);
let canvas = document.createElement("canvas"); let canvas = document.createElement("canvas");
@ -546,6 +547,7 @@ const SCENES = {
UI.nav([ UI.nav([
UI.button("Rotate", () => { INTERFACE.rotate(); }), UI.button("Rotate", () => { INTERFACE.rotate(); }),
UI.button("Mirror", () => { INTERFACE.mirror(); }),
], buttons_bottom); ], buttons_bottom);
let canvas = document.createElement("canvas"); let canvas = document.createElement("canvas");