Scratch Flashcards
Games vs. Robots
Game creates world vs world creates game
Composed of sprites vs robot is sprite
Position and velocity are known vs sensed
Collisions are detected vs avoided
Goal to make world complex vs simplify the world
Components of a game (3)
Stage, Sprites, Code
Describe the Movie Metaphor
In a movie screen is updated 24 times a second, in a game stage is updated 30 times a second.
update is called a frame
Game is an interactive movie
The event-driven paradigm
game code responds to events
external events
player movement (key press, mouse click, hover)
internal events (5)
start of game, frame, message, timer, sprite cloned
event handler
game code that handles all aspects (behaviours) of the game
the main loop
event»handle»update
scratch script
responds to an event
- sequence of blocks starting on a When block
- contains: motion, control, sensing, operator, data, event
the frame event
- when green flag clicked
- forever loop
- wait 0.03 seconds
- broadcast FRAME and wait
Sprites
- properties (costumes, variables, scripts)
- can be characters, obstacles, projectiles, etc. etc.
naming sprites
- name is for what is is
- sprites can have the same name
- sprites can only be referred to by name
costumes
- sprite can change its looks by changing costume
- every sprite has at least one costume
- is a graphical representation of a sprite
- each costume has a name
stage
- special sprite on which all other sprites are displayed
- has backdrops rather than costumes
- stage will always appear behind all other sprites
intrinsic properites
- all sprites have properties
- is a characteristic of a sprite (position, direction, costume, size, visibility, color etc)
- sprites are manipulated by modifying properties
extrinsic properties
- lives or health, difficulty of destroying an obstacle,
- often represented by numbers
- use variables
variables
- location in the program, or sprite that stores a value
- referenced by name
- accessed/mutated (read and written)
- scripts associated with a sprite can access and mutate it
cloning sprites
- multiple copies of a sprite
- EVERYTHING is copied
- manipulation of the clone does not affect the original
- notified when they are created (when i start as a clone)
- can be deleted (should be)
sprite communication
- communicate by broadcasting messages
- messages can not be directed to a specific sprite unless only that sprite has an event handler for that particular message
autonomous motion
- set sprites velocity (steps per frame)
- ## set direction
hitting a wall
what to do?
- fall off edge of stage
- bounce off edge
fall off stage
- hide the sprite when the x or y position goes out of bounds
- OR detect edge “if touching edge
bouncing
- when sprite is touching edge, reverse velocity
- change direction 0-direction for vertical wall and 180-direction for horizontal wall
- if on edge bounce
collision detection
- detects if two of more sprites are touching in some way
- cheap and fast
- expensive and slow
- fast but specialized
- complicated and fast
bounding box
- smallest orthogonal rectangle that can fit the sprite
fast and cheap
- if two bounding boxes overlap, the sprites collide
Pros: fast and cheap
Cons: can’t determine which direction collision came from
-false positives
expensive and slow
- point based collision
- pros: more accurate than bounding box
- cons: sprites compromise many points so many checks are required