|
63 | 63 | },
|
64 | 64 | {
|
65 | 65 | "cell_type": "code",
|
66 |
| - "execution_count": 2, |
| 66 | + "execution_count": null, |
67 | 67 | "metadata": {
|
68 | 68 | "vscode": {
|
69 | 69 | "languageId": "javascript"
|
70 | 70 | }
|
71 | 71 | },
|
72 |
| - "outputs": [ |
73 |
| - { |
74 |
| - "data": { |
75 |
| - "application/javascript": "\n/* Primitive Data Types\nThese are data types that store a single value.\n*/\n\n// Number: Represents numerical values, such as health and speed\nlet health = 100; // Integer\nlet playerSpeed = 5.75; // Float representing the player's speed\n\nconsole.log(\"Health (Number):\", health, \"Type:\", typeof health);\nconsole.log(\"Player Speed (Number):\", playerSpeed, \"Type:\", typeof playerSpeed);\n\n// String: Represents text, such as the user's name or keypress\nlet userName = \"Hero123\"; // User name\nlet keyPress = 'a'; // Keypress\n\nconsole.log(\"User Name (String):\", userName, \"Type:\", typeof userName);\nconsole.log(\"Key Press (String):\", keyPress, \"Type:\", typeof keyPress);\n\n// Compare single character to its ASCII value\nlet asciiValue = keyPress.charCodeAt(0);\nconsole.log(\"ASCII Value of Key Press:\", asciiValue, \"Type:\", typeof asciiValue);\nconsole.log(\"Is Key Press 'a' (ASCII 97)?\", asciiValue === 97);\n\n// Boolean: Represents true/false values, such as isAlive\nlet isAlive = true;\n\nconsole.log(\"Is Alive (Boolean):\", isAlive, \"Type:\", typeof isAlive);\n\n// Undefined: Represents a variable that has been declared but not yet assigned a value\nlet questReward;\n\nconsole.log(\"Quest Reward (Undefined):\", questReward, \"Type:\", typeof questReward);\n\n// Null: Represents the intentional absence of any object value, such as an empty inventory slot\nlet inventorySlot = null;\n\nconsole.log(\"Inventory Slot (Null):\", inventorySlot, \"Type:\", typeof inventorySlot);\n\n// Symbol: Represents a unique and immutable value, often used as unique identifiers for game objects\nlet uniqueID = Symbol('playerID');\n\nconsole.log(\"Unique ID (Symbol):\", uniqueID, \"Type:\", typeof uniqueID);\n\n// BigInt: Represents very large integers, such as the total time played in milliseconds\nlet totalTimePlayed = 1234567890123456789012345678901234567890n;\n\nconsole.log(\"Total Time Played (BigInt):\", totalTimePlayed, \"Type:\", typeof totalTimePlayed);\n\n/* Reference Data Types\nThese are data types that store references to memory locations.\n*/\n\n// Object: Represents a collection of key-value pairs, such as player attributes or game settings\nlet playerAttributes = {\n name: \"Hero123\",\n health: 100,\n mana: 50\n};\n\nconsole.log(\"Player Attributes (Object):\", playerAttributes, \"Type:\", typeof playerAttributes);\n\n// Array: Represents an ordered collection of values, such as a list of high scores or inventory items\nlet highScores = [1500, 1200, 900, 600, 300];\n\nconsole.log(\"High Scores (Array):\", highScores, \"Type:\", typeof highScores);\n\n// Function: Represents a block of code designed to perform a specific task, such as attacking an enemy or saving the game\nfunction attackEnemy() {\n console.log(\"Enemy attacked!\");\n}\n\nconsole.log(\"Attack Enemy (Function):\", attackEnemy, \"Type:\", typeof attackEnemy);\nattackEnemy();\n", |
76 |
| - "text/plain": [ |
77 |
| - "<IPython.core.display.Javascript object>" |
78 |
| - ] |
79 |
| - }, |
80 |
| - "metadata": {}, |
81 |
| - "output_type": "display_data" |
82 |
| - } |
83 |
| - ], |
| 72 | + "outputs": [], |
84 | 73 | "source": [
|
85 | 74 | "%%js\n",
|
86 | 75 | "\n",
|
|
221 | 210 | },
|
222 | 211 | {
|
223 | 212 | "cell_type": "code",
|
224 |
| - "execution_count": 3, |
| 213 | + "execution_count": null, |
225 | 214 | "metadata": {
|
226 | 215 | "vscode": {
|
227 | 216 | "languageId": "html"
|
228 | 217 | }
|
229 | 218 | },
|
230 |
| - "outputs": [ |
231 |
| - { |
232 |
| - "data": { |
233 |
| - "text/html": [ |
234 |
| - "\n", |
235 |
| - "<p>This example uses data types, operators, and functions to scale a block based on a user-defined width.</p>\n", |
236 |
| - "\n", |
237 |
| - "<!-- Input definitions -->\n", |
238 |
| - "<div>\n", |
239 |
| - " <label for=\"width\">Enter Width (1280, 1920, 2560, 3840):</label>\n", |
240 |
| - " <input type=\"number\" id=\"width\" name=\"width\" min=\"1280\" max=\"3840\" step=\"640\" value=\"1280\">\n", |
241 |
| - " <button onclick=\"submitScale()\">Submit</button>\n", |
242 |
| - "</div>\n", |
243 |
| - "\n", |
244 |
| - "<!-- Document Object Model (DOM) output locations -->\n", |
245 |
| - "<div id=\"output\"></div>\n", |
246 |
| - "<div id=\"error\"></div>\n", |
247 |
| - "\n", |
248 |
| - "<!-- Block display -->\n", |
249 |
| - "<div id=\"block\" style=\"width: 64px; height: 36px; background-color: red;\"></div>\n", |
250 |
| - "\n", |
251 |
| - "<script>\n", |
252 |
| - "\n", |
253 |
| - " // Function to validate and output the scale value\n", |
254 |
| - " function submitScale() {\n", |
255 |
| - " const BLOCK_SCALE_FACTOR = 20;\n", |
256 |
| - " const ASPECT_RATIO = 9 / 16;\n", |
257 |
| - " let block = document.getElementById('block');\n", |
258 |
| - " let width = parseInt(document.getElementById('width').value);\n", |
259 |
| - " \n", |
260 |
| - " // Restrict sizes to common HD resolutions\n", |
261 |
| - " if (width === 1280 || width === 1920 || width === 2560 || width === 3840) {\n", |
262 |
| - " // Calculate height based on 16:9 aspect ratio\n", |
263 |
| - " let height = Math.round(width * ASPECT_RATIO);\n", |
264 |
| - " \n", |
265 |
| - " // Calculate block size as 1/20th of the scale dimensions\n", |
266 |
| - " let blockSize = Math.min(width, height) / BLOCK_SCALE_FACTOR;\n", |
267 |
| - " \n", |
268 |
| - " // Set/clear error messages when the value is valid\n", |
269 |
| - " document.getElementById('error').innerHTML = \"\";\n", |
270 |
| - " // Output the scale value to the console\n", |
271 |
| - " document.getElementById('output').innerHTML = \"Scale set to: \" + width + \" x \" + height + \" (Block size: \" + blockSize + \"px)\";\n", |
272 |
| - " \n", |
273 |
| - " // Adjust the size of the block\n", |
274 |
| - " block.style.width = blockSize + \"px\";\n", |
275 |
| - " block.style.height = blockSize * ASPECT_RATIO + \"px\";\n", |
276 |
| - " } else {\n", |
277 |
| - " // Set/clear output messages when there is an error\n", |
278 |
| - " document.getElementById('output').innerHTML = \"\";\n", |
279 |
| - " // Output an error message to the console\n", |
280 |
| - " // Output an error message to the HTML page\n", |
281 |
| - " document.getElementById('error').innerHTML = \"Invalid HD resolution: \" + width;\n", |
282 |
| - "\n", |
283 |
| - " // Clear the block size\n", |
284 |
| - " block.style.width = \"0px\";\n", |
285 |
| - " block.style.height = \"0px\";\n", |
286 |
| - " }\n", |
287 |
| - " console.error(\"HD resolution:\", block.style.width, \"x\", block.style.height);\n", |
288 |
| - " }\n", |
289 |
| - "</script>\n" |
290 |
| - ], |
291 |
| - "text/plain": [ |
292 |
| - "<IPython.core.display.HTML object>" |
293 |
| - ] |
294 |
| - }, |
295 |
| - "metadata": {}, |
296 |
| - "output_type": "display_data" |
297 |
| - } |
298 |
| - ], |
| 219 | + "outputs": [], |
299 | 220 | "source": [
|
300 | 221 | "%%html \n",
|
301 | 222 | "\n",
|
|
319 | 240 | "\n",
|
320 | 241 | " // Function to validate and output the scale value\n",
|
321 | 242 | " function submitScale() {\n",
|
322 |
| - " const BLOCK_SCALE_FACTOR = 20;\n", |
| 243 | + " const BLOCK_SCALE_DIVISOR = 20;\n", |
323 | 244 | " const ASPECT_RATIO = 9 / 16;\n",
|
324 | 245 | " let block = document.getElementById('block');\n",
|
325 | 246 | " let width = parseInt(document.getElementById('width').value);\n",
|
|
330 | 251 | " let height = Math.round(width * ASPECT_RATIO);\n",
|
331 | 252 | " \n",
|
332 | 253 | " // Calculate block size as 1/20th of the scale dimensions\n",
|
333 |
| - " let blockSize = Math.min(width, height) / BLOCK_SCALE_FACTOR;\n", |
| 254 | + " let blockSize = Math.min(width, height) / BLOCK_SCALE_DIVISOR;\n", |
334 | 255 | " \n",
|
335 | 256 | " // Set/clear error messages when the value is valid\n",
|
336 | 257 | " document.getElementById('error').innerHTML = \"\";\n",
|
|
365 | 286 | "Make a code cell that changes block into a square, versus HD resolution"
|
366 | 287 | ]
|
367 | 288 | },
|
| 289 | + { |
| 290 | + "cell_type": "markdown", |
| 291 | + "metadata": {}, |
| 292 | + "source": [ |
| 293 | + "## Placing a Block\n", |
| 294 | + "\n", |
| 295 | + "Often in gaming you will want to position on element in relationship to another." |
| 296 | + ] |
| 297 | + }, |
368 | 298 | {
|
369 | 299 | "cell_type": "code",
|
370 |
| - "execution_count": 4, |
| 300 | + "execution_count": 1, |
371 | 301 | "metadata": {
|
372 | 302 | "vscode": {
|
373 | 303 | "languageId": "html"
|
|
382 | 312 | "\n",
|
383 | 313 | "<!-- Input definitions -->\n",
|
384 | 314 | "<div>\n",
|
385 |
| - " <label for=\"width\">Enter Width (1280, 1920, 2560, 3840):</label>\n", |
386 |
| - " <input type=\"number\" id=\"width\" name=\"width\" min=\"1280\" max=\"3840\" step=\"640\" value=\"1280\">\n", |
| 315 | + " <label for=\"widthCanvas\">Enter Width (1280, 1920, 2560, 3840):</label>\n", |
| 316 | + " <input type=\"number\" id=\"widthCanvas\" name=\"widthCanvas\" min=\"1280\" max=\"3840\" step=\"640\" value=\"1280\">\n", |
387 | 317 | " <button onclick=\"submitScaleImg()\">Submit</button>\n",
|
388 | 318 | "</div>\n",
|
389 | 319 | "\n",
|
|
397 | 327 | "<script>\n",
|
398 | 328 | " // Function to validate and output the scale value\n",
|
399 | 329 | " function submitScaleImg() {\n",
|
| 330 | + " const BLOCK_SCALE_DIVISOR = 20;\n", |
| 331 | + " const ASPECT_RATIO = 9 / 16;\n", |
400 | 332 | " const SCALE_DOWN_FACTOR = 0.5;\n",
|
401 | 333 | " let canvas = document.getElementById('canvas');\n",
|
402 | 334 | " let c = canvas.getContext('2d');\n",
|
403 |
| - " let width = parseInt(document.getElementById('width').value);\n", |
| 335 | + " let width = parseInt(document.getElementById('widthCanvas').value);\n", |
404 | 336 | " \n",
|
405 | 337 | " // Restrict sizes to common HD resolutions\n",
|
406 | 338 | " if (width === 1280 || width === 1920 || width === 2560 || width === 3840) {\n",
|
407 | 339 | " // Calculate height based on 16:9 aspect ratio\n",
|
408 | 340 | " let height = Math.round(width * ASPECT_RATIO);\n",
|
409 | 341 | " \n",
|
410 | 342 | " // Set the canvas dimensions\n",
|
411 |
| - " canvas.width = width;\n", |
412 |
| - " canvas.height = height;\n", |
| 343 | + " canvas.width = width * SCALE_DOWN_FACTOR;\n", |
| 344 | + " canvas.height = height * SCALE_DOWN_FACTOR;\n", |
413 | 345 | " \n",
|
414 | 346 | " // Calculate block size as 1/20th of the scale dimensions and scale down by 50%\n",
|
415 |
| - " let blockSize = Math.min(width, height) / BLOCK_SCALE_FACTOR * SCALE_DOWN_FACTOR;\n", |
| 347 | + " let blockSize = Math.min(width, height) / BLOCK_SCALE_DIVISOR;\n", |
416 | 348 | " \n",
|
417 | 349 | " // Set/clear error messages when the value is valid\n",
|
418 | 350 | " document.getElementById('errorMsg').innerHTML = \"\";\n",
|
|
461 | 393 | "\n",
|
462 | 394 | "<!-- Input definitions -->\n",
|
463 | 395 | "<div>\n",
|
464 |
| - " <label for=\"width\">Enter Width (1280, 1920, 2560, 3840):</label>\n", |
465 |
| - " <input type=\"number\" id=\"width\" name=\"width\" min=\"1280\" max=\"3840\" step=\"640\" value=\"1280\">\n", |
| 396 | + " <label for=\"widthCanvas\">Enter Width (1280, 1920, 2560, 3840):</label>\n", |
| 397 | + " <input type=\"number\" id=\"widthCanvas\" name=\"widthCanvas\" min=\"1280\" max=\"3840\" step=\"640\" value=\"1280\">\n", |
466 | 398 | " <button onclick=\"submitScaleImg()\">Submit</button>\n",
|
467 | 399 | "</div>\n",
|
468 | 400 | "\n",
|
|
476 | 408 | "<script>\n",
|
477 | 409 | " // Function to validate and output the scale value\n",
|
478 | 410 | " function submitScaleImg() {\n",
|
| 411 | + " const BLOCK_SCALE_DIVISOR = 20;\n", |
| 412 | + " const ASPECT_RATIO = 9 / 16;\n", |
479 | 413 | " const SCALE_DOWN_FACTOR = 0.5;\n",
|
480 | 414 | " let canvas = document.getElementById('canvas');\n",
|
481 | 415 | " let c = canvas.getContext('2d');\n",
|
482 |
| - " let width = parseInt(document.getElementById('width').value);\n", |
| 416 | + " let width = parseInt(document.getElementById('widthCanvas').value);\n", |
483 | 417 | " \n",
|
484 | 418 | " // Restrict sizes to common HD resolutions\n",
|
485 | 419 | " if (width === 1280 || width === 1920 || width === 2560 || width === 3840) {\n",
|
486 | 420 | " // Calculate height based on 16:9 aspect ratio\n",
|
487 | 421 | " let height = Math.round(width * ASPECT_RATIO);\n",
|
488 | 422 | " \n",
|
489 | 423 | " // Set the canvas dimensions\n",
|
490 |
| - " canvas.width = width;\n", |
491 |
| - " canvas.height = height;\n", |
| 424 | + " canvas.width = width * SCALE_DOWN_FACTOR;\n", |
| 425 | + " canvas.height = height * SCALE_DOWN_FACTOR;\n", |
492 | 426 | " \n",
|
493 | 427 | " // Calculate block size as 1/20th of the scale dimensions and scale down by 50%\n",
|
494 |
| - " let blockSize = Math.min(width, height) / BLOCK_SCALE_FACTOR * SCALE_DOWN_FACTOR;\n", |
| 428 | + " let blockSize = Math.min(width, height) / BLOCK_SCALE_DIVISOR;\n", |
495 | 429 | " \n",
|
496 | 430 | " // Set/clear error messages when the value is valid\n",
|
497 | 431 | " document.getElementById('errorMsg').innerHTML = \"\";\n",
|
|
525 | 459 | " }\n",
|
526 | 460 | "</script>"
|
527 | 461 | ]
|
| 462 | + }, |
| 463 | + { |
| 464 | + "cell_type": "markdown", |
| 465 | + "metadata": {}, |
| 466 | + "source": [ |
| 467 | + "### Popcorn Hack 3\n", |
| 468 | + "\n", |
| 469 | + "Try to place a square in every corner.\n" |
| 470 | + ] |
| 471 | + }, |
| 472 | + { |
| 473 | + "cell_type": "markdown", |
| 474 | + "metadata": {}, |
| 475 | + "source": [ |
| 476 | + "### Turtle / Fish HW\n", |
| 477 | + "\n", |
| 478 | + "Make the Turtle and Fish start on screen in different locations (ie Fish Center/Left, Turtle Center/Right)" |
| 479 | + ] |
528 | 480 | }
|
529 | 481 | ],
|
530 | 482 | "metadata": {
|
|
0 commit comments