Advertisement
Guest User

Heartbreak 1.0.5 Source Code - BASIC + 6502 Assembly

a guest
Nov 29th, 2013
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Basic4GL 14.07 KB | None | 0 0
  1.  includesfile heartincludes.inc
  2.  
  3.  rem **********************************
  4.  rem * Heartbreak                    *
  5.  rem * A re-imagning of breakout with a lonely heart trapped in a void...                   *
  6.  rem * Cybearg (aka Nic)                        *
  7.  rem * cybearg.plays@gmail.com                 *
  8.  rem * HUGE thanks to bogax, RandomTerrain, theloon, Omegamatrix, Andrew Davie, and all others at AtariAge.com for making this possible! *
  9.  rem **********************************
  10.  
  11.  const COL_NTSC  = 1
  12.  asm
  13.  include colors.h
  14. end
  15.  
  16.  rem ==============
  17.  rem INITIALIZATION
  18.  rem ==============
  19.  
  20.  rem set up settings/optimization
  21.  include fixed_point_math.asm
  22.  set tv ntsc
  23.  set optimization size
  24.  set optimization inlinerand
  25.  set smartbranching on
  26.  
  27.  const AVoxSafetyOff=1
  28.  const LIFEMAX = 3
  29.  const startlevel = 0
  30.  const START_VEL = 128
  31.  
  32.  rem COLORS
  33.  rem NOTE: BLACK isn't $00 because $00 counts a block as destroyed, rather than invisible
  34.  
  35.  asm
  36.   IF COL_NTSC
  37. RED = COL_40
  38. YELLOW = COL_1E
  39. BLUE = COL_96
  40. ORANGE = COL_22
  41. GREEN = COL_D4
  42. PURPLE = COL_62
  43. WHITE = COL_0E
  44. BLACK = COL_01
  45.   ELSE
  46. RED = $60
  47. YELLOW = $2A
  48. BLUE = $B6
  49. ORANGE = $42
  50. GREEN = $52
  51. PURPLE = $A2
  52. WHITE = COL_0E
  53. BLACK = COL_01
  54.   ENDIF
  55. end
  56.  
  57.  
  58.  data _BlockColor
  59.  RED, YELLOW, BLUE, ORANGE, GREEN, PURPLE, WHITE, BLACK
  60. end
  61.  
  62.  
  63.  rem set up my variables
  64.  dim block = a
  65.  dim selection = q
  66.  dim blkcount = r
  67.  dim level = s
  68.  dim soundtimer=t
  69.  dim anglevar=u
  70.  dim pulse=v
  71.  dim lastblock = w
  72.  dim offset=x
  73.  dim ballcolor=y
  74.  dim heartcolor=z
  75.  
  76.  rem cxBlock reports the index of a block's collision from the kernel, informing of which block was hit
  77.  dim cxBlock = $A4
  78.  
  79.  rem the types of possible basic gameplay modes
  80.  dim bits = $A8
  81.  
  82.  def atarivox = bits{0}
  83.  def resetlock = bits{1}
  84.  def hardmode = bits{2}
  85.  def firelock = bits{3}
  86.  
  87.  rem when bounce is enabled, score based on how many bounces can be kept up.
  88.  dim bouncecount = $AD
  89.  
  90.  rem remembers the maximum streak one had for a level
  91.  dim maxbounce = $AE
  92.  
  93.  rem counter for heartbeat audio
  94.  dim lubdub = $AF
  95.  
  96.  rem memory locations for remembering the last high score
  97.  dim save1 = $B0
  98.  dim save2 = $B1
  99.  dim save3 = $B2
  100.  
  101.  dim floatx = $B3
  102.  dim floaty = $B4
  103.  
  104.  dim velfloati = $B5
  105.  dim velfloatd = $B6
  106.  
  107.  dim rand16 = $B7
  108.  
  109.  dim _ballx = player1x.floatx
  110.  dim _bally = player1y.floaty
  111.  
  112.  dim _my88 = temp4.temp5
  113.  dim _velocity = velfloati.velfloatd
  114.  
  115.  rem set up score bytes for reading/writing
  116.  dim sc1=score
  117.  dim sc2=score+1
  118.  dim sc3=score+2
  119.  
  120.  rem set player 0's location
  121.     player0x=80:player0y=48
  122.  
  123.  
  124.  rem ================
  125.  rem ATARIVOX START
  126.  rem ================
  127.  
  128.  rem try to write to AtariVox
  129.  
  130.  temp2=AVoxWriteByte($30,$01,temp3)
  131.  
  132.  if temp1 then goto resetpoint
  133.  
  134.  drawscreen
  135.  
  136.  atarivox = 1
  137.  
  138.  rem initial read loop
  139.  
  140. AvoxRead
  141.  
  142. read1
  143.  save1=AVoxReadByte($06,$80)
  144.  rem sc1 = save1
  145.  drawscreen
  146.  
  147. read2
  148.  save2=AVoxReadByte($06,$81)
  149.  rem sc2 = save
  150.  drawscreen
  151.  
  152. read3
  153.  save3=AVoxReadByte($06,$82)
  154.  rem sc3 = save3
  155.  drawscreen
  156.  
  157.  rem ** if the score is $ff, we need to initialize the eeprom
  158.  rem ** if we don't do this, the high score will be $FFFFFF
  159.  temp2=save1&save2&save3
  160.  if temp2=$ff then save1=0:save2=0:save3=0
  161.  
  162. resetpoint
  163.  gosub avoxSave
  164.  if switchleftb then hardmode = 0 else hardmode = 1
  165.  level = startlevel
  166.  score = 0: AUDV0 = 0: AUDV1 = 0
  167.  gosub setstage
  168.  
  169.  rem ==========
  170.  rem MAIN LOOP
  171.  rem ==========
  172.  
  173. main
  174.  
  175.  gosub sounds
  176.  
  177.  gosub heartbeat
  178.  
  179.  if lives then gosub colormove
  180.  if joy0fire && !firelock then gosub playerfire
  181.  
  182.  if player1x then gosub ballmove: gosub collisiondetect
  183.  
  184.  if !blkcount then gosub stageend: gosub setstage
  185.  
  186.  rem ==================
  187.  rem MAIN DRAWSCREEN
  188.  rem ==================
  189. maindraw
  190.  
  191.  const SCORERED = COL_40
  192.  const SCOREWHITE = COL_0E
  193.  
  194.  if lives = 1 then scorecolor = SCORERED else scorecolor = SCOREWHITE
  195.  
  196.   if pulse < 40 then temp1 = lives else temp1 = lives - 1
  197.  if !lives then temp1 = 0
  198.  asm
  199.     LDX temp1
  200.     LDA spriteslo,x
  201.     STA player0pointerlo
  202.     LDA spriteshi,x
  203.     STA player0pointerhi
  204.  
  205.     LDX #4
  206.     LDA spriteslo,x
  207.     STA player1pointerlo
  208.     LDA spriteshi,x
  209.     STA player1pointerhi
  210.  
  211.     LDA #7
  212.     STA player0height
  213.     STA player1height
  214. end
  215.  
  216.  if switchreset && !resetlock then resetlock = 1: goto resetpoint
  217.  if !switchreset then resetlock = 0
  218.  if !joy0fire then firelock = 0
  219.  drawscreen
  220.  if switchselect && switchreset then gosub avoxSave: T1024T=rand: goto bank_menu
  221.  if switchbw then AUDV0 = 0: AUDV1 = 0: goto maindraw
  222.  goto main
  223.  
  224.  rem ===============
  225.  rem SOUNDS
  226.  rem ===============
  227.  
  228. sounds
  229.  if soundtimer then soundtimer = soundtimer - 1: AUDV1 = 8 else AUDV1 = 0
  230.  
  231.  return thisbank
  232.  
  233.  rem ===============
  234.  rem BEATING HEART
  235.  rem ===============
  236.  
  237. heartbeat
  238.  
  239.  pulse = pulse +1
  240.  if pulse = 38 then AUDC0 = 12: AUDF0 = 31: AUDV0 = 1
  241.  if pulse = 45 then pulse = 0: AUDV0 = 0: heartcolor = heartcolor + 1
  242.  
  243.  rem ensure heartcolor doesn't go too high
  244.  data heartcolors
  245.  0, 1, 2, 1, 2
  246. end
  247.  
  248.  if level < 4 && heartcolor > heartcolors[level] then heartcolor = 0
  249.  if heartcolor = 3 then heartcolor = 0
  250.  
  251.  COLUP0 = _BlockColor[heartcolor]
  252.  
  253.  if !lives then AUDV0 = 0
  254.  
  255.  return thisbank
  256.  
  257.  rem =================
  258.  rem COLOR MOVEMENT
  259.  rem =================
  260.  
  261. colormove
  262.  
  263.  if !tempJoy{6} then offset = offset + 1
  264.  if !tempJoy{7} then offset = offset - 1
  265.  if offset >= 53 then goto left
  266.  if offset <= 47 then goto right
  267.  return thisbank
  268.  
  269.  rem move all block values to the left (counter clockwise)
  270. left    temp3 = a[0]
  271.  for temp1 = 0 to 14
  272.     temp2 = temp1 + 1
  273.     a[temp1] = a[temp2]
  274.  next
  275.     a[15] = temp3
  276.  goto resetoffset
  277.  
  278.  rem move all blocks to the right (clockwise)
  279. right   temp3 = a[15]
  280.  for temp1 = 15 to 0 step -1
  281.     temp2 = temp1 - 1
  282.     a[temp1] = a[temp2]
  283.  next
  284.     a[0] = temp3
  285.  
  286.  rem reset the offset
  287.  
  288. resetoffset
  289.  offset = 50
  290.  
  291.  return thisbank
  292.  
  293.  rem ============
  294.  rem PLAYER FIRE
  295.  rem ============
  296. playerfire
  297.  if !lives then pop: goto resetpoint
  298.  ballcolor = heartcolor
  299.  if !player1x then player1x=80: player1y=48 else return thisbank
  300.  anglevar = (rand/64) * 2 + 1
  301.  
  302.  return thisbank
  303.  
  304.  rem =========
  305.  rem THE BALL
  306.  rem =========
  307. ballmove
  308.  
  309.  COLUP1 = _BlockColor[ballcolor]
  310.  
  311.  rem x motion table
  312.  data xmtbl
  313.  0, 1, 1, 1, 0, -1, -1, -1
  314. end
  315.  
  316.  rem y motion table
  317.  data ymtbl
  318.  -1, -1, 0, 1, 1, 1, 0, -1
  319. end
  320.  
  321. ballMove
  322.  if xmtbl[anglevar] = 1 then _ballx = _ballx + _velocity
  323.  if xmtbl[anglevar] = 255 then _ballx = _ballx - _velocity
  324.  
  325.  if ymtbl[anglevar] = 1 then  _bally = _bally + _velocity
  326.  if ymtbl[anglevar] = 255 then  _bally = _bally - _velocity
  327.  
  328.  return thisbank
  329.  
  330.  rem ====================
  331.  rem COLLISION DETECTION
  332.  rem ====================
  333.  
  334. collisiondetect
  335.  
  336.  rem check to see if player 1 is out of bounds
  337.  if player1x > 25 && player1x < 133 && player1y && player1y < 88 then goto ballinplay
  338.  if hardmode then temp1 = 0 else temp1 = 1
  339.  AUDC1 = 6: AUDF1 = 16: soundtimer = 8
  340.  player1x = 0: player1y = 0: bouncecount = 0
  341.  lastblock = 16:  velfloati = 0: velfloatd = START_VEL
  342. repeatpenalty
  343.  if !sc1 && !sc2 && sc3 < 50 then score = 0 else score = score - 50
  344.  if temp1 then return thisbank else temp1 = 1: goto repeatpenalty
  345.  
  346.  
  347. ballinplay
  348.  if !collision(playfield,player1) || cxBlock = lastblock then return thisbank
  349.  if !block[cxBlock] then return thisbank
  350.  
  351.  rem ====================
  352.  rem COLOR CHECKING
  353.  rem ====================
  354.  
  355.  rem note, index 0 of primaryarray is never used
  356.  data primaryarray
  357.  7, 3, 5, 4
  358. end
  359.  
  360.  data secondaryarray
  361.  1, 0, 6, 6, 2, 1, 2, 6, 0
  362. end
  363.  
  364.  data whitearray
  365.  4, 5, 3
  366. end
  367.  
  368.  rem find the color index of the current block
  369.  for temp1 = 0 to 6
  370.  if block[cxBlock] = _BlockColor[temp1] then goto colorcheck
  371.  next
  372.  
  373. colorcheck
  374.  if temp1 <= 2 then goto primarycheck
  375.  if temp1 > 5 then goto whiteblack
  376.  goto secondarycheck
  377.  
  378. primarycheck
  379.  if ballcolor = temp1 then goto good_hit else goto bad_hit
  380.  
  381. secondarycheck
  382.  temp4 = temp1 - 3
  383.  temp6 = temp4 + temp4 + temp4 + ballcolor
  384.  temp5 = secondaryarray[temp6]
  385.  rem normally, "6" represents an invalid hit, so it is bad
  386.  if temp5 = 6 then goto bad_hit
  387.  
  388.  rem use the array to set the correct resulting color
  389.  block[cxBlock] = _BlockColor[temp5]
  390.  goto keep_going
  391.  
  392. whiteblack
  393. white
  394.  if temp1 = 7 then goto bad_hit
  395.  
  396.  temp2 = whitearray[ballcolor]
  397.  block[cxBlock] = _BlockColor[temp2]: temp5 = temp2 - 3: goto white_hit
  398.  
  399.  rem ====================
  400.  rem CONSEQUENCES
  401.  rem ====================
  402.  
  403. bad_hit
  404.  lives = lives - 1
  405.  velfloati = 0: velfloatd = START_VEL
  406.  AUDC1 = 1: AUDF1 = 24: soundtimer = 8
  407.  firelock = 1: player1x = 0: player1y = 0: bouncecount = 0: lastblock = 16: return thisbank
  408.  
  409. good_hit
  410.  block[cxBlock] = 0
  411.  blkcount = blkcount - 1
  412.  
  413.  score = score + 25
  414.  if hardmode then _velocity = _velocity + 0.025
  415.  
  416.  AUDC1 = 12: AUDF1 = 19: soundtimer = 8
  417.  goto newbounce
  418.  
  419. white_hit
  420.  if lives < 3 then lives = lives + 1
  421.  
  422. keep_going
  423.  score = score + 25
  424.  AUDC1 = 12: AUDF1 = 12: soundtimer = 8
  425.  if hardmode then _velocity = _velocity + 0.005
  426. newbounce
  427.  lastblock = cxBlock
  428.  
  429.  temp1 = rand
  430.  temp2 = cxBlock / 2
  431.  if temp1 <= 85 then anglevar = (temp2 + 3) & 7
  432.  if temp1 > 85 && temp1 <= 170 then anglevar = (temp2 + 4) & 7
  433.  if temp1 > 170 then anglevar = (temp2 + 5) & 7
  434.  
  435.  rem reset ball location to prevent wander
  436.  data blockX
  437.  0, 112, 0, 112, 0, 48, 0, 48
  438. end
  439.  
  440.  data blockY
  441.  0, 18, 0, 78, 0, 78, 0, 18
  442. end
  443.  
  444.  temp2 = cxBlock / 2
  445.  player1x = blockX[temp2]
  446.  player1y = blockY[temp2]
  447.  floatx = 0: floaty = 0
  448.  bouncecount = bouncecount + 1
  449.  if bouncecount > maxbounce then maxbounce = bouncecount
  450.  return thisbank
  451.  
  452.  rem ==================
  453.  rem STAGE ENDING
  454.  rem ==================
  455. stageend
  456.  
  457.  if hardmode then temp1 = 0 else temp1 = 1
  458. pointsrepeat
  459.  score = score + 50
  460.  if lives > 1 then score = score + 50
  461.  if lives > 2 then score = score + 50
  462.  if maxbounce >= 12 then score = score + 50
  463.  if maxbounce >= 16 then score = score + 50
  464.  if maxbounce >= 24 then score = score + 50
  465.  if !temp1 then temp1 = 1: goto pointsrepeat
  466.  
  467.  level = level + 1
  468.  if level = 16 && hardmode then level = 8
  469.  if level = 16 && !hardmode then level = 0: hardmode = 1
  470.  
  471.  return thisbank
  472.  
  473.  rem ==================
  474.  rem STAGE GENERATION
  475.  rem ==================
  476.  
  477. setstage
  478.  
  479.  rem defines the odds of a color for each stage
  480.  data colorodds
  481.  0, 0, 128, 0, 85, 170, 0, 42, 84, 126, 168, 210, 0, 70, 140, 210, 245, 0, 40, 80, 120, 160, 200, 240, 250, 0, 20, 40, 80, 120, 160, 200, 240, 0, 60, 120, 180, 240
  482. end
  483.  
  484.  rem saves space by indicating where the colorodds index should begin, per level
  485.  data startindex
  486.  0, 1, 3, 0, 1, 3, 6, 1, 12, 12, 17, 17, 25, 25, 33, 33
  487. end
  488.  
  489.  rem defines which color checks are in a stage
  490.  data levelcolors
  491.  %00000001, %00000011, %00000111, %00001000, %00011000, %00111000, %00111111, %11000000, %11000111, %11111000, %11111111, %11111111, %11111111, %11111111, %11111000, %11111000
  492. end
  493.  
  494.  data levelcolorsrev
  495.  %00010000, %00110000, %00111000, %00000100, %00000110, %00000111, %00111111, %11000000, %11111000, %11000111, %11111111, %11111111, %11111111, %11111111, %11000111, %11000111
  496. end
  497.  
  498.  rem defines the colors red through black
  499.  data bitlist
  500.  %00000001, %00000010, %00000100, %00001000, %00010000, %00100000, %01000000, %10000000
  501. end
  502.  
  503.  velfloati = 0: velfloatd = START_VEL
  504.  blkcount = 16
  505.  selection = 0: player1x = 0: player1y = 0
  506. generationloop
  507.  
  508.  temp3 = startindex[level]
  509.  
  510.  rem generate a random number
  511.  temp2 = rand
  512.  
  513.  rem if a color is in a level and its number has been rolled, set a pfpixel to its color, then increment the index
  514.  for temp5 = 0 to 7
  515.  rem if the current color is not in the current level, temp 4 = 0
  516.  temp4 = levelcolors[level] & bitlist[temp5]
  517.  rem if the current color is in the current level and that color's number has been rolled, set the current block to that color
  518.  if temp4 &&  temp2 >= colorodds[temp3]  then block[selection] = _BlockColor[temp5]: temp3 = temp3 + 1
  519.  next
  520.  
  521.  if block[selection] = BLACK then blkcount = blkcount - 1
  522.  
  523.  COLUP0 = 0: COLUP1 = 0
  524.  gosub sounds
  525.  drawscreen
  526.  
  527.  if selection < 15 then selection = selection + 1: goto generationloop
  528.  
  529.  lives=LIFEMAX:lastblock=16:AUDV0=0:bouncecount=0:maxbounce=0: pulse = 0: heartcolor = 0
  530.  offset = 50
  531.  
  532.  return thisbank
  533.  
  534.  rem ================
  535.  rem ATARIVOX SAVE
  536.  rem ================
  537.  
  538. avoxSave
  539.  if !atarivox then return thisbank
  540.  
  541.  if sc1 > save1 then goto NewHigh
  542.  
  543.  if sc2 > save2 && sc1 = save1 then goto NewHigh
  544.  
  545.  if sc3 > save3 && sc1 = save1 && sc2 = save2 then goto NewHigh
  546.  
  547.  return thisbank
  548.  
  549. NewHigh
  550.  
  551. write1
  552.  temp2=AVoxWriteByte($06,$80,sc1)
  553.  drawscreen
  554.  
  555. write2
  556.  temp2=AVoxWriteByte($06,$81,sc2)
  557.  drawscreen
  558.  
  559. write3
  560.  temp2=AVoxWriteByte($06,$82,sc3)
  561.  save1 = sc1: save2 = sc2: save3 = sc3
  562.  drawscreen
  563.  
  564.  return thisbank
  565.  
  566.  rem ** include the AtariVox wrapper and driver code...
  567.  asm
  568.  
  569. spriteslo
  570.  .byte <heartnone
  571.  .byte <heartsmall
  572.  .byte <heartmed
  573.  .byte <heartlarge
  574.  .byte <playerball
  575.  
  576. spriteshi
  577.  .byte >heartnone
  578.  .byte >heartsmall
  579.  .byte >heartmed
  580.  .byte >heartlarge
  581.  .byte >playerball
  582.  
  583.  if (<*) > (<(*+7))
  584.     repeat ($100-<*)
  585.     .byte 0
  586.     repend
  587.     endif
  588. playerball
  589.     .byte  %11000000
  590.     .byte  %11000000
  591.     .byte  %00000000
  592.     .byte  %00000000
  593.     .byte  %00000000
  594.     .byte  %00000000
  595.     .byte  %00000000
  596.     .byte  %00000000
  597.  if (<*) > (<(*+7))
  598.     repeat ($100-<*)
  599.     .byte 0
  600.     repend
  601.     endif
  602. heartlarge
  603.     .byte  %00010000
  604.     .byte  %00111000
  605.     .byte  %01111100
  606.     .byte  %11111110
  607.     .byte  %11111110
  608.     .byte  %11111110
  609.     .byte  %01101100
  610.     .byte  %00000000
  611.  if (<*) > (<(*+7))
  612.     repeat ($100-<*)
  613.     .byte 0
  614.     repend
  615.     endif
  616. heartmed
  617.     .byte  %00000000
  618.     .byte  %00010000
  619.     .byte  %00111000
  620.     .byte  %01111100
  621.     .byte  %01111100
  622.     .byte  %00101000
  623.     .byte  %00000000
  624.     .byte  %00000000
  625.  if (<*) > (<(*+7))
  626.     repeat ($100-<*)
  627.     .byte 0
  628.     repend
  629.     endif
  630. heartsmall
  631.     .byte  %00000000
  632.     .byte  %00000000
  633.     .byte  %00010000
  634.     .byte  %00111000
  635.     .byte  %00101000
  636.     .byte  %00000000
  637.     .byte  %00000000
  638.     .byte  %00000000
  639.  if (<*) > (<(*+7))
  640.     repeat ($100-<*)
  641.     .byte 0
  642.     repend
  643.     endif
  644. heartnone
  645.     .byte  %00000000
  646.     .byte  %00000000
  647.     .byte  %00000000
  648.     .byte  %00000000
  649.     .byte  %00000000
  650.     .byte  %00000000
  651.     .byte  %00000000
  652.     .byte  %00000000
  653.  
  654.  include "bbavox-eeprom-static.asm"
  655.  
  656.  echo "bswitch jump: ",start
  657. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement