-
Notifications
You must be signed in to change notification settings - Fork 1
/
game.js
78 lines (65 loc) · 2.81 KB
/
game.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const config = {
type: Phaser.AUTO,
width: 800,
height: 600,
parent: 'game-container',
scene: {
preload: preload,
create: create,
update: update
}
};
const game = new Phaser.Game(config);
let points; // Para almacenar los puntos dibujados
let isDrawingEnabled = false; // Estado del dibujo
let textContainer; // Contenedor para mostrar letras
let waitingForClick = true; // Variable de espera
function preload() {
// Cargar recursos como imágenes y sprites
}
function create() {
points = this.add.group(); // Crear un grupo para almacenar los puntos
textContainer = this.add.text(10, 10, '', { fill: '#ffffff' }); // Crear el contenedor de texto
// Agregar un botón para activar/desactivar el dibujo
const toggleButton = this.add.text(10, 550, 'Activar Dibujo', { fill: '#ffffff' })
.setInteractive()
.on('pointerdown', toggleDrawing.bind(this));
// Configurar la función de clic en el contenedor
this.input.on('pointerdown', handlePointerDown.bind(this));
}
function update() {
if (isDrawingEnabled) {
if (!waitingForClick) {
createPoint.call(this); // Crear un punto si el dibujo está habilitado y no se espera clic
points.children.iterate(point => {
// Aplica aquí las modificaciones o actualizaciones que necesitas en cada punto
// por ejemplo: point.x += 1; para mover el punto hacia la derecha
});
}
}
}
function toggleDrawing() {
isDrawingEnabled = !isDrawingEnabled; // Cambiar el estado del dibujo
waitingForClick = true; // Cambiar a false después del primer clic
// Cambiar el texto del botón según el estado del dibujo
this.children.list[1].setText(isDrawingEnabled ? 'Desactivar Dibujo' : 'Activar Dibujo');
}
function handlePointerDown(pointer) {
if (isDrawingEnabled && waitingForClick) {
waitingForClick = false; // Cambiar a false después del primer clic
} else if (isDrawingEnabled && !waitingForClick) {
createPoint.call(this, pointer); // Crear el círculo sin esperar después del primer clic
}
}
function createPoint(pointer) {
if (pointer) {
const x = pointer.x || 0; // Si pointer.x no está definido, usa 0 como valor predeterminado
const y = pointer.y || 0; // Si pointer.y no está definido, usa 0 como valor predeterminado
const point = this.add.graphics();
point.fillStyle(0xff0000); // Color del punto
point.fillCircle(x, y, 5); // Dibujar un punto con radio de 5 píxeles
points.add(point); // Agregar el punto al grupo
const letter = String.fromCharCode(65 + points.getLength() - 1); // Convertir número en letra (A, B, C, ...)
textContainer.text += letter + ' '; // Agregar la letra al contenedor de texto
}
}