levels and scripts. script engine a symbol table, which contains all the symbols and information...

73
Levels and Scripts

Upload: annabelle-cole

Post on 12-Jan-2016

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Levels and Scripts

Page 2: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Script Engine• A symbol table, which contains all the symbols and information

about type, scope, etc. • A lexical analyzer, which is a function that converts a character

stream (i.e. the source file) into tokens (i.e. keywords, operators, etc.)

• A parser, which takes the token stream and builds a syntax tree from it.

• A semantic checker, which checks the syntax tree for semantic errors

• An intermediate code generator, which converts the syntax tree into intermediate code

• An optimizer (optional) which optimizes the intermediate code • A code generator, which generates bytecode from the intermediate

code Last but not least, the virtual machine on which the bytecode is to be executed.

Page 3: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

http://www.flipcode.com/archives/Implementing_A_Scripting_Engine-Part_1_Overview.shtml

Page 4: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

4

Layered Avatar Behavior Model and Script

• Overall structure

Task-LevelBehavior Script

Task-LevelBehavior Script

Avatar-Object Interaction ModelAvatar-Object

Interaction Model

High-levelMotion ScriptHigh-level

Motion Script

Primitive Motion Script

Primitive Motion Script

1st Translator(Task-to-High)1st Translator(Task-to-High)

GeometricInformationGeometricInformation

2nd Translator(High-to-Primitive)

2nd Translator(High-to-Primitive) Primitive

Motion ScriptPrimitive

Motion Script

AvatarLow-levelAnimation

Data

AvatarLow-levelAnimation

Data

ObjectLow-levelAnimation

Data

ObjectLow-levelAnimation

Data

AvatarLow-levelAnimation

Data

AvatarLow-levelAnimation

Data

ObjectLow-levelAnimation

Data

ObjectLow-levelAnimation

Data

Application Application

Context MenuInterface(Display)

Context MenuInterface(Display)

UserUser

Domain InterfaceLayer

Motion SequenceLayer

Recording

Translating

Translating

ApplicationLayer

Page 5: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

5

Avatar-Object Interaction Model(1/2)• Basic Object Structure

– Proposed model has multiple objects below the ObjectList element– An object is composed of three elements

• Context : object state, access privilege, controlpoint and domain type

• ExecutableBehaviors : all executable behaviors for user interface menu

• MotionList : motion sequence to complete a behavior

ExecutableBehaviors

Object+

ObjectList

Context MotionList

Basic XML DTD sturcture

Page 6: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Avatar-Object Interaction Model(2/2)

6

Avatar-ObjectInteraction Model

Context

ExecutableBehaviors

MotionList

Domain

AcessGroup

ControlPoint

State

UserBehaviorsSelection

TaskPlanning

Selectable Behaviors

Behaviors List

Motion List

Select a Behavior

Generating Motions

Page 7: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

7

Context Element(1/5)• State Element

– Describes internal object states by pair of variable and value attributes

– Variable has affective motion and current state methods• Affective motion defines post-state value, and corresponding

motion which changes the state• Current state function is defined in XSLT script that processes

state element to make boolean result output of current state value

– Behavior menu and motion sequence are decided according to changes of state variables value

Page 8: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

8

Affective MotionPostState

closed

State FunctionsIsClosed

Variable : DoorState

Event Motion

Result State

V V

V V

V

DoorObject

Interaction StateChanges

• IF – (1) Event Motion = Affective Motion– (2) State Function = TRUE

• THEN– (1) Make up of Variable list which satisfy conditions– (2) Set each variable Value to Post_State– (3) Output boolean result by State Function

Valueclosed

MotionNameclose‘close’

‘True’

Context Element(2/5)

Page 9: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

9

Context Element(3/5)

• ControlPoint Element– Spatial reference points around a object where avatar stands and

interact with it– Depending on the behaviors and object states, a object may have

various points– A point is consisted of position, direction and contact elements– The elements has coarse references to represent spatial location at

high-level• Human readable• Independent from physical geometric object models

– Used for behavior sub-tasking and motion sequencing

