aboutsummaryrefslogtreecommitdiff
path: root/enemiesattacks/laser.gbasm
blob: 648c5f70dad4dcd6ae92035664349e6f1f51c454 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
Laser_sight_check: ; BC = XY of the enemy. D = direction (must be unchanged). Direction to face in E (or 0 if not)
	LD E, $00

	; straight line + distance <= 4
	LD A, $mem_bunny_predicted_x
	CP B
	JR Z, =.vertical_distance_check

	LD A, $mem_bunny_predicted_y
	CP C
	RET NZ

	.horizontal_distance_check:
	LD A, $mem_bunny_predicted_x
	CP B
	JR C, =.left

	.right:
		SUB $05
		CP B
		RET NC
		LD E, $enum_direction_right
		RET

	.left:
		ADD $04
		CP B
		RET C
		LD E, $enum_direction_left
		RET

	.vertical_distance_check:
		LD A, $mem_bunny_predicted_y
		CP C
		JR C, =.up

		.down:
			SUB $05
			CP C
			RET NC
			LD E, $enum_direction_down
			RET

		.up:
			ADD $04
			CP C
			RET C
			LD E, $enum_direction_up
			RET

Laser_Enemy_Attack: ; Direction to face in E. Result in BC (XY), Direction in D
	PUSH DE
	PUSH BC

	LD A, E
	DEC A
	AND $03
	SWAP A
	SLA A
	SLA A
	OR $03 ; Laser_Animation
	LD D, A

	LD A, C
	ADD B
	LD B, A

	LD A, $mem_bunny_x
	LD C, A
	LD A, $mem_bunny_y
	ADD C
	SUB B
	.ABS
	SWAP A
	LD E, A

	POP BC
	LD A, D
	LD D, $10
	CALL =Try_Launch_Animation

	LD A, $enum_animation_wait_mode
	LD $mem_requested_mode, A
	LD $mem_current_mode, A
	CALL =Update_VBlank_Handler
	LD A, E
	SUB $f
	LD E, A
	LD A, $mem_animation_wait_frames
	CP E
	JR NC, =.skip_animation_wait_frames_update

	LD A, E
	LD $mem_animation_wait_frames, A

	.skip_animation_wait_frames_update:

	LD A, $mem_animation_wait_frames

	POP DE

	LD A, $mem_bunny_health
	SUB $01
	JR C, =.health_underflow_fix
	DAA
	LD $mem_bunny_health, A
	JR =.Skip_health_underflow_fix

	.health_underflow_fix:
	LD A, $00
	LD $mem_bunny_health, A
	.Skip_health_underflow_fix:

	RET