`------------------------------------
` TITLE
`------------------------------------
remstart
Jack and the Beanstalk
by OBese87
started: 15th July 2007
finished:
remend
 
`------------------------------------
` SETUP
`------------------------------------
hide mouse
sync on : sync rate 30
gosub get_images
Jx = 320
DIM cloud(4)
 
`------------------------------------
` GAME LOOP
`------------------------------------
gosub story
 
 
DO
cls
   `landscape
   ink rgb(0,20,50),0
   box 0,0,639,300
   ink rgb(90,60,0),0
   box 0,300,639,479
 
gosub display
gosub rain
gosub info
 
if Rightkey()= 1 and Jx <=600 then inc Jx,10
if Leftkey()= 1 and Jx >=40 then dec Jx,10
if spacekey()= 1 and Jwater= 5 and ABS(Jx-320) < 20 then Jwater= 0 : inc Bgrowth,1
if Bgrowth = 5 then center text 320,240,"YOU DID IT! WELL DONE!" : sync : END
if Rfall# > 99 then center text 320,240,"YOU FAILED! TOO BAD." : sync : END
 
sync
LOOP
 
END
 
`------------------------------------
` DATA
`------------------------------------
rem JACK (7x12)
data 0,0,0,1,0,0,0
data 0,0,1,2,1,0,0
data 0,0,2,2,2,0,0
data 0,0,0,2,0,0,0
data 0,0,3,3,3,0,0
data 0,3,0,3,0,3,0
data 7,7,7,7,7,7,7
data 0,2,7,7,7,2,0
data 0,0,7,7,7,0,0
data 0,0,4,0,4,0,0
data 0,0,4,0,4,0,0
data 0,0,4,0,4,0,0
rem FULL JACK (7x12)
data 0,0,0,1,0,0,0
data 0,0,1,2,1,0,0
data 0,0,2,2,2,0,0
data 0,0,0,2,0,0,0
data 0,0,3,3,3,0,0
data 0,3,0,3,0,3,0
data 7,4,4,4,4,4,7
data 0,2,7,7,7,2,0
data 0,0,7,7,7,0,0
data 0,0,4,0,4,0,0
data 0,0,4,0,4,0,0
data 0,0,4,0,4,0,0
 
rem Beanstalk (10x13)
data 0,6,6,0,6,6,0,0,0,0
data 6,6,0,6,6,6,0,0,0,0
data 0,0,0,0,6,6,0,0,0,0
data 0,0,0,0,6,6,0,0,0,0
data 0,0,0,0,6,6,0,0,0,0
data 0,0,0,0,6,6,0,0,0,0
data 0,0,0,0,6,6,0,6,6,0
data 0,0,0,0,6,6,6,0,6,6
data 0,0,0,0,6,6,0,0,0,0
data 0,0,0,0,6,6,0,0,0,0
data 0,0,0,0,6,6,0,0,0,0
data 0,0,0,0,6,6,0,0,0,0
data 0,0,0,0,6,6,0,0,0,0
data 0,0,0,0,6,6,0,0,0,0
 
`rem Bone (10x8)
data 0,7,7,0,0,0,0,0,0,0
data 7,7,7,0,0,0,0,0,0,0
data 7,7,7,7,0,0,0,0,0,0
data 0,0,0,0,7,7,0,0,0,0
data 0,0,0,0,0,0,7,7,7,7
data 0,0,0,0,0,0,0,7,7,7
data 0,0,0,0,0,0,0,7,7,0
 