Page 10: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

10

Context Element(4/5)– Position

• Relative 5 basic and 4 composed positions for each objects• Standard axis is –z for front on zy-plane

– Direction• Object relative 4 basic and composed directions to determine avatar’s orientation• Rotation axis is y and zero degree for forward direction

– Contact• designate a specific part of the object when the avatar makes contact with the object • The corners of the bounding box of 3D objects and the center point of the surface

Element Reference Values

PositionFront, Behind, Left, Right, Center

Left&Front, Right&Front, Left&Behind, Right&Behind

DirectionBackward, Forward, Left, Right

Left&Forward, Right&forward, Left&Backward, Right&backward

Contact

Front, Behind, Left, Right, Top, Bottom, Center

Left&Front&Center, Left&Front&Top, Left&Front&Bottom,

Right&Front&Center ….

Position Directionx

z

yContact

Page 11: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

11

• Access Group Element– Object behavior can be accessed by several user types– Each user type has different purpose and usage– Each group has different access to behavior interface

• DomainType Element– Not only internal state of object, but also external domain state can

effect behavior interaction.– The same object can behave as a different semantic object

• e.g. A car object in traffic simulation domain and assembly training domain

– DomainType element defines name of domain for checking current domain type.

Context Element(5/5)

Page 12: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

12

Layered Script Language• Overall structure

Task-LevelBehavior Script

Task-LevelBehavior Script

Avatar-Object Interaction ModelAvatar-Object

Interaction Model

High-levelMotion ScriptHigh-level

Motion Script

Primitive Motion Script

Primitive Motion Script

1st Translator(Task-to-High)1st Translator(Task-to-High)

GeometricInformationGeometricInformation

2nd Translator(High-to-Primitive)

2nd Translator(High-to-Primitive) Primitive

Motion ScriptPrimitive

Motion Script

AvatarLow-levelAnimation

Data

AvatarLow-levelAnimation

Data

ObjectLow-levelAnimation

Data

ObjectLow-levelAnimation

Data

AvatarLow-levelAnimation

Data

AvatarLow-levelAnimation

Data

ObjectLow-levelAnimation

Data

ObjectLow-levelAnimation

Data

Application Application

Context MenuInterface(Display)

Context MenuInterface(Display)

UserUser

Domain InterfaceLayer

Motion SequenceLayer

Recording

Translating

Translating

ApplicationLayer

Page 13: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

13

Task-level Behavior Script(1/2)• Task-level Behavior Script

– Presents object and avatar behaviors using XML DTD– Records and saves user action in temporal sequence– Extensible representation for behavior set

• Objects in a domain makeup the usable behavior set• Cf) existing script which has pre-defined behavior DTD

– Independent from rendering environments • Doesn’t present appearance of avatar model, positional information

of virtual objects, so on.

Page 14: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

14

Task-level Behavior Script(2/2)• Definition of Task-level Avatar-Object Behavior Script

– Template-based Avatar-Object Behavior Representation• Domain behavior set is flexibly defined by object instances• Task-level Behavior = (Object, Executable-Behavior, Narration)

Object Behavior NarrationTask-level Behavior

Script =

Door Enter

Text Highlight

Computer Prev.pageScreen Point

Computer Next page

Hello I’m...

DomainObject Pool

User Selection User Text Typing

Page 15: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

15

High-level Motion Script(1/2)

• High-level Motion Script– Bridges between task-level script and primitive motion script

– Independent from both interface domain and application domain

– Parameterized motion support

• Synchronization, speed, target, repeat, intensity, decay, etc

• Abstract values rather than physical

Page 16: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

16

High-level Motion Script(2/2)

• Structure of high-level script DTD

Page 17: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Primitive Motion Script• Primitive motion

– Supported by rendering engine or motion library

– Represented in physical parameter valuesex) Geometric values such as coordinates of avatar and objects, radian value of

avatar direction, etc

– Parameters are transmitted to animation engine to play animation scenario on screen

Page 18: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

18

