-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEnemy_Float_Main.ccs
More file actions
268 lines (208 loc) · 7.27 KB
/
Copy pathEnemy_Float_Main.ccs
File metadata and controls
268 lines (208 loc) · 7.27 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
import asm65816
import asmref
//-+-+-+-+-+ SCRIPT INFO +-+-+-+-+-
/*
What this script does is to implement a new pointless feature that makes enemy's float. It does not have any gameplay affects other than it looks aesthetically pleasing. In order for an enemy to float, you'll have to give an enemy a status effect of 0x000A. How you can give it to them by ASM is this:
LDA_a (0xA970) to target itself or LDA_a (0xA972) to target others
LDX_i (0x0000)
LDY_i (0x000A)
JSL (Inflict_Status) // <-- this is in the asmref.ccs file
Do note that if an enemy receives any of these status effects, then the floating affect will be overwritten:
. Unconscious
. Diamondized
. Paralyzed
. Nauseous
. Poisoned
. Sunstroke
. Sniffling
Also note that this only works for enemies and not towards players. So if a player got affected with the floating status affect, nothing will happen.
This makes use of the enemy's vitality stat to keep track of the values being used as parameters to a sine function.
So if you intend to use the enemy's vitality stat to play an important role in battle, then what
you will need to do is to change the RAM where it writes the paramters for the sine fuciton to another RAM section.
TODO: Optimize this script so it doesn't lag the game when there's 5 or more floating enemies in battle.
*/
//-+-+-+-+-+ SETTINGS +-+-+-+-+-
// These values are the original y-positions of the enemy in their rows
define First_Row_y = 0x90
define Second_Row_y = 0x80
// These value determines the middle y-axis where the enemy will float through for the first and second row.
define First_Row_Base_y = 0x80
define Second_Row_Base_y = 0x78
// This defines the amplitude of how much to float up and downward.
// Higher amplitudeFraction means a larger distance going up and down
define amplitudeFraction = 8 // Default is 8
// This defines the speed of each y-position per frame.
// So if speedFraction is 2, then that means each y-position will be updated every 2 frames. If this is set at 1, then that means it'll update per frame.
// Remeber that there's 60 frames in a second
define speedFraction = 1 // Default is 1
//-+-+-+-+-+ ASM CODE +-+-+-+-+-
Enemy_Float_Check:{
REP (0x31)
PHD
TDC
ADC_i (0xFFEE)
TCD
LDX_i (0xA21C) // First enemy in the battle
STZ_d (0x02) // Counter
STX_d (0x04) // Current Enemy
// This checks to see if each enemy has a floating status effect
Floating_Status_Check:
LDX_d (0x04)
LDA_x (0x0000)
BEQ_a (Check_Next_Enemy)
LDA_x (0x001D)
CMP_i (0x000A) // Floating Status Effect
BNE_a (Check_y_Position) // If they don't have the effect, check if they are at the right y-position
LDA_i (speedFraction) // Load speedFraction
CMP_i (1)
BEQ_a (Determine_Row) // If it's 1, then branch
// This updates the sprite's y-position per set of frames.
LDA_a (0x00A7) // In-Game Frame counter
AND_i (0x00FF) // Get low byte
LDY_i (speedFraction)
JSL (Divide_YxA)// Mod speedFraction
TYA
CMP_i (0)
BNE_a (Check_Next_Enemy) // If mod speedFraction != 0, branch
Determine_Row:
LDA_x (0x0010)
AND_i (0x00FF)
CMP_i (0)
BNE_a (Second_Row)
LDA_i (First_Row_Base_y)
BRA_a (Store_y_Pos)
Second_Row:
LDA_i (Second_Row_Base_y)
Store_y_Pos:
STA_d (0x0E)
LDX_d (0x04)
JSL (New_Y_Pos)
STA_d (0x06) // DPR 0x06 = New y-position
LDA_d (0x06) // Load the new y-position
SEP (0x20) // Make A register 8-bit
STA_x (0x0045) // Store it back to the Y position
REP (0x20) // Make A register 16-bit
BRA_a (Check_Next_Enemy)
Check_y_Position:
LDA_x (0x0010)
AND_i (0x00FF)
CMP_i (0)
BNE_a (Second_Row_2)
LDA_i (First_Row_y)
BRA_a (Compare_y_pos)
Second_Row_2:
LDA_i (Second_Row_y)
Compare_y_pos:
STA_d (0x0E)
LDX_d (0x04) // Load in the enemy
LDA_x (0x0045) // Load enemy's current y-position
AND_i (0x00FF) // Get low byte
CMP_d (0x0E) // Check to see if they are in the adjusted y-position
BEQ_a (Check_Next_Enemy) // If so, then skip
LDA_d (0x0E) // Else, fix the enemy's first row y-position
SEP (0x20) // Make A register 8-bit
STA_x (0x0045) // Store the original y-position
REP (0x20) // Make A register 16-bit
BRA_a (Check_Next_Enemy) // Branch
Check_Next_Enemy:
INC_d (0x02) // Increment Counter
LDA_d (0x02) // Load Counter
CMP_i (0x0008) // If counter = 8 (as in, we loop through all of the enemies)
BEQ_a (Return) // We return back to the routine we jump out off
BCS_a (Return) // If the counter is above 7, we return too
LDA_d (0x04) // Else, we load the current enemy
CLC
ADC_i (0x004E) // We go to the next enemy
STA_d (0x04) // Store it back to DPR 0x04
BRA_a (Floating_Status_Check) // Loop
Return:
PLD
RTL
}
//-+-+-+-+-+ MISC ROUTINES +-+-+-+-+-
/*------------------------------
This routine will calcualte the new y-position based on the formula:
new_y_pos = base_y_pos - (sin(var) / (base_y_pos / 8))
- where var is an incremental variable stored in RAM from ranges 0 through 127 inclusively
OR
new_y_pos = base_y_pos + (sin(var) / (base_y_pos / 8))
- where var is an incremental variable stored in RAM from ranges 128 through 255 inclusively
Parameters:
A: The base y-position of the enemy
X: Current enemy address location
Returns:
A: The new y-position of the enemy
*/
New_Y_Pos:{
REP (0x31)
PHD
PHA
TDC
ADC_i (0xFFEE)
TCD
PLA
STA_d (0x02) // DPR 0x02 = The base y-position
STX_d (0x04) // DPR 0x04 = Current enemy
LDA_x (0x0030) // Load in the enemy's vitality stat. This will be the "var" value in the sine function
AND_i (0x00FF) // Get low byte
STA_d (0x08) // DPR 0x08 = current enemy's vitality
CMP_i (0x0080) // Compares if it's singed negative in 8-bit
BCS_a (Two_Compliment_This) // Make it a positive number
BRA_a (Continue)
Two_Compliment_This:
EOR_i (0x00FF)
INC
AND_i (0x00FF)
Continue:
JSL (Sine)
STA_d (0x06) // DPR 0x06 = Sin(var) or Cos(var)
LDA_d (0x02) // Load base y-position
LDY_i (amplitudeFraction)
JSL (Divide_YxA)
TAY
LDA_d (0x06) // Load Sin(var) into Y register
JSL (Divide_YxA)
STA_d (0x06) // DPR 0x06 = sin(var) / (y_pos / 8)
LDA_d (0x08) // Load current enemy's vitality
CMP_i (0x0080) // See if it's singed negaitve in 8-bit
BCS_a (Add_y_pos) // If so, then branch
LDA_d (0x02) // Load base y-position
SEC
SBC_d (0x06) // y_pos - (sin(var) / (y_pos / 8))
BRA_a (Continue_2)
Add_y_pos:
LDA_d (0x02)
CLC
ADC_d (0x06) // y_pos + (sin(var) / (y_pos / 8))
Continue_2:
TAY // Transfer the result to the Y register
LDX_d (0x04)
SEP (0x20)
LDA_x (0x0030) // Load in vitality stat
INC // Increment
/*
// Enabling this will make the enemy jump
CMP_8 (0x80) // Check it against 0x80
BMI_a (Set_var) // If it's lower, then set it
LDA_8 (0) // Else, load in 0
*/
Set_var:
STA_x (0x0030)
REP (0x20)
TYA // Transfer the data in Y to A
PLD
RTL
}
/*------------------------------
Rewritting the sine function. Don't know why EB's sine function isn't working for me...
Parameters:
A: Integer to pass to the sine function
Return:
A: The result of the sin loop-up table
*/
Sine:{
TAX
LDA_xl (0xC0B425) // Sine look-up table
AND_i (0x00FF)
RTL
}