game salad 07

39
GameSalad (Lec. 07) Table Young-min Kang Tongmyong University

Upload: young-min-kang

Post on 26-May-2015

269 views

Category:

Entertainment & Humor


0 download

TRANSCRIPT

Page 1: Game salad 07

GameSalad (Lec. 07) Table

Young-min Kang Tongmyong University

Page 2: Game salad 07

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

Page 3: Game salad 07

Table creation• Home > Tables

• click “+” to create as many table as you want

• rename them

Page 4: Game salad 07

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

Page 5: Game salad 07

Prepare for table access• create an actor and place it in the scene

Page 6: Game salad 07

Display table items• make the actor display an item in the table

Page 7: Game salad 07

Test it• press preview button and reset the scene

• every time you reset the scene, randomly chosen item will be displayed

Page 8: Game salad 07

Table modification• Change Table Value behavior

Page 9: Game salad 07

Table applicationtable visualization and manipulation

Page 10: Game salad 07

Create a table• Prepare a table to be displayed and manipulated

Page 11: Game salad 07

Actor to show items• create an actor named “item viewer”

• double click and add behaviors as follows

nothing specified here

Page 12: Game salad 07

common behavior• make the actor display table item (common)

• the item is accessed by attributes of the actor (different attributes for each actor instance)

Page 13: Game salad 07

Instancing• place the actor instances in the scene

Page 14: Game salad 07

add behaviors• double-click the actor instances to edit their

behaviors differently

specify different values to instances

Page 15: Game salad 07

Background• add background and test it

Table items are displayed on the actor instances

Page 16: Game salad 07

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

Page 17: Game salad 07

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

Page 18: Game salad 07

Test• press right key to increase all items in the first column

Page 19: Game salad 07

showing images according to table data

• itemViewer actor

Page 20: Game salad 07

Table Management

Page 21: Game salad 07

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

Page 22: Game salad 07

Condition management• when key is pressed

• game.MoveDirection is set

• the loop will not be stopped while game.MoveDirection is not none

Page 23: Game salad 07

Condition management• when key is released

• prevent loop from being performed again when the key is pressed

Page 24: Game salad 07

looping condition

Page 25: Game salad 07

Going back to “ready” state

Page 26: Game salad 07

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”

Page 27: Game salad 07

Nested “for-loop”• Timer inside a timer?

• quite complex and it doesn’t work…

• Index manipulation

Page 28: Game salad 07

Tasks for each item

nested loop

simulation

increase your table item (indRow, indCol) here

Page 29: Game salad 07

Test

Page 30: Game salad 07

Puzzle Implementation Example

Page 31: Game salad 07

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

Page 32: Game salad 07

keyboard input

Page 33: Game salad 07

keyboard release

Page 34: Game salad 07

Right Move

next slide

Page 35: Game salad 07

Timer Loop for Right Move

next slide

Page 36: Game salad 07

Move Items

More cases inside

Page 37: Game salad 07

more case

Page 38: Game salad 07

yet more case

Page 39: Game salad 07

test

items moved and merged after ‘right’ key pressed

39