• Task-level Behavior Script Translator– Translates task-level behavior script into high-level motion script– Consisted of motion sequences to perform task-level behaviors

• Motion planning by task planner and generate the sequences ex) <get target=“box”/>

1. <highLevelMotion name=“walk” …> 2. <highLevelMotion name=“bend_body”…> 3. <highLevelMotion name=“grab”…>

– Uses logical application domain knowledge– According to formal translation model, script of each domains is

converted to a high-level motion script

Script Translators(1/4)

Page 19: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

19

Script Translators(2/4)

• Formal Task Translation Model– Identification of target

• find location of target object(Lo)– Locomotive motion (Ml)

• identification of present avatar location (La)• spatial distance between La and Lo

• generate Lm, if La ≠ Lo

– Manipulative motion (Mm)• generate Mm for Lo

– Verbal information (Vi)• generate verbal speech for avatar behavior if available• Speed and intensity parameters• parameterize Mm and Ml for speed, intensity and duration

Page 20: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

20

Script Translators(3/4)

– Procedure modules

SpatialInformationGenerator

SpatialInformationGenerator

Temporal InformationGenerator

Temporal InformationGenerator

LocomotionGenerator

LocomotionGenerator

IntensityController

IntensityController

Task-levelBehavior

Task-levelScript Translator

Ex) task-level behavior script<task name="bye" target="students">Let's do it next time!</task>

High-levelMotion

Ex) Generated high-level motion<highLevelMotion name="wave" type="gesture"> <spatialParam> <direction type="object"> <objectName>students</objectName> </direction> </spatialParam> <temporalParam> <speed>normal</speed> <repeat>default</repeat> <duration>default</duration> </temporalParam> <degreeParam> <intensity>normal</intensity> <decay>default</decay> <priority>normal</priority> </degreeParam> <verbalParam> <speech>Let's do it next time!</speech> </verbalParam> </highLevelMotion>

Page 21: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

21

• High-level Motion Script Translator– Major module : Object geometric information analyzer

• Calculates location, size, and direction of virtual objects• Current status of avatar position and posture

– Translates abstract parameters of high-level script to physical values

Script Translators(4/4)

Object GeometryAnalyzer

Object GeometryAnalyzer

Virtual Space

Object Geometry

High-level MotionScript High-level

MotionTrasnlator

High-levelMotion

Trasnlator

Primitive MotionScript

<primitiveMotion name="right_hand_point"> <target> <coord x="-200" y="-1" z="95"/> </target> <destination> <from x="-100" y="9" z="0"/> <to x="-100" y="9" z="0"/> </destination> <direction>-143</direction> <speed>15</speed> <intensity>15</intensity> <repeat>1</repeat> <duration>40</duration> <speech>this is …</speech></primitiveMotion>

Page 22: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

22

System Implementation(1/2)

• Creating a scenario script

Page 23: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

23

System Implementation(2/2)• Running a scenario script in different environments

– Different physical properties of virtual objects

– Applying same task-level script to other applications

OpenGL Application 2D Web Application(MSAgent)

