184 lines
6.4 KiB
Plaintext
184 lines
6.4 KiB
Plaintext
---
|
|
import Layout from "../../layouts/Layout.astro";
|
|
---
|
|
<Layout title="Guided Letter Tracing Game">
|
|
<main>
|
|
<div>
|
|
</div>
|
|
<script is:inline src="/assets/js/phaser_3.60.0.js"></script>
|
|
</main>
|
|
</Layout>
|
|
<script is:inline>
|
|
const isMobile = window.innerWidth <= 768;
|
|
const drawingZone = {
|
|
x: isMobile ? 0 : window.innerWidth / 4,
|
|
y: window.innerHeight / 4,
|
|
width: isMobile ? window.innerWidth : window.innerWidth / 2,
|
|
height: window.innerHeight / 2,
|
|
};
|
|
|
|
const config = {
|
|
type: Phaser.AUTO,
|
|
width: window.innerWidth,
|
|
height: window.innerHeight,
|
|
backgroundColor: 0xFFFFFF,
|
|
scale: {
|
|
mode: Phaser.Scale.FIT,
|
|
autoCenter: Phaser.Scale.CENTER_HORIZONTALLY,
|
|
},
|
|
scene: {
|
|
preload: preload,
|
|
create: create,
|
|
update: update
|
|
}
|
|
};
|
|
|
|
const game = new Phaser.Game(config);
|
|
const customWidth = window.innerWidth;
|
|
const customHeight = window.innerHeight;
|
|
let firstLayer, secondLayer, thirdLayer;
|
|
let graphics;
|
|
let isDrawing = false;
|
|
|
|
|
|
function preload() {
|
|
this.load.svg('letterA', '/assets/letter/a.svg');
|
|
this.load.svg('layer1', '/assets/letter/a_l1.svg');
|
|
this.load.svg('layer2', '/assets/letter/a_l2.svg');
|
|
this.load.svg('layer3', '/assets/letter/a_l3.svg');
|
|
this.load.audio('slantLeft', '/assets/audio/slant-left.mp3');
|
|
this.load.audio('slantRight', '/assets/audio/slant-right.mp3');
|
|
this.load.audio('slide', '/assets/audio/slide.mp3');
|
|
this.load.image('topLogo', '/assets/top_logo.png');
|
|
this.load.svg('succesImage', '/assets/svg/tick.svg');
|
|
}
|
|
|
|
|
|
function create() {
|
|
this.add.image(customWidth / 2 * 1.6 - 0.5, 50, 'topLogo');
|
|
this.add.text(customWidth / 10, 20, "Letter : A", { font: '700 40px quicksand', fill: '#05b3a4', });
|
|
const firstScreen = this.add.image(customWidth / 2, customHeight / 2, 'letterA');
|
|
const screenCenterX = this.cameras.main.worldView.x + this.cameras.main.width / 2;
|
|
const baseFontSize = 20;
|
|
const responsiveFontSize = (window.innerWidth / 480) * baseFontSize;
|
|
const descrptText = this.add.text(screenCenterX, 90, 'Let`s learn to write letter : A', { font: `${responsiveFontSize}px quicksand`, fill: '#7c4c23', fontWeight : 'bold'}).setOrigin(0.5);
|
|
|
|
this.time.delayedCall(2000, () => {
|
|
this.tweens.add({
|
|
targets: firstScreen,
|
|
alpha: 0,
|
|
scaleX: 0.5,
|
|
scaleY: 0.5,
|
|
duration: 1000,
|
|
onComplete: () => {
|
|
firstScreen.setVisible(false);
|
|
firstScreen.setScale(1);
|
|
showLayersWithFadeIn.call(this);
|
|
}
|
|
});
|
|
}, [], this);
|
|
}
|
|
function showLayersWithFadeIn() {
|
|
this.tweens.add({
|
|
targets: [firstLayer, secondLayer, thirdLayer],
|
|
alpha: 1,
|
|
duration: 1000, // Duration of the tween in milliseconds
|
|
delay: 500, // Delay before the fade-in starts
|
|
ease: 'Power2', // Easing function (e.g., 'Linear', 'Cubic', 'Elastic', etc.)
|
|
});
|
|
|
|
let textX, textY;
|
|
|
|
firstLayer = this.add.image(customWidth / 2, customHeight / 2, 'layer1');
|
|
textX = isMobile ? customWidth / 3 : customWidth * 0.75;
|
|
textY = isMobile ? customHeight / 5 : customHeight / 2;
|
|
const firstTextLayer = this.add.text(textX, textY, '1. Slant Left', { font: '700 40px quicksand', fill: '#05b3a4'});
|
|
const slantLeftAudio = this.sound.add('slantLeft');
|
|
slantLeftAudio.play();
|
|
firstLayer.setDepth(1);
|
|
firstLayer.setAlpha(0.5);
|
|
firstLayer.setInteractive({ draggable: true });
|
|
|
|
secondLayer = this.add.image(customWidth / 2, customHeight / 2, 'layer2');
|
|
textX = isMobile ? customWidth / 3 : customWidth * 0.75;
|
|
const secondTextLayer = this.add.text(textX, textY, '2. Slant Right', { font: '700 40px quicksand', fill: '#05b3a4'});
|
|
const slantRightAudio = this.sound.add('slantRight');
|
|
secondTextLayer.setVisible(false);
|
|
secondLayer.setDepth(1);
|
|
secondLayer.setAlpha(0.5);
|
|
secondLayer.setInteractive({ draggable: true });
|
|
secondLayer.setVisible(false);
|
|
|
|
thirdLayer = this.add.image(customWidth / 2, customHeight / 2, 'layer3');
|
|
textX = isMobile ? customWidth / 3 : customWidth * 0.75;
|
|
const thirdTextLayer = this.add.text(textX, textY, '3. Slide', { font: '700 40px quicksand', fill: '#05b3a4'});
|
|
const slideAudio = this.sound.add('slide');
|
|
thirdTextLayer.setVisible(false);
|
|
thirdLayer.setDepth(1.1);
|
|
// thirdLayer.setScale(1.15);
|
|
thirdLayer.setAlpha(0.5);
|
|
thirdLayer.setInteractive({ draggable: true });
|
|
thirdLayer.setVisible(false);
|
|
|
|
firstLayer.on('drag', (pointer) => {
|
|
if (pointer.isDown) {
|
|
firstTextLayer.setVisible(false);
|
|
secondTextLayer.setVisible(true);
|
|
slantRightAudio.play();
|
|
secondLayer.setVisible(true);
|
|
firstLayer.setAlpha(1);
|
|
secondLayer.setAlpha(0.5);
|
|
thirdLayer.setAlpha(0.5);
|
|
} else {
|
|
firstLayer.setAlpha(0.5);
|
|
}
|
|
});
|
|
|
|
secondLayer.on('drag', (pointer) => {
|
|
if (pointer.isDown) {
|
|
secondTextLayer.setVisible(false);
|
|
thirdTextLayer.setVisible(true);
|
|
slideAudio.play();
|
|
thirdLayer.setVisible(true);
|
|
secondLayer.setAlpha(1);
|
|
thirdLayer.setAlpha(0.5);
|
|
} else {
|
|
secondLayer.setAlpha(0.5);
|
|
}
|
|
});
|
|
|
|
thirdLayer.on('drag', (pointer) => {
|
|
if (pointer.isDown) {
|
|
thirdLayer.setAlpha(1);
|
|
thirdTextLayer.setVisible(false);
|
|
// const succesImage = this.add.image(customWidth / 2, customHeight / 2, 'succesImage').setDepth(2);
|
|
// succesImage.setAlpha(0.2);
|
|
// this.add.text(customWidth / 2, customHeight / 2, 'OK', { font: '700 40px quicksand', fill: '#05b3a4'}).setDepth(2);
|
|
} else {
|
|
thirdLayer.setAlpha(0.5);
|
|
}
|
|
});
|
|
graphics = this.add.graphics();
|
|
graphics.lineStyle(15, 0x05b3a4, 2).setDepth(2); // Set line style (width, color, alpha)
|
|
|
|
this.input.on('pointerdown', function (pointer) {
|
|
isDrawing = true;
|
|
graphics.moveTo(pointer.x, pointer.y);
|
|
});
|
|
|
|
this.input.on('pointerup', function () {
|
|
isDrawing = false;
|
|
});
|
|
|
|
this.input.on('pointermove', function (pointer) {
|
|
if (!isDrawing) return;
|
|
|
|
graphics.lineTo(pointer.x, pointer.y);
|
|
graphics.strokePath();
|
|
});
|
|
}
|
|
|
|
function update() {
|
|
// Update any game logic if needed
|
|
}
|
|
</script> |