Advertisement
NovaYoshi

DABG object.s

Apr 12th, 2015
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .proc RunObjects
  2.   ldx #0
  3. Loop:
  4.   jsr Launch
  5.   inx
  6.   cpx #ObjectLen
  7.   beq Exit
  8.   jmp Loop
  9.  
  10. Launch:
  11.   lda #2
  12.   sta DispEnemyHead
  13.   lda #8
  14.   sta EnemyWidth
  15.   lda ObjectF1,x
  16.   and #%111110
  17.   beq Exit
  18.   tay
  19.   lda ObjectTable+1,y
  20.   pha
  21.   lda ObjectTable+0,y
  22.   pha
  23. Exit:
  24.   rts
  25. .endproc
  26.  
  27. .proc EmptyObject
  28.   rts
  29. .endproc
  30.  
  31. .proc rand_8_safe
  32.   stx TempVal
  33.   jsr rand_8
  34.   ldx TempVal
  35.   rts
  36. .endproc
  37.  
  38. .proc EnemyShoot
  39.   sta 0 ; 0 - bullet type
  40.   asl
  41.   sta 1 ; 1 - bullet type * 2
  42.   lda ObjectF1,x
  43.   and #1
  44.   sta 2 ; 2 - just the direction bit
  45.   jsr FindFreeBulletY
  46.   bcc Exit
  47.   lda ObjectPX,x
  48.   sta BulletPX,y
  49.   lda ObjectPYH,x
  50.   add #4
  51.   sta BulletPY,y
  52.   lda 0
  53.   ora #%10000000
  54.   sta BulletF,y
  55.  
  56.   stx 3 ; temp to hold X while we look up stuff not related to it
  57.   lda 1
  58.   ora 2
  59.   tax
  60.   lda BulletXSpeedTable,x
  61.   sta BulletVX,y
  62.   ldx 0
  63.   lda BulletLifeTable,x
  64.   sta BulletLife,y
  65.   ldx 3
  66.  
  67.   lda #0
  68.   sta BulletVY,y
  69.   sta BulletVXL,y
  70.   sta BulletVYL,y
  71.   sta BulletPXL,y
  72.   sta BulletPYL,y
  73.  
  74.   lda 0
  75.   cmp #GUN_VERTICAL
  76.   bne :+
  77.     lda #-4
  78.     sta BulletVY,y
  79.     lda ObjectPYH,x
  80.     bmi :+
  81.       lda #4
  82.       sta BulletVY,y
  83.   :
  84.  
  85.   lda 0
  86.   cmp #GUN_DIAGONAL
  87.   bne :+
  88.     lda #-4
  89.     sta BulletVY,y
  90.     lda retraces
  91.     and #%1000000
  92.     beq :+
  93.       lda #4
  94.       sta BulletVY,y
  95.   :
  96.  
  97.   lda BulletPX,y
  98.   add BulletVX,y
  99.   add BulletVX,y
  100.   sta BulletPX,y
  101.   sec
  102. Exit:
  103.   rts
  104. .endproc
  105.  
  106. .proc EnemyShootAtPlayer
  107.   WhichPlayer = 4
  108.   BulletType = 5
  109.   Temp = 6
  110.   Speed = 7
  111.   sta BulletType
  112.   sty WhichPlayer
  113.  
  114.   cpy #-1 ; pick either player
  115.   bne :+
  116.     lda retraces
  117.     and #1
  118.     sta WhichPlayer
  119. : ldy WhichPlayer
  120.   lda PlayerEnabled,y
  121.   bne :+
  122.     tya
  123.     eor #1
  124.     sta WhichPlayer
  125.   :
  126.  
  127.   jsr FindFreeBulletY
  128.   bcc Exit
  129.   lda ObjectPX,x
  130.   sta BulletPX,y
  131.   sta 0
  132.   lda ObjectPYH,x
  133.   add #4
  134.   sta BulletPY,y
  135.   sta 1
  136.   lda BulletType
  137.   ora #%10000000
  138.   sta BulletF,y
  139.  
  140.   stx Temp
  141.   lda BulletType
  142.   tax
  143.   lda BulletXSpeedTable,x
  144.   asl
  145.   asl
  146.   sta Speed
  147.   ldx BulletType
  148.   lda BulletLifeTable,x
  149.   asl
  150.   sta BulletLife,y
  151.   ldx WhichPlayer
  152.   lda PlayerPX,x
  153.   sta 2
  154.   lda PlayerPYH,x
  155.   add #4
  156.   sta 3
  157.   ldx Temp
  158.  
  159.   sty Temp
  160.   jsr getAngle
  161.   tay
  162.   lda Speed
  163.   jsr SpeedAngle2Offset
  164.   ldy Temp
  165.  
  166.   lda #0
  167.   sta BulletPYL,y
  168.  
  169.   lda 0
  170.   sta BulletVXL,y
  171.   lda 1
  172.   sta BulletVX,y
  173.   lda 2
  174.   sta BulletVYL,y
  175.   lda 3
  176.   sta BulletVY,y
  177.   sec
  178. Exit:
  179.   rts
  180. .endproc
  181.  
  182. .proc BulletXSpeedTable
  183.   .byt 0, -0
  184.   .byt 2, -2
  185.   .byt 3, -3 ; faster
  186.   .byt 2, -2 ; energy thing
  187.   .byt 0,  0 ; energy thing (vertical)
  188.   .byt 5, -5 ; FAST energy thing
  189.   .byt 3, -3 ; fast spiky thing
  190.   .byt 2, -2 ; energy thing
  191.   .byt 2, -2 ; player's weapon
  192.   .byt 4, -4 ; diagonal
  193.   .byt 5, -5 ; spike
  194.   .byt 3, -3 ; block
  195.   .byt 3, -3 ; bomb
  196. .endproc
  197. GUN_DIAGONAL = 9
  198. GUN_VERTICAL = 4
  199.  
  200. .proc BulletLifeTable
  201.   .byt 0
  202.   .byt 40
  203.   .byt 20
  204.   .byt 20
  205.   .byt 20
  206.   .byt 20
  207.   .byt 20
  208.   .byt 20
  209.   .byt 20
  210.   .byt 20
  211.   .byt 20
  212.   .byt 20
  213.   .byt 10
  214. .endproc
  215.  
  216. .proc EnemyHurt
  217.   lda ObjectF1,x
  218.   cmp #%01000000 ; any HP left?
  219.   bcc :+         ; if so, just take away 1HP
  220.   sub #%01000000
  221.   sta ObjectF1,x
  222.   sty TempVal
  223.   lda #SOUND_ENEMYHURT2
  224.   jsr start_sound
  225.   ldy TempVal
  226.   rts
  227. : lda #ENEMY_STATE_STUNNED
  228.   sta ObjectF2,x
  229.   lda #200 ; same amount of time as in FHBG
  230.   sta ObjectTimer,x
  231.   sty TempVal
  232.   lda #SOUND_ENEMYHURT
  233.   jsr start_sound
  234.   ldy TempVal
  235.   rts
  236. .endproc
  237.  
  238. .proc EnemyKill
  239.   lda #0
  240.   sta ObjectF1,x
  241.   sta ObjectF2,x
  242.   dec ScreenEnemiesCount
  243.   lda EnemyWidth
  244.   cmp #16
  245.   bne :+
  246.     lda #OBJECT_BOMB*2
  247.     sta ObjectF1,x
  248.     lda #EXTOBJ_POOF
  249.     sta ObjectF3,x
  250.     lda #12
  251.     sta ObjectTimer,x
  252.     ; give a boost
  253.     lda #-3
  254.     sta PlayerVYH,y
  255.     lda #0
  256.     sta PlayerVYL,y
  257.     lda #10
  258.     sta PlayerJumpCancelLock,y
  259.   :
  260.   lda LevelGoalType
  261.   bne :+
  262.     lda LevelGoalParam
  263.     beq :+
  264.       dec LevelGoalParam
  265. : rts
  266. .endproc
  267.  
  268. .proc EnemyPlayerTouch
  269.   ldy #0
  270. PlayerLoop:
  271.   lda PlayerPX,y
  272.   sta TouchLeftA
  273.   lda PlayerPYH,y
  274.   sta TouchTopA
  275.  
  276.   lda ObjectPX,x
  277.   sta TouchLeftB
  278.   lda ObjectPYH,x
  279.   sta TouchTopB
  280.  
  281.   lda EnemyWidth
  282.   sta TouchWidthB
  283.   lda #8
  284.   sta TouchWidthA
  285.   asl
  286.   sta TouchHeightA
  287.   sta TouchHeightB
  288.  
  289.   jsr ChkTouchGeneric
  290.   bcc NotTouched
  291.     lda ObjectF2,x
  292.     cmp #ENEMY_STATE_STUNNED
  293.     beq IsStunned
  294.     bne IsNotStunned
  295. NotTouched:
  296.   iny
  297.   cpy #MaxNumPlayers
  298.   bne PlayerLoop
  299.   rts
  300. IsStunned:
  301.   ; award points for removing the enemy
  302.   stx TempVal+2
  303.   sty TempVal+3
  304.   lda ObjectF1,x ; get the enemy type number from the flags
  305.   alr #%111110
  306.   tay
  307.   lda ObjectPointsTable,y
  308.   ldx TempVal+3
  309.   jsr PlayerAddScore
  310.  
  311.   lda #SOUND_COLLECT
  312.   jsr start_sound
  313.   ldx TempVal+2
  314.   ldy TempVal+3
  315.   clc
  316.   jsr EnemyKill
  317.   jmp NotTouched
  318. IsNotStunned:
  319.   lda EnemyWidth ; wide enemies always hurt
  320.   cmp #8
  321.   beq :+
  322.     lda ObjectF1,x ; unless it's a Goomba then you can stomp it
  323.     alr #%111110
  324.     cmp #OBJECT_GOOMBA
  325.     beq Goomba
  326.     jsr PlayerHurt
  327.     bne NotTouched
  328. : lda GameDifficulty
  329.   cmp #DIFFICULTY_HARDER
  330.   bcc NotTouched
  331. HurtPlayer:
  332.   jsr PlayerHurt
  333.   jmp NotTouched
  334.  
  335. Goomba:
  336.   lda PlayerVYH,y
  337.   bmi HurtPlayer
  338.   cmp #1
  339.   bcs IsStunned
  340.   lda PlayerVYL,y
  341.   bne IsStunned
  342.   beq HurtPlayer
  343. .endproc
  344.  
  345. .proc EnemyGetShot
  346.   lda ObjectPYH,x
  347.   add #8
  348.   lsr
  349.   lsr
  350.   and #%111000
  351.   sta TempVal
  352.   lda ObjectPX,x
  353.   add #4
  354.   lsr ; / 32 pixels
  355.   lsr
  356.   lsr
  357.   lsr
  358.   lsr
  359.   ora TempVal
  360.   tay
  361.   lda BulletMap,y
  362.   beq Exit
  363.  
  364.   ldy #0
  365. BulletLoop:
  366.   lda BulletF,y
  367.   and #%11000000
  368.   cmp #%11000000 ;enabled, player-made bullets only
  369.   bne SkipBullet
  370.  
  371.   lda BulletPX,y
  372.   sta TouchLeftA
  373.   lda BulletPY,y
  374.   sta TouchTopA
  375.  
  376.   lda ObjectPX,x
  377.   sta TouchLeftB
  378.   lda ObjectPYH,x
  379.   sta TouchTopB
  380.  
  381.   lda EnemyWidth
  382.   sta TouchWidthB
  383.   lda #8
  384.   sta TouchWidthA
  385.   sta TouchHeightA
  386.   asl
  387.   sta TouchHeightB
  388.  
  389.   jsr ChkTouchGeneric
  390.   bcs ShotHit
  391. SkipBullet:
  392.   iny
  393.   cpy #BulletLen
  394.   bne BulletLoop
  395. Exit:
  396.   clc
  397.   rts
  398. ShotHit:
  399.   lda #0
  400.   sta BulletF,y
  401.   sec
  402.   rts
  403. .endproc
  404.  
  405. .proc EnemyWalk
  406.   ldy GameDifficulty
  407.   cpy #DIFFICULTY_HARDER ; if hard mode, add 1 to enemy speed
  408.   adc #0                 ; carry set if equal or greater than
  409.   sta 0
  410.  
  411.   lda EnemyWidth
  412.   sta 1
  413.   dec 1
  414.  
  415.   ; if facing left, negate the speed
  416.   lda ObjectF1,x
  417.   and #1
  418.   beq :+
  419.     lda 0
  420.     eor #255
  421.     add #1
  422.     sta 0
  423.     lda #0               ; also start from left instead of right
  424.     sta 1
  425.   :
  426.  
  427.   ; bump check
  428.   lda ObjectPX,x
  429.   add 1                  ; add offset from direction
  430.   add 0                  ; add offset from walking
  431.   lsr
  432.   lsr
  433.   lsr
  434.   lsr
  435.   sta 1
  436.   lda ObjectPYH,x
  437.   add #8
  438.   and #$f0
  439.   ora 1
  440.   tay
  441.   lda LevelBuf,y
  442.   jsr BlockIsSolid
  443.   beq :+
  444.     sec
  445.     rts
  446.   :
  447.  
  448.   ; no bump? add X offset then
  449.   lda ObjectPX,x
  450.   add 0
  451.   sta ObjectPX,x
  452.   clc
  453.   rts
  454. .endproc
  455.  
  456. .proc EnemyAutoBump
  457.   bcc NoBump
  458.   lda ObjectPX,x
  459.   lsr
  460.   lsr
  461.   lsr
  462.   lsr
  463.   sta 0
  464.   lda ObjectPYH,x
  465.   add #15
  466.   and #$f0
  467.   ora 0
  468.   tay
  469.   lda LevelBuf,y
  470.   cmp #METATILE_LAUNCH
  471.   bne :+
  472.     lda #-2
  473.     sta ObjectVYH,x
  474.     lda #0
  475.     sta ObjectVYL,x
  476.     lda ObjectF1,x
  477.     and #1
  478.     tay
  479.     lda ObjectPX,x
  480.     add OffsetAmount,y
  481.     sta ObjectPX,x
  482.     rts
  483. : lda ObjectF1,x
  484.   eor #1
  485.   sta ObjectF1,x
  486. NoBump:
  487.   rts
  488. OffsetAmount:
  489.   .byt 4, -6
  490. .endproc
  491.  
  492. .proc EnemyGravity
  493.   lda ObjectPYL,x
  494.   add ObjectVYL,x
  495.   bcc :+
  496.     inc ObjectPYH,x
  497. : sta ObjectPYL,x
  498.  
  499.   lda ObjectVYH,x
  500.   bmi GravityOkay
  501.   cmp #8
  502.   bcs SkipGravity
  503. GravityOkay:
  504.   lda ObjectVYL,x
  505.   add #32
  506.   bcc :+
  507.     inc ObjectVYH,x
  508. : sta ObjectVYL,x
  509.   SkipGravity:
  510.   lda ObjectPYH,x
  511.   add ObjectVYH,x
  512.   sta ObjectPYH,x
  513.   rts
  514. .endproc
  515.  
  516. .proc EnemyRemoveFromFalling
  517.   lda #0
  518.   sta ObjectF1,x
  519.   sta ObjectF2,x
  520.   dec ScreenEnemiesCount
  521.   rts
  522. .endproc
  523.  
  524. .proc EnemyFallGravityOnly
  525.   lda ObjectPYH,x ; save old py
  526.   sta 0
  527.   jsr EnemyGravity
  528.  
  529.   lda ObjectVYH,x
  530.   bmi :+
  531.     lda ObjectPYH,x
  532.     cmp 0
  533.     bcs :+
  534.       lda LevelGoalType
  535.       bne EnemyRemoveFromFalling
  536.       stx 0
  537.       jsr rand_8
  538.       ldx 0
  539.       sta ObjectPX,x
  540.       and #1
  541.       eor ObjectF1,x
  542.       sta ObjectF1,x
  543. : rts
  544. .endproc
  545.  
  546. .proc EnemyFall ; carry = standing on platform
  547.   lda ObjectPYH,x ; save old py
  548.   sta 0
  549.   jsr EnemyGravity
  550.  
  551.   lda ObjectVYH,x
  552.   bmi :+
  553.     lda ObjectPYH,x
  554.     cmp 0
  555.     bcs :+
  556.       lda LevelGoalType
  557.       bne EnemyRemoveFromFalling
  558.       stx 0
  559.       jsr rand_8
  560.       ldx 0
  561.       sta ObjectPX,x
  562.       and #1
  563.       eor ObjectF1,x
  564.       sta ObjectF1,x
  565. : lda ObjectPX,x
  566.   add #4
  567. .endproc
  568. ; -- inline tail call --
  569. .proc EnemyCollidePlatforms ; A = ObjectPX,x
  570.   ldy ObjectVYH,x
  571.   bmi :+
  572.   lsr
  573.   lsr
  574.   lsr
  575.   lsr
  576.   sta 0
  577.   lda ObjectPYH,x
  578.   add #16          ; maybe change to allow taller enemies?
  579.   and #$f0
  580.   ora 0
  581.   tay
  582.   lda LevelBuf,y
  583.   cmp #FirstSolidTop
  584.   bcc :+
  585.     lda ObjectPYH,x
  586.     and #$f0
  587.     sta ObjectPYH,x
  588.     lda #0
  589.     sta ObjectVYH,x
  590.     sta ObjectVYL,x
  591.     sec
  592.     rts
  593. : clc
  594.   rts
  595. .endproc
  596.  
  597. .proc EnemyFallWide ; carry = standing on platform
  598.   lda ObjectPYH,x ; save old py
  599.   sta 0
  600.   jsr EnemyGravity
  601.  
  602.   lda ObjectVYH,x
  603.   bmi :+
  604.     lda ObjectPYH,x
  605.     cmp 0
  606.     bcs :+
  607.       lda LevelGoalType
  608.       jne EnemyRemoveFromFalling
  609.       stx 0
  610.       jsr rand_8
  611.       ldx 0
  612.       sta ObjectPX,x
  613.       and #1
  614.       eor ObjectF1,x
  615.       sta ObjectF1,x
  616.   :
  617.  
  618.   lda #0
  619.   sta 1
  620.   lda ObjectPX,x
  621.   pha
  622.   jsr EnemyCollidePlatforms
  623.   rol 1
  624.   pla
  625.   add #15
  626.   jsr EnemyCollidePlatforms
  627.   rol 1
  628.   lda 1
  629.   cmp #1
  630.   rts
  631. .endproc
  632.  
  633. .proc AddEnemies
  634.   lda retraces
  635.   and #31
  636.   bne Exit
  637.   lda ScreenEnemiesCount
  638.   cmp MaxScreenEnemies
  639.   bcs Exit
  640.   jsr rand_8
  641.   lsr
  642.   lsr
  643.   and #15
  644.   tax
  645.   lda LevelEnemyPool,x
  646.   sta 0
  647.   jsr FindFreeObjectX
  648.   bcc Exit
  649.  
  650.   lda 0
  651.   pha
  652.   and #%00011111  ; extract enemy type
  653.   asl
  654.   sta ObjectF1,x
  655.  
  656.   cmp #OBJECT_RETARD*2
  657.   bne :+
  658.     ora #%01000000
  659.     sta ObjectF1,x
  660. : cmp #OBJECT_FLAPPY*2
  661.   bne :+
  662.     ora #%01000000
  663.     sta ObjectF1,x
  664. : cmp #OBJECT_TOASTBOT*2
  665.   bne :+
  666.     ora #%10000000
  667.     sta ObjectF1,x    
  668. : cmp #OBJECT_BURGER3*2
  669.   bne :+
  670.     ora #%01000000
  671.     sta ObjectF1,x    
  672. : cmp #OBJECT_POTION*2
  673.   bne :+
  674.     ora #%11000000
  675.     sta ObjectF1,x
  676.   :
  677.  
  678.   jsr rand_8_safe ; random direction
  679.   lsr
  680.   bcc :+
  681.   inc ObjectF1,x
  682. :
  683.   pla
  684.   and #%11100000  ; also put in the parameters
  685.   sta ObjectF3,x
  686.  
  687.   lda #0
  688.   sta ObjectPYH,x
  689.   sta ObjectPYL,x
  690.   sta ObjectVYH,x
  691.   sta ObjectVYL,x
  692.   sta ObjectTimer,x
  693.   jsr rand_8_safe
  694.   sta ObjectPX,x
  695.  
  696.   inc ScreenEnemiesCount
  697. Exit:
  698.   rts
  699. .endproc
  700.  
  701. .proc FindFreeObjectX ; carry = success
  702.   pha
  703.   ldx #0
  704. : lda ObjectF1,x
  705.   beq Found
  706.   inx
  707.   cpx #ObjectLen
  708.   bne :-
  709. NotFound:
  710.   pla
  711.   clc
  712.   rts
  713. Found:
  714.   pla
  715.   sec
  716.   rts
  717. .endproc
  718.  
  719. ; originally 3, 4, 5
  720. ;DispEnemyBodyType = 3
  721. ;DispEnemyWeapon   = 4
  722. ;DispEnemyHead     = 5
  723.  
  724. .proc DispEnemy
  725.   ; 0 - attribute
  726.   ; 1 - used to preserve Y (register)
  727.   ; 2 - used to preserve Y (position)
  728.   ; x - enemy num
  729.   lda ObjectF2,x
  730.   cmp #ENEMY_STATE_STUNNED
  731.   bne :+
  732.     ldy OamPtr
  733.     lda ObjectPYH,x
  734.     sub #1
  735.     sta OAM_YPOS+(4*0),y
  736.     add #8
  737.     sta OAM_YPOS+(4*1),y
  738.  
  739.     lda #OAM_COLOR_1
  740.     sta OAM_ATTR+(4*0),y
  741.     sta OAM_ATTR+(4*1),y
  742.  
  743.     lda #$41
  744.     sta OAM_TILE+(4*0),y
  745.     lda #$51
  746.     sta OAM_TILE+(4*1),y
  747.  
  748.     lda ObjectPX,x
  749.     sub ScrollX+1
  750.     sta OAM_XPOS+(4*0),y
  751.     sta OAM_XPOS+(4*1),y
  752.  
  753.     tya
  754.     add #8
  755.     sta OamPtr
  756.     rts
  757. :
  758.  
  759.   ldy #OAM_COLOR_1
  760.   lda ObjectF1,x
  761.   and #1
  762.   beq :+
  763.     ldy #OAM_XFLIP|OAM_COLOR_1
  764. : sty 0
  765.   ldy OamPtr
  766.  
  767.   lda ObjectPYH,x
  768.   sub #1
  769.   sta OAM_YPOS+(4*0),y
  770.   add #6
  771.   sta OAM_YPOS+(4*2),y
  772.   add #2
  773.   sta OAM_YPOS+(4*1),y
  774.  
  775.   lda 0
  776.   sta OAM_ATTR+(4*0),y
  777.   sta OAM_ATTR+(4*1),y
  778.   sta OAM_ATTR+(4*2),y
  779.  
  780.   lda DispEnemyWeapon
  781.   cmp #GUN_DIAGONAL
  782.   bne :+
  783.     lda retraces
  784.     and #%1000000
  785.     beq :+
  786.       lda 0
  787.       ora #OAM_YFLIP
  788.       sta OAM_ATTR+(4*2),y
  789.   :
  790.  
  791.   lda DispEnemyHead ; player head
  792.   sta OAM_TILE+(4*0),y
  793.  
  794.   ; walking animation
  795.   sty 1 ; save Y (holds OAM pointer)
  796.   lda DispEnemyBodyType ; body type
  797.   asl
  798.   asl
  799.   sta 0
  800.   tay
  801. ; always moving, don't do the check
  802.   lda retraces
  803.   lsr
  804.   lsr
  805.   and #3
  806.   add 0
  807.   tay
  808.  
  809.   lda BodyTypeAnims,y
  810.   ldy 1 ; restore Y
  811.   sta OAM_TILE+(4*1),y
  812.   lda DispEnemyWeapon ; held item
  813.   ora #$20
  814.   sta OAM_TILE+(4*2),y
  815.  
  816.   lda ObjectPX,x
  817.   sub ScrollX+1
  818.   sta OAM_XPOS+(4*0),y
  819.   sta OAM_XPOS+(4*1),y
  820.  
  821.   sty 1
  822.   lda ObjectF1,x
  823.   and #1
  824.   tay
  825.   lda OffsetHeldX,y
  826.   ldy 1
  827.   add ObjectPX,x
  828.   sub ScrollX+1
  829.   sta OAM_XPOS+(4*2),y
  830.  
  831.   tya
  832.   add #16
  833.   tay
  834.   sty OamPtr
  835.   rts
  836. .endproc
  837.  
  838. DispEnemyWide:
  839.   ; 0 - tile 0 (top left)
  840.   ; 1 - tile 1 (bottom left)
  841.   ; 2 - tile 2 (top right)
  842.   ; 3 - tile 3 (bottom right)
  843.   ; 4 - attribute
  844.   ; 5 - flags (from accumulator)
  845.   ; x - enemy num
  846.   ; y - enemy tiles
  847.   sty 0
  848.   iny
  849.   sty 1
  850.   iny
  851.   sty 2
  852.   iny
  853.   sty 3
  854. .proc DispEnemyWideCustom
  855.   Attribute = 4
  856.   Flags = 5
  857.   sta Flags
  858.  
  859.   ldy #OAM_COLOR_1
  860.   lda Flags
  861.   and #2
  862.   bne NoHFlip
  863.   ; flip horizontally
  864.   lsr Flags
  865.   bcc :+
  866.     lda retraces
  867.     and #%100
  868.     beq DoHFlip
  869.     bne NoHFlip
  870.   :
  871.   lda ObjectF1,x
  872.   and #1
  873.   beq NoHFlip
  874. DoHFlip:
  875.     swapy 0, 2
  876.     swapy 1, 3
  877.     ldy #OAM_XFLIP|OAM_COLOR_1
  878. NoHFlip:
  879.   sty Attribute
  880.  
  881.   ; flip vertically
  882.   lda ObjectF2,x
  883.   cmp #ENEMY_STATE_STUNNED
  884.   bne :+
  885.     swapy 0, 1
  886.     swapy 2, 3
  887.     lda Attribute
  888.     ora #OAM_YFLIP
  889.     sta Attribute
  890. :
  891.  
  892.   ldy OamPtr
  893.  
  894.   lda ObjectPYH,x
  895.   sta OAM_YPOS+(4*0),y
  896.   sta OAM_YPOS+(4*2),y
  897.   add #8
  898.   sta OAM_YPOS+(4*1),y
  899.   sta OAM_YPOS+(4*3),y
  900.  
  901.   lda Attribute
  902.   sta OAM_ATTR+(4*0),y
  903.   sta OAM_ATTR+(4*1),y
  904.   sta OAM_ATTR+(4*2),y
  905.   sta OAM_ATTR+(4*3),y
  906.  
  907.   lda 0
  908.   sta OAM_TILE+(4*0),y
  909.   lda 1
  910.   sta OAM_TILE+(4*1),y
  911.   lda 2
  912.   sta OAM_TILE+(4*2),y
  913.   lda 3
  914.   sta OAM_TILE+(4*3),y
  915.  
  916.   lda ObjectPX,x
  917.   sub ScrollX+1
  918.   sta OAM_XPOS+(4*0),y
  919.   sta OAM_XPOS+(4*1),y
  920.   add #8
  921.   sta OAM_XPOS+(4*2),y
  922.   sta OAM_XPOS+(4*3),y
  923.  
  924.   tya
  925.   add #16
  926.   tay
  927.   sty OamPtr
  928.   rts
  929. .endproc
  930.  
  931.  
  932. ENEMY_STATE_BITS    = %1111
  933. ENEMY_STATE_NORMAL  = 0
  934. ENEMY_STATE_PAUSE   = 1
  935. ENEMY_STATE_STUNNED = 2
  936. ENEMY_STATE_ACTIVE  = 3
  937.  
  938. ; enemy types follow this line                 ;
  939. .proc ObjectTable
  940.   .raddr EmptyObject
  941.   .raddr WalkerEnemy
  942.   .raddr JumpyEnemy
  943.   .raddr DiagShooterEnemy
  944.   .raddr WaitingShooterEnemy
  945.   .raddr BombObject
  946.   .raddr FlyBomberEnemy
  947.   .raddr FlyDiagonalEnemy
  948.   .raddr FloatVertShootEnemy
  949.   .raddr GoombaEnemy
  950.   .raddr SneakerEnemy
  951.   .raddr GeorgeEnemy
  952.   .raddr RetardEnemy
  953.   .raddr ToastbotEnemy
  954.   .raddr BurgerEnemy
  955.   .raddr BurgerEnemy
  956.   .raddr BurgerEnemy
  957.   .raddr BillHeadEnemy
  958.   .raddr RollBallEnemy
  959.   .raddr JumpBallEnemy
  960.   .raddr TrigWalkerEnemy
  961.   .raddr TrigBombShooterEnemy
  962.   .raddr ThwompEnemy
  963.   .raddr ThwompEnemy
  964.   .raddr FlappyEnemy
  965.   .raddr PotionEnemy
  966.   .raddr SpearsEnemy
  967. ;  .raddr EmptyObject
  968. .endproc
  969.  
  970. ObjectIsEnemy: ; doubles as a table to find out if an object is an enemy or not
  971.                ; as non-enemies do not give points
  972. .proc ObjectPointsTable
  973.   .byt 0
  974.   .byt 3   ;walker
  975.   .byt 5   ;jumpy
  976.   .byt 7   ;diagshoot
  977.   .byt 10  ;waitshoot
  978.   .byt 0   ;bomb
  979.   .byt 15  ;flybomber
  980.   .byt 12  ;flydiag
  981.   .byt 10  ;floatvertshoot
  982.   .byt 10  ;goomba
  983.   .byt 20  ;sneaker
  984.   .byt 20  ;george
  985.   .byt 14  ;retard
  986.   .byt 13  ;toastbot
  987.   .byt 18  ;burger1
  988.   .byt 24  ;burger2
  989.   .byt 20  ;burger3
  990.   .byt 40  ;bill nye
  991.   .byt 10  ;roll ball
  992.   .byt 15  ;jump ball
  993.   .byt 10  ;trig walk
  994.   .byt 27  ;trig bomber
  995.   .byt 20  ;thwomp static
  996.   .byt 20  ;thwomp move
  997.   .byt 20  ;flappy
  998.   .byt 20  ;potion
  999.   .byt 7   ;spears
  1000. .endproc
  1001.  
  1002. .enum
  1003.   OBJECT_NONE
  1004.   OBJECT_WALKER
  1005.   OBJECT_JUMPY
  1006.   OBJECT_DIAGSHOOT
  1007.   OBJECT_WAITSHOOT
  1008.   OBJECT_BOMB
  1009.   OBJECT_FLYBOMBER
  1010.   OBJECT_FLYDIAG
  1011.   OBJECT_FLOATVERTSHOOT
  1012.   OBJECT_GOOMBA
  1013.   OBJECT_SNEAKER
  1014.   OBJECT_GEORGE
  1015.   OBJECT_RETARD
  1016.   OBJECT_TOASTBOT
  1017.   OBJECT_BURGER1
  1018.   OBJECT_BURGER2
  1019.   OBJECT_BURGER3
  1020.   OBJECT_BILL_HEAD
  1021. ; new stuff, starting at index 18, 13 more slots to go
  1022.   OBJECT_ROLL_BALL
  1023.   OBJECT_BOUNCE_BALL
  1024.   OBJECT_TRIGWALK ; shoots as it walks
  1025.   OBJECT_TRIGBOMB ; gun direction indicates which player it points at
  1026.   OBJECT_THWOMP_STATIC
  1027.   OBJECT_THWOMP_MOVE
  1028.   OBJECT_FLAPPY
  1029.   OBJECT_POTION
  1030.   OBJECT_SPEARS
  1031. .endenum
  1032.  
  1033. .enum
  1034.   EXTOBJ_BOMB
  1035.   EXTOBJ_WATER
  1036.   EXTOBJ_BILLBLOCK
  1037.   EXTOBJ_POOF
  1038.   EXTOBJ_HPLAT
  1039.   EXTOBJ_VPLAT
  1040.   EXTOBJ_HHURT
  1041.   EXTOBJ_VHURT
  1042. .endenum
  1043.  
  1044. .proc EnemyDecTimer
  1045.   lda ObjectTimer,x
  1046.   beq :+
  1047.     dec ObjectTimer,x
  1048.     bne :+
  1049.       lda #ENEMY_STATE_NORMAL
  1050.       sta ObjectF2,x
  1051. : rts
  1052. .endproc
  1053.  
  1054. .proc BillHeadEnemy
  1055.   lda ObjectF2,x
  1056.   jne NoFly
  1057.     lda #4
  1058.     jsr EnemyWalk
  1059.  
  1060.     lda retraces
  1061.     and #3
  1062.     bne NotDropBomb
  1063.     lda MaxScreenEnemies
  1064.     cmp #1
  1065.     beq :+
  1066.       jsr rand_8_safe
  1067.       and #7
  1068.       beq DoDropBomb
  1069.       bne NotDropBomb
  1070.     :
  1071.     jsr rand_8_safe
  1072.     and #3
  1073.     bne NotDropBomb
  1074. DoDropBomb:
  1075.     lda ObjectPX,x
  1076.     pha
  1077.     add #12
  1078.     sta ObjectPX,x
  1079.     jsr DropBomb
  1080.     pla
  1081.     sta ObjectPX,x
  1082.   NotDropBomb:
  1083.  
  1084.     lda ObjectF1,x ; pick between left/right values for flying into wall
  1085.     and #1
  1086.     tay
  1087.     beq :+         ; left edge
  1088.       lda ObjectPX,x
  1089.       cmp #10
  1090.       bcs NoFly
  1091.       bcc HitWall
  1092.   : lda ObjectPX,x ; right edge
  1093.     cmp #256-24-10
  1094.     bcc NoFly
  1095.   HitWall:
  1096.     lda SideStartX,y
  1097.     sta ObjectPX,x
  1098.     lda ObjectF1,x
  1099.     eor #1
  1100.     sta ObjectF1,x
  1101.     lda #60
  1102.     sta ObjectTimer,x
  1103.     lda #ENEMY_STATE_PAUSE
  1104.     sta ObjectF2,x
  1105.     sty TempVal+1
  1106.     jsr rand_8_safe
  1107.     lsr
  1108.     add #80
  1109.     sta ObjectPYH,x
  1110.     stx TempVal
  1111.     jsr FindFreeObjectX
  1112.     bcc NoFly
  1113.     ldy TempVal+1
  1114.     lda SideStartX2,y
  1115.     sta ObjectPX,x
  1116.  
  1117.     ldy TempVal
  1118.  
  1119.     lda ObjectF1,y
  1120.     and #1
  1121.     ora #OBJECT_BOMB*2
  1122.     sta ObjectF1,x
  1123.     lda #EXTOBJ_BILLBLOCK
  1124.     sta ObjectF3,x
  1125.  
  1126.     lda ObjectPYH,y
  1127.     add #4
  1128.     sta ObjectPYH,x
  1129.     lda #20
  1130.     sta ObjectTimer,x
  1131.  
  1132.     tya
  1133.     tax
  1134.   NoFly:
  1135.  
  1136.   ; collide with blocks
  1137.   ldy #0
  1138. ObjLoop:
  1139.   lda ObjectF1,y
  1140.   bpl SkipObj ; don't react to blocks that haven't been reflected
  1141.   and #%111110
  1142.   cmp #OBJECT_BOMB*2
  1143.   bne SkipObj
  1144.  
  1145.   lda ObjectF3,y
  1146.   cmp #EXTOBJ_BILLBLOCK
  1147.   bne SkipObj
  1148.  
  1149.   lda ObjectPX,y
  1150.   sta TouchLeftA
  1151.   lda ObjectPYH,y
  1152.   sta TouchTopA
  1153.  
  1154.   lda ObjectPX,x
  1155.   sta TouchLeftB
  1156.   lda ObjectPYH,x
  1157.   sta TouchTopB
  1158.  
  1159.   lda #16
  1160.   sta TouchWidthA
  1161.   sta TouchHeightA
  1162.   lda #24
  1163.   sta TouchWidthB
  1164.   sta TouchHeightB
  1165.  
  1166.   jsr ChkTouchGeneric
  1167.   bcc :+
  1168.     lda #0
  1169.     sta ObjectF1,y
  1170.     lda #10
  1171.     sta ObjectTimer,x
  1172.     lda #ENEMY_STATE_PAUSE
  1173.     sta ObjectF2,x
  1174.     inc ObjectF3,x
  1175.     lda ObjectF3,x
  1176.     cmp #4
  1177.     bcc NotKilled
  1178.       sty TempVal
  1179.       lda #SOUND_EXPLODE1
  1180.       jsr start_sound
  1181.       lda #SOUND_EXPLODE2
  1182.       jsr start_sound
  1183.       lda #-2
  1184.       sta ObjectVYH,x
  1185.       ldy TempVal
  1186.       jmp :+
  1187.     NotKilled:
  1188.  
  1189.     sty TempVal
  1190.     lda #SOUND_ENEMYHURT2
  1191.     jsr start_sound
  1192.     ldy TempVal
  1193.   :
  1194. SkipObj:
  1195.   iny
  1196.   cpy #ObjectLen
  1197.   bne ObjLoop
  1198.  
  1199.   ; fall when dying
  1200.   lda ObjectF3,x
  1201.   cmp #4
  1202.   bcc :+
  1203.     jsr EnemyFallGravityOnly
  1204.     lda #1
  1205.     sta ObjectF2,x
  1206.     lda #10
  1207.     sta ObjectTimer,x
  1208.     lda ObjectPYH,x
  1209.     cmp #240
  1210.     bcc :+
  1211.       jmp EnemyKill
  1212.   :
  1213.  
  1214.   lda ObjectF1,x
  1215.   jeq Exit
  1216.  
  1217.   jsr EnemyDecTimer
  1218.  
  1219. ; draw sprite                    
  1220.   ldy OamPtr
  1221.   lda ObjectPYH,x
  1222.   sta OAM_YPOS+(4*0),y
  1223.   sta OAM_YPOS+(4*1),y
  1224.   sta OAM_YPOS+(4*2),y
  1225.   add #8
  1226.   sta OAM_YPOS+(4*3),y
  1227.   sta OAM_YPOS+(4*4),y
  1228.   sta OAM_YPOS+(4*5),y
  1229.   add #8
  1230.   sta OAM_YPOS+(4*6),y
  1231.   sta OAM_YPOS+(4*7),y
  1232.   sta OAM_YPOS+(4*8),y
  1233.  
  1234.   lda #OAM_COLOR_1
  1235.   sta 1
  1236.  
  1237.   lda ObjectF1,x
  1238.   and #1
  1239.   sta 0
  1240.   pha
  1241.   stx TempVal
  1242.   ldx #0
  1243.   pla
  1244.   beq :+
  1245.     ldx #9
  1246.     lda #OAM_COLOR_1 + OAM_XFLIP
  1247.     sta 1
  1248.   :
  1249.  
  1250.   lda 1
  1251.   sta OAM_ATTR+(4*0),y
  1252.   sta OAM_ATTR+(4*1),y
  1253.   sta OAM_ATTR+(4*2),y
  1254.   sta OAM_ATTR+(4*3),y
  1255.   sta OAM_ATTR+(4*4),y
  1256.   sta OAM_ATTR+(4*5),y
  1257.   sta OAM_ATTR+(4*6),y
  1258.   sta OAM_ATTR+(4*7),y
  1259.   sta OAM_ATTR+(4*8),y
  1260.  
  1261.   lda Tiles1+0,x
  1262.   sta OAM_TILE+(4*0),y
  1263.   lda Tiles1+1,x
  1264.   sta OAM_TILE+(4*1),y
  1265.   lda Tiles1+2,x
  1266.   sta OAM_TILE+(4*2),y
  1267.   lda Tiles1+3,x
  1268.   sta OAM_TILE+(4*3),y
  1269.   lda Tiles1+4,x
  1270.   sta OAM_TILE+(4*4),y
  1271.   lda Tiles1+5,x
  1272.   sta OAM_TILE+(4*5),y
  1273.   lda Tiles1+6,x
  1274.   sta OAM_TILE+(4*6),y
  1275.   lda Tiles1+7,x
  1276.   sta OAM_TILE+(4*7),y
  1277.   lda Tiles1+8,x
  1278.   sta OAM_TILE+(4*8),y
  1279.   ldx TempVal
  1280.  
  1281.   lda ObjectPX,x
  1282.   sub ScrollX+1
  1283.   sta OAM_XPOS+(4*0),y
  1284.   sta OAM_XPOS+(4*3),y
  1285.   sta OAM_XPOS+(4*6),y
  1286.   add #8
  1287.   sta OAM_XPOS+(4*1),y
  1288.   sta OAM_XPOS+(4*4),y
  1289.   sta OAM_XPOS+(4*7),y
  1290.   add #8
  1291.   sta OAM_XPOS+(4*2),y
  1292.   sta OAM_XPOS+(4*5),y
  1293.   sta OAM_XPOS+(4*8),y
  1294.   tya
  1295.   add #36
  1296.   sta OamPtr
  1297. Exit:
  1298.   rts
  1299.  
  1300. Tiles1: .byt $70, $71, $72, $80, $81, $82, $90, $91, $92
  1301. Tiles2: .byt $72, $71, $70, $82, $81, $80, $92, $91, $90
  1302.  
  1303. SideStartX: .byt 256-24, 0
  1304. SideStartX2: .byt 256-24-16, 24
  1305. .endproc
  1306.  
  1307. .proc BillBlockObject
  1308.   asl EnemyWidth
  1309.   lda ObjectTimer,x
  1310.   bne :+
  1311.     lda ObjectF1,x
  1312.     and #1
  1313.     tay
  1314.     lda ObjectPX,x
  1315.     add Dirs,y
  1316.     sta ObjectPX,x
  1317.   :
  1318.   jsr EnemyPlayerTouch
  1319.   jsr EnemyGetShot
  1320.   bcc :+
  1321.     lda ObjectF1,x
  1322.     bmi :+     ; only reverse position once
  1323.     eor #1+128 ; EOR will always set the most significant bit since it can't get here if set
  1324.     sta ObjectF1,x
  1325.   :
  1326.  
  1327.   lda ObjectPX,x
  1328.   cmp #16
  1329.   bcc Remove
  1330.   cmp #256-16
  1331.   bcs Remove
  1332.  
  1333.   jsr EnemyDecTimer
  1334.   ldy #$64
  1335.   lda #2
  1336.   jsr DispEnemyWide
  1337.   rts
  1338. Remove:
  1339.   lda #0
  1340.   sta ObjectF1,x
  1341.   rts
  1342. Dirs:
  1343.   .byt 4, -4
  1344. .endproc
  1345.  
  1346. .proc PoofObject
  1347.   ldy OamPtr
  1348.   lda ObjectPYH,x
  1349.   sta OAM_YPOS+(4*0),y
  1350.   sta OAM_YPOS+(4*1),y
  1351.   add #8
  1352.   sta OAM_YPOS+(4*2),y
  1353.   sta OAM_YPOS+(4*3),y
  1354.   lda #OAM_COLOR_1
  1355.   sta OAM_ATTR+(4*0),y
  1356.   lda #OAM_COLOR_1 + OAM_XFLIP
  1357.   sta OAM_ATTR+(4*1),y
  1358.   lda #OAM_COLOR_1 + OAM_YFLIP
  1359.   sta OAM_ATTR+(4*2),y
  1360.   lda #OAM_COLOR_1 + OAM_XFLIP + OAM_YFLIP
  1361.   sta OAM_ATTR+(4*3),y
  1362.  
  1363.   lda #12
  1364.   sub ObjectTimer,x
  1365.   lsr
  1366.   lsr
  1367.   add #$61
  1368.   sta OAM_TILE+(4*0),y
  1369.   sta OAM_TILE+(4*1),y
  1370.   sta OAM_TILE+(4*2),y
  1371.   sta OAM_TILE+(4*3),y
  1372.  
  1373.   lda ObjectPX,x
  1374.   sub ScrollX+1
  1375.   sta OAM_XPOS+(4*0),y
  1376.   sta OAM_XPOS+(4*2),y
  1377.   add #8
  1378.   sta OAM_XPOS+(4*1),y
  1379.   sta OAM_XPOS+(4*3),y
  1380.   tya
  1381.   add #16
  1382.   sta OamPtr
  1383.  
  1384.   dec ObjectTimer,x
  1385.   bne :+
  1386.     lda #0
  1387.     sta ObjectF1,x
  1388. : rts
  1389. .endproc
  1390.  
  1391. .proc WalkerEnemy
  1392.   lda #1
  1393.   sta DispEnemyBodyType
  1394.   lda #1
  1395.   sta DispEnemyWeapon
  1396.  
  1397.   jsr GetShot
  1398.  
  1399.   jsr EnemyFall
  1400.  
  1401.   lda ObjectF1,x
  1402.   beq Exit
  1403.   bcc DontMove
  1404.     lda ObjectF2,x
  1405.     bne DontMove
  1406.  
  1407.     lda #2
  1408.     jsr EnemyWalk
  1409.     jsr EnemyAutoBump
  1410.  
  1411.     jsr rand_8_safe
  1412.     and #%1111
  1413.     bne DontMove
  1414.       lda #1
  1415.       jsr EnemyShoot
  1416. DontMove:
  1417.  
  1418.   jsr EnemyPlayerTouch
  1419.   lda ObjectF1,x
  1420.   beq Exit
  1421.  
  1422.   jsr EnemyDecTimer
  1423.   jsr DispEnemy
  1424. Exit:
  1425.   rts
  1426. .endproc
  1427.  
  1428. .proc PotionEnemy
  1429.   asl EnemyWidth
  1430.   jsr GetShot
  1431.  
  1432.   jsr EnemyFallWide
  1433.   bcc DontMove
  1434.   lda ObjectF1,x
  1435.   beq Exit
  1436.     lda #1
  1437.     jsr EnemyWalk
  1438.     jsr EnemyAutoBump
  1439.  
  1440.     lda ObjectF2,x
  1441.     bne DontMove
  1442.     jsr rand_8_safe
  1443.     and #15
  1444.     bne DontMove
  1445.       jsr LaunchWaterBottle
  1446. DontMove:
  1447.  
  1448.   jsr EnemyPlayerTouch
  1449.   lda ObjectF1,x
  1450.   beq Exit
  1451.  
  1452.   jsr EnemyDecTimer
  1453.  
  1454.   lda retraces
  1455.   ldy #$b4
  1456.   lda #2
  1457.   jsr DispEnemyWide
  1458. Exit:
  1459.   rts
  1460. .endproc
  1461.  
  1462. .proc SpearsEnemy
  1463.   lda #1
  1464.   sta DispEnemyBodyType
  1465.   lda #10
  1466.   sta DispEnemyWeapon
  1467.  
  1468.   jsr GetShot
  1469.  
  1470.   jsr EnemyFall
  1471.  
  1472.   lda ObjectF1,x
  1473.   beq Exit
  1474.   bcc DontMove
  1475.     lda ObjectF2,x
  1476.     bne DontMove
  1477.  
  1478.     lda #3
  1479.     jsr EnemyWalk
  1480.     jsr EnemyAutoBump
  1481.  
  1482.     jsr rand_8_safe
  1483.     and #%1111
  1484.     bne DontMove
  1485.  
  1486.       lda ObjectF1,x
  1487.       pha
  1488.       and #~1
  1489.       sta ObjectF1,x
  1490.       lda #10
  1491.       jsr EnemyShoot
  1492.       pla
  1493.       sta ObjectF1,x
  1494. DontMove:
  1495.  
  1496.   jsr EnemyPlayerTouch
  1497.   lda ObjectF1,x
  1498.   beq Exit
  1499.  
  1500.   jsr EnemyDecTimer
  1501.   lda ObjectF1,x
  1502.   pha
  1503.   and #~1
  1504.   sta ObjectF1,x
  1505.   jsr DispEnemy
  1506.   pla
  1507.   sta ObjectF1,x
  1508. Exit:
  1509.   rts
  1510. .endproc
  1511.  
  1512.  
  1513. .proc TrigWalkerEnemy
  1514.   lda #1
  1515.   sta DispEnemyBodyType
  1516.   lda #6
  1517.   sta DispEnemyWeapon
  1518.  
  1519.   jsr GetShot
  1520.   jsr EnemyFall
  1521.  
  1522.   lda ObjectF1,x
  1523.   beq Exit
  1524.   bcc DontMove
  1525.     lda ObjectF2,x
  1526.     bne DontMove
  1527.  
  1528.     lda #2
  1529.     jsr EnemyWalk
  1530.     jsr EnemyAutoBump
  1531.  
  1532.     jsr rand_8_safe
  1533.     and #%1111
  1534.     bne DontMove
  1535.       lda #6
  1536.       ldy #-1
  1537.       jsr EnemyShootAtPlayer
  1538. DontMove:
  1539.  
  1540.   jsr EnemyPlayerTouch
  1541.   lda ObjectF1,x
  1542.   beq Exit
  1543.  
  1544.   jsr EnemyDecTimer
  1545.   jsr DispEnemy
  1546. Exit:
  1547.   rts
  1548. .endproc
  1549.  
  1550. .proc TrigBombShooterEnemy
  1551.   lda #1
  1552.   sta DispEnemyBodyType
  1553.   lda #12
  1554.   sta DispEnemyWeapon
  1555.  
  1556.   jsr GetShot
  1557.   jsr EnemyFall
  1558.  
  1559.   lda ObjectF1,x
  1560.   beq Exit
  1561.   bcc DontMove
  1562.     lda ObjectF2,x
  1563.     bne DontMove
  1564.  
  1565.     lda #2
  1566.     jsr EnemyWalk
  1567.     jsr EnemyAutoBump
  1568.  
  1569.     jsr rand_8_safe
  1570.     and #%1111
  1571.     bne DontMove
  1572.       lda retraces
  1573.       and #%1000000
  1574.       beq :+
  1575.         lda #1
  1576.     : tay
  1577.       lda PlayerEnabled,y
  1578.       beq DontMove
  1579.       lda #12
  1580.       jsr EnemyShootAtPlayer
  1581. DontMove:
  1582.  
  1583.   jsr EnemyPlayerTouch
  1584.   lda ObjectF1,x
  1585.   beq Exit
  1586.  
  1587.   jsr EnemyDecTimer
  1588.   jsr DispEnemy
  1589. Exit:
  1590.   rts
  1591. .endproc
  1592.  
  1593. .proc DropBomb
  1594.   txa
  1595.   tay
  1596.   lda #-1
  1597.   sta BombDroppedIndex ; error code for if the index is invalid due to no free slots
  1598.   jsr FindFreeObjectX
  1599.   php
  1600.   bcc Restore
  1601.  
  1602.   lda #OBJECT_BOMB*2
  1603.   sta ObjectF1,x
  1604.  
  1605.   lda ObjectPYH,y
  1606.   sta ObjectPYH,x
  1607.   lda #-1
  1608.   sta ObjectVYH,x
  1609.   lda #0
  1610.   sta ObjectPYL,x
  1611.   sta ObjectVYL,x
  1612.   sta ObjectTimer,x
  1613.   sta ObjectF3,x
  1614.   lda ObjectPX,y
  1615.   sta ObjectPX,x
  1616.   stx BombDroppedIndex
  1617.   inc ScreenEnemiesCount
  1618. Restore:
  1619.   tya
  1620.   tax
  1621.   plp
  1622.   rts
  1623. .endproc
  1624.  
  1625. .proc FlyBomberEnemy
  1626.   lda #6
  1627.   sta DispEnemyBodyType
  1628.   asl ;lda #12
  1629.   sta DispEnemyWeapon
  1630.   lda #14
  1631.   sta DispEnemyHead
  1632.  
  1633.   jsr EnemyFall
  1634.   lda ObjectF1,x
  1635.   jeq Exit
  1636.  
  1637.   lda ObjectVYH,x
  1638.   bmi :+
  1639.   cmp #2
  1640.   bcc :+
  1641.     jsr rand_8_safe
  1642.     and #7
  1643.     bne :+
  1644.     lda #-2
  1645.     sta ObjectVYH,x
  1646.     lda #80
  1647.     sta ObjectVYL,x
  1648.   :
  1649.  
  1650.   jsr GetShot
  1651.  
  1652.   lda ObjectF2,x
  1653.   bne DontMove
  1654.     lda #2
  1655.     jsr EnemyWalk
  1656.     jsr EnemyAutoBump
  1657.  
  1658.     lda retraces
  1659.     and #7
  1660.     bne DontMove
  1661.     jsr rand_8_safe
  1662.     and #%1111
  1663.     bne DontMove
  1664.       jsr DropBomb
  1665. DontMove:
  1666.  
  1667.   jsr EnemyPlayerTouch
  1668.   lda ObjectF1,x
  1669.   beq Exit
  1670.  
  1671.   jsr EnemyDecTimer
  1672.   jsr DispEnemy
  1673. Exit:
  1674.   rts
  1675. .endproc
  1676.  
  1677. .proc FlyDiagonalEnemy
  1678.   lda #6
  1679.   sta DispEnemyBodyType
  1680.   lda #GUN_DIAGONAL
  1681.   sta DispEnemyWeapon
  1682.   lda #3
  1683.   sta DispEnemyHead
  1684.  
  1685.   jsr EnemyFall
  1686.   lda ObjectF1,x
  1687.   jeq Exit
  1688.  
  1689.   lda ObjectVYH,x
  1690.   bmi :+
  1691.   cmp #2
  1692.   bcc :+
  1693.     jsr rand_8_safe
  1694.     and #7
  1695.     bne :+
  1696.     lda #-2
  1697.     sta ObjectVYH,x
  1698.     lda #80
  1699.     sta ObjectVYL,x
  1700.   :
  1701.  
  1702.   jsr GetShot
  1703.  
  1704.   lda ObjectF2,x
  1705.   bne DontMove
  1706.     lda #2
  1707.     jsr EnemyWalk
  1708.     jsr EnemyAutoBump
  1709.  
  1710.     lda retraces
  1711.     and #7
  1712.     bne DontMove
  1713.     jsr rand_8_safe
  1714.     and #%1111
  1715.     bne DontMove
  1716.       lda #GUN_DIAGONAL
  1717.       jsr EnemyShoot
  1718. DontMove:
  1719.  
  1720.   jsr EnemyPlayerTouch
  1721.   lda ObjectF1,x
  1722.   beq Exit
  1723.  
  1724.   jsr EnemyDecTimer
  1725.   jsr DispEnemy
  1726. Exit:
  1727.   rts
  1728. .endproc
  1729.  
  1730. .proc BombObject
  1731.   lda ObjectF3,x
  1732.   cmp #EXTOBJ_BILLBLOCK
  1733.   jeq BillBlockObject
  1734.   cmp #EXTOBJ_POOF
  1735.   jeq PoofObject
  1736.   cmp #EXTOBJ_HPLAT
  1737.   jcs MovingObject
  1738.   jeq PoofObject
  1739.  
  1740.   jsr EnemyFall
  1741.   bcc NoExplode
  1742.  
  1743.   lda ObjectPX,x
  1744.   sta 0
  1745.   lda ObjectPYH,x
  1746.   add #8
  1747.   sta 1
  1748.   lda #20
  1749.   jsr CreateExplosion
  1750.   jmp EnemyRemoveFromFalling
  1751. NoExplode:
  1752.   lda ObjectPYH,x
  1753.   cmp #255-16
  1754.   jcs EnemyRemoveFromFalling
  1755.  
  1756.   ldy OamPtr
  1757.  
  1758.   lda ObjectF3,x
  1759.   bne WaterBottle
  1760.   lda ObjectPYH,x
  1761.   add #7
  1762.   sta OAM_YPOS+(4*0),y
  1763.   lda #OAM_COLOR_1
  1764.   sta OAM_ATTR+(4*0),y
  1765.   lda #$3c
  1766.   sta OAM_TILE+(4*0),y
  1767.   lda ObjectPX,x
  1768.   sub ScrollX+1
  1769.   sta OAM_XPOS+(4*0),y
  1770.  
  1771.   tya
  1772.   add #4
  1773.   sta OamPtr
  1774. Exit:
  1775.   rts
  1776.  
  1777. WaterBottle:
  1778.   lda ObjectPYH,x
  1779.   sta OAM_YPOS+(4*0),y
  1780.   add #8
  1781.   sta OAM_YPOS+(4*1),y
  1782.   lda #OAM_COLOR_1
  1783.   sta OAM_ATTR+(4*0),y
  1784.   sta OAM_ATTR+(4*1),y
  1785.   lda #$75
  1786.   sta OAM_TILE+(4*0),y
  1787.   lda #$85
  1788.   sta OAM_TILE+(4*1),y
  1789.   lda ObjectVYH,x
  1790.   bmi :+
  1791.     lda #OAM_COLOR_1 + OAM_YFLIP
  1792.     sta OAM_ATTR+(4*0),y
  1793.     sta OAM_ATTR+(4*1),y
  1794.     lda #$85
  1795.     sta OAM_TILE+(4*0),y
  1796.     lda #$75
  1797.     sta OAM_TILE+(4*1),y
  1798. : lda ObjectPX,x
  1799.   sub ScrollX+1
  1800.   sta OAM_XPOS+(4*0),y
  1801.   sta OAM_XPOS+(4*1),y
  1802.  
  1803.   tya
  1804.   add #8
  1805.   sta OamPtr
  1806.   rts
  1807. .endproc
  1808.  
  1809. .proc DoMoveHorizOrVert
  1810.   cpy #1
  1811.   beq DoVert
  1812.   lda ObjectF1,x
  1813.   and #1
  1814.   tay
  1815.   lda ObjectPX,x
  1816.   add Move4Dir,y
  1817.   sta ObjectPX,x  
  1818.   add Offset4Dir,y
  1819.   lsr
  1820.   lsr
  1821.   lsr
  1822.   lsr
  1823.   sta 0
  1824.   lda ObjectPYH,x
  1825.   and #$f0
  1826.   ora 0
  1827.   tay
  1828.   lda LevelBuf,y
  1829.   cmp #FirstSolidTop
  1830.   bcc :+
  1831.   lda ObjectF1,x
  1832.   eor #1
  1833.   sta ObjectF1,x
  1834. : rts
  1835.  
  1836. DoVert:
  1837.   lda ObjectF1,x
  1838.   eor #1
  1839.   and #1
  1840.   tay
  1841.   lda ObjectPYH,x
  1842.   add Move4Dir,y
  1843.   sta ObjectPYH,x  
  1844.   and #$f0
  1845.   sta 0
  1846.   lda ObjectPX,x
  1847.   lsr
  1848.   lsr
  1849.   lsr
  1850.   lsr
  1851.   ora 0
  1852.   tay
  1853.   lda LevelBuf+1+16,y
  1854.   cmp #FirstSolidTop
  1855.   bcs :+
  1856.   lda LevelBuf-1+16,y
  1857.   cmp #FirstSolidTop
  1858.   bcs :+
  1859.   rts
  1860. : lda ObjectF1,x
  1861.   eor #1
  1862.   sta ObjectF1,x
  1863.   rts
  1864.  
  1865. Move4Dir:
  1866.   .byt 1,-1
  1867. Offset4Dir:
  1868.   .byt 15,0
  1869. .endproc
  1870.  
  1871. .proc PlayerOnMovingPlatform
  1872.   ldy #0
  1873.   jsr Try
  1874.   iny
  1875.   jsr Try
  1876.   rts
  1877. Try:
  1878.   lda PlayerEnabled,y
  1879.   beq No
  1880.   lda PlayerPX,y
  1881.   sta TouchLeftA
  1882.   lda PlayerPYH,y
  1883.   sta TouchTopA
  1884.  
  1885.   lda ObjectPX,x
  1886.   sta TouchLeftB
  1887.   lda ObjectPYH,x
  1888.   sta TouchTopB
  1889.  
  1890.   lda #16
  1891.   sta TouchWidthB
  1892.   sta TouchHeightA
  1893.   sta TouchHeightB
  1894.   lsr
  1895.   sta TouchWidthA
  1896.  
  1897.   jsr ChkTouchGeneric
  1898.   bcs Yes
  1899. No:
  1900.   rts
  1901. Yes:
  1902.   lda PlayerDead,y
  1903.   bne No
  1904.   lda PlayerVYH,y
  1905.   bmi No
  1906.   lda #-2
  1907.   sta PlayerVYH,y
  1908.   lda #0
  1909.   sta PlayerVYL,y
  1910.   lda #1
  1911.   sta PlayerJumpCancelLock,y
  1912.  
  1913.   lda ObjectPYH,x
  1914.   sub #16
  1915.   sta PlayerPYH,y
  1916.  
  1917.   inc 4 ;NeedSpringNoise
  1918.   rts
  1919. .endproc
  1920.  
  1921. .proc MovingObject
  1922.   IsVert = 0
  1923.   IsHurt = 1
  1924.   AddTile = 3
  1925.   NeedSpringNoise = 4
  1926.   sub #EXTOBJ_HPLAT
  1927.   pha
  1928.   and #1
  1929.   sta IsVert
  1930.   lda #0
  1931.   sta NeedSpringNoise
  1932.   pla
  1933.   lsr
  1934.   sta IsHurt
  1935. ; --- move ---
  1936.   bne :+
  1937.     jsr PlayerOnMovingPlatform
  1938.   :
  1939.  
  1940.   ldy IsVert
  1941.   jsr DoMoveHorizOrVert
  1942. ; --- draw ---  
  1943.   lda IsHurt
  1944.   beq :+
  1945.   ldy #$7c
  1946.   lda #0
  1947.   asl EnemyWidth
  1948.   jsr DispEnemyWide
  1949.   jmp EnemyPlayerTouch
  1950. :
  1951.   ldy OamPtr
  1952.   lda ObjectPYH,x
  1953.   sta OAM_YPOS+(4*0),y
  1954.   sta OAM_YPOS+(4*1),y
  1955.   add #8
  1956.   sta OAM_YPOS+(4*2),y
  1957.   sta OAM_YPOS+(4*3),y
  1958.  
  1959.   lda #OAM_COLOR_1
  1960.   sta OAM_ATTR+(4*0),y
  1961.   sta OAM_ATTR+(4*3),y
  1962.   lda #OAM_COLOR_1 | OAM_XFLIP
  1963.   sta OAM_ATTR+(4*1),y
  1964.   sta OAM_ATTR+(4*2),y
  1965.  
  1966.   lda ObjectPX,x
  1967.   sub ScrollX+1
  1968.   sta OAM_XPOS+(4*0),y
  1969.   sta OAM_XPOS+(4*3),y
  1970.   add #8
  1971.   sta OAM_XPOS+(4*1),y
  1972.   sta OAM_XPOS+(4*2),y
  1973.  
  1974.   lda retraces
  1975.   and #%10000
  1976.   add #$74
  1977.   sta OAM_TILE+(4*2),y
  1978.   sta OAM_TILE+(4*3),y
  1979.   lda #$73
  1980.   sta OAM_TILE+(4*0),y
  1981.   sta OAM_TILE+(4*1),y
  1982.   tya
  1983.   add #16
  1984.   sta OamPtr
  1985.  
  1986.   lda NeedSpringNoise
  1987.   beq :+
  1988.     lda #SOUND_SPRING
  1989.     jsr start_sound
  1990. : rts
  1991. .endproc
  1992.  
  1993. .proc JumpyEnemy
  1994.   lda #5
  1995.   sta DispEnemyBodyType
  1996.   lda #2
  1997.   sta DispEnemyWeapon
  1998.  
  1999.   jsr GetShot
  2000.  
  2001.   lda ObjectF2,x
  2002.   bne :+
  2003.     lda #2
  2004.     jsr EnemyWalk
  2005.     jsr EnemyAutoBump
  2006.   :
  2007.  
  2008.   jsr EnemyFall
  2009.   bcc DontMove
  2010.   lda ObjectF1,x
  2011.   beq Exit
  2012.     lda ObjectF2,x
  2013.     bne DontMove
  2014.  
  2015.     jsr rand_8_safe
  2016.     ora #%11111100
  2017.     sta ObjectVYH,x
  2018.     jsr rand_8_safe
  2019.     ora #%10000000
  2020.     sta ObjectVYL,x
  2021.  
  2022.     jsr rand_8_safe
  2023.     pha
  2024.     asl
  2025.     bcc :+
  2026.     lda ObjectF1,x
  2027.     eor #1
  2028.     sta ObjectF1,x
  2029. :
  2030.     pla
  2031.     and #11
  2032.     bne DontMove
  2033.       lda #2
  2034.       jsr EnemyShoot
  2035. DontMove:
  2036.  
  2037.   jsr EnemyPlayerTouch
  2038.   lda ObjectF1,x
  2039.   beq Exit
  2040.  
  2041.   jsr EnemyDecTimer
  2042.  
  2043.   jsr DispEnemy
  2044. Exit:
  2045.   rts
  2046. .endproc
  2047.  
  2048. .proc DiagShooterEnemy
  2049.   lda #0
  2050.   sta DispEnemyBodyType
  2051.   lda #GUN_DIAGONAL
  2052.   sta DispEnemyWeapon
  2053.   lda #3
  2054.   sta DispEnemyHead
  2055.  
  2056.   jsr GetShot
  2057.  
  2058.   jsr EnemyFall
  2059.   lda ObjectF1,x
  2060.   beq Exit
  2061.   bcc DontMove
  2062.     lda ObjectF2,x
  2063.     bne DontMove
  2064.  
  2065.     lda #1
  2066.     jsr EnemyWalk
  2067.     jsr EnemyAutoBump
  2068.  
  2069.     jsr rand_8_safe
  2070.     and #%1111
  2071.     bne DontMove
  2072.       lda #GUN_DIAGONAL
  2073.       jsr EnemyShoot
  2074. DontMove:
  2075.  
  2076.   jsr EnemyPlayerTouch
  2077.   lda ObjectF1,x
  2078.   beq Exit
  2079.  
  2080.   jsr EnemyDecTimer
  2081.   jsr DispEnemy
  2082. Exit:
  2083.   rts
  2084. .endproc
  2085.  
  2086. .proc WaitingShooterEnemy
  2087.   lda #0
  2088.   sta DispEnemyBodyType
  2089.   lda #GUN_DIAGONAL
  2090.   sta DispEnemyWeapon
  2091.  
  2092.   jsr GetShot
  2093.  
  2094.   jsr EnemyFall
  2095.   lda ObjectF1,x
  2096.   beq Exit
  2097.   bcc DontMove
  2098.   jsr rand_8_safe
  2099.   and #3
  2100.   bne :+
  2101.     lda ObjectF2,x
  2102.     bne DontMove
  2103.  
  2104.     lda #1
  2105.     jsr EnemyWalk
  2106.     jsr EnemyAutoBump
  2107.  
  2108.     jsr rand_8_safe
  2109.     and #%1111
  2110.     bne DontMove
  2111.       lda #GUN_DIAGONAL
  2112.       jsr EnemyShoot
  2113.       lda #2
  2114.       jsr EnemyShoot
  2115.       lda ObjectF1,x
  2116.       eor #1
  2117.       sta ObjectF1,x
  2118. DontMove:
  2119.  
  2120.   jsr EnemyPlayerTouch
  2121.   lda ObjectF1,x
  2122.   beq Exit
  2123.  
  2124.   jsr EnemyDecTimer
  2125.   jsr DispEnemy
  2126. Exit:
  2127.   rts
  2128. .endproc
  2129.  
  2130. .proc FloatVertShootEnemy
  2131.   lda #6
  2132.   sta DispEnemyBodyType
  2133.   lda #GUN_VERTICAL
  2134.   sta DispEnemyWeapon
  2135.   lda #5
  2136.   sta DispEnemyHead
  2137.  
  2138.   jsr GetShot
  2139.  
  2140.   lda ObjectPYH,x
  2141.   add #16
  2142.   sta ObjectPYH,x
  2143.   jsr EnemyFall
  2144.   bcc :+
  2145.     jsr rand_8_safe
  2146.     ora #%11111100
  2147.     sta ObjectVYH,x
  2148.     jsr rand_8_safe
  2149.     ora #%10000000
  2150.     sta ObjectVYL,x
  2151.   :
  2152.   lda ObjectPYH,x
  2153.   sub #16
  2154.   sta ObjectPYH,x
  2155.  
  2156.   lda ObjectF1,x
  2157.   beq Exit
  2158.   bcc DontMove
  2159.     lda ObjectF2,x
  2160.     bne DontMove
  2161.  
  2162.     lda #2
  2163.     jsr EnemyWalk
  2164.     jsr EnemyAutoBump
  2165.  
  2166.     jsr rand_8_safe
  2167.     and #%1111
  2168.     bne DontMove
  2169.       lda #GUN_VERTICAL
  2170.       jsr EnemyShoot
  2171. DontMove:
  2172.  
  2173.   jsr EnemyPlayerTouch
  2174.   lda ObjectF1,x
  2175.   beq Exit
  2176.  
  2177.   jsr EnemyDecTimer
  2178.  
  2179.   jsr DispEnemy
  2180. Exit:
  2181.   rts
  2182. .endproc
  2183.  
  2184. .proc GoombaEnemy
  2185.   asl EnemyWidth
  2186.  
  2187.   jsr GetShot
  2188.  
  2189.   jsr EnemyFallWide
  2190. ;  bcc DontMove
  2191.   lda ObjectF1,x
  2192.   beq Exit
  2193.     lda ObjectF2,x
  2194.     bne DontMove
  2195.  
  2196.     lda #1
  2197.     jsr EnemyWalk
  2198.     jsr EnemyAutoBump
  2199. DontMove:
  2200.  
  2201.   jsr EnemyPlayerTouch
  2202.   lda ObjectF1,x
  2203.   beq Exit
  2204.  
  2205.   jsr EnemyDecTimer
  2206.  
  2207.   lda retraces
  2208.   lsr
  2209.   lsr
  2210.   lsr
  2211.   and #3
  2212.   tay
  2213.   lda EnemyFrames,y
  2214.   tay
  2215.   lda #0
  2216.   jsr DispEnemyWide
  2217. Exit:
  2218.   rts
  2219. EnemyFrames:
  2220.   .byt $a0, $a4, $a8, $a4
  2221. .endproc
  2222.  
  2223. .proc ThwompEnemy
  2224.   State = 10
  2225.   asl EnemyWidth
  2226.   jsr GetShot
  2227.  
  2228.   lda ObjectF2,x ; cancel smashing
  2229.   sta State
  2230.   cmp #ENEMY_STATE_ACTIVE
  2231.   bne :+
  2232.     lda ObjectPYH,x
  2233.     cmp #-24
  2234.     bcc :+
  2235.       lda #0
  2236.       sta ObjectF2,x
  2237.   :
  2238.  
  2239.   lda ObjectF1,x
  2240.   jeq Exit
  2241.     and #%111110
  2242.     cmp #OBJECT_THWOMP_MOVE*2
  2243.     bne DontMoveStatic
  2244.       lda ObjectF2,x
  2245.       bne DontMove
  2246.         lda #1
  2247.         jsr EnemyWalk
  2248.         jmp DontMove
  2249.   DontMoveStatic:
  2250.     lda ObjectPX,x
  2251.     cmp #24
  2252.     bcs :+
  2253.       inc ObjectPX,x
  2254.     :
  2255.     lda ObjectPX,x
  2256.     cmp #-24
  2257.     bcc :+
  2258.       dec ObjectPX,x
  2259.     :
  2260. DontMove:
  2261.  
  2262.   lda State
  2263.   cmp #ENEMY_STATE_STUNNED
  2264.   beq :+
  2265.     jsr EnemyFallGravityOnly
  2266.     jmp :++
  2267. : jsr EnemyFallWide
  2268. :
  2269.  
  2270.   lda State
  2271.   bne :+ ; smashing and vulnerable modes don't retain a constant height
  2272.   lda ObjectPYH,x
  2273.   cmp #32
  2274.   bcc :+
  2275.     lda #-2
  2276.     sta ObjectVYH,x
  2277.     lda #0
  2278.     sta ObjectVYL,x
  2279.   :
  2280.  
  2281.   lda ObjectF2,x ; if not hovering, don't check if it should fall
  2282.   bne NotHovering
  2283.  
  2284.   lda ObjectPX,x
  2285.   add #4
  2286.   lsr
  2287.   lsr
  2288.   lsr
  2289.   lsr
  2290.   sta 0
  2291.   ldy #0
  2292. TryNear:
  2293.   lda PlayerPX,y
  2294.   lsr
  2295.   lsr
  2296.   lsr
  2297.   lsr
  2298.   cmp 0
  2299.   beq NeedToFall
  2300.   iny
  2301.   cpy #2
  2302.   bne TryNear
  2303.   beq NotHovering
  2304. NeedToFall:
  2305.   lda #ENEMY_STATE_ACTIVE
  2306.   sta ObjectF2,x
  2307. NotHovering:
  2308.  
  2309.   jsr EnemyPlayerTouch
  2310.   lda ObjectF1,x
  2311.   beq Exit
  2312.  
  2313.   lda ObjectF2,x
  2314.   cmp #ENEMY_STATE_ACTIVE
  2315.   beq :+
  2316.   jsr EnemyDecTimer
  2317. :
  2318.  
  2319.   ldy #$cc
  2320.   lda #2
  2321.   jsr DispEnemyWide
  2322. Exit:
  2323.   rts
  2324. .endproc
  2325.  
  2326. .proc RollBallEnemy
  2327.   asl EnemyWidth
  2328.   jsr GetShot
  2329.   jsr EnemyFallWide
  2330.   bcc DontMove
  2331.   lda ObjectF1,x
  2332.   beq Exit
  2333.     lda ObjectF2,x
  2334.     bne DontMove
  2335.  
  2336.     lda #4
  2337.     jsr EnemyWalk
  2338.     jsr EnemyAutoBump
  2339. DontMove:
  2340.  
  2341.   jsr EnemyPlayerTouch
  2342.   lda ObjectF1,x
  2343.   beq Exit
  2344.  
  2345.   jsr EnemyDecTimer
  2346.  
  2347.   ldy #$b8
  2348.   lda #2
  2349.   jsr DispEnemyWide
  2350. Exit:
  2351.   rts
  2352. .endproc
  2353.  
  2354. .proc JumpBallEnemy
  2355.   asl EnemyWidth
  2356.   jsr GetShot
  2357.  
  2358.   lda ObjectF2,x
  2359.   bne :+
  2360.     lda #2
  2361.     jsr EnemyWalk
  2362.     jsr EnemyAutoBump
  2363.   :
  2364.  
  2365.   jsr EnemyFallWide
  2366.   bcc DontMove
  2367.  
  2368.   lda ObjectF1,x
  2369.   beq Exit
  2370.     lda ObjectF2,x
  2371.     bne DontMove
  2372.  
  2373.     jsr rand_8_safe
  2374.     ora #%11111000
  2375.     sta ObjectVYH,x
  2376.     jsr rand_8_safe
  2377.     ora #%10000000
  2378.     sta ObjectVYL,x
  2379.  
  2380.     jsr rand_8_safe
  2381.     pha
  2382.     asl
  2383.     bcc :+
  2384.     lda ObjectF1,x
  2385.     eor #1
  2386.     sta ObjectF1,x
  2387. :
  2388.     pla
  2389.     and #11
  2390.     bne DontMove
  2391.       lda #2
  2392.       jsr EnemyShoot
  2393. DontMove:
  2394.  
  2395.   jsr EnemyPlayerTouch
  2396.   lda ObjectF1,x
  2397.   beq Exit
  2398.  
  2399.   jsr EnemyDecTimer
  2400.  
  2401.   ldy #$bc
  2402.   lda #2
  2403.   jsr DispEnemyWide
  2404. Exit:
  2405.   rts
  2406. .endproc
  2407.  
  2408. .proc SneakerEnemy
  2409.   asl EnemyWidth
  2410.   jsr GetShot
  2411.   jsr EnemyFallWide
  2412. ;  bcc DontMove
  2413.  
  2414.   lda ObjectF1,x
  2415.   beq Exit
  2416.     lda ObjectF2,x
  2417.     bne DontMove
  2418.  
  2419.     lda #4
  2420.     jsr EnemyWalk
  2421.     jsr EnemyAutoBump
  2422. DontMove:
  2423.  
  2424.   ; run away from bullets
  2425.   lda ObjectPYH,x
  2426.   add #8
  2427.   lsr
  2428.   lsr
  2429.   and #%111000
  2430.   sta TempVal
  2431.   lda ObjectPX,x
  2432.   add #12
  2433.   lsr ; / 32 pixels
  2434.   lsr
  2435.   lsr
  2436.   lsr
  2437.   lsr
  2438.   ora TempVal
  2439.   tay
  2440.   and #15
  2441.   pha
  2442.   beq LeftEdge
  2443.   lda BulletMap-1,y
  2444.   beq LeftEdge
  2445.   lda ObjectF1,x
  2446.   and #~1
  2447.   sta ObjectF1,x
  2448. LeftEdge:
  2449.   pla
  2450.   cmp #15
  2451.   beq RightEdge
  2452.   lda BulletMap+1,y
  2453.   beq RightEdge
  2454.   lda ObjectF1,x
  2455.   ora #1
  2456.   sta ObjectF1,x
  2457. RightEdge:
  2458.  
  2459.   jsr EnemyPlayerTouch
  2460.   lda ObjectF1,x
  2461.   beq Exit
  2462.  
  2463.   jsr EnemyDecTimer
  2464.  
  2465.  
  2466.   lda retraces
  2467.   lsr
  2468.   and #4
  2469.   add #$68
  2470.   tay
  2471.   lda #0
  2472.   jsr DispEnemyWide
  2473. Exit:
  2474.   rts
  2475. .endproc
  2476.  
  2477. .proc GeorgeEnemy
  2478.   asl EnemyWidth
  2479.  
  2480.   jsr GetShot
  2481.  
  2482.   jsr EnemyFallWide
  2483.   bcc DontMove
  2484.   lda ObjectF1,x
  2485.   beq Exit
  2486.     lda ObjectF2,x
  2487.     bne DontMove
  2488.  
  2489.     lda #2
  2490.     jsr EnemyWalk
  2491.     jsr EnemyAutoBump
  2492.  
  2493.     lda retraces
  2494.     and #63
  2495.     bne DontMove
  2496.     jsr rand_8_safe
  2497.     and #1
  2498.     bne DontMove
  2499.     lda #ENEMY_STATE_PAUSE
  2500.     sta ObjectF2,x
  2501.     lda #10
  2502.     sta ObjectTimer,x
  2503.     jsr LaunchWaterBottle    
  2504. DontMove:
  2505.  
  2506.   jsr EnemyPlayerTouch
  2507.   lda ObjectF1,x
  2508.   beq Exit
  2509.  
  2510.   jsr EnemyDecTimer
  2511.  
  2512.   ldy #$78
  2513.   lda #0
  2514.   jsr DispEnemyWide
  2515. Exit:
  2516.   rts
  2517. .endproc
  2518.  
  2519. LaunchWaterBottle:
  2520.   txa
  2521.   tay
  2522.   jsr FindFreeObjectX
  2523.   php
  2524.   bcc @Restore
  2525.  
  2526.   lda #OBJECT_BOMB*2
  2527.   sta ObjectF1,x
  2528.  
  2529.   lda #EXTOBJ_WATER
  2530.   sta ObjectF3,x
  2531.   lda ObjectPYH,y
  2532.   sta ObjectPYH,x
  2533.   lda #-4
  2534.   sta ObjectVYH,x
  2535.   lda #0
  2536.   sta ObjectPYL,x
  2537.   sta ObjectVYL,x
  2538.   sta ObjectTimer,x
  2539.   lda ObjectPX,y
  2540.   sta ObjectPX,x
  2541.  
  2542.   inc ScreenEnemiesCount
  2543. @Restore:
  2544.   tya
  2545.   tax
  2546.   plp
  2547.   rts
  2548.  
  2549. .proc RetardEnemy
  2550.   asl EnemyWidth
  2551.  
  2552.   jsr GetShot
  2553.  
  2554.   lda ObjectF2,x
  2555.   bne :+
  2556.     lda retraces
  2557.     and #63
  2558.     bne :+
  2559.     jsr rand_8_safe
  2560.     and #1
  2561.     bne :+
  2562.     lda #-2
  2563.     sta ObjectVYH,x
  2564.   :
  2565.  
  2566.   jsr EnemyFallWide
  2567.   bcc DontMove
  2568.   lda ObjectF1,x
  2569.   beq Exit
  2570.     lda ObjectF2,x
  2571.     bne DontMove
  2572.  
  2573.     lda #2
  2574.     jsr EnemyWalk
  2575.     jsr EnemyAutoBump
  2576. DontMove:
  2577.  
  2578.   jsr EnemyPlayerTouch
  2579.   lda ObjectF1,x
  2580.   beq Exit
  2581.  
  2582.   jsr EnemyDecTimer
  2583.  
  2584.   lda retraces
  2585.   lsr
  2586.   and #4
  2587.   add #$ac
  2588.   tay
  2589.   lda #0
  2590.   jsr DispEnemyWide
  2591. Exit:
  2592.   rts
  2593. .endproc
  2594.  
  2595. .proc FlappyEnemy
  2596.   asl EnemyWidth
  2597.  
  2598.   jsr GetShot
  2599.  
  2600.   jsr EnemyFallWide
  2601.   bcc :+
  2602.     lda ObjectF2,x
  2603.     bne DontMove
  2604.     lda #-5
  2605.     sta ObjectVYH,x
  2606.     lda #0
  2607.     sta ObjectVYL,x
  2608.     bne DontMove
  2609.   :
  2610.   lda ObjectF1,x
  2611.   beq Exit
  2612.     lda ObjectF2,x
  2613.     bne DontMove
  2614.  
  2615.     lda #2
  2616.     jsr EnemyWalk
  2617.     bcc DontMove
  2618.       lda #-4
  2619.       sta ObjectVYH,x
  2620.       lda #0
  2621.       sta ObjectVYL,x
  2622.  
  2623.       lda #GUN_VERTICAL
  2624.       jsr EnemyShoot
  2625.       sec
  2626.       jsr EnemyAutoBump
  2627. DontMove:
  2628.  
  2629.   lda ObjectVYH,x
  2630.   bmi :+
  2631.   cmp #2
  2632.   bcc :+
  2633.     lda ObjectF2,x
  2634.     bne :+
  2635.     jsr rand_8_safe
  2636.     and #7
  2637.     bne :+
  2638.     lda #-2
  2639.     sta ObjectVYH,x
  2640.     lda #80
  2641.     sta ObjectVYL,x
  2642.   :
  2643.  
  2644.   jsr EnemyPlayerTouch
  2645.   lda ObjectF1,x
  2646.   beq Exit
  2647.  
  2648.   jsr EnemyDecTimer
  2649.  
  2650.   lda retraces
  2651.   lsr
  2652.   and #4
  2653.   add #$ac
  2654.   tay
  2655.   lda #0
  2656.   jsr DispEnemyWide
  2657. Exit:
  2658.   rts
  2659. .endproc
  2660.  
  2661. .proc ToastbotEnemy
  2662.   asl EnemyWidth
  2663.  
  2664.   jsr GetShot
  2665.  
  2666.   jsr EnemyFallWide
  2667.   bcc DontMove
  2668.   lda ObjectF1,x
  2669.   beq Exit
  2670.     lda ObjectF2,x
  2671.     bne DontMove
  2672.  
  2673.     lda #1
  2674.     jsr EnemyWalk
  2675.     jsr EnemyAutoBump
  2676. DontMove:
  2677.  
  2678.   jsr EnemyPlayerTouch
  2679.   lda ObjectF1,x
  2680.   beq Exit
  2681.  
  2682.   jsr EnemyDecTimer
  2683.  
  2684.   ldy #$88
  2685.   lda retraces
  2686.   and #%1000
  2687.   beq :+
  2688.   ldy #$8c
  2689. : lda #0
  2690.   jsr DispEnemyWide
  2691. Exit:
  2692.   rts
  2693. .endproc
  2694.  
  2695. .proc EnemyLookAtPlayer
  2696.   ; check for the cases of both or no players being active
  2697.   lda PlayerEnabled+0
  2698.   add PlayerEnabled+1
  2699.   beq Exit
  2700.   cmp #2
  2701.   beq TwoPlayers
  2702.  
  2703.   ; if only one player, select the right one
  2704.   ldy #0
  2705.   lda PlayerEnabled,y
  2706.   bne OnePlayer
  2707.   inx
  2708.   lda PlayerEnabled,y
  2709.   bne OnePlayer
  2710.   rts
  2711. OnePlayer:
  2712.   lsr ObjectF1,x
  2713.   lda ObjectPX,x
  2714.   cmp PlayerPX,x
  2715.   rol ObjectF1,x
  2716.   rts
  2717. TwoPlayers:
  2718. Exit:
  2719.   rts
  2720. .endproc
  2721.  
  2722. .proc GetShot
  2723.   lda ObjectF2,x
  2724.   cmp #ENEMY_STATE_STUNNED
  2725.   beq :+
  2726.     jsr EnemyGetShot
  2727.     bcc :+
  2728.       jsr EnemyHurt
  2729.   :
  2730.   rts
  2731. .endproc
  2732.  
  2733. .proc BurgerEnemy
  2734.   asl EnemyWidth
  2735.   lda ObjectF1,x
  2736.   alr #%111110
  2737.   sub #OBJECT_BURGER1
  2738.   sta 8
  2739.  
  2740.   jsr GetShot
  2741.  
  2742.   lda retraces
  2743.   and #%100000
  2744.   bne :+
  2745.     jsr rand_8_safe
  2746.     sta ObjectF3,x
  2747.   :
  2748.  
  2749.   lda 8
  2750.   cmp #1
  2751.   bne :+
  2752.     lda ObjectF2,x
  2753.     bne :+
  2754.     jsr rand_8_safe
  2755.     and #%1111
  2756.     bne :+
  2757.     lda ObjectPX,x
  2758.     pha
  2759.     add #4
  2760.     sta ObjectPX,x
  2761.     lda #GUN_VERTICAL
  2762.     jsr EnemyShoot
  2763.     pla
  2764.     sta ObjectPX,x
  2765.   :
  2766.  
  2767.   jsr EnemyFallGravityOnly
  2768.  
  2769.   lda ObjectPYH,x
  2770.   cmp ObjectF3,x
  2771.   bcc :+
  2772.     lda #-1
  2773.     sta ObjectVYH,x
  2774.   :
  2775.  
  2776.   jsr EnemyDecTimer
  2777.  
  2778.   lda ObjectF1,x
  2779.   beq Exit
  2780.     lda ObjectF2,x
  2781.     bne DontMove
  2782.  
  2783.     lda #2
  2784.     ldy 8
  2785.     cpy #2
  2786.     bne :+
  2787.       asl
  2788.   : jsr EnemyWalk
  2789.     jsr EnemyAutoBump
  2790. DontMove:
  2791.  
  2792.   jsr EnemyPlayerTouch
  2793.   lda ObjectF1,x
  2794.   beq Exit
  2795.  
  2796.   jsr EnemyDecTimer
  2797.  
  2798.   lda 8
  2799.   asl
  2800.   asl
  2801.   add #$94
  2802.   tay
  2803.   lda #0
  2804.   jsr DispEnemyWide
  2805. Exit:
  2806.   rts
  2807. .endproc
  2808.  
  2809. .proc FlickerEnemies
  2810.   jsr rand_8
  2811.   and #7
  2812.   tax
  2813.   jsr rand_8_safe
  2814.   and #7
  2815.   tay
  2816.   lda ObjectPX,x
  2817.   sta 0
  2818.   lda ObjectPYH,x
  2819.   sta 1
  2820.   lda ObjectPYL,x
  2821.   sta 2
  2822.   lda ObjectVYH,x
  2823.   sta 3
  2824.   lda ObjectVYL,x
  2825.   sta 4
  2826.   lda ObjectF1,x
  2827.   sta 5
  2828.   lda ObjectF2,x
  2829.   sta 6
  2830.   lda ObjectF3,x
  2831.   sta 7
  2832.   lda ObjectTimer,x
  2833.   sta 8
  2834.  
  2835.   lda ObjectPX,y
  2836.   sta ObjectPX,x
  2837.   lda ObjectPYH,y
  2838.   sta ObjectPYH,x
  2839.   lda ObjectPYL,y
  2840.   sta ObjectPYL,x
  2841.   lda ObjectVYH,y
  2842.   sta ObjectVYH,x
  2843.   lda ObjectVYL,y
  2844.   sta ObjectVYL,x
  2845.   lda ObjectF1,y
  2846.   sta ObjectF1,x
  2847.   lda ObjectF2,y
  2848.   sta ObjectF2,x
  2849.   lda ObjectF3,y
  2850.   sta ObjectF3,x
  2851.   lda ObjectTimer,y
  2852.   sta ObjectTimer,x
  2853.  
  2854.   lda 0
  2855.   sta ObjectPX,y
  2856.   lda 1
  2857.   sta ObjectPYH,y
  2858.   lda 2
  2859.   sta ObjectPYL,y
  2860.   lda 3
  2861.   sta ObjectVYH,y
  2862.   lda 4
  2863.   sta ObjectVYL,y
  2864.   lda 5
  2865.   sta ObjectF1,y
  2866.   lda 6
  2867.   sta ObjectF2,y
  2868.   lda 7
  2869.   sta ObjectF3,y
  2870.   lda 8
  2871.   sta ObjectTimer,y
  2872.   rts
  2873. .endproc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement