ICSOC-8.11.5 Sensing Blocks and Interactive Input (M)

Easy

ICSOC-8.11.5.1 Collision Sensing: Bounding Geometry, Pixel Precision, and Interaction Detection

Collision Sensing: Bounding Geometry, Pixel Precision, and Interaction Detection

Collision detection in Scratch provides the real-time spatial awareness required for interactive physics, boundary enforcement, and object interactions. The primary conditional reporter is the hexagonal boolean block “touching [mouse-pointer / edge / sprite]?”, located in the Sensing category. Unlike basic rectangular bounding-box collision algorithms used in early game engines, Scratch’s virtual machine utilizes exact non-transparent pixel-mask intersection testing. When checking collision against another sprite or the edge of the stage, the engine samples whether any non-transparent pixel (alpha > 0) of the calling sprite physically overlaps a non-transparent pixel of the target entity during the current rendering frame.

The dropdown selector permits dynamic targeting of the current mouse-pointer coordinates, the four rigid stage boundaries (“edge”), or any discrete sprite currently loaded in the project hierarchy (including clones of that sprite). Because collision evaluation occurs synchronously within the Scratch execution loop (running at 30 frames per second), high-speed projectile sprites can occasionally pass through thin target boundaries without triggering collision—a computational phenomenon known as “tunneling.” To prevent tunneling in fast-paced games, developers combine collision sensing with fractional step loops or raymarching algorithms, ensuring pixel-perfect contact registration before the frame completes.

Easy
Which Scratch block category contains the hexagonal boolean block used to detect physical contact between elements?
Option A is correct because collision detection blocks, including , are classified under the light-blue Sensing category in Scratch. Option B is incorrect because Motion blocks govern displacement, coordinates, and rotation. Option C is incorrect because Control blocks manage looping, branching, and script halting. Option D is incorrect because Operators provide mathematical, logical, and string functions.
Medium
How does Scratch’s virtual machine determine whether two sprites are touching when executing the block?
Option A is correct because Scratch utilizes exact pixel-mask collision testing; a collision is only registered when at least one non-transparent pixel (alpha > 0) of the calling sprite physically overlaps a non-transparent pixel of the target sprite. Option B is incorrect because transparent areas within a sprite’s rectangular bounding box do not register collisions. Option C is incorrect because proximity distance is evaluated by the [distance to] block, not the touching block. Option D is incorrect because sprites can collide across various shared overlapping points without having identical center coordinates.
Tricky
In a fast-paced shooting game, a small bullet sprite moves at 50 steps per frame using [move (50) steps]. Occasionally, the bullet passes completely through a thin enemy sprite without triggering the condition. What computational phenomenon causes this bug, and how is it resolved?
Option A is correct because “tunneling” occurs in discrete-time physics when an object moves farther in a single 30 FPS frame tick (50 pixels) than the width of the target obstacle, causing its position before and after the tick to completely bypass the obstacle without overlapping in any single frame. Sub-stepping (e.g., repeating 5 times: move 10 steps and check collision) ensures the sprite tests for intersections along its continuous trajectory. Option B is incorrect because altering stage resolution does not fix discrete sampling tunneling. Option C is incorrect because vector costumes support pixel-perfect collision identically to bitmaps. Option D is incorrect because pen drawings do not have built-in sprite collision sensing.
Medium

ICSOC-8.11.5.2 Color-Based Collision: Hexadecimal Sampling, Multi-Layer Masks, and Hitboxes

Color-Based Collision: Hexadecimal Sampling, Multi-Layer Masks, and Hitboxes

Scratch offers sophisticated chromatic interaction detection through two distinct hexagonal boolean blocks: “touching color [ ]?” and “color [ ] is touching [ ]?”. The single-color block “touching color [ ]?” evaluates whether any non-transparent pixel of the calling sprite makes direct contact with a specific target color present on the stage backdrop, video feed, or any other visible sprite. Scratch represents colors internally using standard 24-bit RGB / HSV values. When a sprite traverses a complex terrain map or maze, this block acts as a versatile sensor for pathfinding, obstacle navigation, and boundary containment.

The more advanced dual-color block, “color [C1] is touching [C2]?”, introduces targeted sub-sprite hitbox sensing. It triggers only when a specific color cluster (C1) belonging to the calling sprite physically touches another designated color (C2) on another sprite or background. This allows programmers to engineer discrete segmented hitboxes—such as a red foot sensor detecting green ground tiles for platformer gravity, or a blue head sensor registering yellow ceiling hazards—without creating separate child sprites. However, color sensing operations are computationally expensive for the rendering engine because each frame requires pixel-by-pixel color buffer scanning, which can induce noticeable frame-rate drops when overused in tightly nested loops.

