$options +optimize, optimize=-convert_percent-const_replace
$define scrY = 184
'scrY = 192-8: 'last line reserver for score display
$define scrX = 320
MUSIC=adr("\60\05\A2\02\A2\10\79\02\6C\02\60\02\5B\02\5B\01\51\09\5B\02\60\02\5B\04\60\02\6C\02\60\04\6C\02\79\04\6C\01\60\05\A2\02\A2\0E\79\02\79\02\6C\02\60\02\5B\02\5B\01\51\09\5B\02\60\02\5B\04\60\02\6C\02\60\04\6C\02\79\04\5B\01\51\03\51\02\51\06\51\02\4C\04\51\04\66\0A\5B\01\51\03\51\02\51\04\4C\04\5B\12\5B\01\51\01\51\04\51\06\44\02\4C\04\51\0A\5B\02\66\02\5B\01\51\03\51\04\51\04\55\01\4C\03\5B\04\5B\04\66\04\6C\04\79\06\51\02\51\12\5B\02\60\02\5B\04\60\02\6C\02\60\04\6C\02\79\02\6C\0A\60\02\5B\02\60\02\6C\02\79\06\51\02\51\12\5B\02\60\02\5B\04\60\02\6C\02\60\04\6C\02\79\02\6C\12")
gr.8+16
poke 710,0
hlen = fre(0)-666
dim hist$(hlen)
hadr=adr(hist$)
color 1
repeat
	read x,y,hist$
	text x,y,hist$
until hist$(len(hist$))="."
data 90,0,Neverending Sorry,10,20,Tale of Atreyu and his dragon Falkor,20,60,The Nothing took over Fantastica,40,80,You - Atreyu - must lead Falkor,10,100,through The Nothing to find shards of,120,120,***Auryn***,123,123,***Auryn***

	for i=MUSIC to MUSIC+192 step 2:'to MUSIC+mlen-2
		m=peek(i)
		p=peek(i+1)
		for plum=15 to 5 step -3
			sound 0,m,10,plum
		next plum
		pause p*3
		if not strig(0):exit:endif
	next i
	sound
gr.8+16
poke 710,0
hpointer = 0
htail = 0
hskip = 5
hjoy = 14 :'up up up
dy = -1   :'up up up
points = -1
x=100:y=100 :'starting point
hx=x:hy=x :'historical x and y
px=x:py=100-5
plot px,py :'so first shard gets placed
text 0,@scrY,"Auryns:":'"Auryn shards collected: ";
music_pointer = MUSIC
do
	'check for death or point
	locate x,y,v
	if v
		if x=px and y=py
			'ate Auryn shard
			points=points+1
			hskip = 1
			'proc place_orb
			do
				px = rand(@scrX)
				py = rand(@scrY)
				locate px,py,v
				if not v
					exit
				endif
			loop
			'play sound
			m=peek(music_pointer)
			for plum=15 to 2 step -1
				sound 0,m,10,plum
			next plum
			music_pointer = music_pointer + 2
			if music_pointer > MUSIC + 192
				music_pointer = MUSIC
			endif
			
			c.1:plot px,py
			text 64,@scrY,points :'"Auryn shards collected: ";
			'endproc
		else
			sound
			color 1
			text 100,@scrY,"Falkor! I failed you!"
			while strig(0):wend
			while not strig(0):wend
			'proc replay
			x=100:y=100 :'starting point
			for hpointer = hadr to hadr+len(hist$)
				'drawing history of the moves optimised for speed
				plot x,y
				s=peek(hpointer)
				x=x+(s=7)-(s=11)
				y=y+(s=13)-(s=14)
				if x=-1: x=@scrX-1:endif
				if x=@scrX: x=0:endif
				if y=-1:y=@scrY-1:endif
				if y=@scrY:y=0:endif
				if not strig(0):exit:endif
			next hpointer
			text 100,@scrY,"--Breath Fire Again--"
			pause 20
			while strig(0):wend
			run
		endif
	endif
	'--------------------------
	color 1
	plot x,y
	s=stick(0)
	'j == [-1 | 0 | +1] 
	jx=(s=7)-(s=11)
	jy=(s=13)-(s=14)
	'chck if joystick moved
	if jx<>jy 
		dx=jx:dy=jy
		hjoy = s
		sound 0,rand(5),0,rand(2)+1
	endif
	x=x+dx:y=y+dy
	'save flying history
	hpointer = (hpointer + 1) mod hlen
	hist$(hpointer,hpointer) = chr$(hjoy)
	'erase tail
	if not hskip
		color 0: plot hx,hy
		s=asc(hist$(htail+1))
		jx=(s=7)-(s=11)
		jy=(s=13)-(s=14)
		hx=hx+jx:hy=hy+jy
		'?x;" ";y;" ";hx;" ";hy;" ";jx;" ";jy
		hx = hx + @scrX*((hx=-1) - (hx=@scrX))
		hy = hy + @scrY*((hy=-1) - (hy=@scrY))
	else
		hskip = hskip-1
		htail = htail-1
	endif
	htail = (htail +1) mod hlen
	
	
	'check for wrapping around screen
	x = x + @scrX*((x=-1) - (x=@scrX))
	y = y + @scrY*((y=-1) - (y=@scrY))
loop
data 10,140,After time The Nothing changes colors,18,160,to intimidate you. But feel no fear,10,180,young warrior and fight for Empress...
