Page 1 of 1

Ball blazers scrolling grid attempt

Posted: Sun Oct 09, 2016 12:46 am
by DrChip

Code: Select all

REM 3D Checkerboard:
REM ported out of Source: https://www.khanacademy.org/computer-programming/3d-checkerboard/972365924
REM sB 5.6 / iOS 6.1 / iPhone 4
REM by Operator
REM added walls and bouncing...automated
REM sB 5.6 / iOS 10.1 / iPhone 6+

GRAPHICS
GRAPHICS CLEAR 1,0,0
init:

DIM wall(5) ' location of end walls

GOSUB drawplayer
scr_w = SCREEN_WIDTH()
scr_h = SCREEN_HEIGHT()
scr_w2 = scr_w/2
scr_h2 = scr_h/2

walkSpeedX = 10
walkSpeedY = 10
perspect = 200 '250
horizon = 180
tileWidth = 100

meX = 400
meY = 40

wall(1) = 700
wall(2) = 20
wall(3) = 600
wall(4) = -90

FIELD "info" TEXT "" AT 0,0 SIZE 320,20 RO
FIELD "info" FONT COLOR 1,1,1
FIELD "info" BACK ALPHA 0


TIME RESET

LOOP:
REFRESH OFF
GRAPHICS CLEAR 1,0,0
loop_count += 1

'drawGrid
FOR x = 0 TO 700 STEP tileWidth
  FOR y = 0 TO 700 STEP tileWidth
    IF y - meY > -tileWidth - 100 THEN
      IF ((x/tileWidth + y/tileWidth)%2) THEN
        FILL COLOR 0,0,0
      ELSE
        FILL COLOR 1,1,1
      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
    
      FILL QUAD x1,y1, x1+tileWidth*p1,y1, x2+tileWidth*p2, y2, x2,y2
    END IF
  NEXT y
NEXT x

IF meX > wall(1) THEN walkSpeedX=-walkSpeedX
IF meX < wall(2) THEN walkSpeedX=-walkSpeedX
IF meY > wall(3) THEN walkSpeedY=-walkSpeedY
IF meY < wall(4) THEN walkSpeedY=-walkSpeedY

meX += walkSpeedX
meY -= walkSpeedY


'DRAW TEXT meX&":"&meY AT 0,40
fps = INT(loop_count/TIME())
'FIELD "info" TEXT " Touch screen to navegate     "&"FPS: "&fps

REFRESH
GOTO LOOP



drawplayer:

BUTTON "player" TEXT "⚽️" AT SCREEN_WIDTH()/2,SCREEN_HEIGHT()/2

RETURN

Re: Ball blazers scrolling grid attempt

Posted: Sun Oct 09, 2016 1:58 am
by rbytes
Looks good. Nice fast action.

If you SET BUTTONS CUSTOM near the start and then insert FILL ALPHA 0 just before the button command and FILL ALPHA 1 just after it, you'll see just the ball without the rest of the button.

Re: Ball blazers scrolling grid attempt

Posted: Sun Oct 09, 2016 4:09 am
by DrChip

Code: Select all

REM 3D Checkerboard:
REM ported out of Source: https://www.khanacademy.org/computer-programming/3d-checkerboard/972365924
REM sB 5.6 / iOS 6.1 / iPhone 4
REM by Operator
REM added walls and bouncing...automsted
REM tgsbkds fir the button tip ricardobytes
REM someone can add obstacles abd fake powerups. :)
REM enjoy...


GRAPHICS
GRAPHICS CLEAR 1,0,0
SET BUTTONS CUSTOM
init:

DIM wall(5) ' location of end walls

GOSUB drawplayer
scr_w = SCREEN_WIDTH()
scr_h = SCREEN_HEIGHT()
scr_w2 = scr_w/2
scr_h2 = scr_h/2

walkSpeedX = 10
walkSpeedY = 10
perspect = 200 '250
horizon = 180
tileWidth = 50 '100

wall(1) = 1600 'x right
wall(2) = 260 'x left
wall(3) = 1500 'y top
wall(4) = -30 'y bottom

meX = 1600/2 '500
meY = 1600/2 '400 '40

FIELD "info" TEXT "" AT 0,0 SIZE 320,20 RO
FIELD "info" FONT COLOR 1,1,1
FIELD "info" BACK ALPHA 0


TIME RESET

LOOP:
REFRESH OFF
GRAPHICS CLEAR 1,0,0
loop_count += 1

'drawGrid
FOR x = 0 TO 1700 STEP tileWidth
  FOR y = 0 TO 1700 STEP tileWidth
    IF y - meY > -tileWidth - 100 THEN
      IF ((x/tileWidth + y/tileWidth)%2) THEN
        FILL COLOR 0,0,meX/255
      ELSE
        FILL COLOR 1,1,meY/255
      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
    
      FILL QUAD x1,y1, x1+tileWidth*p1,y1, x2+tileWidth*p2, y2, x2,y2
    END IF
  NEXT y
NEXT x