`rem Egg (8x5)
data 0,0,0,8,8,8,8,0
data 0,8,8,8,8,8,8,8
data 8,8,8,8,8,8,8,8
data 0,8,8,8,8,8,8,8
data 0,0,0,8,8,8,8,0
 
rem rain1 (1x3)
data 4
data 4
data 4
rem rain2 (5x2)
data 4,0,4,0,4
data 0,4,0,4,0
rem rain3 (7x2)
data 0,0,4,0,4,0,0
data 4,0,0,0,0,0,4
 
rem Cloud (14x7)
data 0,0,0,0,0,0,7,7,7,7,0,0,0,0
data 0,0,0,0,7,7,7,7,9,7,7,0,0,0
data 0,0,7,7,7,7,7,9,7,9,7,0,0,0
data 0,7,7,7,9,9,7,7,7,9,7,7,9,0
data 7,7,7,9,9,7,7,7,9,7,9,7,9,9
data 7,7,7,7,7,7,9,9,9,7,7,9,9,9
data 0,9,9,9,7,9,9,9,7,9,9,9,9,0
 
`------------------------------------
` GOSUBS
`------------------------------------
Story:
ts = 20
ink rgb(255,255,255),0
center text 320,ts*0,"JACK & THE BEANSTALK"
center text 320,ts*2,"Once upon a time, there was a boy named Jack, who had some magic beans..."
center text 320,ts*3,"Now here's the part you didn't know. The beanstalk didn't just grow that high over night!"
center text 320,ts*4,"Where do ya think Jack lived? The Amazon! No he lived... somewhere. Anyway it was the middle"
center text 320,ts*5,"of summer and there was barely any rain at all. The forecast shows only 10mm of rain!"
center text 320,ts*6,"Move Jack using the arrow keys to catch the rain and water the beanstalk with SPACE when your"
center text 320,ts*7,"bucket is full. You must get the beanstalk to grow up into the sky before 10mm of rain has fallen."
sync
wait key
cls
RETURN
 
Get_Images:
for item = 1 to 9
   `set image boundaries
   select item
      case 1 : maxy = 11 : maxx = 6 : endcase : `jack
      case 2 : maxy = 11 : maxx = 6 : endcase : `jackfull
      case 3 : maxy = 12 : maxx = 9 : endcase : `beanstalk
      case 4 : maxy = 7 : maxx = 9 : endcase : `bone
      case 5 : maxy = 4 : maxx = 7 : endcase : `egg
      case 6 : maxy = 2 : maxx = 0 : endcase : `rain1
      case 7 : maxy = 1 : maxx = 4 : endcase : `rain2
      case 8 : maxy = 1 : maxx = 6 : endcase : `rain3
      case 9 : maxy = 6 : maxx = 13 : endcase : `cloud
   endselect
   `draw item
   for y = 0 to maxy
      for x = 0 to maxx
         read cn
         col = colour(cn) : `decode colour
         ink col,0
         dot x,y
      next x
   next y
   get image item, 0,0,maxx+1,maxy+1
   cls
next item
RETURN
 
Rain:
`move clouds
inc Cmove,1
for c = 1 to 4
   cloud(c) = sin(cmove*c)*300 +320
next c
`create rain
if rain =0
   rain=1 : Rx = cloud(rnd(3)+1) : Ry = 0 : Ri = 6 : show sprite 3
endif
`rain fall
if rain =1
   if Ry <= 340
      if Ry >= 300 and ABS(Jx-Rx)<14 and Jwater<5 then inc Jwater,1 : rain=0 : inc Rfall#,0.1
      inc Ry,15
   else
      if Ri<8 then inc Ri,1 else hide sprite 3 : rain=0 : inc Rfall#,0.1 : `splash
   endif
endif
RETURN
 
Display:
for stalk = 0 to Bgrowth
   sprite 7+stalk,320,280-(52*stalk),3 :`beanstalk
next stalk
sprite 1,Jx,300,1+(Jwater/5) : `jack
sprite 2,Rx,Ry,Ri : `rain
for c = 1 to 4
   sprite 2+c,cloud(c),0,9 : `cloud
next c
for spr = 1 to 13
   if sprite exist(spr)
      scale sprite spr,400 : offset sprite spr,sprite width(spr)/2,0
   endif
next spr
RETURN
 
Info:
ink 100,0
box 0,0,200,60
ink rgb(255,255,255),0
set cursor 0,450
Print "Total Rainfall: "; Rfall# ; "mm/10.0mm"
RETURN
 
`------------------------------------
` FUNCTIONS
`------------------------------------
rem #Colour Decoder Function
FUNCTION Colour(num)
  select num
   case 1 : col = rgb(255,255,70) : endcase : `blonde
   case 2 : col = rgb(255,140,160) : endcase : `pink
   case 3 : col = rgb(220,0,0) : endcase : `red
   case 4 : col = rgb(0,100,255) : endcase : `blue
   case 5 : col = rgb(120,80,0) : endcase : `brown
   case 6 : col = rgb(30,255,0) : endcase : `green
   case 7 : col = rgb(200,200,200) : endcase : `white
   case 8 : col = rgb(255,200,0) : endcase : `gold
   case 9 : col = rgb(100,100,100) : endcase : `grey
   case default : col = 0 : endcase : `black
 endselect
ENDFUNCTION col