Saturday, August 12, 2006

Code: Doofy Program - Lite Psycle

[Addendum: Patrick was kind enough to point out an error in the original listing. The editor automagically interprets the greater than/less than symbols as HTML code. Which of course, isn't what we were going for. Oops! :) So that's fixed and fixed the way Patrick suggested, which is way better than what I original wrote. Many thanks, amigo! Also, a .dsk image version is available at
for those that would prefer not to type it in. -Capt 8/15/06]

[And Another: Boy I just can't seem to get away from this one. heh! I found another error. As stated in the article, the scoring is suppose to be the ASCII value of the dot you hit. As it was, it's the ASCII value of the last key pressed. Ooops! Fixed!]

Okay, I've been making noise about posting some of the mini-games I've been working on for some time now, but haven't finished anything to post. This one was the first one I did, and it works, though there's a different version of it that I think will be much better. But still, I promised something, so here ya go. Please, be gentle with comments. ahem... :)

This is the "lite" version of the game, thus the name. The article below is WAY too much explaination, but is offered here for completeness.

---- Article ---


by Captain Computer
July 2006

My favorite CoCo programmer has got to be Richard Ramella. Each month when I was a wee lad, I'd eagerly open up the new issue of Hot CoCo and flip straight to Elmer's Arcade. Usually, I'd be punching in Mr. Ramella's latest ingenious code before even reading the latest goings on at Elmer's. The genius of his games came from the simplicity. Playing Dang It! and Broken Field Nightmare over and over contributed mightly to the nut case I am today.

Most of my programming endeavors at the moment focus around the same concept. I'm nowhere near as skilled or inventive as Mr. Ramella, of course. But I think a bit of visiting Elmer's each month rubbed off and the idea of creating a super simple, but immensely fun game that'll run on just about any CoCo has a huge appeal. This isn't it, but it's a step.

This first offering was actually a test of Roger Taylor's Rainbow IDE for programming in Extended Color BASIC. Not exactly the use for which it was intended, but it certainly beats NotePad by leaps and bounds! Lite Psycle is a smaller version of another game I've written but haven't been able to port over from Ramona (the CoCo 3), yet, called Light Psycles. It's more of a full blow two player version of this game.

Lite Cycle is a variation of the game everyone probably writes up for the CoCo at some point. Kind of the “Hello, World!” program of games. In some forms it's called snakes or Tron-style light cycles, or what-have-you. But it makes an interesting beginner's programming exercise. Being a rank amateur, I figure it's a good place to start.


