Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .proc RunPlayer
- lda #4
- sta PlayerHealth
- jsr UpdateStatus
- jsr HandlePlayer
- rts
- .endproc
- NOVA_ACCEL_SPEED = 4
- NOVA_DEACCEL_SPEED = 8
- .proc UpdateStatus
- HealthX = 0
- HealthCount = 1
- ldy OamPtr
- lda #15
- sta HealthX
- sta OAM_YPOS+(4*0),y
- sta OAM_YPOS+(4*1),y
- sta OAM_XPOS+(4*0),y
- sta OAM_XPOS+(4*2),y
- lda #15+8
- sta OAM_YPOS+(4*2),y
- sta OAM_YPOS+(4*3),y
- sta OAM_XPOS+(4*1),y
- sta OAM_XPOS+(4*3),y
- lda #$4c
- sta OAM_TILE+(4*0),y
- lda #$4d
- sta OAM_TILE+(4*2),y
- lda #$4e
- sta OAM_TILE+(4*1),y
- lda #$4f
- sta OAM_TILE+(4*3),y
- lda #0
- sta OAM_ATTR+(4*0),y
- sta OAM_ATTR+(4*1),y
- sta OAM_ATTR+(4*2),y
- sta OAM_ATTR+(4*3),y
- tya
- add #4*4
- tay
- ; Draw all hearts needed
- lda PlayerHealth
- lsr
- php
- sta HealthCount
- Loop:
- lda HealthCount
- beq NoMoreHearts
- lda #$4a
- jsr MakeHeart
- dec HealthCount
- bne Loop
- NoMoreHearts:
- plp ; add a half heart if needed
- bcc :+
- lda #$4b
- jsr MakeHeart
- :
- sty OamPtr
- rts
- MakeHeart:
- sta OAM_TILE,y
- lda HealthX
- sta OAM_XPOS,y
- add #8
- sta HealthX
- lda #0
- sta OAM_ATTR,y
- lda #15+16
- sta OAM_YPOS,y
- iny
- iny
- iny
- iny
- rts
- .endproc
- .proc HandlePlayer
- lda #0
- sta PlayerOnGround
- lda PlayerVYH
- bmi GravityAddOK
- lda PlayerVYL
- cmp #$60
- bcs SkipGravity
- GravityAddOK:
- lda PlayerVYL
- add #4
- sta PlayerVYL
- bcc SkipGravity
- inc PlayerVYH
- SkipGravity:
- ; apply gravity
- lda PlayerPYL
- add PlayerVYL
- sta PlayerPYL
- lda PlayerPYH
- adc PlayerVYH
- and #$0f
- sta PlayerPYH
- ; detect if hitting anything from below
- lda PlayerPYH
- tay
- ldx PlayerDir
- ; lda FeetXOffsetForDir,x ; left side
- lda #0
- pha
- add PlayerPXL
- lda PlayerPXH
- adc #0
- jsr GetLevelColumnPtr
- sta 0
- pla ; right side
- add #$70
- add PlayerPXL
- lda PlayerPXH
- adc #0
- jsr GetLevelColumnPtr
- sta 1
- ldx 0
- lda MetatileFlags,x
- and #M_SOLID_ALL
- sta 2
- ldx 1
- lda MetatileFlags,x
- and #M_SOLID_ALL
- ora 2
- beq NotHittingBelow
- HittingBelow:
- lda #0
- sta PlayerVYH
- sta PlayerVYL
- NotHittingBelow:
- ; detect if standing on anything solid
- lda PlayerVYH
- bmi NotStandingOnSolid
- lda #0
- sta PlayerJumping
- lda PlayerPYL
- add #<(24*16)
- lda PlayerPYH
- adc #>(24*16)
- tay
- ldx PlayerDir
- lda #0 ; left side
- pha
- add PlayerPXL
- lda PlayerPXH
- adc #0
- jsr GetLevelColumnPtr
- sta 0
- pla ; right side
- add #$70
- add PlayerPXL
- lda PlayerPXH
- adc #0
- jsr GetLevelColumnPtr
- sta 1
- ldx 0
- lda MetatileFlags,x
- and #M_SOLID_TOP
- sta 2
- ldx 1
- lda MetatileFlags,x
- and #M_SOLID_TOP
- ora 2
- beq NotStandingOnSolid
- StandingOnSolid:
- inc PlayerOnGround
- lda #0
- sta PlayerVYH
- sta PlayerVYL
- lda #$80
- sta PlayerPYL
- lda keylast
- and #KEY_A
- bne :+
- lda keydown
- and #KEY_A
- beq :+
- lda #<(-$50)
- sta PlayerVYL
- lda #>(-$50)
- sta PlayerVYH
- inc PlayerJumping
- :
- NotStandingOnSolid:
- lda PlayerVYH
- bpl :+
- lda keydown ; cancel a jump (doesn't appear to work?)
- and #KEY_A
- bne :+
- lda PlayerJumpCancelLock
- bne :+
- lda #0
- sta PlayerVYH
- sta PlayerVYL
- :
- ; handle left and right
- lda keydown
- and #KEY_LEFT
- beq NotLeft
- ; lda PlayerDir
- ; bne :+
- lda #1
- sta PlayerDir
- ; lda PlayerPXL
- ; add #8<<4
- ; sta PlayerPXL
- ; bcc :+
- ; inc PlayerPXH
- ; :
- lda PlayerVXL
- cmp #-64
- beq NotLeft
- lda PlayerVXL
- bne :+
- dec PlayerVXH
- : sub #NOVA_ACCEL_SPEED
- sta PlayerVXL
- NotLeft:
- lda keydown
- and #KEY_RIGHT
- beq NotRight
- ; lda PlayerDir
- ; beq :+
- lda #0
- sta PlayerDir
- ; lda PlayerPXL
- ; sub #8<<4
- ; sta PlayerPXL
- ; bcs :+
- ; dec PlayerPXH
- ; :
- lda PlayerVXL
- cmp #64
- beq NotRight
- lda PlayerVXL
- add #NOVA_ACCEL_SPEED
- sta PlayerVXL
- bne NotRight
- inc PlayerVXH
- NotRight:
- lda keydown
- and #KEY_LEFT | KEY_RIGHT
- bne IsMoving
- lda PlayerVXL
- ora PlayerVXH
- beq IsMoving
- lda PlayerVXH ; if negative, make positive
- and #128
- sta 0
- beq :+
- neg16 PlayerVXL, PlayerVXH
- :
- lda PlayerVXL
- sub #NOVA_DEACCEL_SPEED
- sta PlayerVXL
- bcs @NotCarry
- dec PlayerVXH
- bpl @NotCarry
- lda #0
- sta PlayerVXH
- sta PlayerVXL
- @NotCarry:
- lda 0 ; if it was negative make negative again
- beq :+
- neg16 PlayerVXL, PlayerVXH
- :
- Stopped:
- IsMoving:
- ; apply speed without caring if it's gonna push us into a wall or not
- lda PlayerPXL
- add PlayerVXL
- sta PlayerPXL
- lda PlayerPXH
- adc PlayerVXH
- ; and #$0f ; comment out when we put in scrolling
- sta PlayerPXH
- ; now see if we pushed into a wall
- lda PlayerPYL
- add #<(23*16)
- lda PlayerPYH
- adc #>(23*16)
- tay
- lda PlayerVXH
- cmp #$80
- lda #0
- rol ; negative bit is now bit 0
- tax
- sta 0
- lda PlayerPXL
- add HSpeedDirectionOffset,x
- lda PlayerPXH
- adc #0
- jsr GetLevelColumnPtr
- tax
- lda MetatileFlags,x
- and #M_SOLID_ALL
- bne YesInWall
- ; try by player's head
- lda PlayerPYL
- add #<(2*16)
- lda PlayerPYH
- adc #>(2*16)
- tay
- lda (LevelBlockPtr),y
- tax
- lda MetatileFlags,x
- and #M_SOLID_ALL
- bne YesInWall
- beq NotInWall
- YesInWall:
- lda #0
- sta PlayerVXL
- sta PlayerVXH
- sta PlayerPXL
- lda 0
- bne :+
- lda #$8f
- sta PlayerPXL
- bne NotInWall
- :
- lda 0
- beq :+
- inc PlayerPXH
- :
- NotInWall:
- rts
- HSpeedDirectionOffset:
- .byt $8f, 0
- .endproc
- .proc DisplayPlayer
- DrawX = 0
- DrawY = 1
- Attrib = 2
- RealPosToScreenPos PlayerPXL, PlayerPXH, ScrollX, DrawX
- RealPosToScreenPos PlayerPYL, PlayerPYH, ScrollY, DrawY
- lda PlayerDir
- bne :+
- lda DrawX
- sub #8
- sta DrawX
- :
- lda #$00
- sta PlayerTiles+0
- lda #$01
- sta PlayerTiles+1
- lda #$02
- sta PlayerTiles+2
- lda #$03
- sta PlayerTiles+3
- lda #$04
- sta PlayerTiles+4
- lda #$05
- sta PlayerTiles+5
- lda PlayerJumping
- beq :+
- lda #$0c
- sta PlayerTiles+3
- lda #$08
- sta PlayerTiles+4
- lda #$09
- sta PlayerTiles+5
- jmp NoSpecialAnimation
- :
- lda PlayerOnGround
- bne :+
- lda #$0d
- sta PlayerTiles+2
- lda #$0e
- sta PlayerTiles+3
- lda #$0a
- sta PlayerTiles+4
- lda #$0b
- sta PlayerTiles+5
- jmp NoSpecialAnimation
- :
- ; animate walking
- lda PlayerVXL
- ora PlayerVXH
- beq :+
- lda retraces
- and #%100
- beq :+
- lda #$06
- sta PlayerTiles+4
- lda #$07
- sta PlayerTiles+5
- :
- NoSpecialAnimation:
- lda #0
- sta Attrib
- ; flip horizontally
- lda PlayerDir
- beq :+
- lda #OAM_XFLIP
- sta Attrib
- swapy PlayerTiles+0, PlayerTiles+1
- swapy PlayerTiles+2, PlayerTiles+3
- swapy PlayerTiles+4, PlayerTiles+5
- :
- ldx OamPtr
- ldy #0 ; current sprite
- PutSprite:
- lda PlayerTiles,y
- sta OAM_TILE,x
- lda DrawX
- add XPosList,y
- sta OAM_XPOS,x
- lda DrawY
- add YPosList,y
- sta OAM_YPOS,x
- lda Attrib
- sta OAM_ATTR,x
- inx
- inx
- inx
- inx
- iny
- cpy #6
- bne PutSprite
- stx OamPtr
- rts
- XPosList: .byt 0, 8, 0, 8, 0, 8
- YPosList: .byt 0, 0, 8, 8, 16, 16
- .endproc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement