Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SneakerSprite = $00 | 1
- GoombaSprite = $04 | 1
- SmushGoombaSprite = $08 | 1
- GeorgeSprite = $20 | 1
- GeorgeSpurt = $24 | 1
- WaterBottleSide = $26 | 1 ; also $28
- WaterBottleTall = $2A | 1
- ToastBot = $2C | 1 ; also $30
- DinnerSprite = $34 | 1
- .proc EnemyScoreIncrease
- .byt 0 ; blank
- .byt 25 ; goomba
- .byt 100 ; toast bot
- .byt 100 ; sneaker
- .byt 0 ; George the volcano
- .byt 0 ; stomped goomba ( not really used )
- .byt 0 ; Poof
- .byt 25 ; rotate thing
- .byt 0 ; Bill Nye
- .byt 75 ; retard goomba
- .byt 75 ; cheeseburger
- .endproc
- .proc EnemyHitsToKill
- .byt 0<<5 ; blank
- .byt 0<<5 ; goomba
- .byt 0<<5 ; toast bot
- .byt 0<<5 ; sneaker
- .byt 0<<5 ; George the volcano
- .byt 0<<5 ; stomped goomba ( not really used )
- .byt 0<<5 ; Poof
- .byt 0<<5 ; rotate thing
- .byt 0<<5 ; Bill Nye
- .byt 0<<5 ; retard goomba
- .byt 0<<5 ; cheeseburger
- .endproc
- .proc EnemyGraphic
- .byt $00 | 0 ; blank
- .byt $04 | 1 ; goomba
- .byt $2C | 1 ; toast bot
- .byt $00 | 1 ; sneaker
- .byt $24 | 1 ; George the volcano
- .byt $08 | 1 ; stomped goomba ( not really used )
- .byt $00 | 0 ; Poof
- .byt $60 | 1 ; rotate thing
- .byt $00 | 1 ; Bill Nye (custom routine)
- .byt $64 | 1 ; retard goomba
- .byt $34 | 1 ; cheeseburger
- .endproc
- .proc EnemyWalkSpeed
- .byt 0, 0 ; blank
- .byt -1, 1 ; goomba
- .byt -5, 5 ; toast bot ( FREAKING FAST but takes one hit )
- .byt -3, 3 ; sneaker (harder than Goomba)
- .byt -10, 10 ; George
- .byt 0, 0 ; stomped goomba
- .byt 0, 0 ; Poof
- .byt -1, 1 ; rotate thing
- .byt -1, 1 ; Bill Nye
- .byt -2, 2 ; retard goomba
- .byt -3, 3 ; Cheeseburger
- .endproc
- .proc ProcessEnemies
- .dj_loop #8, 0
- ldx 0
- dex
- lda EnemyType,x
- and #%11110 ; the first bit is the direction bit
- jsr Run_Enemy_Routine
- .end_djl
- rts
- Run_Enemy_Routine: ; some people get butthurt over JumpEngine
- tay
- lda Enemy_Routine_Addresses+1,y
- pha
- lda Enemy_Routine_Addresses+0,y
- pha
- rts
- Enemy_Routine_Addresses:
- .raddr EnemyNone ;0 - nothing
- .raddr EnemySimple ;2 - goomba
- .raddr EnemySimple ;4 - toast bot
- .raddr EnemySimple ;6 - sneaker
- .raddr EnemyNone ;8 - George the volcano
- .raddr EnemyStomp ;10 - Stomped Goomba
- .raddr EnemyPoof ;12 - EnemyKaboom
- .raddr EnemyRotate ;14 - rotate thing
- .raddr EnemyNone ;16 - Bill Nye
- .raddr EnemySimple ;18 - retard goomba
- .raddr EnemyRotate ;20 - Cheeseburger
- .raddr EnemyNone ;22 - nothing
- .raddr EnemyNone ;24 - nothing
- .raddr EnemyNone ;26 - nothing
- .raddr EnemyNone ;28 - nothing
- .raddr EnemyNone ;30 - nothing
- EnemyNone: ; Empty enemy slots do nothing
- lda #0 ; They die, though
- sta EnemyType,x
- rts
- EnemyStomp: ; I need to code support for stomped goombas.
- rts
- .proc EnemyPoof
- ldx 0 ; Get enemy slot number
- dex
- ; was gonna sorta float down but it didn't look very cool
- ; lda EnemyStun,x
- ; lsr
- ; lsr
- ; lsr
- ; add EnemyPosY,x
- ; sta EnemyPosY,x
- ldy OamPtr
- lda EnemyStun,x
- pha
- add #1
- sta EnemyStun,x
- cmp #15 ; erase poof after a little bit
- bcc ErasePoof
- lda #0
- sta EnemyType,x
- inc EnemiesKilled
- beq :+
- inc EnemiesKilled+1
- :
- ; since I can't figure out how to fix this bug I'll make it nicer to experience
- ; ( actually fixed, but I'll keep this part in )
- cpx #0
- bne ErasePoof
- : inx
- cpx #5 ; no enemy slots to swap?
- beq NoSlotsPoof
- lda EnemyType,x
- bne :+
- beq :-
- : sta EnemyType ; copy over to first slot
- lda EnemyPosX,x
- sta EnemyPosX
- lda EnemyPosY,x
- sta EnemyPosY
- lda EnemyStun,x
- sta EnemyStun
- lda #0 ; erase old slot
- sta EnemyType,x
- sta EnemyPosX,x
- sta EnemyPosY,x
- sta EnemyStun,x
- NoSlotsPoof:
- ldx #0 ; restore the zero
- ErasePoof:
- pla
- lsr
- lsr
- add #$48
- ora #1 ; second page
- sta 4
- ; first half --------------------------------
- lda EnemyPosY,x
- sta $200,y
- iny
- lda 4
- sta $200,y
- iny
- lda #0 ; attribute
- sta $200,y
- iny
- lda EnemyPosX,x
- sub #8
- sta $200,y
- iny
- ; next half ---------------------------------
- lda EnemyPosY,x
- sta $200,y
- iny
- lda 4
- sta $200,y
- iny
- lda #OAM_XFLIP ; attribute
- sta $200,y
- iny
- lda EnemyPosX,x
- ; sub #8
- sta $200,y
- iny
- ; done --------------------------------------
- sty OamPtr
- rts
- .endproc
- .proc EnemyRotate
- ldy 0
- dey
- jsr ChkEnemyTouchBlock
- jsr EnemyFlyAcrossScreen
- jsr EnemyDisplay2
- rts
- .endproc
- .proc EnemySimple
- ldy 0
- dey
- lda EnemyPosY,x ; fall speed
- add #4
- sta EnemyPosY,x
- jsr ChkEnemyTouchBlock
- jsr EnemySimpleMove
- jsr EnemyDisplay1
- rts
- .endproc
- .proc EnemyFlyAcrossScreen
- ldx 0 ; Get enemy slot number
- dex
- jsr EnemyGetFromTables
- lda EnemyStun,x ; Stunned? No movement!
- beq :+
- lda #0
- sta 1
- sta 2
- dec EnemyStun,x
- :
- lda EnemyType,x ; walk in direction
- and #1
- tay
- lda 1,y ; get walk speed from table based on direction
- add EnemyPosX,x
- sta EnemyPosX,x
- .scope check_off_screen ; check if the enemy is off the screen
- lda EnemyPosX,x
- cmp #256-8 ; need new place?
- bcs :+
- cmp #8
- bcc :+
- jmp :++
- :
- lda #20
- sta EnemyPosX,x
- stx 10
- sty 11
- jsr rand_8
- ldy 11
- ldx 10
- sta EnemyPosY,x
- lda #10
- sta EnemyStun,x
- lda EnemyType,x ; flip horizontally
- eor #1
- sta EnemyType,x
- :
- .endscope
- rts
- .endproc
- .proc EnemyDisplay2 ; two halves are the same
- .scope display
- ; display
- lda retraces
- and #%100
- bne :+
- lda 4
- sta 3
- :
- ; cpx #0 ; different color if first one
- ; bne :+
- ; lda 5
- ; ora #1
- ; sta 5
- ; :
- ldy OamPtr
- lda EnemyPosY,x
- sta $200,y
- iny
- lda 3 ; get graphic
- sta $200,y
- iny
- lda 5 ; get attribute
- sta $200,y
- iny
- lda EnemyPosX,x
- sub #8
- sta $200,y
- iny
- lda EnemyPosY,x
- sta $200,y
- iny
- lda 3 ; get graphic
- sta $200,y
- iny
- lda 5
- ora #OAM_XFLIP ; get attribute
- sta $200,y
- iny
- lda EnemyPosX,x
- add #0
- sta $200,y
- iny
- sty OamPtr
- .endscope
- rts
- .endproc
- .proc EnemyDisplay1 ; flip back and forth between two
- .scope display
- ; display
- ldy OamPtr
- lda EnemyPosY,x
- sta $200,y
- iny
- lda 3 ; get graphic
- sta $200,y
- iny
- lda 5 ; get attribute
- sta $200,y
- iny
- lda EnemyPosX,x
- sub #8
- sta $200,y
- iny
- lda EnemyPosY,x
- sta $200,y
- iny
- lda 4 ; get graphic
- sta $200,y
- iny
- lda 5 ; get attribute
- sta $200,y
- iny
- lda EnemyPosX,x
- add #0
- sta $200,y
- iny
- sty OamPtr
- .endscope
- rts
- .endproc
- .proc EnemyGetFromTables ; read attributes for this enemy
- ldx 0 ; Get enemy slot number
- dex
- lda EnemyType, x ; Get enemy type, for looking up attributes
- and #%11110
- ; fetch walk speed ( 2 entries )
- tay
- lda EnemyWalkSpeed,y
- sta 1
- lda EnemyWalkSpeed+1,y
- sta 2
- lda EnemyStun,x ; stunned enemies can't walk
- beq :+
- lda #0
- sta 1
- sta 2
- :
- lda #0
- ; cpx #0 ; different color if first one
- ; bne :+
- ; lda #1
- ; :
- sta 5 ; temp attribute
- tya
- lsr
- tay
- lda EnemyGraphic,y
- sta 3
- add #2
- sta 4
- rts
- .endproc
- .proc EnemySimpleMove
- jsr EnemyGetFromTables
- ; okay, got everything out of the tables that we need
- lda #0
- lda retraces ; simple, crap animation :3
- and #%1000
- bne :+
- lda 3 ; swap left tile and right tile
- tay
- lda 4
- sta 3
- tya
- sta 4
- lda 5 ; get attribute
- ora #OAM_XFLIP
- sta 5 ; poked in
- :
- lda EnemyStun,x ; flip onto its back if stunned
- beq :+
- lda 5
- ora #OAM_YFLIP
- sta 5
- dec EnemyStun,x
- :
- ; okay, now we can process this sprite
- .scope platform_test ; check if the enemy is on a platform
- ; see if on a platform
- lda EnemyPosY,x
- add #16
- and #$F0
- sta 6
- lda EnemyPosX,x
- .repeat 4
- lsr
- .endrep
- ora 6
- tay
- lda LevelBuf,y
- cmp #1
- beq IsOnPlatform ; IS on platform!
- stx 8
- jsr rand_8
- ldx 8
- and #8
- lsr
- lsr
- lsr
- eor EnemyType,x
- sta EnemyType,x
- jmp IsNotOnPlatform
- IsOnPlatform:
- lda EnemyPosY,x ; round to nearest metatile
- and #%11110000
- sta EnemyPosY,x
- lda EnemyType,x ; check sideways for wall collision
- and #1
- tay
- lda 1,y ; get walk speed from table based on direction
- add EnemyPosX,x
- .repeat 4
- lsr
- .endrep
- sta 6
- lda EnemyPosY,x
- ;sub #8
- and #$F0
- ora 6
- tay
- lda LevelBuf,y
- cmp #1
- bne :+
- lda EnemyType,x
- eor #1
- sta EnemyType,x
- :
- lda EnemyType,x ; walk in direction
- and #1
- tay
- lda 1,y ; get walk speed from table based on direction
- add EnemyPosX,x
- sta EnemyPosX,x
- jmp WasOnPlatform
- IsNotOnPlatform:
- lda EnemyType,x
- and #%111110
- cmp #9*2 ; Sneaker?
- bne Land_NotRetardGoomba
- lda EnemyType,x
- and #%11111110
- ora #1
- sta EnemyType,x
- tay
- lda EnemyPosX,x
- cmp UserPosX
- bcc RetardGoomba_NotLeft
- dey
- tya
- sta EnemyType,x
- RetardGoomba_NotLeft:
- Land_NotRetardGoomba:
- WasOnPlatform:
- .endscope
- .scope check_off_screen ; check if the enemy is off the screen
- lda EnemyPosX,x
- cmp #256-8 ; need new place?
- bcs :+
- cmp #8
- bcc :+
- jmp :++
- :
- lda #128
- sta EnemyPosX,x
- lda #10
- sta EnemyPosY,x
- lda EnemyType,x ; flip horizontally
- eor #1
- sta EnemyType,x
- :
- .endscope
- rts
- .endproc
- .endproc
- ; goomba
- ; s-kill flings-1
- ; t.bot
- ; s-none flings-2
- ; sneaker
- ; s-hurt flings-3
- ; george
- ; s-hurt flings-3
- ; HHHTTTTD
- .proc ChkEnemyTouchBlock ; don't care which block, just that a block touched
- EnemyIndex = 14
- BlockCounter = 6
- TempX1 = 2
- TempY1 = 3
- TempX2 = 4
- TempY2 = 5
- lda EnemyStun,y
- sty EnemyIndex ; enemy index backup
- .dj_loop #BlockNumber, BlockCounter
- ldx BlockCounter
- dex
- lda BlocksEnabled
- and Bitfield,x
- beq NextIndex
- ldy EnemyIndex
- jsr runtest1
- .end_djl
- ldy EnemyIndex
- jsr runtest2
- rts
- runtest1: ; enemy to block
- ldy EnemyIndex
- lda BlockX,x
- sub #8
- sta TempX1
- lda BlockY,x
- sta TempY1
- lda EnemyPosX,y ; 8x16 so offset left by 8 to make it into a 16x16 area
- sub #8
- sta TempX2 ; D
- lda EnemyPosY,y
- sta TempY2 ; E
- jsr CheckBlk
- lda TempX1
- sta TempX2
- lda TempY1
- sta TempY2
- lda EnemyPosX,y ; 8x16 so offset left by 8 to make it into a 16x16 area
- sub #8
- sta TempX1
- lda EnemyPosY,y
- sta TempY1
- jsr CheckBlk
- rts
- runtest2: ; enemy to user
- ldy EnemyIndex
- lda UserPosX,x
- sub #8
- sta TempX1
- lda UserPosY,x
- sub #8
- sta TempY1
- lda EnemyPosX,y ; 8x16 so offset left by 8 to make it into a 16x16 area
- sub #8
- sta TempX2 ; D
- lda EnemyPosY,y
- sta TempY2 ; E
- jsr CheckUsr
- lda TempX1
- sta TempX2
- lda TempY1
- sta TempY2
- ldy EnemyIndex
- lda EnemyPosX,y ; 8x16 so offset left by 8 to make it into a 16x16 area
- sub #8
- sta TempX1
- lda EnemyPosY,y
- sta TempY1
- jsr CheckUsr
- NoCol2:
- clc
- rts
- CheckUsr:
- lda TempX1
- cmp TempX2
- bcc NoCol2
- lda TempX2
- add #16
- cmp TempX1
- bcc NoCol2
- lda TempY1
- cmp TempY2
- bcc NoCol2
- lda TempY2
- add #16
- cmp TempY1
- bcc NoCol2
- pla ; pop "Check"'s return address off stack
- pla
- ; apply damage to the enemy
- ldy EnemyIndex
- lda EnemyStun,y
- beq NotStunned
- lda #20
- sta UserBounceEnemy
- lda #0 ; put it back on its feet
- sta EnemyStun,y
- lda #-4
- sta UserVelY
- lda EnemyType,y ; HP is stored alongside enemy type and direction
- lsr ; Divide by 2 to get enemy type
- pha
- and #%1111 ; Mask off everything that isn't the enemy type
- tax ; We're going to use it as an index later
- pla
- and #%01110000 ; Take JUST the hit counter
- add #%00010000 ; Add one to the hit counter
- sta 6 ; Save it for a bit
- cmp EnemyHitsToKill,x
- bcc NotKilled
- lda Score
- add EnemyScoreIncrease,x
- sta Score
- bcc :+
- inc Score+1
- :
- ldy EnemyIndex
- lda #12 ; poof
- sta EnemyType,y
- lda #CH_ALL ; make a nice explosion sound
- sta SND_CHN
- lda #10 | SQ_1_2
- sta NOISE_VOL
- lda #255
- sta NOISE_LO
- lda #%00001000
- sta NOISE_HI
- jmp NotStunned ; don't rewrite EnemyType
- ; or play the other sound
- NotKilled:
- lda #CH_ALL
- sta SND_CHN
- lda #4 | SQ_1_4
- sta SQ1_VOL ; for pulse 1
- lda #15 ;SWEEP_OFF
- sta SQ1_SWEEP ; for pulse 1
- lda #255
- sta SQ1_LO
- lda #%00001010
- sta SQ1_HI
- ldy EnemyIndex
- lda EnemyType,y
- and #%00011111 ; Kill health bits
- .ifdef REAL_CONSOLE
- slo 6 ; OR in new value
- .else
- asl 6
- ora 6
- .endif
- sta EnemyType,y ; Updated health
- rts
- NotStunned: ; this means player killed
- lda UserBounceEnemy
- bne NotHurtByEnemy
- lda #12 ; So an enemy can't kill you over and over and over
- sta EnemyType,y
- lda #0
- sta EnemyStun,y
- jsr PlayerHurt
- NotHurtByEnemy:
- rts
- NoCol1:
- clc
- rts
- CheckBlk:
- lda TempX1
- cmp TempX2
- bcc NoCol1
- lda TempX2
- add #16
- cmp TempX1
- bcc NoCol1
- lda TempY1
- cmp TempY2
- bcc NoCol1
- lda TempY2
- add #16
- cmp TempY1
- bcc NoCol1
- pla ; pop "Check"'s return address off stack
- pla
- ldy EnemyIndex
- lda #200 ; increased a little
- sta EnemyStun,y
- lda #CH_ALL ; make a nice explosion sound
- sta SND_CHN
- lda #5 | SQ_1_2
- sta NOISE_VOL
- lda #32
- sta NOISE_LO
- lda #%00001000
- sta NOISE_HI
- rts
- .endproc
- .proc PlayerHurt ; stupid fly-into-sky animation
- dec UserLives
- lda #180 ; invincible for a bit after dying
- sta UserBounceEnemy
- lda #CH_ALL ; make a nice explosion sound
- sta SND_CHN
- lda #10 | SQ_1_2
- sta NOISE_VOL
- lda #50
- sta NOISE_LO
- lda #%00001000
- sta NOISE_HI
- rts
- ; clear sprites
- ldx #0
- txa
- : sta $200,x
- inx
- bne :-
- ; float up into the sky
- lda #0
- sta 5 ; y velocity
- : lda UserPosY
- sub 5
- bcc EndAwesome ; comment this line out for longer animation
- sta UserPosY
- inc 5
- jsr DrawPlayer
- jsr wait_vblank
- lda #CH_ALL
- sta SND_CHN
- lda #4 | SQ_1_4
- sta SQ1_VOL ; for pulse 1
- lda #15 ;SWEEP_OFF
- sta SQ1_SWEEP ; for pulse 1
- jsr rand_8
- sta SQ1_LO
- lda #%00001000
- sta SQ1_HI
- lda UserPosY
- bne :-
- EndAwesome:
- ; make sure the player isn't caught in the ceiling
- lda #32
- sta UserPosY
- add #AdjustPlayerYForChecking
- and #%11110000
- sta 5
- lda UserPosX
- .repeat 4 ; divide by 16
- lsr
- .endrep
- add 5
- tax
- TestIndex:
- lda LevelBuf,x
- bne OkayIndex
- lda UserPosY
- add #16
- sta UserPosY
- txa
- add #16
- tax
- jmp TestIndex
- OkayIndex:
- rts
- .endproc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement