TweetFollow Us on Twitter

Simon Game
Volume Number:4
Issue Number:7
Column Tag:Basic School

True Basic Plays the Simon Game

By Dave Kelly, MacTutor Editorial Board

The new and improved version of True Basic (ver. 2.01) has just recently started shipping. Some of the new features include: built in support for full color and PICT format images, 68881 coprocessor support, and a more structured environment using modules and workspaces. True Basic also now includes the Runtime package (which used to cost a few hundred dollars), but they are packaging the Macintosh Developer’s Toolkit separately. The toolkit contains all of the libraries which are essential for making “real” Macintosh programs (menus, windows, controls etc). It is obvious to any dedicated Macintosh developer that this package should have been included with the True Basic “Basic” package. However, it is true that when True Basic is sold to a school as a training tool, there is not much need for the Macintosh libraries.

This month, I am not going to do an in depth analysis of True Basic 2.01 (Basic Wars, part ??). I’ll save that for next month. I would like to show off some of True Basic’s new features with respect to Macintosh II color. I’m still impressed by Mac II’s color!

True Basic has its own unique set of statements for using color. The SET COLOR n statement (where n is a number from 0 to 255) sets the drawing pen to the color selected. Then a PLOT or some other graphics command may be given to operate in the selected color. Selecting color is not really very unique. ZBasic uses a similar statement (COLOR=n) to select colors.

The Palette Manager is responsible for monitoring and establishing the color environment on the Mac II. The system provides a default palette of colors which applications may use as desired. The default palette is a set of standard colors which may be selected. Color Quickdraw will match the selected color as best as it can, but there may be times when more shades of a particular color are desired than are available in the default palette.

Most video devices including the Mac II video card use an indexed color model. Each pixel value in the video device’s memory corresponds to an indexed value in the color table. The color display card uses the RGB value found in the look up table to display the desired color. There are several advantages to using this indexed display method. One is that it is faster. Also, it allows color animation to be used. In color animation, the index value is changed to change display colors; the pixel color itself is not changed. You can especially see the effects of this when using Pixel Paint or Modern Artist and changing the palette using the application. Another way to see the effects of changing the palette is by using the Colorizer software, by Palomar. This is recommended to any Mac II user that wants to make better use of color on the Mac II. [The Colorizer and the PICT Dective are available from MacTutor’s Mail Order Store at the back of this issue. -Ed]

Fig. 1 Our Simon Game in True Basic (This is in color on the Mac II!)

Color Palette Manipulation

True Basic allows you to change colors in the color palette. The SET COLOR MIX (x) r,g,b statement sets the color x to the color specified by the red, green, blue values given by r,g and b. In True Basic the values of r,g and b are from 0 to 1 (whereas the hardware is looking for values from 0 to 65535). For the user it is much easier to think in terms of 0 to 1 than 0 to 65535. A SET COLOR MIX (5) .25,0,0 would change color 5 to 25% of the full red value and no green and blue. The number of distinct intensities available on your Mac II depends on the number of colors available. You may use ASK MAX COLOR to determine how many of the colors are available out of the total 256 colors (assuming you can display 256 colors). Actually ASK MAX COLOR returns n-3 colors because some of the colors are already in use by the system. ASK MAX COLOR will only let you know the maximum possible number of colors. SET COLOR MIX is ignored on black and white systems.

Using color is fun as you can see from this months program (see the black and white figure 1; on the Mac II, this Simon game is in color with the background an animated palette). The theme I selected is based on the Simon game (Milton Bradley) which I’m sure you have all seen before. There are a few things which must be done to set up the program if you are starting from scratch. First go to a paint program (color is preferred, but not necessary) and create the main PICT for the game as shown here in figure 2.

Fig. 2 PICT for the Simon Game

It doesn’t matter what colors are used or even the shape of the colored areas. The program will do a fill (FLOOD x,y statement in True Basic) and fill in the correct colors as long as the size of the PICT rectangle remains the same size. If the same color is used as the original, the SET COLOR MIX statement needs to use a different color because the FLOOD statement fills the area till it finds a change in color or it finds the same color as the one being use to fill the area.

