Advertisement
NovaYoshi

DABG player.s

Sep 21st, 2013
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .proc PlayerGameOver
  2.   lda #0
  3.   sta PlayerEnabled,x
  4.   rts
  5. .endproc
  6. .proc RunPlayer
  7.   lda PlayerDead,x
  8.   beq NotDead
  9.  
  10.   ; increase gravity
  11.   lda PlayerVYL,x
  12.   add #32
  13.   bcc :+
  14.     inc PlayerVYH,x
  15. : sta PlayerVYL,x
  16.  
  17.   ; apply gravity
  18.   lda PlayerPYL,x
  19.   add PlayerVYL,x
  20.   sta PlayerPYL,x
  21.  
  22.   lda PlayerPYH,x
  23.   adc PlayerVYH,x
  24.   sta PlayerPYH,x  
  25.  
  26.   cmp #-12
  27.   bcc :+
  28.   ; revive player
  29.   dec PlayerLives,x
  30.   lda PlayerLives,x
  31.   jeq PlayerGameOver
  32.  
  33.   lda #0
  34.   sta PlayerDead,x
  35.   jsr PlayerResetPos
  36.   lda #60
  37.   sta PlayerInvincible
  38.   jsr ResetPlayerHealthX
  39. :
  40.   jsr DispPlayer
  41.   rts
  42. NotDead:
  43.  
  44.   ; holding B lets you go twice as fast
  45.   ldy #2
  46.   lda keydown,x
  47.   and #KEY_B
  48.   beq :+
  49.     ldy #4
  50. : sty 0
  51.  
  52.   ; moving left and right
  53.   lda keydown,x
  54.   and #KEY_LEFT
  55.   beq :+
  56.     lda PlayerPX,x
  57.     sub 0
  58.     lsr
  59.     lsr
  60.     lsr
  61.     lsr
  62.     sta 1
  63.     lda PlayerPYH,x
  64.     add #8
  65.     and #$f0
  66.     ora 1
  67.     tay
  68.     lda LevelBuf,y
  69.     cmp #METATILE_SOLID
  70.     beq :+
  71.  
  72.     lda PlayerPX,x
  73.     sub 0
  74.     sta PlayerPX,x
  75.     lda #1
  76.     sta PlayerDir,x
  77. : lda keydown,x
  78.   and #KEY_RIGHT
  79.   beq :+
  80.     lda PlayerPX,x
  81.     add #7
  82.     add 0
  83.     lsr
  84.     lsr
  85.     lsr
  86.     lsr
  87.     sta 1
  88.     lda PlayerPYH,x
  89.     add #8
  90.     and #$f0
  91.     ora 1
  92.     tay
  93.     lda LevelBuf,y
  94.     cmp #METATILE_SOLID
  95.     beq :+
  96.  
  97.     lda PlayerPX,x
  98.     add 0
  99.     sta PlayerPX,x
  100.     lda #0
  101.     sta PlayerDir,x
  102.   :
  103.  
  104.   ; select skips to the next level, or skips to the level edit screen
  105.   lda keydown,x
  106.   and #KEY_SELECT
  107.   beq :+
  108.     jsr init_sound
  109.     lda LevelEditMode
  110.     jne StartEditorNormal
  111.     lda retraces
  112.     beq :+
  113.       sta r_seed
  114.       pla             ; don't mess up the stack
  115.       pla
  116.       jmp NewLevel
  117.   :
  118.  
  119.   ; gravity
  120.   lda PlayerPYL,x
  121.   add PlayerVYL,x
  122.   bcc :+
  123.     inc PlayerPYH,x
  124. : sta PlayerPYL,x
  125.  
  126.   lda PlayerVYH,x
  127.   bmi GravityOkay
  128.   cmp #8
  129.   bcs GravitySkip
  130. GravityOkay:
  131.   lda PlayerVYL,x
  132.   add #32
  133.   bcc :+
  134.     inc PlayerVYH,x
  135. : sta PlayerVYL,x
  136. GravitySkip:
  137.  
  138.   ; check for collision with blocks above before adding gravity
  139.   lda PlayerVYH,x
  140.   bpl :+
  141.   lda PlayerPX,x
  142.   add #4
  143.   lsr
  144.   lsr
  145.   lsr
  146.   lsr
  147.   sta 1
  148.   lda PlayerPYH,x
  149.   add PlayerVYH,x
  150.   and #$f0
  151.   ora 1
  152.   tay
  153.   lda LevelBuf,y
  154.   cmp #METATILE_SOLID
  155.   bne :+
  156.     lda #0
  157.     sta PlayerVYH,x
  158.   :
  159.  
  160.   ; more gravity
  161.   lda PlayerPYH,x
  162.   add PlayerVYH,x
  163.   sta PlayerPYH,x
  164.  
  165.   lda keydown,x
  166.   and #KEY_B
  167.   beq NoShoot
  168.     lda keylast,x
  169.     and #KEY_B
  170.     bne NoShoot
  171.       lda #SOUND_SHOOT
  172.       jsr start_sound
  173.  
  174.       jsr FindFreeBulletY
  175.       bcc NoShoot
  176.       sty 0
  177.       ldy PlayerDir,x
  178.       lda OffsetHeldX,y
  179.       ldy 0
  180.  
  181.       add PlayerPX,x
  182.       sta BulletPX,y
  183.  
  184.       ldy PlayerDir,x
  185.       lda BulletSpeed,y
  186.       ldy 0
  187.       sta BulletVX,y
  188.  
  189.       lda #0
  190.       sta BulletVY,y
  191.       sta BulletVYL,y
  192.  
  193.       lda PlayerPYH,x
  194.       add #4
  195.       sta BulletPY,y
  196.       lda #%11001000
  197.       sta BulletF,y
  198.  
  199.       lda #15
  200.       sta BulletLife,y
  201.   NoShoot:
  202.  
  203.   lda PlayerVYH,x
  204.   bpl :+
  205.     lda keydown,x        ; cancel a jump (doesn't appear to work?)
  206.     and #KEY_A
  207.     bne :+
  208.       lda PlayerJumpCancelLock,x
  209.       bne :+
  210.         lda #0
  211.         sta PlayerVYH,x
  212.         sta PlayerVYL,x
  213.   :
  214.  
  215.   ; lower PlayerDropLock if it isn't zero yet
  216.   lda PlayerDropLock
  217.   beq :+
  218.   dec PlayerDropLock
  219. :
  220.  
  221.   lda PlayerPX,x
  222.   add #4 ; start from middle
  223.   lsr
  224.   lsr
  225.   lsr
  226.   lsr
  227.   sta PlayerXShifted
  228.   sta 0 ; for the falling through platforms stuff after
  229.   pha
  230.  
  231.   lda PlayerPYH,x
  232.   add #15
  233.   and #$f0
  234.   ora 0
  235.   tay
  236.   sty 10
  237. ; check for things that don't care about Y velocity first
  238.   lda LevelBuf,y
  239.   cmp #METATILE_PICKUP
  240.   bne NotPickup
  241.     lda #0
  242.     jsr ChangeBlock
  243.  
  244.     lda #POWERUP_HEALTH
  245.     jsr CreatePowerup
  246.  
  247.     lda #SOUND_MONEY
  248.     jsr start_sound
  249.     jmp SkipWalkthrough2
  250. NotPickup:
  251.   lda LevelBuf,y
  252.   cmp #METATILE_MONEY
  253.   bne NotMoney
  254.     sty 1
  255.     jsr IndexToBitmap
  256.     sta 0
  257.     and CollectMap,y
  258.     bne NotMoney
  259.     lda 0
  260.     ora CollectMap,y
  261.     sta CollectMap,y
  262.     ldy 1
  263.  
  264.     lda #0
  265.     jsr ChangeBlockColor
  266.  
  267.     lda LevelGoalType
  268.     cmp #3
  269.     bne NotMoneyType
  270.       lda LevelGoalParam
  271.       beq NotMoneyType
  272.         dec LevelGoalParam
  273.     NotMoneyType:
  274.  
  275.     lda #SOUND_MONEY
  276.     jsr start_sound
  277.  
  278.     lda #1
  279.     jsr PlayerAddScore
  280. NotMoney:
  281. ;---------------------------------------------
  282. SkipWalkthrough2:
  283.   pla
  284.   sta 0
  285.  
  286.   ; it's only OK to fall through platforms, nothing else
  287.   lda PlayerPYH,x
  288.   add #16
  289.   and #$f0
  290.   ora 0
  291.   tay
  292.   lda LevelBuf,y
  293.   cmp #METATILE_PLATFM
  294.   bne :+
  295.   lda keydown,x
  296.   and #KEY_A|KEY_DOWN
  297.   cmp #KEY_A|KEY_DOWN
  298.   beq DropThroughPlatform ; fallthrough
  299.   lda PlayerDropLock,x
  300.   bne SkipPlatformCheck
  301. : ; collision with platforms
  302.   lda PlayerVYH,x
  303.   bpl NotSkipMi
  304.   jmp :+
  305. NotSkipMi:
  306.   lda PlayerXShifted
  307.   sta 0
  308.   lda PlayerPYH,x
  309.   add #16
  310.   and #$f0
  311.   ora 0
  312.   tay
  313.   sty 0
  314.   lda LevelBuf,y
  315.   cmp #FirstSolidTop
  316.   bcc SkipPlatformCheck
  317.     lda PlayerPYH,x
  318.     and #$f0
  319.     sta PlayerPYH,x
  320.     lda #0
  321.     sta PlayerVYH,x
  322.     sta PlayerVYL,x
  323.     sta PlayerJumpCancelLock,x
  324.  
  325.     lda keydown,x      ; start a jump
  326.     and #KEY_A
  327.     beq SkipPlatformCheck
  328.       lda #SOUND_JUMP
  329.       jsr start_sound
  330.  
  331.       lda #-4 ;-5
  332.       sta PlayerVYH,x
  333.       lda #0  ;90
  334.       sta PlayerVYL,x
  335.       beq SkipPlatformCheck
  336. DropThroughPlatform:
  337.   lda #13
  338.   sta PlayerDropLock
  339. SkipPlatformCheck:
  340. ; check for block types you walk through instead
  341.   ldy 10
  342.   lda LevelBuf,y
  343.   cmp #METATILE_SPRING
  344.   bne NotSpring
  345.     lda #METATILE_SPRING2
  346.     jsr ChangeBlock
  347.     lda retraces
  348.     add #4
  349.     sta 0
  350.     lda #METATILE_SPRING
  351.     jsr AddDelayMetaEdit
  352.  
  353.     lda #-5
  354.     sta PlayerVYH,x
  355.     lda #80
  356.     sta PlayerVYL,x
  357.     lda #1
  358.     sta PlayerJumpCancelLock,x
  359.     lda #SOUND_SPRING
  360.     jsr start_sound
  361.  
  362.     jmp SkipWalkthrough
  363. NotSpring:
  364.   cmp #METATILE_SPIKES
  365.   bne NotSpikes
  366.     txa
  367.     tay
  368.     jsr PlayerHurt
  369. NotSpikes:
  370. SkipWalkthrough:
  371.  
  372.   lda PlayerInvincible,x
  373.   beq :+
  374.     dec PlayerInvincible,x
  375.   :
  376.  
  377.   ; collision with bullets
  378.   jsr PlayerGetShot
  379.   bcc :+
  380.     txa
  381.     tay
  382.     jsr PlayerHurt
  383. : jsr DispPlayer
  384.   rts
  385. BlockXSpeed:
  386.   .byt 3, -3
  387. .endproc
  388.  
  389. .proc BodyTypeAnims
  390.   .byt $18, $19, $18, $1A ; style the player uses
  391.   .byt $1B, $1C, $1B, $1D ; stick figure style
  392.   .byt $11, $12, $11, $12 ; fat guy
  393.   .byt $14, $14, $14, $14 ; hover guy?
  394.   .byt $15, $15, $15, $15 ; solid guy
  395.   .byt $16, $17, $16, $17 ; tilty pogo guy
  396.   .byt $1e, $1e, $1e, $1e ; hover guy 2
  397. .endproc
  398.  
  399. .proc PlayerGetShot
  400.   lda PlayerPYH,x
  401.   add #8
  402.   lsr
  403.   lsr
  404.   and #%111000
  405.   sta TempVal
  406.   lda PlayerPX,x
  407.   add #4
  408.   lsr ; / 32 pixels
  409.   lsr
  410.   lsr
  411.   lsr
  412.   lsr
  413.   ora TempVal
  414.   tay
  415.   lda BulletMap,y
  416.   beq Exit
  417.  
  418.   ldy #0
  419. BulletLoop:
  420.   lda BulletF,y
  421.   and #%10000000
  422.   cmp #%10000000 ;enabled, enemy-made bullets only
  423.   bne SkipBullet
  424.  
  425.   lda BulletPX,y
  426.   sta TouchLeftA
  427.   lda BulletPY,y
  428.   sta TouchTopA
  429.  
  430.   lda PlayerPX,x
  431.   sta TouchLeftB
  432.   lda PlayerPYH,x
  433.   sta TouchTopB
  434.  
  435.   lda #8
  436.   sta TouchWidthA
  437.   sta TouchWidthB
  438.   sta TouchHeightA
  439.   asl
  440.   sta TouchHeightB
  441.  
  442.   jsr ChkTouchGeneric
  443.   bcs ShotHit
  444. SkipBullet:
  445.   iny
  446.   cpy #BulletLen
  447.   bne BulletLoop
  448. Exit:
  449.   clc
  450.   rts
  451. ShotHit:
  452.   lda PlayerInvincible,x
  453.   bne :+
  454.   lda #0
  455.   sta BulletF,y
  456.   sec
  457. : rts
  458. .endproc
  459.  
  460. .proc DispPlayer
  461.   ; 0 - attribute
  462.   ; 1 - used to preserve Y (register)
  463.   ; 2 - used to preserve Y (position)
  464.   ; x - player num
  465.  
  466.   lda PlayerInvincible,x
  467.   beq :+
  468.     lda retraces
  469.     and #1
  470.     beq :+
  471.       rts
  472.   :
  473.  
  474.   ; change stuff when player is facing left
  475.   lda #0|OAM_COLOR_0
  476.   ldy PlayerDir,x   ; garbage load; we only care about the flags
  477.   beq :+
  478.     lda #OAM_XFLIP|OAM_COLOR_0
  479. : sta 0
  480.  
  481.   ldy OamPtr
  482.  
  483.   lda PlayerPYH,x
  484.   sub #1
  485.   sta OAM_YPOS+(4*0),y
  486.   add #6
  487.   sta OAM_YPOS+(4*2),y
  488.   add #2
  489.   sta OAM_YPOS+(4*1),y
  490.  
  491.   lda 0
  492.   sta OAM_ATTR+(4*0),y
  493.   sta OAM_ATTR+(4*1),y
  494.   sta OAM_ATTR+(4*2),y
  495.  
  496.   lda PlayerHead,x
  497.   sta OAM_TILE+(4*0),y
  498.  
  499.   ; walking animation
  500.   sty 1 ; save Y
  501.   lda PlayerBody,x
  502.   asl
  503.   asl
  504.   sta 0
  505.   tay
  506.   lda keydown,x
  507.   and #KEY_LEFT + KEY_RIGHT
  508.   beq :+
  509.     lda retraces
  510.     lsr
  511.     lsr
  512.     and #3
  513.     add 0
  514.     tay
  515.   :
  516.   lda BodyTypeAnims,y
  517.   ldy 1 ; restore Y
  518.   sta OAM_TILE+(4*1),y
  519.   lda PlayerHeld,x
  520.   ora #$20
  521.   sta OAM_TILE+(4*2),y
  522.  
  523.   lda PlayerPX,x
  524.   sta OAM_XPOS+(4*0),y
  525.   sta OAM_XPOS+(4*1),y
  526.  
  527.   sty 1
  528.   lda PlayerDir,x
  529.   tay
  530.   lda OffsetHeldX,y
  531.   ldy 1
  532.   add PlayerPX,x
  533.   sta OAM_XPOS+(4*2),y
  534.  
  535.   tya
  536.   add #16
  537.   tay
  538.   sty OamPtr
  539.   rts
  540. .endproc
  541. .proc OffsetHeldX
  542.   .byt 8, -8
  543. .endproc
  544. .proc BulletSpeed
  545.   .byt 6, -6
  546. .endproc
  547.  
  548. .proc IsPlayerTouching
  549.   ; X - player number
  550.   lda PlayerPX,x
  551.   sta TouchLeftA,x
  552.   lda PlayerPYH,x
  553.   sta TouchTopA,x
  554.   lda #8
  555.   sta TouchWidthA
  556.   lda #16
  557.   sta TouchHeightA
  558. ;  jmp ChkTouchGeneric
  559. .endproc
  560.  
  561. .proc ChkTouchGeneric
  562.   jsr :+
  563.   swapa TouchLeftA,   TouchLeftB
  564.   swapa TouchTopA,    TouchTopB
  565.   swapa TouchWidthA,  TouchWidthB
  566.   swapa TouchHeightA, TouchHeightB
  567.   jsr :+
  568.   clc ; no collision
  569.   rts
  570. : lda TouchLeftB
  571.   add TouchWidthB
  572.   sta TouchRight
  573.   lda TouchTopB
  574.   add TouchHeightB
  575.   sta TouchBottom
  576.  
  577.   lda TouchLeftA
  578.   cmp TouchLeftB
  579.   bcc :+
  580.  
  581.   lda TouchLeftA
  582.   cmp TouchRight
  583.   bcs :+
  584.  
  585.   lda TouchTopA
  586.   cmp TouchTopB
  587.   bcc :+
  588.  
  589.   lda TouchTopA
  590.   cmp TouchBottom
  591.   bcs :+
  592.   pla
  593.   pla
  594.   sec ; collision detected
  595. : rts
  596. .endproc
  597.  
  598. .proc PlayerHurt ; Y is actually the player here, not X
  599.   txa
  600.   pha
  601.  
  602.   lda PlayerHealth,y
  603.   beq :+
  604.     lda PlayerInvincible,y
  605.     bne :+
  606.       sty TempVal
  607.       lda #SOUND_YOUHURT
  608.       jsr start_sound
  609.       ldy TempVal
  610.  
  611.       dcp PlayerHealth,y
  612.       lda #60
  613.       sta PlayerInvincible,y
  614.       lda PlayerHealth,y
  615.       bne :+
  616.         lda #1
  617.         sta PlayerDead,y
  618. : pla
  619.   tax
  620.   rts
  621. .endproc
  622.  
  623. .proc PlayerAddScore
  624.   tay
  625.   lda BCD64,y
  626.   unpack TempVal,TempVal+1
  627.   ldy PlayerScoreIndex,x
  628.   tya
  629.   pha
  630.   lda ScoreDigits+2,y
  631.   pha
  632.  
  633.   lda ScoreDigits,y
  634.   add TempVal
  635.   sta ScoreDigits,y
  636.   lda ScoreDigits+1,y
  637.   add TempVal+1
  638.   sta ScoreDigits+1,y
  639. FixLoop: ; if it goes past 9, carry it over
  640.   lda ScoreDigits,y
  641.   cmp #'9'+1 ; 9 or less: no fixing
  642.   bcc Next
  643.   sub #10
  644.   sta ScoreDigits,y
  645.   isc ScoreDigits+1,y
  646. Next:
  647.   iny
  648.   cpy #NumScoreDigits
  649.   beq Exit
  650.   cpy #NumScoreDigits*2
  651.   bne FixLoop
  652. Exit:
  653.   pla
  654.   sta TempVal
  655.   pla
  656.   tay
  657.   lda TempVal
  658.   cmp ScoreDigits+2,y
  659.   beq :+
  660.     lda ScoreDigits+2,y
  661.     cmp #'0'
  662.     beq AddLife
  663.     cmp #'5'
  664.     beq AddLife
  665.   :
  666.   rts
  667. AddLife:
  668.   lda PlayerLives,x
  669.   cmp #9
  670.   beq :+
  671.   inc PlayerLives,x
  672.   rts
  673. .endproc
  674.  
  675. PlayerScoreIndex:
  676.   .byt 0, NumScoreDigits
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement