626 lines
24 KiB
Plaintext
626 lines
24 KiB
Plaintext
---
|
|
import Layout from '../../layouts/Layout.astro';
|
|
---
|
|
<Layout title="Drag Game">
|
|
<main>
|
|
<div>
|
|
<div id="loadingMainContainer" class="w-full h-screen bg-[#00000070] absolute" style="display: none;">
|
|
<div id="loadingState" style="display: none;" class="bg-white flex text-[#000] absolute left-1/2 top-1/2 -translate-y-1/2 -translate-x-1/2 max-w-lg flex-col rounded-[8px] items-center space-y-2 w-full px-6 py-16"></div>
|
|
</div>
|
|
<div id="scoreBoard" class=" w-full h-screen bg-[#00000070] absolute" style="display: none;">
|
|
<div class="flex absolute left-1/2 top-1/2 -translate-y-1/2 -translate-x-1/2 max-w-lg flex-col rounded-[8px] bg-white space-y-2 w-full p-6" >
|
|
<div class="flex flex-row space-x-4 items-center justify-center">
|
|
<div id="star-container"></div>
|
|
</div>
|
|
<div class="flex flex-row" style="margin-top: 15px; margin-bottom: 15px;">
|
|
<img class="z-10" src="/assets/clip-art.svg" alt="" />
|
|
<p id="starFeedbackMessage" class="text-[#0348A8] text-[12px] font-[700] p-6 rounded-[10px] -ml-[10px]" style="background: linear-gradient(270.05deg, #FFFFFF 4.67%, #DAEAFF 99.61%);"></p>
|
|
</div>
|
|
<div class="flex flex-col w-full max-w-sm items-center justify-center mx-auto gap-3">
|
|
<button class="rounded-[4px] bg-[#0348A8] text-[#FFF] text-[12px] font-[700] p-2.5 w-full border-[1px] border-[#0348A8]">Wow, Lets Go</button>
|
|
<button onclick="retryGame();" class="border-[1px] border-[#0348A8] p-2.5 rounded-[4px] text-[#0348A8] w-full">Try Again</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div id="wsSavedImg" class="clip-art-container absolute -z-10 bottom-0 right-0">
|
|
<img src="/assets/svg/clip-art2.svg" alt="Clip Art" class="clip-art">
|
|
</div>
|
|
</div>
|
|
<script is:inline src="/assets/js/phaser_3.60.0.js"></script>
|
|
</main>
|
|
</Layout>
|
|
<script src="/saveGameData.js" is:inline></script>
|
|
<script is:inline>
|
|
function showAnimation() {
|
|
const clipArt = document.querySelector('.clip-art');
|
|
clipArt.classList.add('show');
|
|
}
|
|
const isMobile = window.innerWidth <= 768; // Define your mobile breakpoint as needed
|
|
const isTab = window.innerWidth > 768 && window.innerWidth <= 1416;
|
|
const drawingZone = {
|
|
x: isMobile ? 0 : window.innerWidth / 4, // Set x to 0 on mobile, else 1/4 of screen width
|
|
y: window.innerHeight / 4,
|
|
width: isMobile ? window.innerWidth : window.innerWidth / 2, // Full width on mobile, else 1/2 of screen width
|
|
height: window.innerHeight / 2,
|
|
};
|
|
let submitButton;
|
|
let formattedDateTime;
|
|
let shortUniqueID;
|
|
let scoreTotal = 0;
|
|
let maxScore = 8;
|
|
let resultView;
|
|
let topLogoWidth;
|
|
let muteIconWidth;
|
|
let resetIconWidth;
|
|
let tickIconWidth;
|
|
let cancelIconWidth;
|
|
let retryButton;
|
|
let blockMatches;
|
|
let leftTargetZoneW;
|
|
let rightTargetZoneW;
|
|
let retryButtonWidth;
|
|
|
|
if(isMobile){
|
|
topLogoWidth = 4.5;
|
|
muteIconWidth = 1.8;
|
|
resetIconWidth = 1.47;
|
|
tickIconWidth = 1.24;
|
|
cancelIconWidth = 1.08;
|
|
}else if(isTab){
|
|
topLogoWidth = 4.5;
|
|
muteIconWidth = 1.6;
|
|
resetIconWidth = 1.43;
|
|
tickIconWidth = 1.29;
|
|
cancelIconWidth = 1.18;
|
|
}else{
|
|
topLogoWidth = 6;
|
|
muteIconWidth = 1.3;
|
|
resetIconWidth = 1.26;
|
|
tickIconWidth = 1.222;
|
|
cancelIconWidth = 1.185;
|
|
}
|
|
|
|
if(isMobile){
|
|
noticeWidth = 100;
|
|
noticeHeight = 0;
|
|
buttonWidth = 67;
|
|
buttonHeight = 0;
|
|
retryButtonWidth = window.innerWidth / 2 - 140;
|
|
retryButtonHeight = window.innerHeight - 50;
|
|
leftTargetZoneW = window.innerWidth / 6;
|
|
rightTargetZoneW = window.innerWidth * 0.9 - 40;
|
|
} else {
|
|
noticeWidth = 100;
|
|
noticeHeight = 0;
|
|
buttonWidth = 100;
|
|
buttonHeight = 0;
|
|
retryButtonWidth = window.innerWidth / 2 - 50;
|
|
retryButtonHeight = window.innerHeight - 70;
|
|
leftTargetZoneW = window.innerWidth / 6;
|
|
rightTargetZoneW = window.innerWidth * 0.9 - 172;
|
|
}
|
|
gameResult = [];
|
|
window.onload = function() {
|
|
// Get the current date and time
|
|
currentDate = new Date();
|
|
|
|
formattedDateTime = currentDate.toLocaleString();
|
|
|
|
};
|
|
function generateShortUniqueID(length) {14
|
|
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
let result = '';
|
|
for (let i = 0; i < length; i++) {
|
|
const randomIndex = Math.floor(Math.random() * characters.length);
|
|
result += characters.charAt(randomIndex);
|
|
}
|
|
return result;
|
|
};
|
|
shortUniqueID = generateShortUniqueID(10); // Change 10 to the desired length * 0.9 - 172
|
|
const leftTargetZones = [
|
|
{
|
|
x: leftTargetZoneW + 30,
|
|
y: window.innerHeight / 2.5,
|
|
name: "target1",
|
|
block: null,
|
|
},
|
|
// Add more left target zones as needed
|
|
];
|
|
|
|
const rightTargetZones = [
|
|
{
|
|
x: rightTargetZoneW - 30,
|
|
y: window.innerHeight / 2.5,
|
|
name: "target2",
|
|
block: null,
|
|
},
|
|
// Add more right target zones as needed
|
|
];
|
|
|
|
const targetZones = [...leftTargetZones, ...rightTargetZones];
|
|
// console.log(blockMatches.blockName, blockMatches.targetName)
|
|
var assetsList = {};
|
|
const params = new URLSearchParams(window.location.search);
|
|
const paramsID = params.get('id');
|
|
const data = fetch(`https://game-du.teachertrainingkolkata.in/items/game_drag_v4/${encodeURIComponent(paramsID)}?filter[status][_eq]=published`)
|
|
.then(response => response.json())
|
|
.then(({data}) => {
|
|
const {image1, image2, image3, image4, image5, image6, image7, image8} = data;
|
|
if(isMobile){imageCustomWidth = "?width=100";} else{imageCustomWidth = "?width=100";};
|
|
const assetsURL = "https://game-du.teachertrainingkolkata.in/assets/"
|
|
assetsList.element1 = assetsURL + image1 + imageCustomWidth;
|
|
assetsList.element2 = assetsURL + image2 + imageCustomWidth;
|
|
assetsList.element3 = assetsURL + image3 + imageCustomWidth;
|
|
assetsList.element4 = assetsURL + image4 + imageCustomWidth;
|
|
assetsList.element5 = assetsURL + image5 + imageCustomWidth;
|
|
assetsList.element6 = assetsURL + image6 + imageCustomWidth;
|
|
assetsList.element7 = assetsURL + image7 + imageCustomWidth;
|
|
assetsList.element8 = assetsURL + image8 + imageCustomWidth;
|
|
// console.log(assetsList.left_image1)
|
|
const config = {
|
|
type: Phaser.AUTO,
|
|
width: window.innerWidth,
|
|
height: window.innerHeight,
|
|
backgroundColor: '#ffffff',
|
|
parent: "phaser-example",
|
|
scale: {
|
|
mode: Phaser.Scale.FIT,
|
|
autoCenter: Phaser.Scale.CENTER_HORIZONTALLY,
|
|
},
|
|
scene: MyGame,
|
|
};
|
|
const game = new Phaser.Game(config);
|
|
|
|
})
|
|
.catch(error => {
|
|
|
|
console.error('Error fetching initial data:', error);
|
|
});
|
|
class MyGame extends Phaser.Scene {
|
|
constructor() {
|
|
super();
|
|
}
|
|
preload() {
|
|
var progressBar = this.add.graphics();
|
|
var progressBox = this.add.graphics();
|
|
progressBox.fillStyle(0x222222, 0.8);
|
|
progressBox.fillRect(240, 270, 320, 50);
|
|
|
|
var width = this.cameras.main.width;
|
|
var height = this.cameras.main.height;
|
|
var loadingText = this.make.text({
|
|
x: width / 2,
|
|
y: height / 2 - 50,
|
|
text: 'Loading...',
|
|
style: {
|
|
font: '20px monospace',
|
|
fill: '#ffffff'
|
|
}
|
|
});
|
|
loadingText.setOrigin(0.5, 0.5);
|
|
var percentText = this.make.text({
|
|
x: width / 2,
|
|
y: height / 2 - 5,
|
|
text: '0%',
|
|
style: {
|
|
font: '18px monospace',
|
|
fill: '#ffffff'
|
|
}
|
|
});
|
|
percentText.setOrigin(0.5, 0.5);
|
|
var assetText = this.make.text({
|
|
x: width / 2,
|
|
y: height / 2 + 50,
|
|
text: '',
|
|
style: {
|
|
font: '18px monospace',
|
|
fill: '#ffffff'
|
|
}
|
|
});
|
|
assetText.setOrigin(0.5, 0.5);
|
|
this.load.on('progress', function (value) {
|
|
percentText.setText(parseInt(value * 100) + '%');
|
|
progressBar.clear();
|
|
progressBar.fillStyle(0xffffff, 1);
|
|
progressBar.fillRect(250, 280, 300 * value, 30);
|
|
});
|
|
this.load.on('fileprogress', function (file) {
|
|
assetText.setText('Loading asset: ' + file.key);
|
|
});
|
|
this.load.on('complete', function () {
|
|
progressBar.destroy();
|
|
progressBox.destroy();
|
|
loadingText.destroy();
|
|
percentText.destroy();
|
|
assetText.destroy();
|
|
});
|
|
// this.load.image('logo', 'zenvalogo.png');
|
|
for (var i = 0; i < 5; i++) {
|
|
this.load.image('logo'+i, '/assets/background.jpg');
|
|
}
|
|
this.load.image("topMatch", "/assets/top_match.jpg");
|
|
this.load.image('topLogo', '/assets/top_logo.svg');
|
|
// this.load.image("tick", '/assets/tick.png');
|
|
|
|
this.load.image("tickIcon", '/assets/svg/tick2.svg');
|
|
this.load.image("muteIcon", '/assets/svg/mute.svg');
|
|
this.load.image("cancelIcon", '/assets/svg/cancel.svg');
|
|
this.load.image("resetIcon", '/assets/svg/reset.svg');
|
|
|
|
// this.load.image("retryIcon", "/assets/svg/retry.svg")
|
|
this.load.image("border", '/assets/squar.png');
|
|
|
|
|
|
this.load.spritesheet("blocks1", assetsList.element5,{
|
|
frameWidth: 100,
|
|
frameHeight: 100,
|
|
});
|
|
this.load.spritesheet("blocks2", assetsList.element6,{
|
|
frameWidth: 100,
|
|
frameHeight: 100,
|
|
});
|
|
this.load.spritesheet("blocks3", assetsList.element7,{
|
|
frameWidth: 100,
|
|
frameHeight: 100,
|
|
});
|
|
this.load.spritesheet("blocks4", assetsList.element8,{
|
|
frameWidth: 100,
|
|
frameHeight: 100,
|
|
});
|
|
this.load.spritesheet("blocks5", assetsList.element1,{
|
|
frameWidth: 100,
|
|
frameHeight: 100,
|
|
});
|
|
this.load.spritesheet("blocks6", assetsList.element2, {
|
|
frameWidth: 100,
|
|
frameHeight: 100,
|
|
});
|
|
this.load.spritesheet("blocks7", assetsList.element3, {
|
|
frameWidth: 100,
|
|
frameHeight: 100,
|
|
});
|
|
this.load.spritesheet("blocks8", assetsList.element4, {
|
|
frameWidth: 100,
|
|
frameHeight: 100,
|
|
});
|
|
}
|
|
|
|
create() {
|
|
|
|
const params = new URLSearchParams(window.location.search);
|
|
const paramsID = params.get('id');
|
|
fetch(`https://game-du.teachertrainingkolkata.in/items/game_drag_v4/${encodeURIComponent(paramsID)}?filter[status][_eq]=published`)
|
|
.then(response => response.json())
|
|
.then(({ data }) => {
|
|
blockMatches = [
|
|
{
|
|
blockName: "blocks1",
|
|
targetName: `target${data.match1}`,
|
|
},
|
|
{
|
|
blockName: "blocks2",
|
|
targetName: `target${data.match2}`,
|
|
},
|
|
{
|
|
blockName: "blocks3",
|
|
targetName: `target${data.match3}`,
|
|
},
|
|
{
|
|
blockName: "blocks4",
|
|
targetName: `target${data.match4}`,
|
|
},
|
|
{
|
|
blockName: "blocks5",
|
|
targetName: `target${data.match5}`,
|
|
},
|
|
{
|
|
blockName: "blocks6",
|
|
targetName: `target${data.match6}`,
|
|
},
|
|
{
|
|
blockName: "blocks7",
|
|
targetName: `target${data.match7}`,
|
|
},
|
|
{
|
|
blockName: "blocks8",
|
|
targetName: `target${data.match8}`,
|
|
}
|
|
];
|
|
// console.log(data)
|
|
if(data.label1, data.label2, data.label3, data.label4, data.label5, data.label6, data.label7, data.label8){
|
|
this.add.text(window.innerWidth / 2 - 170, window.innerHeight - 20, data.label1, {font:`15px`, fill: `#7c4c23`})
|
|
this.add.text(window.innerWidth / 2 - 80, window.innerHeight - 20, data.label2, {font:`15px`, fill: `#7c4c23`})
|
|
this.add.text(window.innerWidth / 2 + 30, window.innerHeight - 20, data.label3, {font:`15px`, fill: `#7c4c23`})
|
|
this.add.text(window.innerWidth / 2 + 125, window.innerHeight - 20, data.label4, {font:`15px`, fill: `#7c4c23`})
|
|
this.add.text(window.innerWidth / 2 - 170, window.innerHeight - 150, data.label5, {font:`15px`, fill: `#7c4c23`})
|
|
this.add.text(window.innerWidth / 2 - 80, window.innerHeight - 150, data.label6, {font:`15px`, fill: `#7c4c23`})
|
|
this.add.text(window.innerWidth / 2 + 30, window.innerHeight - 150, data.label7, {font:`15px`, fill: `#7c4c23`})
|
|
this.add.text(window.innerWidth / 2 + 125, window.innerHeight - 150, data.label8, {font:`15px`, fill: `#7c4c23`})
|
|
}
|
|
if(isMobile){
|
|
this.add.text(window.innerWidth / 18, window.innerHeight / 4, data.left_label+'!', {font:`10px`, fill: `#60C6CB`});
|
|
this.add.text(window.innerWidth / 1.8, window.innerHeight / 4, data.right_label, {font:`10px`, fill: `#60C6CB`});
|
|
} else if(isTab){
|
|
this.add.text(window.innerWidth / 17, window.innerHeight / 6, data.left_label+'!', {font: `20px`, fill: `#60C6CB`});
|
|
this.add.text(window.innerWidth / 1.8, window.innerHeight / 6, data.right_label, {font: `20px`, fill: `#60C6CB`});
|
|
} else{
|
|
this.add.text(window.innerWidth / 9, window.innerHeight / 6, data.left_label+'!', {font: `20px`, fill: `#60C6CB`});
|
|
this.add.text(window.innerWidth / 1.39, window.innerHeight / 6, data.right_label, {font: `20px`, fill: `#60C6CB`});
|
|
}
|
|
let wrapWidth;
|
|
let textSizeScale;
|
|
if(isMobile){
|
|
wrapWidth = 10;
|
|
textSizeScale = 540
|
|
} else{
|
|
wrapWidth = 200;
|
|
textSizeScale = 940
|
|
}
|
|
const screenCenterX = this.cameras.main.worldView.x + this.cameras.main.width / 2;
|
|
const baseFontSize = 24;
|
|
const responsiveFontSize = (window.innerWidth / textSizeScale) * baseFontSize;
|
|
const descrptText = this.add.text(screenCenterX, 85, data.description, { font: `${responsiveFontSize}px quicksand`, fill: '#60C6CB', align: "center", wordWrap: {width: window.innerWidth-wrapWidth}}, ).setOrigin(0.5);
|
|
})
|
|
.catch(error => {
|
|
console.error('Error fetching initial data:', error);
|
|
});
|
|
const displayW = window.innerWidth;
|
|
// const URL = window.location.href;
|
|
// const gameName = URL.split('/');
|
|
// let userData = {
|
|
// 'user': 'drawing@beanstalkedu.com',
|
|
// 'game_name': gameName[3],
|
|
// 'starts': formattedDateTime,
|
|
// // 'game_start' : gameStartTime,
|
|
// };
|
|
// function submitUserData() {
|
|
// fetch(`https://2016.dev2-cs.siliconpin.com/save/`, {
|
|
// method: 'POST',
|
|
// headers: {
|
|
// 'Content-Type' : 'application/json'
|
|
// },
|
|
// body: JSON.stringify(userData)
|
|
// })
|
|
// .then(response => {
|
|
// if(response.ok){
|
|
// // console.log('Data Saved', response)
|
|
// } else{
|
|
// // console.log('Something Wrong', response)
|
|
// }
|
|
// })
|
|
// .catch(error => {
|
|
// console.error('An error occured', error)
|
|
// });
|
|
// };
|
|
// window.load
|
|
|
|
const graphics = this.add.graphics();
|
|
const x = 0; const y = 54;
|
|
const lineWidth = window.innerWidth;
|
|
graphics.lineStyle(1, 0x0348A8);
|
|
graphics.setAlpha(0.2);
|
|
graphics.beginPath();
|
|
graphics.moveTo(x, y);
|
|
graphics.lineTo(x + lineWidth, y);
|
|
graphics.strokePath();
|
|
|
|
this.add.image(displayW / topLogoWidth, 30, "topLogo").setScale();
|
|
this.add.image(displayW / muteIconWidth, 30, "muteIcon").setScale();
|
|
const retryButton = this.add.image(displayW / resetIconWidth, 30, "resetIcon").setScale();
|
|
submitButton = this.add.image(displayW / tickIconWidth, 30, "tickIcon").setScale();
|
|
this.add.image(displayW / cancelIconWidth, 30, "cancelIcon").setScale();
|
|
// submitButton = this.add.text(window.innerWidth / 2 - buttonWidth, window.innerHeight / 2 - buttonHeight, "Submit", {
|
|
// font: '600 30px Quicksand',
|
|
// fill: '#fff',
|
|
// backgroundColor: 'blue',
|
|
// padding: { x: 20, y: 10 },
|
|
// }).setDepth(1);
|
|
submitButton.setInteractive().on('pointerdown', () => {
|
|
// console.log('Clicked');
|
|
// window.location.reload();
|
|
// windowLoad();
|
|
submitUserData(this);
|
|
showAnimation();
|
|
})
|
|
// this.add.image(displayW / 2, displayH / 2, "bg").setScale(2.4);
|
|
|
|
|
|
|
|
const blocks = [
|
|
{
|
|
x: displayW / 2 - 200,
|
|
y: window.innerHeight - 250,
|
|
textureKey: "blocks1",
|
|
id: "block1",
|
|
},
|
|
{
|
|
x: displayW / 2-100,
|
|
y: window.innerHeight - 250,
|
|
textureKey: "blocks2",
|
|
id: "block2",
|
|
},
|
|
{
|
|
x: displayW / 2,
|
|
y: window.innerHeight - 250,
|
|
textureKey: "blocks3",
|
|
id: "block3",
|
|
},
|
|
{
|
|
x: displayW / 2+100,
|
|
y: window.innerHeight - 250,
|
|
textureKey: "blocks4",
|
|
id: "block4",
|
|
},
|
|
{
|
|
x: displayW / 2-200,
|
|
y: window.innerHeight - 120,
|
|
textureKey: "blocks5",
|
|
id: "block5",
|
|
},
|
|
{
|
|
x: displayW / 2-100,
|
|
y: window.innerHeight - 120,
|
|
textureKey: "blocks6",
|
|
id: "block6",
|
|
},
|
|
{
|
|
x: displayW / 2,
|
|
y: window.innerHeight - 120,
|
|
textureKey: "blocks7",
|
|
id: "block7",
|
|
},
|
|
{
|
|
x: displayW / 2+100,
|
|
y: window.innerHeight - 120,
|
|
textureKey: "blocks8",
|
|
id: "block8",
|
|
},
|
|
];
|
|
// console.log('test blocks',blocks[0])
|
|
let borderScale; if(isMobile){borderScale = 0.9;} else{borderScale = 1.5;}
|
|
const droppedBlocks = [];
|
|
const targetZoneBorders = [];
|
|
targetZones.forEach((targetZone) => {
|
|
const targetImage = this.add.image(targetZone.x, targetZone.y, targetZone.name).setAlpha(0);
|
|
const targetBorder = this.add.image(targetZone.x , targetZone.y, "border").setAlpha(0.05).setScale(borderScale);
|
|
targetZoneBorders.push(targetBorder);
|
|
targetZone.block = null;
|
|
}),
|
|
blocks.forEach((block, index) => {
|
|
let blocksScale;
|
|
|
|
if(isMobile){
|
|
blocksScale = 0.75;
|
|
} else{
|
|
blocksScale = 1;
|
|
}
|
|
const newBlock = this.add.sprite(block.x + 10, block.y, block.textureKey, 0).setOrigin(0, 0).setInteractive({ draggable: true }).setScale(blocksScale);
|
|
// this.add.sprite(block.x, block.y, block.textureKey, 1).setOrigin(0, 0).setAlpha(0.3);
|
|
newBlock.on("drag", (pointer, dragX, dragY) => {
|
|
newBlock.setScale(blocksScale+.3);
|
|
newBlock.x = dragX;
|
|
newBlock.y = dragY;
|
|
});
|
|
|
|
newBlock.on("dragend", () => {
|
|
newBlock.setScale(blocksScale).setDepth(-2);
|
|
let droppedOnTargetZone = false;
|
|
|
|
targetZones.forEach((targetZone, targetIndex) => {
|
|
let phaserGeomX, phaserGeomY, blockSetPosition;
|
|
if(isMobile){
|
|
phaserGeomX = 50;
|
|
phaserGeomY = 25;
|
|
blockSetPosition = 40;
|
|
}else{
|
|
phaserGeomX = 200;
|
|
phaserGeomY = 100;
|
|
blockSetPosition = 50;
|
|
}
|
|
if (
|
|
Phaser.Geom.Intersects.RectangleToRectangle(
|
|
newBlock.getBounds(),
|
|
new Phaser.Geom.Rectangle(targetZone.x, targetZone.y, phaserGeomX, phaserGeomY)
|
|
)
|
|
) {
|
|
// newBlock.setPosition(targetZone.x - 50, targetZone.y - 50);
|
|
const col = counter % 2;
|
|
const row = Math.floor(counter / 2);
|
|
|
|
newBlock.setPosition(targetZone.x - blockSetPosition, targetZone.y - blockSetPosition);
|
|
newBlock.disableInteractive();
|
|
targetZone.block = newBlock;
|
|
droppedBlocks.push(newBlock);
|
|
|
|
// Adjust isMatch function based on your requirements
|
|
if (isMatch(newBlock.texture.key, targetZone.name)) {
|
|
// Handle match logic if needed
|
|
}
|
|
|
|
droppedOnTargetZone = true;
|
|
targetZoneBorders[targetIndex].setVisible(true);
|
|
targetZoneBorders[targetIndex].setAlpha(0.05);
|
|
return;
|
|
}
|
|
});
|
|
|
|
if (!droppedOnTargetZone) {
|
|
newBlock.setPosition(newBlock.input.dragStartX, newBlock.input.dragStartY);
|
|
};
|
|
|
|
// Check if all blocks have been dropped on target zones
|
|
if (droppedBlocks.length === targetZones.length) {
|
|
displayResult(droppedBlocks);
|
|
newBlock.setVisible(false);
|
|
}
|
|
});
|
|
|
|
|
|
|
|
});
|
|
// retryButton = this.add.image(retryButtonWidth, retryButtonHeight, 'retryIcon')
|
|
retryButton.setInteractive().on('pointerdown', () => {
|
|
window.location.reload();
|
|
})
|
|
let score = 0;
|
|
let counter = 0;
|
|
const isMatch = (blockName, targetName) => {
|
|
if(isMatch){
|
|
counter++;
|
|
// console.log(counter)
|
|
}
|
|
const match = blockMatches.find((m) => m.blockName === blockName && m.targetName === targetName);
|
|
// console.log(match)
|
|
if(match !== undefined){
|
|
scoreTotal++;
|
|
console.log("Score Total", scoreTotal)
|
|
}
|
|
if(counter === 8){
|
|
// console.log(counter)
|
|
submitButton.setVisible(true);
|
|
retryButton.setVisible(true);
|
|
}
|
|
};
|
|
}
|
|
}
|
|
const displayResult = (droppedBlocks) => {
|
|
droppedBlocks.forEach((block) => {
|
|
const targetZone = targetZones.find((zone) => zone.name === block.texture.key);
|
|
});
|
|
};
|
|
|
|
</script>
|
|
<style href="https://fonts.googleapis.com/css?family=Quicksand&display=swap" rel="stylesheet" >
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
cursor: -webkit-grab; cursor: grab;
|
|
font-family: quicksand;
|
|
}
|
|
/* Animation styles */
|
|
@keyframes slideInUp {
|
|
0% {
|
|
opacity: 0;
|
|
transform: translateY(100%); /* Start below the viewport */
|
|
}
|
|
100% {
|
|
opacity: 1;
|
|
transform: translateY(0); /* End at its original position */
|
|
}
|
|
}
|
|
|
|
.clip-art-container {
|
|
overflow: hidden; /* Prevents overflow during the animation */
|
|
}
|
|
|
|
.clip-art {
|
|
transform: translateX(100%); /* Initially off-screen to the right */
|
|
opacity: 0; /* Initially hidden */
|
|
transition: transform 0.5s ease-in-out, opacity 0.5s ease-in-out; /* Smooth transition */
|
|
}
|
|
|
|
.clip-art.show {
|
|
transform: translateX(0); /* Move the image into view */
|
|
opacity: 1; /* Fade in */
|
|
}
|
|
</style> |