22
Copyright © 2005 , Richard A. DeVenezia. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Other brand and product names are registered trademarks or Trademarks of their respective companies. Slide imagery Copyright © 2005, SAS Institute Inc. All rights reserved. Tetris: SAS/AF Considerations Richard A. DeVenezia Independent Consultant

Copyright © 2005, Richard A. DeVenezia. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries

Embed Size (px)

Citation preview

Page 1: Copyright © 2005, Richard A. DeVenezia. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries

Copyright © 2005 , Richard A. DeVenezia. All rights reserved.

SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Other brand and product names are registered trademarks or Trademarks of their respective companies.Slide imagery Copyright © 2005, SAS Institute Inc. All rights reserved.

Tetris: SAS/AF Considerations

Richard A. DeVenezia

Independent Consultant

Page 2: Copyright © 2005, Richard A. DeVenezia. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries

Copyright © 2005 , Richard A. DeVenezia. All rights reserved.

Overview

SAS/AF - Dead or Alive ?

• Built to last

Gaming Tradition

Page 3: Copyright © 2005, Richard A. DeVenezia. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries

Copyright © 2005 , Richard A. DeVenezia. All rights reserved.

Tradition

Page 4: Copyright © 2005, Richard A. DeVenezia. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries

Copyright © 2005 , Richard A. DeVenezia. All rights reserved.

Topics to be Covered

Invention

Pieces

Game Play

Movement Keys

Layout

Timing Loop

Page 5: Copyright © 2005, Richard A. DeVenezia. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries

Copyright © 2005 , Richard A. DeVenezia. All rights reserved.

Inventor

Alexey Pajitnov

1985

World wide craze

• More dangerous than a Rubik’s Cube

Still popular

Page 6: Copyright © 2005, Richard A. DeVenezia. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries

Copyright © 2005 , Richard A. DeVenezia. All rights reserved.

Pieces

Arrangement of four squares or blocks

• Seven shapes

Page 7: Copyright © 2005, Richard A. DeVenezia. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries

Copyright © 2005 , Richard A. DeVenezia. All rights reserved.

Drawing a block

DATA Step - DSGI

45 degree lines

• left side, then bottom side

• color varies by linear interpolation

Page 8: Copyright © 2005, Richard A. DeVenezia. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries

Copyright © 2005 , Richard A. DeVenezia. All rights reserved.

Saving a block

goptions device=GIF xpixels=30 ypixels=30;

rc = graph (‘CLEAR’, “E”); ......rc = gset ('COLREP', cindex, acolor);rc = gset ('LINCOLOR', cindex);rc = gdraw ('LINE', 2, x1,x2, y1,y2);... rc = graph (‘UPDATE’); * creates E.GIF;

PIECE.CLASS uses 4 block images

Page 9: Copyright © 2005, Richard A. DeVenezia. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries

Copyright © 2005 , Richard A. DeVenezia. All rights reserved.

.GIF to .IMAGE

sashelp.fsp.imgdatImage Data Model

_readFilePath(file)_writeCatalog(ent)

Images in same catalog as game

Page 10: Copyright © 2005, Richard A. DeVenezia. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries

Copyright © 2005 , Richard A. DeVenezia. All rights reserved.

Game Play

Pieces drop by gravity

Player can move, rotate or drop pieces

• Within the grid

Can’t move?

• Locked piece

• Check for completed rows

Game over?

• Any part of locked piece outside the grid

Page 11: Copyright © 2005, Richard A. DeVenezia. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries

Copyright © 2005 , Richard A. DeVenezia. All rights reserved.

Piece Class

Adapts to piece type A,B,C,...• arrays define geometryprivate num D [ 4, 3, 3 ] / ( initialValue ={ ., ., ., 1, 2, 3, ., ., 4

, ., 1, ., ., 2, ., 4, 3, .

, 4, ., ., 3, 2, 1, ., ., .

, ., 3, 4, ., 2, ., ., 1, .});

One array per piece

• 4 states of rotation

• 4 blocks per piece

• values define block layout

1, 2, 3 4

1,2,3,4,

3, 2, 14,

43,2,1,

Page 12: Copyright © 2005, Richard A. DeVenezia. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries

Copyright © 2005 , Richard A. DeVenezia. All rights reserved.