Easy
What type of value does the Scratch block return when evaluated inside an [if-then] condition?
Option A is correct because blocks with hexagonal, pointed edges in Scratch are boolean reporters that evaluate strictly to either true or false. Option B, C, and D are incorrect because rounded reporter blocks output numbers or text strings, whereas hexagonal sensing blocks represent conditional boolean predicates.
Medium
In a platformer game, a developer uses the block where red is the color of the player sprite’s shoes and green is the terrain. How does this block differ from ?
Option A is correct because checks whether a specific color segment (C1) belonging to the calling sprite is contacting color (C2) in the environment. This enables precise multi-part hitbox mechanics (like ground detection via shoes) without needing separate auxiliary sprites. Option B is incorrect because both colors must be in mutual physical contact. Option C is incorrect because sensing blocks read states and never modify costume colors. Option D is incorrect because sensing blocks perform collision checks, not graphic blending.
Tricky
Why does extensively using multiple blocks inside tight [forever] loops often cause severe frame-rate drops (lag) compared to standard blocks?
Option A is correct because sprite-to-sprite collision can be quickly optimized via coarse bounding checks before checking mask overlaps, whereas color-on-color sensing requires inspecting the exact rendered frame-buffer pixels of both colors across the composite canvas, introducing heavy per-frame pixel scanning overhead. Option B is incorrect because color sensing runs entirely locally in the browser VM. Option C is incorrect because Scratch does not throttle the host CPU. Option D is incorrect because graphics rendering has no relation to audio buffers.
Medium

ICSOC-8.11.5.3 Euclidean Distance Calculations: Pythagorean Proximity and Dynamic Vector Tracking

Euclidean Distance Calculations: Pythagorean Proximity and Dynamic Vector Tracking

Proximity detection and radial tracking in Scratch are governed by the rounded reporter block “distance to [mouse-pointer / sprite]”. Rather than relying on simple bounding boxes, this block computes the continuous, scalar Euclidean distance between the calling sprite’s rotation center (defined by its costume canvas origin) and the target entity’s center point. Under the hood, the Scratch virtual machine evaluates the classical Pythagorean distance formula: sqrt((x2 – x1)^2 + (y2 – y1)^2), where (x1, y1) and (x2, y2) represent the Cartesian coordinates of the respective sprites on the 480×360 stage coordinate grid.

