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
115
116
117
118
119
120
121
122
123
124
125
126
|
Move_Bunny:
PUSH HL
LD C, $00 ; (bit 0 = has_scrolled, bit 1 = has ended movement)
LD A, $mem_bunny_direction
BIT 3, A
JR NZ, =Move_Bunny.check_direction
LD B, $00
Move_Bunny.check_start_action:
LD A, $mem_button_action
BIT 0, A
JR Z, =Move_Bunny.check_start_action.end
LD B, $10
Move_Bunny.check_start_action.end:
LD A, $mem_bunny_direction
AND $0f
OR B
LD $mem_bunny_direction, A
LD A, $mem_bunny_direction
AND $f0
LD B, A
LD A, $mem_button_direction
CP $00
JP Z, =Move_Bunny.end
SET 3, A
OR B
LD $mem_bunny_direction, A
Move_Bunny.check_collision:
LD A, $mem_moving_animation_step
CP $00
JR NZ, =Move_Bunny.check_collision.end
; THIS ASSUMES THAT THE BUNNY IS ALWAYS THE FIRST ENTITY IN THE LIST
LD HL, $mem_entities_list
LD A, $mem_bunny_direction
PUSH BC
CALL =Get_Position_After_Move
LD A, C
CALL =Is_Collisionable
CALL =Carve_Entity_Collision_Map
POP BC
CP $00
JR Z, =Move_Bunny.check_collision.end
Move_Bunny.check_collision.collision:
LD A, $mem_bunny_direction
RES 3, A
LD $mem_bunny_direction, A
JP =Move_Bunny.end
Move_Bunny.check_collision.end:
Move_Bunny.check_direction:
LD A, $mem_bunny_direction
DEC A
LD B, $01 ; Direction of the movement (+1)
BIT 0, A
JR NZ, =Move_Bunny.check_direction_end
LD B, $FF ; Direction of the movement (-1)
Move_Bunny.check_direction_end:
BIT 1, A
JR NZ, =Move_Bunny.vertical_viewport_move
Move_Bunny.horizontal_viewport_move:
SET 0, C
LD A, $reg_viewport_x
ADD B
LD $reg_viewport_x, A
JP =Move_Bunny.check_end_of_movement
Move_Bunny.vertical_viewport_move:
SET 0, C
LD A, $reg_viewport_y
ADD B
LD $reg_viewport_y, A
Move_Bunny.check_end_of_movement:
LD A, $mem_moving_animation_step
INC A
AND $0f
LD $mem_moving_animation_step, A
JR NZ, =Move_Bunny.end
SET 1, C
LD A, $mem_bunny_direction
RES 3, A
LD $mem_bunny_direction, A
AND $07
DEC A
BIT 1, A
JR NZ, =Move_Bunny.vertical_tile_move
Move_Bunny.horizontal_tile_move:
BIT 0, C
JR Z, =Move_Bunny.horizontal_tile_move.move_viewport_end
LD A, $mem_viewport_x
ADD B
LD $mem_viewport_x, A
Move_Bunny.horizontal_tile_move.move_viewport_end:
LD A, $mem_bunny_x
ADD B
LD $mem_bunny_x, A
JP =Move_Bunny.end
Move_Bunny.vertical_tile_move:
BIT 0, C
JR Z, =Move_Bunny.vertical_tile_move.move_viewport_end
LD A, $mem_viewport_y
ADD B
LD $mem_viewport_y, A
Move_Bunny.vertical_tile_move.move_viewport_end:
LD A, $mem_bunny_y
ADD B
LD $mem_bunny_y, A
Move_Bunny.end:
LD A, C
LD $mem_map_loading_flags, A
POP HL
RET
|