Concatenative topics
Concatenative meta
Other languages
Meta
Pong is a virtual table tennis arcade video game, featuring simple two-dimensional graphics. Each player controls one paddle on either side of the screen
|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 |80 @Controller &vector $2 &button $1 &key $1 |000 @position $2 @score $2 |100 @on-reset ( -> ) ( | theme ) #0f08 DEOk INC INC DEOk INC INC DEO ;on-frame .Screen/vector DEO2 [ LIT2 02 -Screen/auto ] DEO .Screen/width DEI2 .Screen/height DEI2 ( | court ) ;court-icn .Screen/addr DEO2 OVR2 #01 SFT2 .Screen/x DEO2 #0000 .Screen/y DEO2 DUP2 #03 SFT2 SWP SUB &>l ( -- ) [ LIT2 01 -Screen/sprite ] DEO INC DUP ?&>l POP ( | bounds ) #03 SFT2 DUP #01 SUB ;on-frame/b STA #05 SUB ;<move>/b STA POP #03 SFT2 #01 SUB ;on-frame/r STA POP ;fill-icn .Screen/addr DEO2 <draw-score> <reset-ball> BRK @on-frame ( -> ) [ LIT &f $1 ] INCk ,&f STR ( 30 fps ) #01 AND ?{ BRK } ( | ball ) [ LIT2 00 &y $1 ] DUP2 #30 SFT2 .Screen/y DEO2 [ LIT2 00 &x $1 ] DUP2 #30 SFT2 .Screen/x DEO2 [ LIT2 40 -Screen/sprite ] DEO DUP [ LIT &r $1 ] NEQ ?{ OVR2 #01 hit [ LIT2 ff _&dx ] STR } DUP ?{ OVR2 #00 hit [ LIT2 01 _&dx ] STR } [ LIT &dx 01 ] ADD DUP ,&x STR #30 SFT2 .Screen/x DEO2 DUP [ LIT &b $1 ] NEQ ?{ [ LIT2 ff _&dy ] STR } DUP ?{ [ LIT2 01 _&dy ] STR } [ LIT &dy 01 ] ADD DUP ,&y STR #30 SFT2 .Screen/y DEO2 [ LIT2 41 -Screen/sprite ] DEO ( | controls ) [ LIT2 ff -Controller/button ] DEI EOR DUP #10 AND ?{ #ff00 <move> } DUP #20 AND ?{ #0100 <move> } DUP #04 AND ?{ #ff01 <move> } DUP #01 AND ?{ #0101 <move> } POP ( | paddles ) .Screen/width DEI2 #0008 SUB2 .Screen/x DEO2 #0000 .Screen/y DEO2 .position LDZ2 <draw-paddle> #0000 DUP2 .Screen/x DEO2 .Screen/y DEO2 <draw-paddle> BRK @on-frame-hit ( -> ) [ LIT &f $1 ] INCk ,&f STR #40 NEQ ?{ ;on-frame .Screen/vector DEO2 <reset-ball> } BRK @<reset-ball> ( -- ) #00 ;on-frame/x LDA #30 SFT2 .Screen/x DEO2 #00 ;on-frame/y LDA #30 SFT2 .Screen/y DEO2 [ LIT2 40 -Screen/sprite ] DEO .Screen/width DEI2 #04 SFT2 ;on-frame/x STA POP .Screen/height DEI2 #04 SFT2 ;on-frame/y STA POP JMP2r @<move> ( offset id -- ) ( top ) DUP2 LDZ ADD INCk ?{ POP POP2 JMP2r } ( bottom ) [ LIT &b $1 ] NEQ ?{ POP2 JMP2r } STHk LDZ ADD STHr STZ JMP2r @<draw-paddle> ( y -- ) STH ;on-frame/b LDA #00 &>l ( -- ) DUP STHkr GTH OVR STHkr #06 ADD LTH AND .Screen/sprite DEO INC GTHk ?&>l POP2 POPr JMP2r @hit ( y* id -- ) ROT POP STHk LDZ SUB #05 GTH ?{ POPr JMP2r } STHr #00 EQU .score ADD LDZk INC SWP STZ ;on-frame-hit .Screen/vector DEO2 #00 ;on-frame-hit/f STA ( >> ) @<draw-score> ( -- ) #0010 .Screen/y DEO2 [ LITr -Screen/width ] DEI2r [ LITr 01 ] SFT2r DUP2r [ LIT2r 0030 ] SUB2r [ LITr -Screen/x ] DEO2r .score LDZ2 SWP <draw-number> [ LIT2r 0010 ] ADD2r [ LITr -Screen/x ] DEO2r ( >> ) @<draw-number> ( num -- ) ( clip ) #0a DIVk MUL SUB ( seg. ) #00 SWP #20 SFT ;num-lut ADD2 LDAk <draw-col> INC2 LDAk <draw-col> INC2 LDAk <draw-col> INC2 LDA ( >> ) @<draw-col> ( bitmap -- ) ( save ) [ LITr -Screen/y ] DEI2kr STH #0800 &>l ( -- ) STHkr OVR SFT #01 AND .Screen/sprite DEO INC GTHk ?&>l POP2 POPr .Screen/x DEI2k #0008 ADD2 ROT DEO2 ( restore ) ROTr DEO2r JMP2r @num-lut [ ff81 81ff 0000 ff00 f989 898f 8989 89ff 0f08 08ff 8f89 89f9 ff88 88f8 0101 01ff ff89 89ff 0f09 09ff ] @fill-icn [ ffff ffff ffff ffff ] @court-icn [ 0080 8000 0080 8000 ]
This revision created on Sat, 23 Mar 2024 22:02:07 by neauoire