41 lines
892 B
JavaScript
41 lines
892 B
JavaScript
export const BarcoTipo = Object.freeze({
|
|
FRAGATA: 1,
|
|
DESTRUCTOR: 2,
|
|
ACORAZADO: 3,
|
|
PORTAAVIONES: 4,
|
|
});
|
|
|
|
class Barco {
|
|
constructor(x, y, longitud, orientacion) {
|
|
this.x = x;
|
|
this.y = y;
|
|
this.longitud = longitud;
|
|
this.orientacion = orientacion;
|
|
this.dragging = false;
|
|
this.offsetX = 0;
|
|
this.offsetY = 0;
|
|
}
|
|
iniciarArrastre(event) {
|
|
this.dragging = true;
|
|
this.offsetX = event.offsetX;
|
|
this.offsetY = event.offsetY;
|
|
}
|
|
moverBarco(event, canvas) {
|
|
if (this.dragging) {
|
|
const rect = canvas.getBoundingClientRect();
|
|
this.x = event.clientX - rect.left - this.offsetX;
|
|
this.y = event.clientY - rect.top - this.offsetY;
|
|
}
|
|
}
|
|
finalizarArrastre() {
|
|
this.dragging = false;
|
|
}
|
|
|
|
draw(ctx) {
|
|
ctx.fillStyle = "red";
|
|
ctx.fillRect(this.x * 32, this.y * 32, 32, 32 * this.longitud);
|
|
}
|
|
}
|
|
|
|
export default Barco;
|