Author Topic: SB demo  (Read 2419 times)

B+

  • Guest
SB demo
« on: September 19, 2018, 03:13:44 PM »
Picking up on topic started here: http://retrogamecoding.org/board/index.php?topic=700.0

I have written, Infinite Pong The Movie SB.txt, for SB.exe interpreter. Pretty sure it is a BASIC because it was build in QB64 and I don't know any other PL's other than BASIC to build an Interpreter.

What does SB stand for? Shorthand Basic, Still-another-small-Basic, Santa Basic (love it thanks John!) or just plain 'ol Sh*t Basic  ;D

Without further ado and for your enjoyment here is "Infinite Pong the Movie":
Code: [Select]
Infinite Pong the Movie (for SB by B+ 2018-09-19)

constants
n p1y 2
n p2y 43
n pw 10

ball
n bx 75
n by 20
n bdx 2
n bdy 1

main
[
c
gs P1
gs P2
gs B
w .1
]

s P1
n p1x bx - 5
l p1y p1x
; 1111111111
r

s P2
n p2x bx - 5
l p2y p2x
; 2222222222
r

s B
i bx + bdx < 7
n bdx bdx * -1 + int(rnd * 3) - 1
f
i bx + bdx > 143
n bdx bdx * -1 + int(rnd * 3) - 1
f
i by + bdy < 3
n bdy bdy * -1
n bdx bdx + int(rnd * 3) - 1
f
i by + bdy > 42
n bdy bdy * -1
n bdx bdx + int(rnd * 3) - 1
f
n bx bx + bdx
n by by + bdy
l by bx
; O
r

To avoid a straight up, straight down repeat... until bored, I added a little randomness to each bounce.

I will translate this into sb or QB64 or JB for others to enjoy.

PS I am pleased as punch that I had to slow the sucker down with a
Code: [Select]
w .1 statement!
« Last Edit: September 19, 2018, 03:17:26 PM by B+ »

B+

  • Guest
Re: SB demo
« Reply #1 on: September 19, 2018, 04:11:27 PM »
For Richey here is Infinite Pong the Movie in JB v2.0 though the version wont matter here:
Code: [Select]
' translated to JB (v2.0 but version wont matter here) from
' Infinite Pong the Movie (for SB by B+ 2018-09-19)

' Under JB IDE Menu check or reset Columns and Rows to at least
' Setup > Prefernces Main Winow Columns 80 Rows 30

'constants
p1y = 2
p2y = 28
pw = 10

'ball
bx = 30
by = 14
bdx = 2
bdy = 1

'main
Do
    Scan
    Cls
    Gosub [P1]
    Gosub [P2]
    Gosub [B]
    Call Pause 60
Loop Until theCowsComeHome

[P1]
    p1x = bx - 5
    Locate p1x, p1y
    Print "1111111111";
Return

[P2]
    p2x = bx - 5
    Locate p2x, p2y
    Print "2222222222";
Return

[B]
    If bx + bdx < 7 Then
        bdx = bdx * -1 + Int(Rnd(0) * 3) - 1
    End If
    If bx + bdx > 73 Then
        bdx = bdx * -1 + Int(Rnd(0) * 3) - 1
    End If
    If by + bdy < 3 Then
        bdy = bdy * -1
        bdx = bdx + Int(Rnd(0) * 3) - 1
    End If
    If by + bdy > 27 Then
        bdy = bdy * -1
        bdx = bdx + Int(Rnd(0) * 3) - 1
    End If
    bx = bx + bdx
    by = by + bdy
    Locate bx, by
    Print "O";
    Locate 1, 1  'EDIT: a little fix to get rid of line stuck to ball
Return

sub Pause mil   'tsh version has scan built-in
    t0 = time$("ms")
    while time$("ms") < t0 + mil : scan : wend
end sub


Edit: see EDIT: comment in code.
« Last Edit: September 19, 2018, 04:38:27 PM by B+ »

B+

  • Guest
Re: SB demo
« Reply #2 on: September 19, 2018, 06:20:16 PM »
A condensed version for SmallBASIC:
Code: [Select]
'Infinite Pong the Movie.bas for SmallBASIC v 0.12.13 B+ 2018-09-19
' have window opened enough for 105 char cells across and 31+ down
p1y = 1 : p2y = 30 'paddle y
bx = 50 : by = 20 : bdx = 2 : bdy = 1  'ball x, y, dx, dy
while 1
    Cls
    p1x = bx - 5 : Locate p1y, p1x : Print "1111111111"; ' draw paddle 1
    p2x = bx - 5 : Locate p2y, p2x : Print "2222222222"; ' draw paddle 2
    If bx + bdx < 7 Then bdx = bdx * -1 + Int(Rnd * 3) - 1
    if bx + bdx > 100 Then bdx = bdx * -1 + Int(Rnd * 3) - 1
    if by + bdy < 2 Then bdy = bdy * -1 : bdx = bdx + Int(Rnd * 3) - 1
    if by + bdy > 29 Then bdy = bdy * -1 : bdx = bdx + Int(Rnd * 3) - 1
    bx = bx + bdx : by = by + bdy
    Locate by, bx : Print "O";
    Delay 60
wend

And QB64 version:
Code: [Select]
_TITLE "Infinite Pong the Movie.bas for QB64 B+ 2018-09-19"
p1y = 1: p2y = 25 'paddle y
bx = 30: by = 10: bdx = 2: bdy = 1 'ball x, y, dx, dy
WHILE 1
    CLS
    p1x = bx - 5: _PRINTSTRING (p1x, p1y), "1111111111" ' draw paddle 1
    p2x = bx - 5: _PRINTSTRING (p2x, p2y), "2222222222" ' draw paddle 2
    IF bx + bdx < 6 THEN bdx = bdx * -1 + INT(RND * 3) - 1
    IF bx + bdx > 74 THEN bdx = bdx * -1 + INT(RND * 3) - 1
    IF by + bdy < 2 THEN bdy = bdy * -1: bdx = bdx + INT(RND * 3) - 1
    IF by + bdy > 24 THEN bdy = bdy * -1: bdx = bdx + INT(RND * 3) - 1
    bx = bx + bdx: by = by + bdy
    _PRINTSTRING (bx, by), "O"
    _LIMIT 10
WEND
« Last Edit: September 19, 2018, 06:50:05 PM by B+ »

Richly

  • Guest
Re: SB demo
« Reply #3 on: September 19, 2018, 09:34:08 PM »
For Richey here is Infinite Pong the Movie in JB v2.0 though the version wont matter here:

Thank you B+  :)

ScriptBasic

  • Guest
Re: SB demo
« Reply #4 on: September 20, 2018, 03:14:26 AM »
Here is a SB PONG example using Peter Wirbelauer's Simple Windows library. Note that this is really old code. (March 2013 - running on XP) Being a GUI program using a traditional console scripting language and with sound in the amount of code used made Peter's library a good candidate for beginners.



Code: [Select]
' ScriptBasic PONG by Peter Wirbelauer
 
INCLUDE "sbsw.inc"
 
SW_Window 320, 240, 1
SW_SetCaption "ScriptBasic Pong"
 
SW_SetFPS 60
 
SPLIT "50, 50, 130, 150, 2, 2, 2, 1, 0" BY "," TO x, y, x2, y2, pspeed, xadj, yadj, delay, score
 
haha = "wav/haha.wav"
pong = "wav/pong.wav"
 
WHILE SW_Key(27) = 0
  SW_Cls SW_RGB(200, 200, 247)
  SW_FillCircle x, y, 8, SW_RGB(0, 0, 255)
  SW_FillBox x2, y2, 30, 4, SW_RGB(255, 255, 255)
  SW_Box 20, 20, 280, 160, 4, SW_RGB(255, 255, 0)
  SW_SetText 10, 0, "SCORE:" & score, SW_RGB(255, 0, 0)
  IF y <= 20 THEN
    yadj = 1
    SW_PlayWav pong
  END IF
  IF y >= 180 THEN
    yadj = -1
    SW_PlayWav pong
  END IF
  IF x >= 300 THEN
    xadj = -1
    SW_PlayWav pong
  END IF
  IF x <= 20 THEN
    xadj = 1
    SW_PlayWav pong
  END IF
  IF SW_Key(37) AND x2 > 18 THEN x2 = x2 - pspeed
  IF SW_Key(39) AND x2 < 270 THEN x2 = x2 + pspeed
  x += xadj
  y += yadj
  IF y > y2 - 7 AND y2 < y2 + 2 AND x < x2 + 30 AND x > x2 THEN
    yadj = -1
    score += 1
  END IF
  IF y > y2 + 10 THEN
    SW_SetText 100, 200, "GAME OVER!", SW_RGB(0, 160, 55)
    SW_Playwav haha
    SW_Waitkey
    SPLIT "0, 50, 50, 130, 150" BY "," TO score, x, y, x2, y2
  END IF
  SW_Sync
WEND
SW_CloseWindow
« Last Edit: September 20, 2018, 06:47:10 AM by John »

ScriptBasic

  • Guest
Re: SB demo
« Reply #5 on: September 20, 2018, 05:55:08 AM »
B+,

Tomaaz said he didn't like Script BASIC because there was no install program for Linux and was confused how to include the SB executable path or create the configuration file. I  would have been happy to help him get going if he would have asked.

What don't you like about Script BASIC?
« Last Edit: September 20, 2018, 06:07:55 AM by John »

B+

  • Guest
Re: SB demo
« Reply #6 on: September 20, 2018, 03:43:24 PM »
Another SB demo:

Code: [Select]
. Hello World!
« Last Edit: September 20, 2018, 04:47:37 PM by B+ »