Post Reply 
(34S) Crude Snake game
06-01-2014, 12:55 PM (This post was last modified: 06-15-2017 01:21 PM by Gene.)
Post: #1
(34S) Crude Snake game
Since the 34S has some simple commands for polling the keyboard and drawing directly to the (tiny) dot-matrix screen, I figured I may as well see how suitable it is for action games. The results aren't too bad.

Code:
001 LBL'SNK'
002 LocR 16 //Could be reduced. I started the graphics block at 10, and was too lazy to move it down.
003 CLα
004 6
005 ENTER
006 # 043 //Entered via # in the CONST menu
007 gDIM .10
008 3
009 STO .00
010 STO .01
011 1
012 STO .02
013 0
014 STO .03
015 STO .04
016 LBL 20
017 RCL .01
018 RCL .00
019 gPIX? .10
020 GTO 99
021 gSET .10
022 RCL .04
023 gPLOT .10
024 PSE 01
025 KEY? X
026 GTO 21
027 KTP? X
028 LBL?->X
029 GTO->X
030 GTO 21
031 LBL 02
032 1
033 STO .03
034 0
035 STO .02
036 GTO 21
037 LBL 04
038 1
039 +/-
040 STO .02
041 0
042 STO .03
043 GTO 21
044 LBL 06
045 1
046 STO .02
047 0
048 STO .03
049 GTO 21
050 LBL 08
051 1
052 +/-
053 STO .03
054 0
055 STO .02
056 GTO 21
057 LBL 21
058 RCL .00
059 RCL+ .02
060 # 043
061 MOD
062 STO .00
063 RCL .01
064 RCL+ .03
065 6
066 MOD
067 STO .01
068 INC .04
069 GTO 20
070 LBL 99
071 RCL .04
072 CLα
072 α'GAM'
073 α'E O'
074 α'VER'
075 VWα+ X
076 RTN
078 END

Just XEQ'SNK', and the game begins immediately. Use 2, 4, 6, and 8 to control the snake's direction. The snake can wrap around the edges of the playfield. Your score is displayed during and after the game.

There's plenty of room for improvement here. I'm not real pleased with the keyboard handling, but I wrote it at 2:00 AM.

Seems like it's a bit more sluggish than I would expect based on the hardware, but that's probably because gPLOT has to blit the entire screen from several registers, rather than being able to directly poke at bits in the display RAM. Paul, Walter, more graphics commands for future firmware versions perhaps? Smile
Visit this user's website Find all posts by this user
Quote this message in a reply
11-05-2015, 04:35 PM
Post: #2
RE: (WP-34S) Crude Snake game
hi, I just bought a wp 34s and I'm trying to learn to code...
I can't input line 028 and 029

LBL? -> X
GTO->X

I put it without "->" but the snake doesn't turn... in fact keys 2, 4, 6 and 8 doesn't work...

any help?
Find all posts by this user
Quote this message in a reply
11-05-2015, 04:50 PM (This post was last modified: 11-05-2015 04:58 PM by fhub.)
Post: #3
RE: (WP-34S) Crude Snake game
(11-05-2015 04:35 PM)inaqui76 Wrote:  I can't input line 028 and 029
LBL? -> X
GTO->X
any help?
After -> you have to use the ENTER key (displays a small 's' for stack), and then X is working.
That's needed for a many operations which addresses the stack registers, when the key for it (e.g. [.] for X) has also a different meaning. So it's a good idea to always precede such stack calls with an ENTER key.

PS: here are 2 other examples which also work only with ENTER
STO T needs: STO ENTER T because without ENTER it would give STO*
RCL Z needs RCL ENTER Z (without ENTER you get RCL+)

Franz
Visit this user's website Find all posts by this user
Quote this message in a reply
11-05-2015, 06:16 PM
Post: #4
RE: (WP-34S) Crude Snake game
Thanks!

now those lines convert into

LBL?->X to LBL?'H'

is that correct?
because "my snake" doesn't turn around, the 2, 4, 6 and 8 key does nothing...


(11-05-2015 04:50 PM)fhub Wrote:  
(11-05-2015 04:35 PM)inaqui76 Wrote:  I can't input line 028 and 029
LBL? -> X
GTO->X
any help?
After -> you have to use the ENTER key (displays a small 's' for stack), and then X is working.
That's needed for a many operations which addresses the stack registers, when the key for it (e.g. [.] for X) has also a different meaning. So it's a good idea to always precede such stack calls with an ENTER key.

PS: here are 2 other examples which also work only with ENTER
STO T needs: STO ENTER T because without ENTER it would give STO*
RCL Z needs RCL ENTER Z (without ENTER you get RCL+)

Franz
Find all posts by this user
Quote this message in a reply
11-05-2015, 06:44 PM
Post: #5
RE: (WP-34S) Crude Snake game
(11-05-2015 06:16 PM)inaqui76 Wrote:  now those lines convert into
LBL?->X to LBL?'H'
is that correct?
No, I don't understand how you end up with the letter 'H' ???

After selecting LBL? from the TEST menu, press following keys:
[->] [ENTER] [.]

Franz
Visit this user's website Find all posts by this user
Quote this message in a reply
11-05-2015, 06:51 PM
Post: #6
RE: (WP-34S) Crude Snake game
my bad... I mean X instead of H... shame on me...

Now I got it... [->] key is the one with CONV...

the program now works perfect....
Thanks for the help!!

(11-05-2015 06:44 PM)fhub Wrote:  
(11-05-2015 06:16 PM)inaqui76 Wrote:  now those lines convert into
LBL?->X to LBL?'H'
is that correct?
No, I don't understand how you end up with the letter 'H' ???

After selecting LBL? from the TEST menu, press following keys:
[->] [ENTER] [.]

Franz
Find all posts by this user
Quote this message in a reply
11-12-2015, 07:39 AM
Post: #7
RE: (WP-34S) Crude Snake game
You can enter the X register as . . pretty much everywhere. I.e. you don't need the ENTER to bring the s onto the display.

Also, the program will be faster if the #xxx constants are used instead of digits wherever possible. Especially the single digit numbers. The reason is the digits are entered into the command line and then they are parsed into a number using lots of floating point arithmetic. The #xxx constants are directly loaded into the register.

A neat program nonetheless.


- Pauli
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)