Page 1 of 1

Breakout .2

Posted: Thu Mar 09, 2017 2:51 am
by DrChip
Just having some fun... enjoy!

Code: Select all

REM breakout
REM just a fun toy i made as i was waiting.
REM you can add more bricks and patterns
REM i was plannimg on adding sound, colors and diffrent backgrounds.
REM i ran out of time... v.2 bug fixes
REM enjoy...

GRAPHICS
sw=INT(SCREEN_WIDTH())
sh=INT(SCREEN_HEIGHT())-4
res = 20 ' size 2-20
deltax=res
deltay=res
DIM board(sw+res+res,sh+res+res)
px=sw/2
py=sh/2
brick=5 'brick strength
wall=10 'wall fix strength

'setup bricks and walls
setup: 
   FOR x = 0 TO sw-res STEP res
       board(x,0) = wall
       board(x,sh-res) = wall
   NEXT x
   FOR y = res TO sh-res STEP res
       board(0,y) = wall
       board(sw-res,y) = wall
   NEXT y
   FOR x = res TO sw-res-res STEP res
       board(x,res) = brick
       board(x,res*2) = brick
       board(x,res*3) = brick
       board(x,sh/2) = brick
   NEXT x
   FOR y = res TO sh-res-res STEP res
       board(sw/2,y) = brick
   NEXT y
   
   
main:
REFRESH OFF
GRAPHICS CLEAR 0,0,0
GOSUB moveplayer
GOSUB moveblock
GOSUB drawgrid
DRAW COLOR 0,1,0
DRAW TEXT px&":"&py&" "&deltax&":"&deltay AT 0,0
REFRESH 
GOTO main

moveplayer:
    'draw tail
    FILL COLOR 0,0,0
    FILL RECT px,py TO px+res,py+res
    
    'move
    px=px+deltax
    py=py+deltay
    
    'draw player / ball
    FILL COLOR 1,0,0
    FILL RECT px,py TO px+res,py+res
    
    'test brick and ball
     IF board(px,py-res)>0 AND deltay < 0 THEN 
         deltay=-deltay
         IF board(px,py-res) <=brick THEN board(px,py-res)=board(px,py-res)-1
     END IF 
     IF board(px+res,py)>0 AND deltax > 0 THEN 
          deltax=-deltax
          IF board(px+res,py) <=brick THEN board(px+res,py)=board(px+res,py)-1
     END IF 
     IF board(px,py+res)>0  AND deltay > 0 THEN 
          deltay=-deltay
          IF board(px,py+res)<=brick THEN board(px,py+res)=board(px,py+res)-1
     END IF 
     IF board(px-res,py)>0 AND deltax < 0 THEN 
          deltax=-deltax
    IF board(px-res,py)<=brick THEN board(px-res,py)=board(px-res,py)-1
     END IF 
     
RETURN

'update bricks 
moveblock:
     FOR x = 0 TO sw STEP res
        FOR y = 0 TO sh STEP res
             IF board(x,y) > 0 THEN
                       IF board(x,y) = wall THEN
                       FILL COLOR 1,0,0
                       ELSE
                      FILL COLOR (board(x,y))/brick,board(x,y)/brick,board(x,y)/brick
                      END IF 
                       FILL RECT x,y TO x+res,y+res 
             END IF
        NEXT y
     NEXT x
RETURN

'standard grid
drawgrid:
DRAW COLOR 1,1,1
   FOR x = 0 TO sw-res STEP res
        FOR y = 0 TO sh-res STEP res
            DRAW RECT x,y TO x+res,y+res
        NEXT y
    NEXT x 
RETURN

Re: Breakout .2

Posted: Thu Mar 09, 2017 6:12 am
by rbytes
HI. I can't get either version of breakout to work on my iPad Air. I suspect you have designed them just for iPhone. Hope you will make iPad versions. I will post what my screen shots look like.

In both programs, with the screen horizontal, the ball immediately goes through the bottom wall instead of bouncing off, and they both then crash with the error shown.

In both programs, with the screen vertical, the ball immediately goes through the right wall instead of bouncing off, and they both then crash with the error shown.