Next the PICT should be stored in the clipboard and then run the ‘Save Clip’ program. The purpose of this program is to convert the clipboard PICT file into a disk PICT file. True Basic could read the PICT file direct, but this way we know that we have only selected the actually PICT and not some of the areas surrounding it. When the ‘Save Clip’ program asks for a filename, the name of the file as used in the main program should be used (in this case ‘Prof Says.PICT’ is the filename).

{1}
! Save Clip
! This program will save the contents of the clipboard to a file
LIBRARY “Mactools*”
LIBRARY “PictLib*”
DECLARE DEF MacPutFile$
LET doneflag=0
DO until doneflag=1
   CALL Read_clipboard(“PICT”,s$)
   LET filename$=MacPutFile$(50,50,”Enter Filename to save as ”,””,””)
   IF filename$<>”” THEN
      CALL Write_pictfile(filename$,s$)
      PRINT “Do another?”;
      GET KEY Answer
      IF Answer<>ord(“Y”) OR Answer<>ord(“y”) THEN LET doneflag=1
   ELSE
      LET doneflag=1
   END IF
LOOP
END

The main program requires the use of the MacTools and PictLib Libraries. These are provided with the True Basic package. To help True Basic find the libraries (in case they are moved to a strange place) the ALIAS statement should be used. The manual is not too clear on this, but ALIAS statements should be run from a file ‘TB Startup’ automatically when True Basic is run. This is a satisfactory solution to fix the HFS problems that True Basic 1.0 had.

The next thing that might be different for you is the way that True Basic specifies the window (or screen) coordinates. No matter what kind of computer True Basic is being run on, the coordinates are the same. The coordinates start with 0,0 in the bottom left corner of the screen and go to 1,1 in the top right corner. Then using the SET WINDOW statement any coordinate system may be mapped to the current window. A smaller portion of the screen may be partitioned off to act as a kind of clipping region for text. The PictStuff library seems to only use screen coordinates and doesn’t pay much attention to the location of the window. However, by using the CALL Set_Frame statement, the PICT graphics may be displayed anywhere you want. The OPEN #1:screen left, right, bottom, top statement is set up for the Apple RGB Monitor. These values may have to be adjusted if used on other size monitors.

Of course, True Basic statements are used all the way through the program except for the MacTools calls which are used mostly used to display text. A few of the other Macintosh things which are included in the MacTools Library are:

MacPenSize(width,height)
MacPenMode(mode)
MacTextFont(font)
MacTextFace(style$)
MacTextMode(mode)
MacTextSize(size)
MacTextBox(left,right,bottom,top,s$,just$)
MacSpaceExtra(extra)
MacGetFontInfo(ascent,descent,widmax,leading)
MacGetFile$(h,v,type$,button$)
MacPutFile$(h,v,pr$,iname$,button$)
MacSysBeep(duration)

also other commands for drawing ovals and rectangles.

I am somewhat disappointed that more of the Macintosh Toolbox is not included (built in) to the True Basic system. Of course the Developer Toolkit should include the rest of the Macintosh ROM world, but it would be nice to have it integrated. [We are still waiting for delivery of the Developer Toolkit. True Basic is sending return postcards to order the library but as yet we have not seen it. -Ed] If you use any library a lot, you may load it when you startup and have it resident in memory so at least there is a way to simplify the system. I hope to be able to review the Developer Toolkit when it is released. I will have more to say about True Basic next month.

{2}
! Professor Mac Says 
! By David Kelly
! ©MacTutor, 1988
! With special thanks to Milton Bradley Co.
! For their “Simon” Game

