Tetris: SAS/AF® Considerations
Download
Report
Transcript Tetris: SAS/AF® Considerations
Tetris: SAS/AF Considerations
Richard A. DeVenezia
Independent Consultant
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.
Copyright © 2005 , Richard A. DeVenezia. All rights reserved.
Overview
SAS/AF - Dead or Alive ?
• Built to last
Gaming Tradition
Copyright © 2005 , Richard A. DeVenezia. All rights reserved.
Tradition
Copyright © 2005 , Richard A. DeVenezia. All rights reserved.
Topics to be Covered
Invention
Pieces
Game Play
Movement Keys
Layout
Timing Loop
Copyright © 2005 , Richard A. DeVenezia. All rights reserved.
Inventor
Alexey Pajitnov
1985
World wide craze
• More dangerous than a Rubik’s Cube
Still popular
Copyright © 2005 , Richard A. DeVenezia. All rights reserved.
Pieces
Arrangement of four squares or blocks
• Seven shapes
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
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
Copyright © 2005 , Richard A. DeVenezia. All rights reserved.
.GIF to .IMAGE
sashelp.fsp.imgdat
Image Data Model
_readFilePath(file)
_writeCatalog(ent)
Images in same catalog as
game
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
Copyright © 2005 , Richard A. DeVenezia. All rights reserved.
Piece Class
Adapts to piece type A,B,C,...
• arrays define geometry
private
{ ., .,
, 1, 2,
, ., .,
num D [ 4, 3, 3 ] / ( initialValue =
.
3
4
, ., 1, .
, ., 2, .
, 4, 3, .
, 4, ., .
, 3, 2, 1
, ., ., .
, .,
, .,
, .,
});
3, 44
2, .
1, .
Copyright © 2005 , Richard A. DeVenezia. All rights reserved.
One array per piece
• 4 states of rotation
• 4 blocks per piece
• values define block layout
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
Where, when, how, what is going on
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
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
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
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;
Copyright © 2005 , Richard A. DeVenezia. All rights reserved.
What caused the event?
A Text Entry Control
• Field where user types in
4
left
5
6
rotate right
2
drop
Has overrides
kbd.keyFeedback = ‘Yes’
kbd. _setInstanceMethod ('_onKey',
'Playmethods', 'onkey');
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...
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;
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/AF
event supervisor
Text Entry
key pressed
Control
Loop
piece.wait()
for event()
Copyright © 2005 , Richard A. DeVenezia. All rights reserved.
Text Entry
onKey()
Conclusion
SAS/AF is very much alive
• A gem with many little seen facets
Tetris is still fun
Install SAS/Tetris from
www.devenezia.com/downloads/sas/af
Copyright © 2005 , Richard A. DeVenezia. All rights reserved.
About the Speaker
Speaker Richard A. DeVenezia
Independent Consultant
Location 9949 East Steuben Road
Remsen, NY 13438
Telephone (315) 831-8802
E-Mail [email protected]
Copyright © 2005 , Richard A. DeVenezia. All rights reserved.