Shop OBEX P1 Docs P2 Docs Learn Events
Break down the wall & build a better BREAKOUT game. — Parallax Forums

Break down the wall & build a better BREAKOUT game.

Peter JakackiPeter Jakacki Posts: 10,193
edited 2021-02-28 13:52 in Propeller 2

Almost 2 years ago now I wrote a simple version of the BREAKOUT game for TAQOZ to run on VGA as well as playing a music track and with a couple of game sounds. This was mainly to test out TAQOZ and have some fun but I never made it into a complete game. It was mainly a demonstration and used the serial terminal for control keys.

The thing is that you can interact with the game at the console level and test out changes etc. You can do this by running it from the TAQOZ console cog or getting it to run in another cog and interact with it while it is running.

The Forth source is attached here and takes 1.5k code space.
172 lines and 1,506 bytes compiled, with 0 errors in 594ms ok
The main routines are at the end since they are built on other simpler functions, much like a wall is not a wall until you have the foundation and all the bricks in place :)

I will post a new binary here shortly but maybe you can have some fun and maybe make it even better.

I have a modified Forth highlighter I use for TAQOZ based on fttx.language-forth but I will have to setup a Marketplace account so I can make it a proper extension.

cropped source code (due to forum code)
```

*** GAME CONTROLS ***

pri ALERTBOX
290 x 240 y 60 w 16 h
;
pub GAMEOVER
" GAME OVER"
pri ALERT
white ALERTBOX
red PEN white PAPER 295 244 VXY VGA PRINT$
ROUT PIN MUTE 1 COGSTOP 2 COGSTOP CON CONSOLE
;

pub NEWGAME
black PAPER CLRSCR
--- play audio track but not on right channel
" BREAKOUT" PLAY$ rch C~
NEWPADDLE WALLS BORDER
--- reset balls and score
3 balls C! score C~
.SCORE NEWBALL
;

pri FASTER speed W@ IF speed W-- THEN ;
pri SLOWER speed W++ ;

byte boflgs

--- game control keys ---
pub GAMEKEY
KEY ?DUP 0EXIT a>A SWITCH
'Z' CASE L BREAK
'X' CASE R BREAK
'+' CASE FASTER BREAK
'=' CASE 5 speed W! BREAK
'-' CASE SLOWER BREAK
"_" CASE 100 speed W! BREAK
$20 CASE MUTE WKEY $1B = IF CON CONSOLE THEN BREAK
'B' CASE NEWBALL BREAK
'W' CASE WALLS BREAK
'<' CASE HIDEBALL ballw 1- 2 MAX ballwh BREAK
'>' CASE HIDEBALL ballw 1+ ballwh BREAK
$0D CASE NEWGAME BREAK
$1B CASE " CONSOLE" ALERT ROUT PIN MUTE BREAK
CASE@ '0' '9' WITHIN IF CASE@ boflgs C! THEN
;

pub ACTION
--- make it speed up proportionaly to the score
\ 130 score C@ - 3 / speed W!
COGID 0= IF GAMEKEY THEN
duration TIMEOUT? IF ROUT PIN MUTE THEN
?BALL
--- debug, slow ball down when approaching wall
1 boflgs SET? IF bally@ 130 < IF 50 ms THEN THEN
--- testing: autostart a new game
score C@ #total = IF NEWGAME THEN
;

pub BREAKOUT
8 BPP 360p !VGA
boflgs C~
NEWGAME
pub CONTINUE
0 ALERTBOX
6 TERM
BEGIN ACTION AGAIN
;

END

```

Comments

  • Nice, Peter!.

    The breakout I'm used to was monochrome and ran on the 5" crt of the Osborne 1. On that platform it was called 'tbreak'. I'm not sure I could handle the excitement of both colour and big screen all at once

  • I was reading about the history of this game and see that it was the Woz that designed it which many of us know. However it wasn't software he designed as I assumed, but it was TTL logic and it was supposed to be Steve Jobs' job but it really wasn't his forte and Jobs was only going to be paid $700 although there would a bonus for every chip less than 50 that he could design it in. In those days many of the boards had 100 to 150 chips. He got the Woz to design it which he did over about four 24hr days and he did it in 44 chips. Jobs got a $5000 bonus but only gave Woz half of the $700! Anyway, the design was "too complicated" to understand for Atari engineers so they ended up making it with 100 chips instead.

    When Woz designed the Apple II, he did so with the Breakout game in mind, so that it could be done in software (Basic) with hardware support for real color (not tape), and sound.

    Now we can do it 1.5k of TAQOZ code on the P2 in 8-bit VGA color and wave audio.

  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2021-03-01 00:26

    Now here is a more complicated part of the code that checks the ball position and what to do next step if it hits something. Even though it cascades into the ?REBOUND function, it is effectively one function that has not yet been refactored.
    Could it be better?

    --- Check if ball is ready for next movement and proceed
    pub ?BALL
    --- ready yet?
        speedtmr TIMEOUT? 0EXIT
    --- yes, set next timeout period
        speed W@ speedtmr TIMEOUT
    --- hide ball
        HIDEBALL
    ---  and update new position (but still hidden)
        velx @ ballx +! vely @ bally +!
    --- change the direction if the ball has hit something
    pri ?REBOUND
        ?PADDLE
    --- only smash a brick if the top center of the ball hits it
        HIT? IF vely +-! THEN
    --- determine direction of rebound based on current direction
        LEFT? IF ballx@ 1- ELSE ballx@ ballw + 1+ THEN ( ballx )
    --- and ball y  fetch pixel if hit something - reverse ball x velocity 
        bally@ 1+   XY@         IF BONK velx NEGATE! THEN
    --- UP? if use top of ball    else down uses bottom of ball xy
        UP? IF ballx@ 1+ bally@ 1- ELSE ballx@ 1+ bally@ ballw + 1+ THEN
    --- if it has hit something then reverse vertical direction
        XY@ IF BONK vely NEGATE! THEN
        SHOWBALL
        ;
    
    
    
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2021-03-01 07:01

    Yes, that routine can be better simply by factoring it into smaller logical routines like this:

    --- Check if ball is ready for next movement and proceed
    pub ?BALL    BALLTIMER? IF HIDEBALL MOVEBALL ?BOUNCE SHOWBALL THEN ;
    

    Reading that it becomes
    public routine to check the ball - if the ball timer is ready, hide the ball, move the ball, check for bounce and show the ball, then return.

    TAQOZ# SEE ?BALL
    1BC44: pub ?BALL
    0B11C: B014     BALLTIMER?
    0B11E: 1C04     IF $B128
    0B120: AF9C       HIDEBALL
    0B122: AFC0       MOVEBALL
    0B124: B114       ?BOUNCE
    0B126: AFA2       SHOWBALL
                   THEN
    0B128: 005D     ;
          ( 14  bytes ) 
    
  • RaymanRayman Posts: 14,744

    Nice example. I might have to take a crack at this sometime too...
    Kind of like the color scheme shown here: https://github.com/thxi/breakout

  • Remember when I said that you can interact with a live game? Well, what happens when a live game interacts with you? When the console is diverted to the VGA terminal during a game and you type a command and just as you are about to hit enter this ball comes flying up and smashes the command, not even stopping to say sorry, just makes a silly bonk sound and goes bouncing off! I'll give that naughty ball a good paddling I will. When I catch it that is.

    btw, the original color scheme was boring because they used mono screens with colored tape. I just generate random colors but I might do some textured bricks next or even read a bmp file.

Sign In or Register to comment.