LIBRARY “Mactools*”! MacStuff Library
LIBRARY “PictLib*” ! PICTStuff Library
DECLARE DEF MacGetFile$
DIM notes(31)
RANDOMIZE
LET skilllevel=8 ! Set up levels
LET level=1
SET BACKGROUND COLOR 10 !  Get a Background color
OPEN #1:screen .25,.67,.165,.75    ! open a section of screen
WINDOW #1 ! and use it as a window
SET WINDOW 0,1,0,1
ASK SCREEN a,b,c,d
CALL set_frame(a,b,c,d)

LET filename$=”Prof Says.PICT”! Get the PICT resource
IF filename$<>”” THEN
 CALL Read_pictfile(filename$,s$)
 CALL Draw_string(s$,1)
ELSE
 PRINT “Prof Says.PICT file not found!”
END IF

! Set up the main screen
CALL SetRed
FLOOD .3,.7 ! Fill the shape with Red
CALL SetBlue
FLOOD .7,.7 ! Fill the shape with Blue
CALL SetGreen
FLOOD .3,.3 ! Fill the shape with Green
CALL SetYellow
FLOOD .7,.3 ! Fill the shape with Yellow
! Turn off all shapes
CALL darkred
CALL darkblue
CALL darkgreen
CALL darkyellow
ASK WINDOW a,b,c,d
BOX KEEP a,b,c,d in None$ ! Save PICT so it can be             
 ! restored later
CALL MacTextFont(2)! Get New York font
SET TEXT JUSTIFY “center”,”half”
DO ! Start the Main program loop
 SET COLOR MIX (0) rnd,rnd,rnd   ! change background color
 CALL SetButtons(level)
 DO
 LET Animationcount=Animationcount+1
 IF Animationcount>=500 then
 SET COLOR MIX (0) rnd,rnd,rnd! change the background color
 LET Animationcount=0
 END IF
 GET MOUSE x,y,s ! Check for mouse press
 IF s>=1 then
 GET POINT x,y   ! Get the mouse press
 LET result=0
 CALL PtInRect(x,y,.12,.295,.7,.8,result)    ! Level 1
 IF result=1 then
 LET skilllevel=8
 LET level=1
 CALL SetStartGameButton(Level)
 END IF
 LET result=0
 CALL PtInRect(x,y,.32,.495,.7,.8,result)    ! Level 2
 IF result=1 then
 LET skilllevel=14
 LET level=2
 CALL SetStartGameButton(Level)
 END IF
 LET result=0
 CALL PtInRect(x,y,.505,.680,.7,.8,result)   ! Level 3
 IF result=1 then
 LET skilllevel=20
 LET level=3
 CALL SetStartGameButton(Level)
 END IF
 LET result=0
 CALL PtInRect(x,y,.705,.880,.7,.8,result)   ! Level 4
 IF result=1 then
 LET skilllevel=31
 LET level=4
 CALL SetStartGameButton(Level)
 END IF
 LET result=0
 CALL PtInRect(x,y,.3,.7,.05,.15,result)
 IF result=1 then
 ! Quit Routine
 SET COLOR “White”
 BOX AREA 0,1,0,1
 SET COLOR “Black”
 BOX LINES 0,1,0,1
 SET COLOR “Blue”
 CALL MacTextSize(24)
 PLOT TEXT, AT .5,.6:”Thank you for”
 PLOT TEXT, AT .5,.4:”Reading MacTutor™”
 STOP
 END IF
 LET result=0
 CALL PtInRect(x,y,.3,.7,.2,.3,result)
 IF result=1 then
 ! Play the Game
 BOX SHOW none$ at 0,0
 LET x=0
 LET y=0
 LET numberofnotes=1
 LET tempo=100
 DO until numberofnotes=skilllevel
 CALL PlaySequence(numberofnotes,tempo, notes())
 FOR i=1 to numberofnotes
 SET COLOR MIX (0) rnd,rnd,rnd
 GET POINT x,y
 CALL buttonpress(x,y,selection)
 IF selection<>notes(i) then
 CALL MacSysBeep(500)
 CALL MacSysBeep(500)
 CALL MacSysBeep(500)
 EXIT DO
 END IF
 NEXT i
 LET numberofnotes=numberofnotes+1
 LET tempo=tempo+i*10
 PAUSE 1
 LOOP
 CALL SetButtons(level)
 END IF
 END IF
 LOOP
