#################################
# BASIC Tenliners Contest 2018  #
#                               #
# Bitcoin Miner                 #
# (c) 2018 Roman Werner @romwer #
# email: roman.werner@gmail.com #
#################################

Oh no! You are just starting up your new shiny gamer PC with the latest high-end graphic card when you hear your mother say:
"Oh honey, by the way, when your father comes back from the dump, don't forget to thank him for getting rid of your old laptop".
"Yes, yes, sure mom, but do you know where my hard disk is, that I told him to take out?".
"Of course, honey, there it is, on the table".
"Mom ... this is a Compact Disc".
Only slowly you realize that your Bitcoins that you had mined over the last 9 years became a victim of simple misunderstanding.

Newport, South Wales, UK. It's 23:45 near a landfill.
You just made it over the fence standing there in your rubber boots ready with your pickaxe.
You've got a goal: Find the remains of your hard drive and get back your Bitcoins that are currently worth $80 million.
But better be quick, because the security guard shortly begins to make his round...


Task and Goal
=============
- Dig yourself through the landfill ground and collect the bitcoins you find on the way.
- Beware of the security guard following you. If he catches up - the game is over.
- There is no way back - you can only move directions other than the way you came from.
- Plan your next steps carefully otherwise you may dig yourself a dead end.
- The more bitcoins you collect, the higher your adrenaline rises. So, don't panic and keep calm.
- After 10 bitcoins you call it a day, have some sleep and return again the next night.


Control:
========
<space bar> on keyboard -or- fire button* (Joystick port 1)
Keep pressing to dig in the direction where the pickaxe (#) points to.

* This game is also compatible with the official SiBUGA (Single Button Game) controller - let me know if you like one :)


Game Requirements:
==================
- C64/C128* with BASIC 2.0 runtime environment (or compatible)
- 1 Player

*Also playable on Windows/MacOS/iOS/Android (C64 Emulator required)


Starting in VICE: C64 emulator (http://vice-emu.sourceforge.net/):
==================================================================
Start the emulator and then drag and drop the "bitcoinminer.prg" into the VICE window.
-or-
Load the program with the command: load "bitcoinminer.prg",8
Then start the program with:       run


BitcoinMiner BASIC program code:
================================
0m=53280:pOm,0:pOm+1,0:k=203:o(0)=-1:o(1)=-40:o(2)=1:o(3)=40:c=54272:dIx(800)
1l=0:n=0:u=6:f=0:a=32:e=64:b=10:r=a:s=1124:t=s:?"{light blue}{clear} {purple}bitcoins"h:?"{down}{down} ";:fOi=1to6
2l=l+1:fOj=1tol:fOg=1to19:?mI("{green}{brown}{orange}{light gray}{gray}{dark gray}",l,1)"{reverse on}  {reverse off}";:nE:?"  ";:nE:nE:fOi=0to9
3t(i)=1204+int(rN(1)*800):on-(pE(t(i))=a)gO3:pOt(i),81:pOc+t(i),7:nE:pOs,88
4d=(d+1)aN3:q=s+o(d):r=pE(q):on-(r=a)gO8:u=6:pOq,35:fOi=1toe-h:ifpE(k)=etHnE:gO8
5p=s+o(d):on-(pE(k)=e)gO4:on-(pE(p)=a)gO5:x(n)=s:s=p:n=n+1
6fOi=0to9:ift(i)=ptHt(i)=0:b=b-1:h=h+1:?"{home}{purple}{reverse off}"tA9)h
7nE:pOs,88:pOc+s,14:pOt,a:t=s:on-(b=0)gO1:gO5
8pOq,r:u=u-1:onugO9:on-(n<b)gO4:f=f+1:pOx(f-1),a:pOx(f),88:pOc+x(f),2:iff<n-1gO4
9?"{home}"tA30)"{red}game over":pO162,0:wA162,64:?tA15)"{yellow}try again ?":wAk,60:h=0:gO1