Page 24: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Script Compilerprint "Please enter your name > "; input name; if (name == "Jan") { // string comparison name = "my creator"; // string assignmenthappy = "yes"; } print "Thank you, " + name + "!\n" + // string concatenation

"You've just made a simple program very happy!";

"if" {return IF;} "=" {return ASSIGN;} ";" {return END_STMT;} {IDENT} {Identifier (); /* identifier: copy name */

return ID;} {STR} {StringConstant (); /* string constant: copy contents */ return STRING;} "//" {EatComment();} /* comment: skip */ \n {lineno++;} /* newline: count lines */ {WSPACE} {} /* whitespace: (do nothing) */ . {return ERROR_TOKEN;} /* other char: error, illegal token */

Page 25: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Challenge: Design Levels

• 60 levels = 6 groups of 10• Easy to hard within a group• Each group features different devices

60 levels, structured as 6 ramps of 10 puzzles each. Puzzles within a ramp start easy and get harder. Each ramp has a different visual theme and emphasizes a different mix of features, to keep the game from getting too repetitive.

Page 26: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Building Levels

• Tell a Story• Paint a Picture• Create a Mood• Use Math• Exploit features• Lay a Trap

Page 27: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Building Levels: Tell a Story

#17 Run Like Crazy

Some puzzles are structured as a linear sequence of events. For this puzzle started by drawing a board that wraps a long narrow corridor into a small space.

Page 28: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Building Levels: Tell a Story

#17 Run Like Crazy

This puzzle features an autodetonator, shown in red here, which blows up automatically in a preset amount of time unless you touch it to reset it. The basic drama of this puzzle is that you must run to the autodetonator, then push it back a long way so it blows up a bomb.

Page 29: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Building Levels: Tell a Story

#17 Run Like Crazy

I then compounded the puzzle by adding obstacles along the three legs of the journey. Moving spikes that raise and lower out of the game cause you to have to wait a bit before you can get to the autodetonator -- frustrating when you have to get there quickly.

Page 30: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Building Levels: Tell a Story

#17 Run Like Crazy

Next you must push the autodetonator onto a moving platform that travels slowly to the right, then push it off. Again, timing is critical if you are to execute this move before the autodetonator blows up.

Page 31: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Building Levels: Tell a Story

#17 Run Like Crazy

I added one more spike in the right leg of the journey..

Page 32: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Building Levels: Tell a Story

#17 Run Like Crazy

Finally there is the end game. One bombs only blow up themselves, so the ending position must be an autodetonator surrounded by one bombs. Because two of the 1 bombs are against walls they cannot be pushed away from, there is only one possible ending position.

Page 33: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Building Levels: Paint a Picture

#48 Ice Rink. Initial pattern.

Another way to invent a puzzle is to start with a pretty pattern, then try playing it. Here are three opening positions I considered for the puzzle Ice Rink. They look similar, but behave very differently. You cannot stop moving on ice until you hit a wall or reach solid ground.

Page 34: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Building Levels: Paint a Picture

#49 Diamond. Initial pattern.

Here are three patterns I considered for a puzzle called Diamond, which features a patch of ice surrounded by solid ground. After drawing the opening patterns I played them to see if they could be solved. If they were not solvable, I then had to decide how to modify the pattern.

Page 35: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Building Levels: Paint a Picture

#60 The… Final pattern.

For the final puzzle I decided to aim for a pretty final position that would spell the word “End”. This is what I originally hoped for..

Page 36: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Building Levels: Paint a Picture

#60 The… Initial pattern.

The actual final puzzle required many modifications to the boards and pieces to make sure that the puzzle only had one solution. Shown here is the final beginning position.

Page 37: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Building Levels: Paint a Picture#57 Pinball. Overall picture.

One of the features of Charlie Blast is bumpers, which rebound bombs pushed into them. Bumpers reminded me of pinball bumpers, so I built this puzzle to look like a pinball machine, complete with a moving beltway for returning a queue of balls into play.

Page 38: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Building Levels: Create a Mood

#16 Long Haul

Some puzzles create distinct moods. Long haul, for instance, creates a frantic suspenseful mood as you must run further and further away from an autodetonator with a very short fuse in order to reposition bombs that are further and further away.

Page 39: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Building Levels: Create a Mood

#16 Long Haul

It is easy to see that the autodetonator and 1 bomb cannot move, so the solution must be to create a chain of 3 bombs reaching from one end to the other.

Page 40: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Building Levels: Create a Mood

#16 Long Haul

Or is it really that easy? A bit of analysis will show that the previous solution cannot be achieved, so a modified chain like this is necessary.

Page 41: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Building Levels: Use Math

#39 Peninsula

Puzzle designers often mine mathematics for ideas. Shown above is a puzzle based on the mathematical idea of a tour. The goal is to draw a closed path that visits every square once, using all the red lines. The unique solution is shown at right.

Page 42: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Building Levels: Use Math

#39 Peninsula

I decided to make a puzzle for Charlie Blast that used the idea of a tour. Suppose the tiles above are all breakaway tiles, which means you can only step on them once. How would you push all three one bombs off the bottom edge of the square? One solution is shown at right.

Page 43: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Building Levels: Use Math

#39 Peninsula

After a bit of work I came up with this more difficult tour puzzle. The goal is to push all three 1 bombs off the bottom edge of the square by walking a single path. The unique solution requires that you visit every square exactly once.

Page 44: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Building Levels: Use Math

#39 Peninsula

Here’s the final puzzle. The purple electric bombs act like 2 bombs, except if one electric bomb blows up, the other also blows up. Since the electric bomb along the bottom edge cannot be pushed up toward the 1 bombs, the three 1 bombs must be pushed down to surround it.

Page 45: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Building Levels: Exploit Features

#30 Moving Ground

Another strategy is to exploit a feature. Shown above are two states of the same board, built entirely of moving platforms. The tall rectangles move left and right, while the wide rectangles move up and down. The green arrows show how the 2 bomb could be pushed.

Page 46: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Building Levels: Exploit Features

#30 Moving Ground

Here is the final puzzle. The ground at the bottom is stable, while the ground at the top is moving. The goal is clear: build a chain of bombs between the immovable detonator at left and 1 bomb at right. But getting there requires a hair-raising ride around the platforms.

Page 47: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Building Levels: Exploit Features

#30 Moving Ground

This puzzle is easier to analyze if we collapse time and push all the platforms together so all adjacencies are present at the once. The green arrows show all paths that bombs can follow as they move around the platforms. Removing the dead ends, we discover the loop at right.

Page 48: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Building Levels: Lay a Trap

#58 Tadpole

Finally, puzzles can trick you into pursuing the wrong line of reasoning. For the puzzle Tadpole, I started by observing that a puzzle involving a 2 bomb, detonator and six 1 bombs must end with the 2 bomb and detonator surrounded by the 1 bombs.

Page 49: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Building Levels: Lay a Trap

#58 Tadpole

With that analysis in mind, this puzzle appears to be simple: push the autodetonator into the pocket, seal the opening with a 1 bomb, then sit back and watch the fireworks.

Page 50: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Building Levels: Lay a Trap

#58 Tadpole

By adding a couple of spikes I gave the puzzle a new wrinkle.

Page 51: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Building Levels: Lay a Trap

#58 Tadpole

Now you can only push the autodetonator as far as shown above by the green line. You cannot push the autodetonator any further because the spikes prevent you from getting to the square to the right of the final position of the autodetonator.

Page 52: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Building Levels: Lay a Trap

#58 Tadpole

The real solution requires that you rebuild the entire hexagonal pattern of 1 bombs up and to the right one square.

Page 53: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Building Levels: Lay a Trap

#58 Tadpole

To complete the puzzle, I added some blocks and breakaway tiles.. These complications add difficulty to the puzzle, but are not integral to the central theme of the puzzle.

Page 54: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

What is a tile (generally speaking)?• A building block of a game

board• Piece together tiles to create

a world• Why use tiles?

– to conserve memory– graphics reuse– dynamic content

Page 55: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Are there any other background alternatives?

• Large background images– can provide rich, full detail

• Combination of large images and tiling

Page 56: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

A memory comparison

• Ex: Warcraft III map (assume 32-bit color, 4 byte/pixel)– 6,400 pixels x 6,400 pixels– Option 1: Large Background Image (no tiles)

• Memory requirements: a single image– 6,400 x 6,400 x 4 bytes/pixel = 163,840,000 bytes

– Option 2: 100 tile set• each tile: 64 pixels x 64 pixels = 4,096 pixels per tile• map layout: 100 tiles x 100 tiles = 10,000 tiles• Memory requirements

– a tile engine to store the 100 tiles» 100 tiles x 4,096 pixels/tile x 4 bytes/pixel = 1,638,400 bytes

– An array to specify where tiles are to be placed» 10,000 tiles x 1 byte per tile = 10,000 bytes

– Total memory usage = 1,638,300 + 10,000 bytes = 1,648,300 bytes

Page 57: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Why else is graphics reuse important?• Because artist time is expensive• Level designers can layout a map

Page 58: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

How can tiles be dynamic?• Random map generator

– adds to game re-playability– a different game each time you play it

Page 59: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Identify tiles needed

• Terrain– grass, dirt, sand, snow, water, mountains, etc.

• Walls• Roads• Buildings• etc.

• And don’t forget terrain borders?

Page 60: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Layout Level Map

• Generate a map file to describe layout• What format? Many used

– tools like MapMaker just for this purpose• Criteria for format:

– easy to edit by a non-programmer (i.e. level designer)– easy to read in and use by game program

• One option: use a CSV file. What’s CSV?– comma separated value

• How?– denote a tile number or tile string in each cell

• Alternative: create a level design program– a GUI to graphically pick & place tiles

Page 61: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Map Editing Example (3x5 world)

• Map drawn using a 10 piece tile set– T refers to top, B refers to bottom– L refers to left, R refers to left– Ex: TSHORE refers to top shore– Ex: BRSHORE refers to bottom right shore

Page 62: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

What is a tile (practically speaking)?

• An image• Can be created by Paint, Photoshop, etc.• Decide on tile size, which depends on:

– size of map– memory restrictions

• Common to use powers of 2:– 26 = 32– 27 = 64– 28 = 128

• Danger: a map with many different large tiles

Page 63: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

What are Textures?

• Used for tiling games elements– backgrounds, sprites, and 3D models

• DirectX has a class for storing textures:– LPDIRECT3DTEXTURE9

• Provides fast access to image data

• Common file types:– .tga, .dds– image files can be converted by Texture Tool

Page 64: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Image vs. Texture Files

• What’s the advantage to keeping tiles in image files?– artists can tweak images– good during game development stage

• What’s the advantage to converting tiles from image files to texture files (.tga or .dds)?– speed of execution (loading levels)– good after game has been deployed

Page 65: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Color Key• Color to represent transparency

– when a tile or sprite is drawn, pixels with the color key are ignored

– Why?• because those pixels should not be drawn

Specify this precise shade of blue as color key when:

reading file

drawing object

Page 66: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Multi-layering Tiles• Most worlds require

layering. Ex:– place grass– place flowers on grass– place cloud over flowers

• Other common objects:– trees– rocks– treasure

• To edit:– use multiple CSV files, one for

each layer– map file may join & order CSV

files

Page 67: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

How should we manage our layers?

• Different types of layers:– TiledLayer– SparseLayer– IsometricLayer (we’ll see this later this semester)

• We can layer them on top of one another, ex:– TiledLayer first, then SparseLayer

Page 68: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

TiledLayer• Background is wall-to-wall tiles• Images loaded into texture manager• Each image gets an id, layout using ids• Ex:

0,1,2,3,0,0,1,20,1,2,3,0,0,1,20,1,2,3,0,0,1,20,1,2,3,0,0,1,2etc.

Page 69: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Implementing TiledLayer• A 2D grid of Tilesclass TiledLayer: public WorldLayer{protected:

vector<Tile*> *tileLayout;int columns;int rows;int tileWidth;int tileHeight;int layerWidth;int layerHeight;int z;

struct Tile{

int textureID;bool collidable;

};

Page 70: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Rendering via render list

• Again, only render that which is visible

• More on this when we talk about scrolling

Page 71: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

SparseLayer

• Tiles (overlay images) here and there

• Spaces in between

• Tiles of various sizes

Page 72: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

Implementing SparseLayerstruct OverlayImage{

int imageID; // INDEX OF IMAGE IN TEXTURE MANAGERint x; // X LOCATIONint y; // Y LOCATIONint z; // Z LAYERint alpha; // TRANSPARENCYint width; // TEXTURE WIDTH TO USEint height; // TEXTURE HEIGHT TO USE

};

class SparseLayer : public WorldLayer{private:

vector<OverlayImage*> *sparseTiles;…

Page 73: Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is

So how do we render our world?

• Depends on what we are viewing– game world scrolls

• Each frame:– add visible tiles to level render list– render contents or render list like any other

texture