LOOP
END

SUB SetButtons(GameLevel)     ! Set Game Buttons
 CALL MacTextSize(14)
 SET COLOR “white”
 BOX AREA .3,.7,.05,.15   ! Quit Game Button
 BOX AREA .12,.295,.7,.8  ! Level 1 Button
 BOX AREA .32,.495,.7,.8  ! Level 2 Button
 BOX AREA .505,.680,.7,.8 ! Level 3 Button
 BOX AREA .705,.880,.7,.8 ! Level 4 Button
 SET COLOR “Black”
 BOX LINES .3,.7,.05,.15  ! Quit Game Button
 BOX LINES .12,.295,.7,.8 ! Level 1 Button
 BOX LINES .32,.495,.7,.8 ! Level 2 Button
 BOX LINES .505,.680,.7,.8  ! Level 3 Button
 BOX LINES .705,.880,.7,.8! Level 4 Button
 SET COLOR “Red”
 CALL SetStartGameButton(GameLevel)
 PLOT TEXT, AT .5,.11:”Quit Game”
 CALL MacTextSize(12)
 PLOT TEXT, AT .195,.77:”1"
 PLOT TEXT, AT .4,.77:”2"
 PLOT TEXT, AT .575,.77:”3"
 PLOT TEXT, AT .825,.77:”4"
END SUB

SUB SetStartGameButton(GameLevel)  ! Set up the Start Game Button
 SET COLOR MIX (0) rnd,rnd,rnd
 CALL MacTextSize(14)
 SET COLOR “White”
 BOX AREA .1,.9,.2,.3! Start Game Button
 SET COLOR “Black”
 BOX LINES .1,.9,.2,.3  ! Start Game Button
 SET COLOR “Red”
 PLOT TEXT, AT .5,.26:”Start Game Level “ & STR$(Gamelevel)
END SUB

SUB SetNone ! Display the PICT with colors off
 BOX SHOW None$ at 0,0
END SUB

SUB SetRed
 SET COLOR MIX (13) 1,0,0
 SET COLOR 13
END SUB
SUB DarkRed
 SET COLOR MIX (13) 0,0,0
 SET COLOR 13
END SUB
SUB SetGreen
 SET COLOR MIX (14) 0,1,0
 SET COLOR 14
END SUB

SUB DarkGreen
 SET COLOR MIX (14) 0,0,0
 SET COLOR 14
END SUB
SUB SetBlue
 SET COLOR MIX (15) 0,0,1
 SET COLOR 15
END SUB
SUB DarkBlue
 SET COLOR MIX (15) 0,0,0
 SET COLOR 15
END SUB
SUB SetYellow
 SET COLOR MIX (16) .9,1,0
 SET COLOR 16
END SUB
SUB DarkYellow
 SET COLOR MIX (16) 0,0,0
 SET COLOR 16
END SUB
SUB FlashRed
 SET COLOR MIX (13) 1,0,0
 LET note$=”o5 mf ms c”
 PLAY note$
 PAUSE .5
 SET COLOR MIX (13) 0,0,0
END SUB
SUB FlashGreen
 SET COLOR MIX (14) 0,1,0
 LET note$=”o5 mf ms a”
 PLAY note$
 PAUSE .5
 SET COLOR MIX (14) 0,0,0
END SUB

SUB FlashBlue
 SET COLOR MIX (15) 0,0,1
 LET note$=”o5 mf ms >a”
 PLAY note$
 PAUSE .5
 SET COLOR MIX (15) 0,0,0
END SUB
SUB FlashYellow
 SET COLOR MIX (16) 1,1,0
 LET note$=”o5 mf ms e”
 PLAY note$
 PAUSE .5
 SET COLOR MIX (16) 0,0,0