Tip: Copy/paste the program-Code into CBM prg Studio (http://www.ajordison.co.uk/).
There you can see the commands in nice color highlighting and you can directly execute the game in an emulator of your choice.


Bitcoin Miner Tenliner explained (000=row 0/100=row 1/...):
===========================================================
000 m=53280: rem base address for border/background-color
001 pokem,0: rem set border color to black
002 pokem+1,0: rem set background color to black
003 k=203: rem zeropage address for currently pressed keycode
004 o(0)=-1: rem pickaxe offset left (no of chars to be added to the player position
005 o(1)=-40: rem above
006 o(2)=1: rem right
007 o(3)=40: rem below
008 c=54272: rem color ram (55296-1024) so that video ram address can be added to it
009 dimx(800): rem array to store passed video ram addresses so that the guard can follow

100 l=0: rem ground layer counter (green, brown, orange, light gray, gray, dark gray)
101 n=0: rem steps counter of player
102 u=6: rem counter to check if there is no remaining way out. will jump to game over when 1.
103 f=0: rem steps counter of guard
104 a=32: rem constant for space character
105 e=64: rem constant for no key pressed as in peek(203)
106 b=10: rem no of bitcoins
107 r=a: rem store character that is in place where pickaxe (#) is being drawn
108 s=1124: rem start position in screen ram for player character
109 t=s: rem remember last position before move
110 print"{light blue}{clear} {purple}bitcoins"h: rem fill color ram with light blue and print score
111 print"{down}{down} ";: rem position cursor to rows down in order to draw ground layers
112 fori=1to6: rem print 6 layers in total

200 l=l+1: rem add 1 to the color index (used in the mid$ below)
201 forj=1tol: rem print layer 1 with a width of 1 line, layer 2 with 2 lines, etc.
202 forg=1to19: rem print 19x2=38 reversed space
203 printmid$("{green}{brown}{orange}{light gray}{gray}{dark gray}",l,1)"{reverse on}  {reverse off}";
204 next
205 print"  ";: rem move to the next line(this left and right space stops player from walking)
206 next
207 next
208 fori=0to9: rem for 10 bitcoins...

300 t(i)=1204+int(rnd(1)*800): rem calculate a random screen ram location
301 on-(peek(t(i))=a)goto300: rem if it hit a space character try again
302 poket(i),81: rem place a round symbol for bitcoin
303 pokec+t(i),7: rem make it yellow
304 next
305 pokes,88: rem put player character at the top middle screen position.

400 d=(d+1)and3: rem counter 1,2,3,4=0,1,2,3,4=0,etc. to loop through pickaxe index
401 q=s+o(d): rem calculate screen offset
402 r=peek(q): rem get character at screen offset
403 on-(r=a)goto800: rem if character is space then do not show pickaxe at that position and continue with guard AI
404 u=6: rem reset no-remaining-way-out counter to 6 because there is a character to dig
405 pokeq,35: rem show the pickaxe symbol (#) at the screen offset
406 fori=1toe-h: rem main-loop speed delay - delay will get shorter with each bitcoin picked up
407 ifpeek(k)=ethennext:goto800: rem if no key press then continue until delay loop finished. Then continue with guard AI

500 p=s+o(d): rem get screen position at pickaxe offset
501 on-(peek(k)=e)goto400: rem when key is released go back to show pickaxe swing
502 on-(peek(p)=a)goto500: rem when that screen position is a space then do nothing
503 x(n)=s: rem add the old screen position to the track of passed screen addresses
504 s=p: rem assign new screen position
505 n=n+1: rem increase step counter

600 fori=0to9: rem for 10 bitcoins check if it matches with new screen position.
601 ift(i)=pthent(i)=0:b=b-1:h=h+1:print"{home}{purple}{reverse off}"tab(9)h: rem If so then mark bitcoin as picked up

700 next
701 pokes,88: rem show player symbol at new screen position
702 pokec+s,14: rem make it light blue
703 poket,a: rem place space character at previous screen position
704 t=s: rem store new screen position as previous screen position
705 on-(b=0)goto100: rem when all bitcoins have been picked up go to next level
706 goto500: rem otherwise make next step in the given direction

800 pokeq,r: rem restore character that was saved before pickaxe was placed on top of it
801 u=u-1: rem count down how many times no ground element was found
802 onugoto900: rem reaching 1 means no ground element left to dig so: game over
803 on-(n<b)goto400: rem as long as player has not made more than 10 steps ignore guard logic
804 f=f+1: rem increase step counter of guard
805 pokex(f-1),a: rem place space character at previous guard position
806 pokex(f),88: rem show guard character at screen address of current guard step index
807 pokec+x(f),2: rem make this one dangerously red
808 iff<n-1goto400: rem as long as step counter of guard is smaller than player step counter, continue with main loop

900 print"{home}"tab(30)"{red}game over": rem print "game over" in the top right corner
901 poke162,0: rem set timer address to 0
902 wait162,64: rem wait until timer has counted to 64 (about 1 second)
903 printtab(15)"{yellow}try again ?": rem print "try again ?"
904 waitk,60: rem wait until a key is pressed
905 h=0: rem reset no of collected bitcoins
906 goto100: rem restart game


Variables used in the code
==========================
a = constant value 32 (peek/poke value of the space character)
b = bitcoin cointer (starting with 10)
c = constant base address 54272 (=55296-1024) to calculate color ram offset
d = counter for pickaxe offset index o(d)
e = constant value 64 (peek value for no key pressed)
f = steps counter of guard
g = temporary variable used as for/next loop counter
h = counter of collected bitcoins
i = temporary variable used as for/next loop counter
j = temporary variable used as for/next loop counter
k = zeropage address 203 for currently pressed keycode
l = ground layer counter when constructing landfill
m = base address for border/background-color
n = steps counter of player
o() = direction offset (0-3) for next pickaxe position
p = screen position at pickaxe offset
q = previous screen position at pickaxe offset
r = character that was saved before pickaxe was placed on top of it
s = position in screen ram for player character
t = last player position in screen ram before move
u = counter how many times no ground element was found
x() = screen positions of player steps

Trivia
======
- After the "sports simulation" ;) Golf64 I wanted to make a game that was a bit more colorful and arcade-like.
- I first wanted to use water filling out the mine instead of a following guard but the mechanics allowed me then to dig through the water.
- There is a glitch: you may be able to run over the guard when he passes you. Sometimes this is the only way to save you from game over.
- Apparently there really are bitcoins worth $80 million hidden somewhere on a landfill in Newport, South Wales.

Tools Used
==========
- VICE 2.4 (http://vice-emu.sourceforge.net/)
- CBM prg Studio V3.12.1 BETA 6 by Arthur Jordison (http://www.ajordison.co.uk)