Re: Breakout .2

Posted: Thu Mar 09, 2017 6:33 am
by DrChip
Sorry... I haven't had time. The problem is the screen width and height (sw and sh variables) I cheated and rounded it by subtracting 4. :)

I'll try to fix it for iPads too l, soon.

Cheers,
DrChip

Re: Breakout .2

Posted: Thu Mar 09, 2017 6:52 am
by DrChip

Code: Select all

REM breakout
REM just a fun toy i made as i was waiting.
REM you can add more bricks and patterns
REM i was plannimg on adding sound, colors and diffrent backgrounds.
REM i ran out of time... v.2 bug fixes
REM enjoy...

GRAPHICS
sw=INT(SCREEN_WIDTH())-8 'ipad air 1064 would be -64
sh=INT(SCREEN_HEIGHT())-20 'ipad air 760 would be -60 I'll clean it up later.
res = 20 ' size 2-20
deltax=res
deltay=res
DIM board(sw+res+res,sh+res+res)
px=sw/2
py=sh/2
brick=5 'brick strength
wall=10 'wall fix strength

'setup bricks and walls
setup: 
   FOR x = 0 TO sw-res STEP res
       board(x,0) = wall
       board(x,sh-res) = wall
   NEXT x
   FOR y = res TO sh-res STEP res
       board(0,y) = wall
       board(sw-res,y) = wall
   NEXT y
   FOR x = res TO sw-res-res STEP res
       board(x,res) = brick
       board(x,res*2) = brick
       board(x,res*3) = brick
       board(x,sh/2) = brick
   NEXT x
   FOR y = res TO sh-res-res STEP res
       board(sw/2,y) = brick
   NEXT y
   
   
main:
REFRESH OFF
GRAPHICS CLEAR 0,0,0
GOSUB moveplayer
GOSUB moveblock
GOSUB drawgrid
DRAW COLOR 0,1,0
DRAW TEXT px&":"&py&" "&deltax&":"&deltay AT 0,0
REFRESH 
GOTO main

moveplayer:
    'draw tail
    FILL COLOR 0,0,0
    FILL RECT px,py TO px+res,py+res
    
    'move
    px=px+deltax
    py=py+deltay
    
    'draw player / ball
    FILL COLOR 1,0,0
    FILL RECT px,py TO px+res,py+res
    
    'test brick and ball
     IF board(px,py-res)>0 AND deltay < 0 THEN 
         deltay=-deltay
         IF board(px,py-res) <=brick THEN board(px,py-res)=board(px,py-res)-1
     END IF 
     IF board(px+res,py)>0 AND deltax > 0 THEN 
          deltax=-deltax
          IF board(px+res,py) <=brick THEN board(px+res,py)=board(px+res,py)-1
     END IF 
     IF board(px,py+res)>0  AND deltay > 0 THEN 
          deltay=-deltay
          IF board(px,py+res)<=brick THEN board(px,py+res)=board(px,py+res)-1
     END IF 
     IF board(px-res,py)>0 AND deltax < 0 THEN 
          deltax=-deltax
    IF board(px-res,py)<=brick THEN board(px-res,py)=board(px-res,py)-1
     END IF 
     
RETURN

'update bricks 
moveblock:
     FOR x = 0 TO sw STEP res
        FOR y = 0 TO sh STEP res
             IF board(x,y) > 0 THEN
                       IF board(x,y) = wall THEN
                       FILL COLOR 1,0,0
                       ELSE
                      FILL COLOR (board(x,y))/brick,board(x,y)/brick,board(x,y)/brick
                      END IF 
                       FILL RECT x,y TO x+res,y+res 
             END IF
        NEXT y
     NEXT x
RETURN

'standard grid
drawgrid:
DRAW COLOR 1,1,1
   FOR x = 0 TO sw-res STEP res
        FOR y = 0 TO sh-res STEP res
            DRAW RECT x,y TO x+res,y+res
        NEXT y
    NEXT x 
RETURN

Re: Breakout .2

Posted: Thu Mar 09, 2017 7:14 am
by rbytes
Fast work. It runs fine on my iPad now in portrait mode. Thanks! :D