|
| 1 | + |
1 | 2 | // src/components/screens/GameMap.tsx |
2 | 3 |
|
3 | 4 | // IMPORT LIBRARIES |
4 | 5 | import * as React from 'react'; |
| 6 | + |
| 7 | +import React, { useState } from 'react'; |
| 8 | + |
5 | 9 | import { useNavigate } from 'react-router-dom'; |
6 | | -import Minion from './Minions'; |
| 10 | +import Minion from './Minions'; |
7 | 11 | import "../../styles/codezilla.css"; |
8 | 12 |
|
9 | 13 | const GameMap: React.FC = () => { |
10 | 14 | const navigate = useNavigate(); |
| 15 | + const [completedPaths, setCompletedPaths] = useState<string[]>([]); |
11 | 16 |
|
12 | 17 | const minions = [ |
13 | 18 | { |
14 | 19 | id: '1', |
15 | | - x: 100, |
16 | | - y: 150, |
| 20 | + xPercent: 17, |
| 21 | + yPercent: 25, |
17 | 22 | image: '/minions/nullbyte3a.png', |
18 | 23 | name: 'Nullbyte', |
19 | 24 | questionId: 'q1', |
20 | 25 | }, |
21 | 26 | { |
22 | 27 | id: '2', |
23 | | - x: 250, |
24 | | - y: 200, |
| 28 | + xPercent: 35, |
| 29 | + yPercent: 48, |
25 | 30 | image: '/minions/dbug2a.png', |
26 | 31 | name: 'Dbug', |
27 | 32 | questionId: 'q2', |
28 | 33 | }, |
29 | 34 | { |
30 | 35 | id: '3', |
31 | | - x: 400, |
32 | | - y: 250, |
| 36 | + xPercent: 53, |
| 37 | + yPercent: 65, |
33 | 38 | image: '/minions/typerrorus.png', |
34 | 39 | name: 'Typerrorasaurus', |
35 | 40 | questionId: 'q3', |
36 | 41 | }, |
37 | 42 | { |
38 | 43 | id: '4', |
39 | | - x: 550, |
40 | | - y: 300, |
| 44 | + xPercent: 72, |
| 45 | + yPercent: 50, |
41 | 46 | image: '/minions/monster-left.png', |
42 | 47 | name: 'Pie-Thon', |
43 | 48 | questionId: 'q4', |
44 | 49 | }, |
45 | 50 | { |
46 | 51 | id: '5', |
47 | | - x: 700, |
48 | | - y: 350, |
| 52 | + xPercent: 87, |
| 53 | + yPercent: 27, |
49 | 54 | image: '/minions/codezilla2.png', |
50 | 55 | name: 'Codezilla', |
51 | 56 | questionId: 'q5', |
52 | 57 | }, |
53 | 58 | ]; |
54 | 59 |
|
| 60 | + const nodes = [ |
| 61 | + { id: 'node1', xPercent: 18, yPercent: 28 }, // START LEFT |
| 62 | + { id: 'node2', xPercent: 18, yPercent: 48 }, // SMALL DOWN |
| 63 | + { id: 'node3', xPercent: 35, yPercent: 48 }, // SMALL RIGHT |
| 64 | + { id: 'node4', xPercent: 35, yPercent: 68 }, // SMALL DOWN |
| 65 | + { id: 'node5', xPercent: 53, yPercent: 68 }, // SMALL RIGHT |
| 66 | + { id: 'node6', xPercent: 53, yPercent: 48 }, // SMALL UP |
| 67 | + { id: 'node7', xPercent: 70, yPercent: 48 }, // SMALL RIGHT |
| 68 | + { id: 'node8', xPercent: 70, yPercent: 28 }, // SMALL UP |
| 69 | + { id: 'node9', xPercent: 88, yPercent: 28 }, // CODEZILLA |
| 70 | + ]; |
| 71 | + |
55 | 72 | const goToQuestion = (questionId: string) => { |
56 | 73 | console.log('Go to question', questionId); |
| 74 | + |
| 75 | + const currentIndex = minions.findIndex(m => m.questionId === questionId); |
| 76 | + |
| 77 | + if (currentIndex < nodes.length - 1) { |
| 78 | + const pathId = `${nodes[currentIndex].id}-${nodes[currentIndex + 1].id}`; |
| 79 | + setCompletedPaths(prev => [...prev, pathId]); |
| 80 | + } |
| 81 | + |
57 | 82 | navigate(`/question/${questionId}`); |
58 | 83 | }; |
59 | 84 |
|
60 | 85 | return ( |
61 | 86 | <div className="game-map"> |
62 | | - {/* Background image */} |
63 | | - <img |
64 | | - src="/background/codezilla_bkgd.png" |
65 | | - alt="rainy cityscape" |
66 | | - className="background-image" |
67 | | - /> |
68 | | - |
69 | | - {/* Minions */} |
| 87 | + |
| 88 | + {/* SVG LINES AND CIRCLES 2*/} |
| 89 | + <svg className="map-lines"> |
| 90 | + {/* LINES BETWEEN NODES */} |
| 91 | + {nodes.map((node, index) => { |
| 92 | + const nextNode = nodes[index + 1]; |
| 93 | + if (!nextNode) return null; |
| 94 | + |
| 95 | + return ( |
| 96 | + <line |
| 97 | + key={`line-${node.id}-${nextNode.id}`} |
| 98 | + x1={`${node.xPercent}%`} |
| 99 | + y1={`${node.yPercent}%`} |
| 100 | + x2={`${nextNode.xPercent}%`} |
| 101 | + y2={`${nextNode.yPercent}%`} |
| 102 | + className={`map-line ${completedPaths.includes(`${node.id}-${nextNode.id}`) ? 'completed' : ''}`} |
| 103 | + /> |
| 104 | + ); |
| 105 | + })} |
| 106 | + |
| 107 | + {/* GLOWING OUTER CIRCLE + DARKER INNER CIRCLE */} |
| 108 | + {nodes.map((node, index) => { |
| 109 | + const isCompleted = index < completedPaths.length; |
| 110 | + |
| 111 | + return ( |
| 112 | + <g key={`node-${node.id}`}> |
| 113 | + {/* OUTER GLOW CIRCLE */} |
| 114 | + <circle |
| 115 | + cx={`${node.xPercent}%`} |
| 116 | + cy={`${node.yPercent}%`} |
| 117 | + r="3.5%" |
| 118 | + className={`map-node-outer ${isCompleted ? 'completed' : ''}`} |
| 119 | + /> |
| 120 | + {/* INNER DARKER CIRCLE */} |
| 121 | + <circle |
| 122 | + cx={`${node.xPercent}%`} |
| 123 | + cy={`${node.yPercent}%`} |
| 124 | + r="3%" |
| 125 | + className="map-node-inner" |
| 126 | + /> |
| 127 | + </g> |
| 128 | + ); |
| 129 | + })} |
| 130 | + </svg> |
| 131 | + |
| 132 | + {/* MINIONS */} |
70 | 133 | {minions.map((minion) => ( |
71 | 134 | <Minion |
72 | 135 | key={minion.id} |
73 | 136 | id={minion.id} |
74 | | - x={minion.x} |
75 | | - y={minion.y} |
| 137 | + xPercent={minion.xPercent} |
| 138 | + yPercent={minion.yPercent} |
76 | 139 | image={minion.image} |
77 | 140 | name={minion.name} |
78 | 141 | questionId={minion.questionId} |
|
0 commit comments