Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

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. ® 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

2 Copyright © 2005, Richard A. DeVenezia. All rights reserved. Overview n SAS/AF - Dead or Alive ? Built to last n Gaming Tradition

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

4 Copyright © 2005, Richard A. DeVenezia. All rights reserved. Topics to be Covered n Invention n Pieces n Game Play n Movement Keys n Layout n Timing Loop

5 Copyright © 2005, Richard A. DeVenezia. All rights reserved. Inventor n Alexey Pajitnov n 1985 n World wide craze More dangerous than a Rubik’s Cube n Still popular

6 Copyright © 2005, Richard A. DeVenezia. All rights reserved. Pieces n Arrangement of four squares or blocks Seven shapes

7 Copyright © 2005, Richard A. DeVenezia. All rights reserved. Drawing a block n DATA Step - DSGI n 45 degree lines left side, then bottom side color varies by linear interpolation

8 Copyright © 2005, Richard A. DeVenezia. All rights reserved. Saving a block n goptions device=GIF xpixels=30 ypixels=30; n 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; n PIECE.CLASS uses 4 block images

9 Copyright © 2005, Richard A. DeVenezia. All rights reserved..GIF to.IMAGE sashelp.fsp.imgdat Image Data Model _readFilePath(file) _writeCatalog(ent) n Images in same catalog as game

10 Copyright © 2005, Richard A. DeVenezia. All rights reserved. Game Play n Pieces drop by gravity n Player can move, rotate or drop pieces Within the grid n Can’t move? Locked piece Check for completed rows n Game over? Any part of locked piece outside the grid

11 Copyright © 2005, Richard A. DeVenezia. All rights reserved. Piece Class n Adapts to piece type A,B,C,... arrays define geometry private num D [ 4, 3, 3 ] / ( initialValue = {.,.,., 1, 2, 3,.,., 4,., 1,.,., 2,., 4, 3,., 4,.,., 3, 2, 1,.,.,.,., 3, 4,., 2,.,., 1,. }); n 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, 1 4, 4 3, 2, 1,

12 Copyright © 2005, Richard A. DeVenezia. All rights reserved. Piece Class - attributes Track state block[4]- image viewers field- grid (locked blocks) piece- A,B,C... state- rotation state 1..4 side- dimension of side (px) gravity- how much to drop (px) timeout- when gravity next occurs baseSleep - event checking interval x,y,row,col - position of piece on field n Where, when, how, what is going on

13 Copyright © 2005, Richard A. DeVenezia. All rights reserved. Piece Class - methods Attribute driven methods setcam* - x,y,row,col Behaviors right - move blocks of piece left down drop rotate lock Misc blockRowOf(y), topOfRow(n) - support geometry tests

14 Copyright © 2005, Richard A. DeVenezia. All rights reserved. HOLD ON, WAIT a SECOND! n Piece.wait() Important and essential Wait for player to do something n Does what needs doing while the player does nothing Drop a little (gravity) Play a blip sound

15 Copyright © 2005, Richard A. DeVenezia. All rights reserved. I’m Waiting... n EVENT() returns 1 when the player stops doing nothing n SLEEP() yields gracefully, but unresponding

16 Copyright © 2005, Richard A. DeVenezia. All rights reserved. The Waiting Game wait: method return=num dt = datetime(); do until EVENT(); do while (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;

17 Copyright © 2005, Richard A. DeVenezia. All rights reserved. What caused the event? n A Text Entry Control Field where user types in 4 5 6 left rotate right 2 drop n Has overrides kbd.keyFeedback = ‘Yes’ kbd. _setInstanceMethod ('_onKey', 'Playmethods', 'onkey');

18 Copyright © 2005, Richard A. DeVenezia. All rights reserved. Playmethods.scl:onKey n 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; n AND...

19 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;

20 Copyright © 2005, Richard A. DeVenezia. All rights reserved. BUT... n Pending event (by design) is a keyPress n SAS/AF Executor, event handling Invokes onKey of Text Entry SAS/AF event supervisor Text Entry onKey() piece.wait() for event() Text Entry key pressed Control Loop

21 Copyright © 2005, Richard A. DeVenezia. All rights reserved. Conclusion n SAS/AF is very much alive A gem with many little seen facets n Tetris is still fun n Install SAS/Tetris from www.devenezia.com/downloads/sas/af

22 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 radevenz@ix.netcom.com


Download ppt "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."

Similar presentations


Ads by Google