game salad 07
TRANSCRIPT
GameSalad (Lec. 07) Table
Young-min Kang Tongmyong University
Basics• table
• matrix shaped 2D data
• can be accessed with row and column indices
• all items in a column should be of an identical type
• you can create as many tables as you want
• tables are treated as attributes of game
Table creation• Home > Tables
• click “+” to create as many table as you want
• rename them
Edit your tables• determine the # of rows and columns
• determine the type of each column
• you can easily increase the number of columns or rows
• you can rearrange the order of the columns and rows
Prepare for table access• create an actor and place it in the scene
Display table items• make the actor display an item in the table
Test it• press preview button and reset the scene
• every time you reset the scene, randomly chosen item will be displayed
Table modification• Change Table Value behavior
Table applicationtable visualization and manipulation
Create a table• Prepare a table to be displayed and manipulated
Actor to show items• create an actor named “item viewer”
• double click and add behaviors as follows
nothing specified here
common behavior• make the actor display table item (common)
• the item is accessed by attributes of the actor (different attributes for each actor instance)
Instancing• place the actor instances in the scene
add behaviors• double-click the actor instances to edit their
behaviors differently
specify different values to instances
Background• add background and test it
Table items are displayed on the actor instances
Table manipulation• Table items should be accessed with structured
looping method
• loop behavior
• only in ‘pro’ version which costs $299!
• alternative
• inventing your loop with available behaviors
Single for loop• for(int i=1;i<=4;i++) {
• TB_State[i][1] = TB_State[i][1]+1;
• }
!• add attributes
• idxI
• idxJ
• use those indices for our for loop
• here, a single for loop is presented
• idxI is used
Test• press right key to increase all items in the first column
showing images according to table data
• itemViewer actor
Table Management
Problem of Timers• Rule+Timer for looping
• when the condition for the rule is no more valid, the timer is immediately released
• loop can be stopped with unfinished tasks left
• Clever condition manipulation is needed
add an attribute MoveDirection (text)
to Game !
add an attribute bKeyPressed (boolean) to background actor
Condition management• when key is pressed
• game.MoveDirection is set
• the loop will not be stopped while game.MoveDirection is not none
Condition management• when key is released
• prevent loop from being performed again when the key is pressed
looping condition
Going back to “ready” state
Images for table items• If you want display items with matching images
• import images to your library
• add an attribute “TB data” to the actor “itemViewer”
Nested “for-loop”• Timer inside a timer?
• quite complex and it doesn’t work…
• Index manipulation
Tasks for each item
nested loop
simulation
increase your table item (indRow, indCol) here
Test
Puzzle Implementation Example
2048 style dinoPuzzle
Right Move [ ][ ][ c ][ t ]!!initialize t <- 4 , c <- 3!!while c > 0!!case ( v(c) = 0 ) {!! decrease c! }!case ( v(t) = 0 and v(c) != 0 ) {!! v(t) <- v(c)! ! v(c) <- 0! ! decrease c! }!case ( v(t) != 0 and v(c) = v(t) ) {!! promote v(t)! ! v(c) <- 0! ! decrease t! ! decrease c! }!case ( v(t) != 0 and v(c) != v(t) ) {!! decrease t! ! decrease c! }
Left Move [ t ][ c ][ ][ ]!!initialize t <- 1 , c <- 2!!while c < 5!!case ( v(c) = 0 ) {!! increase c! }!case ( v(t) = 0 and v(c) != 0 ) {!! v(t) <- v(c)! ! v(c) <- 0! ! increase c! }!case ( v(t) != 0 and v(c) = v(t) ) {!! promote v(t)! ! v(c) <- 0! ! increase t! ! increase c! }!case ( v(t) != 0 and v(c) != v(t) ) {!! increase t! ! increase c! }!
Up Move !!initialize t <- 1 , r <- 2!!while r < 5!!case ( v(r) = 0 ) {!! increase r! }!case ( v(t) = 0 and v(r) != 0 ) {!! v(t) <- v(r)! ! v(r) <- 0! ! increase r! }!case ( v(t) != 0 and v(r) = v(t) ) {!! promote v(t)! ! v(r) <- 0! ! increase t! ! increase r! }!case ( v(t) != 0 and v(r) != v(t) ) {!! increase t! ! increase r! }!
Down Move !!initialize t <- 4 , r <- 3!!while r > 0 !!case ( v(r) = 0 ) {!! decrease r! }!case ( v(t) = 0 and v(r) != 0 ) {!! v(t) <- v(r)! ! v(r) <- 0! ! decrease r! }!case ( v(t) != 0 and v(r) = v(t) ) {!! promote v(t)! ! v(r) <- 0! ! decrease t! ! decrease r! }!case ( v(t) != 0 and v(r) != v(t) ) {!! decrease t! ! decrease r! }
if you program it, it would look like this
keyboard input
keyboard release
Right Move
next slide
Timer Loop for Right Move
next slide
Move Items
More cases inside
more case
yet more case
test
items moved and merged after ‘right’ key pressed
39