Goto 10 RetroComputing: Atari and more

Share this post

Pumpkin Man: A (Simple) BASIC Game

www.goto10retro.com

Pumpkin Man: A (Simple) BASIC Game

Happy Halloween

Paul Lefebvre
Oct 28, 2022
4
1
Share this post

Pumpkin Man: A (Simple) BASIC Game

www.goto10retro.com

Last week I showed how to create a Player (aka Sprite) in the shape of a pumpkin that you could move around the screen with the joystick.

The code was written in Atari BASIC and used an ML subroutine to actually move the player (well, actually it was two players side-by-side but moved together to look like on larger player).

This time, I have re-written the code using a better version of BASIC, which makes it much simpler to read and understand. Plus, it’s also faster.

In addition, I added a new feature where the pumpkin gets points by “eating candy” that is on the screen.

But first, the new version of last week’s program is below:

10 Rem PUMPKIN MAN
100 Graphics 18:Setcolor 2,0,0:Print #6;" HAPPY HALLOWEEN"
110 Pmgraphics 2
120 Pmclr 0:Pmclr 1
130 P1=Pmadr(0):Y=48
135 Pmcolor 0,2,8:Pmcolor 1,2,8
140 For I=P1+Y To P1+Y+13
150 Read D1
160 Poke I,D1
170 Next I
180 P2=Pmadr(1)
190 For I=P2+Y To P2+Y+13
200 Read D1
210 Poke I,D1
220 Next I
225 Set 7,1
230 Hpos=50:Vpos=0
240 Hpos=Hpos+Hstick(0)
250 Vpos=Vstick(0)
255 Y=Y+Vpos
260 If Hpos<20 Then Hpos=220
261 If Hpos>220 Then Hpos=20
270 Pmmove 0,Hpos;Vpos:Pmmove 1,Hpos+8;Vpos
280 Goto 240
5000 Rem PLAYER DATA
5010 Data 0,1,7,31,63,123,113,127,101,112,122,63,31,7
5020 Data 192,128,224,248,252,222,142,254,166,14,94,252,248,224

I wrote it using BASIC XE (but it also works in Altirra BASIC which also shares the same Player/Missile commands). Here’s a breakdown of the code:

  • Line 100: Switches to large-size character graphics mode and displays “HAPPY HALLOWEEN” on the screen.

  • Lines 110-220: Turn on Player/Missile Graphics, clear the memory area, set the player colors to orange, load the player data into the addresses for player 0 and 1.

  • Line 225: Allows the player to wrap between the top/bottom of the screen.

  • Lines 230-280:Moves the player based on how the joystick is moved.

  • Lines 5010-5020:Player data for the left and right parts of the pumpkin.

With that all working, the next thing is to display some “candy” on the screen and to get points when you “eat” it. For simplicity I will use the “c” character to indicate candy. Eventually I will want to redefine the character set with something more accurate, but this will work for now to get the concept across.

Since the game is run using Graphics 2, it already using big characters, so we can tell it to draw them to the screen using a subroutine:

4000 Xc=Int(Rnd(0)*19):Yc=Int(Rnd(0)*9)+1
4020 Position Xc,Yc:Print #6;"c"
4030 Return

We can call the subroutine in the initial setup:

235 GOSUB 4000

If you run the program now, you can still move the pumpkin around, but nothing happens to the candy. What we need to do is check the player for a collision with the playfield. The BASIC XE (and Altirra BASIC) command for that is BUMP. By using BUMP we can know when the player touches one of the characters (and thus “eats” it). We can then add a point to the score and remove the “candy” from the screen.

So first we can add another subroutine to erase the candy:

4100 Position Xc,Yc:Print #6;" "
4110 Return

And a routine to display the score:

4200 Position 0,11:Print #6;"SCORE:";Score
4210 Return

Now we can check to see if the pumpkin touches the candy by adding this to the main program loop:

275 If Bump(0,9)=1 Or Bump(1,9)=1 Then Gosub 4100:Gosub 4000:Hitclr :Score=Score+1:Gosub 4200

And lastly, display the score in the initialization:

235 Gosub 4000:Score=0:Gosub 4200

This is not the world’s most exciting game, but now when you move the pumpkin around and it touches the “C” for candy, the score will increase by 1 and candy will appear at a new position.

I really like BASIC XE as its extra commands help keep this code pretty easy to understand.

Future tasks for Pumpkin Man:

  • Add an enemy ghost that chases the pumpkin around the screen

  • Redefine the character set so that the “C” looks like an actual piece of candy.

  • Add some sound.

Be sure to join the Goto 10 mailing list so you’ll be notified when new posts are available!

And remember, the source for this (and many others things) is one of the many perks that paid subscribers get.

1
Share this post

Pumpkin Man: A (Simple) BASIC Game

www.goto10retro.com
Previous
Next
1 Comment
John Paul Wohlscheid
Writes Computer Ads from the Past
Oct 28, 2022·edited Oct 28, 2022Liked by Paul Lefebvre

Cool beans. Now, I'm tempted to return to BASIC.

Expand full comment
Reply
TopNewCommunity

No posts

Ready for more?

© 2023 Paul Lefebvre
Privacy ∙ Terms ∙ Collection notice
Start WritingGet the app
Substack is the home for great writing