Piece Class - attributes

Track state

block[4] - image viewersfield - grid (locked blocks)piece - A,B,C...state - rotation state 1..4side - dimension of side (px)gravity - how much to drop (px)timeout - when gravity next occursbaseSleep - event checking intervalx,y,row,col - position of piece on field

Where, when, how, what is going on

Page 13: Copyright © 2005, Richard A. DeVenezia. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries

Copyright © 2005 , Richard A. DeVenezia. All rights reserved.

Piece Class - methods

Attribute driven methods

setcam* - x,y,row,col

Behaviors right - move blocks of pieceleftdowndroprotatelock

Misc blockRowOf(y), topOfRow(n) - support geometry tests

Page 14: Copyright © 2005, Richard A. DeVenezia. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries

Copyright © 2005 , Richard A. DeVenezia. All rights reserved.

HOLD ON, WAIT a SECOND!

Piece.wait()

• Important and essential

• Wait for player to do something

Does what needs doing while the player does nothing

• Drop a little (gravity)

• Play a blip sound

Page 15: Copyright © 2005, Richard A. DeVenezia. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries

Copyright © 2005 , Richard A. DeVenezia. All rights reserved.

I’m Waiting...

EVENT() returns 1

• when the player stops doing nothing

SLEEP()

• yields gracefully, but unresponding

Page 16: Copyright © 2005, Richard A. DeVenezia. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries

Copyright © 2005 , Richard A. DeVenezia. All rights reserved.

The Waiting Game

wait: method return=num

dt = datetime();do until EVENT(); do while (dt<timeout and not EVENT()); SLEEP(10,0.001); * 10 milli seconds; dt = datetime(); end;

if (dt>=timeout) then do; ... move down, play sound, timeout+X ... return 1 if locked, -1 if game over end;end;return 0; * event needs servicing;

Page 17: Copyright © 2005, Richard A. DeVenezia. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries

Copyright © 2005 , Richard A. DeVenezia. All rights reserved.

What caused the event?

A Text Entry Control

• Field where user types in

4 5 6left rotate right 2 drop

Has overrideskbd.keyFeedback = ‘Yes’

kbd. _setInstanceMethod ('_onKey', 'Playmethods', 'onkey');

Page 18: Copyright © 2005, Richard A. DeVenezia. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries

Copyright © 2005 , Richard A. DeVenezia. All rights reserved.

Playmethods.scl:onKey

Dispatches keypress handlers

piece = _self_.piece; select (upcase(_self_.text)); when ('4') piece.left(); when ('5') piece.rotate(); when ('6') piece.right(); when ('2') piece.drop(); when ('D') piece.drop(); when ('Q') field.gameover = 1; otherwise ; end;

AND...

Page 19: Copyright © 2005, Richard A. DeVenezia. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries

Copyright © 2005 , Richard A. DeVenezia. All rights reserved.

AND...

Re-enters the wait method

wait: rc = piece.wait(); if rc > 0 then do; ... is game over ? ... if not, lock the piece and randomly select a new one

_self_.piece = _new_ Piece (field, byte(41x + ranuni(0)*7);

goto wait; end; * code reaches here if EVENT() is pending;

endmethod;

Page 20: Copyright © 2005, Richard A. DeVenezia. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries

Copyright © 2005 , Richard A. DeVenezia. All rights reserved.

BUT...

Pending event (by design) is a keyPress

SAS/AF Executor, event handling

• Invokes onKey of Text Entry

SAS/AFevent supervisor

Text EntryonKey()

piece.wait()for event()

Text Entrykey pressed

ControlLoop

Page 21: Copyright © 2005, Richard A. DeVenezia. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries

Copyright © 2005 , Richard A. DeVenezia. All rights reserved.

Conclusion

SAS/AF is very much alive

• A gem with many little seen facets

Tetris is still fun

Install SAS/Tetris fromwww.devenezia.com/downloads/sas/af

Page 22: Copyright © 2005, Richard A. DeVenezia. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries

Copyright © 2005 , Richard A. DeVenezia. All rights reserved.

About the Speaker

Speaker

Location

Telephone

E-Mail

Richard A. DeVenezia

Independent Consultant

9949 East Steuben Road

Remsen, NY 13438

(315) 831-8802

[email protected]