Skip to content

Commit

Permalink
handle bonus to go to next step
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheelax committed Nov 19, 2024
1 parent 6d09d8e commit b47cbd7
Showing 1 changed file with 17 additions and 39 deletions.
56 changes: 17 additions & 39 deletions client/src/ui/components/Tutorial/TutorialGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,7 @@ const TutorialGrid: React.FC<GridProps> = forwardRef(
setGameState(GameState.GRAVITY);
}, [dragging, initialX]);

const handleMouseDown = (e: React.MouseEvent, block: Block) => {
e.preventDefault();
e.stopPropagation();

const handleBonusApplication = (block: Block) => {
setBlockBonus(block);
if (bonus === BonusType.Wave) {
setBlocks(removeBlocksSameRow(block, blocks));
Expand All @@ -280,18 +277,30 @@ const TutorialGrid: React.FC<GridProps> = forwardRef(
);
});
} else if (bonus === BonusType.Hammer) {
console.log("Hammer bonus", { block });
setBlocks(removeBlockId(block, blocks));
if (gridPosition === null) return;
handleTriggerLocalExplosion(
gridPosition.left + block.x * gridSize + (block.width * gridSize) / 2,
gridPosition.top + block.y * gridSize,
);
if (tutorialStep === 2) onUpdate(true);
}

// Apply gravity immediately after bonus
applyGravity();
setIsMoving(true);
setGameState(GameState.GRAVITY_BONUS);
if (bonus === BonusType.Hammer && tutorialStep === 2) onUpdate(true);
if (bonus === BonusType.Wave && tutorialStep === 3) onUpdate(true);
if (bonus === BonusType.Totem && tutorialStep === 4) onUpdate(true);
};

const handleMouseDown = (e: React.MouseEvent, block: Block) => {
e.preventDefault();
e.stopPropagation();

if (bonus !== BonusType.None) {
setIsMoving(true);
setGameState(GameState.GRAVITY_BONUS);
handleBonusApplication(block);
return;
}
handleDragStart(e.clientX, block);
Expand All @@ -308,41 +317,10 @@ const TutorialGrid: React.FC<GridProps> = forwardRef(
e.preventDefault();
e.stopPropagation();

setBlockBonus(block);
if (bonus === BonusType.Wave) {
setBlocks(removeBlocksSameRow(block, blocks));
getBlocksSameRow(block.y, blocks).forEach((b) => {
if (gridPosition === null) return;
handleTriggerLocalExplosion(
gridPosition.left + b.x * gridSize + (b.width * gridSize) / 2,
gridPosition.top + b.y * gridSize,
);
});
} else if (bonus === BonusType.Totem) {
setBlocks(removeBlocksSameWidth(block, blocks));
getBlocksSameWidth(block, blocks).forEach((b) => {
if (gridPosition === null) return;
handleTriggerLocalExplosion(
gridPosition.left + b.x * gridSize + (b.width * gridSize) / 2,
gridPosition.top + b.y * gridSize,
);
});
} else if (bonus === BonusType.Hammer) {
setBlocks(removeBlockId(block, blocks));
if (gridPosition === null) return;
handleTriggerLocalExplosion(
gridPosition.left + block.x * gridSize + (block.width * gridSize) / 2,
gridPosition.top + block.y * gridSize,
);
if (tutorialStep === 2) onUpdate(true);
}

if (bonus !== BonusType.None) {
setIsMoving(true);
setGameState(GameState.GRAVITY_BONUS);
handleBonusApplication(block);
return;
}

const touch = e.touches[0];
handleDragStart(touch.clientX, block);
};
Expand Down

0 comments on commit b47cbd7

Please sign in to comment.