strawberry.asm
ReinUsesLisp_celeste-nes/strawberry.asm
InitStrawberry:
	STX strawberry_x
	STY strawberry_y
	MOVB #$01, strawberry_on
	RTS

SetFlyStrawberry:
	MOVB #$01, strawberry_fly
	RTS
	
ResetStrawberry:
	LDA #$00
	STA strawberry_x
	STA strawberry_y
	STA strawberry_on
	STA strawberry_fly
	STA strawberry_fly_away
	RTS
	
LoadStrawberry:
	TYA
	PHA
	JSR PopWorld
	TAX
	JSR PopWorld
	TAY
	JSR InitStrawberry
	
	PLA
	TAY
	INY
	INY
	RTS

HideStrawberry:
	LDA #$FF
	STA SLOT_STRAWBERRY+DRAW_Y
	STA SLOT_STRAWBERRY+DRAW_Y+4
	STA SLOT_STRAWBERRY+DRAW_Y+8
	STA SLOT_STRAWBERRY+DRAW_Y+12
	STA SLOT_STRAWBERRY+DRAW_Y+16
	STA SLOT_STRAWBERRY+DRAW_Y+20
HideWings:	
	LDA #$FF
	STA SLOT_STRAWBERRY+DRAW_Y+24
	STA SLOT_STRAWBERRY+DRAW_Y+28
	STA SLOT_STRAWBERRY+DRAW_Y+36
	STA SLOT_STRAWBERRY+DRAW_Y+40
	STA SLOT_STRAWBERRY+DRAW_Y+32
	STA SLOT_STRAWBERRY+DRAW_Y+44
	RTS
	
DrawStrawberry:
	LDA strawberry_on
	BNE .do
	JSR HideStrawberry
	RTS
.do:	
	LDA strawberry_y
	ASL A
	SEC
	SBC #$01
	CLC
	STA SLOT_STRAWBERRY+DRAW_Y
	STA SLOT_STRAWBERRY+DRAW_Y+4
	STA SLOT_STRAWBERRY+DRAW_Y+16
	STA SLOT_STRAWBERRY+DRAW_Y+20
	ADC #$08
	STA SLOT_STRAWBERRY+DRAW_Y+8
	STA SLOT_STRAWBERRY+DRAW_Y+12
	
	MOVB #$08, SLOT_STRAWBERRY+DRAW_TILE
	MOVB #$09, SLOT_STRAWBERRY+DRAW_TILE+4
	MOVB #$18, SLOT_STRAWBERRY+DRAW_TILE+8
	MOVB #$19, SLOT_STRAWBERRY+DRAW_TILE+12
	MOVB #$06, SLOT_STRAWBERRY+DRAW_TILE+16
	MOVB #$07, SLOT_STRAWBERRY+DRAW_TILE+20

	LDA #%00000010
	STA SLOT_STRAWBERRY+DRAW_ATTR
	STA SLOT_STRAWBERRY+DRAW_ATTR+4
	STA SLOT_STRAWBERRY+DRAW_ATTR+8
	STA SLOT_STRAWBERRY+DRAW_ATTR+12
	LDA #%00000011
	STA SLOT_STRAWBERRY+DRAW_ATTR+16
	STA SLOT_STRAWBERRY+DRAW_ATTR+20

	LDA strawberry_x
	ASL A
	STA SLOT_STRAWBERRY+DRAW_X
	STA SLOT_STRAWBERRY+DRAW_X+8
	STA SLOT_STRAWBERRY+DRAW_X+16
	ADC #$08
	STA SLOT_STRAWBERRY+DRAW_X+4
	STA SLOT_STRAWBERRY+DRAW_X+12
	STA SLOT_STRAWBERRY+DRAW_X+20

	LDA strawberry_fly
	BNE DrawFlyStrawberry
	JSR HideWings
	RTS

DrawFlyStrawberry:
	LDA strawberry_y
	ASL A
	SEC
	SBC #$01
	CLC
	TAX
	LDA frames
	AND #%00111111
	CMP #$15
	BMI .noFixY
	TXA
	ADC #$04
	TAX
.noFixY:
	TXA

	STA SLOT_STRAWBERRY+DRAW_Y+24
	STA SLOT_STRAWBERRY+DRAW_Y+28
	STA SLOT_STRAWBERRY+DRAW_Y+36
	STA SLOT_STRAWBERRY+DRAW_Y+40
	ADC #$08
	STA SLOT_STRAWBERRY+DRAW_Y+32
	STA SLOT_STRAWBERRY+DRAW_Y+44

	LDA frames
	AND #%00111111
	CMP #$2A
	BPL .midWings
	CMP #$15
	BPL .lowWings
.highWings:	
	LDA #$22
	LDX #$23
	LDY #$33
	JMP .setTile
.midWings:
	LDA #$34
	LDX #$35
	LDY #$0D
	JMP .setTile
.lowWings:
	LDA #$24
	LDX #$25
	LDY #$0D
.setTile:
	STA SLOT_STRAWBERRY+DRAW_TILE+24
	STX SLOT_STRAWBERRY+DRAW_TILE+28
	STY SLOT_STRAWBERRY+DRAW_TILE+32
	STA SLOT_STRAWBERRY+DRAW_TILE+36
	STX SLOT_STRAWBERRY+DRAW_TILE+40
	STY SLOT_STRAWBERRY+DRAW_TILE+44

	LDA #%00000001
	STA SLOT_STRAWBERRY+DRAW_ATTR+24
	STA SLOT_STRAWBERRY+DRAW_ATTR+28
	STA SLOT_STRAWBERRY+DRAW_ATTR+32
	LDA #%01000001
	STA SLOT_STRAWBERRY+DRAW_ATTR+36
	STA SLOT_STRAWBERRY+DRAW_ATTR+40
	STA SLOT_STRAWBERRY+DRAW_ATTR+44

	LDA strawberry_x
	ASL A
	SEC
	SBC #$0E
	CLC
	STA SLOT_STRAWBERRY+DRAW_X+24
	ADC #$08
	STA SLOT_STRAWBERRY+DRAW_X+28
	STA SLOT_STRAWBERRY+DRAW_X+32
	ADC #$14
	STA SLOT_STRAWBERRY+DRAW_X+40
	STA SLOT_STRAWBERRY+DRAW_X+44
	ADC #$08
	STA SLOT_STRAWBERRY+DRAW_X+36
	RTS

	
UpdateStrawberry:
	;; Animate strawberry
	LDA frames
	AND #%00011111
	BNE .animEnd
	LDX strawberry_y
	LDA frames
	BPL .animDown
	INX
	JMP .animFinish
.animDown:
	DEX
.animFinish:
	TXA
	STA strawberry_y
.animEnd:

	LDA #$01
	STA flag_strawberry
	
	MOVB strawberry_x, rectangle_x
	MOVB strawberry_y, rectangle_y
	LDA #$08
	STA rectangle_width
	STA rectangle_height
	
	JSR PlayerAt
	BNE .grab
	JMP .finish
.grab:
	;; Play animation
	;; Show 1000
	;; Give reward
.finish:
	LDA strawberry_fly
	BNE UpdateFlyStrawberry
	RTS

UpdateFlyStrawberry:
	LDA dash
	BEQ .noFlyAway
	LDA #$01
	STA strawberry_fly_away
.noFlyAway:

	LDA strawberry_fly_away
	BEQ .end
	DEC strawberry_y
	BPL .end
	LDA #$00
	STA strawberry_on
	;; Put the strawberry somewhere it can't be touched
	LDA #$90		; yay I'm so random
	STA strawberry_x
	STA strawberry_y
	
.end:	
	RTS