Because the output is a continuous floating-point numeric reporter, it serves as a foundational building block for game mechanics such as artificial intelligence proximity aggro radii, dynamic audio volume modulation, radar sweeping, and gravity simulation. When combined with mathematical comparison operators (such as “< distance to [sprite] < 50"), it enables circular trigger zones that are significantly more realistic than axis-aligned bounding boxes. Note that the distance block measures strictly between costume origin centers; an incorrectly centered costume canvas will distort distance calculations, causing radial triggers to fire offset from visual boundaries.

Easy
What mathematical unit and coordinate reference does the reporter block (distance to [mouse-pointer v]) measure?
Option A is correct because (distance to [ ]) computes the straight-line Euclidean distance in Scratch stage coordinate steps (pixels) between the calling sprite’s costume rotation center and the target entity. Option B is incorrect because distance accounts for both X and Y dimensions simultaneously using Euclidean geometry, not Manhattan grid distance. Option C is incorrect because it measures spatial distance, not latency. Option D is incorrect because angular heading is reported by (point towards) or mathematical trigonometric calculations, not the distance block.
Medium
Sprite A is located at (0, 0) and Sprite B is located at (30, 40). Assuming both costumes have their center crosshairs correctly positioned at their graphical centers, what value will (distance to [Sprite B v]) report when evaluated by Sprite A?
Option A is correct because the Euclidean distance formula is sqrt((x2 – x1)^2 + (y2 – y1)^2). Substituting the coordinates yields sqrt((30 – 0)^2 + (40 – 0)^2) = sqrt(900 + 1600) = sqrt(2500) = 50 steps. Option B is incorrect because 70 is the sum of |x| + |y| (Manhattan distance). Option C is incorrect because 35 is the arithmetic mean of 30 and 40. Option D is incorrect because 1200 is the product of 30 and 40.
Tricky
A programmer notices that when Sprite A visually touches Sprite B, the block (distance to [Sprite B v]) reports a distance of 140 instead of near 0. What is the most likely architectural cause of this discrepancy?
Option A is correct because Scratch calculates distance strictly between the costume canvas rotation centers (the small crosshair in the costume editor). If an artist draws a costume 140 pixels away from the center crosshair, the visual graphic will be offset, causing the distance block to compute distance from the invisible offset origin rather than the visible artwork. Option B is incorrect because Scratch’s stage coordinate space is fixed at 480×360. Option C is incorrect because rotation style affects visual orientation, not Cartesian coordinate positions or distance calculations. Option D is incorrect because distance is a dynamic reporter that updates synchronously on every evaluation.
Tricky

ICSOC-8.11.5.4 Interactive Text Input: Synchronous Prompt Execution and Global Answer Registers

Interactive Text Input: Synchronous Prompt Execution and Global Answer Registers

Two-way textual communication between the user and a Scratch application is handled by the synchronous stack block “ask [text] and wait” paired with the system reporter block “answer”. When the “ask and wait” block executes, it immediately renders an interactive input dialog bar at the bottom of the stage and speech-bubbles the prompt string from the calling sprite (or a standalone prompt bar if executed by the Stage). Critically, this block enforces thread synchronization: it suspends the execution of the calling script stack until the user submits text by pressing the Enter key or clicking the blue checkmark icon.

Upon submission, the user’s raw input string is stored into the built-in system variable reporter “answer”. This “answer” reporter functions as a single global register shared across the entire project; it is not local to the sprite that issued the prompt. Consequently, if multiple sprites issue “ask and wait” prompts concurrently, or if a new prompt executes before the prior answer is processed, the contents of “answer” are overwritten immediately. To safeguard input data in multi-step quizzes or complex data entry systems, developers must immediately transfer the value of “answer” into designated user-defined local or global variables before triggering subsequent prompts.

Easy
When the Scratch block [ask [What is your age?] and wait] is executed, what happens to the script containing this block?
Option A is correct because the “and wait” clause creates a synchronous wait state; the virtual machine halts execution of that specific script thread until the user submits their response into the text prompt bar. Option B is incorrect because the script is strictly blocked from advancing until input is received. Option C is incorrect because the script resumes execution immediately after input submission. Option D is incorrect because no broadcast message is dispatched.
Medium
A program asks two consecutive questions: [ask [Enter your name:] and wait] followed immediately by [ask [Enter your city:] and wait]. What happens to the first input stored in the (answer) reporter if the programmer did not save it into a variable?
Option A is correct because the (answer) reporter is a single global system variable across the entire project; each new submission to an [ask and wait] prompt completely overwrites the previous value of (answer). To retain historical inputs, the programmer must explicitly store (answer) into custom variables (e.g., [set [name v] to (answer)]) before triggering another prompt. Option B, C, and D are incorrect because Scratch does not provide automated queuing, list creation, or per-sprite isolation for the system answer register.
Tricky
If Sprite 1 and Sprite 2 both execute [ask [Question] and wait] simultaneously in concurrent threads under separate [when green flag clicked] blocks, how does the Scratch virtual machine resolve the prompt conflict?
Option A is correct because Scratch maintains an internal modal input prompt queue. Only one input bar can occupy the stage at any given moment. When multiple ask blocks are executed simultaneously across different sprites or threads, the engine displays the first received prompt and keeps the second script paused in a wait state until the first input is submitted. Option B is incorrect because Scratch’s UI framework manages modal conflicts gracefully without crashing. Option C is incorrect because neither prompt is dropped or skipped. Option D is incorrect because prompt strings are never merged.
Tricky

ICSOC-8.11.5.5 Hardware State Polling: Asynchronous Event Listeners vs. Continuous Frame Sampling

Hardware State Polling: Asynchronous Event Listeners vs. Continuous Frame Sampling

Scratch provides robust hardware input interrogation through two contrasting architectural paradigms: event-driven interrupt handling and continuous state polling. In the Sensing category, the boolean blocks “key [space v] pressed?” and “mouse down?”, alongside coordinate reporters “mouse x” and “mouse y”, represent continuous hardware polling functions. Unlike the event hat block “when [key v] pressed”, which relies on operating system key-repeat intervals and suffers from an inherent delay before rapid-fire repeats, polling “key [pressed]?” inside a high-frequency [forever] loop queries the keyboard buffer every virtual machine frame tick (~33 ms). This enables fluid, zero-latency multi-directional movement in arcade and platformer games.

Continuous input polling also facilitates simultaneous multi-key combinations—such as pressing both the Up Arrow and Right Arrow keys to achieve diagonal velocity—which event hat blocks cannot reliably orchestrate. Similarly, the “mouse down?” boolean reports whether the primary mouse button (or touchscreen contact) is currently depressed, while “mouse x” and “mouse y” stream continuous real-time pointer coordinates mapped precisely to the -240 to +240 horizontal and -180 to +180 vertical Cartesian grid. This enables developers to create dynamic custom crosshairs, drag-and-drop physics, and mouse-follow orientation vectors.

Easy
What are the minimum and maximum possible values reported by (mouse x) when the cursor moves across the entire width of the standard Scratch stage?
Option A is correct because Scratch’s stage coordinate system has its origin (0, 0) centered on the screen, spanning 480 pixels horizontally from x = -240 (far left) to x = +240 (far right). Option B is incorrect because Scratch does not use top-left origin coordinates (0 to 480). Option C is incorrect because -180 to +180 represents the vertical Y-axis range. Option D is incorrect because -100 to +100 is an arbitrary range not matching the stage dimensions.
Medium
Why do experienced Scratch game developers prefer using [forever: if then: change x by (5)] instead of the event block [when [right arrow v] key pressed: change x by (5)] for player movement?
Option A is correct because [when key pressed] relies on standard operating system keyboard typematic repeat events, which introduce a mandatory ~250–500 ms pause between the initial press and subsequent repeated signals (causing visible player stutter). In contrast, polling inside a [forever] loop queries the keyboard hardware state continuously on every 30 FPS virtual machine cycle, providing immediate, seamless movement. Option B is incorrect because event blocks trigger indefinitely. Option C is incorrect because all code consumes memory. Option D is incorrect because event blocks listen globally regardless of cursor position.
Tricky
A player wants a sprite to move diagonally when both the Up Arrow and Right Arrow keys are held down simultaneously. Why does polling and in an update loop easily allow this, whereas separate [when [key v] pressed] event hats struggle?
Option A is correct because inside a continuous execution loop, multiple independent booleans can evaluate to true during the exact same frame execution pass, executing both [change y by (5)] and [change x by (5)] to produce clean diagonal vectors. Conversely, OS-level event hat blocks fire asynchronously for single key events and typically prioritize the most recently pressed key, frequently interrupting or dropping the typematic pulse of the other held key. Option B, C, and D are incorrect technical fabrications.
Medium

ICSOC-8.11.5.6 Internal Precision Clocks: Microsecond Accumulators and Deterministic Game Loops

Internal Precision Clocks: Microsecond Accumulators and Deterministic Game Loops

Temporal regulation in Scratch is anchored by the built-in precision clock system accessible via the rounded reporter “timer” and the stack block “reset timer”. The timer functions as an autonomous, high-precision stop-watch managed by the Scratch virtual machine, measuring elapsed real time in decimal seconds with millisecond precision (three decimal places). The timer begins counting upward from zero the exact instant the Scratch project is initialized or loaded, and continues accumulating time independently of script execution, sprite switching, or frame-rate slowdowns.

Executing the “reset timer” stack block sets the internal timer accumulator back to 0.000 seconds instantly across the entire project. Because the timer is an immutable global system resource, resetting it affects any other sprite or script referencing the “timer” reporter. For this reason, professional developers avoid resetting the master timer repeatedly during complex games; instead, they capture baseline timestamps into local variables (e.g., [set [start_time] to (timer)]) and calculate delta intervals (timer – start_time) to manage individual cooldowns, animations, and speedrun records without introducing cross-script temporal interference.

Easy
When does the built-in Scratch (timer) begin counting upward from 0?
Option A is correct because Scratch’s internal timer is an autonomous virtual machine clock that initializes and begins accumulating elapsed time as soon as the project is loaded into runtime memory, continuing to tick independently even before the green flag is clicked. Option B is incorrect because clicking the green flag does not automatically reset the timer unless coded with [reset timer]. Option C is incorrect because the timer runs from project start even if [reset timer] is never called. Option D is incorrect because keyboard events have no native attachment to timer initialization.
Medium
A project contains five different sprites, each with independent attack cooldowns. Why is using [reset timer] to measure an individual sprite’s cooldown considered a catastrophic design flaw?
Option A is correct because there is only one global timer shared across all sprites and the stage in a Scratch project. Calling [reset timer] immediately resets this global clock to 0.000 for every running script, destroying any concurrent timing logic in other sprites. Instead, scripts should capture individual baseline timestamps into separate variables (e.g., [set [my_timer] to (timer)]) and calculate elapsed time differentials. Option B, C, and D are incorrect because [reset timer] is completely safe to call syntactically, works in any sprite, and affects only the internal project timer.
Tricky
A programmer needs to create a 5-second countdown timer for a mini-game that does NOT disrupt other scripts using the global timer, and must remain completely immune to lag or frame-rate drops. Which implementation is mathematically and architecturally optimal?
Option A is correct because capturing a future target timestamp ((timer) + 5) and comparing with <(timer) > (target_time)> relies on real-world elapsed clock time, maintaining millisecond precision without resetting the shared global timer and remaining completely immune to virtual machine lag or frame-rate stutter. Option B and D are flawed because [wait () seconds] and repeat loops accumulate frame quantization delays and loop execution overhead, causing significant drift during lag. Option C is flawed because it resets the global timer for all other scripts, and exact equality <(timer) = (5)> will almost certainly fail because the timer increments continuously in floating-point milliseconds and may never land exactly on 5.000000 on a frame tick.