END SUB
SUB PtInRect(x,y,left,right,bottom,top,Result)     
! See if point is in Rectangle
 IF x>left and x<right and y>bottom and y<top then
 LET Result=1
 ELSE
 LET Result=0
 END IF
END SUB

SUB Buttonpress(x,y,selection)! Handle button press
 CALL PtInRect(x,y,0,.5,.5,1,result)
 IF result=1 then LET selectedcolor=13
 CALL PtInRect(x,y,0,.5,0,.5,result)
 IF result=1 then LET selectedcolor=14
 CALL PtInRect(x,y,.5,1,.5,1,result)
 IF result=1 then LET selectedcolor=15
 CALL PtInRect(x,y,.5,1,0,.5,result)
 IF result=1 then LET selectedcolor=16
 SELECT CASE selectedcolor
 CASE 13
 CALL flashred
 LET selection=1
 CASE 14
 CALL flashgreen
 LET selection=2
 CASE 15
 CALL flashblue
 LET selection=3
 CASE 16
 CALL flashyellow
 LET selection=4
 CASE ELSE
 LET selection=0
 END SELECT
END SUB

SUB PlaySequence(numberofnotes,tempo,notes()) ! Play the notes
 LET tempo$=”t”&str$(tempo)
 PLAY tempo$
 FOR i=1 to numberofnotes
 SET COLOR MIX (0) rnd,rnd,rnd
 IF notes(i)=0 then
 LET note=int(4*rnd)+1
 ELSE
 LET note=notes(i)
 END IF
 SELECT CASE note
 CASE 1
 CALL flashred
 CASE 2
 CALL flashgreen
 CASE 3
 CALL flashblue
 CASE 4
 CALL flashyellow
 END SELECT
 LET notes(i)=note
 NEXT i
END SUB
 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Fresh From the Land Down Under – The Tou...
After a two week hiatus, we are back with another episode of The TouchArcade Show. Eli is fresh off his trip to Australia, which according to him is very similar to America but more upside down. Also kangaroos all over. Other topics this week... | Read more »
TouchArcade Game of the Week: ‘Dungeon T...
I’m a little conflicted on this week’s pick. Pretty much everyone knows the legend of Dungeon Raid, the match-3 RPG hybrid that took the world by storm way back in 2011. Everyone at the time was obsessed with it, but for whatever reason the... | Read more »
SwitchArcade Round-Up: Reviews Featuring...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for July 19th, 2024. In today’s article, we finish up the week with the unusual appearance of a review. I’ve spent my time with Hot Lap Racing, and I’m ready to give my verdict. After... | Read more »
Draknek Interview: Alan Hazelden on Thin...
Ever since I played my first release from Draknek & Friends years ago, I knew I wanted to sit down with Alan Hazelden and chat about the team, puzzle games, and much more. | Read more »
The Latest ‘Marvel Snap’ OTA Update Buff...
I don’t know about all of you, my fellow Marvel Snap (Free) players, but these days when I see a balance update I find myself clenching my… teeth and bracing for the impact to my decks. They’ve been pretty spicy of late, after all. How will the... | Read more »
‘Honkai Star Rail’ Version 2.4 “Finest D...
HoYoverse just announced the Honkai Star Rail (Free) version 2.4 “Finest Duel Under the Pristine Blue" update alongside a surprising collaboration. Honkai Star Rail 2.4 follows the 2.3 “Farewell, Penacony" update. Read about that here. | Read more »
‘Vampire Survivors+’ on Apple Arcade Wil...
Earlier this month, Apple revealed that poncle’s excellent Vampire Survivors+ () would be heading to Apple Arcade as a new App Store Great. I reached out to poncle to check in on the DLC for Vampire Survivors+ because only the first two DLCs were... | Read more »
Homerun Clash 2: Legends Derby opens for...
Since launching in 2018, Homerun Clash has performed admirably for HAEGIN, racking up 12 million players all eager to prove they could be the next baseball champions. Well, the title will soon be up for grabs again, as Homerun Clash 2: Legends... | Read more »
‘Neverness to Everness’ Is a Free To Pla...
Perfect World Games and Hotta Studio (Tower of Fantasy) announced a new free to play open world RPG in the form of Neverness to Everness a few days ago (via Gematsu). Neverness to Everness has an urban setting, and the two reveal trailers for it... | Read more »
Meditative Puzzler ‘Ouros’ Coming to iOS...
Ouros is a mediative puzzle game from developer Michael Kamm that launched on PC just a couple of months back, and today it has been revealed that the title is now heading to iOS and Android devices next month. Which is good news I say because this... | Read more »

