https://www.dropbox.com/s/t7an5z5m7izx2 ... r.mid?dl=0
Code: Select all
REM 3D Checkerboard / ball blazer game demo v1.6
REM ported out of Source: https://www.khanacademy.org/computer-programming/3d-checkerboard/972365924
REM sB 5.6 / iOS 6.1 / iPhone 4
REM origanal port by Operator
REM modified to ballblazer demo by DrChip
REM added walls, bouncing, corrected color...automated
REM thanks for the button tips ricardobytes
REM someone can add obstacles and fake powerups. :)
REM its a work in progress. thanks everyone
REM if anyone wants to align the grids, perspectives and reverse the top, that would be cool!
REM ballblazer.mid can be found in my dropbox:
REM https://www.dropbox.com/s/t7an5z5m7izx2xp/ballblazer.mid?dl=0
REM 1.6 - fixes for sB 6.0
REM sB 6 is much faster... updated code for sB 6.0
REM enjoy...
GRAPHICS
GRAPHICS CLEAR 0,0,1
SET BUTTONS CUSTOM
init:
DEF reload
NOTES LOAD "ballblazer.mid"
NOTES PLAY
END DEF
DIM wall(5) ' location of end walls
scr_w = SCREEN_WIDTH()
scr_h = SCREEN_HEIGHT()
scr_w2 = scr_w/2
scr_h2 = scr_h/2
walkSpeedX = 10
walkSpeedY = 10
perspect = 250
horizon = scr_h2
tileWidth = 50 '100
gridsizeX=1700 '
gridsizeY=1600 '
wall(1) = gridsizeX-30 'x max right
wall(2) = 60 'x min left
wall(3) = gridsizeY-130 'y max top
wall(4) = 60 'y min bottom
meX = wall(1)/2 '500
meY = wall(3)/2 '400
GOSUB drawplayer
TIME RESET
reload
LOOP:
IF NOTES_TIME()>NOTES_LENGTH() THEN reload
REFRESH OFF
GRAPHICS CLEAR 0,0,1
loop_count += 1
'drawGrid
FOR x = 0 TO gridsizeX STEP tileWidth
FOR y = 0 TO gridsizeY STEP tileWidth
IF y - meY > -tileWidth - 100 THEN
IF ((x/tileWidth + y/tileWidth)%2) THEN
FILL COLOR 0,1,0
ELSE
FILL COLOR 0,.5,0
END IF
p1 = perspect/(perspect + y - meY)
x1 = scr_w2 + p1*(x - meX)
y1 = (horizon + p1*scr_h2)
p2 = perspect/(perspect + y - meY + tileWidth)
x2 = scr_w2 + p2*(x - meX)
y2 = (horizon + p2*scr_h2)
topyy1=y1/3
topyy2=y2/3
boty1=(y1/2)+220
boty2=(y2/2)+220
'top grid backwards
FILL QUAD x1,topyy1, x1+tileWidth*p1,topyy1, x2+tileWidth*p2, topyy2, x2,topyy2
'bottom grid
FILL QUAD x1,boty1, x1+tileWidth*p1,boty1, x2+tileWidth*p2, boty2, x2,boty2
END IF
NEXT y
NEXT x
'walls / players / objects
DRAW COLOR 0,0,0
DRAW SIZE 50 ' border
DRAW RECT 0,0 TO scr_w,scr_h2 'border top
DRAW RECT 0,scr_h2 TO scr_w,scr_h 'border bottom
FILL COLOR 0,0,0
FILL RECT 0,scr_h2-50 TO scr_w,scr_h2+50 'center scoreboard
DRAW COLOR 0,0,0
IF meX > wall(1) THEN
walkSpeedX= -(walkSpeedX+RND(3))!BEEP
DRAW COLOR 1,0,0
DRAW RECT 0,0 TO scr_w,scr_h
DRAW COLOR 1,1,1
score = score + 1
END IF
IF meX < wall(2) THEN
walkSpeedX= -(walkSpeedX+RND(3))!BEEP
DRAW COLOR 1,0,0
DRAW RECT 0,0 TO scr_w,scr_h
DRAW COLOR 1,1,1
score = score + 1
END IF
IF meY > wall(3) THEN
walkSpeedY= -(walkSpeedY+RND(2))!BEEP
DRAW COLOR 1,0,0
DRAW RECT 0,0 TO scr_w,scr_h
DRAW COLOR 1,1,1
score = score + 1
END IF
IF meY < wall(4) THEN
walkSpeedY = -(walkSpeedY+RND(2))!BEEP
DRAW COLOR 1,0,0
DRAW RECT 0,0 TO scr_w,scr_h
DRAW COLOR 1,1,1
score = score + 1
END IF
'move direction
meX += walkSpeedX
meY -= walkSpeedY
'score board
DRAW COLOR 1,1,1
fps = INT(loop_count/TIME())
DRAW TEXT "Score: "&score&" FPS: "&fps AT 40,scr_h/2
DRAW TEXT meX&":"&meY AT 40,scr_h2-40
DRAW TEXT walkSpeedX&":"&walkSpeedY AT 40,scr_h2-20
REFRESH ON
GOTO LOOP
'place holder for player sprites (directional)
drawplayer:
FILL ALPHA 0
BUTTON "player1" TEXT "⚽️" AT scr_w2,scr_h/1.3
BUTTON "player2" TEXT "⚽️" AT scr_w2,scr_h/4.5
FILL ALPHA 1
RETURN
Introscreen:
RETURN