'walls
DRAW SIZE 50 ' border
DRAW RECT 0,0 TO scr_w,scr_h
DRAW COLOR 1,1,1
IF meX > wall(1) THEN 
   walkSpeedX=-walkSpeedX!BEEP
   DRAW COLOR 1,0,0
   DRAW RECT 0,0 TO scr_w,scr_h
   DRAW COLOR 1,1,1
END IF 
IF meX < wall(2) THEN 
    walkSpeedX=-walkSpeedX!BEEP
    DRAW COLOR 1,0,0
    DRAW RECT 0,0 TO scr_w,scr_h
    DRAW COLOR 1,1,1
END IF
IF meY > wall(3) THEN 
    walkSpeedY=-walkSpeedY!BEEP
    DRAW COLOR 1,0,0
    DRAW RECT 0,0 TO scr_w,scr_h
    DRAW COLOR 1,1,1
END IF
IF meY < wall(4) THEN 
    walkSpeedY=-walkSpeedY!BEEP
    DRAW COLOR 1,0,0
    DRAW RECT 0,0 TO scr_w,scr_h
    DRAW COLOR 1,1,1
END IF

'move direction
meX += walkSpeedX
meY -= walkSpeedY


'DRAW TEXT meX&":"&meY AT 0,40
fps = INT(loop_count/TIME())
'FIELD "info" TEXT " Touch screen to navegate     "&"FPS: "&fps

REFRESH ON
GOTO LOOP


'place holder for player sprites (directional)
drawplayer:
FILL ALPHA 0
BUTTON "player" TEXT "⚽️" AT SCREEN_WIDTH()/2,SCREEN_HEIGHT()/2
FILL ALPHA 1
RETURN

Re: Ball blazers scrolling grid demo

Posted: Tue Oct 11, 2016 3:02 am
by DrChip

Code: Select all

REM 3D Checkerboard / ball blazer game demo v1.1
REM ported out of Source: https://www.khanacademy.org/computer-programming/3d-checkerboard/972365924
REM sB 5.6 / iOS 6.1 / iPhone 4
REM by Operator, DrChip and ricardobytes
REM iOS 10.1 beta 3 / iPhone 6+
REM added walls and bouncing...automsted
REM tgsbkds fir the button tip ricardobytes
REM someone can add obstacles abd fake powerups. :)
REM its a work in progress. Thanks everyone.
REM if anyone wants to align the grids, perspectives and reverse 
REM the top, randomize the walk speed when the wall is hit...
REM that would be cool
REM enjoy...



GRAPHICS
GRAPHICS CLEAR 1,0,0
SET BUTTONS CUSTOM
init:
DIM wall(5) ' location of end walls

GOSUB drawplayer
scr_w = SCREEN_WIDTH()
scr_h = SCREEN_HEIGHT()
scr_w2 = scr_w/2
scr_h2 = scr_h/2

walkSpeedX = 10
walkSpeedY = 10
perspect = 200 '250
horizon = scr_h2 '180
tileWidth = 50 '100

gridsizeX=1700 '1700
gridsizeY=1700 '1700

wall(1) = gridsizeX 'x max right
wall(2) = 260 'x min left
wall(3) = gridsizeY 'y max top
wall(4) = 30 'y min bottom

meX = wall(1)/2 '500
meY = wall(3)/2 '400 '40

FIELD "info" TEXT "" AT 0,0 SIZE scr_w2,scr_h RO
FIELD "info" FONT COLOR 1,0,0
FIELD "info" BACK ALPHA 0


TIME RESET

LOOP:
REFRESH OFF
GRAPHICS CLEAR 1,0,0
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,0,meX/255
      ELSE
        FILL COLOR 1,1,meY/255
      END IF
      p1 = perspect/(perspect + y - meY)
      x1 = scr_w2 + p1*(x - meX)
      y1 = horizon + p1*scr_h2
      yy1=y1/3.8
      p2 = perspect/(perspect + y - meY + tileWidth)
      x2 = scr_w2 + p2*(x - meX)
      y2 = horizon + p2*scr_h2
      yy2=y2/3.8
      'top grid backwards 
      FILL QUAD x1,yy1, x1+tileWidth*p1,yy1, x2+tileWidth*p2, yy2, x2,yy2
      'bottom grid
      FILL QUAD x1,y1, x1+tileWidth*p1,y1, x2+tileWidth*p2, y2, x2,y2
    END IF
  NEXT y
NEXT x

'walls / players / objects
DRAW SIZE 50 ' border
DRAW RECT 0,0 TO scr_w,scr_h 'border
FILL COLOR 1,1,1
FILL RECT 0,scr_h2-50 TO scr_w,scr_h2+50 'center scoreboard
DRAW COLOR 1,1,1
IF meX > wall(1) THEN 
   walkSpeedX=-walkSpeedX!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!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!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!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 TEXT meX&":"&meY AT 0,40
fps = INT(loop_count/TIME())
FIELD "info" TEXT "         Score:"&score&"          FPS: "&fps

REFRESH ON
GOTO LOOP


'place holder for player sprites (directional)
drawplayer:
FILL ALPHA 0
BUTTON "player" TEXT "⚽️" AT SCREEN_WIDTH()/2,SCREEN_HEIGHT()-200
FILL ALPHA 1
RETURN