Price Scanner via MacPrices.net

Amazon is still selling 16-inch MacBook Pros...
Prime Day in July is over, but Amazon is still selling 16-inch Apple MacBook Pros for $500-$600 off MSRP. Shipping is free. These are the lowest prices available this weekend for new 16″ Apple... Read more
Walmart continues to sell clearance 13-inch M...
Walmart continues to offer clearance, but new, Apple 13″ M1 MacBook Airs (8GB RAM, 256GB SSD) online for $699, $300 off original MSRP, in Space Gray, Silver, and Gold colors. These are new MacBooks... Read more
Apple is offering steep discounts, up to $600...
Apple has standard-configuration 16″ M3 Max MacBook Pros available, Certified Refurbished, starting at $2969 and ranging up to $600 off MSRP. Each model features a new outer case, shipping is free,... Read more
Save up to $480 with these 14-inch M3 Pro/M3...
Apple has 14″ M3 Pro and M3 Max MacBook Pros in stock today and available, Certified Refurbished, starting at $1699 and ranging up to $480 off MSRP. Each model features a new outer case, shipping is... Read more
Amazon has clearance 9th-generation WiFi iPad...
Amazon has Apple’s 9th generation 10.2″ WiFi iPads on sale for $80-$100 off MSRP, starting only $249. Their prices are the lowest available for new iPads anywhere: – 10″ 64GB WiFi iPad (Space Gray or... Read more
Apple is offering a $50 discount on 2nd-gener...
Apple has Certified Refurbished White and Midnight HomePods available for $249, Certified Refurbished. That’s $50 off MSRP and the lowest price currently available for a full-size Apple HomePod today... Read more
The latest MacBook Pro sale at Amazon: 16-inc...
Amazon is offering instant discounts on 16″ M3 Pro and 16″ M3 Max MacBook Pros ranging up to $400 off MSRP as part of their early July 4th sale. Shipping is free. These are the lowest prices... Read more
14-inch M3 Pro MacBook Pros with 36GB of RAM...
B&H Photo has 14″ M3 Pro MacBook Pros with 36GB of RAM and 512GB or 1TB SSDs in stock today and on sale for $200 off Apple’s MSRP, each including free 1-2 day shipping: – 14″ M3 Pro MacBook Pro (... Read more
14-inch M3 MacBook Pros with 16GB of RAM on s...
B&H Photo has 14″ M3 MacBook Pros with 16GB of RAM and 512GB or 1TB SSDs in stock today and on sale for $150-$200 off Apple’s MSRP, each including free 1-2 day shipping: – 14″ M3 MacBook Pro (... Read more
Amazon is offering $170-$200 discounts on new...
Amazon is offering a $170-$200 discount on every configuration and color of Apple’s M3-powered 15″ MacBook Airs. Prices start at $1129 for models with 8GB of RAM and 256GB of storage: – 15″ M3... Read more

Jobs Board

*Apple* Systems Engineer - Chenega Corporati...
…LLC,** a **Chenega Professional Services** ' company, is looking for a ** Apple Systems Engineer** to support the Information Technology Operations and Maintenance Read more
Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
*Apple* / Mac Administrator - JAMF Pro - Ame...
Amentum is seeking an ** Apple / Mac Administrator - JAMF Pro** to provide support with the Apple Ecosystem to include hardware and software to join our team and Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.