commit 4e6807c2d76f77694f8c4d4842631305df2fd1ce Author: Jeff Epler Date: Sat Jun 18 12:07:14 2016 -0500 initial commit Signed-off-by: Jeff Epler diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8279703 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +game.bas +game.prg diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..de0f6a0 --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +TOKENIZE=petcat -w2 -l 1001 + +.PHONY: all +all: game.prg + +.PHONY: run +run: game.prg + xvic -autostart $< + +%.bas: %.md + awk 'BEGIN {f=0} {of = f} /^~~~~/ { f = !f; } {if(f && of) print}' < $< | sort -n > $@ +%.prg: %.bas + $(TOKENIZE) -o $@ -- $< diff --git a/README.md b/README.md new file mode 100644 index 0000000..98de6fc --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# VIC 20 Incremental Game + +I still feel nostalgic for 80s Commodore computers, and it's been a goal +for awhile to write an incremental game. So today, the two ideas got +mixed together, to make the VIC 20 Incremental Game. The goal: to buy a +Commodore 64, or else to make the most income you can. + +This game runs in VICE's "xvic" emulating the unexpanded Vic 20. You can +buy over 5 different kinds of expansion items for your Vic 20, which +inexplicably earn you income that lets you buy more items. + +It's not a very *balanced* incremental, but it's also not a bad effort +for part of a saturday morning. (it's also an excellent reminder of just +how far we've come in hardware and software in the last 35 years) + +![The game, in xvic](https://raw.githubusercontent.com/jepler/vicinc/master/vicinc.png) + +# Building and running the software + +The game is implemented in "literate basic", which is a markdown file +full of code-blocks and commentary. On a UNIX-style system with standard +utilities like `awk` and `make` as well as VICE-specific tools like `petcat` +and `xvic`, you can build the whole thing by running `make` (which creates the +tokenized basic program `game.prg`, or run the game with `make run`. In +principle, you could put `game.prg` onto a disk or tape and run it on actual +hardware, but of course I don't own my childhood Vic 20 anymore to try it diff --git a/game.md b/game.md new file mode 100644 index 0000000..85595a3 --- /dev/null +++ b/game.md @@ -0,0 +1,128 @@ +# An incremental game in BASIC for the unexpanded Vic 20 (1980) + +## Variable reference: + - A$(): Name of properties + - N%(): Number of properties + - B(): Base price of property + - P(): Base production of property + - C: Cash on hand + - Q: Quantity to purchase + + - R: Selected row + - M: Max row to display + + - T: time of next tick + + - J, E: used to print numbers (J=number to print) + + - X: total number of items + +## Initial setup +~~~~ +10 print"{clr}" +20 dim a$(10),n%(10),b(10),p(10) +30 c=100:n%(1)=1:q=1:r=1:m=2:t=ti+60:x=7 +40 fori=1tox:reada$(i),b(i),p(i):next +~~~~ + +## These are the properties you can own +~~~~ +60001 data"{blk}c1530 datasette",25,1 +60002 data"{pur}3k ram pack",300,3 +60003 data"{red}vicmodem",900,20 +60004 data"{cyn}8k ram pack",1600,80 +60005 data"{blu}c1540 disk drive",4000,100 +60006 data"{yel}16k ram pack",16000,200 +60007 data"{grn}commodore 64",200000,500 +~~~~ + +## Calculate the price of the next item +"fn pr" is the price function +~~~~ +100 def fn pr(n)=.2*n+.05*n*n+1 +~~~~ + +## The main "event" loop +.. It runs at 1 update per second on an NTSC VIC20 ('ti' increments at 1 per +jiffy) + +~~~~ +1000 gosub 20000 +1010 gosub 21000 +1020 ift0thenr=r-1 +1050 ifc$="b"thengosub23000 +1060 goto1030 +~~~~ + +## Utility functions +###Print a number in exponential notation with up to 3 digits: +~~~~ +10000 e=0:ifj<1thenj=0 +10010 ifj>=1000thene=e+1:j=j/10:goto10010 +10020 j$=mid$(str$(int(j)),2,99) +10030 ifethenj$=str$(int(j)/100)+"e"+mid$(str$(e+2),2,99) +10100 j$=left$(j$+" ",8) +10110 k=int((pos(0)+10)/11)*11+2:printtab(k);j$;:return +~~~~ +In principle, 10100 is an entry point for printing a string but I never used it. + +### Print the main game screen +~~~~ +20000 print "{home}vic20 incremental game":print" accessory":print" price","production":print +20010 fori=1tom:printn%(i);"{left} ";a$(i);"{blu}" +20020 j=fn pr(n%(i))*b(i):ifj" +~~~~ + +### A second has passed, update things +~~~~ +22000 gosub24000:c=c+j +22010 return +~~~~ + +### Buy a thing +~~~~ +23000 ifc + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA diff --git a/vicinc.png b/vicinc.png new file mode 100644 index 0000000..be4684b Binary files /dev/null and b/vicinc.png differ