reverse drag v3 and v4

pull/2/head
dev sp 2024-02-08 15:48:41 +00:00
parent c229800e73
commit 9fff1e4a29
3 changed files with 193 additions and 209 deletions

View File

@ -86,6 +86,9 @@ import Layout from '../../layouts/Layout.astro';
// Format the date and time as a string // Format the date and time as a string
formattedDateTime = currentDate.toLocaleString(); formattedDateTime = currentDate.toLocaleString();
// Log the formatted date and time to the console
// // console.log("Page loaded on: " + formattedDateTime);
}; };
function generateShortUniqueID(length) {14 function generateShortUniqueID(length) {14
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
@ -230,6 +233,11 @@ import Layout from '../../layouts/Layout.astro';
this.load.image("topMatch", "/assets/top_match.jpg"); this.load.image("topMatch", "/assets/top_match.jpg");
this.load.image("topLogo", "/assets/top_logo.jpg"); this.load.image("topLogo", "/assets/top_logo.jpg");
this.load.image("tick", '/assets/tick.png'); this.load.image("tick", '/assets/tick.png');
// this.load.image("bg", '/assets/bgwhite.jpg');
// this.load.image("target1", assetsList.right_image1);
// this.load.image("target2", '/assets/hay.png');
// this.load.image("target3", '/assets/mat.png');
// this.load.image("target4", '/assets/star.png');
this.load.image("border", '/assets/squar.png'); this.load.image("border", '/assets/squar.png');
this.load.spritesheet("target1", assetsList.right_image1,{ this.load.spritesheet("target1", assetsList.right_image1,{
frameWidth: 100, frameWidth: 100,
@ -293,6 +301,7 @@ import Layout from '../../layouts/Layout.astro';
const screenCenterX = this.cameras.main.worldView.x + this.cameras.main.width / 2; const screenCenterX = this.cameras.main.worldView.x + this.cameras.main.width / 2;
// Base font size for your text // Base font size for your text
const baseFontSize = 30; const baseFontSize = 30;
// Calculate responsive font size based on screen width
const responsiveFontSize = (window.innerWidth / 950) * baseFontSize; // Adjust 800 to your desired reference width const responsiveFontSize = (window.innerWidth / 950) * baseFontSize; // Adjust 800 to your desired reference width
const descrptText = this.add.text(screenCenterX, 76, data.description, { const descrptText = this.add.text(screenCenterX, 76, data.description, {
font: ` ${responsiveFontSize}px Quicksand`, font: ` ${responsiveFontSize}px Quicksand`,
@ -301,21 +310,16 @@ import Layout from '../../layouts/Layout.astro';
// this.add.text(displayW / 14 - 15, 50, data.LearningArea, {font: `20px`}).setTint(0x7c4c23); // this.add.text(displayW / 14 - 15, 50, data.LearningArea, {font: `20px`}).setTint(0x7c4c23);
// this.add.text(displayW / 14 - 15, 70, data.LearningSubArea_copy, {font: `19px`}).setTint(0x7c4c23); // this.add.text(displayW / 14 - 15, 70, data.LearningSubArea_copy, {font: `19px`}).setTint(0x7c4c23);
// Left Image Name // Left Image Name
let customWidth = window.innerWidth; this.add.text(displayW / 14 - 15, 240, data.left_image1_name).setTint(0x7c4c23);
let customHeight = window.innerHeight; this.add.text(displayW / 14 - 15, 409, data.left_image2_name).setTint(0x7c4c23);
let nameTextSize; this.add.text(displayW / 14 - 15, 579, data.left_image3_name).setTint(0x7c4c23);
let namePosition; this.add.text(displayW / 14 - 15, 750, data.left_image4_name).setTint(0x7c4c23);
if(isMobile){nameTextSize = `10px`; namePosition = 30}else{nameTextSize = `15px`; namePosition = 0}
this.add.text(customWidth / 20, 240, data.left_image1_name, {font: nameTextSize, fill: `#7c4c23`});
this.add.text(customWidth / 20, 409, data.left_image2_name, {font: nameTextSize, fill: `#7c4c23`});
this.add.text(customWidth / 20, 579, data.left_image3_name, {font: nameTextSize, fill: `#7c4c23`});
this.add.text(customWidth / 20, 750, data.left_image4_name, {font : nameTextSize, fill: `#7c4c23`});
//Right Image Name //Right Image Name
this.add.text(customWidth / 1.3 - namePosition, 240, data.right_image1_name, {font: nameTextSize, fill: `#7c4c23`}); this.add.text(displayW * 0.9-80, 240, data.right_image1_name).setTint(0x7c4c23);
this.add.text(customWidth / 1.3 - namePosition, 409, data.right_image2_name, {font: nameTextSize, fill: `#7c4c23`}); this.add.text(displayW * 0.9-80, 409, data.right_image2_name).setTint(0x7c4c23);
this.add.text(customWidth / 1.3 - namePosition, 579, data.right_image3_name, {font: nameTextSize, fill: `#7c4c23`}); this.add.text(displayW * 0.9-80, 579, data.right_image3_name).setTint(0x7c4c23);
this.add.text(customWidth / 1.3 - namePosition, 750, data.right_image4_name, {font: nameTextSize, fill: `#7c4c23`}); this.add.text(displayW * 0.9-80, 750, data.right_image4_name).setTint(0x7c4c23);
}) })
.catch(error => { .catch(error => {
console.error('Error fetching initial data:', error); console.error('Error fetching initial data:', error);
@ -371,16 +375,16 @@ import Layout from '../../layouts/Layout.astro';
submitUserData(); submitUserData();
}) })
// this.add.image(displayW / 2, displayH / 2, "bg").setScale(2.4); // this.add.image(displayW / 2, displayH / 2, "bg").setScale(2.4);
// this.add.image(displayW / 6, 30, "topMatch").setScale(); this.add.image(displayW / 6, 30, "topMatch").setScale();
// this.add.image(displayW * 0.80-5, 30, "topLogo").setScale(); this.add.image(displayW * 0.80-5, 30, "topLogo").setScale();
// this.add.image(displayW * 0.9-32, 170, "target1"), this.add.image(displayW * 0.9-32, 170, "target1"),
// this.add.image(displayW * 0.9-43, 170, "border").setAlpha(0.4).setScale(0.65), this.add.image(displayW * 0.9-43, 170, "border").setAlpha(0.4).setScale(0.65),
// this.add.image(displayW * 0.9-32, 340, "target2"), this.add.image(displayW * 0.9-32, 340, "target2"),
// this.add.image(displayW * 0.9-43, 340, "border").setAlpha(0.4).setScale(0.65), this.add.image(displayW * 0.9-43, 340, "border").setAlpha(0.4).setScale(0.65),
// this.add.image(displayW * 0.9-32, 510, "target3"), this.add.image(displayW * 0.9-32, 510, "target3"),
// this.add.image(displayW * 0.9-43, 510, "border").setAlpha(0.4).setScale(0.65), this.add.image(displayW * 0.9-43, 510, "border").setAlpha(0.4).setScale(0.65),
// this.add.image(displayW * 0.9-32, 680, "target4"), this.add.image(displayW * 0.9-32, 680, "target4"),
// this.add.image(displayW * 0.9-43, 680, "border").setAlpha(0.4).setScale(0.65); this.add.image(displayW * 0.9-43, 680, "border").setAlpha(0.4).setScale(0.65);
const blocks = [ const blocks = [
{ {
x: displayW / 15 - 15, x: displayW / 15 - 15,
@ -412,16 +416,15 @@ import Layout from '../../layouts/Layout.astro';
const targetZoneBorders = []; const targetZoneBorders = [];
targetZones.forEach((targetZone) => { targetZones.forEach((targetZone) => {
const targetImage = this.add.image(targetZone.x, targetZone.y, targetZone.name).setAlpha(0); const targetImage = this.add.image(targetZone.x, targetZone.y, targetZone.name).setAlpha(0);
const targetBorder = this.add.image(targetZone.x = displayW / 1.25, targetZone.y, targetZone.name).setAlpha(1).setScale(1); const targetBorder = this.add.image(targetZone.x = displayW * 0.9 - 172, targetZone.y, "border").setAlpha(0.2).setScale(0.65);
targetZoneBorders.push(targetBorder); targetZoneBorders.push(targetBorder);
targetZone.block = null; targetZone.block = null;
}), }),
blocks.forEach((block, index) => { blocks.forEach((block, index) => {
const newBlock = this.add.sprite(block.x, block.y, block.textureKey, 1).setOrigin(0, 0).setInteractive({ draggable: true }); const newBlock = this.add.sprite(block.x, block.y, block.textureKey, 1).setOrigin(0, 0).setInteractive({ draggable: true });
this.add.sprite(block.x, block.y, block.textureKey, 1).setOrigin(0, 0).setAlpha(1); this.add.sprite(block.x, block.y, block.textureKey, 1).setOrigin(0, 0).setAlpha(0.3);
newBlock.on("drag", (pointer, dragX, dragY) => { newBlock.on("drag", (pointer, dragX, dragY) => {
newBlock.setAlpha(0)
newBlock.setScale(1.3); newBlock.setScale(1.3);
newBlock.x = dragX; newBlock.x = dragX;
newBlock.y = dragY; newBlock.y = dragY;

View File

@ -64,8 +64,8 @@ import Layout from '../../layouts/Layout.astro';
buttonHeight = 0; buttonHeight = 0;
retryButtonWidth = window.innerWidth / 2 - 140; retryButtonWidth = window.innerWidth / 2 - 140;
retryButtonHeight = window.innerHeight - 50; retryButtonHeight = window.innerHeight - 50;
leftTargetZoneW = window.innerWidth / 6; leftTargetZoneW = window.innerWidth * 0.9 - 40;
rightTargetZoneW = window.innerWidth * 0.9 - 40; rightTargetZoneW = window.innerWidth / 6;
} else { } else {
noticeWidth = 100; noticeWidth = 100;
noticeHeight = 0; noticeHeight = 0;
@ -73,23 +73,26 @@ import Layout from '../../layouts/Layout.astro';
buttonHeight = 0; buttonHeight = 0;
retryButtonWidth = window.innerWidth / 2 - 50; retryButtonWidth = window.innerWidth / 2 - 50;
retryButtonHeight = window.innerHeight - 70; retryButtonHeight = window.innerHeight - 70;
leftTargetZoneW = window.innerWidth / 6; leftTargetZoneW = window.innerWidth * 0.9 - 172;
rightTargetZoneW = window.innerWidth * 0.9 - 172; rightTargetZoneW = window.innerWidth / 6;
} }
let submitButton; let submitButton;
let formattedDateTime; let formattedDateTime;
let shortUniqueID; let shortUniqueID;
let retryButton; let retryButton;
let blockMatches; let blockMatches;
let scoreTotal = 0; let resultView;
let resultView; // scoreTotal resultView let scoreTotal = 0; // resultView scoreTotal
gameResult = []; gameResult = [];
window.onload = function() { window.onload = function() {
// Get the current date and time // Get the current date and time
currentDate = new Date(); currentDate = new Date();
// Format the date and time as a string
formattedDateTime = currentDate.toLocaleString(); formattedDateTime = currentDate.toLocaleString();
// Log the formatted date and time to the console
// // console.log("Page loaded on: " + formattedDateTime);
}; };
function generateShortUniqueID(length) {14 function generateShortUniqueID(length) {14
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
@ -101,41 +104,62 @@ import Layout from '../../layouts/Layout.astro';
return result; return result;
}; };
shortUniqueID = generateShortUniqueID(10); // Change 10 to the desired length * 0.9 - 172 shortUniqueID = generateShortUniqueID(10); // Change 10 to the desired length * 0.9 - 172
const leftTargetZones = [
const targetZones = [
{ {
x: window.innerWidth / 4, x: rightTargetZoneW,
y: window.innerHeight / 2.5, y: 170,
name: "target1", name: "target1",
block: null, block: null,
}, },
// Add more left target zones as needed
];
const centerTargetZones = [
{ {
x: window.innerWidth / 2, x: rightTargetZoneW,
y: window.innerHeight / 2.5, y: 340,
name: "target2", name: "target2",
block: null, block: null,
}, },
// Add more right target zones as needed
];
const rightTargetZones = [
{ {
x: window.innerWidth / 1.33, x: rightTargetZoneW,
y: window.innerHeight / 2.5, y: 510,
name: "target3", name: "target3",
block: null, block: null,
}, },
// Add more right target zones as needed {
x: rightTargetZoneW,
y: 680,
name: "target4",
block: null,
},
{
x: leftTargetZoneW,
y: 170,
name: "target5",
block: null,
},
{
x: leftTargetZoneW,
y: 340,
name: "target6",
block: null,
},
{
x: leftTargetZoneW,
y: 510,
name: "target7",
block: null,
},
{
x: leftTargetZoneW,
y: 680,
name: "target8",
block: null,
},
]; ];
const targetZones = [...leftTargetZones, ...centerTargetZones, ...rightTargetZones];
// console.log(blockMatches.blockName, blockMatches.targetName) // console.log(blockMatches.blockName, blockMatches.targetName)
var assetsList = {}; var assetsList = {};
const params = new URLSearchParams(window.location.search); const params = new URLSearchParams(window.location.search);
const paramsID = params.get('id'); const paramsID = params.get('id');
const data = fetch(`https://game-du.teachertrainingkolkata.in/items/game_drag_v03/${encodeURIComponent(paramsID)}?filter[status][_eq]=published`) const data = fetch(`https://game-du.teachertrainingkolkata.in/items/game_drag_v3/${encodeURIComponent(paramsID)}?filter[status][_eq]=published`)
.then(response => response.json()) .then(response => response.json())
.then(({data}) => { .then(({data}) => {
const {image1, image2, image3, image4, image5, image6, image7, image8} = data; const {image1, image2, image3, image4, image5, image6, image7, image8} = data;
@ -153,7 +177,6 @@ import Layout from '../../layouts/Layout.astro';
assetsList.element6 = assetsURL + image6 + imageCustomWidth; assetsList.element6 = assetsURL + image6 + imageCustomWidth;
assetsList.element7 = assetsURL + image7 + imageCustomWidth; assetsList.element7 = assetsURL + image7 + imageCustomWidth;
assetsList.element8 = assetsURL + image8 + imageCustomWidth; assetsList.element8 = assetsURL + image8 + imageCustomWidth;
// console.log(assetsList.left_image1)
const config = { const config = {
type: Phaser.AUTO, type: Phaser.AUTO,
width: window.innerWidth, width: window.innerWidth,
@ -231,7 +254,6 @@ import Layout from '../../layouts/Layout.astro';
percentText.destroy(); percentText.destroy();
assetText.destroy(); assetText.destroy();
}); });
// this.load.image('logo', 'zenvalogo.png');
for (var i = 0; i < 5; i++) { for (var i = 0; i < 5; i++) {
this.load.image('logo'+i, '/assets/background.jpg'); this.load.image('logo'+i, '/assets/background.jpg');
} }
@ -275,30 +297,12 @@ import Layout from '../../layouts/Layout.astro';
} }
create() { create() {
// const borderGraphics = this.add.graphics();
// borderGraphics.lineStyle(borderThickness, 0x7c4c23); // Border color: 0x000000 (black), Border thickness: 2
// const borderX = window.innerWidth / 2 - borderThickness / 2; // Center the border on the screen
// borderGraphics.beginPath();
// borderGraphics.moveTo(borderX, 130);
// borderGraphics.lineTo(borderX, window.innerHeight - 260);
// borderGraphics.strokePath();
// borderGraphics.closePath();
const borderThickness = 6;
const borderGraphicsX = this.add.graphics();
const borderThicknessX = 6;
borderGraphicsX.lineStyle(borderThicknessX, 0x7c4c23); // Border color: 0x7c4c23, Border thickness: 6
const borderY = window.innerHeight / 1.5; // Center the border vertically on the screen
borderGraphicsX.beginPath();
borderGraphicsX.moveTo(0, borderY);
borderGraphicsX.lineTo(window.innerWidth, borderY);
borderGraphicsX.strokePath();
borderGraphicsX.closePath();
const params = new URLSearchParams(window.location.search); const params = new URLSearchParams(window.location.search);
const paramsID = params.get('id'); const paramsID = params.get('id');
fetch(`https://game-du.teachertrainingkolkata.in/items/game_drag_v03/${encodeURIComponent(paramsID)}?filter[status][_eq]=published`) fetch(`https://game-du.teachertrainingkolkata.in/items/game_drag_v3/${encodeURIComponent(paramsID)}?filter[status][_eq]=published`)
.then(response => response.json()) .then(response => response.json())
.then(({ data }) => { .then(({ data }) => {
console.log(data)
blockMatches = [ blockMatches = [
{ {
blockName: "blocks1", blockName: "blocks1",
@ -334,26 +338,9 @@ import Layout from '../../layouts/Layout.astro';
} }
]; ];
// console.log(data) // 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 - 30, data.label1, {font:`15px`, fill: `#7c4c23`})
this.add.text(window.innerWidth / 2 - 90, window.innerHeight - 30, data.label2, {font:`15px`, fill: `#7c4c23`})
this.add.text(window.innerWidth / 2 + 30, window.innerHeight - 30, data.label3, {font:`15px`, fill: `#7c4c23`})
this.add.text(window.innerWidth / 2 + 125, window.innerHeight - 30, 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 - 50, 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(leftTargetZoneW - 60, window.innerHeight / 6, data.left_label, {font:`13px`, fill: `#7C4C23`});
this.add.text(rightTargetZoneW - 120, window.innerHeight / 6, data.right_label, {font:`13px`, fill: `#7C4C23`});
} else{
this.add.text(leftTargetZoneW - 100, window.innerHeight / 6, data.left_label, {font: `20px`, fill: `#7C4C23`});
this.add.text(rightTargetZoneW - 165, window.innerHeight / 6, data.right_label, {font: `20px`, fill: `#7C4C23`});
}
const screenCenterX = this.cameras.main.worldView.x + this.cameras.main.width / 2; const screenCenterX = this.cameras.main.worldView.x + this.cameras.main.width / 2;
// Base font size for your text // Base font size for your text
const baseFontSize = 22; const baseFontSize = 30;
// Calculate responsive font size based on screen width // Calculate responsive font size based on screen width
const responsiveFontSize = (window.innerWidth / 950) * baseFontSize; // Adjust 800 to your desired reference width const responsiveFontSize = (window.innerWidth / 950) * baseFontSize; // Adjust 800 to your desired reference width
const descrptText = this.add.text(screenCenterX, 95, data.description, { const descrptText = this.add.text(screenCenterX, 95, data.description, {
@ -419,61 +406,61 @@ import Layout from '../../layouts/Layout.astro';
this.add.image(displayW * 0.80-5, 30, "topLogo").setScale(); this.add.image(displayW * 0.80-5, 30, "topLogo").setScale();
const blocks = [ const blocks = [
{ {
x: displayW / 2 - 200, x: displayW / 2-400,
y: window.innerHeight - 250, y: window.innerHeight - 120,
textureKey: "blocks1", textureKey: "blocks1",
id: "block1", id: "block1",
}, },
{ {
x: displayW / 2-100, x: displayW / 2-300,
y: window.innerHeight - 250, y: window.innerHeight - 120,
textureKey: "blocks2", textureKey: "blocks2",
id: "block2", id: "block2",
}, },
{ {
x: displayW / 2, x: displayW / 2-200,
y: window.innerHeight - 250, y: window.innerHeight - 120,
textureKey: "blocks3", textureKey: "blocks3",
id: "block3", id: "block3",
}, },
{ {
x: displayW / 2+100, x: displayW / 2 - 100,
y: window.innerHeight - 250, y: window.innerHeight - 120,
textureKey: "blocks4", textureKey: "blocks4",
id: "block4", id: "block4",
}, },
{ {
x: displayW / 2-200, x: displayW / 2,
y: window.innerHeight - 120, y: window.innerHeight - 120,
textureKey: "blocks5", textureKey: "blocks5",
id: "block5", id: "block5",
}, },
{ {
x: displayW / 2-100, x: displayW / 2+100,
y: window.innerHeight - 120, y: window.innerHeight - 120,
textureKey: "blocks6", textureKey: "blocks6",
id: "block6", id: "block6",
}, },
{ {
x: displayW / 2, x: displayW / 2+200,
y: window.innerHeight - 120, y: window.innerHeight - 120,
textureKey: "blocks7", textureKey: "blocks7",
id: "block7", id: "block7",
}, },
{ {
x: displayW / 2+100, x: displayW / 2+300,
y: window.innerHeight - 120, y: window.innerHeight - 120,
textureKey: "blocks8", textureKey: "blocks8",
id: "block8", id: "block8",
}, },
]; ];
// console.log('test blocks',blocks[0]) // console.log('test blocks',blocks[0])
let borderScale; if(isMobile){borderScale = 0.9;} else{borderScale = 1.2;}
const droppedBlocks = []; const droppedBlocks = [];
const targetZoneBorders = []; const targetZoneBorders = [];
targetZones.forEach((targetZone) => { targetZones.forEach((targetZone, index) => {
const targetImage = this.add.image(targetZone.x, targetZone.y, targetZone.name).setAlpha(0); 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.2).setScale(borderScale); const targetBorder = this.add.image(targetZone.x, targetZone.y, "border").setAlpha(0.2).setScale(0.65);
const targetIndex = this.add.text(targetZone.x, targetZone.y, index+1, {fill: `#7c4c23`, font: `30px`}).setOrigin(0.5, 0.5).setAlpha(0.7)
targetZoneBorders.push(targetBorder); targetZoneBorders.push(targetBorder);
targetZone.block = null; targetZone.block = null;
}), }),
@ -485,31 +472,26 @@ import Layout from '../../layouts/Layout.astro';
newBlock.x = dragX; newBlock.x = dragX;
newBlock.y = dragY; newBlock.y = dragY;
}); });
newBlock.on("dragend", () => { newBlock.on("dragend", () => {
newBlock.setScale(1.0).setDepth(-2); newBlock.setScale(1.0);
let droppedOnTargetZone = false; let droppedOnTargetZone = false;
targetZones.forEach((targetZone, targetIndex) => { targetZones.forEach((targetZone, targetIndex) => {
if ( if (
Phaser.Geom.Intersects.RectangleToRectangle( Phaser.Geom .Intersects.RectangleToRectangle(
newBlock.getBounds(), newBlock.getBounds(),
new Phaser.Geom.Rectangle(targetZone.x, targetZone.y, 200, 100) new Phaser.Geom.Rectangle(targetZone.x, targetZone.y, 200, 100)
) )
) { ) {
// newBlock.setPosition(targetZone.x - 50, targetZone.y - 50); //backgroundColor:`#FF0000` if (targetZone.block === null) {
const col = counter % 2; newBlock.setPosition(targetZone.x - 50, targetZone.y - 50);
const row = Math.floor(counter / 2);
newBlock.setPosition(targetZone.x - col * (newBlock.width + 10), targetZone.y - row * (newBlock.height + 10));
newBlock.disableInteractive(); newBlock.disableInteractive();
targetZone.block = newBlock; targetZone.block = newBlock;
droppedBlocks.push(newBlock); droppedBlocks.push(newBlock);
// Adjust isMatch function based on your requirements
if (isMatch(newBlock.texture.key, targetZone.name)) { if (isMatch(newBlock.texture.key, targetZone.name)) {
// Handle match logic if needed
} }
} else {
newBlock.setPosition(block.x, block.y);
}
droppedOnTargetZone = true; droppedOnTargetZone = true;
targetZoneBorders[targetIndex].setVisible(true); targetZoneBorders[targetIndex].setVisible(true);
targetZoneBorders[targetIndex].setAlpha(1); targetZoneBorders[targetIndex].setAlpha(1);
@ -518,17 +500,13 @@ import Layout from '../../layouts/Layout.astro';
}); });
if (!droppedOnTargetZone) { if (!droppedOnTargetZone) {
newBlock.setPosition(newBlock.input.dragStartX, newBlock.input.dragStartY); newBlock.setPosition(block.x, block.y);
} }
if (droppedBlocks.length === targetZones.length)
// Check if all blocks have been dropped on target zones {
if (droppedBlocks.length === targetZones.length) {
displayResult(droppedBlocks); displayResult(droppedBlocks);
} }
}); });
}); });
retryButton = this.add.image(retryButtonWidth, retryButtonHeight, 'retryIcon') retryButton = this.add.image(retryButtonWidth, retryButtonHeight, 'retryIcon')
retryButton.setInteractive().on('pointerdown', () => { retryButton.setInteractive().on('pointerdown', () => {
@ -537,17 +515,19 @@ import Layout from '../../layouts/Layout.astro';
retryButton.setVisible(false); retryButton.setVisible(false);
let score = 0; let score = 0;
let counter = 0; let counter = 0;
const isMatch = (blockName, targetName) => { const isMatch = (blockName, targetName) => {
if(isMatch){ if(isMatch){
counter++; counter++;
// console.log(counter) // console.log(counter)
} }
//resultView scoreTotal
const match = blockMatches.find((m) => m.blockName === blockName && m.targetName === targetName); const match = blockMatches.find((m) => m.blockName === blockName && m.targetName === targetName);
console.log(match) console.log(match)
if(match !== undefined){ if(match){
scoreTotal++; scoreTotal++;
resultView = this.add.text(window.innerWidth / 2 - 100, window.innerHeight / 2 - 100, `Your Score: ${scoreTotal}`, {font: `24px`, fill: `#7c4c23`}).setVisible(false); resultView = this.add.text(window.innerWidth / 2 - 100, window.innerHeight / 2 - 100, `Your Score: ${scoreTotal}`, {font: `24px`, fill: `#7c4c23`}).setVisible(false);
console.log("Score Total", scoreTotal) // console.log(scoreTotal)
} }
if(counter === 8){ if(counter === 8){
// console.log(counter) // console.log(counter)

View File

@ -465,7 +465,7 @@ import Layout from '../../layouts/Layout.astro';
const targetZoneBorders = []; const targetZoneBorders = [];
targetZones.forEach((targetZone) => { targetZones.forEach((targetZone) => {
const targetImage = this.add.image(targetZone.x, targetZone.y, targetZone.name).setAlpha(0); 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).setScale(borderScale); const targetBorder = this.add.image(targetZone.x, targetZone.y, "border").setAlpha(0.2).setScale(borderScale);
targetZoneBorders.push(targetBorder); targetZoneBorders.push(targetBorder);
targetZone.block = null; targetZone.block = null;
}), }),
@ -492,8 +492,8 @@ import Layout from '../../layouts/Layout.astro';
// newBlock.setPosition(targetZone.x - 50, targetZone.y - 50); //backgroundColor:`#FF0000` // newBlock.setPosition(targetZone.x - 50, targetZone.y - 50); //backgroundColor:`#FF0000`
const col = counter % 2; const col = counter % 2;
const row = Math.floor(counter / 2); const row = Math.floor(counter / 2);
// newBlock.setPosition(targetZone.x - col * (newBlock.width + 10), targetZone.y - row * (newBlock.height + 10));
newBlock.setPosition(targetZone.x - 50, targetZone.y - 50); newBlock.setPosition(targetZone.x - 50, targetZone.y -50);
newBlock.disableInteractive(); newBlock.disableInteractive();
targetZone.block = newBlock; targetZone.block = newBlock;
droppedBlocks.push(newBlock); droppedBlocks.push(newBlock);
@ -505,18 +505,19 @@ import Layout from '../../layouts/Layout.astro';
droppedOnTargetZone = true; droppedOnTargetZone = true;
targetZoneBorders[targetIndex].setVisible(true); targetZoneBorders[targetIndex].setVisible(true);
targetZoneBorders[targetIndex].setAlpha(0); targetZoneBorders[targetIndex].setAlpha(1);
return; return;
} }
}); });
if (!droppedOnTargetZone) { if (!droppedOnTargetZone) {
newBlock.setPosition(newBlock.input.dragStartX, newBlock.input.dragStartY); newBlock.setPosition(newBlock.input.dragStartX, newBlock.input.dragStartY);
} };
// Check if all blocks have been dropped on target zones // Check if all blocks have been dropped on target zones
if (droppedBlocks.length === targetZones.length) { if (droppedBlocks.length === targetZones.length) {
displayResult(droppedBlocks); displayResult(droppedBlocks);
newBlock.setVisible(false);
} }
}); });