Lite Cycles uses smidgen more than 800 bytes (that's with comments, spacing, and formatting), so it should run on any CoCo, 4K and up, tape or disk. I don't think I used any ECB commands in there, so it should run on a Color BASIC machines as well.

I tested it on Ramona (CoCo 3, DECB 2.1, 128K) and Ol' Betty (CoCo 1, F-Board, DECB 1.1, 64K), as well as the CoCo 2B and CoCo 3 (NTSC) emulation in MESS.

Color Computer 3 users that have a CM-8 or other RGB monitor will want to type:


prior to running the game. Might even add a line there at the top:


since the game will not run properly out of 40 or 80 column mode.

I also recommend the high speed POKE for those that prefer a little more action. (I play it exclusively at this speed. It's way more fun.)

CoCo 3: POKE 65497,0
CoCo 1/2: POKE 65495,0

Be sure to slow down before accessing the disk or tape:

CoCo 3: POKE 65496,0
CoCo 1/2: POKE 65494,0

Some very old CoCo 1's may not be able to use this POKE.

Game Play

Playing the game is pretty simple. You find yourself on the VidGrid ensconced in the ever popular and overly cliché Lite Psycle. Your job is to drive about and snag all the colored squares you can before you bash into your own light trail. But beware, the evil video game controller gods have set upon the field nasty green squares that will smash you just as easily as smacking into your trail. Avoid them, drive like a maniac (using the arrow keys) and rack up as many points as you can!

I always liked weird scoring systems. So here's one! Every space on the screen your psycle moves you get 10 points. Easy enough. When you snag a colored square, though, you get 10 points plus ASCII value of that square! Do you know your CoCo colors? If so, hitting those “higher” colors can net you more points.

In the spirit of simplicity, there's no exit. Hit BREAK when you're tired of it.

The Program

The program itself is dirt simple and should be easily readable. Here's my explanation, for what it's worth.

Lines 10 – 50 just set up a few things, like clearing the screen and setting X, Y, and score variables.

Lines 70-100 are kind of neat because they're “pushing” the CoCo's buttons, as it were. POKE 135 it like mashing a key. The values simulate pressing up, down, left and right keys. In this case, we're randomly setting the direction of initial travel for the psycle. (By the way, to get a more “random” number from the program, add the line 5 R=RND(-TIMER) to the listing. I didn't notice much difference, so I left it out, but for the purists, there ya go!).

Lines 110-140 just POKE in random dots around the screen. I chose 25 after some experimentation, but you can raise or lower this value according to your tastes. Line 120 looks like a mess, but it's pretty straight forward. The value 1024 corresponds to the first (upper left) locataion of the CoCo's text (or low-res) screen. There are 32 times 16, or 512, locations (1024 through 1536) . So POKEing a value into that location makes the CoCo display the ASCII equivalent of the value to the screen. We want a random location somewhere within 32 columns (0-31) and 15 rows (0-14). There are 16 rows on the CoCo's screen, but we'll save the bottom bit for score information. The second part of the POKE selects what character is to be placed at the screen location selected previously. In this case we want a solid color block. Value 128 is a solid black block, to which we add color using the formula found on page 292 of the Color Computer 3 Extended BASIC manual.

Lines 150-230 represent checking for a key press and then making sure the psycle stays on the screen. POKE 135 is a handy little guy for reading the keyboard (with some limitations, you can't read multiple key presses at the same time, for example). The values tested are for the arrow keys, up, down, left and right respectively (see pages 289 and 291 of the Color Computer 3 Extended BASIC manual). As a challenge, there's no border indicated (it's a bit disorienting) and the psycle just wraps around the screen. So watch out!

Lines 240 and 250 check to see if a colored square has been hit. If it's not code 143, a green square, the the player scores. If it is code 143, then the player has either hit a random green square, or hit their own light trail and the game ends.

Line 260 actually displays the next square for the light psycle's path, as calculated in lines 150-230.

Line 270 adds 10 to the score for a successful move, sans crash. I call this the “survival bonus.”

Line 280 prints the current score on the screen.

Line 290 finishes the main loop and sends the CoCo back for the next move.

Line 300 is necessary to clear out the keyboard, resetting it to its “no key pressed” state. Without it, the INKEY$ in the next line barfs and thinks a key is pressed. No waiting!

Line 310 waits while you lament your recent demise.

Line 320 checks to see if you scored enough for a high score and loads up that variable (to be displayed on restart way back on Line 20).

Line 330 is the do over line. Hit BREAK to quit.

Play With It!

One of the fun things about silly simple programs like this is modifying and expanding them, of course. Add joystick control, two players, have the psycle change colors when it hits a block (and then wreck it if hits the same color block next), or any number of bits and pieces.

In the end, this didn't turn out to be a good game, but it was an interesting programing exercise. I also got to play with Rainbow IDE and ended up with a game my 6 year old daughter thinks is pretty neat. (Hey, she's 6.) It's been 17 years since I did this, so it's fun to get back into it and relearn. I hope others out there will do the same. And if you do, post your efforts!

10 CLS0
20 PRINT@500,"HIGH:"HS;
50 X=15:Y=7:S=0:B$=CHR$(128)
60 D=RND(3)
70 IF D=0 THEN POKE135,8
80 IF D=1 THEN POKE135,9
90 IF D=2 THEN POKE135,10
100 IF D=3 THEN POKE135,94
110 FOR L=1 TO 25
120 C=RND(8)
130 POKE (1024+RND(31)+(RND(14)*32)),128+16*(C-1)+15
140 NEXT L
150 P=PEEK(135)
160 IF P=94 THEN Y=Y-1
170 IF P=10 THEN Y=Y+1
180 IF P=8 THEN X=X-1
190 IF P=9 THEN X=X+1
200 IF Y < 0 THEN Y=14 ELSE IF Y > 14 THEN Y=0
220 IF X < 0 THEN X=31 ELSE IF X > 31 THEN X=0
240 IF PEEK (1024+X+(Y*32))>143 THEN S=S+PEEK(1024+X+(Y*32)):SOUND200,1
250 IF PEEK (1024+X+(Y*32))=143 THEN PRINT@263,"crash"+B$+"crash"+B$+"crash";:GOTO 300
260 POKE 1024+X+(Y*32),143
270 S=S+10
280 PRINT@480,"SCORE:";S;
290 GOTO 150
300 POKE135,0
310 IF INKEY$="" THEN GOTO 310
330 GOTO 10


Patrick said...

I gave it a try, fun one! :)

Isn't there a mistake at lines 200-220? I was getting an error and fixed it this way:

200 IF Y<0 THEN Y=14 ELSE IF Y>14 THEN Y=0
220 IF X<0 THEN X=31 ELSE IF X>31 THEN X=0

CaptCPU said...

Heh! Ooops! Okay, that was suppose to read:

200 IF Y<0 THEN Y=14
210 IF Y>14 THEN Y=0
220 IF X<0 THEN X=31
230 IF X>31 THEN X=0

Not sure why it copied over all wonky. I'm looking at the .BAS file that I copied and pasted from Notepad++ and it looks fine. hmmm... Anyhoo...

You solution is much more elegent and compact, so let's go with that. ;)

Here's a disk image for those that want to fire it up sans typing: