Tetris SASAF Considerations Richard A De Venezia Independent

  • Slides: 22
Download presentation
Tetris: SAS/AF Considerations Richard A. De. Venezia Independent Consultant SAS is a registered trademark

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

Overview n SAS/AF - Dead or Alive ? • Built to last n Gaming

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

Tradition Copyright © 2005 , Richard A. De. Venezia. All rights reserved.

Tradition Copyright © 2005 , Richard A. De. Venezia. All rights reserved.

Topics to be Covered n Invention n Pieces n Game Play n Movement Keys

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

Inventor n Alexey Pajitnov n 1985 n World wide craze • More dangerous than

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

Pieces n Arrangement of four squares or blocks • Seven shapes Copyright © 2005

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

Drawing a block n DATA Step - DSGI n 45 degree lines • left

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

Saving a block n goptions device=GIF xpixels=30 ypixels=30; n rc = graph (‘CLEAR’, “E”);

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, x 1, x 2, y 1, y 2); . . . rc = graph (‘UPDATE’); * creates E. GIF; n PIECE. CLASS uses 4 block images Copyright © 2005 , Richard A. De. Venezia. All rights reserved.

. GIF to. IMAGE n sashelp. fsp. imgdat Image Data Model _read. File. Path(file)

. GIF to. IMAGE n sashelp. fsp. imgdat Image Data Model _read. File. Path(file) _write. Catalog(ent) n Images in same catalog as game Copyright © 2005 , Richard A. De. Venezia. All rights reserved.

Game Play n Pieces drop by gravity n Player can move, rotate or drop

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 Copyright © 2005 , Richard A. De. Venezia. All rights reserved.

Piece Class n Adapts to piece type A, B, C, . . . •

Piece Class n Adapts to piece type A, B, C, . . . • arrays define geometry private {. , , 1, 2, , . , num D [ 4, 3, 3 ] / ( initial. Value =. 3 4 , . , 1, . , 2, . , 4, 3, . , 4, . , 3, 2, 1 , . , . , }); 3, 44 2, . 1, . Copyright © 2005 , Richard A. De. Venezia. All rights reserved. n One array per piece • 4 states of rotation • 4 blocks per piece • values define block layout

Piece Class - attributes n Track state block[4] - image viewers field - grid

Piece Class - attributes n 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 base. Sleep - event checking interval x, y, row, col - position of piece on field n Where, when, how, what is going on Copyright © 2005 , Richard A. De. Venezia. All rights reserved.

Piece Class - methods n Attribute driven methods setcam* - x, y, row, col

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

HOLD ON, WAIT a SECOND! n Piece. wait() • Important and essential • Wait

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 Copyright © 2005 , Richard A. De. Venezia. All rights reserved.

I’m Waiting. . . n EVENT() returns 1 • when the player stops doing

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

The Waiting Game wait: method return=num dt = datetime(); do until EVENT(); do while

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; return 0; * event needs servicing; Copyright © 2005 , Richard A. De. Venezia. All rights reserved.

What caused the event? n A Text Entry Control • Field where user types

What caused the event? n A Text Entry Control • Field where user types in 4 left n 5 6 rotate right 2 drop Has overrides kbd. key. Feedback = ‘Yes’ kbd. _set. Instance. Method ('_on. Key', 'Playmethods', 'onkey'); Copyright © 2005 , Richard A. De. Venezia. All rights reserved.

Playmethods. scl: on. Key n Dispatches keypress handlers piece = _self_. piece; select (upcase(_self_.

Playmethods. scl: on. Key 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. . . Copyright © 2005 , Richard A. De. Venezia. All rights reserved.

AND. . . n Re-enters the wait method wait: rc = piece. wait(); if

AND. . . n 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(41 x + ranuni(0)*7); goto wait; end; * code reaches here if EVENT() is pending; endmethod; Copyright © 2005 , Richard A. De. Venezia. All rights reserved.

BUT. . . n Pending event (by design) is a key. Press n SAS/AF

BUT. . . n Pending event (by design) is a key. Press n SAS/AF Executor, event handling • Invokes on. Key of Text Entry SAS/AF event supervisor Text Entry key pressed Control Loop piece. wait() for event() Copyright © 2005 , Richard A. De. Venezia. All rights reserved. Text Entry on. Key()

Conclusion n SAS/AF is very much alive • A gem with many little seen

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 Copyright © 2005 , Richard A. De. Venezia. All rights reserved.

About the Speaker Richard A. De. Venezia Independent Consultant Location 9949 East Steuben Road

About the Speaker Richard A. De. Venezia Independent Consultant Location 9949 East Steuben Road Remsen, NY 13438 Telephone (315) 831 -8802 E-Mail radevenz@ix. netcom. com Copyright © 2005 , Richard A. De. Venezia. All rights reserved.