Author Topic: Shuffleboard testing  (Read 1759 times)

B+

  • Guest
Shuffleboard testing
« on: January 28, 2016, 03:11:41 PM »
Ready for retirement? 

Testing a simple shuffleboard game, any screen (portrait or landscape), flexible font size, any dialect?

This should be easy to translate to your dialects (or PL's) it's pretty basic:
SmallBASIC 0.12.2
Code: [Select]
rem
rem Shuffleboard test by Johnno 2016-01-26
rem 2016-01-26 [B+=MGA] testing on NOOK

rem This is my modified 'friction on ice' program.
rem
rem Very crude version of Shuffleboard - One Player.
rem
rem Press and hold the SPACE key to release.
rem Press too long and you lose a life.
rem
rem 27 Jan 2016 - modified to fit screen width
rem
rem 2016-01-27 {MGA fork} convert all Y dimensions in terms of text height
rem ''''''''''''''''''''' convert lives to 10 shots then game over (added with stripe)
rem ''''''''''''''''''''' add mouse support, trim down code

const yellow = rgb(255,255,0)
const darkyellow = rgb(220,220,80)
const magenta = rgb(255,0,255)
const cyan = rgb(0,255,255)
const red = rgb(255,0,0)
const grey = rgb(128,128,128)
const blue = rgb(0,0,255)
const darkblue = rgb(0,0,128)
const orange = rgb(255,128,0)
const black = rgb(0,0,0)
const green = rgb(0,255,0)
const white = rgb(255,255,255)
const limit = xmax*.980
const th=txth("By")
const spacebar="Tap/Click/Drag/SPACEBAR(PC)... not too long"
cls

posX = th
posY = 7*th
score = 0
lives = 10
shot = 0
XVel = 0

sub center(lineNum,txt)
  at xmax/2 - txtw(txt)/2,linenum*th : ? txt
end

sub stripe(tlXfracXmax)
  rect xmax*tlXfracXmax,2*th,xmax*tlXfracXmax+.005*xmax,11*th filled
end

sub updateStats
  color yellow,black
  center(14,"Score: " + str(score))
  color green,black
  center(16,"Shots: " + str(lives))
  color white,black
  center(18,spacebar)
end

sub updateBoard
  rect 0,0,xmax,2*th,blue filled
  rect .25*th,.25*th,xmax-.25*th,1.75*th,darkblue filled
  rect 0,11*th,xmax,13*th,blue filled
  rect .25*th,11.25*th,xmax-.25*th,12.75*th,darkblue filled
 
  color white,black
  stripe .2
  at int(xmax*.25),3*th: print "10"
 
  color grey,black
  stripe .3
  at int(xmax*.35),3*th: print "20"
 
  color orange,black
  stripe .4
  at int(xmax*.45),3*th: print "30"
 
  color blue,black
  stripe .5
  at int(xmax*.55),3*th: print "40"
 
  color green,black
  stripe .6
  at int(xmax*.65),3*th: print "55"

  color cyan,black
  stripe .7
  at int(xmax*.75),3*th: print "75"
 
  color magenta,black
  stripe .8
  at int(xmax*.85),3*th: print "100"
 
  color yellow,black
  stripe .9
  at int(xmax*.95),3*th: print "-25"
  at int(xmax*.15),3*th: print "-25"

  color red,black
  center(21, "WARNING: Hit Red Stripe -50 !")
  stripe .995
end

sub updatePlayer
  pen on
  k = inkey
  if k=" " or pen(3)=1  and posX < xmax/2 then
    XVel = XVel + 0.8
    delay 30
  endif
  pen off
  XVel = XVel * 0.98
  posX = posX + XVel
  posX = int(posX)
  posY = int(posY)
  'pause
  if posX > 2*th and XVel < 1 then XVel = 0
  if posX >= limit then
    color red,black
    posX = limit
    delay 1000
    score-=50
    lives-=1
    if lives=0 then gameover
    posX = th
    XVel = 0
  end if
  circle posX,posY,th,1,yellow filled
  circle posX,posY,.75*th,1,orange filled
end

sub updateScore
  if XVel=0 and posX>th then
    if posX>xmax*.9 and posX<limit-5 then
      score-=25
      elif posX>xmax*.8
        score+=100
      elif posX>xmax*.7
        score+=75
      elif posX>xmax*.6
        score+=55
      elif posX>xmax*.5
        score+=40
      elif posX>xmax*.4
        score+=30
      elif posX>xmax*.3
        score+=20
      elif posX>xmax*.2
        score+=10
      else
        score-=25 
      end if
      delay 1000
      posX=th
      lives-=1
      if lives=0 then gameover
      'at posX-th,posY+th:? int(posX)
  endif
end

sub Gameover
  color 15,0
  center(18,space(len(spacebar)+2))
  center(18,"Game Over, press any...")
  showpage
  pause
end

'Main ==================================================

while lives > 0
  cls
  updateStats
  updateBoard
  updatePlayer
  updateScore
  showpage
  delay 15
wend

notes:
xmax, ymax are built in constants so use your screen width and height there (pixels)
txth(string) will return pixel height of current font loaded, you can set yours manually if not similar function
txtw(string) as above for width
pen on/off you wont likely need
pen(3) is left mouse button 0/1, T/F
showpage is same as screenswap, redraw... or whatever you use to update screen with new text or graphics
pause waits for user key press
delay is wait time in ms approx
elif is elf with i ? no silly, is elseif
circle uses aspect for ellipsis, 1 is just a circle, syntax: circle x, y, r, [aspect, [color... ] [filled]
at x,y locates AT x,y (pixels) for print ( ? short version of print)

Current tests show a great discrepancy between using the spacebar, the mouse button down, and pointing device (your finger on screen) on NOOK (Android device).

Any ideas or suggestions for more consistent results between pointing systems, devices and OS would be appreciated.

Thanks